blob: a2abec26e91e36cb99f527f3cecb99f0890a2322 [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 Brown46b9ac02010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800152 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800162 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700164 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean DEBUG_APP_TRANSITIONS = false;
166 static final boolean DEBUG_STARTING_WINDOW = false;
167 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700168 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800169 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700171 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 static final boolean PROFILE_ORIENTATION = false;
174 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700175 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to multiply the policy's type layer, to reserve room
178 * for multiple windows of the same type and Z-ordering adjustment
179 * with TYPE_LAYER_OFFSET. */
180 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
183 * or below others in the same layer. */
184 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** How much to increment the layer for each window, to reserve room
187 * for effect surfaces between them.
188 */
189 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** The maximum length we will accept for a loaded animation duration:
192 * this is 10 seconds.
193 */
194 static final int MAX_ANIMATION_DURATION = 10*1000;
195
196 /** Amount of time (in milliseconds) to animate the dim surface from one
197 * value to another, when no window animation is driving it.
198 */
199 static final int DEFAULT_DIM_DURATION = 200;
200
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700201 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
202 * compatible windows.
203 */
204 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
205
Dianne Hackborna1111872010-11-23 20:55:11 -0800206 /**
207 * If true, the window manager will do its own custom freezing and general
208 * management of the screen during rotation.
209 */
210 static final boolean CUSTOM_SCREEN_ROTATION = true;
211
Jeff Brown7fbdc842010-06-17 20:52:56 -0700212 // Maximum number of milliseconds to wait for input event injection.
213 // FIXME is this value reasonable?
214 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800215
216 // Maximum number of milliseconds to wait for input devices to be enumerated before
217 // proceding with safe mode detection.
218 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700219
220 // Default input dispatching timeout in nanoseconds.
221 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 static final int UPDATE_FOCUS_NORMAL = 0;
224 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
225 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
226 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700229 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
231 /**
232 * Condition waited on by {@link #reenableKeyguard} to know the call to
233 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 * This is set to true only if mKeyguardTokenWatcher.acquired() has
235 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
Jim Miller284b62e2010-06-08 14:27:42 -0700239 private static final int ALLOW_DISABLE_YES = 1;
240 private static final int ALLOW_DISABLE_NO = 0;
241 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
242 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
243
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
245 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700247 if (shouldAllowDisableKeyguard()) {
248 mPolicy.enableKeyguard(false);
249 mKeyguardDisabled = true;
250 } else {
251 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700255 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500256 synchronized (mKeyguardTokenWatcher) {
257 mKeyguardDisabled = false;
258 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260 }
261 };
262
Jim Miller284b62e2010-06-08 14:27:42 -0700263 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
264 @Override
265 public void onReceive(Context context, Intent intent) {
266 mPolicy.enableKeyguard(true);
267 synchronized(mKeyguardTokenWatcher) {
268 // lazily evaluate this next time we're asked to disable keyguard
269 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
270 mKeyguardDisabled = false;
271 }
272 }
273 };
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final Context mContext;
276
277 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
282
283 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 /**
288 * All currently active sessions with clients.
289 */
290 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 /**
293 * Mapping from an IWindow IBinder to the server's Window object.
294 * This is also used as the lock for all of our state.
295 */
296 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
297
298 /**
299 * Mapping from a token IBinder to a WindowToken object.
300 */
301 final HashMap<IBinder, WindowToken> mTokenMap =
302 new HashMap<IBinder, WindowToken>();
303
304 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 * Window tokens that are in the process of exiting, but still
306 * on screen for animations.
307 */
308 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
309
310 /**
311 * Z-ordered (bottom-most first) list of all application tokens, for
312 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800313 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 */
315 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * Application tokens that are in the process of exiting, but still
319 * on screen for animations.
320 */
321 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
322
323 /**
324 * List of window tokens that have finished starting their application,
325 * and now need to have the policy remove their windows.
326 */
327 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
328
329 /**
330 * Z-ordered (bottom-most first) list of all Window objects.
331 */
Jeff Browne33348b2010-07-15 23:54:05 -0700332 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
334 /**
335 * Windows that are being resized. Used so we can tell the client about
336 * the resize after closing the transaction in which we resized the
337 * underlying surface.
338 */
339 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
340
341 /**
342 * Windows whose animations have ended and now must be removed.
343 */
344 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
345
346 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800347 * Used when processing mPendingRemove to avoid working on the original array.
348 */
349 WindowState[] mPendingRemoveTmp = new WindowState[20];
350
351 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 * Windows whose surface should be destroyed.
353 */
354 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
355
356 /**
357 * Windows that have lost input focus and are waiting for the new
358 * focus window to be displayed before they are told about this.
359 */
360 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
361
362 /**
363 * This is set when we have run out of memory, and will either be an empty
364 * list or contain windows that need to be force removed.
365 */
366 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700367
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800368 /**
369 * Used when rebuilding window list to keep track of windows that have
370 * been removed.
371 */
372 WindowState[] mRebuildTmp = new WindowState[20];
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800381 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800382 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 final float[] mTmpFloats = new float[9];
387
388 boolean mSafeMode;
389 boolean mDisplayEnabled = false;
390 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700391 int mInitialDisplayWidth = 0;
392 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 int mRotation = 0;
394 int mRequestedRotation = 0;
395 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700396 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 ArrayList<IRotationWatcher> mRotationWatchers
398 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800399 int mDeferredRotation;
400 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mLayoutNeeded = true;
403 boolean mAnimationPending = false;
404 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800405 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean mWindowsFreezingScreen = false;
407 long mFreezeGcPending = 0;
408 int mAppsFreezingScreen = 0;
409
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 int mLayoutSeq = 0;
411
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800412 // State while inside of layoutAndPlaceSurfacesLocked().
413 boolean mFocusMayChange;
414
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800415 Configuration mCurConfiguration = new Configuration();
416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 // This is held as long as we have the screen frozen, to give us time to
418 // perform a rotation animation when turning off shows the lock screen which
419 // changes the orientation.
420 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // State management of app transitions. When we are preparing for a
423 // transition, mNextAppTransition will be the kind of transition to
424 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
425 // mOpeningApps and mClosingApps are the lists of tokens that will be
426 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700427 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700428 String mNextAppTransitionPackage;
429 int mNextAppTransitionEnter;
430 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 boolean mAppTransitionTimeout = false;
434 boolean mStartingIconInTransition = false;
435 boolean mSkipAppTransitionAnimation = false;
436 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700438 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
439 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 H mH = new H();
444
445 WindowState mCurrentFocus = null;
446 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 // This just indicates the window the input method is on top of, not
449 // necessarily the window its input is going to.
450 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 boolean mInputMethodTargetWaitingAnim;
452 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 WindowState mInputMethodWindow = null;
455 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
456
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700457 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800458
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700459 // If non-null, this is the currently visible window that is associated
460 // with the wallpaper.
461 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the lower one in Z-order.
464 WindowState mLowerWallpaperTarget = null;
465 // If non-null, we are in the middle of animating from one wallpaper target
466 // to another, and this is the higher one in Z-order.
467 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800468 // Window currently running an animation that has requested it be detached
469 // from the wallpaper. This means we need to ensure the wallpaper is
470 // visible behind it in case it animates in a way that would allow it to be
471 // seen.
472 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700473 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700474 float mLastWallpaperX = -1;
475 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800476 float mLastWallpaperXStep = -1;
477 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700478 // This is set when we are waiting for a wallpaper to tell us it is done
479 // changing its scroll position.
480 WindowState mWaitingOnWallpaper;
481 // The last time we had a timeout when waiting for a wallpaper.
482 long mLastWallpaperTimeoutTime;
483 // We give a wallpaper up to 150ms to finish scrolling.
484 static final long WALLPAPER_TIMEOUT = 150;
485 // Time we wait after a timeout before trying to wait again.
486 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 AppWindowToken mFocusedApp = null;
489
490 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 float mWindowAnimationScale = 1.0f;
493 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Jeff Brown46b9ac02010-04-22 18:58:52 -0700495 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496
497 // Who is holding the screen on.
498 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700499 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700500
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700501 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700504 * Drag/drop state
505 */
506 class DragState {
507 IBinder mToken;
508 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800509 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700510 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700511 ClipData mData;
512 ClipDescription mDataDescription;
Chris Tated4533f12010-10-19 15:15:08 -0700513 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700514 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 float mThumbOffsetX, mThumbOffsetY;
516 InputChannel mServerChannel, mClientChannel;
517 WindowState mTargetWindow;
518 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700519 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700520
Jeff Brownfbf09772011-01-16 14:06:57 -0800521 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700522
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800523 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700524 mToken = token;
525 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800526 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700527 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700528 mNotifiedWindows = new ArrayList<WindowState>();
529 }
530
531 void reset() {
532 if (mSurface != null) {
533 mSurface.destroy();
534 }
535 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800536 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700537 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700538 mToken = null;
539 mData = null;
540 mThumbOffsetX = mThumbOffsetY = 0;
541 mNotifiedWindows = null;
542 }
543
544 void register() {
545 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
546 if (mClientChannel != null) {
547 Slog.e(TAG, "Duplicate register of drag input channel");
548 } else {
549 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
550 mServerChannel = channels[0];
551 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800552 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700553 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
554 mH.getLooper().getQueue());
555 }
556 }
557
558 void unregister() {
559 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
560 if (mClientChannel == null) {
561 Slog.e(TAG, "Unregister of nonexistent drag input channel");
562 } else {
563 mInputManager.unregisterInputChannel(mServerChannel);
564 InputQueue.unregisterInputChannel(mClientChannel);
565 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700566 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 mClientChannel = null;
568 mServerChannel = null;
569 }
570 }
571
Chris Tatea32dcf72010-10-14 12:13:50 -0700572 int getDragLayerLw() {
573 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
574 * TYPE_LAYER_MULTIPLIER
575 + TYPE_LAYER_OFFSET;
576 }
577
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 /* call out to each visible window/session informing it about the drag
579 */
Chris Tateb8203e92010-10-12 14:23:21 -0700580 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 // Cache a base-class instance of the clip metadata so that parceling
582 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800583 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700585 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700586
587 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700588 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
590
Christopher Tate2c095f32010-10-04 14:13:40 -0700591 final int N = mWindows.size();
592 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700593 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700595 }
596
597 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
598 * designated window is potentially a drop recipient. There are race situations
599 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
600 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700601 *
602 * This method clones the 'event' parameter if it's being delivered to the same
603 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700604 */
Chris Tateb478f462010-10-15 16:02:26 -0700605 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
606 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700607 // Don't actually send the event if the drag is supposed to be pinned
608 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800609 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700610 final IBinder winBinder = newWin.mClient.asBinder();
611 if (winBinder != mLocalWin) {
612 if (DEBUG_DRAG) {
613 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
614 }
615 return;
616 }
617 }
618
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700619 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700620 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
621 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800622 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700623 try {
624 newWin.mClient.dispatchDragEvent(event);
625 // track each window that we've notified that the drag is starting
626 mNotifiedWindows.add(newWin);
627 } catch (RemoteException e) {
628 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700629 } finally {
630 // if the callee was local, the dispatch has already recycled the event
631 if (Process.myPid() != newWin.mSession.mPid) {
632 event.recycle();
633 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700634 }
635 }
636 }
637
638 /* helper - construct and send a DRAG_STARTED event only if the window has not
639 * previously been notified, i.e. it became visible after the drag operation
640 * was begun. This is a rare case.
641 */
642 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700643 if (mDragInProgress) {
644 // If we have sent the drag-started, we needn't do so again
645 for (WindowState ws : mNotifiedWindows) {
646 if (ws == newWin) {
647 return;
648 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700650 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700651 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700652 }
Chris Tateb478f462010-10-15 16:02:26 -0700653 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700654 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700655 }
656
Chris Tated4533f12010-10-19 15:15:08 -0700657 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 if (DEBUG_DRAG) {
659 Slog.d(TAG, "broadcasting DRAG_ENDED");
660 }
Chris Tated4533f12010-10-19 15:15:08 -0700661 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800662 0, 0, null, null, null, mDragResult);
Chris Tated4533f12010-10-19 15:15:08 -0700663 for (WindowState ws: mNotifiedWindows) {
664 try {
665 ws.mClient.dispatchDragEvent(evt);
666 } catch (RemoteException e) {
667 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700668 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700669 }
Chris Tated4533f12010-10-19 15:15:08 -0700670 mNotifiedWindows.clear();
671 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 evt.recycle();
673 }
674
Chris Tated4533f12010-10-19 15:15:08 -0700675 void endDragLw() {
676 mDragState.broadcastDragEndedLw();
677
678 // stop intercepting input
679 mDragState.unregister();
Jeff Brown3a22cd92011-01-21 13:59:04 -0800680 mInputMonitor.setUpdateInputWindowsNeededLw();
Chris Tated4533f12010-10-19 15:15:08 -0700681 mInputMonitor.updateInputWindowsLw();
682
683 // free our resources and drop all the object references
684 mDragState.reset();
685 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800686
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800687 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
688 boolean changed = setRotationUncheckedLocked(
689 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
690 if (changed) {
691 sendNewConfiguration();
Christopher Tateccd24de2011-01-12 15:02:55 -0800692 }
Chris Tated4533f12010-10-19 15:15:08 -0700693 }
694
Christopher Tatea53146c2010-09-07 11:57:52 -0700695 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700696 final int myPid = Process.myPid();
697
698 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800699 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800700 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800701 try {
702 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
703 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800704 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800705 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
706 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700707
708 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700709 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800710 if (touchedWin == null) {
711 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
712 return;
713 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800714 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700715 final IBinder touchedBinder = touchedWin.mClient.asBinder();
716 if (touchedBinder != mLocalWin) {
717 // This drag is pinned only to the originating window, but the drag
718 // point is outside that window. Pretend it's over empty space.
719 touchedWin = null;
720 }
721 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700722 try {
723 // have we dragged over a new window?
724 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
725 if (DEBUG_DRAG) {
726 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
727 }
728 // force DRAG_EXITED_EVENT if appropriate
729 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700730 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800731 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700732 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700733 if (myPid != mTargetWindow.mSession.mPid) {
734 evt.recycle();
735 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700736 }
737 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700738 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700739 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
740 }
741 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700742 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800743 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700744 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700745 if (myPid != touchedWin.mSession.mPid) {
746 evt.recycle();
747 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700748 }
749 } catch (RemoteException e) {
750 Slog.w(TAG, "can't send drag notification to windows");
751 }
752 mTargetWindow = touchedWin;
753 }
754
Chris Tated4533f12010-10-19 15:15:08 -0700755 // Tell the drop target about the data. Returns 'true' if we can immediately
756 // dispatch the global drag-ended message, 'false' if we need to wait for a
757 // result from the recipient.
758 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700759 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f12010-10-19 15:15:08 -0700760 if (touchedWin == null) {
761 // "drop" outside a valid window -- no recipient to apply a
762 // timeout to, and we can send the drag-ended message immediately.
763 mDragResult = false;
764 return true;
765 }
766
767 if (DEBUG_DRAG) {
768 Slog.d(TAG, "sending DROP to " + touchedWin);
769 }
770 final int myPid = Process.myPid();
771 final IBinder token = touchedWin.mClient.asBinder();
772 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
773 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800774 null, null, mData, false);
Chris Tated4533f12010-10-19 15:15:08 -0700775 try {
776 touchedWin.mClient.dispatchDragEvent(evt);
777
778 // 5 second timeout for this window to respond to the drop
779 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
780 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
781 mH.sendMessageDelayed(msg, 5000);
782 } catch (RemoteException e) {
783 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
784 return true;
785 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700786 if (myPid != touchedWin.mSession.mPid) {
787 evt.recycle();
788 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700789 }
Chris Tated4533f12010-10-19 15:15:08 -0700790 mToken = token;
791 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700792 }
793
794 // Find the visible, touch-deliverable window under the given point
795 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
796 WindowState touchedWin = null;
797 final int x = (int) xf;
798 final int y = (int) yf;
799 final ArrayList<WindowState> windows = mWindows;
800 final int N = windows.size();
801 for (int i = N - 1; i >= 0; i--) {
802 WindowState child = windows.get(i);
803 final int flags = child.mAttrs.flags;
804 if (!child.isVisibleLw()) {
805 // not visible == don't tell about drags
806 continue;
807 }
808 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
809 // not touchable == don't tell about drags
810 continue;
811 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800812
813 child.getTouchableRegion(mTmpRegion);
814
Christopher Tatea53146c2010-09-07 11:57:52 -0700815 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800816 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
817 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
818 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700819 // Found it
820 touchedWin = child;
821 break;
822 }
823 }
824
825 return touchedWin;
826 }
827 }
828
829 DragState mDragState = null;
830 private final InputHandler mDragInputHandler = new BaseInputHandler() {
831 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700832 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
833 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700834 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700835 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
836 && mDragState != null) {
837 boolean endDrag = false;
838 final float newX = event.getRawX();
839 final float newY = event.getRawY();
840
Christopher Tatea53146c2010-09-07 11:57:52 -0700841 switch (event.getAction()) {
842 case MotionEvent.ACTION_DOWN: {
843 if (DEBUG_DRAG) {
844 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
845 }
846 } break;
847
848 case MotionEvent.ACTION_MOVE: {
849 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700850 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700851 mDragState.notifyMoveLw(newX, newY);
852 }
853 } break;
854
855 case MotionEvent.ACTION_UP: {
856 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
857 + newX + "," + newY);
858 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700859 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700860 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700861 } break;
862
863 case MotionEvent.ACTION_CANCEL: {
864 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
865 endDrag = true;
866 } break;
867 }
868
869 if (endDrag) {
870 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
871 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700872 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700873 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700874 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700875 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700876
877 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700878 }
879 } catch (Exception e) {
880 Slog.e(TAG, "Exception caught by drag handleMotion", e);
881 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700882 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700883 }
884 }
885 };
886
887 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 * Whether the UI is currently running in touch mode (not showing
889 * navigational focus because the user is directly pressing the screen).
890 */
891 boolean mInTouchMode = false;
892
893 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700894 private ArrayList<WindowChangeListener> mWindowChangeListeners =
895 new ArrayList<WindowChangeListener>();
896 private boolean mWindowsChanged = false;
897
898 public interface WindowChangeListener {
899 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700900 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902
Dianne Hackbornc485a602009-03-24 22:39:49 -0700903 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700904 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700905
906 // The frame use to limit the size of the app running in compatibility mode.
907 Rect mCompatibleScreenFrame = new Rect();
908 // The surface used to fill the outer rim of the app running in compatibility mode.
909 Surface mBackgroundFillerSurface = null;
910 boolean mBackgroundFillerShown = false;
911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 public static WindowManagerService main(Context context,
913 PowerManagerService pm, boolean haveInputMethods) {
914 WMThread thr = new WMThread(context, pm, haveInputMethods);
915 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 synchronized (thr) {
918 while (thr.mService == null) {
919 try {
920 thr.wait();
921 } catch (InterruptedException e) {
922 }
923 }
924 }
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 return thr.mService;
927 }
Romain Guy06882f82009-06-10 13:36:04 -0700928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 static class WMThread extends Thread {
930 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 private final Context mContext;
933 private final PowerManagerService mPM;
934 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 public WMThread(Context context, PowerManagerService pm,
937 boolean haveInputMethods) {
938 super("WindowManager");
939 mContext = context;
940 mPM = pm;
941 mHaveInputMethods = haveInputMethods;
942 }
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 public void run() {
945 Looper.prepare();
946 WindowManagerService s = new WindowManagerService(mContext, mPM,
947 mHaveInputMethods);
948 android.os.Process.setThreadPriority(
949 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700950 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 synchronized (this) {
953 mService = s;
954 notifyAll();
955 }
Romain Guy06882f82009-06-10 13:36:04 -0700956
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700957 // For debug builds, log event loop stalls to dropbox for analysis.
958 if (StrictMode.conditionallyEnableDebugLogging()) {
959 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
960 }
961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 Looper.loop();
963 }
964 }
965
966 static class PolicyThread extends Thread {
967 private final WindowManagerPolicy mPolicy;
968 private final WindowManagerService mService;
969 private final Context mContext;
970 private final PowerManagerService mPM;
971 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 public PolicyThread(WindowManagerPolicy policy,
974 WindowManagerService service, Context context,
975 PowerManagerService pm) {
976 super("WindowManagerPolicy");
977 mPolicy = policy;
978 mService = service;
979 mContext = context;
980 mPM = pm;
981 }
Romain Guy06882f82009-06-10 13:36:04 -0700982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 public void run() {
984 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800985 WindowManagerPolicyThread.set(this, Looper.myLooper());
986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800988 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 android.os.Process.setThreadPriority(
990 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700991 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 synchronized (this) {
995 mRunning = true;
996 notifyAll();
997 }
Romain Guy06882f82009-06-10 13:36:04 -0700998
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700999 // For debug builds, log event loop stalls to dropbox for analysis.
1000 if (StrictMode.conditionallyEnableDebugLogging()) {
1001 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1002 }
1003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 Looper.loop();
1005 }
1006 }
1007
1008 private WindowManagerService(Context context, PowerManagerService pm,
1009 boolean haveInputMethods) {
1010 mContext = context;
1011 mHaveInputMethods = haveInputMethods;
1012 mLimitedAlphaCompositing = context.getResources().getBoolean(
1013 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 mPowerManager = pm;
1016 mPowerManager.setPolicy(mPolicy);
1017 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1018 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1019 "SCREEN_FROZEN");
1020 mScreenFrozenLock.setReferenceCounted(false);
1021
1022 mActivityManager = ActivityManagerNative.getDefault();
1023 mBatteryStats = BatteryStatsService.getService();
1024
1025 // Get persisted window scale setting
1026 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1027 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1028 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1029 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001030
Jim Miller284b62e2010-06-08 14:27:42 -07001031 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1032 IntentFilter filter = new IntentFilter();
1033 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1034 mContext.registerReceiver(mBroadcastReceiver, filter);
1035
Jeff Brown46b9ac02010-04-22 18:58:52 -07001036 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1037 "KEEP_SCREEN_ON_FLAG");
1038 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039
Jeff Browne33348b2010-07-15 23:54:05 -07001040 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1043 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 synchronized (thr) {
1046 while (!thr.mRunning) {
1047 try {
1048 thr.wait();
1049 } catch (InterruptedException e) {
1050 }
1051 }
1052 }
Romain Guy06882f82009-06-10 13:36:04 -07001053
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001054 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 // Add ourself to the Watchdog monitors.
1057 Watchdog.getInstance().addMonitor(this);
1058 }
1059
1060 @Override
1061 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1062 throws RemoteException {
1063 try {
1064 return super.onTransact(code, data, reply, flags);
1065 } catch (RuntimeException e) {
1066 // The window manager only throws security exceptions, so let's
1067 // log all others.
1068 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001069 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 }
1071 throw e;
1072 }
1073 }
1074
Jeff Browne33348b2010-07-15 23:54:05 -07001075 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001077 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 TAG, "Adding window " + window + " at "
1079 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1080 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001081 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 }
1083
Jeff Browne33348b2010-07-15 23:54:05 -07001084 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001086 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 TAG, "Adding window " + window + " at "
1088 + i + " of " + mWindows.size() + " (before " + pos + ")");
1089 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001090 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 }
1092
1093 //This method finds out the index of a window that has the same app token as
1094 //win. used for z ordering the windows in mWindows
1095 private int findIdxBasedOnAppTokens(WindowState win) {
1096 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001097 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 int jmax = localmWindows.size();
1099 if(jmax == 0) {
1100 return -1;
1101 }
1102 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001103 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 if(wentry.mAppToken == win.mAppToken) {
1105 return j;
1106 }
1107 }
1108 return -1;
1109 }
Romain Guy06882f82009-06-10 13:36:04 -07001110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1112 final IWindow client = win.mClient;
1113 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001114 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 final int N = localmWindows.size();
1117 final WindowState attached = win.mAttachedWindow;
1118 int i;
1119 if (attached == null) {
1120 int tokenWindowsPos = token.windows.size();
1121 if (token.appWindowToken != null) {
1122 int index = tokenWindowsPos-1;
1123 if (index >= 0) {
1124 // If this application has existing windows, we
1125 // simply place the new window on top of them... but
1126 // keep the starting window on top.
1127 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1128 // Base windows go behind everything else.
1129 placeWindowBefore(token.windows.get(0), win);
1130 tokenWindowsPos = 0;
1131 } else {
1132 AppWindowToken atoken = win.mAppToken;
1133 if (atoken != null &&
1134 token.windows.get(index) == atoken.startingWindow) {
1135 placeWindowBefore(token.windows.get(index), win);
1136 tokenWindowsPos--;
1137 } else {
1138 int newIdx = findIdxBasedOnAppTokens(win);
1139 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001140 //there is a window above this one associated with the same
1141 //apptoken note that the window could be a floating window
1142 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001144 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1145 Slog.v(TAG, "Adding window " + win + " at "
1146 + (newIdx+1) + " of " + N);
1147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001149 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
1152 }
1153 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001154 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 TAG, "Figuring out where to add app window "
1156 + client.asBinder() + " (token=" + token + ")");
1157 // Figure out where the window should go, based on the
1158 // order of applications.
1159 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001160 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 for (i=NA-1; i>=0; i--) {
1162 AppWindowToken t = mAppTokens.get(i);
1163 if (t == token) {
1164 i--;
1165 break;
1166 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001167
Dianne Hackborna8f60182009-09-01 19:01:50 -07001168 // We haven't reached the token yet; if this token
1169 // is not going to the bottom and has windows, we can
1170 // use it as an anchor for when we do reach the token.
1171 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 pos = t.windows.get(0);
1173 }
1174 }
1175 // We now know the index into the apps. If we found
1176 // an app window above, that gives us the position; else
1177 // we need to look some more.
1178 if (pos != null) {
1179 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001180 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 if (atoken != null) {
1182 final int NC = atoken.windows.size();
1183 if (NC > 0) {
1184 WindowState bottom = atoken.windows.get(0);
1185 if (bottom.mSubLayer < 0) {
1186 pos = bottom;
1187 }
1188 }
1189 }
1190 placeWindowBefore(pos, win);
1191 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001192 // Continue looking down until we find the first
1193 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 while (i >= 0) {
1195 AppWindowToken t = mAppTokens.get(i);
1196 final int NW = t.windows.size();
1197 if (NW > 0) {
1198 pos = t.windows.get(NW-1);
1199 break;
1200 }
1201 i--;
1202 }
1203 if (pos != null) {
1204 // Move in front of any windows attached to this
1205 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001206 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 if (atoken != null) {
1208 final int NC = atoken.windows.size();
1209 if (NC > 0) {
1210 WindowState top = atoken.windows.get(NC-1);
1211 if (top.mSubLayer >= 0) {
1212 pos = top;
1213 }
1214 }
1215 }
1216 placeWindowAfter(pos, win);
1217 } else {
1218 // Just search for the start of this layer.
1219 final int myLayer = win.mBaseLayer;
1220 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001221 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 if (w.mBaseLayer > myLayer) {
1223 break;
1224 }
1225 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001226 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1227 Slog.v(TAG, "Adding window " + win + " at "
1228 + i + " of " + N);
1229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001231 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 }
1233 }
1234 }
1235 } else {
1236 // Figure out where window should go, based on layer.
1237 final int myLayer = win.mBaseLayer;
1238 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001239 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 i++;
1241 break;
1242 }
1243 }
1244 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001245 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001246 TAG, "Adding window " + win + " at "
1247 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001249 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 }
1251 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001252 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 token.windows.add(tokenWindowsPos, win);
1254 }
1255
1256 } else {
1257 // Figure out this window's ordering relative to the window
1258 // it is attached to.
1259 final int NA = token.windows.size();
1260 final int sublayer = win.mSubLayer;
1261 int largestSublayer = Integer.MIN_VALUE;
1262 WindowState windowWithLargestSublayer = null;
1263 for (i=0; i<NA; i++) {
1264 WindowState w = token.windows.get(i);
1265 final int wSublayer = w.mSubLayer;
1266 if (wSublayer >= largestSublayer) {
1267 largestSublayer = wSublayer;
1268 windowWithLargestSublayer = w;
1269 }
1270 if (sublayer < 0) {
1271 // For negative sublayers, we go below all windows
1272 // in the same sublayer.
1273 if (wSublayer >= sublayer) {
1274 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001275 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 token.windows.add(i, win);
1277 }
1278 placeWindowBefore(
1279 wSublayer >= 0 ? attached : w, win);
1280 break;
1281 }
1282 } else {
1283 // For positive sublayers, we go above all windows
1284 // in the same sublayer.
1285 if (wSublayer > sublayer) {
1286 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001287 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 token.windows.add(i, win);
1289 }
1290 placeWindowBefore(w, win);
1291 break;
1292 }
1293 }
1294 }
1295 if (i >= NA) {
1296 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001297 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 token.windows.add(win);
1299 }
1300 if (sublayer < 0) {
1301 placeWindowBefore(attached, win);
1302 } else {
1303 placeWindowAfter(largestSublayer >= 0
1304 ? windowWithLargestSublayer
1305 : attached,
1306 win);
1307 }
1308 }
1309 }
Romain Guy06882f82009-06-10 13:36:04 -07001310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 if (win.mAppToken != null && addToToken) {
1312 win.mAppToken.allAppWindows.add(win);
1313 }
1314 }
Romain Guy06882f82009-06-10 13:36:04 -07001315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 static boolean canBeImeTarget(WindowState w) {
1317 final int fl = w.mAttrs.flags
1318 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1319 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1320 return w.isVisibleOrAdding();
1321 }
1322 return false;
1323 }
Romain Guy06882f82009-06-10 13:36:04 -07001324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001326 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 final int N = localmWindows.size();
1328 WindowState w = null;
1329 int i = N;
1330 while (i > 0) {
1331 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001332 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001333
Joe Onorato8a9b2202010-02-26 18:56:32 -08001334 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 // + Integer.toHexString(w.mAttrs.flags));
1336 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001337 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 // Yet more tricksyness! If this window is a "starting"
1340 // window, we do actually want to be on top of it, but
1341 // it is not -really- where input will go. So if the caller
1342 // is not actually looking to move the IME, look down below
1343 // for a real window to target...
1344 if (!willMove
1345 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1346 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001347 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1349 i--;
1350 w = wb;
1351 }
1352 }
1353 break;
1354 }
1355 }
Romain Guy06882f82009-06-10 13:36:04 -07001356
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001357 // Now, a special case -- if the last target's window is in the
1358 // process of exiting, and is above the new target, keep on the
1359 // last target to avoid flicker. Consider for example a Dialog with
1360 // the IME shown: when the Dialog is dismissed, we want to keep
1361 // the IME above it until it is completely gone so it doesn't drop
1362 // behind the dialog or its full-screen scrim.
1363 if (mInputMethodTarget != null && w != null
1364 && mInputMethodTarget.isDisplayedLw()
1365 && mInputMethodTarget.mExiting) {
1366 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1367 w = mInputMethodTarget;
1368 i = localmWindows.indexOf(w);
1369 }
1370 }
Romain Guy06882f82009-06-10 13:36:04 -07001371
Joe Onorato8a9b2202010-02-26 18:56:32 -08001372 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 if (willMove && w != null) {
1376 final WindowState curTarget = mInputMethodTarget;
1377 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 // Now some fun for dealing with window animations that
1380 // modify the Z order. We need to look at all windows below
1381 // the current target that are in this app, finding the highest
1382 // visible one in layering.
1383 AppWindowToken token = curTarget.mAppToken;
1384 WindowState highestTarget = null;
1385 int highestPos = 0;
1386 if (token.animating || token.animation != null) {
1387 int pos = 0;
1388 pos = localmWindows.indexOf(curTarget);
1389 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001390 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 if (win.mAppToken != token) {
1392 break;
1393 }
1394 if (!win.mRemoved) {
1395 if (highestTarget == null || win.mAnimLayer >
1396 highestTarget.mAnimLayer) {
1397 highestTarget = win;
1398 highestPos = pos;
1399 }
1400 }
1401 pos--;
1402 }
1403 }
Romain Guy06882f82009-06-10 13:36:04 -07001404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001406 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 + mNextAppTransition + " " + highestTarget
1408 + " animating=" + highestTarget.isAnimating()
1409 + " layer=" + highestTarget.mAnimLayer
1410 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001411
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001412 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 // If we are currently setting up for an animation,
1414 // hold everything until we can find out what will happen.
1415 mInputMethodTargetWaitingAnim = true;
1416 mInputMethodTarget = highestTarget;
1417 return highestPos + 1;
1418 } else if (highestTarget.isAnimating() &&
1419 highestTarget.mAnimLayer > w.mAnimLayer) {
1420 // If the window we are currently targeting is involved
1421 // with an animation, and it is on top of the next target
1422 // we will be over, then hold off on moving until
1423 // that is done.
1424 mInputMethodTarget = highestTarget;
1425 return highestPos + 1;
1426 }
1427 }
1428 }
1429 }
Romain Guy06882f82009-06-10 13:36:04 -07001430
Joe Onorato8a9b2202010-02-26 18:56:32 -08001431 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 if (w != null) {
1433 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001434 if (DEBUG_INPUT_METHOD) {
1435 RuntimeException e = null;
1436 if (!HIDE_STACK_CRAWLS) {
1437 e = new RuntimeException();
1438 e.fillInStackTrace();
1439 }
1440 Slog.w(TAG, "Moving IM target from "
1441 + mInputMethodTarget + " to " + w, e);
1442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 mInputMethodTarget = w;
1444 if (w.mAppToken != null) {
1445 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1446 } else {
1447 setInputMethodAnimLayerAdjustment(0);
1448 }
1449 }
1450 return i+1;
1451 }
1452 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001453 if (DEBUG_INPUT_METHOD) {
1454 RuntimeException e = null;
1455 if (!HIDE_STACK_CRAWLS) {
1456 e = new RuntimeException();
1457 e.fillInStackTrace();
1458 }
1459 Slog.w(TAG, "Moving IM target from "
1460 + mInputMethodTarget + " to null", e);
1461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 mInputMethodTarget = null;
1463 setInputMethodAnimLayerAdjustment(0);
1464 }
1465 return -1;
1466 }
Romain Guy06882f82009-06-10 13:36:04 -07001467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 void addInputMethodWindowToListLocked(WindowState win) {
1469 int pos = findDesiredInputMethodWindowIndexLocked(true);
1470 if (pos >= 0) {
1471 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001472 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001473 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001475 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 moveInputMethodDialogsLocked(pos+1);
1477 return;
1478 }
1479 win.mTargetAppToken = null;
1480 addWindowToListInOrderLocked(win, true);
1481 moveInputMethodDialogsLocked(pos);
1482 }
Romain Guy06882f82009-06-10 13:36:04 -07001483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001485 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 mInputMethodAnimLayerAdjustment = adj;
1487 WindowState imw = mInputMethodWindow;
1488 if (imw != null) {
1489 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001490 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 + " anim layer: " + imw.mAnimLayer);
1492 int wi = imw.mChildWindows.size();
1493 while (wi > 0) {
1494 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001495 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 + " anim layer: " + cw.mAnimLayer);
1499 }
1500 }
1501 int di = mInputMethodDialogs.size();
1502 while (di > 0) {
1503 di --;
1504 imw = mInputMethodDialogs.get(di);
1505 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001506 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 + " anim layer: " + imw.mAnimLayer);
1508 }
1509 }
Romain Guy06882f82009-06-10 13:36:04 -07001510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1512 int wpos = mWindows.indexOf(win);
1513 if (wpos >= 0) {
1514 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001515 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001517 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 int NC = win.mChildWindows.size();
1519 while (NC > 0) {
1520 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001521 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 int cpos = mWindows.indexOf(cw);
1523 if (cpos >= 0) {
1524 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001525 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001526 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 mWindows.remove(cpos);
1528 }
1529 }
1530 }
1531 return interestingPos;
1532 }
Romain Guy06882f82009-06-10 13:36:04 -07001533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 private void reAddWindowToListInOrderLocked(WindowState win) {
1535 addWindowToListInOrderLocked(win, false);
1536 // This is a hack to get all of the child windows added as well
1537 // at the right position. Child windows should be rare and
1538 // this case should be rare, so it shouldn't be that big a deal.
1539 int wpos = mWindows.indexOf(win);
1540 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001541 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001542 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001544 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 reAddWindowLocked(wpos, win);
1546 }
1547 }
Romain Guy06882f82009-06-10 13:36:04 -07001548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 void logWindowList(String prefix) {
1550 int N = mWindows.size();
1551 while (N > 0) {
1552 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001553 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001554 }
1555 }
Romain Guy06882f82009-06-10 13:36:04 -07001556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 void moveInputMethodDialogsLocked(int pos) {
1558 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 for (int i=0; i<N; i++) {
1563 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1564 }
1565 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001566 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 logWindowList(" ");
1568 }
Romain Guy06882f82009-06-10 13:36:04 -07001569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 if (pos >= 0) {
1571 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1572 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001573 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 if (wp == mInputMethodWindow) {
1575 pos++;
1576 }
1577 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001578 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 for (int i=0; i<N; i++) {
1580 WindowState win = dialogs.get(i);
1581 win.mTargetAppToken = targetAppToken;
1582 pos = reAddWindowLocked(pos, win);
1583 }
1584 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001585 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 logWindowList(" ");
1587 }
1588 return;
1589 }
1590 for (int i=0; i<N; i++) {
1591 WindowState win = dialogs.get(i);
1592 win.mTargetAppToken = null;
1593 reAddWindowToListInOrderLocked(win);
1594 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001595 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 logWindowList(" ");
1597 }
1598 }
1599 }
Romain Guy06882f82009-06-10 13:36:04 -07001600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1602 final WindowState imWin = mInputMethodWindow;
1603 final int DN = mInputMethodDialogs.size();
1604 if (imWin == null && DN == 0) {
1605 return false;
1606 }
Romain Guy06882f82009-06-10 13:36:04 -07001607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1609 if (imPos >= 0) {
1610 // In this case, the input method windows are to be placed
1611 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 // First check to see if the input method windows are already
1614 // located here, and contiguous.
1615 final int N = mWindows.size();
1616 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001617 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 // Figure out the actual input method window that should be
1620 // at the bottom of their stack.
1621 WindowState baseImWin = imWin != null
1622 ? imWin : mInputMethodDialogs.get(0);
1623 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001624 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 if (cw.mSubLayer < 0) baseImWin = cw;
1626 }
Romain Guy06882f82009-06-10 13:36:04 -07001627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 if (firstImWin == baseImWin) {
1629 // The windows haven't moved... but are they still contiguous?
1630 // First find the top IM window.
1631 int pos = imPos+1;
1632 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001633 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 break;
1635 }
1636 pos++;
1637 }
1638 pos++;
1639 // Now there should be no more input method windows above.
1640 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001641 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 break;
1643 }
1644 pos++;
1645 }
1646 if (pos >= N) {
1647 // All is good!
1648 return false;
1649 }
1650 }
Romain Guy06882f82009-06-10 13:36:04 -07001651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 if (imWin != null) {
1653 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 logWindowList(" ");
1656 }
1657 imPos = tmpRemoveWindowLocked(imPos, imWin);
1658 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001659 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 logWindowList(" ");
1661 }
1662 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1663 reAddWindowLocked(imPos, imWin);
1664 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001665 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 logWindowList(" ");
1667 }
1668 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1669 } else {
1670 moveInputMethodDialogsLocked(imPos);
1671 }
Romain Guy06882f82009-06-10 13:36:04 -07001672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 } else {
1674 // In this case, the input method windows go in a fixed layer,
1675 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 tmpRemoveWindowLocked(0, imWin);
1680 imWin.mTargetAppToken = null;
1681 reAddWindowToListInOrderLocked(imWin);
1682 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001683 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 logWindowList(" ");
1685 }
1686 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1687 } else {
1688 moveInputMethodDialogsLocked(-1);;
1689 }
Romain Guy06882f82009-06-10 13:36:04 -07001690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 }
Romain Guy06882f82009-06-10 13:36:04 -07001692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 if (needAssignLayers) {
1694 assignLayersLocked();
1695 }
Romain Guy06882f82009-06-10 13:36:04 -07001696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 return true;
1698 }
Romain Guy06882f82009-06-10 13:36:04 -07001699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 void adjustInputMethodDialogsLocked() {
1701 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1702 }
Romain Guy06882f82009-06-10 13:36:04 -07001703
Dianne Hackborn25994b42009-09-04 14:21:19 -07001704 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001705 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001706 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1707 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1708 ? wallpaperTarget.mAppToken.animation : null)
1709 + " upper=" + mUpperWallpaperTarget
1710 + " lower=" + mLowerWallpaperTarget);
1711 return (wallpaperTarget != null
1712 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1713 && wallpaperTarget.mAppToken.animation != null)))
1714 || mUpperWallpaperTarget != null
1715 || mLowerWallpaperTarget != null;
1716 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001717
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001718 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1719 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001720
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001721 int adjustWallpaperWindowsLocked() {
1722 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001724 final int dw = mDisplay.getWidth();
1725 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001726
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001727 // First find top-most window that has asked to be on top of the
1728 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001729 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001730 int N = localmWindows.size();
1731 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001732 WindowState foundW = null;
1733 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001734 WindowState topCurW = null;
1735 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001736 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001737 int i = N;
1738 while (i > 0) {
1739 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001740 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001741 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1742 if (topCurW == null) {
1743 topCurW = w;
1744 topCurI = i;
1745 }
1746 continue;
1747 }
1748 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001749 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001750 // If this window's app token is hidden and not animating,
1751 // it is of no interest to us.
1752 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001753 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001754 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001755 continue;
1756 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001757 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001758 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001759 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1760 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001761 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001762 && (mWallpaperTarget == w
1763 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001764 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001765 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001766 foundW = w;
1767 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001768 if (w == mWallpaperTarget && ((w.mAppToken != null
1769 && w.mAppToken.animation != null)
1770 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001771 // The current wallpaper target is animating, so we'll
1772 // look behind it for another possible target and figure
1773 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001774 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001775 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001776 continue;
1777 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001778 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001779 } else if (w == mWindowDetachedWallpaper) {
1780 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001781 }
1782 }
1783
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001784 if (foundW == null && windowDetachedI >= 0) {
1785 if (DEBUG_WALLPAPER) Slog.v(TAG,
1786 "Found animating detached wallpaper activity: #" + i + "=" + w);
1787 foundW = w;
1788 foundI = windowDetachedI;
1789 }
1790
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001791 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001792 // If we are currently waiting for an app transition, and either
1793 // the current target or the next target are involved with it,
1794 // then hold off on doing anything with the wallpaper.
1795 // Note that we are checking here for just whether the target
1796 // is part of an app token... which is potentially overly aggressive
1797 // (the app token may not be involved in the transition), but good
1798 // enough (we'll just wait until whatever transition is pending
1799 // executes).
1800 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001801 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001802 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001803 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001804 }
1805 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001806 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001807 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001808 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001809 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001810 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001811
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001812 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001813 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001815 + " oldTarget: " + mWallpaperTarget);
1816 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001817
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 mLowerWallpaperTarget = null;
1819 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001820
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001821 WindowState oldW = mWallpaperTarget;
1822 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001823
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001824 // Now what is happening... if the current and new targets are
1825 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001826 if (foundW != null && oldW != null) {
1827 boolean oldAnim = oldW.mAnimation != null
1828 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1829 boolean foundAnim = foundW.mAnimation != null
1830 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001831 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001833 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001834 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001835 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001836 int oldI = localmWindows.indexOf(oldW);
1837 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001838 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001839 }
1840 if (oldI >= 0) {
1841 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001842 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001843 + "=" + oldW + "; new#" + foundI
1844 + "=" + foundW);
1845 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001846
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001847 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001848 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001849 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001850 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001851 }
1852 mWallpaperTarget = oldW;
1853 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001854
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001855 // Now set the upper and lower wallpaper targets
1856 // correctly, and make sure that we are positioning
1857 // the wallpaper below the lower.
1858 if (foundI > oldI) {
1859 // The new target is on top of the old one.
1860 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001861 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001862 }
1863 mUpperWallpaperTarget = foundW;
1864 mLowerWallpaperTarget = oldW;
1865 foundW = oldW;
1866 foundI = oldI;
1867 } else {
1868 // The new target is below the old one.
1869 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001870 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001871 }
1872 mUpperWallpaperTarget = oldW;
1873 mLowerWallpaperTarget = foundW;
1874 }
1875 }
1876 }
1877 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001878
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001879 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001880 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001881 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1882 || (mLowerWallpaperTarget.mAppToken != null
1883 && mLowerWallpaperTarget.mAppToken.animation != null);
1884 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1885 || (mUpperWallpaperTarget.mAppToken != null
1886 && mUpperWallpaperTarget.mAppToken.animation != null);
1887 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001888 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001889 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001890 }
1891 mLowerWallpaperTarget = null;
1892 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001893 }
1894 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001895
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001896 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001897 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001898 // The window is visible to the compositor... but is it visible
1899 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001900 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001901 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001902
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001903 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001904 // its layer adjustment. Only do this if we are not transfering
1905 // between two wallpaper targets.
1906 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001907 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001908 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001909
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001910 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1911 * TYPE_LAYER_MULTIPLIER
1912 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001913
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001914 // Now w is the window we are supposed to be behind... but we
1915 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001916 // AND any starting window associated with it, AND below the
1917 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001918 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001919 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001920 if (wb.mBaseLayer < maxLayer &&
1921 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001922 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001923 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001924 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001925 // This window is not related to the previous one in any
1926 // interesting way, so stop here.
1927 break;
1928 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001929 foundW = wb;
1930 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001931 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001932 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001933 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001934 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001935
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001936 if (foundW == null && topCurW != null) {
1937 // There is no wallpaper target, so it goes at the bottom.
1938 // We will assume it is the same place as last time, if known.
1939 foundW = topCurW;
1940 foundI = topCurI+1;
1941 } else {
1942 // Okay i is the position immediately above the wallpaper. Look at
1943 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001944 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001945 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001946
Dianne Hackborn284ac932009-08-28 10:34:25 -07001947 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001948 if (mWallpaperTarget.mWallpaperX >= 0) {
1949 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001950 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001951 }
1952 if (mWallpaperTarget.mWallpaperY >= 0) {
1953 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001954 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001955 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001957
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001958 // Start stepping backwards from here, ensuring that our wallpaper windows
1959 // are correctly placed.
1960 int curTokenIndex = mWallpaperTokens.size();
1961 while (curTokenIndex > 0) {
1962 curTokenIndex--;
1963 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001964 if (token.hidden == visible) {
1965 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1966 token.hidden = !visible;
1967 // Need to do a layout to ensure the wallpaper now has the
1968 // correct size.
1969 mLayoutNeeded = true;
1970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001971
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001972 int curWallpaperIndex = token.windows.size();
1973 while (curWallpaperIndex > 0) {
1974 curWallpaperIndex--;
1975 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001976
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001977 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001978 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001979 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001980
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001981 // First, make sure the client has the current visibility
1982 // state.
1983 if (wallpaper.mWallpaperVisible != visible) {
1984 wallpaper.mWallpaperVisible = visible;
1985 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001986 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001987 "Setting visibility of wallpaper " + wallpaper
1988 + ": " + visible);
1989 wallpaper.mClient.dispatchAppVisibility(visible);
1990 } catch (RemoteException e) {
1991 }
1992 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001993
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001994 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001995 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001996 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001997
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001998 // First, if this window is at the current index, then all
1999 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002000 if (wallpaper == foundW) {
2001 foundI--;
2002 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002003 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002004 continue;
2005 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002006
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002007 // The window didn't match... the current wallpaper window,
2008 // wherever it is, is in the wrong place, so make sure it is
2009 // not in the list.
2010 int oldIndex = localmWindows.indexOf(wallpaper);
2011 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002012 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002013 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002014 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002015 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002016 if (oldIndex < foundI) {
2017 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002018 }
2019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002021 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002022 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2023 Slog.v(TAG, "Moving wallpaper " + wallpaper
2024 + " from " + oldIndex + " to " + foundI);
2025 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002026
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002027 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002028 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002029 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002030 }
2031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002032
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002033 return changed;
2034 }
2035
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002036 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002037 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002038 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002039 mWallpaperAnimLayerAdjustment = adj;
2040 int curTokenIndex = mWallpaperTokens.size();
2041 while (curTokenIndex > 0) {
2042 curTokenIndex--;
2043 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2044 int curWallpaperIndex = token.windows.size();
2045 while (curWallpaperIndex > 0) {
2046 curWallpaperIndex--;
2047 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2048 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002049 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002050 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002051 }
2052 }
2053 }
2054
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002055 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2056 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002057 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002058 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002059 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002060 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002061 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2062 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2063 changed = wallpaperWin.mXOffset != offset;
2064 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002065 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002066 + wallpaperWin + " x: " + offset);
2067 wallpaperWin.mXOffset = offset;
2068 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002069 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002070 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002071 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002072 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002073 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002074
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002075 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002076 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002077 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2078 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2079 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002080 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002081 + wallpaperWin + " y: " + offset);
2082 changed = true;
2083 wallpaperWin.mYOffset = offset;
2084 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002085 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002086 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002087 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002089 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002090
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002091 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002092 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002093 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002094 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2095 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002096 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002097 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002098 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002099 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002100 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2101 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002102 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002103 if (mWaitingOnWallpaper != null) {
2104 long start = SystemClock.uptimeMillis();
2105 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2106 < start) {
2107 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002108 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002109 "Waiting for offset complete...");
2110 mWindowMap.wait(WALLPAPER_TIMEOUT);
2111 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002112 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002113 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002114 if ((start+WALLPAPER_TIMEOUT)
2115 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002116 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002117 + wallpaperWin);
2118 mLastWallpaperTimeoutTime = start;
2119 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002120 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002121 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002122 }
2123 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002124 } catch (RemoteException e) {
2125 }
2126 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002127
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002128 return changed;
2129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002130
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002131 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002132 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002133 if (mWaitingOnWallpaper != null &&
2134 mWaitingOnWallpaper.mClient.asBinder() == window) {
2135 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002136 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002137 }
2138 }
2139 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002140
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002141 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002142 final int dw = mDisplay.getWidth();
2143 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002144
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002145 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002146
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002147 WindowState target = mWallpaperTarget;
2148 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002149 if (target.mWallpaperX >= 0) {
2150 mLastWallpaperX = target.mWallpaperX;
2151 } else if (changingTarget.mWallpaperX >= 0) {
2152 mLastWallpaperX = changingTarget.mWallpaperX;
2153 }
2154 if (target.mWallpaperY >= 0) {
2155 mLastWallpaperY = target.mWallpaperY;
2156 } else if (changingTarget.mWallpaperY >= 0) {
2157 mLastWallpaperY = changingTarget.mWallpaperY;
2158 }
2159 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002160
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002161 int curTokenIndex = mWallpaperTokens.size();
2162 while (curTokenIndex > 0) {
2163 curTokenIndex--;
2164 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2165 int curWallpaperIndex = token.windows.size();
2166 while (curWallpaperIndex > 0) {
2167 curWallpaperIndex--;
2168 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2169 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2170 wallpaper.computeShownFrameLocked();
2171 changed = true;
2172 // We only want to be synchronous with one wallpaper.
2173 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002174 }
2175 }
2176 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002177
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002178 return changed;
2179 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002180
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002181 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002182 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002183 final int dw = mDisplay.getWidth();
2184 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002185
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002186 int curTokenIndex = mWallpaperTokens.size();
2187 while (curTokenIndex > 0) {
2188 curTokenIndex--;
2189 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002190 if (token.hidden == visible) {
2191 token.hidden = !visible;
2192 // Need to do a layout to ensure the wallpaper now has the
2193 // correct size.
2194 mLayoutNeeded = true;
2195 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002196
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002197 int curWallpaperIndex = token.windows.size();
2198 while (curWallpaperIndex > 0) {
2199 curWallpaperIndex--;
2200 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2201 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002202 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002203 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002204
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002205 if (wallpaper.mWallpaperVisible != visible) {
2206 wallpaper.mWallpaperVisible = visible;
2207 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002208 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002209 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002210 + ": " + visible);
2211 wallpaper.mClient.dispatchAppVisibility(visible);
2212 } catch (RemoteException e) {
2213 }
2214 }
2215 }
2216 }
2217 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 public int addWindow(Session session, IWindow client,
2220 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002221 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 int res = mPolicy.checkAddPermission(attrs);
2223 if (res != WindowManagerImpl.ADD_OKAY) {
2224 return res;
2225 }
Romain Guy06882f82009-06-10 13:36:04 -07002226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 boolean reportNewConfig = false;
2228 WindowState attachedWindow = null;
2229 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002230 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002234 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 }
Romain Guy06882f82009-06-10 13:36:04 -07002236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002238 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2240 }
2241
2242 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002243 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002245 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 + attrs.token + ". Aborting.");
2247 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2248 }
2249 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2250 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002251 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 + attrs.token + ". Aborting.");
2253 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2254 }
2255 }
2256
2257 boolean addToken = false;
2258 WindowToken token = mTokenMap.get(attrs.token);
2259 if (token == null) {
2260 if (attrs.type >= FIRST_APPLICATION_WINDOW
2261 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002262 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 + attrs.token + ". Aborting.");
2264 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2265 }
2266 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002267 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 + attrs.token + ". Aborting.");
2269 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2270 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002271 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002272 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002273 + attrs.token + ". Aborting.");
2274 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 token = new WindowToken(attrs.token, -1, false);
2277 addToken = true;
2278 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2279 && attrs.type <= LAST_APPLICATION_WINDOW) {
2280 AppWindowToken atoken = token.appWindowToken;
2281 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002282 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 + token + ". Aborting.");
2284 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2285 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002286 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 + token + ". Aborting.");
2288 return WindowManagerImpl.ADD_APP_EXITING;
2289 }
2290 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2291 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002292 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2294 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2295 }
2296 } else if (attrs.type == TYPE_INPUT_METHOD) {
2297 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002298 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 + attrs.token + ". Aborting.");
2300 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2301 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002302 } else if (attrs.type == TYPE_WALLPAPER) {
2303 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002304 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002305 + attrs.token + ". Aborting.");
2306 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 }
2309
2310 win = new WindowState(session, client, token,
2311 attachedWindow, attrs, viewVisibility);
2312 if (win.mDeathRecipient == null) {
2313 // Client has apparently died, so there is no reason to
2314 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002315 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 + " that is dead, aborting.");
2317 return WindowManagerImpl.ADD_APP_EXITING;
2318 }
2319
2320 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 res = mPolicy.prepareAddWindowLw(win, attrs);
2323 if (res != WindowManagerImpl.ADD_OKAY) {
2324 return res;
2325 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002326
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002327 if (outInputChannel != null) {
2328 String name = win.makeInputChannelName();
2329 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2330 win.mInputChannel = inputChannels[0];
2331 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2332
Jeff Brown928e0542011-01-10 11:17:36 -08002333 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335
2336 // From now on, no exceptions or errors allowed!
2337
2338 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002339
Dianne Hackborn5132b372010-07-29 12:51:35 -07002340 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 if (addToken) {
2343 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 }
2345 win.attach();
2346 mWindowMap.put(client.asBinder(), win);
2347
2348 if (attrs.type == TYPE_APPLICATION_STARTING &&
2349 token.appWindowToken != null) {
2350 token.appWindowToken.startingWindow = win;
2351 }
2352
2353 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (attrs.type == TYPE_INPUT_METHOD) {
2356 mInputMethodWindow = win;
2357 addInputMethodWindowToListLocked(win);
2358 imMayMove = false;
2359 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2360 mInputMethodDialogs.add(win);
2361 addWindowToListInOrderLocked(win, true);
2362 adjustInputMethodDialogsLocked();
2363 imMayMove = false;
2364 } else {
2365 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002366 if (attrs.type == TYPE_WALLPAPER) {
2367 mLastWallpaperTimeoutTime = 0;
2368 adjustWallpaperWindowsLocked();
2369 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002370 adjustWallpaperWindowsLocked();
2371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 }
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 if (mInTouchMode) {
2379 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2380 }
2381 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2382 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2383 }
Romain Guy06882f82009-06-10 13:36:04 -07002384
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002385 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002387 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2388 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002389 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 imMayMove = false;
2391 }
2392 }
Romain Guy06882f82009-06-10 13:36:04 -07002393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002395 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 }
Romain Guy06882f82009-06-10 13:36:04 -07002397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 assignLayersLocked();
2399 // Don't do layout here, the window must call
2400 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 //dump();
2403
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002404 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002405 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002406 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002407 mInputMonitor.updateInputWindowsLw();
2408
Joe Onorato8a9b2202010-02-26 18:56:32 -08002409 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 TAG, "New client " + client.asBinder()
2411 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002412
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002413 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002414 reportNewConfig = true;
2415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 }
2417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 if (reportNewConfig) {
2419 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 return res;
2425 }
Romain Guy06882f82009-06-10 13:36:04 -07002426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 public void removeWindow(Session session, IWindow client) {
2428 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002429 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 if (win == null) {
2431 return;
2432 }
2433 removeWindowLocked(session, win);
2434 }
2435 }
Romain Guy06882f82009-06-10 13:36:04 -07002436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 public void removeWindowLocked(Session session, WindowState win) {
2438
Joe Onorato8a9b2202010-02-26 18:56:32 -08002439 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 TAG, "Remove " + win + " client="
2441 + Integer.toHexString(System.identityHashCode(
2442 win.mClient.asBinder()))
2443 + ", surface=" + win.mSurface);
2444
2445 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002446
2447 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002448
Joe Onorato8a9b2202010-02-26 18:56:32 -08002449 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2451 + " mExiting=" + win.mExiting
2452 + " isAnimating=" + win.isAnimating()
2453 + " app-animation="
2454 + (win.mAppToken != null ? win.mAppToken.animation : null)
2455 + " inPendingTransaction="
2456 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2457 + " mDisplayFrozen=" + mDisplayFrozen);
2458 // Visibility of the removed window. Will be used later to update orientation later on.
2459 boolean wasVisible = false;
2460 // First, see if we need to run an animation. If we do, we have
2461 // to hold off on removing the window until the animation is done.
2462 // If the display is frozen, just remove immediately, since the
2463 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002464 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 // If we are not currently running the exit animation, we
2466 // need to see about starting one.
2467 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2470 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2471 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2472 }
2473 // Try starting an animation.
2474 if (applyAnimationLocked(win, transit, false)) {
2475 win.mExiting = true;
2476 }
2477 }
2478 if (win.mExiting || win.isAnimating()) {
2479 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002480 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 win.mExiting = true;
2482 win.mRemoveOnExit = true;
2483 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002484 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2485 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08002487 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 if (win.mAppToken != null) {
2489 win.mAppToken.updateReportedVisibilityLocked();
2490 }
2491 //dump();
2492 Binder.restoreCallingIdentity(origId);
2493 return;
2494 }
2495 }
2496
2497 removeWindowInnerLocked(session, win);
2498 // Removing a visible window will effect the computed orientation
2499 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002500 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002501 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002502 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002503 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002505 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 Binder.restoreCallingIdentity(origId);
2507 }
Romain Guy06882f82009-06-10 13:36:04 -07002508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002510 if (win.mRemoved) {
2511 // Nothing to do.
2512 return;
2513 }
2514
2515 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2516 WindowState cwin = win.mChildWindows.get(i);
2517 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2518 + win);
2519 removeWindowInnerLocked(cwin.mSession, cwin);
2520 }
2521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 if (mInputMethodTarget == win) {
2525 moveInputMethodWindowsIfNeededLocked(false);
2526 }
Romain Guy06882f82009-06-10 13:36:04 -07002527
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002528 if (false) {
2529 RuntimeException e = new RuntimeException("here");
2530 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002531 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002532 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 mPolicy.removeWindowLw(win);
2535 win.removeLocked();
2536
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002537 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 mWindowMap.remove(win.mClient.asBinder());
2539 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002540 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002541 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002542 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543
2544 if (mInputMethodWindow == win) {
2545 mInputMethodWindow = null;
2546 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2547 mInputMethodDialogs.remove(win);
2548 }
Romain Guy06882f82009-06-10 13:36:04 -07002549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 final WindowToken token = win.mToken;
2551 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002552 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 token.windows.remove(win);
2554 if (atoken != null) {
2555 atoken.allAppWindows.remove(win);
2556 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002557 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 TAG, "**** Removing window " + win + ": count="
2559 + token.windows.size());
2560 if (token.windows.size() == 0) {
2561 if (!token.explicit) {
2562 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 } else if (atoken != null) {
2564 atoken.firstWindowDrawn = false;
2565 }
2566 }
2567
2568 if (atoken != null) {
2569 if (atoken.startingWindow == win) {
2570 atoken.startingWindow = null;
2571 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2572 // If this is the last window and we had requested a starting
2573 // transition window, well there is no point now.
2574 atoken.startingData = null;
2575 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2576 // If this is the last window except for a starting transition
2577 // window, we need to get rid of the starting transition.
2578 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002579 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 + ": no more real windows");
2581 }
2582 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2583 mH.sendMessage(m);
2584 }
2585 }
Romain Guy06882f82009-06-10 13:36:04 -07002586
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002587 if (win.mAttrs.type == TYPE_WALLPAPER) {
2588 mLastWallpaperTimeoutTime = 0;
2589 adjustWallpaperWindowsLocked();
2590 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002591 adjustWallpaperWindowsLocked();
2592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 if (!mInLayout) {
2595 assignLayersLocked();
2596 mLayoutNeeded = true;
2597 performLayoutAndPlaceSurfacesLocked();
2598 if (win.mAppToken != null) {
2599 win.mAppToken.updateReportedVisibilityLocked();
2600 }
2601 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002602
Jeff Brown3a22cd92011-01-21 13:59:04 -08002603 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002604 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 }
2606
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002607 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2608 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2609 + ": " + msg + " / " + w.mAttrs.getTitle();
2610 if (where != null) {
2611 Slog.i(TAG, str, where);
2612 } else {
2613 Slog.i(TAG, str);
2614 }
2615 }
2616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2618 long origId = Binder.clearCallingIdentity();
2619 try {
2620 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002621 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002623 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2624 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 Surface.openTransaction();
2626 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002627 if (SHOW_TRANSACTIONS) logSurface(w,
2628 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 w.mSurface.setTransparentRegionHint(region);
2630 } finally {
2631 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002632 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2633 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 }
2635 }
2636 }
2637 } finally {
2638 Binder.restoreCallingIdentity(origId);
2639 }
2640 }
2641
2642 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002643 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002644 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 long origId = Binder.clearCallingIdentity();
2646 try {
2647 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002648 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 if (w != null) {
2650 w.mGivenInsetsPending = false;
2651 w.mGivenContentInsets.set(contentInsets);
2652 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002653 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 w.mTouchableInsets = touchableInsets;
2655 mLayoutNeeded = true;
2656 performLayoutAndPlaceSurfacesLocked();
2657 }
2658 }
2659 } finally {
2660 Binder.restoreCallingIdentity(origId);
2661 }
2662 }
Romain Guy06882f82009-06-10 13:36:04 -07002663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 public void getWindowDisplayFrame(Session session, IWindow client,
2665 Rect outDisplayFrame) {
2666 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002667 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 if (win == null) {
2669 outDisplayFrame.setEmpty();
2670 return;
2671 }
2672 outDisplayFrame.set(win.mDisplayFrame);
2673 }
2674 }
2675
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002676 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2677 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002678 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2679 window.mWallpaperX = x;
2680 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002681 window.mWallpaperXStep = xStep;
2682 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002683 if (updateWallpaperOffsetLocked(window, true)) {
2684 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002685 }
2686 }
2687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002688
Dianne Hackborn75804932009-10-20 20:15:20 -07002689 void wallpaperCommandComplete(IBinder window, Bundle result) {
2690 synchronized (mWindowMap) {
2691 if (mWaitingOnWallpaper != null &&
2692 mWaitingOnWallpaper.mClient.asBinder() == window) {
2693 mWaitingOnWallpaper = null;
2694 mWindowMap.notifyAll();
2695 }
2696 }
2697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002698
Dianne Hackborn75804932009-10-20 20:15:20 -07002699 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2700 String action, int x, int y, int z, Bundle extras, boolean sync) {
2701 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2702 || window == mUpperWallpaperTarget) {
2703 boolean doWait = sync;
2704 int curTokenIndex = mWallpaperTokens.size();
2705 while (curTokenIndex > 0) {
2706 curTokenIndex--;
2707 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2708 int curWallpaperIndex = token.windows.size();
2709 while (curWallpaperIndex > 0) {
2710 curWallpaperIndex--;
2711 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2712 try {
2713 wallpaper.mClient.dispatchWallpaperCommand(action,
2714 x, y, z, extras, sync);
2715 // We only want to be synchronous with one wallpaper.
2716 sync = false;
2717 } catch (RemoteException e) {
2718 }
2719 }
2720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002721
Dianne Hackborn75804932009-10-20 20:15:20 -07002722 if (doWait) {
2723 // XXX Need to wait for result.
2724 }
2725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002726
Dianne Hackborn75804932009-10-20 20:15:20 -07002727 return null;
2728 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 public int relayoutWindow(Session session, IWindow client,
2731 WindowManager.LayoutParams attrs, int requestedWidth,
2732 int requestedHeight, int viewVisibility, boolean insetsPending,
2733 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002734 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 boolean displayed = false;
2736 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002737 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002741 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 if (win == null) {
2743 return 0;
2744 }
2745 win.mRequestedWidth = requestedWidth;
2746 win.mRequestedHeight = requestedHeight;
2747
2748 if (attrs != null) {
2749 mPolicy.adjustWindowParamsLw(attrs);
2750 }
Romain Guy06882f82009-06-10 13:36:04 -07002751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 int attrChanges = 0;
2753 int flagChanges = 0;
2754 if (attrs != null) {
2755 flagChanges = win.mAttrs.flags ^= attrs.flags;
2756 attrChanges = win.mAttrs.copyFrom(attrs);
2757 }
2758
Joe Onorato8a9b2202010-02-26 18:56:32 -08002759 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760
2761 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2762 win.mAlpha = attrs.alpha;
2763 }
2764
2765 final boolean scaledWindow =
2766 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2767
2768 if (scaledWindow) {
2769 // requested{Width|Height} Surface's physical size
2770 // attrs.{width|height} Size on screen
2771 win.mHScale = (attrs.width != requestedWidth) ?
2772 (attrs.width / (float)requestedWidth) : 1.0f;
2773 win.mVScale = (attrs.height != requestedHeight) ?
2774 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002775 } else {
2776 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 }
2778
2779 boolean imMayMove = (flagChanges&(
2780 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2781 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 boolean focusMayChange = win.mViewVisibility != viewVisibility
2784 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2785 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002786
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002787 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2788 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 win.mRelayoutCalled = true;
2791 final int oldVisibility = win.mViewVisibility;
2792 win.mViewVisibility = viewVisibility;
2793 if (viewVisibility == View.VISIBLE &&
2794 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2795 displayed = !win.isVisibleLw();
2796 if (win.mExiting) {
2797 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002798 if (win.mAnimation != null) {
2799 win.mAnimation.cancel();
2800 win.mAnimation = null;
2801 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 }
2803 if (win.mDestroying) {
2804 win.mDestroying = false;
2805 mDestroySurface.remove(win);
2806 }
2807 if (oldVisibility == View.GONE) {
2808 win.mEnterAnimationPending = true;
2809 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002810 if (displayed) {
2811 if (win.mSurface != null && !win.mDrawPending
2812 && !win.mCommitDrawPending && !mDisplayFrozen
2813 && mPolicy.isScreenOn()) {
2814 applyEnterAnimationLocked(win);
2815 }
2816 if ((win.mAttrs.flags
2817 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2818 if (DEBUG_VISIBILITY) Slog.v(TAG,
2819 "Relayout window turning screen on: " + win);
2820 win.mTurnOnScreen = true;
2821 }
2822 int diff = 0;
2823 if (win.mConfiguration != mCurConfiguration
2824 && (win.mConfiguration == null
2825 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2826 win.mConfiguration = mCurConfiguration;
2827 if (DEBUG_CONFIGURATION) {
2828 Slog.i(TAG, "Window " + win + " visible with new config: "
2829 + win.mConfiguration + " / 0x"
2830 + Integer.toHexString(diff));
2831 }
2832 outConfig.setTo(mCurConfiguration);
2833 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2836 // To change the format, we need to re-build the surface.
2837 win.destroySurfaceLocked();
2838 displayed = true;
2839 }
2840 try {
2841 Surface surface = win.createSurfaceLocked();
2842 if (surface != null) {
2843 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002844 win.mReportDestroySurface = false;
2845 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002846 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002847 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002849 // For some reason there isn't a surface. Clear the
2850 // caller's object so they see the same state.
2851 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 }
2853 } catch (Exception e) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002854 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Browne33348b2010-07-15 23:54:05 -07002855 mInputMonitor.updateInputWindowsLw();
2856
Joe Onorato8a9b2202010-02-26 18:56:32 -08002857 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002858 + client + " (" + win.mAttrs.getTitle() + ")",
2859 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 Binder.restoreCallingIdentity(origId);
2861 return 0;
2862 }
2863 if (displayed) {
2864 focusMayChange = true;
2865 }
2866 if (win.mAttrs.type == TYPE_INPUT_METHOD
2867 && mInputMethodWindow == null) {
2868 mInputMethodWindow = win;
2869 imMayMove = true;
2870 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002871 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2872 && win.mAppToken != null
2873 && win.mAppToken.startingWindow != null) {
2874 // Special handling of starting window over the base
2875 // window of the app: propagate lock screen flags to it,
2876 // to provide the correct semantics while starting.
2877 final int mask =
2878 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002879 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2880 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002881 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2882 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 } else {
2885 win.mEnterAnimationPending = false;
2886 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002887 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002888 + ": mExiting=" + win.mExiting
2889 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 // If we are not currently running the exit animation, we
2891 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002892 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 // Try starting an animation; if there isn't one, we
2894 // can destroy the surface right away.
2895 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2896 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2897 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2898 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002899 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002901 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 } else if (win.isAnimating()) {
2904 // Currently in a hide animation... turn this into
2905 // an exit.
2906 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002907 } else if (win == mWallpaperTarget) {
2908 // If the wallpaper is currently behind this
2909 // window, we need to change both of them inside
2910 // of a transaction to avoid artifacts.
2911 win.mExiting = true;
2912 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 } else {
2914 if (mInputMethodWindow == win) {
2915 mInputMethodWindow = null;
2916 }
2917 win.destroySurfaceLocked();
2918 }
2919 }
2920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002921
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002922 if (win.mSurface == null || (win.getAttrs().flags
2923 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2924 || win.mSurfacePendingDestroy) {
2925 // We are being called from a local process, which
2926 // means outSurface holds its current surface. Ensure the
2927 // surface object is cleared, but we don't want it actually
2928 // destroyed at this point.
2929 win.mSurfacePendingDestroy = false;
2930 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002931 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002932 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002933 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002934 "Keeping surface, will report destroy: " + win);
2935 win.mReportDestroySurface = true;
2936 outSurface.copyFrom(win.mSurface);
2937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 }
2939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 if (focusMayChange) {
2941 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002942 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2943 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 imMayMove = false;
2945 }
2946 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2947 }
Romain Guy06882f82009-06-10 13:36:04 -07002948
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002949 // updateFocusedWindowLocked() already assigned layers so we only need to
2950 // reassign them at this point if the IM window state gets shuffled
2951 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002954 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2955 // Little hack here -- we -should- be able to rely on the
2956 // function to return true if the IME has moved and needs
2957 // its layer recomputed. However, if the IME was hidden
2958 // and isn't actually moved in the list, its layer may be
2959 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 assignLayers = true;
2961 }
2962 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002963 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002964 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002965 assignLayers = true;
2966 }
2967 }
Romain Guy06882f82009-06-10 13:36:04 -07002968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 mLayoutNeeded = true;
2970 win.mGivenInsetsPending = insetsPending;
2971 if (assignLayers) {
2972 assignLayersLocked();
2973 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002974 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002976 if (displayed && win.mIsWallpaper) {
2977 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002978 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 if (win.mAppToken != null) {
2981 win.mAppToken.updateReportedVisibilityLocked();
2982 }
2983 outFrame.set(win.mFrame);
2984 outContentInsets.set(win.mContentInsets);
2985 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002986 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002988 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 + ", requestedHeight=" + requestedHeight
2990 + ", viewVisibility=" + viewVisibility
2991 + "\nRelayout returning frame=" + outFrame
2992 + ", surface=" + outSurface);
2993
Joe Onorato8a9b2202010-02-26 18:56:32 -08002994 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2996
2997 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002998
Jeff Brown3a22cd92011-01-21 13:59:04 -08002999 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Browne33348b2010-07-15 23:54:05 -07003000 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 }
3002
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003003 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 sendNewConfiguration();
3005 }
Romain Guy06882f82009-06-10 13:36:04 -07003006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3010 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3011 }
3012
3013 public void finishDrawingWindow(Session session, IWindow client) {
3014 final long origId = Binder.clearCallingIdentity();
3015 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003016 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003017 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003018 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3019 adjustWallpaperWindowsLocked();
3020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 mLayoutNeeded = true;
3022 performLayoutAndPlaceSurfacesLocked();
3023 }
3024 }
3025 Binder.restoreCallingIdentity(origId);
3026 }
3027
3028 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003029 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 + (lp != null ? lp.packageName : null)
3031 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3032 if (lp != null && lp.windowAnimations != 0) {
3033 // If this is a system resource, don't try to load it from the
3034 // application resources. It is nice to avoid loading application
3035 // resources if we can.
3036 String packageName = lp.packageName != null ? lp.packageName : "android";
3037 int resId = lp.windowAnimations;
3038 if ((resId&0xFF000000) == 0x01000000) {
3039 packageName = "android";
3040 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003041 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 + packageName);
3043 return AttributeCache.instance().get(packageName, resId,
3044 com.android.internal.R.styleable.WindowAnimation);
3045 }
3046 return null;
3047 }
Romain Guy06882f82009-06-10 13:36:04 -07003048
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003049 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003050 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003051 + packageName + " resId=0x" + Integer.toHexString(resId));
3052 if (packageName != null) {
3053 if ((resId&0xFF000000) == 0x01000000) {
3054 packageName = "android";
3055 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003056 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003057 + packageName);
3058 return AttributeCache.instance().get(packageName, resId,
3059 com.android.internal.R.styleable.WindowAnimation);
3060 }
3061 return null;
3062 }
3063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 private void applyEnterAnimationLocked(WindowState win) {
3065 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3066 if (win.mEnterAnimationPending) {
3067 win.mEnterAnimationPending = false;
3068 transit = WindowManagerPolicy.TRANSIT_ENTER;
3069 }
3070
3071 applyAnimationLocked(win, transit, true);
3072 }
3073
3074 private boolean applyAnimationLocked(WindowState win,
3075 int transit, boolean isEntrance) {
3076 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3077 // If we are trying to apply an animation, but already running
3078 // an animation of the same type, then just leave that one alone.
3079 return true;
3080 }
Romain Guy06882f82009-06-10 13:36:04 -07003081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 // Only apply an animation if the display isn't frozen. If it is
3083 // frozen, there is no reason to animate and it can cause strange
3084 // artifacts when we unfreeze the display if some different animation
3085 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003086 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 int anim = mPolicy.selectAnimationLw(win, transit);
3088 int attr = -1;
3089 Animation a = null;
3090 if (anim != 0) {
3091 a = AnimationUtils.loadAnimation(mContext, anim);
3092 } else {
3093 switch (transit) {
3094 case WindowManagerPolicy.TRANSIT_ENTER:
3095 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3096 break;
3097 case WindowManagerPolicy.TRANSIT_EXIT:
3098 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3099 break;
3100 case WindowManagerPolicy.TRANSIT_SHOW:
3101 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3102 break;
3103 case WindowManagerPolicy.TRANSIT_HIDE:
3104 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3105 break;
3106 }
3107 if (attr >= 0) {
3108 a = loadAnimation(win.mAttrs, attr);
3109 }
3110 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003111 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3113 + " mAnimation=" + win.mAnimation
3114 + " isEntrance=" + isEntrance);
3115 if (a != null) {
3116 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003117 RuntimeException e = null;
3118 if (!HIDE_STACK_CRAWLS) {
3119 e = new RuntimeException();
3120 e.fillInStackTrace();
3121 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003122 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 }
3124 win.setAnimation(a);
3125 win.mAnimationIsEntrance = isEntrance;
3126 }
3127 } else {
3128 win.clearAnimation();
3129 }
3130
3131 return win.mAnimation != null;
3132 }
3133
3134 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3135 int anim = 0;
3136 Context context = mContext;
3137 if (animAttr >= 0) {
3138 AttributeCache.Entry ent = getCachedAnimations(lp);
3139 if (ent != null) {
3140 context = ent.context;
3141 anim = ent.array.getResourceId(animAttr, 0);
3142 }
3143 }
3144 if (anim != 0) {
3145 return AnimationUtils.loadAnimation(context, anim);
3146 }
3147 return null;
3148 }
Romain Guy06882f82009-06-10 13:36:04 -07003149
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003150 private Animation loadAnimation(String packageName, int resId) {
3151 int anim = 0;
3152 Context context = mContext;
3153 if (resId >= 0) {
3154 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3155 if (ent != null) {
3156 context = ent.context;
3157 anim = resId;
3158 }
3159 }
3160 if (anim != 0) {
3161 return AnimationUtils.loadAnimation(context, anim);
3162 }
3163 return null;
3164 }
3165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 private boolean applyAnimationLocked(AppWindowToken wtoken,
3167 WindowManager.LayoutParams lp, int transit, boolean enter) {
3168 // Only apply an animation if the display isn't frozen. If it is
3169 // frozen, there is no reason to animate and it can cause strange
3170 // artifacts when we unfreeze the display if some different animation
3171 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003172 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003173 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003174 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003175 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003176 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003177 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003178 } else if (mNextAppTransitionPackage != null) {
3179 a = loadAnimation(mNextAppTransitionPackage, enter ?
3180 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003181 } else {
3182 int animAttr = 0;
3183 switch (transit) {
3184 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3185 animAttr = enter
3186 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3187 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3188 break;
3189 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3190 animAttr = enter
3191 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3192 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3193 break;
3194 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3195 animAttr = enter
3196 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3197 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3198 break;
3199 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3200 animAttr = enter
3201 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3202 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3203 break;
3204 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3205 animAttr = enter
3206 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3207 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3208 break;
3209 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3210 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003211 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003212 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3213 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003214 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003215 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003216 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3217 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003218 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003219 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003220 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003221 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3222 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3223 break;
3224 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3225 animAttr = enter
3226 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3227 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3228 break;
3229 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3230 animAttr = enter
3231 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3232 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003233 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003234 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003235 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003236 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003237 + " anim=" + a
3238 + " animAttr=0x" + Integer.toHexString(animAttr)
3239 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003240 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003241 if (a != null) {
3242 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003243 RuntimeException e = null;
3244 if (!HIDE_STACK_CRAWLS) {
3245 e = new RuntimeException();
3246 e.fillInStackTrace();
3247 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003248 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 }
3250 wtoken.setAnimation(a);
3251 }
3252 } else {
3253 wtoken.clearAnimation();
3254 }
3255
3256 return wtoken.animation != null;
3257 }
3258
3259 // -------------------------------------------------------------
3260 // Application Window Tokens
3261 // -------------------------------------------------------------
3262
3263 public void validateAppTokens(List tokens) {
3264 int v = tokens.size()-1;
3265 int m = mAppTokens.size()-1;
3266 while (v >= 0 && m >= 0) {
3267 AppWindowToken wtoken = mAppTokens.get(m);
3268 if (wtoken.removed) {
3269 m--;
3270 continue;
3271 }
3272 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003273 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3275 }
3276 v--;
3277 m--;
3278 }
3279 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003280 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 v--;
3282 }
3283 while (m >= 0) {
3284 AppWindowToken wtoken = mAppTokens.get(m);
3285 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003286 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003287 }
3288 m--;
3289 }
3290 }
3291
3292 boolean checkCallingPermission(String permission, String func) {
3293 // Quick check: if the calling permission is me, it's all okay.
3294 if (Binder.getCallingPid() == Process.myPid()) {
3295 return true;
3296 }
Romain Guy06882f82009-06-10 13:36:04 -07003297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 if (mContext.checkCallingPermission(permission)
3299 == PackageManager.PERMISSION_GRANTED) {
3300 return true;
3301 }
3302 String msg = "Permission Denial: " + func + " from pid="
3303 + Binder.getCallingPid()
3304 + ", uid=" + Binder.getCallingUid()
3305 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003306 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 return false;
3308 }
Romain Guy06882f82009-06-10 13:36:04 -07003309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310 AppWindowToken findAppWindowToken(IBinder token) {
3311 WindowToken wtoken = mTokenMap.get(token);
3312 if (wtoken == null) {
3313 return null;
3314 }
3315 return wtoken.appWindowToken;
3316 }
Romain Guy06882f82009-06-10 13:36:04 -07003317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 public void addWindowToken(IBinder token, int type) {
3319 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3320 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003321 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 }
Romain Guy06882f82009-06-10 13:36:04 -07003323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 synchronized(mWindowMap) {
3325 WindowToken wtoken = mTokenMap.get(token);
3326 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003327 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 return;
3329 }
3330 wtoken = new WindowToken(token, type, true);
3331 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003332 if (type == TYPE_WALLPAPER) {
3333 mWallpaperTokens.add(wtoken);
3334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 }
3336 }
Romain Guy06882f82009-06-10 13:36:04 -07003337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 public void removeWindowToken(IBinder token) {
3339 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3340 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003341 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 }
3343
3344 final long origId = Binder.clearCallingIdentity();
3345 synchronized(mWindowMap) {
3346 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 if (wtoken != null) {
3348 boolean delayed = false;
3349 if (!wtoken.hidden) {
3350 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 final int N = wtoken.windows.size();
3353 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 for (int i=0; i<N; i++) {
3356 WindowState win = wtoken.windows.get(i);
3357
3358 if (win.isAnimating()) {
3359 delayed = true;
3360 }
Romain Guy06882f82009-06-10 13:36:04 -07003361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 if (win.isVisibleNow()) {
3363 applyAnimationLocked(win,
3364 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 changed = true;
3366 }
3367 }
3368
3369 if (changed) {
3370 mLayoutNeeded = true;
3371 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003372 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3373 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 }
Romain Guy06882f82009-06-10 13:36:04 -07003375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 if (delayed) {
3377 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003378 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3379 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 }
3381 }
Romain Guy06882f82009-06-10 13:36:04 -07003382
Jeff Brown3a22cd92011-01-21 13:59:04 -08003383 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brownc5ed5912010-07-14 18:48:53 -07003384 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003386 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 }
3388 }
3389 Binder.restoreCallingIdentity(origId);
3390 }
3391
3392 public void addAppToken(int addPos, IApplicationToken token,
3393 int groupId, int requestedOrientation, boolean fullscreen) {
3394 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3395 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003396 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 }
Jeff Brown349703e2010-06-22 01:27:15 -07003398
3399 // Get the dispatching timeout here while we are not holding any locks so that it
3400 // can be cached by the AppWindowToken. The timeout value is used later by the
3401 // input dispatcher in code that does hold locks. If we did not cache the value
3402 // here we would run the chance of introducing a deadlock between the window manager
3403 // (which holds locks while updating the input dispatcher state) and the activity manager
3404 // (which holds locks while querying the application token).
3405 long inputDispatchingTimeoutNanos;
3406 try {
3407 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3408 } catch (RemoteException ex) {
3409 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3410 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3411 }
Romain Guy06882f82009-06-10 13:36:04 -07003412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 synchronized(mWindowMap) {
3414 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3415 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003416 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 return;
3418 }
3419 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003420 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 wtoken.groupId = groupId;
3422 wtoken.appFullscreen = fullscreen;
3423 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003424 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 // Application tokens start out hidden.
3429 wtoken.hidden = true;
3430 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003432 //dump();
3433 }
3434 }
Romain Guy06882f82009-06-10 13:36:04 -07003435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 public void setAppGroupId(IBinder token, int groupId) {
3437 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3438 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003439 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 }
3441
3442 synchronized(mWindowMap) {
3443 AppWindowToken wtoken = findAppWindowToken(token);
3444 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003445 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 return;
3447 }
3448 wtoken.groupId = groupId;
3449 }
3450 }
Romain Guy06882f82009-06-10 13:36:04 -07003451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452 public int getOrientationFromWindowsLocked() {
3453 int pos = mWindows.size() - 1;
3454 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003455 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 pos--;
3457 if (wtoken.mAppToken != null) {
3458 // We hit an application window. so the orientation will be determined by the
3459 // app window. No point in continuing further.
3460 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3461 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003462 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 continue;
3464 }
3465 int req = wtoken.mAttrs.screenOrientation;
3466 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3467 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3468 continue;
3469 } else {
3470 return req;
3471 }
3472 }
3473 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3474 }
Romain Guy06882f82009-06-10 13:36:04 -07003475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003477 int pos = mAppTokens.size() - 1;
3478 int curGroup = 0;
3479 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3480 boolean findingBehind = false;
3481 boolean haveGroup = false;
3482 boolean lastFullscreen = false;
3483 while (pos >= 0) {
3484 AppWindowToken wtoken = mAppTokens.get(pos);
3485 pos--;
3486 // if we're about to tear down this window and not seek for
3487 // the behind activity, don't use it for orientation
3488 if (!findingBehind
3489 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3490 continue;
3491 }
3492
3493 if (!haveGroup) {
3494 // We ignore any hidden applications on the top.
3495 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003496 continue;
3497 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003498 haveGroup = true;
3499 curGroup = wtoken.groupId;
3500 lastOrientation = wtoken.requestedOrientation;
3501 } else if (curGroup != wtoken.groupId) {
3502 // If we have hit a new application group, and the bottom
3503 // of the previous group didn't explicitly say to use
3504 // the orientation behind it, and the last app was
3505 // full screen, then we'll stick with the
3506 // user's orientation.
3507 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3508 && lastFullscreen) {
3509 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003512 int or = wtoken.requestedOrientation;
3513 // If this application is fullscreen, and didn't explicitly say
3514 // to use the orientation behind it, then just take whatever
3515 // orientation it has and ignores whatever is under it.
3516 lastFullscreen = wtoken.appFullscreen;
3517 if (lastFullscreen
3518 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3519 return or;
3520 }
3521 // If this application has requested an explicit orientation,
3522 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003523 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3524 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003525 return or;
3526 }
3527 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3528 }
3529 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 }
Romain Guy06882f82009-06-10 13:36:04 -07003531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003533 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003534 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3535 "updateOrientationFromAppTokens()")) {
3536 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3537 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003538
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003539 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003541
3542 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003543 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003544 if (freezeThisOneIfNeeded != null) {
3545 AppWindowToken wtoken = findAppWindowToken(
3546 freezeThisOneIfNeeded);
3547 if (wtoken != null) {
3548 startAppFreezingScreenLocked(wtoken,
3549 ActivityInfo.CONFIG_ORIENTATION);
3550 }
3551 }
3552 config = computeNewConfigurationLocked();
3553
3554 } else if (currentConfig != null) {
3555 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003556 // state mismatches the activity manager's, update it,
3557 // disregarding font scale, which should remain set to
3558 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003560 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003561 if (computeNewConfigurationLocked(mTempConfiguration)) {
3562 if (currentConfig.diff(mTempConfiguration) != 0) {
3563 mWaitingForConfig = true;
3564 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003565 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003566 config = new Configuration(mTempConfiguration);
3567 }
3568 }
3569 }
3570 }
3571
Dianne Hackborncfaef692009-06-15 14:24:44 -07003572 Binder.restoreCallingIdentity(ident);
3573 return config;
3574 }
3575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003577 * Determine the new desired orientation of the display, returning
3578 * a non-null new Configuration if it has changed from the current
3579 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3580 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3581 * SCREEN. This will typically be done for you if you call
3582 * sendNewConfiguration().
3583 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 * The orientation is computed from non-application windows first. If none of
3585 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003586 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3588 * android.os.IBinder)
3589 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003590 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3591 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003592 // If the display is frozen, some activities may be in the middle
3593 // of restarting, and thus have removed their old window. If the
3594 // window has the flag to hide the lock screen, then the lock screen
3595 // can re-appear and inflict its own orientation on us. Keep the
3596 // orientation stable until this all settles down.
3597 return false;
3598 }
3599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 long ident = Binder.clearCallingIdentity();
3602 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003603 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 mForcedAppOrientation = req;
3607 //send a message to Policy indicating orientation change to take
3608 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003609 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003610 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003611 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3612 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003613 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 }
3615 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003616
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003617 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 } finally {
3619 Binder.restoreCallingIdentity(ident);
3620 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 }
Romain Guy06882f82009-06-10 13:36:04 -07003622
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003623 int computeForcedAppOrientationLocked() {
3624 int req = getOrientationFromWindowsLocked();
3625 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3626 req = getOrientationFromAppTokensLocked();
3627 }
3628 return req;
3629 }
Romain Guy06882f82009-06-10 13:36:04 -07003630
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003631 public void setNewConfiguration(Configuration config) {
3632 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3633 "setNewConfiguration()")) {
3634 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3635 }
3636
3637 synchronized(mWindowMap) {
3638 mCurConfiguration = new Configuration(config);
3639 mWaitingForConfig = false;
3640 performLayoutAndPlaceSurfacesLocked();
3641 }
3642 }
3643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3645 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3646 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003647 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 }
Romain Guy06882f82009-06-10 13:36:04 -07003649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003650 synchronized(mWindowMap) {
3651 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3652 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003653 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 return;
3655 }
Romain Guy06882f82009-06-10 13:36:04 -07003656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 wtoken.requestedOrientation = requestedOrientation;
3658 }
3659 }
Romain Guy06882f82009-06-10 13:36:04 -07003660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 public int getAppOrientation(IApplicationToken token) {
3662 synchronized(mWindowMap) {
3663 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3664 if (wtoken == null) {
3665 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3666 }
Romain Guy06882f82009-06-10 13:36:04 -07003667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 return wtoken.requestedOrientation;
3669 }
3670 }
Romain Guy06882f82009-06-10 13:36:04 -07003671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3673 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3674 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003675 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 }
3677
3678 synchronized(mWindowMap) {
3679 boolean changed = false;
3680 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003681 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 changed = mFocusedApp != null;
3683 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003684 if (changed) {
3685 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 } else {
3688 AppWindowToken newFocus = findAppWindowToken(token);
3689 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003690 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 return;
3692 }
3693 changed = mFocusedApp != newFocus;
3694 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003695 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003696 if (changed) {
3697 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003698 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 }
3700
3701 if (moveFocusNow && changed) {
3702 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003703 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 Binder.restoreCallingIdentity(origId);
3705 }
3706 }
3707 }
3708
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003709 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3711 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003712 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 }
Romain Guy06882f82009-06-10 13:36:04 -07003714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003716 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 TAG, "Prepare app transition: transit=" + transit
3718 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003719 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003720 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3721 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003723 } else if (!alwaysKeepCurrent) {
3724 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3725 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3726 // Opening a new task always supersedes a close for the anim.
3727 mNextAppTransition = transit;
3728 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3729 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3730 // Opening a new activity always supersedes a close for the anim.
3731 mNextAppTransition = transit;
3732 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 }
3734 mAppTransitionReady = false;
3735 mAppTransitionTimeout = false;
3736 mStartingIconInTransition = false;
3737 mSkipAppTransitionAnimation = false;
3738 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3739 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3740 5000);
3741 }
3742 }
3743 }
3744
3745 public int getPendingAppTransition() {
3746 return mNextAppTransition;
3747 }
Romain Guy06882f82009-06-10 13:36:04 -07003748
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003749 public void overridePendingAppTransition(String packageName,
3750 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003751 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003752 mNextAppTransitionPackage = packageName;
3753 mNextAppTransitionEnter = enterAnim;
3754 mNextAppTransitionExit = exitAnim;
3755 }
3756 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 public void executeAppTransition() {
3759 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3760 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003761 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 }
Romain Guy06882f82009-06-10 13:36:04 -07003763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003765 if (DEBUG_APP_TRANSITIONS) {
3766 RuntimeException e = new RuntimeException("here");
3767 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003768 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003769 + mNextAppTransition, e);
3770 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003771 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 mAppTransitionReady = true;
3773 final long origId = Binder.clearCallingIdentity();
3774 performLayoutAndPlaceSurfacesLocked();
3775 Binder.restoreCallingIdentity(origId);
3776 }
3777 }
3778 }
3779
3780 public void setAppStartingWindow(IBinder token, String pkg,
3781 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003782 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3784 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003785 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 }
3787
3788 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003789 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3791 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 AppWindowToken wtoken = findAppWindowToken(token);
3794 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003795 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 return;
3797 }
3798
3799 // If the display is frozen, we won't do anything until the
3800 // actual window is displayed so there is no reason to put in
3801 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003802 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 return;
3804 }
Romain Guy06882f82009-06-10 13:36:04 -07003805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 if (wtoken.startingData != null) {
3807 return;
3808 }
Romain Guy06882f82009-06-10 13:36:04 -07003809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 if (transferFrom != null) {
3811 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3812 if (ttoken != null) {
3813 WindowState startingWindow = ttoken.startingWindow;
3814 if (startingWindow != null) {
3815 if (mStartingIconInTransition) {
3816 // In this case, the starting icon has already
3817 // been displayed, so start letting windows get
3818 // shown immediately without any more transitions.
3819 mSkipAppTransitionAnimation = true;
3820 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003821 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 "Moving existing starting from " + ttoken
3823 + " to " + wtoken);
3824 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 // Transfer the starting window over to the new
3827 // token.
3828 wtoken.startingData = ttoken.startingData;
3829 wtoken.startingView = ttoken.startingView;
3830 wtoken.startingWindow = startingWindow;
3831 ttoken.startingData = null;
3832 ttoken.startingView = null;
3833 ttoken.startingWindow = null;
3834 ttoken.startingMoved = true;
3835 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003836 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003838 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003839 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003841 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003842 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3843 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 ttoken.windows.remove(startingWindow);
3845 ttoken.allAppWindows.remove(startingWindow);
3846 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 // Propagate other interesting state between the
3849 // tokens. If the old token is displayed, we should
3850 // immediately force the new one to be displayed. If
3851 // it is animating, we need to move that animation to
3852 // the new one.
3853 if (ttoken.allDrawn) {
3854 wtoken.allDrawn = true;
3855 }
3856 if (ttoken.firstWindowDrawn) {
3857 wtoken.firstWindowDrawn = true;
3858 }
3859 if (!ttoken.hidden) {
3860 wtoken.hidden = false;
3861 wtoken.hiddenRequested = false;
3862 wtoken.willBeHidden = false;
3863 }
3864 if (wtoken.clientHidden != ttoken.clientHidden) {
3865 wtoken.clientHidden = ttoken.clientHidden;
3866 wtoken.sendAppVisibilityToClients();
3867 }
3868 if (ttoken.animation != null) {
3869 wtoken.animation = ttoken.animation;
3870 wtoken.animating = ttoken.animating;
3871 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3872 ttoken.animation = null;
3873 ttoken.animLayerAdjustment = 0;
3874 wtoken.updateLayers();
3875 ttoken.updateLayers();
3876 }
Romain Guy06882f82009-06-10 13:36:04 -07003877
Jeff Brown3a22cd92011-01-21 13:59:04 -08003878 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3879 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 mLayoutNeeded = true;
3881 performLayoutAndPlaceSurfacesLocked();
3882 Binder.restoreCallingIdentity(origId);
3883 return;
3884 } else if (ttoken.startingData != null) {
3885 // The previous app was getting ready to show a
3886 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003887 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 "Moving pending starting from " + ttoken
3889 + " to " + wtoken);
3890 wtoken.startingData = ttoken.startingData;
3891 ttoken.startingData = null;
3892 ttoken.startingMoved = true;
3893 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3894 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3895 // want to process the message ASAP, before any other queued
3896 // messages.
3897 mH.sendMessageAtFrontOfQueue(m);
3898 return;
3899 }
3900 }
3901 }
3902
3903 // There is no existing starting window, and the caller doesn't
3904 // want us to create one, so that's it!
3905 if (!createIfNeeded) {
3906 return;
3907 }
Romain Guy06882f82009-06-10 13:36:04 -07003908
Dianne Hackborn284ac932009-08-28 10:34:25 -07003909 // If this is a translucent or wallpaper window, then don't
3910 // show a starting window -- the current effect (a full-screen
3911 // opaque starting window that fades away to the real contents
3912 // when it is ready) does not work for this.
3913 if (theme != 0) {
3914 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3915 com.android.internal.R.styleable.Window);
3916 if (ent.array.getBoolean(
3917 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3918 return;
3919 }
3920 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003921 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3922 return;
3923 }
3924 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003925 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3926 return;
3927 }
3928 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 mStartingIconInTransition = true;
3931 wtoken.startingData = new StartingData(
3932 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003933 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3935 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3936 // want to process the message ASAP, before any other queued
3937 // messages.
3938 mH.sendMessageAtFrontOfQueue(m);
3939 }
3940 }
3941
3942 public void setAppWillBeHidden(IBinder token) {
3943 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3944 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003945 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 }
3947
3948 AppWindowToken wtoken;
3949
3950 synchronized(mWindowMap) {
3951 wtoken = findAppWindowToken(token);
3952 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003953 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 -08003954 return;
3955 }
3956 wtoken.willBeHidden = true;
3957 }
3958 }
Romain Guy06882f82009-06-10 13:36:04 -07003959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3961 boolean visible, int transit, boolean performLayout) {
3962 boolean delayed = false;
3963
3964 if (wtoken.clientHidden == visible) {
3965 wtoken.clientHidden = !visible;
3966 wtoken.sendAppVisibilityToClients();
3967 }
Romain Guy06882f82009-06-10 13:36:04 -07003968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 wtoken.willBeHidden = false;
3970 if (wtoken.hidden == visible) {
3971 final int N = wtoken.allAppWindows.size();
3972 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003973 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3975 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003978
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003979 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 if (wtoken.animation == sDummyAnimation) {
3981 wtoken.animation = null;
3982 }
3983 applyAnimationLocked(wtoken, lp, transit, visible);
3984 changed = true;
3985 if (wtoken.animation != null) {
3986 delayed = runningAppAnimation = true;
3987 }
3988 }
Romain Guy06882f82009-06-10 13:36:04 -07003989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 for (int i=0; i<N; i++) {
3991 WindowState win = wtoken.allAppWindows.get(i);
3992 if (win == wtoken.startingWindow) {
3993 continue;
3994 }
3995
3996 if (win.isAnimating()) {
3997 delayed = true;
3998 }
Romain Guy06882f82009-06-10 13:36:04 -07003999
Joe Onorato8a9b2202010-02-26 18:56:32 -08004000 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 //win.dump(" ");
4002 if (visible) {
4003 if (!win.isVisibleNow()) {
4004 if (!runningAppAnimation) {
4005 applyAnimationLocked(win,
4006 WindowManagerPolicy.TRANSIT_ENTER, true);
4007 }
4008 changed = true;
4009 }
4010 } else if (win.isVisibleNow()) {
4011 if (!runningAppAnimation) {
4012 applyAnimationLocked(win,
4013 WindowManagerPolicy.TRANSIT_EXIT, false);
4014 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 changed = true;
4016 }
4017 }
4018
4019 wtoken.hidden = wtoken.hiddenRequested = !visible;
4020 if (!visible) {
4021 unsetAppFreezingScreenLocked(wtoken, true, true);
4022 } else {
4023 // If we are being set visible, and the starting window is
4024 // not yet displayed, then make sure it doesn't get displayed.
4025 WindowState swin = wtoken.startingWindow;
4026 if (swin != null && (swin.mDrawPending
4027 || swin.mCommitDrawPending)) {
4028 swin.mPolicyVisibility = false;
4029 swin.mPolicyVisibilityAfterAnim = false;
4030 }
4031 }
Romain Guy06882f82009-06-10 13:36:04 -07004032
Joe Onorato8a9b2202010-02-26 18:56:32 -08004033 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4035 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004036
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004037 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004038 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004039 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004040 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004041 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4042 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004043 performLayoutAndPlaceSurfacesLocked();
4044 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08004045 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004046 }
4047 }
4048
4049 if (wtoken.animation != null) {
4050 delayed = true;
4051 }
Romain Guy06882f82009-06-10 13:36:04 -07004052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004053 return delayed;
4054 }
4055
4056 public void setAppVisibility(IBinder token, boolean visible) {
4057 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4058 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004059 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004060 }
4061
4062 AppWindowToken wtoken;
4063
4064 synchronized(mWindowMap) {
4065 wtoken = findAppWindowToken(token);
4066 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004067 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 return;
4069 }
4070
4071 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004072 RuntimeException e = null;
4073 if (!HIDE_STACK_CRAWLS) {
4074 e = new RuntimeException();
4075 e.fillInStackTrace();
4076 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004077 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 + "): mNextAppTransition=" + mNextAppTransition
4079 + " hidden=" + wtoken.hidden
4080 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4081 }
Romain Guy06882f82009-06-10 13:36:04 -07004082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 // If we are preparing an app transition, then delay changing
4084 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004085 if (!mDisplayFrozen && mPolicy.isScreenOn()
4086 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004087 // Already in requested state, don't do anything more.
4088 if (wtoken.hiddenRequested != visible) {
4089 return;
4090 }
4091 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004092
Joe Onorato8a9b2202010-02-26 18:56:32 -08004093 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094 TAG, "Setting dummy animation on: " + wtoken);
4095 wtoken.setDummyAnimation();
4096 mOpeningApps.remove(wtoken);
4097 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004098 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 wtoken.inPendingTransaction = true;
4100 if (visible) {
4101 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 wtoken.startingDisplayed = false;
4103 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004104
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004105 // If the token is currently hidden (should be the
4106 // common case), then we need to set up to wait for
4107 // its windows to be ready.
4108 if (wtoken.hidden) {
4109 wtoken.allDrawn = false;
4110 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004111
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004112 if (wtoken.clientHidden) {
4113 // In the case where we are making an app visible
4114 // but holding off for a transition, we still need
4115 // to tell the client to make its windows visible so
4116 // they get drawn. Otherwise, we will wait on
4117 // performing the transition until all windows have
4118 // been drawn, they never will be, and we are sad.
4119 wtoken.clientHidden = false;
4120 wtoken.sendAppVisibilityToClients();
4121 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004122 }
4123 } else {
4124 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004125
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004126 // If the token is currently visible (should be the
4127 // common case), then set up to wait for it to be hidden.
4128 if (!wtoken.hidden) {
4129 wtoken.waitingToHide = true;
4130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004131 }
4132 return;
4133 }
Romain Guy06882f82009-06-10 13:36:04 -07004134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004136 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004137 wtoken.updateReportedVisibilityLocked();
4138 Binder.restoreCallingIdentity(origId);
4139 }
4140 }
4141
4142 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4143 boolean unfreezeSurfaceNow, boolean force) {
4144 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004145 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 + " force=" + force);
4147 final int N = wtoken.allAppWindows.size();
4148 boolean unfrozeWindows = false;
4149 for (int i=0; i<N; i++) {
4150 WindowState w = wtoken.allAppWindows.get(i);
4151 if (w.mAppFreezing) {
4152 w.mAppFreezing = false;
4153 if (w.mSurface != null && !w.mOrientationChanging) {
4154 w.mOrientationChanging = true;
4155 }
4156 unfrozeWindows = true;
4157 }
4158 }
4159 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004160 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 wtoken.freezingScreen = false;
4162 mAppsFreezingScreen--;
4163 }
4164 if (unfreezeSurfaceNow) {
4165 if (unfrozeWindows) {
4166 mLayoutNeeded = true;
4167 performLayoutAndPlaceSurfacesLocked();
4168 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004169 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004170 }
4171 }
4172 }
Romain Guy06882f82009-06-10 13:36:04 -07004173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4175 int configChanges) {
4176 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004177 RuntimeException e = null;
4178 if (!HIDE_STACK_CRAWLS) {
4179 e = new RuntimeException();
4180 e.fillInStackTrace();
4181 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004182 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004183 + ": hidden=" + wtoken.hidden + " freezing="
4184 + wtoken.freezingScreen, e);
4185 }
4186 if (!wtoken.hiddenRequested) {
4187 if (!wtoken.freezingScreen) {
4188 wtoken.freezingScreen = true;
4189 mAppsFreezingScreen++;
4190 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004191 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4193 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4194 5000);
4195 }
4196 }
4197 final int N = wtoken.allAppWindows.size();
4198 for (int i=0; i<N; i++) {
4199 WindowState w = wtoken.allAppWindows.get(i);
4200 w.mAppFreezing = true;
4201 }
4202 }
4203 }
Romain Guy06882f82009-06-10 13:36:04 -07004204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 public void startAppFreezingScreen(IBinder token, int configChanges) {
4206 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4207 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004208 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 }
4210
4211 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004212 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004213 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004214 return;
4215 }
Romain Guy06882f82009-06-10 13:36:04 -07004216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 AppWindowToken wtoken = findAppWindowToken(token);
4218 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004219 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 return;
4221 }
4222 final long origId = Binder.clearCallingIdentity();
4223 startAppFreezingScreenLocked(wtoken, configChanges);
4224 Binder.restoreCallingIdentity(origId);
4225 }
4226 }
Romain Guy06882f82009-06-10 13:36:04 -07004227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004228 public void stopAppFreezingScreen(IBinder token, boolean force) {
4229 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4230 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004231 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004232 }
4233
4234 synchronized(mWindowMap) {
4235 AppWindowToken wtoken = findAppWindowToken(token);
4236 if (wtoken == null || wtoken.appToken == null) {
4237 return;
4238 }
4239 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004240 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004241 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4242 unsetAppFreezingScreenLocked(wtoken, true, force);
4243 Binder.restoreCallingIdentity(origId);
4244 }
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 public void removeAppToken(IBinder token) {
4248 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4249 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004250 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 }
4252
4253 AppWindowToken wtoken = null;
4254 AppWindowToken startingToken = null;
4255 boolean delayed = false;
4256
4257 final long origId = Binder.clearCallingIdentity();
4258 synchronized(mWindowMap) {
4259 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004261 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004262 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004263 wtoken.inPendingTransaction = false;
4264 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004265 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 if (mClosingApps.contains(wtoken)) {
4267 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004268 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004270 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 delayed = true;
4272 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004273 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274 TAG, "Removing app " + wtoken + " delayed=" + delayed
4275 + " animation=" + wtoken.animation
4276 + " animating=" + wtoken.animating);
4277 if (delayed) {
4278 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004279 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4280 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004282 } else {
4283 // Make sure there is no animation running on this token,
4284 // so any windows associated with it will be removed as
4285 // soon as their animations are complete
4286 wtoken.animation = null;
4287 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004289 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4290 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 mAppTokens.remove(wtoken);
4292 wtoken.removed = true;
4293 if (wtoken.startingData != null) {
4294 startingToken = wtoken;
4295 }
4296 unsetAppFreezingScreenLocked(wtoken, true, true);
4297 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004298 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004300 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004301 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 }
4303 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004304 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 }
Romain Guy06882f82009-06-10 13:36:04 -07004306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 if (!delayed && wtoken != null) {
4308 wtoken.updateReportedVisibilityLocked();
4309 }
4310 }
4311 Binder.restoreCallingIdentity(origId);
4312
4313 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004314 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 + startingToken + ": app token removed");
4316 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4317 mH.sendMessage(m);
4318 }
4319 }
4320
4321 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4322 final int NW = token.windows.size();
4323 for (int i=0; i<NW; i++) {
4324 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004325 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004327 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 int j = win.mChildWindows.size();
4329 while (j > 0) {
4330 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004331 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004332 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004333 "Tmp removing child window " + cwin);
4334 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 }
4336 }
4337 return NW > 0;
4338 }
4339
4340 void dumpAppTokensLocked() {
4341 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004342 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 }
4344 }
Romain Guy06882f82009-06-10 13:36:04 -07004345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 void dumpWindowsLocked() {
4347 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004348 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 }
4350 }
Romain Guy06882f82009-06-10 13:36:04 -07004351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 private int findWindowOffsetLocked(int tokenPos) {
4353 final int NW = mWindows.size();
4354
4355 if (tokenPos >= mAppTokens.size()) {
4356 int i = NW;
4357 while (i > 0) {
4358 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004359 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 if (win.getAppToken() != null) {
4361 return i+1;
4362 }
4363 }
4364 }
4365
4366 while (tokenPos > 0) {
4367 // Find the first app token below the new position that has
4368 // a window displayed.
4369 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004370 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004371 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004372 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004373 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004374 "Skipping token -- currently sending to bottom");
4375 tokenPos--;
4376 continue;
4377 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 int i = wtoken.windows.size();
4379 while (i > 0) {
4380 i--;
4381 WindowState win = wtoken.windows.get(i);
4382 int j = win.mChildWindows.size();
4383 while (j > 0) {
4384 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004385 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004386 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 for (int pos=NW-1; pos>=0; pos--) {
4388 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004389 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 "Found child win @" + (pos+1));
4391 return pos+1;
4392 }
4393 }
4394 }
4395 }
4396 for (int pos=NW-1; pos>=0; pos--) {
4397 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004398 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004399 return pos+1;
4400 }
4401 }
4402 }
4403 tokenPos--;
4404 }
4405
4406 return 0;
4407 }
4408
4409 private final int reAddWindowLocked(int index, WindowState win) {
4410 final int NCW = win.mChildWindows.size();
4411 boolean added = false;
4412 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004413 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004414 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004415 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004416 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004417 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 mWindows.add(index, win);
4419 index++;
4420 added = true;
4421 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004422 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004423 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004424 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 mWindows.add(index, cwin);
4426 index++;
4427 }
4428 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004429 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004430 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004431 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 mWindows.add(index, win);
4433 index++;
4434 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004435 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 return index;
4437 }
Romain Guy06882f82009-06-10 13:36:04 -07004438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4440 final int NW = token.windows.size();
4441 for (int i=0; i<NW; i++) {
4442 index = reAddWindowLocked(index, token.windows.get(i));
4443 }
4444 return index;
4445 }
4446
4447 public void moveAppToken(int index, IBinder token) {
4448 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4449 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004450 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 }
4452
4453 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004454 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 if (DEBUG_REORDER) dumpAppTokensLocked();
4456 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004457 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4458 "Start moving token " + wtoken + " initially at "
4459 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004461 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 + token + " (" + wtoken + ")");
4463 return;
4464 }
4465 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004466 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004467 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004468 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004471 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 if (DEBUG_REORDER) dumpWindowsLocked();
4473 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004474 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 if (DEBUG_REORDER) dumpWindowsLocked();
4476 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004477 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004479 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4480 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 mLayoutNeeded = true;
4482 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004483 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 }
4485 Binder.restoreCallingIdentity(origId);
4486 }
4487 }
4488
4489 private void removeAppTokensLocked(List<IBinder> tokens) {
4490 // XXX This should be done more efficiently!
4491 // (take advantage of the fact that both lists should be
4492 // ordered in the same way.)
4493 int N = tokens.size();
4494 for (int i=0; i<N; i++) {
4495 IBinder token = tokens.get(i);
4496 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004497 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4498 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004500 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 + token + " (" + wtoken + ")");
4502 i--;
4503 N--;
4504 }
4505 }
4506 }
4507
Dianne Hackborna8f60182009-09-01 19:01:50 -07004508 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4509 boolean updateFocusAndLayout) {
4510 // First remove all of the windows from the list.
4511 tmpRemoveAppWindowsLocked(wtoken);
4512
4513 // Where to start adding?
4514 int pos = findWindowOffsetLocked(tokenPos);
4515
4516 // And now add them back at the correct place.
4517 pos = reAddAppWindowsLocked(pos, wtoken);
4518
4519 if (updateFocusAndLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004520 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4521 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004522 assignLayersLocked();
4523 }
4524 mLayoutNeeded = true;
4525 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004526 mInputMonitor.updateInputWindowsLw();
Dianne Hackborna8f60182009-09-01 19:01:50 -07004527 }
4528 }
4529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4531 // First remove all of the windows from the list.
4532 final int N = tokens.size();
4533 int i;
4534 for (i=0; i<N; i++) {
4535 WindowToken token = mTokenMap.get(tokens.get(i));
4536 if (token != null) {
4537 tmpRemoveAppWindowsLocked(token);
4538 }
4539 }
4540
4541 // Where to start adding?
4542 int pos = findWindowOffsetLocked(tokenPos);
4543
4544 // And now add them back at the correct place.
4545 for (i=0; i<N; i++) {
4546 WindowToken token = mTokenMap.get(tokens.get(i));
4547 if (token != null) {
4548 pos = reAddAppWindowsLocked(pos, token);
4549 }
4550 }
4551
Jeff Brown3a22cd92011-01-21 13:59:04 -08004552 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4553 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004554 assignLayersLocked();
4555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004556 mLayoutNeeded = true;
4557 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004558 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004559
4560 //dump();
4561 }
4562
4563 public void moveAppTokensToTop(List<IBinder> tokens) {
4564 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4565 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004566 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004567 }
4568
4569 final long origId = Binder.clearCallingIdentity();
4570 synchronized(mWindowMap) {
4571 removeAppTokensLocked(tokens);
4572 final int N = tokens.size();
4573 for (int i=0; i<N; i++) {
4574 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4575 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004576 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4577 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004579 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004580 mToTopApps.remove(wt);
4581 mToBottomApps.remove(wt);
4582 mToTopApps.add(wt);
4583 wt.sendingToBottom = false;
4584 wt.sendingToTop = true;
4585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 }
4587 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004588
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004589 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004590 moveAppWindowsLocked(tokens, mAppTokens.size());
4591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 }
4593 Binder.restoreCallingIdentity(origId);
4594 }
4595
4596 public void moveAppTokensToBottom(List<IBinder> tokens) {
4597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4598 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 }
4601
4602 final long origId = Binder.clearCallingIdentity();
4603 synchronized(mWindowMap) {
4604 removeAppTokensLocked(tokens);
4605 final int N = tokens.size();
4606 int pos = 0;
4607 for (int i=0; i<N; i++) {
4608 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4609 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004610 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4611 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004613 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004614 mToTopApps.remove(wt);
4615 mToBottomApps.remove(wt);
4616 mToBottomApps.add(i, wt);
4617 wt.sendingToTop = false;
4618 wt.sendingToBottom = true;
4619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 pos++;
4621 }
4622 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004623
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004624 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004625 moveAppWindowsLocked(tokens, 0);
4626 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 }
4628 Binder.restoreCallingIdentity(origId);
4629 }
4630
4631 // -------------------------------------------------------------
4632 // Misc IWindowSession methods
4633 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004634
Jim Miller284b62e2010-06-08 14:27:42 -07004635 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004636 {
Jim Miller284b62e2010-06-08 14:27:42 -07004637 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4638 // called before DevicePolicyManagerService has started.
4639 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4640 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4641 Context.DEVICE_POLICY_SERVICE);
4642 if (dpm != null) {
4643 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4644 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4645 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4646 }
Jim Millerd6b57052010-06-07 17:52:42 -07004647 }
Jim Miller284b62e2010-06-08 14:27:42 -07004648 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004649 }
4650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004652 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 != PackageManager.PERMISSION_GRANTED) {
4654 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4655 }
Jim Millerd6b57052010-06-07 17:52:42 -07004656
Jim Miller284b62e2010-06-08 14:27:42 -07004657 synchronized (mKeyguardTokenWatcher) {
4658 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 }
4661
4662 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004663 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 != PackageManager.PERMISSION_GRANTED) {
4665 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004667
Jim Miller284b62e2010-06-08 14:27:42 -07004668 synchronized (mKeyguardTokenWatcher) {
4669 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004670
Jim Miller284b62e2010-06-08 14:27:42 -07004671 if (!mKeyguardTokenWatcher.isAcquired()) {
4672 // If we are the last one to reenable the keyguard wait until
4673 // we have actually finished reenabling until returning.
4674 // It is possible that reenableKeyguard() can be called before
4675 // the previous disableKeyguard() is handled, in which case
4676 // neither mKeyguardTokenWatcher.acquired() or released() would
4677 // be called. In that case mKeyguardDisabled will be false here
4678 // and we have nothing to wait for.
4679 while (mKeyguardDisabled) {
4680 try {
4681 mKeyguardTokenWatcher.wait();
4682 } catch (InterruptedException e) {
4683 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 }
4685 }
4686 }
4687 }
4688 }
4689
4690 /**
4691 * @see android.app.KeyguardManager#exitKeyguardSecurely
4692 */
4693 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004694 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004695 != PackageManager.PERMISSION_GRANTED) {
4696 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4697 }
4698 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4699 public void onKeyguardExitResult(boolean success) {
4700 try {
4701 callback.onKeyguardExitResult(success);
4702 } catch (RemoteException e) {
4703 // Client has died, we don't care.
4704 }
4705 }
4706 });
4707 }
4708
4709 public boolean inKeyguardRestrictedInputMode() {
4710 return mPolicy.inKeyguardRestrictedKeyInputMode();
4711 }
Romain Guy06882f82009-06-10 13:36:04 -07004712
Dianne Hackbornffa42482009-09-23 22:20:11 -07004713 public void closeSystemDialogs(String reason) {
4714 synchronized(mWindowMap) {
4715 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004716 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004717 if (w.mSurface != null) {
4718 try {
4719 w.mClient.closeSystemDialogs(reason);
4720 } catch (RemoteException e) {
4721 }
4722 }
4723 }
4724 }
4725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004727 static float fixScale(float scale) {
4728 if (scale < 0) scale = 0;
4729 else if (scale > 20) scale = 20;
4730 return Math.abs(scale);
4731 }
Romain Guy06882f82009-06-10 13:36:04 -07004732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004733 public void setAnimationScale(int which, float scale) {
4734 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4735 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004736 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 }
4738
4739 if (scale < 0) scale = 0;
4740 else if (scale > 20) scale = 20;
4741 scale = Math.abs(scale);
4742 switch (which) {
4743 case 0: mWindowAnimationScale = fixScale(scale); break;
4744 case 1: mTransitionAnimationScale = fixScale(scale); break;
4745 }
Romain Guy06882f82009-06-10 13:36:04 -07004746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004747 // Persist setting
4748 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4749 }
Romain Guy06882f82009-06-10 13:36:04 -07004750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004751 public void setAnimationScales(float[] scales) {
4752 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4753 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004754 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004755 }
4756
4757 if (scales != null) {
4758 if (scales.length >= 1) {
4759 mWindowAnimationScale = fixScale(scales[0]);
4760 }
4761 if (scales.length >= 2) {
4762 mTransitionAnimationScale = fixScale(scales[1]);
4763 }
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 // Persist setting
4767 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4768 }
Romain Guy06882f82009-06-10 13:36:04 -07004769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 public float getAnimationScale(int which) {
4771 switch (which) {
4772 case 0: return mWindowAnimationScale;
4773 case 1: return mTransitionAnimationScale;
4774 }
4775 return 0;
4776 }
Romain Guy06882f82009-06-10 13:36:04 -07004777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 public float[] getAnimationScales() {
4779 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4780 }
Romain Guy06882f82009-06-10 13:36:04 -07004781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004782 public int getSwitchState(int sw) {
4783 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4784 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004785 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004786 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004787 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 public int getSwitchStateForDevice(int devid, int sw) {
4791 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4792 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004793 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004795 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 }
Romain Guy06882f82009-06-10 13:36:04 -07004797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 public int getScancodeState(int sw) {
4799 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4800 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004801 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004802 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004803 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 }
Romain Guy06882f82009-06-10 13:36:04 -07004805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004806 public int getScancodeStateForDevice(int devid, int sw) {
4807 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4808 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004809 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004811 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 }
Romain Guy06882f82009-06-10 13:36:04 -07004813
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004814 public int getTrackballScancodeState(int sw) {
4815 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4816 "getTrackballScancodeState()")) {
4817 throw new SecurityException("Requires READ_INPUT_STATE permission");
4818 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004819 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004820 }
4821
4822 public int getDPadScancodeState(int sw) {
4823 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4824 "getDPadScancodeState()")) {
4825 throw new SecurityException("Requires READ_INPUT_STATE permission");
4826 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004827 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004828 }
4829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830 public int getKeycodeState(int sw) {
4831 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4832 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004833 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004835 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004836 }
Romain Guy06882f82009-06-10 13:36:04 -07004837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004838 public int getKeycodeStateForDevice(int devid, int sw) {
4839 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4840 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004841 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004843 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004844 }
Romain Guy06882f82009-06-10 13:36:04 -07004845
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004846 public int getTrackballKeycodeState(int sw) {
4847 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4848 "getTrackballKeycodeState()")) {
4849 throw new SecurityException("Requires READ_INPUT_STATE permission");
4850 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004851 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004852 }
4853
4854 public int getDPadKeycodeState(int sw) {
4855 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4856 "getDPadKeycodeState()")) {
4857 throw new SecurityException("Requires READ_INPUT_STATE permission");
4858 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004859 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004860 }
Jeff Browna41ca772010-08-11 14:46:32 -07004861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004863 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 }
Romain Guy06882f82009-06-10 13:36:04 -07004865
Jeff Browna41ca772010-08-11 14:46:32 -07004866 public InputChannel monitorInput(String inputChannelName) {
4867 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4868 "monitorInput()")) {
4869 throw new SecurityException("Requires READ_INPUT_STATE permission");
4870 }
4871 return mInputManager.monitorInput(inputChannelName);
4872 }
4873
Jeff Brown8d608662010-08-30 03:02:23 -07004874 public InputDevice getInputDevice(int deviceId) {
4875 return mInputManager.getInputDevice(deviceId);
4876 }
4877
4878 public int[] getInputDeviceIds() {
4879 return mInputManager.getInputDeviceIds();
4880 }
4881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004882 public void enableScreenAfterBoot() {
4883 synchronized(mWindowMap) {
4884 if (mSystemBooted) {
4885 return;
4886 }
4887 mSystemBooted = true;
4888 }
Romain Guy06882f82009-06-10 13:36:04 -07004889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004890 performEnableScreen();
4891 }
Romain Guy06882f82009-06-10 13:36:04 -07004892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004893 public void enableScreenIfNeededLocked() {
4894 if (mDisplayEnabled) {
4895 return;
4896 }
4897 if (!mSystemBooted) {
4898 return;
4899 }
4900 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4901 }
Romain Guy06882f82009-06-10 13:36:04 -07004902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004903 public void performEnableScreen() {
4904 synchronized(mWindowMap) {
4905 if (mDisplayEnabled) {
4906 return;
4907 }
4908 if (!mSystemBooted) {
4909 return;
4910 }
Romain Guy06882f82009-06-10 13:36:04 -07004911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004912 // Don't enable the screen until all existing windows
4913 // have been drawn.
4914 final int N = mWindows.size();
4915 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004916 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004917 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004918 return;
4919 }
4920 }
Romain Guy06882f82009-06-10 13:36:04 -07004921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004922 mDisplayEnabled = true;
4923 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004924 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 StringWriter sw = new StringWriter();
4926 PrintWriter pw = new PrintWriter(sw);
4927 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004928 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 }
4930 try {
4931 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4932 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004933 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004934 Parcel data = Parcel.obtain();
4935 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4936 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4937 data, null, 0);
4938 data.recycle();
4939 }
4940 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004941 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 }
4943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004948 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4949 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 }
Romain Guy06882f82009-06-10 13:36:04 -07004951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 public void setInTouchMode(boolean mode) {
4953 synchronized(mWindowMap) {
4954 mInTouchMode = mode;
4955 }
4956 }
4957
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004958 // TODO: more accounting of which pid(s) turned it on, keep count,
4959 // only allow disables from pids which have count on, etc.
4960 public void showStrictModeViolation(boolean on) {
4961 int pid = Binder.getCallingPid();
4962 synchronized(mWindowMap) {
4963 // Ignoring requests to enable the red border from clients
4964 // which aren't on screen. (e.g. Broadcast Receivers in
4965 // the background..)
4966 if (on) {
4967 boolean isVisible = false;
4968 for (WindowState ws : mWindows) {
4969 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4970 isVisible = true;
4971 break;
4972 }
4973 }
4974 if (!isVisible) {
4975 return;
4976 }
4977 }
4978
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004979 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004980 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004981 try {
4982 if (mStrictModeFlash == null) {
4983 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4984 }
4985 mStrictModeFlash.setVisibility(on);
4986 } finally {
4987 Surface.closeTransaction();
4988 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004989 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004990 }
4991 }
4992
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004993 public void setStrictModeVisualIndicatorPreference(String value) {
4994 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4995 }
4996
Dianne Hackbornd2835932010-12-13 16:28:46 -08004997 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004998 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4999 "screenshotApplications()")) {
5000 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5001 }
5002
5003 Bitmap rawss;
5004
Dianne Hackbornd2835932010-12-13 16:28:46 -08005005 int maxLayer = 0;
5006 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005007 final Rect frame = new Rect();
5008
5009 float scale;
5010 int sw, sh, dw, dh;
5011 int rot;
5012
5013 synchronized(mWindowMap) {
5014 long ident = Binder.clearCallingIdentity();
5015
5016 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5017 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5018 + TYPE_LAYER_OFFSET;
5019 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5020
5021 // Figure out the part of the screen that is actually the app.
5022 for (int i=0; i<mWindows.size(); i++) {
5023 WindowState ws = mWindows.get(i);
5024 if (ws.mSurface == null) {
5025 continue;
5026 }
5027 if (ws.mLayer >= aboveAppLayer) {
5028 break;
5029 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005030 if (appToken != null && (ws.mAppToken == null
5031 || ws.mAppToken.token != appToken)) {
5032 continue;
5033 }
5034 if (maxLayer < ws.mAnimLayer) {
5035 maxLayer = ws.mAnimLayer;
5036 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005037 final Rect wf = ws.mFrame;
5038 final Rect cr = ws.mContentInsets;
5039 int left = wf.left + cr.left;
5040 int top = wf.top + cr.top;
5041 int right = wf.right - cr.right;
5042 int bottom = wf.bottom - cr.bottom;
5043 frame.union(left, top, right, bottom);
5044 }
5045 Binder.restoreCallingIdentity(ident);
5046
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005047 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005048 return null;
5049 }
5050
5051 // The screenshot API does not apply the current screen rotation.
5052 rot = mDisplay.getRotation();
5053 int fw = frame.width();
5054 int fh = frame.height();
5055
5056 // First try reducing to fit in x dimension.
5057 scale = maxWidth/(float)fw;
5058 sw = maxWidth;
5059 sh = (int)(fh*scale);
5060 if (sh > maxHeight) {
5061 // y dimension became too long; constrain by that.
5062 scale = maxHeight/(float)fh;
5063 sw = (int)(fw*scale);
5064 sh = maxHeight;
5065 }
5066
5067 // The screen shot will contain the entire screen.
5068 dw = (int)(mDisplay.getWidth()*scale);
5069 dh = (int)(mDisplay.getHeight()*scale);
5070 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5071 int tmp = dw;
5072 dw = dh;
5073 dh = tmp;
5074 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5075 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005076 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005077 }
5078
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005079 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005080 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5081 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005082 return null;
5083 }
5084
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005085 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5086 Matrix matrix = new Matrix();
5087 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5088 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5089 Canvas canvas = new Canvas(bm);
5090 canvas.drawBitmap(rawss, matrix, null);
5091
5092 rawss.recycle();
5093 return bm;
5094 }
5095
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005096 public void freezeRotation() {
5097 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5098 "setRotation()")) {
5099 throw new SecurityException("Requires SET_ORIENTATION permission");
5100 }
5101
5102 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5103 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5104 }
5105
5106 public void thawRotation() {
5107 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5108 "setRotation()")) {
5109 throw new SecurityException("Requires SET_ORIENTATION permission");
5110 }
5111
5112 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5113 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5114 }
5115
Romain Guy06882f82009-06-10 13:36:04 -07005116 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005117 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005118 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005119 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005120 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005121 }
5122
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005123 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 }
Romain Guy06882f82009-06-10 13:36:04 -07005125
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005126 public void setRotationUnchecked(int rotation,
5127 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005128 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005129 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005131 long origId = Binder.clearCallingIdentity();
5132 boolean changed;
5133 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005134 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005135 }
Romain Guy06882f82009-06-10 13:36:04 -07005136
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005137 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005138 sendNewConfiguration();
5139 }
Romain Guy06882f82009-06-10 13:36:04 -07005140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005141 Binder.restoreCallingIdentity(origId);
5142 }
Romain Guy06882f82009-06-10 13:36:04 -07005143
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005144 /**
5145 * Apply a new rotation to the screen, respecting the requests of
5146 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5147 * re-evaluate the desired rotation.
5148 *
5149 * Returns null if the rotation has been changed. In this case YOU
5150 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5151 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005152 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005153 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005154 // Potential rotation during a drag. Don't do the rotation now, but make
5155 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005156 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5157 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5158 mDeferredRotation = rotation;
5159 mDeferredRotationAnimFlags = animFlags;
5160 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005161 return false;
5162 }
5163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005164 boolean changed;
5165 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005166 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5167 rotation = mDeferredRotation;
5168 mRequestedRotation = rotation;
5169 mLastRotationFlags = mDeferredRotationAnimFlags;
5170 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005171 rotation = mRequestedRotation;
5172 } else {
5173 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005174 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005175 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005176 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005177 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005178 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005180 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005181 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005183 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005184 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 "Rotation changed to " + rotation
5186 + " from " + mRotation
5187 + " (forceApp=" + mForcedAppOrientation
5188 + ", req=" + mRequestedRotation + ")");
5189 mRotation = rotation;
5190 mWindowsFreezingScreen = true;
5191 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5192 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5193 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005194 mWaitingForConfig = true;
5195 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005196 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005197 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005198 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005199 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005200 if (CUSTOM_SCREEN_ROTATION) {
5201 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005202 if (!inTransaction) {
5203 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5204 ">>> OPEN TRANSACTION setRotationUnchecked");
5205 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005206 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005207 try {
5208 if (mScreenRotationAnimation != null) {
5209 mScreenRotationAnimation.setRotation(rotation);
5210 }
5211 } finally {
5212 if (!inTransaction) {
5213 Surface.closeTransaction();
5214 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5215 "<<< CLOSE TRANSACTION setRotationUnchecked");
5216 }
5217 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005218 Surface.setOrientation(0, rotation, animFlags);
5219 Surface.unfreezeDisplay(0);
5220 } else {
5221 Surface.setOrientation(0, rotation, animFlags);
5222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005223 }
5224 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005225 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005226 if (w.mSurface != null) {
5227 w.mOrientationChanging = true;
5228 }
5229 }
5230 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5231 try {
5232 mRotationWatchers.get(i).onRotationChanged(rotation);
5233 } catch (RemoteException e) {
5234 }
5235 }
5236 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 return changed;
5239 }
Romain Guy06882f82009-06-10 13:36:04 -07005240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 public int getRotation() {
5242 return mRotation;
5243 }
5244
5245 public int watchRotation(IRotationWatcher watcher) {
5246 final IBinder watcherBinder = watcher.asBinder();
5247 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5248 public void binderDied() {
5249 synchronized (mWindowMap) {
5250 for (int i=0; i<mRotationWatchers.size(); i++) {
5251 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005252 IRotationWatcher removed = mRotationWatchers.remove(i);
5253 if (removed != null) {
5254 removed.asBinder().unlinkToDeath(this, 0);
5255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 i--;
5257 }
5258 }
5259 }
5260 }
5261 };
Romain Guy06882f82009-06-10 13:36:04 -07005262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263 synchronized (mWindowMap) {
5264 try {
5265 watcher.asBinder().linkToDeath(dr, 0);
5266 mRotationWatchers.add(watcher);
5267 } catch (RemoteException e) {
5268 // Client died, no cleanup needed.
5269 }
Romain Guy06882f82009-06-10 13:36:04 -07005270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005271 return mRotation;
5272 }
5273 }
5274
5275 /**
5276 * Starts the view server on the specified port.
5277 *
5278 * @param port The port to listener to.
5279 *
5280 * @return True if the server was successfully started, false otherwise.
5281 *
5282 * @see com.android.server.ViewServer
5283 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5284 */
5285 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005286 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005287 return false;
5288 }
5289
5290 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5291 return false;
5292 }
5293
5294 if (port < 1024) {
5295 return false;
5296 }
5297
5298 if (mViewServer != null) {
5299 if (!mViewServer.isRunning()) {
5300 try {
5301 return mViewServer.start();
5302 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005303 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005304 }
5305 }
5306 return false;
5307 }
5308
5309 try {
5310 mViewServer = new ViewServer(this, port);
5311 return mViewServer.start();
5312 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005313 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005314 }
5315 return false;
5316 }
5317
Romain Guy06882f82009-06-10 13:36:04 -07005318 private boolean isSystemSecure() {
5319 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5320 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5321 }
5322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 /**
5324 * Stops the view server if it exists.
5325 *
5326 * @return True if the server stopped, false if it wasn't started or
5327 * couldn't be stopped.
5328 *
5329 * @see com.android.server.ViewServer
5330 */
5331 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005332 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333 return false;
5334 }
5335
5336 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5337 return false;
5338 }
5339
5340 if (mViewServer != null) {
5341 return mViewServer.stop();
5342 }
5343 return false;
5344 }
5345
5346 /**
5347 * Indicates whether the view server is running.
5348 *
5349 * @return True if the server is running, false otherwise.
5350 *
5351 * @see com.android.server.ViewServer
5352 */
5353 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005354 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355 return false;
5356 }
5357
5358 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5359 return false;
5360 }
5361
5362 return mViewServer != null && mViewServer.isRunning();
5363 }
5364
5365 /**
5366 * Lists all availble windows in the system. The listing is written in the
5367 * specified Socket's output stream with the following syntax:
5368 * windowHashCodeInHexadecimal windowName
5369 * Each line of the ouput represents a different window.
5370 *
5371 * @param client The remote client to send the listing to.
5372 * @return False if an error occured, true otherwise.
5373 */
5374 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005375 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005376 return false;
5377 }
5378
5379 boolean result = true;
5380
Jeff Browne33348b2010-07-15 23:54:05 -07005381 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005383 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005384 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 }
5386
5387 BufferedWriter out = null;
5388
5389 // Any uncaught exception will crash the system process
5390 try {
5391 OutputStream clientStream = client.getOutputStream();
5392 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5393
5394 final int count = windows.length;
5395 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005396 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005397 out.write(Integer.toHexString(System.identityHashCode(w)));
5398 out.write(' ');
5399 out.append(w.mAttrs.getTitle());
5400 out.write('\n');
5401 }
5402
5403 out.write("DONE.\n");
5404 out.flush();
5405 } catch (Exception e) {
5406 result = false;
5407 } finally {
5408 if (out != null) {
5409 try {
5410 out.close();
5411 } catch (IOException e) {
5412 result = false;
5413 }
5414 }
5415 }
5416
5417 return result;
5418 }
5419
5420 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005421 * Returns the focused window in the following format:
5422 * windowHashCodeInHexadecimal windowName
5423 *
5424 * @param client The remote client to send the listing to.
5425 * @return False if an error occurred, true otherwise.
5426 */
5427 boolean viewServerGetFocusedWindow(Socket client) {
5428 if (isSystemSecure()) {
5429 return false;
5430 }
5431
5432 boolean result = true;
5433
5434 WindowState focusedWindow = getFocusedWindow();
5435
5436 BufferedWriter out = null;
5437
5438 // Any uncaught exception will crash the system process
5439 try {
5440 OutputStream clientStream = client.getOutputStream();
5441 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5442
5443 if(focusedWindow != null) {
5444 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5445 out.write(' ');
5446 out.append(focusedWindow.mAttrs.getTitle());
5447 }
5448 out.write('\n');
5449 out.flush();
5450 } catch (Exception e) {
5451 result = false;
5452 } finally {
5453 if (out != null) {
5454 try {
5455 out.close();
5456 } catch (IOException e) {
5457 result = false;
5458 }
5459 }
5460 }
5461
5462 return result;
5463 }
5464
5465 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005466 * Sends a command to a target window. The result of the command, if any, will be
5467 * written in the output stream of the specified socket.
5468 *
5469 * The parameters must follow this syntax:
5470 * windowHashcode extra
5471 *
5472 * Where XX is the length in characeters of the windowTitle.
5473 *
5474 * The first parameter is the target window. The window with the specified hashcode
5475 * will be the target. If no target can be found, nothing happens. The extra parameters
5476 * will be delivered to the target window and as parameters to the command itself.
5477 *
5478 * @param client The remote client to sent the result, if any, to.
5479 * @param command The command to execute.
5480 * @param parameters The command parameters.
5481 *
5482 * @return True if the command was successfully delivered, false otherwise. This does
5483 * not indicate whether the command itself was successful.
5484 */
5485 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005486 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005487 return false;
5488 }
5489
5490 boolean success = true;
5491 Parcel data = null;
5492 Parcel reply = null;
5493
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005494 BufferedWriter out = null;
5495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 // Any uncaught exception will crash the system process
5497 try {
5498 // Find the hashcode of the window
5499 int index = parameters.indexOf(' ');
5500 if (index == -1) {
5501 index = parameters.length();
5502 }
5503 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005504 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005505
5506 // Extract the command's parameter after the window description
5507 if (index < parameters.length()) {
5508 parameters = parameters.substring(index + 1);
5509 } else {
5510 parameters = "";
5511 }
5512
5513 final WindowManagerService.WindowState window = findWindow(hashCode);
5514 if (window == null) {
5515 return false;
5516 }
5517
5518 data = Parcel.obtain();
5519 data.writeInterfaceToken("android.view.IWindow");
5520 data.writeString(command);
5521 data.writeString(parameters);
5522 data.writeInt(1);
5523 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5524
5525 reply = Parcel.obtain();
5526
5527 final IBinder binder = window.mClient.asBinder();
5528 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5529 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5530
5531 reply.readException();
5532
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005533 if (!client.isOutputShutdown()) {
5534 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5535 out.write("DONE\n");
5536 out.flush();
5537 }
5538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005540 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005541 success = false;
5542 } finally {
5543 if (data != null) {
5544 data.recycle();
5545 }
5546 if (reply != null) {
5547 reply.recycle();
5548 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005549 if (out != null) {
5550 try {
5551 out.close();
5552 } catch (IOException e) {
5553
5554 }
5555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005556 }
5557
5558 return success;
5559 }
5560
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005561 public void addWindowChangeListener(WindowChangeListener listener) {
5562 synchronized(mWindowMap) {
5563 mWindowChangeListeners.add(listener);
5564 }
5565 }
5566
5567 public void removeWindowChangeListener(WindowChangeListener listener) {
5568 synchronized(mWindowMap) {
5569 mWindowChangeListeners.remove(listener);
5570 }
5571 }
5572
5573 private void notifyWindowsChanged() {
5574 WindowChangeListener[] windowChangeListeners;
5575 synchronized(mWindowMap) {
5576 if(mWindowChangeListeners.isEmpty()) {
5577 return;
5578 }
5579 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5580 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5581 }
5582 int N = windowChangeListeners.length;
5583 for(int i = 0; i < N; i++) {
5584 windowChangeListeners[i].windowsChanged();
5585 }
5586 }
5587
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005588 private void notifyFocusChanged() {
5589 WindowChangeListener[] windowChangeListeners;
5590 synchronized(mWindowMap) {
5591 if(mWindowChangeListeners.isEmpty()) {
5592 return;
5593 }
5594 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5595 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5596 }
5597 int N = windowChangeListeners.length;
5598 for(int i = 0; i < N; i++) {
5599 windowChangeListeners[i].focusChanged();
5600 }
5601 }
5602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005603 private WindowState findWindow(int hashCode) {
5604 if (hashCode == -1) {
5605 return getFocusedWindow();
5606 }
5607
5608 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005609 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005610 final int count = windows.size();
5611
5612 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005613 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005614 if (System.identityHashCode(w) == hashCode) {
5615 return w;
5616 }
5617 }
5618 }
5619
5620 return null;
5621 }
5622
5623 /*
5624 * Instruct the Activity Manager to fetch the current configuration and broadcast
5625 * that to config-changed listeners if appropriate.
5626 */
5627 void sendNewConfiguration() {
5628 try {
5629 mActivityManager.updateConfiguration(null);
5630 } catch (RemoteException e) {
5631 }
5632 }
Romain Guy06882f82009-06-10 13:36:04 -07005633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005634 public Configuration computeNewConfiguration() {
5635 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005636 Configuration config = computeNewConfigurationLocked();
5637 if (config == null && mWaitingForConfig) {
5638 // Nothing changed but we are waiting for something... stop that!
5639 mWaitingForConfig = false;
5640 performLayoutAndPlaceSurfacesLocked();
5641 }
5642 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005643 }
5644 }
Romain Guy06882f82009-06-10 13:36:04 -07005645
Dianne Hackbornc485a602009-03-24 22:39:49 -07005646 Configuration computeNewConfigurationLocked() {
5647 Configuration config = new Configuration();
5648 if (!computeNewConfigurationLocked(config)) {
5649 return null;
5650 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005651 return config;
5652 }
Romain Guy06882f82009-06-10 13:36:04 -07005653
Dianne Hackbornc485a602009-03-24 22:39:49 -07005654 boolean computeNewConfigurationLocked(Configuration config) {
5655 if (mDisplay == null) {
5656 return false;
5657 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005658
5659 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005660
5661 // Use the effective "visual" dimensions based on current rotation
5662 final boolean rotated = (mRotation == Surface.ROTATION_90
5663 || mRotation == Surface.ROTATION_270);
5664 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5665 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5666
Dianne Hackbornc485a602009-03-24 22:39:49 -07005667 int orientation = Configuration.ORIENTATION_SQUARE;
5668 if (dw < dh) {
5669 orientation = Configuration.ORIENTATION_PORTRAIT;
5670 } else if (dw > dh) {
5671 orientation = Configuration.ORIENTATION_LANDSCAPE;
5672 }
5673 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005674
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005675 DisplayMetrics dm = new DisplayMetrics();
5676 mDisplay.getMetrics(dm);
5677 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5678
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005679 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005680 // Note we only do this once because at this point we don't
5681 // expect the screen to change in this way at runtime, and want
5682 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005683 int longSize = dw;
5684 int shortSize = dh;
5685 if (longSize < shortSize) {
5686 int tmp = longSize;
5687 longSize = shortSize;
5688 shortSize = tmp;
5689 }
5690 longSize = (int)(longSize/dm.density);
5691 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005692
Dianne Hackborn723738c2009-06-25 19:48:04 -07005693 // These semi-magic numbers define our compatibility modes for
5694 // applications with different screens. Don't change unless you
5695 // make sure to test lots and lots of apps!
5696 if (longSize < 470) {
5697 // This is shorter than an HVGA normal density screen (which
5698 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005699 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5700 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005701 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005702 // What size is this screen screen?
5703 if (longSize >= 800 && shortSize >= 600) {
5704 // SVGA or larger screens at medium density are the point
5705 // at which we consider it to be an extra large screen.
5706 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005707 } else if (longSize >= 530 && shortSize >= 400) {
5708 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005709 // at which we consider it to be a large screen.
5710 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5711 } else {
5712 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005713
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005714 // If this screen is wider than normal HVGA, or taller
5715 // than FWVGA, then for old apps we want to run in size
5716 // compatibility mode.
5717 if (shortSize > 321 || longSize > 570) {
5718 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5719 }
5720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005721
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005722 // Is this a long screen?
5723 if (((longSize*3)/5) >= (shortSize-1)) {
5724 // Anything wider than WVGA (5:3) is considering to be long.
5725 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5726 } else {
5727 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5728 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005729 }
5730 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005731 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005732
Dianne Hackbornc485a602009-03-24 22:39:49 -07005733 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5734 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5735 mPolicy.adjustConfigurationLw(config);
5736 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005738
5739 // -------------------------------------------------------------
5740 // Drag and drop
5741 // -------------------------------------------------------------
5742
5743 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005744 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005745 if (DEBUG_DRAG) {
5746 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005747 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005748 + " asbinder=" + window.asBinder());
5749 }
5750
5751 final int callerPid = Binder.getCallingPid();
5752 final long origId = Binder.clearCallingIdentity();
5753 IBinder token = null;
5754
5755 try {
5756 synchronized (mWindowMap) {
5757 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005758 if (mDragState == null) {
5759 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5760 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5761 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005762 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005763 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005764 // TODO: preserve flags param in DragState
5765 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005766 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005767 token = mDragState.mToken = new Binder();
5768
5769 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005770 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5771 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005772 mH.sendMessageDelayed(msg, 5000);
5773 } else {
5774 Slog.w(TAG, "Drag already in progress");
5775 }
5776 } catch (Surface.OutOfResourcesException e) {
5777 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5778 if (mDragState != null) {
5779 mDragState.reset();
5780 mDragState = null;
5781 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005782 }
5783 }
5784 } finally {
5785 Binder.restoreCallingIdentity(origId);
5786 }
5787
5788 return token;
5789 }
5790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 // -------------------------------------------------------------
5792 // Input Events and Focus Management
5793 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005794
Jeff Brown349703e2010-06-22 01:27:15 -07005795 InputMonitor mInputMonitor = new InputMonitor();
5796
5797 /* Tracks the progress of input dispatch and ensures that input dispatch state
5798 * is kept in sync with changes in window focus, visibility, registration, and
5799 * other relevant Window Manager state transitions. */
5800 final class InputMonitor {
5801 // Current window with input focus for keys and other non-touch events. May be null.
5802 private WindowState mInputFocus;
5803
5804 // When true, prevents input dispatch from proceeding until set to false again.
5805 private boolean mInputDispatchFrozen;
5806
5807 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5808 private boolean mInputDispatchEnabled = true;
5809
Jeff Brown3a22cd92011-01-21 13:59:04 -08005810 // When true, need to call updateInputWindowsLw().
5811 private boolean mUpdateInputWindowsNeeded = true;
5812
Jeff Brown349703e2010-06-22 01:27:15 -07005813 // Temporary list of windows information to provide to the input dispatcher.
5814 private InputWindowList mTempInputWindows = new InputWindowList();
5815
5816 // Temporary input application object to provide to the input dispatcher.
5817 private InputApplication mTempInputApplication = new InputApplication();
5818
Jeff Brownb09abc12011-01-13 21:08:27 -08005819 // Set to true when the first input device configuration change notification
5820 // is received to indicate that the input devices are ready.
5821 private final Object mInputDevicesReadyMonitor = new Object();
5822 private boolean mInputDevicesReady;
5823
Jeff Brown349703e2010-06-22 01:27:15 -07005824 /* Notifies the window manager about a broken input channel.
5825 *
5826 * Called by the InputManager.
5827 */
Jeff Brown928e0542011-01-10 11:17:36 -08005828 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5829 if (inputWindowHandle == null) {
5830 return;
5831 }
5832
Jeff Brown349703e2010-06-22 01:27:15 -07005833 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005834 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005835 Slog.i(TAG, "WINDOW DIED " + windowState);
5836 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005837 }
5838 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005839
Jeff Brown519e0242010-09-15 15:18:56 -07005840 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005841 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005842 *
5843 * Called by the InputManager.
5844 */
Jeff Brown928e0542011-01-10 11:17:36 -08005845 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5846 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005847 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005848 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005849 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005850 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005851 if (windowState != null) {
5852 Slog.i(TAG, "Input event dispatching timed out sending to "
5853 + windowState.mAttrs.getTitle());
5854 appWindowToken = windowState.mAppToken;
5855 }
Jeff Brown349703e2010-06-22 01:27:15 -07005856 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005857 }
5858
Jeff Brown928e0542011-01-10 11:17:36 -08005859 if (appWindowToken == null && inputApplicationHandle != null) {
5860 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005861 Slog.i(TAG, "Input event dispatching timed out sending to application "
5862 + appWindowToken.stringName);
5863 }
Jeff Brown349703e2010-06-22 01:27:15 -07005864
Jeff Brown519e0242010-09-15 15:18:56 -07005865 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005866 try {
5867 // Notify the activity manager about the timeout and let it decide whether
5868 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005869 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005870 if (! abort) {
5871 // The activity manager declined to abort dispatching.
5872 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005873 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005874 }
Jeff Brown349703e2010-06-22 01:27:15 -07005875 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005876 }
5877 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005878 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005879 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005880
Chris Tatea32dcf72010-10-14 12:13:50 -07005881 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005882 final InputWindow inputWindow = windowList.add();
5883 inputWindow.inputChannel = mDragState.mServerChannel;
5884 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08005885 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07005886 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5887 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5888 inputWindow.visible = true;
5889 inputWindow.canReceiveKeys = false;
5890 inputWindow.hasFocus = true;
5891 inputWindow.hasWallpaper = false;
5892 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005893 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005894 inputWindow.ownerPid = Process.myPid();
5895 inputWindow.ownerUid = Process.myUid();
5896
5897 // The drag window covers the entire display
5898 inputWindow.frameLeft = 0;
5899 inputWindow.frameTop = 0;
5900 inputWindow.frameRight = mDisplay.getWidth();
5901 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005902
Jeff Brownfbf09772011-01-16 14:06:57 -08005903 // The drag window cannot receive new touches.
5904 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07005905 }
5906
Jeff Brown3a22cd92011-01-21 13:59:04 -08005907 public void setUpdateInputWindowsNeededLw() {
5908 mUpdateInputWindowsNeeded = true;
5909 }
5910
Jeff Brown349703e2010-06-22 01:27:15 -07005911 /* Updates the cached window information provided to the input dispatcher. */
5912 public void updateInputWindowsLw() {
Jeff Brown3a22cd92011-01-21 13:59:04 -08005913 if (!mUpdateInputWindowsNeeded) {
5914 return;
5915 }
5916 mUpdateInputWindowsNeeded = false;
5917
Jeff Brown349703e2010-06-22 01:27:15 -07005918 // Populate the input window list with information about all of the windows that
5919 // could potentially receive input.
5920 // As an optimization, we could try to prune the list of windows but this turns
5921 // out to be difficult because only the native code knows for sure which window
5922 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005923 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005924
5925 // If there's a drag in flight, provide a pseudowindow to catch drag input
5926 final boolean inDrag = (mDragState != null);
5927 if (inDrag) {
5928 if (DEBUG_DRAG) {
5929 Log.d(TAG, "Inserting drag window");
5930 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005931 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005932 }
5933
Jeff Brown7fbdc842010-06-17 20:52:56 -07005934 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005935 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005936 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005937 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005938 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005939 continue;
5940 }
5941
Jeff Brown349703e2010-06-22 01:27:15 -07005942 final int flags = child.mAttrs.flags;
5943 final int type = child.mAttrs.type;
5944
5945 final boolean hasFocus = (child == mInputFocus);
5946 final boolean isVisible = child.isVisibleLw();
5947 final boolean hasWallpaper = (child == mWallpaperTarget)
5948 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005949
5950 // If there's a drag in progress and 'child' is a potential drop target,
5951 // make sure it's been told about the drag
5952 if (inDrag && isVisible) {
5953 mDragState.sendDragStartedIfNeededLw(child);
5954 }
5955
Jeff Brown349703e2010-06-22 01:27:15 -07005956 // Add a window to our list of input windows.
5957 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005958 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005959 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005960 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005961 inputWindow.layoutParamsFlags = flags;
5962 inputWindow.layoutParamsType = type;
5963 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5964 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005965 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005966 inputWindow.hasFocus = hasFocus;
5967 inputWindow.hasWallpaper = hasWallpaper;
5968 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005969 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005970 inputWindow.ownerPid = child.mSession.mPid;
5971 inputWindow.ownerUid = child.mSession.mUid;
5972
5973 final Rect frame = child.mFrame;
5974 inputWindow.frameLeft = frame.left;
5975 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005976 inputWindow.frameRight = frame.right;
5977 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08005978
5979 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005980 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005981
Jeff Brown349703e2010-06-22 01:27:15 -07005982 // Send windows to native code.
5983 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005984
Jeff Brown349703e2010-06-22 01:27:15 -07005985 // Clear the list in preparation for the next round.
5986 // Also avoids keeping InputChannel objects referenced unnecessarily.
5987 mTempInputWindows.clear();
5988 }
Jeff Brownb09abc12011-01-13 21:08:27 -08005989
5990 /* Notifies that the input device configuration has changed. */
5991 public void notifyConfigurationChanged() {
5992 sendNewConfiguration();
5993
5994 synchronized (mInputDevicesReadyMonitor) {
5995 if (!mInputDevicesReady) {
5996 mInputDevicesReady = true;
5997 mInputDevicesReadyMonitor.notifyAll();
5998 }
5999 }
6000 }
6001
6002 /* Waits until the built-in input devices have been configured. */
6003 public boolean waitForInputDevicesReady(long timeoutMillis) {
6004 synchronized (mInputDevicesReadyMonitor) {
6005 if (!mInputDevicesReady) {
6006 try {
6007 mInputDevicesReadyMonitor.wait(timeoutMillis);
6008 } catch (InterruptedException ex) {
6009 }
6010 }
6011 return mInputDevicesReady;
6012 }
6013 }
6014
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006015 /* Notifies that the lid switch changed state. */
6016 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6017 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6018 }
6019
Jeff Brown349703e2010-06-22 01:27:15 -07006020 /* Provides an opportunity for the window manager policy to intercept early key
6021 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006022 public int interceptKeyBeforeQueueing(
6023 KeyEvent event, int policyFlags, boolean isScreenOn) {
6024 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006025 }
6026
6027 /* Provides an opportunity for the window manager policy to process a key before
6028 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006029 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006030 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006031 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006032 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006033 }
6034
Jeff Brown3915bb82010-11-05 15:02:16 -07006035 /* Provides an opportunity for the window manager policy to process a key that
6036 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006037 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006038 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006039 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006040 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006041 }
6042
Jeff Brown349703e2010-06-22 01:27:15 -07006043 /* Called when the current input focus changes.
6044 * Layer assignment is assumed to be complete by the time this is called.
6045 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006046 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006047 if (DEBUG_INPUT) {
6048 Slog.d(TAG, "Input focus has changed to " + newWindow);
6049 }
6050
6051 if (newWindow != mInputFocus) {
6052 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006053 // Displaying a window implicitly causes dispatching to be unpaused.
6054 // This is to protect against bugs if someone pauses dispatching but
6055 // forgets to resume.
6056 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006057 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006058
Jeff Brown349703e2010-06-22 01:27:15 -07006059 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006060 setUpdateInputWindowsNeededLw();
6061
6062 if (updateInputWindows) {
6063 updateInputWindowsLw();
6064 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07006065 }
6066 }
6067
Jeff Brown349703e2010-06-22 01:27:15 -07006068 public void setFocusedAppLw(AppWindowToken newApp) {
6069 // Focused app has changed.
6070 if (newApp == null) {
6071 mInputManager.setFocusedApplication(null);
6072 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006073 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006074 mTempInputApplication.name = newApp.toString();
6075 mTempInputApplication.dispatchingTimeoutNanos =
6076 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006077
Jeff Brown349703e2010-06-22 01:27:15 -07006078 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006079
6080 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006081 }
6082 }
6083
Jeff Brown349703e2010-06-22 01:27:15 -07006084 public void pauseDispatchingLw(WindowToken window) {
6085 if (! window.paused) {
6086 if (DEBUG_INPUT) {
6087 Slog.v(TAG, "Pausing WindowToken " + window);
6088 }
6089
6090 window.paused = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006091 setUpdateInputWindowsNeededLw();
Jeff Brown349703e2010-06-22 01:27:15 -07006092 updateInputWindowsLw();
6093 }
6094 }
6095
6096 public void resumeDispatchingLw(WindowToken window) {
6097 if (window.paused) {
6098 if (DEBUG_INPUT) {
6099 Slog.v(TAG, "Resuming WindowToken " + window);
6100 }
6101
6102 window.paused = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006103 setUpdateInputWindowsNeededLw();
Jeff Brown349703e2010-06-22 01:27:15 -07006104 updateInputWindowsLw();
6105 }
6106 }
6107
6108 public void freezeInputDispatchingLw() {
6109 if (! mInputDispatchFrozen) {
6110 if (DEBUG_INPUT) {
6111 Slog.v(TAG, "Freezing input dispatching");
6112 }
6113
6114 mInputDispatchFrozen = true;
6115 updateInputDispatchModeLw();
6116 }
6117 }
6118
6119 public void thawInputDispatchingLw() {
6120 if (mInputDispatchFrozen) {
6121 if (DEBUG_INPUT) {
6122 Slog.v(TAG, "Thawing input dispatching");
6123 }
6124
6125 mInputDispatchFrozen = false;
6126 updateInputDispatchModeLw();
6127 }
6128 }
6129
6130 public void setEventDispatchingLw(boolean enabled) {
6131 if (mInputDispatchEnabled != enabled) {
6132 if (DEBUG_INPUT) {
6133 Slog.v(TAG, "Setting event dispatching to " + enabled);
6134 }
6135
6136 mInputDispatchEnabled = enabled;
6137 updateInputDispatchModeLw();
6138 }
6139 }
6140
6141 private void updateInputDispatchModeLw() {
6142 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6143 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07006144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 public void pauseKeyDispatching(IBinder _token) {
6147 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6148 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006149 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 }
6151
6152 synchronized (mWindowMap) {
6153 WindowToken token = mTokenMap.get(_token);
6154 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006155 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006156 }
6157 }
6158 }
6159
6160 public void resumeKeyDispatching(IBinder _token) {
6161 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6162 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006163 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 }
6165
6166 synchronized (mWindowMap) {
6167 WindowToken token = mTokenMap.get(_token);
6168 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006169 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 }
6171 }
6172 }
6173
6174 public void setEventDispatching(boolean enabled) {
6175 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6176 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006177 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006178 }
6179
6180 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006181 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006182 }
6183 }
Romain Guy06882f82009-06-10 13:36:04 -07006184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006185 /**
6186 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006187 * Even when sync is false, this method may block while waiting for current
6188 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006189 *
6190 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 * {@link SystemClock#uptimeMillis()} as the timebase.)
6192 * @param sync If true, wait for the event to be completed before returning to the caller.
6193 * @return Returns true if event was dispatched, false if it was dropped for any reason
6194 */
6195 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6196 long downTime = ev.getDownTime();
6197 long eventTime = ev.getEventTime();
6198
6199 int action = ev.getAction();
6200 int code = ev.getKeyCode();
6201 int repeatCount = ev.getRepeatCount();
6202 int metaState = ev.getMetaState();
6203 int deviceId = ev.getDeviceId();
6204 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006205 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006206 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006207
6208 if (source == InputDevice.SOURCE_UNKNOWN) {
6209 source = InputDevice.SOURCE_KEYBOARD;
6210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006211
6212 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6213 if (downTime == 0) downTime = eventTime;
6214
6215 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006216 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006217
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006218 final int pid = Binder.getCallingPid();
6219 final int uid = Binder.getCallingUid();
6220 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006221
Jeff Brownbbda99d2010-07-28 15:48:59 -07006222 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6223 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6224 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6225 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006226
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006227 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006228 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 }
6230
6231 /**
6232 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006233 * Even when sync is false, this method may block while waiting for current
6234 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006235 *
6236 * @param ev A motion event describing the pointer (touch) action. (As noted in
6237 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006238 * {@link SystemClock#uptimeMillis()} as the timebase.)
6239 * @param sync If true, wait for the event to be completed before returning to the caller.
6240 * @return Returns true if event was dispatched, false if it was dropped for any reason
6241 */
6242 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006243 final int pid = Binder.getCallingPid();
6244 final int uid = Binder.getCallingUid();
6245 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006246
Jeff Brownc5ed5912010-07-14 18:48:53 -07006247 MotionEvent newEvent = MotionEvent.obtain(ev);
6248 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6249 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6250 }
6251
Jeff Brownbbda99d2010-07-28 15:48:59 -07006252 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6253 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6254 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6255 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006256
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006257 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006258 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006259 }
Romain Guy06882f82009-06-10 13:36:04 -07006260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006261 /**
6262 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006263 * Even when sync is false, this method may block while waiting for current
6264 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006265 *
6266 * @param ev A motion event describing the trackball action. (As noted in
6267 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 * {@link SystemClock#uptimeMillis()} as the timebase.)
6269 * @param sync If true, wait for the event to be completed before returning to the caller.
6270 * @return Returns true if event was dispatched, false if it was dropped for any reason
6271 */
6272 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006273 final int pid = Binder.getCallingPid();
6274 final int uid = Binder.getCallingUid();
6275 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006276
Jeff Brownc5ed5912010-07-14 18:48:53 -07006277 MotionEvent newEvent = MotionEvent.obtain(ev);
6278 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6279 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6280 }
6281
Jeff Brownbbda99d2010-07-28 15:48:59 -07006282 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6283 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6284 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6285 INJECTION_TIMEOUT_MILLIS);
6286
6287 Binder.restoreCallingIdentity(ident);
6288 return reportInjectionResult(result);
6289 }
6290
6291 /**
6292 * Inject an input event into the UI without waiting for dispatch to commence.
6293 * This variant is useful for fire-and-forget input event injection. It does not
6294 * block any longer than it takes to enqueue the input event.
6295 *
6296 * @param ev An input event. (Be sure to set the input source correctly.)
6297 * @return Returns true if event was dispatched, false if it was dropped for any reason
6298 */
6299 public boolean injectInputEventNoWait(InputEvent ev) {
6300 final int pid = Binder.getCallingPid();
6301 final int uid = Binder.getCallingUid();
6302 final long ident = Binder.clearCallingIdentity();
6303
6304 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6305 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6306 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006307
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006308 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006309 return reportInjectionResult(result);
6310 }
6311
6312 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006313 switch (result) {
6314 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6315 Slog.w(TAG, "Input event injection permission denied.");
6316 throw new SecurityException(
6317 "Injecting to another application requires INJECT_EVENTS permission");
6318 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006319 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006320 return true;
6321 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6322 Slog.w(TAG, "Input event injection timed out.");
6323 return false;
6324 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6325 default:
6326 Slog.w(TAG, "Input event injection failed.");
6327 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 }
Romain Guy06882f82009-06-10 13:36:04 -07006330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 private WindowState getFocusedWindow() {
6332 synchronized (mWindowMap) {
6333 return getFocusedWindowLocked();
6334 }
6335 }
6336
6337 private WindowState getFocusedWindowLocked() {
6338 return mCurrentFocus;
6339 }
Romain Guy06882f82009-06-10 13:36:04 -07006340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006341 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006342 if (!mInputMonitor.waitForInputDevicesReady(
6343 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6344 Slog.w(TAG, "Devices still not ready after waiting "
6345 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6346 + " milliseconds before attempting to detect safe mode.");
6347 }
6348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 mSafeMode = mPolicy.detectSafeMode();
6350 return mSafeMode;
6351 }
Romain Guy06882f82009-06-10 13:36:04 -07006352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006354 synchronized(mWindowMap) {
6355 if (mDisplay != null) {
6356 throw new IllegalStateException("Display already initialized");
6357 }
6358 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6359 mDisplay = wm.getDefaultDisplay();
6360 mInitialDisplayWidth = mDisplay.getWidth();
6361 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006362 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6363 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006364 }
6365
6366 try {
6367 mActivityManager.updateConfiguration(null);
6368 } catch (RemoteException e) {
6369 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006370
6371 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006372 }
6373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 // -------------------------------------------------------------
6375 // Client Session State
6376 // -------------------------------------------------------------
6377
6378 private final class Session extends IWindowSession.Stub
6379 implements IBinder.DeathRecipient {
6380 final IInputMethodClient mClient;
6381 final IInputContext mInputContext;
6382 final int mUid;
6383 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006384 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 SurfaceSession mSurfaceSession;
6386 int mNumWindow = 0;
6387 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 public Session(IInputMethodClient client, IInputContext inputContext) {
6390 mClient = client;
6391 mInputContext = inputContext;
6392 mUid = Binder.getCallingUid();
6393 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006394 StringBuilder sb = new StringBuilder();
6395 sb.append("Session{");
6396 sb.append(Integer.toHexString(System.identityHashCode(this)));
6397 sb.append(" uid ");
6398 sb.append(mUid);
6399 sb.append("}");
6400 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 synchronized (mWindowMap) {
6403 if (mInputMethodManager == null && mHaveInputMethods) {
6404 IBinder b = ServiceManager.getService(
6405 Context.INPUT_METHOD_SERVICE);
6406 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6407 }
6408 }
6409 long ident = Binder.clearCallingIdentity();
6410 try {
6411 // Note: it is safe to call in to the input method manager
6412 // here because we are not holding our lock.
6413 if (mInputMethodManager != null) {
6414 mInputMethodManager.addClient(client, inputContext,
6415 mUid, mPid);
6416 } else {
6417 client.setUsingInputMethod(false);
6418 }
6419 client.asBinder().linkToDeath(this, 0);
6420 } catch (RemoteException e) {
6421 // The caller has died, so we can just forget about this.
6422 try {
6423 if (mInputMethodManager != null) {
6424 mInputMethodManager.removeClient(client);
6425 }
6426 } catch (RemoteException ee) {
6427 }
6428 } finally {
6429 Binder.restoreCallingIdentity(ident);
6430 }
6431 }
Romain Guy06882f82009-06-10 13:36:04 -07006432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 @Override
6434 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6435 throws RemoteException {
6436 try {
6437 return super.onTransact(code, data, reply, flags);
6438 } catch (RuntimeException e) {
6439 // Log all 'real' exceptions thrown to the caller
6440 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006441 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 }
6443 throw e;
6444 }
6445 }
6446
6447 public void binderDied() {
6448 // Note: it is safe to call in to the input method manager
6449 // here because we are not holding our lock.
6450 try {
6451 if (mInputMethodManager != null) {
6452 mInputMethodManager.removeClient(mClient);
6453 }
6454 } catch (RemoteException e) {
6455 }
6456 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006457 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 mClientDead = true;
6459 killSessionLocked();
6460 }
6461 }
6462
6463 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006464 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6465 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6466 outInputChannel);
6467 }
6468
6469 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006471 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 }
Romain Guy06882f82009-06-10 13:36:04 -07006473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 public void remove(IWindow window) {
6475 removeWindow(this, window);
6476 }
Romain Guy06882f82009-06-10 13:36:04 -07006477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6479 int requestedWidth, int requestedHeight, int viewFlags,
6480 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006481 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006482 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6483 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006484 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006485 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006486 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6487 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 }
Romain Guy06882f82009-06-10 13:36:04 -07006489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 public void setTransparentRegion(IWindow window, Region region) {
6491 setTransparentRegionWindow(this, window, region);
6492 }
Romain Guy06882f82009-06-10 13:36:04 -07006493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006495 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006497 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 }
Romain Guy06882f82009-06-10 13:36:04 -07006499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006500 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6501 getWindowDisplayFrame(this, window, outDisplayFrame);
6502 }
Romain Guy06882f82009-06-10 13:36:04 -07006503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006504 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006505 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006506 TAG, "IWindow finishDrawing called for " + window);
6507 finishDrawingWindow(this, window);
6508 }
6509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 public void setInTouchMode(boolean mode) {
6511 synchronized(mWindowMap) {
6512 mInTouchMode = mode;
6513 }
6514 }
6515
6516 public boolean getInTouchMode() {
6517 synchronized(mWindowMap) {
6518 return mInTouchMode;
6519 }
6520 }
6521
6522 public boolean performHapticFeedback(IWindow window, int effectId,
6523 boolean always) {
6524 synchronized(mWindowMap) {
6525 long ident = Binder.clearCallingIdentity();
6526 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006527 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006528 windowForClientLocked(this, window, true),
6529 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006530 } finally {
6531 Binder.restoreCallingIdentity(ident);
6532 }
6533 }
6534 }
Romain Guy06882f82009-06-10 13:36:04 -07006535
Christopher Tatea53146c2010-09-07 11:57:52 -07006536 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006537 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006538 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006539 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006540 width, height, outSurface);
6541 }
6542
6543 public boolean performDrag(IWindow window, IBinder dragToken,
6544 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6545 ClipData data) {
6546 if (DEBUG_DRAG) {
6547 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6548 }
6549
6550 synchronized (mWindowMap) {
6551 if (mDragState == null) {
6552 Slog.w(TAG, "No drag prepared");
6553 throw new IllegalStateException("performDrag() without prepareDrag()");
6554 }
6555
6556 if (dragToken != mDragState.mToken) {
6557 Slog.w(TAG, "Performing mismatched drag");
6558 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6559 }
6560
6561 WindowState callingWin = windowForClientLocked(null, window, false);
6562 if (callingWin == null) {
6563 Slog.w(TAG, "Bad requesting window " + window);
6564 return false; // !!! TODO: throw here?
6565 }
6566
6567 // !!! TODO: if input is not still focused on the initiating window, fail
6568 // the drag initiation (e.g. an alarm window popped up just as the application
6569 // called performDrag()
6570
6571 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6572
Christopher Tate2c095f32010-10-04 14:13:40 -07006573 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6574 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006575
Chris Tateb478f462010-10-15 16:02:26 -07006576 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6577 // the actual drag event dispatch stuff in the dragstate
6578
Christopher Tatea53146c2010-09-07 11:57:52 -07006579 mDragState.register();
Jeff Brown3a22cd92011-01-21 13:59:04 -08006580 mInputMonitor.setUpdateInputWindowsNeededLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006581 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006582 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6583 mDragState.mServerChannel)) {
6584 Slog.e(TAG, "Unable to transfer touch focus");
6585 mDragState.unregister();
6586 mDragState = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006587 mInputMonitor.setUpdateInputWindowsNeededLw();
Chris Tateef70a072010-10-22 19:10:34 -07006588 mInputMonitor.updateInputWindowsLw();
6589 return false;
6590 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006591
6592 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006593 mDragState.mCurrentX = touchX;
6594 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006595 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006596
6597 // remember the thumb offsets for later
6598 mDragState.mThumbOffsetX = thumbCenterX;
6599 mDragState.mThumbOffsetY = thumbCenterY;
6600
6601 // Make the surface visible at the proper location
6602 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006603 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006604 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006605 try {
6606 surface.setPosition((int)(touchX - thumbCenterX),
6607 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006608 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006609 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006610 surface.show();
6611 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006612 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006613 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006614 }
6615 }
6616
6617 return true; // success!
6618 }
6619
Chris Tated4533f12010-10-19 15:15:08 -07006620 public void reportDropResult(IWindow window, boolean consumed) {
6621 IBinder token = window.asBinder();
6622 if (DEBUG_DRAG) {
6623 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6624 }
6625
6626 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006627 long ident = Binder.clearCallingIdentity();
6628 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006629 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006630 Slog.w(TAG, "Invalid drop-result claim by " + window);
6631 throw new IllegalStateException("reportDropResult() by non-recipient");
6632 }
6633
6634 // The right window has responded, even if it's no longer around,
6635 // so be sure to halt the timeout even if the later WindowState
6636 // lookup fails.
6637 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6638 WindowState callingWin = windowForClientLocked(null, window, false);
6639 if (callingWin == null) {
6640 Slog.w(TAG, "Bad result-reporting window " + window);
6641 return; // !!! TODO: throw here?
6642 }
6643
6644 mDragState.mDragResult = consumed;
6645 mDragState.endDragLw();
6646 } finally {
6647 Binder.restoreCallingIdentity(ident);
Chris Tated4533f12010-10-19 15:15:08 -07006648 }
Chris Tated4533f12010-10-19 15:15:08 -07006649 }
6650 }
6651
Christopher Tatea53146c2010-09-07 11:57:52 -07006652 public void dragRecipientEntered(IWindow window) {
6653 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006654 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006655 }
6656 }
6657
6658 public void dragRecipientExited(IWindow window) {
6659 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006660 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006661 }
6662 }
6663
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006664 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006665 synchronized(mWindowMap) {
6666 long ident = Binder.clearCallingIdentity();
6667 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006668 setWindowWallpaperPositionLocked(
6669 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006670 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006671 } finally {
6672 Binder.restoreCallingIdentity(ident);
6673 }
6674 }
6675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006676
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006677 public void wallpaperOffsetsComplete(IBinder window) {
6678 WindowManagerService.this.wallpaperOffsetsComplete(window);
6679 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006680
Dianne Hackborn75804932009-10-20 20:15:20 -07006681 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6682 int z, Bundle extras, boolean sync) {
6683 synchronized(mWindowMap) {
6684 long ident = Binder.clearCallingIdentity();
6685 try {
6686 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006687 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006688 action, x, y, z, extras, sync);
6689 } finally {
6690 Binder.restoreCallingIdentity(ident);
6691 }
6692 }
6693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006694
Dianne Hackborn75804932009-10-20 20:15:20 -07006695 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6696 WindowManagerService.this.wallpaperCommandComplete(window, result);
6697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 void windowAddedLocked() {
6700 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006701 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 TAG, "First window added to " + this + ", creating SurfaceSession");
6703 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006704 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006705 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 mSessions.add(this);
6707 }
6708 mNumWindow++;
6709 }
6710
6711 void windowRemovedLocked() {
6712 mNumWindow--;
6713 killSessionLocked();
6714 }
Romain Guy06882f82009-06-10 13:36:04 -07006715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 void killSessionLocked() {
6717 if (mNumWindow <= 0 && mClientDead) {
6718 mSessions.remove(this);
6719 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006720 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006721 TAG, "Last window removed from " + this
6722 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006723 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006724 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 try {
6726 mSurfaceSession.kill();
6727 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006728 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729 + mSurfaceSession + " in session " + this
6730 + ": " + e.toString());
6731 }
6732 mSurfaceSession = null;
6733 }
6734 }
6735 }
Romain Guy06882f82009-06-10 13:36:04 -07006736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006738 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6739 pw.print(" mClientDead="); pw.print(mClientDead);
6740 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006741 }
6742
6743 @Override
6744 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006745 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006746 }
6747 }
6748
6749 // -------------------------------------------------------------
6750 // Client Window State
6751 // -------------------------------------------------------------
6752
6753 private final class WindowState implements WindowManagerPolicy.WindowState {
6754 final Session mSession;
6755 final IWindow mClient;
6756 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006757 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 AppWindowToken mAppToken;
6759 AppWindowToken mTargetAppToken;
6760 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6761 final DeathRecipient mDeathRecipient;
6762 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006763 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764 final int mBaseLayer;
6765 final int mSubLayer;
6766 final boolean mLayoutAttached;
6767 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006768 final boolean mIsWallpaper;
6769 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006770 int mViewVisibility;
6771 boolean mPolicyVisibility = true;
6772 boolean mPolicyVisibilityAfterAnim = true;
6773 boolean mAppFreezing;
6774 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006775 boolean mReportDestroySurface;
6776 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006777 boolean mAttachedHidden; // is our parent window hidden?
6778 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006779 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 int mRequestedWidth;
6781 int mRequestedHeight;
6782 int mLastRequestedWidth;
6783 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 int mLayer;
6785 int mAnimLayer;
6786 int mLastLayer;
6787 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006788 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006789 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006790
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006791 int mLayoutSeq = -1;
6792
6793 Configuration mConfiguration = null;
6794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006795 // Actual frame shown on-screen (may be modified by animation)
6796 final Rect mShownFrame = new Rect();
6797 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006799 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006800 * Set when we have changed the size of the surface, to know that
6801 * we must tell them application to resize (and thus redraw itself).
6802 */
6803 boolean mSurfaceResized;
6804
6805 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 * Insets that determine the actually visible area
6807 */
6808 final Rect mVisibleInsets = new Rect();
6809 final Rect mLastVisibleInsets = new Rect();
6810 boolean mVisibleInsetsChanged;
6811
6812 /**
6813 * Insets that are covered by system windows
6814 */
6815 final Rect mContentInsets = new Rect();
6816 final Rect mLastContentInsets = new Rect();
6817 boolean mContentInsetsChanged;
6818
6819 /**
6820 * Set to true if we are waiting for this window to receive its
6821 * given internal insets before laying out other windows based on it.
6822 */
6823 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 /**
6826 * These are the content insets that were given during layout for
6827 * this window, to be applied to windows behind it.
6828 */
6829 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006831 /**
6832 * These are the visible insets that were given during layout for
6833 * this window, to be applied to windows behind it.
6834 */
6835 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006837 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006838 * This is the given touchable area relative to the window frame, or null if none.
6839 */
6840 final Region mGivenTouchableRegion = new Region();
6841
6842 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 * Flag indicating whether the touchable region should be adjusted by
6844 * the visible insets; if false the area outside the visible insets is
6845 * NOT touchable, so we must use those to adjust the frame during hit
6846 * tests.
6847 */
6848 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006850 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006851 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6853 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6854 float mHScale=1, mVScale=1;
6855 float mLastHScale=1, mLastVScale=1;
6856 final Matrix mTmpMatrix = new Matrix();
6857
6858 // "Real" frame that the application sees.
6859 final Rect mFrame = new Rect();
6860 final Rect mLastFrame = new Rect();
6861
6862 final Rect mContainingFrame = new Rect();
6863 final Rect mDisplayFrame = new Rect();
6864 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006865 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 final Rect mVisibleFrame = new Rect();
6867
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006868 boolean mContentChanged;
6869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 float mShownAlpha = 1;
6871 float mAlpha = 1;
6872 float mLastAlpha = 1;
6873
6874 // Set to true if, when the window gets displayed, it should perform
6875 // an enter animation.
6876 boolean mEnterAnimationPending;
6877
6878 // Currently running animation.
6879 boolean mAnimating;
6880 boolean mLocalAnimating;
6881 Animation mAnimation;
6882 boolean mAnimationIsEntrance;
6883 boolean mHasTransformation;
6884 boolean mHasLocalTransformation;
6885 final Transformation mTransformation = new Transformation();
6886
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006887 // If a window showing a wallpaper: the requested offset for the
6888 // wallpaper; if a wallpaper window: the currently applied offset.
6889 float mWallpaperX = -1;
6890 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006891
6892 // If a window showing a wallpaper: what fraction of the offset
6893 // range corresponds to a full virtual screen.
6894 float mWallpaperXStep = -1;
6895 float mWallpaperYStep = -1;
6896
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006897 // Wallpaper windows: pixels offset based on above variables.
6898 int mXOffset;
6899 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 // This is set after IWindowSession.relayout() has been called at
6902 // least once for the window. It allows us to detect the situation
6903 // where we don't yet have a surface, but should have one soon, so
6904 // we can give the window focus before waiting for the relayout.
6905 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 // This is set after the Surface has been created but before the
6908 // window has been drawn. During this time the surface is hidden.
6909 boolean mDrawPending;
6910
6911 // This is set after the window has finished drawing for the first
6912 // time but before its surface is shown. The surface will be
6913 // displayed when the next layout is run.
6914 boolean mCommitDrawPending;
6915
6916 // This is set during the time after the window's drawing has been
6917 // committed, and before its surface is actually shown. It is used
6918 // to delay showing the surface until all windows in a token are ready
6919 // to be shown.
6920 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006922 // Set when the window has been shown in the screen the first time.
6923 boolean mHasDrawn;
6924
6925 // Currently running an exit animation?
6926 boolean mExiting;
6927
6928 // Currently on the mDestroySurface list?
6929 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006931 // Completely remove from window manager after exit animation?
6932 boolean mRemoveOnExit;
6933
6934 // Set when the orientation is changing and this window has not yet
6935 // been updated for the new orientation.
6936 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 // Is this window now (or just being) removed?
6939 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006940
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006941 // Temp for keeping track of windows that have been removed when
6942 // rebuilding window list.
6943 boolean mRebuilding;
6944
Dianne Hackborn16064f92010-03-25 00:47:24 -07006945 // For debugging, this is the last information given to the surface flinger.
6946 boolean mSurfaceShown;
6947 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6948 int mSurfaceLayer;
6949 float mSurfaceAlpha;
6950
Jeff Brown928e0542011-01-10 11:17:36 -08006951 // Input channel and input window handle used by the input dispatcher.
6952 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006953 InputChannel mInputChannel;
6954
Mattias Petersson1622eee2010-12-21 10:15:11 +01006955 // Used to improve performance of toString()
6956 String mStringNameCache;
6957 CharSequence mLastTitle;
6958 boolean mWasPaused;
6959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006960 WindowState(Session s, IWindow c, WindowToken token,
6961 WindowState attachedWindow, WindowManager.LayoutParams a,
6962 int viewVisibility) {
6963 mSession = s;
6964 mClient = c;
6965 mToken = token;
6966 mAttrs.copyFrom(a);
6967 mViewVisibility = viewVisibility;
6968 DeathRecipient deathRecipient = new DeathRecipient();
6969 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006970 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006971 TAG, "Window " + this + " client=" + c.asBinder()
6972 + " token=" + token + " (" + mAttrs.token + ")");
6973 try {
6974 c.asBinder().linkToDeath(deathRecipient, 0);
6975 } catch (RemoteException e) {
6976 mDeathRecipient = null;
6977 mAttachedWindow = null;
6978 mLayoutAttached = false;
6979 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006980 mIsWallpaper = false;
6981 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006982 mBaseLayer = 0;
6983 mSubLayer = 0;
6984 return;
6985 }
6986 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006988 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6989 mAttrs.type <= LAST_SUB_WINDOW)) {
6990 // The multiplier here is to reserve space for multiple
6991 // windows in the same type layer.
6992 mBaseLayer = mPolicy.windowTypeToLayerLw(
6993 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6994 + TYPE_LAYER_OFFSET;
6995 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6996 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006997 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006998 mAttachedWindow.mChildWindows.add(this);
6999 mLayoutAttached = mAttrs.type !=
7000 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7001 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7002 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007003 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7004 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 } else {
7006 // The multiplier here is to reserve space for multiple
7007 // windows in the same type layer.
7008 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7009 * TYPE_LAYER_MULTIPLIER
7010 + TYPE_LAYER_OFFSET;
7011 mSubLayer = 0;
7012 mAttachedWindow = null;
7013 mLayoutAttached = false;
7014 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7015 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007016 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7017 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 }
7019
7020 WindowState appWin = this;
7021 while (appWin.mAttachedWindow != null) {
7022 appWin = mAttachedWindow;
7023 }
7024 WindowToken appToken = appWin.mToken;
7025 while (appToken.appWindowToken == null) {
7026 WindowToken parent = mTokenMap.get(appToken.token);
7027 if (parent == null || appToken == parent) {
7028 break;
7029 }
7030 appToken = parent;
7031 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007032 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007033 mAppToken = appToken.appWindowToken;
7034
7035 mSurface = null;
7036 mRequestedWidth = 0;
7037 mRequestedHeight = 0;
7038 mLastRequestedWidth = 0;
7039 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007040 mXOffset = 0;
7041 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007042 mLayer = 0;
7043 mAnimLayer = 0;
7044 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007045 mInputWindowHandle = new InputWindowHandle(
7046 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007047 }
7048
7049 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007050 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007051 TAG, "Attaching " + this + " token=" + mToken
7052 + ", list=" + mToken.windows);
7053 mSession.windowAddedLocked();
7054 }
7055
7056 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7057 mHaveFrame = true;
7058
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007059 final Rect container = mContainingFrame;
7060 container.set(pf);
7061
7062 final Rect display = mDisplayFrame;
7063 display.set(df);
7064
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007065 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007066 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007067 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7068 display.intersect(mCompatibleScreenFrame);
7069 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007070 }
7071
7072 final int pw = container.right - container.left;
7073 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074
7075 int w,h;
7076 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7077 w = mAttrs.width < 0 ? pw : mAttrs.width;
7078 h = mAttrs.height< 0 ? ph : mAttrs.height;
7079 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007080 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7081 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007082 }
Romain Guy06882f82009-06-10 13:36:04 -07007083
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007084 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007085 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7086 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007087 mParentFrame.set(pf);
7088 mContentChanged = true;
7089 }
7090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 final Rect content = mContentFrame;
7092 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 final Rect visible = mVisibleFrame;
7095 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007098 final int fw = frame.width();
7099 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7102 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7103
7104 Gravity.apply(mAttrs.gravity, w, h, container,
7105 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7106 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7107
7108 //System.out.println("Out: " + mFrame);
7109
7110 // Now make sure the window fits in the overall display.
7111 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007113 // Make sure the content and visible frames are inside of the
7114 // final window frame.
7115 if (content.left < frame.left) content.left = frame.left;
7116 if (content.top < frame.top) content.top = frame.top;
7117 if (content.right > frame.right) content.right = frame.right;
7118 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7119 if (visible.left < frame.left) visible.left = frame.left;
7120 if (visible.top < frame.top) visible.top = frame.top;
7121 if (visible.right > frame.right) visible.right = frame.right;
7122 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007124 final Rect contentInsets = mContentInsets;
7125 contentInsets.left = content.left-frame.left;
7126 contentInsets.top = content.top-frame.top;
7127 contentInsets.right = frame.right-content.right;
7128 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 final Rect visibleInsets = mVisibleInsets;
7131 visibleInsets.left = visible.left-frame.left;
7132 visibleInsets.top = visible.top-frame.top;
7133 visibleInsets.right = frame.right-visible.right;
7134 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007135
Dianne Hackborn284ac932009-08-28 10:34:25 -07007136 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7137 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007138 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007139 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 if (localLOGV) {
7142 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7143 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007144 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 + mRequestedWidth + ", mRequestedheight="
7146 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7147 + "): frame=" + mFrame.toShortString()
7148 + " ci=" + contentInsets.toShortString()
7149 + " vi=" + visibleInsets.toShortString());
7150 //}
7151 }
7152 }
Romain Guy06882f82009-06-10 13:36:04 -07007153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154 public Rect getFrameLw() {
7155 return mFrame;
7156 }
7157
7158 public Rect getShownFrameLw() {
7159 return mShownFrame;
7160 }
7161
7162 public Rect getDisplayFrameLw() {
7163 return mDisplayFrame;
7164 }
7165
7166 public Rect getContentFrameLw() {
7167 return mContentFrame;
7168 }
7169
7170 public Rect getVisibleFrameLw() {
7171 return mVisibleFrame;
7172 }
7173
7174 public boolean getGivenInsetsPendingLw() {
7175 return mGivenInsetsPending;
7176 }
7177
7178 public Rect getGivenContentInsetsLw() {
7179 return mGivenContentInsets;
7180 }
Romain Guy06882f82009-06-10 13:36:04 -07007181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182 public Rect getGivenVisibleInsetsLw() {
7183 return mGivenVisibleInsets;
7184 }
Romain Guy06882f82009-06-10 13:36:04 -07007185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007186 public WindowManager.LayoutParams getAttrs() {
7187 return mAttrs;
7188 }
7189
7190 public int getSurfaceLayer() {
7191 return mLayer;
7192 }
Romain Guy06882f82009-06-10 13:36:04 -07007193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 public IApplicationToken getAppToken() {
7195 return mAppToken != null ? mAppToken.appToken : null;
7196 }
Jeff Brown349703e2010-06-22 01:27:15 -07007197
7198 public long getInputDispatchingTimeoutNanos() {
7199 return mAppToken != null
7200 ? mAppToken.inputDispatchingTimeoutNanos
7201 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7202 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203
7204 public boolean hasAppShownWindows() {
7205 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7206 }
7207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007208 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007209 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007210 TAG, "Setting animation in " + this + ": " + anim);
7211 mAnimating = false;
7212 mLocalAnimating = false;
7213 mAnimation = anim;
7214 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7215 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7216 }
7217
7218 public void clearAnimation() {
7219 if (mAnimation != null) {
7220 mAnimating = true;
7221 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007222 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 mAnimation = null;
7224 }
7225 }
Romain Guy06882f82009-06-10 13:36:04 -07007226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007227 Surface createSurfaceLocked() {
7228 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007229 mReportDestroySurface = false;
7230 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 mDrawPending = true;
7232 mCommitDrawPending = false;
7233 mReadyToShow = false;
7234 if (mAppToken != null) {
7235 mAppToken.allDrawn = false;
7236 }
7237
7238 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239
7240 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7241 flags |= Surface.SECURE;
7242 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007243 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 TAG, "Creating surface in session "
7245 + mSession.mSurfaceSession + " window " + this
7246 + " w=" + mFrame.width()
7247 + " h=" + mFrame.height() + " format="
7248 + mAttrs.format + " flags=" + flags);
7249
7250 int w = mFrame.width();
7251 int h = mFrame.height();
7252 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7253 // for a scaled surface, we always want the requested
7254 // size.
7255 w = mRequestedWidth;
7256 h = mRequestedHeight;
7257 }
7258
Romain Guy9825ec62009-10-01 00:58:09 -07007259 // Something is wrong and SurfaceFlinger will not like this,
7260 // try to revert to sane values
7261 if (w <= 0) w = 1;
7262 if (h <= 0) h = 1;
7263
Dianne Hackborn16064f92010-03-25 00:47:24 -07007264 mSurfaceShown = false;
7265 mSurfaceLayer = 0;
7266 mSurfaceAlpha = 1;
7267 mSurfaceX = 0;
7268 mSurfaceY = 0;
7269 mSurfaceW = w;
7270 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007271 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007272 final boolean isHwAccelerated = (mAttrs.flags &
7273 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7274 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7275 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7276 flags |= Surface.OPAQUE;
7277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007279 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007280 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007281 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007282 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007283 + mSurface + " IN SESSION "
7284 + mSession.mSurfaceSession
7285 + ": pid=" + mSession.mPid + " format="
7286 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007287 + Integer.toHexString(flags)
7288 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007290 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 reclaimSomeSurfaceMemoryLocked(this, "create");
7292 return null;
7293 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007294 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 return null;
7296 }
Romain Guy06882f82009-06-10 13:36:04 -07007297
Joe Onorato8a9b2202010-02-26 18:56:32 -08007298 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 TAG, "Got surface: " + mSurface
7300 + ", set left=" + mFrame.left + " top=" + mFrame.top
7301 + ", animLayer=" + mAnimLayer);
7302 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007303 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7304 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007305 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7306 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007307 }
7308 Surface.openTransaction();
7309 try {
7310 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007311 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007312 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007313 mSurface.setPosition(mSurfaceX, mSurfaceY);
7314 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007315 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007316 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 mSurface.hide();
7318 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007319 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 mSurface.setFlags(Surface.SURFACE_DITHER,
7321 Surface.SURFACE_DITHER);
7322 }
7323 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007324 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7326 }
7327 mLastHidden = true;
7328 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007330 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007332 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007333 TAG, "Created surface " + this);
7334 }
7335 return mSurface;
7336 }
Romain Guy06882f82009-06-10 13:36:04 -07007337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 if (mAppToken != null && this == mAppToken.startingWindow) {
7340 mAppToken.startingDisplayed = false;
7341 }
Romain Guy06882f82009-06-10 13:36:04 -07007342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007344 mDrawPending = false;
7345 mCommitDrawPending = false;
7346 mReadyToShow = false;
7347
7348 int i = mChildWindows.size();
7349 while (i > 0) {
7350 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007351 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007352 c.mAttachedHidden = true;
7353 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007354
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007355 if (mReportDestroySurface) {
7356 mReportDestroySurface = false;
7357 mSurfacePendingDestroy = true;
7358 try {
7359 mClient.dispatchGetNewSurface();
7360 // We'll really destroy on the next time around.
7361 return;
7362 } catch (RemoteException e) {
7363 }
7364 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007366 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007367 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007368 RuntimeException e = null;
7369 if (!HIDE_STACK_CRAWLS) {
7370 e = new RuntimeException();
7371 e.fillInStackTrace();
7372 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007373 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007374 + mSurface + ", session " + mSession, e);
7375 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007377 RuntimeException e = null;
7378 if (!HIDE_STACK_CRAWLS) {
7379 e = new RuntimeException();
7380 e.fillInStackTrace();
7381 }
7382 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007384 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007386 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 + " surface " + mSurface + " session " + mSession
7388 + ": " + e.toString());
7389 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007390
Dianne Hackborn16064f92010-03-25 00:47:24 -07007391 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007393 }
7394 }
7395
7396 boolean finishDrawingLocked() {
7397 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007398 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 TAG, "finishDrawingLocked: " + mSurface);
7400 mCommitDrawPending = true;
7401 mDrawPending = false;
7402 return true;
7403 }
7404 return false;
7405 }
7406
7407 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007408 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007409 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007411 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 }
7413 mCommitDrawPending = false;
7414 mReadyToShow = true;
7415 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7416 final AppWindowToken atoken = mAppToken;
7417 if (atoken == null || atoken.allDrawn || starting) {
7418 performShowLocked();
7419 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007420 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 }
7422
7423 // This must be called while inside a transaction.
7424 boolean performShowLocked() {
7425 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007426 RuntimeException e = null;
7427 if (!HIDE_STACK_CRAWLS) {
7428 e = new RuntimeException();
7429 e.fillInStackTrace();
7430 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007431 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7433 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7434 }
7435 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007436 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7437 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007438 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 + " during animation: policyVis=" + mPolicyVisibility
7440 + " attHidden=" + mAttachedHidden
7441 + " tok.hiddenRequested="
7442 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007443 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 + (mAppToken != null ? mAppToken.hidden : false)
7445 + " animating=" + mAnimating
7446 + " tok animating="
7447 + (mAppToken != null ? mAppToken.animating : false));
7448 if (!showSurfaceRobustlyLocked(this)) {
7449 return false;
7450 }
7451 mLastAlpha = -1;
7452 mHasDrawn = true;
7453 mLastHidden = false;
7454 mReadyToShow = false;
7455 enableScreenIfNeededLocked();
7456
7457 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007459 int i = mChildWindows.size();
7460 while (i > 0) {
7461 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007462 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007463 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007465 if (c.mSurface != null) {
7466 c.performShowLocked();
7467 // It hadn't been shown, which means layout not
7468 // performed on it, so now we want to make sure to
7469 // do a layout. If called from within the transaction
7470 // loop, this will cause it to restart with a new
7471 // layout.
7472 mLayoutNeeded = true;
7473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 }
7475 }
Romain Guy06882f82009-06-10 13:36:04 -07007476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 if (mAttrs.type != TYPE_APPLICATION_STARTING
7478 && mAppToken != null) {
7479 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007480
Dianne Hackborn248b1882009-09-16 16:46:44 -07007481 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007482 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007483 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007485 // If this initial window is animating, stop it -- we
7486 // will do an animation to reveal it from behind the
7487 // starting window, so there is no need for it to also
7488 // be doing its own stuff.
7489 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007490 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007491 mAnimation = null;
7492 // Make sure we clean up the animation.
7493 mAnimating = true;
7494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 mFinishedStarting.add(mAppToken);
7496 mH.sendEmptyMessage(H.FINISHED_STARTING);
7497 }
7498 mAppToken.updateReportedVisibilityLocked();
7499 }
7500 }
7501 return true;
7502 }
Romain Guy06882f82009-06-10 13:36:04 -07007503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 // This must be called while inside a transaction. Returns true if
7505 // there is more animation to run.
7506 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007507 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7511 mHasTransformation = true;
7512 mHasLocalTransformation = true;
7513 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007514 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007515 TAG, "Starting animation in " + this +
7516 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7517 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7518 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7519 mAnimation.setStartTime(currentTime);
7520 mLocalAnimating = true;
7521 mAnimating = true;
7522 }
7523 mTransformation.clear();
7524 final boolean more = mAnimation.getTransformation(
7525 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007526 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 TAG, "Stepped animation in " + this +
7528 ": more=" + more + ", xform=" + mTransformation);
7529 if (more) {
7530 // we're not done!
7531 return true;
7532 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007533 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007534 TAG, "Finished animation in " + this +
7535 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007536
7537 if (mAnimation != null) {
7538 mAnimation.cancel();
7539 mAnimation = null;
7540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007541 //WindowManagerService.this.dump();
7542 }
7543 mHasLocalTransformation = false;
7544 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007545 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 // When our app token is animating, we kind-of pretend like
7547 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7548 // part of this check means that we will only do this if
7549 // our window is not currently exiting, or it is not
7550 // locally animating itself. The idea being that one that
7551 // is exiting and doing a local animation should be removed
7552 // once that animation is done.
7553 mAnimating = true;
7554 mHasTransformation = true;
7555 mTransformation.clear();
7556 return false;
7557 } else if (mHasTransformation) {
7558 // Little trick to get through the path below to act like
7559 // we have finished an animation.
7560 mAnimating = true;
7561 } else if (isAnimating()) {
7562 mAnimating = true;
7563 }
7564 } else if (mAnimation != null) {
7565 // If the display is frozen, and there is a pending animation,
7566 // clear it and make sure we run the cleanup code.
7567 mAnimating = true;
7568 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007569 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007570 mAnimation = null;
7571 }
Romain Guy06882f82009-06-10 13:36:04 -07007572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 if (!mAnimating && !mLocalAnimating) {
7574 return false;
7575 }
7576
Joe Onorato8a9b2202010-02-26 18:56:32 -08007577 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007578 TAG, "Animation done in " + this + ": exiting=" + mExiting
7579 + ", reportedVisible="
7580 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 mAnimating = false;
7583 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007584 if (mAnimation != null) {
7585 mAnimation.cancel();
7586 mAnimation = null;
7587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 mAnimLayer = mLayer;
7589 if (mIsImWindow) {
7590 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007591 } else if (mIsWallpaper) {
7592 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007594 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007595 + " anim layer: " + mAnimLayer);
7596 mHasTransformation = false;
7597 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007598 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7599 if (DEBUG_VISIBILITY) {
7600 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7601 + mPolicyVisibilityAfterAnim);
7602 }
7603 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7604 if (!mPolicyVisibility) {
7605 if (mCurrentFocus == this) {
7606 mFocusMayChange = true;
7607 }
7608 // Window is no longer visible -- make sure if we were waiting
7609 // for it to be displayed before enabling the display, that
7610 // we allow the display to be enabled now.
7611 enableScreenIfNeededLocked();
7612 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 mTransformation.clear();
7615 if (mHasDrawn
7616 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7617 && mAppToken != null
7618 && mAppToken.firstWindowDrawn
7619 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007620 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 + mToken + ": first real window done animating");
7622 mFinishedStarting.add(mAppToken);
7623 mH.sendEmptyMessage(H.FINISHED_STARTING);
7624 }
Romain Guy06882f82009-06-10 13:36:04 -07007625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 finishExit();
7627
7628 if (mAppToken != null) {
7629 mAppToken.updateReportedVisibilityLocked();
7630 }
7631
7632 return false;
7633 }
7634
7635 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007636 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007637 TAG, "finishExit in " + this
7638 + ": exiting=" + mExiting
7639 + " remove=" + mRemoveOnExit
7640 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 final int N = mChildWindows.size();
7643 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007644 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007645 }
Romain Guy06882f82009-06-10 13:36:04 -07007646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 if (!mExiting) {
7648 return;
7649 }
Romain Guy06882f82009-06-10 13:36:04 -07007650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 if (isWindowAnimating()) {
7652 return;
7653 }
7654
Joe Onorato8a9b2202010-02-26 18:56:32 -08007655 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007656 TAG, "Exit animation finished in " + this
7657 + ": remove=" + mRemoveOnExit);
7658 if (mSurface != null) {
7659 mDestroySurface.add(this);
7660 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007661 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007662 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 try {
7664 mSurface.hide();
7665 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007666 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007667 }
7668 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007669 }
7670 mExiting = false;
7671 if (mRemoveOnExit) {
7672 mPendingRemove.add(this);
7673 mRemoveOnExit = false;
7674 }
7675 }
Romain Guy06882f82009-06-10 13:36:04 -07007676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7678 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7679 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7680 if (dtdx < -.000001f || dtdx > .000001f) return false;
7681 if (dsdy < -.000001f || dsdy > .000001f) return false;
7682 return true;
7683 }
Romain Guy06882f82009-06-10 13:36:04 -07007684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 void computeShownFrameLocked() {
7686 final boolean selfTransformation = mHasLocalTransformation;
7687 Transformation attachedTransformation =
7688 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7689 ? mAttachedWindow.mTransformation : null;
7690 Transformation appTransformation =
7691 (mAppToken != null && mAppToken.hasTransformation)
7692 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007693
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007694 // Wallpapers are animated based on the "real" window they
7695 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007696 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007697 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007698 if (mWallpaperTarget.mHasLocalTransformation &&
7699 mWallpaperTarget.mAnimation != null &&
7700 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007701 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007702 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007703 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007704 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007705 }
7706 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007707 mWallpaperTarget.mAppToken.hasTransformation &&
7708 mWallpaperTarget.mAppToken.animation != null &&
7709 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007710 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007711 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007712 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007713 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007714 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007716
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007717 final boolean screenAnimation = mScreenRotationAnimation != null
7718 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007720 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007721 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007722 final Rect frame = mFrame;
7723 final float tmpFloats[] = mTmpFloats;
7724 final Matrix tmpMatrix = mTmpMatrix;
7725
7726 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007727 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007729 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007731 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007733 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007734 }
7735 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007736 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007738 if (screenAnimation) {
7739 tmpMatrix.postConcat(
7740 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7741 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007742
7743 // "convert" it into SurfaceFlinger's format
7744 // (a 2x2 matrix + an offset)
7745 // Here we must not transform the position of the surface
7746 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007747 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007748
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007749 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 tmpMatrix.getValues(tmpFloats);
7751 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007752 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7753 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007754 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007755 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7756 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007757 int w = frame.width();
7758 int h = frame.height();
7759 mShownFrame.set(x, y, x+w, y+h);
7760
7761 // Now set the alpha... but because our current hardware
7762 // can't do alpha transformation on a non-opaque surface,
7763 // turn it off if we are running an animation that is also
7764 // transforming since it is more important to have that
7765 // animation be smooth.
7766 mShownAlpha = mAlpha;
7767 if (!mLimitedAlphaCompositing
7768 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7769 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7770 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007771 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 if (selfTransformation) {
7773 mShownAlpha *= mTransformation.getAlpha();
7774 }
7775 if (attachedTransformation != null) {
7776 mShownAlpha *= attachedTransformation.getAlpha();
7777 }
7778 if (appTransformation != null) {
7779 mShownAlpha *= appTransformation.getAlpha();
7780 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007781 if (screenAnimation) {
7782 mShownAlpha *=
7783 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7784 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007785 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007786 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 }
Romain Guy06882f82009-06-10 13:36:04 -07007788
Joe Onorato8a9b2202010-02-26 18:56:32 -08007789 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007790 TAG, "Continuing animation in " + this +
7791 ": " + mShownFrame +
7792 ", alpha=" + mTransformation.getAlpha());
7793 return;
7794 }
Romain Guy06882f82009-06-10 13:36:04 -07007795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007797 if (mXOffset != 0 || mYOffset != 0) {
7798 mShownFrame.offset(mXOffset, mYOffset);
7799 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007800 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007801 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007802 mDsDx = 1;
7803 mDtDx = 0;
7804 mDsDy = 0;
7805 mDtDy = 1;
7806 }
Romain Guy06882f82009-06-10 13:36:04 -07007807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007808 /**
7809 * Is this window visible? It is not visible if there is no
7810 * surface, or we are in the process of running an exit animation
7811 * that will remove the surface, or its app token has been hidden.
7812 */
7813 public boolean isVisibleLw() {
7814 final AppWindowToken atoken = mAppToken;
7815 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7816 && (atoken == null || !atoken.hiddenRequested)
7817 && !mExiting && !mDestroying;
7818 }
7819
7820 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007821 * Like {@link #isVisibleLw}, but also counts a window that is currently
7822 * "hidden" behind the keyguard as visible. This allows us to apply
7823 * things like window flags that impact the keyguard.
7824 * XXX I am starting to think we need to have ANOTHER visibility flag
7825 * for this "hidden behind keyguard" state rather than overloading
7826 * mPolicyVisibility. Ungh.
7827 */
7828 public boolean isVisibleOrBehindKeyguardLw() {
7829 final AppWindowToken atoken = mAppToken;
7830 return mSurface != null && !mAttachedHidden
7831 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007832 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007833 && !mExiting && !mDestroying;
7834 }
7835
7836 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007837 * Is this window visible, ignoring its app token? It is not visible
7838 * if there is no surface, or we are in the process of running an exit animation
7839 * that will remove the surface.
7840 */
7841 public boolean isWinVisibleLw() {
7842 final AppWindowToken atoken = mAppToken;
7843 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7844 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7845 && !mExiting && !mDestroying;
7846 }
7847
7848 /**
7849 * The same as isVisible(), but follows the current hidden state of
7850 * the associated app token, not the pending requested hidden state.
7851 */
7852 boolean isVisibleNow() {
7853 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007854 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007855 }
7856
7857 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007858 * Can this window possibly be a drag/drop target? The test here is
7859 * a combination of the above "visible now" with the check that the
7860 * Input Manager uses when discarding windows from input consideration.
7861 */
7862 boolean isPotentialDragTarget() {
7863 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7864 }
7865
7866 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007867 * Same as isVisible(), but we also count it as visible between the
7868 * call to IWindowSession.add() and the first relayout().
7869 */
7870 boolean isVisibleOrAdding() {
7871 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007872 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007873 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7874 && mPolicyVisibility && !mAttachedHidden
7875 && (atoken == null || !atoken.hiddenRequested)
7876 && !mExiting && !mDestroying;
7877 }
7878
7879 /**
7880 * Is this window currently on-screen? It is on-screen either if it
7881 * is visible or it is currently running an animation before no longer
7882 * being visible.
7883 */
7884 boolean isOnScreen() {
7885 final AppWindowToken atoken = mAppToken;
7886 if (atoken != null) {
7887 return mSurface != null && mPolicyVisibility && !mDestroying
7888 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007889 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007890 } else {
7891 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007892 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007893 }
7894 }
Romain Guy06882f82009-06-10 13:36:04 -07007895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007896 /**
7897 * Like isOnScreen(), but we don't return true if the window is part
7898 * of a transition that has not yet been started.
7899 */
7900 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007901 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007902 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007903 return false;
7904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007905 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007906 final boolean animating = atoken != null
7907 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007909 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7910 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007911 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 }
7913
7914 /** Is the window or its container currently animating? */
7915 boolean isAnimating() {
7916 final WindowState attached = mAttachedWindow;
7917 final AppWindowToken atoken = mAppToken;
7918 return mAnimation != null
7919 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007920 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921 (atoken.animation != null
7922 || atoken.inPendingTransaction));
7923 }
7924
7925 /** Is this window currently animating? */
7926 boolean isWindowAnimating() {
7927 return mAnimation != null;
7928 }
7929
7930 /**
7931 * Like isOnScreen, but returns false if the surface hasn't yet
7932 * been drawn.
7933 */
7934 public boolean isDisplayedLw() {
7935 final AppWindowToken atoken = mAppToken;
7936 return mSurface != null && mPolicyVisibility && !mDestroying
7937 && !mDrawPending && !mCommitDrawPending
7938 && ((!mAttachedHidden &&
7939 (atoken == null || !atoken.hiddenRequested))
7940 || mAnimating);
7941 }
7942
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007943 /**
7944 * Returns true if the window has a surface that it has drawn a
7945 * complete UI in to.
7946 */
7947 public boolean isDrawnLw() {
7948 final AppWindowToken atoken = mAppToken;
7949 return mSurface != null && !mDestroying
7950 && !mDrawPending && !mCommitDrawPending;
7951 }
7952
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007953 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007954 * Return true if the window is opaque and fully drawn. This indicates
7955 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007956 */
7957 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007958 return (mAttrs.format == PixelFormat.OPAQUE
7959 || mAttrs.type == TYPE_WALLPAPER)
7960 && mSurface != null && mAnimation == null
7961 && (mAppToken == null || mAppToken.animation == null)
7962 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007963 }
7964
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007965 /**
7966 * Return whether this window is wanting to have a translation
7967 * animation applied to it for an in-progress move. (Only makes
7968 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7969 */
7970 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007971 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007972 && (mFrame.top != mLastFrame.top
7973 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007974 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007975 && mPolicy.isScreenOn();
7976 }
7977
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007978 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7979 return
7980 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007981 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7982 // only if it's visible
7983 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007984 // and only if the application fills the compatible screen
7985 mFrame.left <= mCompatibleScreenFrame.left &&
7986 mFrame.top <= mCompatibleScreenFrame.top &&
7987 mFrame.right >= mCompatibleScreenFrame.right &&
7988 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007989 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007990 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007991 }
7992
7993 boolean isFullscreen(int screenWidth, int screenHeight) {
7994 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007995 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007996 }
7997
7998 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007999 disposeInputChannel();
8000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008002 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 mAttachedWindow.mChildWindows.remove(this);
8004 }
8005 destroySurfaceLocked();
8006 mSession.windowRemovedLocked();
8007 try {
8008 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8009 } catch (RuntimeException e) {
8010 // Ignore if it has already been removed (usually because
8011 // we are doing this as part of processing a death note.)
8012 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008013 }
8014
8015 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008016 if (mInputChannel != null) {
8017 mInputManager.unregisterInputChannel(mInputChannel);
8018
8019 mInputChannel.dispose();
8020 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07008021 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 }
8023
8024 private class DeathRecipient implements IBinder.DeathRecipient {
8025 public void binderDied() {
8026 try {
8027 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008028 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008029 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008030 if (win != null) {
8031 removeWindowLocked(mSession, win);
8032 }
8033 }
8034 } catch (IllegalArgumentException ex) {
8035 // This will happen if the window has already been
8036 // removed.
8037 }
8038 }
8039 }
8040
8041 /** Returns true if this window desires key events. */
8042 public final boolean canReceiveKeys() {
8043 return isVisibleOrAdding()
8044 && (mViewVisibility == View.VISIBLE)
8045 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8046 }
8047
8048 public boolean hasDrawnLw() {
8049 return mHasDrawn;
8050 }
8051
8052 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008053 return showLw(doAnimation, true);
8054 }
8055
8056 boolean showLw(boolean doAnimation, boolean requestAnim) {
8057 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8058 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008060 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008061 if (doAnimation) {
8062 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8063 + mPolicyVisibility + " mAnimation=" + mAnimation);
8064 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8065 doAnimation = false;
8066 } else if (mPolicyVisibility && mAnimation == null) {
8067 // Check for the case where we are currently visible and
8068 // not animating; we do not want to do animation at such a
8069 // point to become visible when we already are.
8070 doAnimation = false;
8071 }
8072 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008073 mPolicyVisibility = true;
8074 mPolicyVisibilityAfterAnim = true;
8075 if (doAnimation) {
8076 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8077 }
8078 if (requestAnim) {
8079 requestAnimationLocked(0);
8080 }
8081 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008082 }
8083
8084 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008085 return hideLw(doAnimation, true);
8086 }
8087
8088 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008089 if (doAnimation) {
8090 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8091 doAnimation = false;
8092 }
8093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8095 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008096 if (!current) {
8097 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008099 if (doAnimation) {
8100 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8101 if (mAnimation == null) {
8102 doAnimation = false;
8103 }
8104 }
8105 if (doAnimation) {
8106 mPolicyVisibilityAfterAnim = false;
8107 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008108 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008109 mPolicyVisibilityAfterAnim = false;
8110 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008111 // Window is no longer visible -- make sure if we were waiting
8112 // for it to be displayed before enabling the display, that
8113 // we allow the display to be enabled now.
8114 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008115 if (mCurrentFocus == this) {
8116 mFocusMayChange = true;
8117 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008118 }
8119 if (requestAnim) {
8120 requestAnimationLocked(0);
8121 }
8122 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008123 }
8124
Jeff Brownfbf09772011-01-16 14:06:57 -08008125 public void getTouchableRegion(Region outRegion) {
8126 final Rect frame = mFrame;
8127 switch (mTouchableInsets) {
8128 default:
8129 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8130 outRegion.set(frame);
8131 break;
8132 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8133 final Rect inset = mGivenContentInsets;
8134 outRegion.set(
8135 frame.left + inset.left, frame.top + inset.top,
8136 frame.right - inset.right, frame.bottom - inset.bottom);
8137 break;
8138 }
8139 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8140 final Rect inset = mGivenVisibleInsets;
8141 outRegion.set(
8142 frame.left + inset.left, frame.top + inset.top,
8143 frame.right - inset.right, frame.bottom - inset.bottom);
8144 break;
8145 }
8146 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8147 final Region givenTouchableRegion = mGivenTouchableRegion;
8148 outRegion.set(givenTouchableRegion);
8149 outRegion.translate(frame.left, frame.top);
8150 break;
8151 }
8152 }
8153 }
8154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008155 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008156 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8157 pw.print(" mClient="); pw.println(mClient.asBinder());
8158 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8159 if (mAttachedWindow != null || mLayoutAttached) {
8160 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8161 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8162 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008163 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8164 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8165 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008166 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8167 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008168 }
8169 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8170 pw.print(" mSubLayer="); pw.print(mSubLayer);
8171 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8172 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8173 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8174 pw.print("="); pw.print(mAnimLayer);
8175 pw.print(" mLastLayer="); pw.println(mLastLayer);
8176 if (mSurface != null) {
8177 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008178 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8179 pw.print(" layer="); pw.print(mSurfaceLayer);
8180 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8181 pw.print(" rect=("); pw.print(mSurfaceX);
8182 pw.print(","); pw.print(mSurfaceY);
8183 pw.print(") "); pw.print(mSurfaceW);
8184 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008185 }
8186 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8187 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8188 if (mAppToken != null) {
8189 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8190 }
8191 if (mTargetAppToken != null) {
8192 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8193 }
8194 pw.print(prefix); pw.print("mViewVisibility=0x");
8195 pw.print(Integer.toHexString(mViewVisibility));
8196 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008197 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8198 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008199 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8200 pw.print(prefix); pw.print("mPolicyVisibility=");
8201 pw.print(mPolicyVisibility);
8202 pw.print(" mPolicyVisibilityAfterAnim=");
8203 pw.print(mPolicyVisibilityAfterAnim);
8204 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8205 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008206 if (!mRelayoutCalled) {
8207 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8208 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008209 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008210 pw.print(" h="); pw.print(mRequestedHeight);
8211 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008212 if (mXOffset != 0 || mYOffset != 0) {
8213 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8214 pw.print(" y="); pw.println(mYOffset);
8215 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008216 pw.print(prefix); pw.print("mGivenContentInsets=");
8217 mGivenContentInsets.printShortString(pw);
8218 pw.print(" mGivenVisibleInsets=");
8219 mGivenVisibleInsets.printShortString(pw);
8220 pw.println();
8221 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8222 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8223 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8224 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008225 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008226 pw.print(prefix); pw.print("mShownFrame=");
8227 mShownFrame.printShortString(pw);
8228 pw.print(" last="); mLastShownFrame.printShortString(pw);
8229 pw.println();
8230 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8231 pw.print(" last="); mLastFrame.printShortString(pw);
8232 pw.println();
8233 pw.print(prefix); pw.print("mContainingFrame=");
8234 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008235 pw.print(" mParentFrame=");
8236 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008237 pw.print(" mDisplayFrame=");
8238 mDisplayFrame.printShortString(pw);
8239 pw.println();
8240 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8241 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8242 pw.println();
8243 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8244 pw.print(" last="); mLastContentInsets.printShortString(pw);
8245 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8246 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8247 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008248 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8249 || mAnimation != null) {
8250 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8251 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8252 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8253 pw.print(" mAnimation="); pw.println(mAnimation);
8254 }
8255 if (mHasTransformation || mHasLocalTransformation) {
8256 pw.print(prefix); pw.print("XForm: has=");
8257 pw.print(mHasTransformation);
8258 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8259 pw.print(" "); mTransformation.printShortString(pw);
8260 pw.println();
8261 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008262 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8263 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8264 pw.print(" mAlpha="); pw.print(mAlpha);
8265 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8266 }
8267 if (mHaveMatrix) {
8268 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8269 pw.print(" mDtDx="); pw.print(mDtDx);
8270 pw.print(" mDsDy="); pw.print(mDsDy);
8271 pw.print(" mDtDy="); pw.println(mDtDy);
8272 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008273 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8274 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8275 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8276 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8277 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8278 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8279 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8280 pw.print(" mDestroying="); pw.print(mDestroying);
8281 pw.print(" mRemoved="); pw.println(mRemoved);
8282 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008283 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008284 pw.print(prefix); pw.print("mOrientationChanging=");
8285 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008286 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8287 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008288 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008289 if (mHScale != 1 || mVScale != 1) {
8290 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8291 pw.print(" mVScale="); pw.println(mVScale);
8292 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008293 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008294 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8295 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8296 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008297 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8298 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8299 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008301 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07008302
8303 String makeInputChannelName() {
8304 return Integer.toHexString(System.identityHashCode(this))
8305 + " " + mAttrs.getTitle();
8306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307
8308 @Override
8309 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008310 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8311 || mWasPaused != mToken.paused) {
8312 mLastTitle = mAttrs.getTitle();
8313 mWasPaused = mToken.paused;
8314 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8315 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8316 }
8317 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008318 }
8319 }
Romain Guy06882f82009-06-10 13:36:04 -07008320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 // -------------------------------------------------------------
8322 // Window Token State
8323 // -------------------------------------------------------------
8324
8325 class WindowToken {
8326 // The actual token.
8327 final IBinder token;
8328
8329 // The type of window this token is for, as per WindowManager.LayoutParams.
8330 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008332 // Set if this token was explicitly added by a client, so should
8333 // not be removed when all windows are removed.
8334 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008335
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008336 // For printing.
8337 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008339 // If this is an AppWindowToken, this is non-null.
8340 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 // All of the windows associated with this token.
8343 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8344
8345 // Is key dispatching paused for this token?
8346 boolean paused = false;
8347
8348 // Should this token's windows be hidden?
8349 boolean hidden;
8350
8351 // Temporary for finding which tokens no longer have visible windows.
8352 boolean hasVisible;
8353
Dianne Hackborna8f60182009-09-01 19:01:50 -07008354 // Set to true when this token is in a pending transaction where it
8355 // will be shown.
8356 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008357
Dianne Hackborna8f60182009-09-01 19:01:50 -07008358 // Set to true when this token is in a pending transaction where it
8359 // will be hidden.
8360 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008361
Dianne Hackborna8f60182009-09-01 19:01:50 -07008362 // Set to true when this token is in a pending transaction where its
8363 // windows will be put to the bottom of the list.
8364 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008365
Dianne Hackborna8f60182009-09-01 19:01:50 -07008366 // Set to true when this token is in a pending transaction where its
8367 // windows will be put to the top of the list.
8368 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008370 WindowToken(IBinder _token, int type, boolean _explicit) {
8371 token = _token;
8372 windowType = type;
8373 explicit = _explicit;
8374 }
8375
8376 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008377 pw.print(prefix); pw.print("token="); pw.println(token);
8378 pw.print(prefix); pw.print("windows="); pw.println(windows);
8379 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8380 pw.print(" hidden="); pw.print(hidden);
8381 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008382 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8383 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8384 pw.print(" waitingToHide="); pw.print(waitingToHide);
8385 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8386 pw.print(" sendingToTop="); pw.println(sendingToTop);
8387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008388 }
8389
8390 @Override
8391 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008392 if (stringName == null) {
8393 StringBuilder sb = new StringBuilder();
8394 sb.append("WindowToken{");
8395 sb.append(Integer.toHexString(System.identityHashCode(this)));
8396 sb.append(" token="); sb.append(token); sb.append('}');
8397 stringName = sb.toString();
8398 }
8399 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008400 }
8401 };
8402
8403 class AppWindowToken extends WindowToken {
8404 // Non-null only for application tokens.
8405 final IApplicationToken appToken;
8406
8407 // All of the windows and child windows that are included in this
8408 // application token. Note this list is NOT sorted!
8409 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8410
8411 int groupId = -1;
8412 boolean appFullscreen;
8413 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008414
8415 // The input dispatching timeout for this application token in nanoseconds.
8416 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 // These are used for determining when all windows associated with
8419 // an activity have been drawn, so they can be made visible together
8420 // at the same time.
8421 int lastTransactionSequence = mTransactionSequence-1;
8422 int numInterestingWindows;
8423 int numDrawnWindows;
8424 boolean inPendingTransaction;
8425 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 // Is this token going to be hidden in a little while? If so, it
8428 // won't be taken into account for setting the screen orientation.
8429 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008431 // Is this window's surface needed? This is almost like hidden, except
8432 // it will sometimes be true a little earlier: when the token has
8433 // been shown, but is still waiting for its app transition to execute
8434 // before making its windows shown.
8435 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 // Have we told the window clients to hide themselves?
8438 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 // Last visibility state we reported to the app token.
8441 boolean reportedVisible;
8442
8443 // Set to true when the token has been removed from the window mgr.
8444 boolean removed;
8445
8446 // Have we been asked to have this token keep the screen frozen?
8447 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 boolean animating;
8450 Animation animation;
8451 boolean hasTransformation;
8452 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008454 // Offset to the window of all layers in the token, for use by
8455 // AppWindowToken animations.
8456 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 // Information about an application starting window if displayed.
8459 StartingData startingData;
8460 WindowState startingWindow;
8461 View startingView;
8462 boolean startingDisplayed;
8463 boolean startingMoved;
8464 boolean firstWindowDrawn;
8465
Jeff Brown928e0542011-01-10 11:17:36 -08008466 // Input application handle used by the input dispatcher.
8467 InputApplicationHandle mInputApplicationHandle;
8468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 AppWindowToken(IApplicationToken _token) {
8470 super(_token.asBinder(),
8471 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8472 appWindowToken = this;
8473 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008474 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 }
Romain Guy06882f82009-06-10 13:36:04 -07008476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008477 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008478 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 TAG, "Setting animation in " + this + ": " + anim);
8480 animation = anim;
8481 animating = false;
8482 anim.restrictDuration(MAX_ANIMATION_DURATION);
8483 anim.scaleCurrentDuration(mTransitionAnimationScale);
8484 int zorder = anim.getZAdjustment();
8485 int adj = 0;
8486 if (zorder == Animation.ZORDER_TOP) {
8487 adj = TYPE_LAYER_OFFSET;
8488 } else if (zorder == Animation.ZORDER_BOTTOM) {
8489 adj = -TYPE_LAYER_OFFSET;
8490 }
Romain Guy06882f82009-06-10 13:36:04 -07008491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008492 if (animLayerAdjustment != adj) {
8493 animLayerAdjustment = adj;
8494 updateLayers();
8495 }
8496 }
Romain Guy06882f82009-06-10 13:36:04 -07008497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008498 public void setDummyAnimation() {
8499 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008500 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 TAG, "Setting dummy animation in " + this);
8502 animation = sDummyAnimation;
8503 }
8504 }
8505
8506 public void clearAnimation() {
8507 if (animation != null) {
8508 animation = null;
8509 animating = true;
8510 }
8511 }
Romain Guy06882f82009-06-10 13:36:04 -07008512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008513 void updateLayers() {
8514 final int N = allAppWindows.size();
8515 final int adj = animLayerAdjustment;
8516 for (int i=0; i<N; i++) {
8517 WindowState w = allAppWindows.get(i);
8518 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008519 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008520 + w.mAnimLayer);
8521 if (w == mInputMethodTarget) {
8522 setInputMethodAnimLayerAdjustment(adj);
8523 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008524 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008525 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 }
8528 }
Romain Guy06882f82009-06-10 13:36:04 -07008529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008530 void sendAppVisibilityToClients() {
8531 final int N = allAppWindows.size();
8532 for (int i=0; i<N; i++) {
8533 WindowState win = allAppWindows.get(i);
8534 if (win == startingWindow && clientHidden) {
8535 // Don't hide the starting window.
8536 continue;
8537 }
8538 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008539 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 "Setting visibility of " + win + ": " + (!clientHidden));
8541 win.mClient.dispatchAppVisibility(!clientHidden);
8542 } catch (RemoteException e) {
8543 }
8544 }
8545 }
Romain Guy06882f82009-06-10 13:36:04 -07008546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 void showAllWindowsLocked() {
8548 final int NW = allAppWindows.size();
8549 for (int i=0; i<NW; i++) {
8550 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008551 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 "performing show on: " + w);
8553 w.performShowLocked();
8554 }
8555 }
Romain Guy06882f82009-06-10 13:36:04 -07008556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 // This must be called while inside a transaction.
8558 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008559 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008560 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562 if (animation == sDummyAnimation) {
8563 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008564 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008565 // when it is really time to animate, this will be set to
8566 // a real animation and the next call will execute normally.
8567 return false;
8568 }
Romain Guy06882f82009-06-10 13:36:04 -07008569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8571 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008572 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573 TAG, "Starting animation in " + this +
8574 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8575 + " scale=" + mTransitionAnimationScale
8576 + " allDrawn=" + allDrawn + " animating=" + animating);
8577 animation.initialize(dw, dh, dw, dh);
8578 animation.setStartTime(currentTime);
8579 animating = true;
8580 }
8581 transformation.clear();
8582 final boolean more = animation.getTransformation(
8583 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008584 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008585 TAG, "Stepped animation in " + this +
8586 ": more=" + more + ", xform=" + transformation);
8587 if (more) {
8588 // we're done!
8589 hasTransformation = true;
8590 return true;
8591 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008592 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008593 TAG, "Finished animation in " + this +
8594 " @ " + currentTime);
8595 animation = null;
8596 }
8597 } else if (animation != null) {
8598 // If the display is frozen, and there is a pending animation,
8599 // clear it and make sure we run the cleanup code.
8600 animating = true;
8601 animation = null;
8602 }
8603
8604 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 if (!animating) {
8607 return false;
8608 }
8609
8610 clearAnimation();
8611 animating = false;
8612 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8613 moveInputMethodWindowsIfNeededLocked(true);
8614 }
Romain Guy06882f82009-06-10 13:36:04 -07008615
Joe Onorato8a9b2202010-02-26 18:56:32 -08008616 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008617 TAG, "Animation done in " + this
8618 + ": reportedVisible=" + reportedVisible);
8619
8620 transformation.clear();
8621 if (animLayerAdjustment != 0) {
8622 animLayerAdjustment = 0;
8623 updateLayers();
8624 }
Romain Guy06882f82009-06-10 13:36:04 -07008625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 final int N = windows.size();
8627 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008628 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 }
8630 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008632 return false;
8633 }
8634
8635 void updateReportedVisibilityLocked() {
8636 if (appToken == null) {
8637 return;
8638 }
Romain Guy06882f82009-06-10 13:36:04 -07008639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 int numInteresting = 0;
8641 int numVisible = 0;
8642 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008643
Joe Onorato8a9b2202010-02-26 18:56:32 -08008644 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 final int N = allAppWindows.size();
8646 for (int i=0; i<N; i++) {
8647 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008648 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008649 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008650 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8651 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008652 continue;
8653 }
8654 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008655 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008656 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008657 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008658 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008659 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008660 + " pv=" + win.mPolicyVisibility
8661 + " dp=" + win.mDrawPending
8662 + " cdp=" + win.mCommitDrawPending
8663 + " ah=" + win.mAttachedHidden
8664 + " th="
8665 + (win.mAppToken != null
8666 ? win.mAppToken.hiddenRequested : false)
8667 + " a=" + win.mAnimating);
8668 }
8669 }
8670 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008671 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672 if (!win.isAnimating()) {
8673 numVisible++;
8674 }
8675 nowGone = false;
8676 } else if (win.isAnimating()) {
8677 nowGone = false;
8678 }
8679 }
Romain Guy06882f82009-06-10 13:36:04 -07008680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008682 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008683 + numInteresting + " visible=" + numVisible);
8684 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008685 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 TAG, "Visibility changed in " + this
8687 + ": vis=" + nowVisible);
8688 reportedVisible = nowVisible;
8689 Message m = mH.obtainMessage(
8690 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8691 nowVisible ? 1 : 0,
8692 nowGone ? 1 : 0,
8693 this);
8694 mH.sendMessage(m);
8695 }
8696 }
Romain Guy06882f82009-06-10 13:36:04 -07008697
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008698 WindowState findMainWindow() {
8699 int j = windows.size();
8700 while (j > 0) {
8701 j--;
8702 WindowState win = windows.get(j);
8703 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8704 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8705 return win;
8706 }
8707 }
8708 return null;
8709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008711 void dump(PrintWriter pw, String prefix) {
8712 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008713 if (appToken != null) {
8714 pw.print(prefix); pw.println("app=true");
8715 }
8716 if (allAppWindows.size() > 0) {
8717 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8718 }
8719 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008720 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008721 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8722 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8723 pw.print(" clientHidden="); pw.print(clientHidden);
8724 pw.print(" willBeHidden="); pw.print(willBeHidden);
8725 pw.print(" reportedVisible="); pw.println(reportedVisible);
8726 if (paused || freezingScreen) {
8727 pw.print(prefix); pw.print("paused="); pw.print(paused);
8728 pw.print(" freezingScreen="); pw.println(freezingScreen);
8729 }
8730 if (numInterestingWindows != 0 || numDrawnWindows != 0
8731 || inPendingTransaction || allDrawn) {
8732 pw.print(prefix); pw.print("numInterestingWindows=");
8733 pw.print(numInterestingWindows);
8734 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8735 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8736 pw.print(" allDrawn="); pw.println(allDrawn);
8737 }
8738 if (animating || animation != null) {
8739 pw.print(prefix); pw.print("animating="); pw.print(animating);
8740 pw.print(" animation="); pw.println(animation);
8741 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008742 if (hasTransformation) {
8743 pw.print(prefix); pw.print("XForm: ");
8744 transformation.printShortString(pw);
8745 pw.println();
8746 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008747 if (animLayerAdjustment != 0) {
8748 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8749 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008750 if (startingData != null || removed || firstWindowDrawn) {
8751 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8752 pw.print(" removed="); pw.print(removed);
8753 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8754 }
8755 if (startingWindow != null || startingView != null
8756 || startingDisplayed || startingMoved) {
8757 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8758 pw.print(" startingView="); pw.print(startingView);
8759 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8760 pw.print(" startingMoved"); pw.println(startingMoved);
8761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008762 }
8763
8764 @Override
8765 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008766 if (stringName == null) {
8767 StringBuilder sb = new StringBuilder();
8768 sb.append("AppWindowToken{");
8769 sb.append(Integer.toHexString(System.identityHashCode(this)));
8770 sb.append(" token="); sb.append(token); sb.append('}');
8771 stringName = sb.toString();
8772 }
8773 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008774 }
8775 }
Romain Guy06882f82009-06-10 13:36:04 -07008776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008777 // -------------------------------------------------------------
8778 // DummyAnimation
8779 // -------------------------------------------------------------
8780
8781 // This is an animation that does nothing: it just immediately finishes
8782 // itself every time it is called. It is used as a stub animation in cases
8783 // where we want to synchronize multiple things that may be animating.
8784 static final class DummyAnimation extends Animation {
8785 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8786 return false;
8787 }
8788 }
8789 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008791 // -------------------------------------------------------------
8792 // Async Handler
8793 // -------------------------------------------------------------
8794
8795 static final class StartingData {
8796 final String pkg;
8797 final int theme;
8798 final CharSequence nonLocalizedLabel;
8799 final int labelRes;
8800 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008801 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008803 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008804 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008805 pkg = _pkg;
8806 theme = _theme;
8807 nonLocalizedLabel = _nonLocalizedLabel;
8808 labelRes = _labelRes;
8809 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008810 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008811 }
8812 }
8813
8814 private final class H extends Handler {
8815 public static final int REPORT_FOCUS_CHANGE = 2;
8816 public static final int REPORT_LOSING_FOCUS = 3;
8817 public static final int ANIMATE = 4;
8818 public static final int ADD_STARTING = 5;
8819 public static final int REMOVE_STARTING = 6;
8820 public static final int FINISHED_STARTING = 7;
8821 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008822 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8823 public static final int HOLD_SCREEN_CHANGED = 12;
8824 public static final int APP_TRANSITION_TIMEOUT = 13;
8825 public static final int PERSIST_ANIMATION_SCALE = 14;
8826 public static final int FORCE_GC = 15;
8827 public static final int ENABLE_SCREEN = 16;
8828 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008829 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008830 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008831 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008832 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008834 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008836 public H() {
8837 }
Romain Guy06882f82009-06-10 13:36:04 -07008838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008839 @Override
8840 public void handleMessage(Message msg) {
8841 switch (msg.what) {
8842 case REPORT_FOCUS_CHANGE: {
8843 WindowState lastFocus;
8844 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008846 synchronized(mWindowMap) {
8847 lastFocus = mLastFocus;
8848 newFocus = mCurrentFocus;
8849 if (lastFocus == newFocus) {
8850 // Focus is not changing, so nothing to do.
8851 return;
8852 }
8853 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008854 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 // + " to " + newFocus);
8856 if (newFocus != null && lastFocus != null
8857 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008858 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008859 mLosingFocus.add(lastFocus);
8860 lastFocus = null;
8861 }
8862 }
8863
8864 if (lastFocus != newFocus) {
8865 //System.out.println("Changing focus from " + lastFocus
8866 // + " to " + newFocus);
8867 if (newFocus != null) {
8868 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008869 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008870 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8871 } catch (RemoteException e) {
8872 // Ignore if process has died.
8873 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008874 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 }
8876
8877 if (lastFocus != null) {
8878 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008879 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008880 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8881 } catch (RemoteException e) {
8882 // Ignore if process has died.
8883 }
8884 }
8885 }
8886 } break;
8887
8888 case REPORT_LOSING_FOCUS: {
8889 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 synchronized(mWindowMap) {
8892 losers = mLosingFocus;
8893 mLosingFocus = new ArrayList<WindowState>();
8894 }
8895
8896 final int N = losers.size();
8897 for (int i=0; i<N; i++) {
8898 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8901 } catch (RemoteException e) {
8902 // Ignore if process has died.
8903 }
8904 }
8905 } break;
8906
8907 case ANIMATE: {
8908 synchronized(mWindowMap) {
8909 mAnimationPending = false;
8910 performLayoutAndPlaceSurfacesLocked();
8911 }
8912 } break;
8913
8914 case ADD_STARTING: {
8915 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8916 final StartingData sd = wtoken.startingData;
8917
8918 if (sd == null) {
8919 // Animation has been canceled... do nothing.
8920 return;
8921 }
Romain Guy06882f82009-06-10 13:36:04 -07008922
Joe Onorato8a9b2202010-02-26 18:56:32 -08008923 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008926 View view = null;
8927 try {
8928 view = mPolicy.addStartingWindow(
8929 wtoken.token, sd.pkg,
8930 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008931 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008933 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008934 }
8935
8936 if (view != null) {
8937 boolean abort = false;
8938
8939 synchronized(mWindowMap) {
8940 if (wtoken.removed || wtoken.startingData == null) {
8941 // If the window was successfully added, then
8942 // we need to remove it.
8943 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008944 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 "Aborted starting " + wtoken
8946 + ": removed=" + wtoken.removed
8947 + " startingData=" + wtoken.startingData);
8948 wtoken.startingWindow = null;
8949 wtoken.startingData = null;
8950 abort = true;
8951 }
8952 } else {
8953 wtoken.startingView = view;
8954 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008955 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008956 "Added starting " + wtoken
8957 + ": startingWindow="
8958 + wtoken.startingWindow + " startingView="
8959 + wtoken.startingView);
8960 }
8961
8962 if (abort) {
8963 try {
8964 mPolicy.removeStartingWindow(wtoken.token, view);
8965 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008966 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 }
8968 }
8969 }
8970 } break;
8971
8972 case REMOVE_STARTING: {
8973 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8974 IBinder token = null;
8975 View view = null;
8976 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008977 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008978 + wtoken + ": startingWindow="
8979 + wtoken.startingWindow + " startingView="
8980 + wtoken.startingView);
8981 if (wtoken.startingWindow != null) {
8982 view = wtoken.startingView;
8983 token = wtoken.token;
8984 wtoken.startingData = null;
8985 wtoken.startingView = null;
8986 wtoken.startingWindow = null;
8987 }
8988 }
8989 if (view != null) {
8990 try {
8991 mPolicy.removeStartingWindow(token, view);
8992 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008993 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008994 }
8995 }
8996 } break;
8997
8998 case FINISHED_STARTING: {
8999 IBinder token = null;
9000 View view = null;
9001 while (true) {
9002 synchronized (mWindowMap) {
9003 final int N = mFinishedStarting.size();
9004 if (N <= 0) {
9005 break;
9006 }
9007 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9008
Joe Onorato8a9b2202010-02-26 18:56:32 -08009009 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009010 "Finished starting " + wtoken
9011 + ": startingWindow=" + wtoken.startingWindow
9012 + " startingView=" + wtoken.startingView);
9013
9014 if (wtoken.startingWindow == null) {
9015 continue;
9016 }
9017
9018 view = wtoken.startingView;
9019 token = wtoken.token;
9020 wtoken.startingData = null;
9021 wtoken.startingView = null;
9022 wtoken.startingWindow = null;
9023 }
9024
9025 try {
9026 mPolicy.removeStartingWindow(token, view);
9027 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009028 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009029 }
9030 }
9031 } break;
9032
9033 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9034 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9035
9036 boolean nowVisible = msg.arg1 != 0;
9037 boolean nowGone = msg.arg2 != 0;
9038
9039 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009040 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009041 TAG, "Reporting visible in " + wtoken
9042 + " visible=" + nowVisible
9043 + " gone=" + nowGone);
9044 if (nowVisible) {
9045 wtoken.appToken.windowsVisible();
9046 } else {
9047 wtoken.appToken.windowsGone();
9048 }
9049 } catch (RemoteException ex) {
9050 }
9051 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009053 case WINDOW_FREEZE_TIMEOUT: {
9054 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009055 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056 int i = mWindows.size();
9057 while (i > 0) {
9058 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009059 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009060 if (w.mOrientationChanging) {
9061 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009062 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009063 }
9064 }
9065 performLayoutAndPlaceSurfacesLocked();
9066 }
9067 break;
9068 }
Romain Guy06882f82009-06-10 13:36:04 -07009069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009070 case HOLD_SCREEN_CHANGED: {
9071 Session oldHold;
9072 Session newHold;
9073 synchronized (mWindowMap) {
9074 oldHold = mLastReportedHold;
9075 newHold = (Session)msg.obj;
9076 mLastReportedHold = newHold;
9077 }
Romain Guy06882f82009-06-10 13:36:04 -07009078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009079 if (oldHold != newHold) {
9080 try {
9081 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009082 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009083 "window",
9084 BatteryStats.WAKE_TYPE_WINDOW);
9085 }
9086 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009087 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009088 "window",
9089 BatteryStats.WAKE_TYPE_WINDOW);
9090 }
9091 } catch (RemoteException e) {
9092 }
9093 }
9094 break;
9095 }
Romain Guy06882f82009-06-10 13:36:04 -07009096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009097 case APP_TRANSITION_TIMEOUT: {
9098 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009099 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009100 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009101 "*** APP TRANSITION TIMEOUT");
9102 mAppTransitionReady = true;
9103 mAppTransitionTimeout = true;
9104 performLayoutAndPlaceSurfacesLocked();
9105 }
9106 }
9107 break;
9108 }
Romain Guy06882f82009-06-10 13:36:04 -07009109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009110 case PERSIST_ANIMATION_SCALE: {
9111 Settings.System.putFloat(mContext.getContentResolver(),
9112 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9113 Settings.System.putFloat(mContext.getContentResolver(),
9114 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9115 break;
9116 }
Romain Guy06882f82009-06-10 13:36:04 -07009117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 case FORCE_GC: {
9119 synchronized(mWindowMap) {
9120 if (mAnimationPending) {
9121 // If we are animating, don't do the gc now but
9122 // delay a bit so we don't interrupt the animation.
9123 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9124 2000);
9125 return;
9126 }
9127 // If we are currently rotating the display, it will
9128 // schedule a new message when done.
9129 if (mDisplayFrozen) {
9130 return;
9131 }
9132 mFreezeGcPending = 0;
9133 }
9134 Runtime.getRuntime().gc();
9135 break;
9136 }
Romain Guy06882f82009-06-10 13:36:04 -07009137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009138 case ENABLE_SCREEN: {
9139 performEnableScreen();
9140 break;
9141 }
Romain Guy06882f82009-06-10 13:36:04 -07009142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 case APP_FREEZE_TIMEOUT: {
9144 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009145 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009146 int i = mAppTokens.size();
9147 while (i > 0) {
9148 i--;
9149 AppWindowToken tok = mAppTokens.get(i);
9150 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009151 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009152 unsetAppFreezingScreenLocked(tok, true, true);
9153 }
9154 }
9155 }
9156 break;
9157 }
Romain Guy06882f82009-06-10 13:36:04 -07009158
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009159 case SEND_NEW_CONFIGURATION: {
9160 removeMessages(SEND_NEW_CONFIGURATION);
9161 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009162 break;
9163 }
Romain Guy06882f82009-06-10 13:36:04 -07009164
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009165 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009166 if (mWindowsChanged) {
9167 synchronized (mWindowMap) {
9168 mWindowsChanged = false;
9169 }
9170 notifyWindowsChanged();
9171 }
9172 break;
9173 }
9174
Christopher Tatea53146c2010-09-07 11:57:52 -07009175 case DRAG_START_TIMEOUT: {
9176 IBinder win = (IBinder)msg.obj;
9177 if (DEBUG_DRAG) {
9178 Slog.w(TAG, "Timeout starting drag by win " + win);
9179 }
9180 synchronized (mWindowMap) {
9181 // !!! TODO: ANR the app that has failed to start the drag in time
9182 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07009183 mDragState.unregister();
Jeff Brown3a22cd92011-01-21 13:59:04 -08009184 mInputMonitor.setUpdateInputWindowsNeededLw();
Chris Tated4533f12010-10-19 15:15:08 -07009185 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009186 mDragState.reset();
9187 mDragState = null;
9188 }
9189 }
Chris Tated4533f12010-10-19 15:15:08 -07009190 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009191 }
9192
Chris Tated4533f12010-10-19 15:15:08 -07009193 case DRAG_END_TIMEOUT: {
9194 IBinder win = (IBinder)msg.obj;
9195 if (DEBUG_DRAG) {
9196 Slog.w(TAG, "Timeout ending drag to win " + win);
9197 }
9198 synchronized (mWindowMap) {
9199 // !!! TODO: ANR the drag-receiving app
9200 mDragState.mDragResult = false;
9201 mDragState.endDragLw();
9202 }
9203 break;
9204 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 }
9206 }
9207 }
9208
9209 // -------------------------------------------------------------
9210 // IWindowManager API
9211 // -------------------------------------------------------------
9212
9213 public IWindowSession openSession(IInputMethodClient client,
9214 IInputContext inputContext) {
9215 if (client == null) throw new IllegalArgumentException("null client");
9216 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07009217 Session session = new Session(client, inputContext);
9218 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 }
9220
9221 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9222 synchronized (mWindowMap) {
9223 // The focus for the client is the window immediately below
9224 // where we would place the input method window.
9225 int idx = findDesiredInputMethodWindowIndexLocked(false);
9226 WindowState imFocus;
9227 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009228 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009229 if (imFocus != null) {
9230 if (imFocus.mSession.mClient != null &&
9231 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9232 return true;
9233 }
9234 }
9235 }
9236 }
9237 return false;
9238 }
Romain Guy06882f82009-06-10 13:36:04 -07009239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009240 // -------------------------------------------------------------
9241 // Internals
9242 // -------------------------------------------------------------
9243
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009244 final WindowState windowForClientLocked(Session session, IWindow client,
9245 boolean throwOnError) {
9246 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 }
Romain Guy06882f82009-06-10 13:36:04 -07009248
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009249 final WindowState windowForClientLocked(Session session, IBinder client,
9250 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009251 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009252 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 TAG, "Looking up client " + client + ": " + win);
9254 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009255 RuntimeException ex = new IllegalArgumentException(
9256 "Requested window " + client + " does not exist");
9257 if (throwOnError) {
9258 throw ex;
9259 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009260 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009261 return null;
9262 }
9263 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009264 RuntimeException ex = new IllegalArgumentException(
9265 "Requested window " + client + " is in session " +
9266 win.mSession + ", not " + session);
9267 if (throwOnError) {
9268 throw ex;
9269 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009270 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009271 return null;
9272 }
9273
9274 return win;
9275 }
9276
Dianne Hackborna8f60182009-09-01 19:01:50 -07009277 final void rebuildAppWindowListLocked() {
9278 int NW = mWindows.size();
9279 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009280 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009281 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009282
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009283 if (mRebuildTmp.length < NW) {
9284 mRebuildTmp = new WindowState[NW+10];
9285 }
9286
Dianne Hackborna8f60182009-09-01 19:01:50 -07009287 // First remove all existing app windows.
9288 i=0;
9289 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009290 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009291 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009292 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009293 win.mRebuilding = true;
9294 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009295 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009296 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009297 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009298 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009299 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009300 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009301 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9302 && lastWallpaper == i-1) {
9303 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009304 }
9305 i++;
9306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009307
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009308 // The wallpaper window(s) typically live at the bottom of the stack,
9309 // so skip them before adding app tokens.
9310 lastWallpaper++;
9311 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009312
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009313 // First add all of the exiting app tokens... these are no longer
9314 // in the main app list, but still have windows shown. We put them
9315 // in the back because now that the animation is over we no longer
9316 // will care about them.
9317 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009318 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009319 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9320 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009321
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009322 // And add in the still active app tokens in Z order.
9323 NT = mAppTokens.size();
9324 for (int j=0; j<NT; j++) {
9325 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009326 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009327
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009328 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009329 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009330 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009331 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009332 for (i=0; i<numRemoved; i++) {
9333 WindowState ws = mRebuildTmp[i];
9334 if (ws.mRebuilding) {
9335 StringWriter sw = new StringWriter();
9336 PrintWriter pw = new PrintWriter(sw);
9337 ws.dump(pw, "");
9338 pw.flush();
9339 Slog.w(TAG, "This window was lost: " + ws);
9340 Slog.w(TAG, sw.toString());
9341 }
9342 }
9343 Slog.w(TAG, "Current app token list:");
9344 dumpAppTokensLocked();
9345 Slog.w(TAG, "Final window list:");
9346 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009347 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009348 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009350 private final void assignLayersLocked() {
9351 int N = mWindows.size();
9352 int curBaseLayer = 0;
9353 int curLayer = 0;
9354 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009355
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009356 if (DEBUG_LAYERS) {
9357 RuntimeException here = new RuntimeException("here");
9358 here.fillInStackTrace();
9359 Log.v(TAG, "Assigning layers", here);
9360 }
9361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009362 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009363 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009364 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9365 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009366 curLayer += WINDOW_LAYER_MULTIPLIER;
9367 w.mLayer = curLayer;
9368 } else {
9369 curBaseLayer = curLayer = w.mBaseLayer;
9370 w.mLayer = curLayer;
9371 }
9372 if (w.mTargetAppToken != null) {
9373 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9374 } else if (w.mAppToken != null) {
9375 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9376 } else {
9377 w.mAnimLayer = w.mLayer;
9378 }
9379 if (w.mIsImWindow) {
9380 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009381 } else if (w.mIsWallpaper) {
9382 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009384 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009385 + w.mAnimLayer);
9386 //System.out.println(
9387 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9388 }
9389 }
9390
9391 private boolean mInLayout = false;
9392 private final void performLayoutAndPlaceSurfacesLocked() {
9393 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009394 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009395 throw new RuntimeException("Recursive call!");
9396 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009397 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 return;
9399 }
9400
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009401 if (mWaitingForConfig) {
9402 // Our configuration has changed (most likely rotation), but we
9403 // don't yet have the complete configuration to report to
9404 // applications. Don't do any window layout until we have it.
9405 return;
9406 }
9407
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009408 if (mDisplay == null) {
9409 // Not yet initialized, nothing to do.
9410 return;
9411 }
9412
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009413 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009414 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009415
9416 try {
9417 if (mForceRemoves != null) {
9418 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009419 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009420 for (int i=0; i<mForceRemoves.size(); i++) {
9421 WindowState ws = mForceRemoves.get(i);
9422 Slog.i(TAG, "Force removing: " + ws);
9423 removeWindowInnerLocked(ws.mSession, ws);
9424 }
9425 mForceRemoves = null;
9426 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9427 Object tmp = new Object();
9428 synchronized (tmp) {
9429 try {
9430 tmp.wait(250);
9431 } catch (InterruptedException e) {
9432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009433 }
9434 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009435 } catch (RuntimeException e) {
9436 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009437 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009439 try {
9440 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009441
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009442 int N = mPendingRemove.size();
9443 if (N > 0) {
9444 if (mPendingRemoveTmp.length < N) {
9445 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009446 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009447 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009448 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009449 for (int i=0; i<N; i++) {
9450 WindowState w = mPendingRemoveTmp[i];
9451 removeWindowInnerLocked(w.mSession, w);
9452 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009453
9454 mInLayout = false;
9455 assignLayersLocked();
9456 mLayoutNeeded = true;
9457 performLayoutAndPlaceSurfacesLocked();
9458
9459 } else {
9460 mInLayout = false;
9461 if (mLayoutNeeded) {
9462 requestAnimationLocked(0);
9463 }
9464 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009465 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009466 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9467 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 } catch (RuntimeException e) {
9470 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009471 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 }
9473 }
9474
Jeff Brown3a22cd92011-01-21 13:59:04 -08009475 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009476 if (!mLayoutNeeded) {
9477 return 0;
9478 }
9479
9480 mLayoutNeeded = false;
9481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009482 final int dw = mDisplay.getWidth();
9483 final int dh = mDisplay.getHeight();
9484
9485 final int N = mWindows.size();
9486 int i;
9487
Joe Onorato8a9b2202010-02-26 18:56:32 -08009488 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009489 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9490
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009491 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009492
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009493 int seq = mLayoutSeq+1;
9494 if (seq < 0) seq = 0;
9495 mLayoutSeq = seq;
9496
9497 // First perform layout of any root windows (not attached
9498 // to another window).
9499 int topAttached = -1;
9500 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009501 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009502
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009503 // Don't do layout of a window if it is not visible, or
9504 // soon won't be visible, to avoid wasting time and funky
9505 // changes while a window is animating away.
9506 final AppWindowToken atoken = win.mAppToken;
9507 final boolean gone = win.mViewVisibility == View.GONE
9508 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009509 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009510 || (atoken != null && atoken.hiddenRequested)
9511 || win.mAttachedHidden
9512 || win.mExiting || win.mDestroying;
9513
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009514 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9515 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009516 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9517 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009518 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009519 + win.mViewVisibility + " mRelayoutCalled="
9520 + win.mRelayoutCalled + " hidden="
9521 + win.mRootToken.hidden + " hiddenRequested="
9522 + (atoken != null && atoken.hiddenRequested)
9523 + " mAttachedHidden=" + win.mAttachedHidden);
9524 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009525
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009526 // If this view is GONE, then skip it -- keep the current
9527 // frame, and let the caller know so they can ignore it
9528 // if they want. (We do the normal layout for INVISIBLE
9529 // windows, since that means "perform layout as normal,
9530 // just don't display").
9531 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009532 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009533 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009534 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009535 win.mContentChanged = false;
9536 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009537 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9538 win.mLayoutSeq = seq;
9539 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9540 + win.mFrame + " mContainingFrame="
9541 + win.mContainingFrame + " mDisplayFrame="
9542 + win.mDisplayFrame);
9543 } else {
9544 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009545 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009547 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009548
9549 // Now perform layout of attached windows, which usually
9550 // depend on the position of the window they are attached to.
9551 // XXX does not deal with windows that are attached to windows
9552 // that are themselves attached.
9553 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009554 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009555
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009556 if (win.mLayoutAttached) {
9557 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9558 + " mHaveFrame=" + win.mHaveFrame
9559 + " mViewVisibility=" + win.mViewVisibility
9560 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009561 // If this view is GONE, then skip it -- keep the current
9562 // frame, and let the caller know so they can ignore it
9563 // if they want. (We do the normal layout for INVISIBLE
9564 // windows, since that means "perform layout as normal,
9565 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009566 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9567 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009568 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009569 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009570 win.mContentChanged = false;
9571 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009572 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9573 win.mLayoutSeq = seq;
9574 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9575 + win.mFrame + " mContainingFrame="
9576 + win.mContainingFrame + " mDisplayFrame="
9577 + win.mDisplayFrame);
9578 }
9579 }
9580 }
Jeff Brown349703e2010-06-22 01:27:15 -07009581
9582 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009583 mInputMonitor.setUpdateInputWindowsNeededLw();
9584 if (updateInputWindows) {
9585 mInputMonitor.updateInputWindowsLw();
9586 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009587
9588 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 }
Romain Guy06882f82009-06-10 13:36:04 -07009590
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009591 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009592 private final void performLayoutAndPlaceSurfacesLockedInner(
9593 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009594 if (mDisplay == null) {
9595 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9596 return;
9597 }
9598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009599 final long currentTime = SystemClock.uptimeMillis();
9600 final int dw = mDisplay.getWidth();
9601 final int dh = mDisplay.getHeight();
9602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 int i;
9604
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009605 if (mFocusMayChange) {
9606 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009607 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9608 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009609 }
9610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009611 // Initialize state of exiting tokens.
9612 for (i=mExitingTokens.size()-1; i>=0; i--) {
9613 mExitingTokens.get(i).hasVisible = false;
9614 }
9615
9616 // Initialize state of exiting applications.
9617 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9618 mExitingAppTokens.get(i).hasVisible = false;
9619 }
9620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009621 boolean orientationChangeComplete = true;
9622 Session holdScreen = null;
9623 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009624 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625 boolean focusDisplayed = false;
9626 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009627 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009628 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009629
9630 if (mFxSession == null) {
9631 mFxSession = new SurfaceSession();
9632 createWatermark = true;
9633 }
9634
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009635 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009636
9637 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009638
9639 if (createWatermark) {
9640 createWatermark();
9641 }
9642 if (mWatermark != null) {
9643 mWatermark.positionSurface(dw, dh);
9644 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009645 if (mStrictModeFlash != null) {
9646 mStrictModeFlash.positionSurface(dw, dh);
9647 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009649 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009650 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009651 int repeats = 0;
9652 int changes = 0;
9653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009654 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009655 repeats++;
9656 if (repeats > 6) {
9657 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9658 mLayoutNeeded = false;
9659 break;
9660 }
9661
9662 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9663 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9664 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9665 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9666 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9667 assignLayersLocked();
9668 mLayoutNeeded = true;
9669 }
9670 }
9671 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9672 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009673 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009674 mLayoutNeeded = true;
9675 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9676 }
9677 }
9678 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9679 mLayoutNeeded = true;
9680 }
9681 }
9682
9683 // FIRST LOOP: Perform a layout, if needed.
9684 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009685 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009686 if (changes != 0) {
9687 continue;
9688 }
9689 } else {
9690 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9691 changes = 0;
9692 }
9693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694 final int transactionSequence = ++mTransactionSequence;
9695
9696 // Update animations of all applications, including those
9697 // associated with exiting/removed apps
9698 boolean tokensAnimating = false;
9699 final int NAT = mAppTokens.size();
9700 for (i=0; i<NAT; i++) {
9701 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9702 tokensAnimating = true;
9703 }
9704 }
9705 final int NEAT = mExitingAppTokens.size();
9706 for (i=0; i<NEAT; i++) {
9707 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9708 tokensAnimating = true;
9709 }
9710 }
9711
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009712 // SECOND LOOP: Execute animations and update visibility of windows.
9713
Joe Onorato8a9b2202010-02-26 18:56:32 -08009714 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009715 + transactionSequence + " tokensAnimating="
9716 + tokensAnimating);
9717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009718 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009720 if (mScreenRotationAnimation != null) {
9721 if (mScreenRotationAnimation.isAnimating()) {
9722 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9723 animating = true;
9724 } else {
9725 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009726 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009727 }
9728 }
9729 }
9730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009731 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009732 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009733 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009734 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009735
9736 mPolicy.beginAnimationLw(dw, dh);
9737
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009738 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009740 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009741 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742
9743 final WindowManager.LayoutParams attrs = w.mAttrs;
9744
9745 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009746 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009747 if (w.commitFinishDrawingLocked(currentTime)) {
9748 if ((w.mAttrs.flags
9749 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009751 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009752 wallpaperMayChange = true;
9753 }
9754 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009755
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009756 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009757
9758 int animDw = dw;
9759 int animDh = dh;
9760
9761 // If the window has moved due to its containing
9762 // content frame changing, then we'd like to animate
9763 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009764 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009765 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009766 // Frame has moved, containing content frame
9767 // has also moved, and we're not currently animating...
9768 // let's do something.
9769 Animation a = AnimationUtils.loadAnimation(mContext,
9770 com.android.internal.R.anim.window_move_from_decor);
9771 w.setAnimation(a);
9772 animDw = w.mLastFrame.left - w.mFrame.left;
9773 animDh = w.mLastFrame.top - w.mFrame.top;
9774 }
9775
9776 // Execute animation.
9777 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9778 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009779
9780 // If this window is animating, make a note that we have
9781 // an animating window and take care of a request to run
9782 // a detached wallpaper animation.
9783 if (nowAnimating) {
9784 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9785 windowDetachedWallpaper = w;
9786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009789
9790 // If this window's app token is running a detached wallpaper
9791 // animation, make a note so we can ensure the wallpaper is
9792 // displayed behind it.
9793 if (w.mAppToken != null && w.mAppToken.animation != null
9794 && w.mAppToken.animation.getDetachWallpaper()) {
9795 windowDetachedWallpaper = w;
9796 }
9797
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009798 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9799 wallpaperMayChange = true;
9800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009801
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009802 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009803 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009804 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009805 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009806 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009807 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009808 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009809 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9810 forceHiding = true;
9811 }
9812 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9813 boolean changed;
9814 if (forceHiding) {
9815 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009816 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9817 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009818 } else {
9819 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009820 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9821 "Now policy shown: " + w);
9822 if (changed) {
9823 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009824 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009825 // Assume we will need to animate. If
9826 // we don't (because the wallpaper will
9827 // stay with the lock screen), then we will
9828 // clean up later.
9829 Animation a = mPolicy.createForceHideEnterAnimation();
9830 if (a != null) {
9831 w.setAnimation(a);
9832 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009833 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009834 if (mCurrentFocus == null ||
9835 mCurrentFocus.mLayer < w.mLayer) {
9836 // We are showing on to of the current
9837 // focus, so re-evaluate focus to make
9838 // sure it is correct.
9839 mFocusMayChange = true;
9840 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009841 }
9842 }
9843 if (changed && (attrs.flags
9844 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9845 wallpaperMayChange = true;
9846 }
9847 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009849 mPolicy.animatingWindowLw(w, attrs);
9850 }
9851
9852 final AppWindowToken atoken = w.mAppToken;
9853 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9854 if (atoken.lastTransactionSequence != transactionSequence) {
9855 atoken.lastTransactionSequence = transactionSequence;
9856 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9857 atoken.startingDisplayed = false;
9858 }
9859 if ((w.isOnScreen() || w.mAttrs.type
9860 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9861 && !w.mExiting && !w.mDestroying) {
9862 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009863 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009864 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009865 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009866 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009867 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 + " pv=" + w.mPolicyVisibility
9869 + " dp=" + w.mDrawPending
9870 + " cdp=" + w.mCommitDrawPending
9871 + " ah=" + w.mAttachedHidden
9872 + " th=" + atoken.hiddenRequested
9873 + " a=" + w.mAnimating);
9874 }
9875 }
9876 if (w != atoken.startingWindow) {
9877 if (!atoken.freezingScreen || !w.mAppFreezing) {
9878 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009879 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009880 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009881 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 "tokenMayBeDrawn: " + atoken
9883 + " freezingScreen=" + atoken.freezingScreen
9884 + " mAppFreezing=" + w.mAppFreezing);
9885 tokenMayBeDrawn = true;
9886 }
9887 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009888 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889 atoken.startingDisplayed = true;
9890 }
9891 }
9892 } else if (w.mReadyToShow) {
9893 w.performShowLocked();
9894 }
9895 }
9896
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009897 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009898
9899 if (tokenMayBeDrawn) {
9900 // See if any windows have been drawn, so they (and others
9901 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009902 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009904 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905 if (wtoken.freezingScreen) {
9906 int numInteresting = wtoken.numInterestingWindows;
9907 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009908 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 "allDrawn: " + wtoken
9910 + " interesting=" + numInteresting
9911 + " drawn=" + wtoken.numDrawnWindows);
9912 wtoken.showAllWindowsLocked();
9913 unsetAppFreezingScreenLocked(wtoken, false, true);
9914 orientationChangeComplete = true;
9915 }
9916 } else if (!wtoken.allDrawn) {
9917 int numInteresting = wtoken.numInterestingWindows;
9918 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009919 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920 "allDrawn: " + wtoken
9921 + " interesting=" + numInteresting
9922 + " drawn=" + wtoken.numDrawnWindows);
9923 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009924 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925
9926 // We can now show all of the drawn windows!
9927 if (!mOpeningApps.contains(wtoken)) {
9928 wtoken.showAllWindowsLocked();
9929 }
9930 }
9931 }
9932 }
9933 }
9934
9935 // If we are ready to perform an app transition, check through
9936 // all of the app tokens to be shown and see if they are ready
9937 // to go.
9938 if (mAppTransitionReady) {
9939 int NN = mOpeningApps.size();
9940 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009941 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 "Checking " + NN + " opening apps (frozen="
9943 + mDisplayFrozen + " timeout="
9944 + mAppTransitionTimeout + ")...");
9945 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9946 // If the display isn't frozen, wait to do anything until
9947 // all of the apps are ready. Otherwise just go because
9948 // we'll unfreeze the display when everyone is ready.
9949 for (i=0; i<NN && goodToGo; i++) {
9950 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009951 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009952 "Check opening app" + wtoken + ": allDrawn="
9953 + wtoken.allDrawn + " startingDisplayed="
9954 + wtoken.startingDisplayed);
9955 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9956 && !wtoken.startingMoved) {
9957 goodToGo = false;
9958 }
9959 }
9960 }
9961 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009962 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 int transit = mNextAppTransition;
9964 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009965 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009966 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009967 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009968 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009969 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009970 mAppTransitionTimeout = false;
9971 mStartingIconInTransition = false;
9972 mSkipAppTransitionAnimation = false;
9973
9974 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9975
Dianne Hackborna8f60182009-09-01 19:01:50 -07009976 // If there are applications waiting to come to the
9977 // top of the stack, now is the time to move their windows.
9978 // (Note that we don't do apps going to the bottom
9979 // here -- we want to keep their windows in the old
9980 // Z-order until the animation completes.)
9981 if (mToTopApps.size() > 0) {
9982 NN = mAppTokens.size();
9983 for (i=0; i<NN; i++) {
9984 AppWindowToken wtoken = mAppTokens.get(i);
9985 if (wtoken.sendingToTop) {
9986 wtoken.sendingToTop = false;
9987 moveAppWindowsLocked(wtoken, NN, false);
9988 }
9989 }
9990 mToTopApps.clear();
9991 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009992
Dianne Hackborn25994b42009-09-04 14:21:19 -07009993 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009994
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009995 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009996 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009997
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009998 // The top-most window will supply the layout params,
9999 // and we will determine it below.
10000 LayoutParams animLp = null;
10001 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010002 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010003
Joe Onorato8a9b2202010-02-26 18:56:32 -080010004 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010005 "New wallpaper target=" + mWallpaperTarget
10006 + ", lower target=" + mLowerWallpaperTarget
10007 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010008 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010009 // Do a first pass through the tokens for two
10010 // things:
10011 // (1) Determine if both the closing and opening
10012 // app token sets are wallpaper targets, in which
10013 // case special animations are needed
10014 // (since the wallpaper needs to stay static
10015 // behind them).
10016 // (2) Find the layout params of the top-most
10017 // application window in the tokens, which is
10018 // what will control the animation theme.
10019 final int NC = mClosingApps.size();
10020 NN = NC + mOpeningApps.size();
10021 for (i=0; i<NN; i++) {
10022 AppWindowToken wtoken;
10023 int mode;
10024 if (i < NC) {
10025 wtoken = mClosingApps.get(i);
10026 mode = 1;
10027 } else {
10028 wtoken = mOpeningApps.get(i-NC);
10029 mode = 2;
10030 }
10031 if (mLowerWallpaperTarget != null) {
10032 if (mLowerWallpaperTarget.mAppToken == wtoken
10033 || mUpperWallpaperTarget.mAppToken == wtoken) {
10034 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010035 }
10036 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010037 if (wtoken.appFullscreen) {
10038 WindowState ws = wtoken.findMainWindow();
10039 if (ws != null) {
10040 // If this is a compatibility mode
10041 // window, we will always use its anim.
10042 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10043 animLp = ws.mAttrs;
10044 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010045 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010046 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010047 bestAnimLayer = ws.mLayer;
10048 }
10049 fullscreenAnim = true;
10050 }
10051 } else if (!fullscreenAnim) {
10052 WindowState ws = wtoken.findMainWindow();
10053 if (ws != null) {
10054 if (ws.mLayer > bestAnimLayer) {
10055 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010056 bestAnimLayer = ws.mLayer;
10057 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010058 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010059 }
10060 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010061
Dianne Hackborn25994b42009-09-04 14:21:19 -070010062 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010063 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010064 "Wallpaper animation!");
10065 switch (transit) {
10066 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10067 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10068 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10069 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10070 break;
10071 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10072 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10073 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10074 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10075 break;
10076 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010077 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010078 "New transit: " + transit);
10079 } else if (oldWallpaper != null) {
10080 // We are transitioning from an activity with
10081 // a wallpaper to one without.
10082 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010083 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010084 "New transit away from wallpaper: " + transit);
10085 } else if (mWallpaperTarget != null) {
10086 // We are transitioning from an activity without
10087 // a wallpaper to now showing the wallpaper
10088 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010089 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010090 "New transit into wallpaper: " + transit);
10091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010092
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010093 // If all closing windows are obscured, then there is
10094 // no need to do an animation. This is the case, for
10095 // example, when this transition is being done behind
10096 // the lock screen.
10097 if (!mPolicy.allowAppAnimationsLw()) {
10098 animLp = null;
10099 }
10100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010101 NN = mOpeningApps.size();
10102 for (i=0; i<NN; i++) {
10103 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010104 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010105 "Now opening app" + wtoken);
10106 wtoken.reportedVisible = false;
10107 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010108 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010109 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010110 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010111 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 wtoken.showAllWindowsLocked();
10113 }
10114 NN = mClosingApps.size();
10115 for (i=0; i<NN; i++) {
10116 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010117 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 "Now closing app" + wtoken);
10119 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010120 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010121 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010122 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010123 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 // Force the allDrawn flag, because we want to start
10125 // this guy's animations regardless of whether it's
10126 // gotten drawn.
10127 wtoken.allDrawn = true;
10128 }
10129
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010130 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010132 mOpeningApps.clear();
10133 mClosingApps.clear();
10134
10135 // This has changed the visibility of windows, so perform
10136 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010137 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10138 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010139 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010140 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10141 assignLayersLocked();
10142 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010143 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10144 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010145 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010146 }
10147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010148
Dianne Hackborn16064f92010-03-25 00:47:24 -070010149 int adjResult = 0;
10150
Dianne Hackborna8f60182009-09-01 19:01:50 -070010151 if (!animating && mAppTransitionRunning) {
10152 // We have finished the animation of an app transition. To do
10153 // this, we have delayed a lot of operations like showing and
10154 // hiding apps, moving apps in Z-order, etc. The app token list
10155 // reflects the correct Z-order, but the window list may now
10156 // be out of sync with it. So here we will just rebuild the
10157 // entire app window list. Fun!
10158 mAppTransitionRunning = false;
10159 // Clear information about apps that were moving.
10160 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010161
Dianne Hackborna8f60182009-09-01 19:01:50 -070010162 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010163 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010164 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010165 moveInputMethodWindowsIfNeededLocked(false);
10166 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010167 // Since the window list has been rebuilt, focus might
10168 // have to be recomputed since the actual order of windows
10169 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010170 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010171 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010172
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010173 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010174 // At this point, there was a window with a wallpaper that
10175 // was force hiding other windows behind it, but now it
10176 // is going away. This may be simple -- just animate
10177 // away the wallpaper and its window -- or it may be
10178 // hard -- the wallpaper now needs to be shown behind
10179 // something that was hidden.
10180 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010181 if (mLowerWallpaperTarget != null
10182 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010183 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010184 "wallpaperForceHiding changed with lower="
10185 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010186 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010187 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10188 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10189 if (mLowerWallpaperTarget.mAppToken.hidden) {
10190 // The lower target has become hidden before we
10191 // actually started the animation... let's completely
10192 // re-evaluate everything.
10193 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010194 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010195 }
10196 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010197 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010198 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010199 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010200 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010201 + " NEW: " + mWallpaperTarget
10202 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010203 if (mLowerWallpaperTarget == null) {
10204 // Whoops, we don't need a special wallpaper animation.
10205 // Clear them out.
10206 forceHiding = false;
10207 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010208 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010209 if (w.mSurface != null) {
10210 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010211 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010212 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010213 forceHiding = true;
10214 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10215 if (!w.mAnimating) {
10216 // We set the animation above so it
10217 // is not yet running.
10218 w.clearAnimation();
10219 }
10220 }
10221 }
10222 }
10223 }
10224 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010225
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010226 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10227 if (DEBUG_WALLPAPER) Slog.v(TAG,
10228 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10229 + windowDetachedWallpaper);
10230 mWindowDetachedWallpaper = windowDetachedWallpaper;
10231 wallpaperMayChange = true;
10232 }
10233
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010234 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010235 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010236 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010237 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010239
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010240 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010241 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010242 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010243 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010244 assignLayersLocked();
10245 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010246 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010247 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010248 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010249 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010250
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010251 if (mFocusMayChange) {
10252 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010253 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10254 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010255 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010256 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010257 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010258 }
10259
10260 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010261 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010262 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010263
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010264 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10265 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010266 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010267
10268 // THIRD LOOP: Update the surfaces of all windows.
10269
10270 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10271
10272 boolean obscured = false;
10273 boolean blurring = false;
10274 boolean dimming = false;
10275 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010276 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010277 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010279 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010282 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283
10284 boolean displayed = false;
10285 final WindowManager.LayoutParams attrs = w.mAttrs;
10286 final int attrFlags = attrs.flags;
10287
10288 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010289 // XXX NOTE: The logic here could be improved. We have
10290 // the decision about whether to resize a window separated
10291 // from whether to hide the surface. This can cause us to
10292 // resize a surface even if we are going to hide it. You
10293 // can see this by (1) holding device in landscape mode on
10294 // home screen; (2) tapping browser icon (device will rotate
10295 // to landscape; (3) tap home. The wallpaper will be resized
10296 // in step 2 but then immediately hidden, causing us to
10297 // have to resize and then redraw it again in step 3. It
10298 // would be nice to figure out how to avoid this, but it is
10299 // difficult because we do need to resize surfaces in some
10300 // cases while they are hidden such as when first showing a
10301 // window.
10302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010303 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010304 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010305 TAG, "Placing surface #" + i + " " + w.mSurface
10306 + ": new=" + w.mShownFrame + ", old="
10307 + w.mLastShownFrame);
10308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010309 int width, height;
10310 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 // for a scaled surface, we just want to use
10312 // the requested size.
10313 width = w.mRequestedWidth;
10314 height = w.mRequestedHeight;
10315 w.mLastRequestedWidth = width;
10316 w.mLastRequestedHeight = height;
10317 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010318 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319 width = w.mShownFrame.width();
10320 height = w.mShownFrame.height();
10321 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010322 }
10323
Jeff Brownfbae7222011-01-23 13:07:25 -080010324 if (w.mSurface != null) {
10325 if (w.mSurfaceX != w.mShownFrame.left
10326 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010327 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010328 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010329 "POS " + w.mShownFrame.left
10330 + ", " + w.mShownFrame.top, null);
10331 w.mSurfaceX = w.mShownFrame.left;
10332 w.mSurfaceY = w.mShownFrame.top;
10333 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10334 } catch (RuntimeException e) {
10335 Slog.w(TAG, "Error positioning surface of " + w
10336 + " pos=(" + w.mShownFrame.left
10337 + "," + w.mShownFrame.top + ")", e);
10338 if (!recoveringMemory) {
10339 reclaimSomeSurfaceMemoryLocked(w, "position");
10340 }
10341 }
10342 }
10343
10344 if (width < 1) {
10345 width = 1;
10346 }
10347 if (height < 1) {
10348 height = 1;
10349 }
10350
10351 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10352 try {
10353 if (SHOW_TRANSACTIONS) logSurface(w,
10354 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010355 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010356 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010357 w.mSurfaceW = width;
10358 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010360 } catch (RuntimeException e) {
10361 // If something goes wrong with the surface (such
10362 // as running out of memory), don't take down the
10363 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010364 Slog.e(TAG, "Error resizing surface of " + w
10365 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010366 if (!recoveringMemory) {
10367 reclaimSomeSurfaceMemoryLocked(w, "size");
10368 }
10369 }
10370 }
10371 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010372
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010373 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010374 w.mContentInsetsChanged =
10375 !w.mLastContentInsets.equals(w.mContentInsets);
10376 w.mVisibleInsetsChanged =
10377 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010378 boolean configChanged =
10379 w.mConfiguration != mCurConfiguration
10380 && (w.mConfiguration == null
10381 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010382 if (DEBUG_CONFIGURATION && configChanged) {
10383 Slog.v(TAG, "Win " + w + " config changed: "
10384 + mCurConfiguration);
10385 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010386 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010387 + ": configChanged=" + configChanged
10388 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010389 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10390 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010391 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010392 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010393 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010394 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010395 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10396 Slog.v(TAG, "Resize reasons: "
10397 + "frameChanged=" + frameChanged
10398 + " contentInsetsChanged=" + w.mContentInsetsChanged
10399 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10400 + " surfaceResized=" + w.mSurfaceResized
10401 + " configChanged=" + configChanged);
10402 }
10403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010404 w.mLastFrame.set(w.mFrame);
10405 w.mLastContentInsets.set(w.mContentInsets);
10406 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010407 // If the screen is currently frozen, then keep
10408 // it frozen until this window draws at its new
10409 // orientation.
10410 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010411 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010412 "Resizing while display frozen: " + w);
10413 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010414 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010415 mWindowsFreezingScreen = true;
10416 // XXX should probably keep timeout from
10417 // when we first froze the display.
10418 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10419 mH.sendMessageDelayed(mH.obtainMessage(
10420 H.WINDOW_FREEZE_TIMEOUT), 2000);
10421 }
10422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 // If the orientation is changing, then we need to
10424 // hold off on unfreezing the display until this
10425 // window has been redrawn; to do that, we need
10426 // to go through the process of getting informed
10427 // by the application when it has finished drawing.
10428 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010429 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010430 "Orientation start waiting for draw in "
10431 + w + ", surface " + w.mSurface);
10432 w.mDrawPending = true;
10433 w.mCommitDrawPending = false;
10434 w.mReadyToShow = false;
10435 if (w.mAppToken != null) {
10436 w.mAppToken.allDrawn = false;
10437 }
10438 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010439 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010440 "Resizing window " + w + " to " + w.mFrame);
10441 mResizingWindows.add(w);
10442 } else if (w.mOrientationChanging) {
10443 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010444 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010445 "Orientation not waiting for draw in "
10446 + w + ", surface " + w.mSurface);
10447 w.mOrientationChanging = false;
10448 }
10449 }
10450 }
10451
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010452 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010453 if (!w.mLastHidden) {
10454 //dump();
10455 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010456 if (SHOW_TRANSACTIONS) logSurface(w,
10457 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010458 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010459 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 try {
10461 w.mSurface.hide();
10462 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010463 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010464 }
10465 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 }
10467 // If we are waiting for this window to handle an
10468 // orientation change, well, it is hidden, so
10469 // doesn't really matter. Note that this does
10470 // introduce a potential glitch if the window
10471 // becomes unhidden before it has drawn for the
10472 // new orientation.
10473 if (w.mOrientationChanging) {
10474 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010475 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010476 "Orientation change skips hidden " + w);
10477 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 } else if (w.mLastLayer != w.mAnimLayer
10479 || w.mLastAlpha != w.mShownAlpha
10480 || w.mLastDsDx != w.mDsDx
10481 || w.mLastDtDx != w.mDtDx
10482 || w.mLastDsDy != w.mDsDy
10483 || w.mLastDtDy != w.mDtDy
10484 || w.mLastHScale != w.mHScale
10485 || w.mLastVScale != w.mVScale
10486 || w.mLastHidden) {
10487 displayed = true;
10488 w.mLastAlpha = w.mShownAlpha;
10489 w.mLastLayer = w.mAnimLayer;
10490 w.mLastDsDx = w.mDsDx;
10491 w.mLastDtDx = w.mDtDx;
10492 w.mLastDsDy = w.mDsDy;
10493 w.mLastDtDy = w.mDtDy;
10494 w.mLastHScale = w.mHScale;
10495 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010496 if (SHOW_TRANSACTIONS) logSurface(w,
10497 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010498 + " matrix=[" + (w.mDsDx*w.mHScale)
10499 + "," + (w.mDtDx*w.mVScale)
10500 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010501 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 if (w.mSurface != null) {
10503 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010504 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010505 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010506 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 w.mSurface.setLayer(w.mAnimLayer);
10508 w.mSurface.setMatrix(
10509 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10510 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10511 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010512 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 if (!recoveringMemory) {
10514 reclaimSomeSurfaceMemoryLocked(w, "update");
10515 }
10516 }
10517 }
10518
10519 if (w.mLastHidden && !w.mDrawPending
10520 && !w.mCommitDrawPending
10521 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010522 if (SHOW_TRANSACTIONS) logSurface(w,
10523 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010524 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 + " during relayout");
10526 if (showSurfaceRobustlyLocked(w)) {
10527 w.mHasDrawn = true;
10528 w.mLastHidden = false;
10529 } else {
10530 w.mOrientationChanging = false;
10531 }
10532 }
10533 if (w.mSurface != null) {
10534 w.mToken.hasVisible = true;
10535 }
10536 } else {
10537 displayed = true;
10538 }
10539
10540 if (displayed) {
10541 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010542 if (attrs.width == LayoutParams.MATCH_PARENT
10543 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010544 covered = true;
10545 }
10546 }
10547 if (w.mOrientationChanging) {
10548 if (w.mDrawPending || w.mCommitDrawPending) {
10549 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010550 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551 "Orientation continue waiting for draw in " + w);
10552 } else {
10553 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010554 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010555 "Orientation change complete in " + w);
10556 }
10557 }
10558 w.mToken.hasVisible = true;
10559 }
10560 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010561 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010562 "Orientation change skips hidden " + w);
10563 w.mOrientationChanging = false;
10564 }
10565
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010566 if (w.mContentChanged) {
10567 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10568 w.mContentChanged = false;
10569 }
10570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010571 final boolean canBeSeen = w.isDisplayedLw();
10572
10573 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10574 focusDisplayed = true;
10575 }
10576
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010577 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010579 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010580 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 if (w.mSurface != null) {
10582 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10583 holdScreen = w.mSession;
10584 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010585 if (!syswin && w.mAttrs.screenBrightness >= 0
10586 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010587 screenBrightness = w.mAttrs.screenBrightness;
10588 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010589 if (!syswin && w.mAttrs.buttonBrightness >= 0
10590 && buttonBrightness < 0) {
10591 buttonBrightness = w.mAttrs.buttonBrightness;
10592 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010593 if (canBeSeen
10594 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10595 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10596 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010597 syswin = true;
10598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010600
Dianne Hackborn25994b42009-09-04 14:21:19 -070010601 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10602 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010603 // This window completely covers everything behind it,
10604 // so we want to leave all of them as unblurred (for
10605 // performance reasons).
10606 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010607 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010608 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010609 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010610 obscured = true;
10611 if (mBackgroundFillerSurface == null) {
10612 try {
10613 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010614 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010615 0, dw, dh,
10616 PixelFormat.OPAQUE,
10617 Surface.FX_SURFACE_NORMAL);
10618 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010619 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010620 }
10621 }
10622 try {
10623 mBackgroundFillerSurface.setPosition(0, 0);
10624 mBackgroundFillerSurface.setSize(dw, dh);
10625 // Using the same layer as Dim because they will never be shown at the
10626 // same time.
10627 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10628 mBackgroundFillerSurface.show();
10629 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010630 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010631 }
10632 backgroundFillerShown = true;
10633 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010634 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010635 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010636 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010637 + ": blurring=" + blurring
10638 + " obscured=" + obscured
10639 + " displayed=" + displayed);
10640 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10641 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010642 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010643 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010644 if (mDimAnimator == null) {
10645 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010646 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010647 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010648 mDimAnimator.updateParameters(mContext.getResources(),
10649 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010651 }
10652 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10653 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010654 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010656 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010657 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010658 + mBlurSurface + ": CREATE");
10659 try {
Romain Guy06882f82009-06-10 13:36:04 -070010660 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010661 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 -1, 16, 16,
10663 PixelFormat.OPAQUE,
10664 Surface.FX_SURFACE_BLUR);
10665 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010666 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010667 }
10668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010669 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010670 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10671 + mBlurSurface + ": pos=(0,0) (" +
10672 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010673 mBlurSurface.setPosition(0, 0);
10674 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010675 mBlurSurface.setLayer(w.mAnimLayer-2);
10676 if (!mBlurShown) {
10677 try {
10678 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10679 + mBlurSurface + ": SHOW");
10680 mBlurSurface.show();
10681 } catch (RuntimeException e) {
10682 Slog.w(TAG, "Failure showing blur surface", e);
10683 }
10684 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010685 }
10686 }
10687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010688 }
10689 }
10690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010691
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010692 if (obscuredChanged && mWallpaperTarget == w) {
10693 // This is the wallpaper target and its obscured state
10694 // changed... make sure the current wallaper's visibility
10695 // has been updated accordingly.
10696 updateWallpaperVisibilityLocked();
10697 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010699
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010700 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10701 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010702 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010703 try {
10704 mBackgroundFillerSurface.hide();
10705 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010706 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010707 }
10708 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010709
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010710 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010711 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10712 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010713 }
Romain Guy06882f82009-06-10 13:36:04 -070010714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010715 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010716 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717 + ": HIDE");
10718 try {
10719 mBlurSurface.hide();
10720 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010721 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 }
10723 mBlurShown = false;
10724 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010725 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010726 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010727 }
10728
10729 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010730
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010731 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10732
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010733 if (mWatermark != null) {
10734 mWatermark.drawIfNeeded();
10735 }
10736
Joe Onorato8a9b2202010-02-26 18:56:32 -080010737 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 "With display frozen, orientationChangeComplete="
10739 + orientationChangeComplete);
10740 if (orientationChangeComplete) {
10741 if (mWindowsFreezingScreen) {
10742 mWindowsFreezingScreen = false;
10743 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10744 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010745 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010746 }
Romain Guy06882f82009-06-10 13:36:04 -070010747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010748 i = mResizingWindows.size();
10749 if (i > 0) {
10750 do {
10751 i--;
10752 WindowState win = mResizingWindows.get(i);
10753 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010754 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10755 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010756 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010757 boolean configChanged =
10758 win.mConfiguration != mCurConfiguration
10759 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010760 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10761 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10762 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010763 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010764 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010765 + " / " + mCurConfiguration + " / 0x"
10766 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010767 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010768 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010769 win.mClient.resized(win.mFrame.width(),
10770 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010771 win.mLastVisibleInsets, win.mDrawPending,
10772 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010773 win.mContentInsetsChanged = false;
10774 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010775 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010776 } catch (RemoteException e) {
10777 win.mOrientationChanging = false;
10778 }
10779 } while (i > 0);
10780 mResizingWindows.clear();
10781 }
Romain Guy06882f82009-06-10 13:36:04 -070010782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010783 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010784 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 i = mDestroySurface.size();
10786 if (i > 0) {
10787 do {
10788 i--;
10789 WindowState win = mDestroySurface.get(i);
10790 win.mDestroying = false;
10791 if (mInputMethodWindow == win) {
10792 mInputMethodWindow = null;
10793 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010794 if (win == mWallpaperTarget) {
10795 wallpaperDestroyed = true;
10796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 win.destroySurfaceLocked();
10798 } while (i > 0);
10799 mDestroySurface.clear();
10800 }
10801
10802 // Time to remove any exiting tokens?
10803 for (i=mExitingTokens.size()-1; i>=0; i--) {
10804 WindowToken token = mExitingTokens.get(i);
10805 if (!token.hasVisible) {
10806 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010807 if (token.windowType == TYPE_WALLPAPER) {
10808 mWallpaperTokens.remove(token);
10809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 }
10811 }
10812
10813 // Time to remove any exiting applications?
10814 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10815 AppWindowToken token = mExitingAppTokens.get(i);
10816 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010817 // Make sure there is no animation running on this token,
10818 // so any windows associated with it will be removed as
10819 // soon as their animations are complete
10820 token.animation = null;
10821 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010822 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10823 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010824 mAppTokens.remove(token);
10825 mExitingAppTokens.remove(i);
10826 }
10827 }
10828
Dianne Hackborna8f60182009-09-01 19:01:50 -070010829 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010830
Dianne Hackborna8f60182009-09-01 19:01:50 -070010831 if (!animating && mAppTransitionRunning) {
10832 // We have finished the animation of an app transition. To do
10833 // this, we have delayed a lot of operations like showing and
10834 // hiding apps, moving apps in Z-order, etc. The app token list
10835 // reflects the correct Z-order, but the window list may now
10836 // be out of sync with it. So here we will just rebuild the
10837 // entire app window list. Fun!
10838 mAppTransitionRunning = false;
10839 needRelayout = true;
10840 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010841 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010842 // Clear information about apps that were moving.
10843 mToBottomApps.clear();
10844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010846 if (focusDisplayed) {
10847 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10848 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010849 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010850 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010851 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010852 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010853 requestAnimationLocked(0);
10854 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010855 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10856 }
Jeff Browneb857f12010-07-16 10:06:33 -070010857
Jeff Brown3a22cd92011-01-21 13:59:04 -080010858 // Finally update all input windows now that the window changes have stabilized.
10859 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Browne33348b2010-07-15 23:54:05 -070010860 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010861
Jeff Brown8e03b752010-06-13 19:16:55 -070010862 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010863 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10864 mPowerManager.setScreenBrightnessOverride(-1);
10865 } else {
10866 mPowerManager.setScreenBrightnessOverride((int)
10867 (screenBrightness * Power.BRIGHTNESS_ON));
10868 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010869 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10870 mPowerManager.setButtonBrightnessOverride(-1);
10871 } else {
10872 mPowerManager.setButtonBrightnessOverride((int)
10873 (buttonBrightness * Power.BRIGHTNESS_ON));
10874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 if (holdScreen != mHoldingScreenOn) {
10876 mHoldingScreenOn = holdScreen;
10877 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10878 mH.sendMessage(m);
10879 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010880
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010881 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010882 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010883 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10884 LocalPowerManager.BUTTON_EVENT, true);
10885 mTurnOnScreen = false;
10886 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010887
Dianne Hackborn89ba6752011-01-23 16:51:16 -080010888 if (updateRotation) {
10889 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
10890 boolean changed = setRotationUncheckedLocked(
10891 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
10892 if (changed) {
10893 sendNewConfiguration();
10894 }
10895 }
10896
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010897 // Check to see if we are now in a state where the screen should
10898 // be enabled, because the window obscured flags have changed.
10899 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010900 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010901
10902 /**
10903 * Must be called with the main window manager lock held.
10904 */
10905 void setHoldScreenLocked(boolean holding) {
10906 boolean state = mHoldingScreenWakeLock.isHeld();
10907 if (holding != state) {
10908 if (holding) {
10909 mHoldingScreenWakeLock.acquire();
10910 } else {
10911 mPolicy.screenOnStoppedLw();
10912 mHoldingScreenWakeLock.release();
10913 }
10914 }
10915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010916
10917 void requestAnimationLocked(long delay) {
10918 if (!mAnimationPending) {
10919 mAnimationPending = true;
10920 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10921 }
10922 }
Romain Guy06882f82009-06-10 13:36:04 -070010923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 /**
10925 * Have the surface flinger show a surface, robustly dealing with
10926 * error conditions. In particular, if there is not enough memory
10927 * to show the surface, then we will try to get rid of other surfaces
10928 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010929 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010930 * @return Returns true if the surface was successfully shown.
10931 */
10932 boolean showSurfaceRobustlyLocked(WindowState win) {
10933 try {
10934 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010935 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010936 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010937 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010938 if (DEBUG_VISIBILITY) Slog.v(TAG,
10939 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010940 win.mTurnOnScreen = false;
10941 mTurnOnScreen = true;
10942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010943 }
10944 return true;
10945 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010946 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 }
Romain Guy06882f82009-06-10 13:36:04 -070010948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010949 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010951 return false;
10952 }
Romain Guy06882f82009-06-10 13:36:04 -070010953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010954 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10955 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010956
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010957 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010958 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010960 if (mForceRemoves == null) {
10961 mForceRemoves = new ArrayList<WindowState>();
10962 }
Romain Guy06882f82009-06-10 13:36:04 -070010963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010964 long callingIdentity = Binder.clearCallingIdentity();
10965 try {
10966 // There was some problem... first, do a sanity check of the
10967 // window list to make sure we haven't left any dangling surfaces
10968 // around.
10969 int N = mWindows.size();
10970 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010971 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010972 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010973 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 if (ws.mSurface != null) {
10975 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010976 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010977 + ws + " surface=" + ws.mSurface
10978 + " token=" + win.mToken
10979 + " pid=" + ws.mSession.mPid
10980 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010981 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010982 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010983 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010984 ws.mSurface = null;
10985 mForceRemoves.add(ws);
10986 i--;
10987 N--;
10988 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010989 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010990 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010991 + ws + " surface=" + ws.mSurface
10992 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010993 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010994 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010995 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010996 ws.mSurface = null;
10997 leakedSurface = true;
10998 }
10999 }
11000 }
Romain Guy06882f82009-06-10 13:36:04 -070011001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011002 boolean killedApps = false;
11003 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011004 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011005 SparseIntArray pidCandidates = new SparseIntArray();
11006 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011007 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011008 if (ws.mSurface != null) {
11009 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11010 }
11011 }
11012 if (pidCandidates.size() > 0) {
11013 int[] pids = new int[pidCandidates.size()];
11014 for (int i=0; i<pids.length; i++) {
11015 pids[i] = pidCandidates.keyAt(i);
11016 }
11017 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011018 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011019 killedApps = true;
11020 }
11021 } catch (RemoteException e) {
11022 }
11023 }
11024 }
Romain Guy06882f82009-06-10 13:36:04 -070011025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 if (leakedSurface || killedApps) {
11027 // We managed to reclaim some memory, so get rid of the trouble
11028 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011029 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011030 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011031 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011032 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011033 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011034 win.mSurface = null;
11035 }
Romain Guy06882f82009-06-10 13:36:04 -070011036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011037 try {
11038 win.mClient.dispatchGetNewSurface();
11039 } catch (RemoteException e) {
11040 }
11041 }
11042 } finally {
11043 Binder.restoreCallingIdentity(callingIdentity);
11044 }
11045 }
Romain Guy06882f82009-06-10 13:36:04 -070011046
Jeff Brown3a22cd92011-01-21 13:59:04 -080011047 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011048 WindowState newFocus = computeFocusedWindowLocked();
11049 if (mCurrentFocus != newFocus) {
11050 // This check makes sure that we don't already have the focus
11051 // change message pending.
11052 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11053 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011054 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011055 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11056 final WindowState oldFocus = mCurrentFocus;
11057 mCurrentFocus = newFocus;
11058 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011060 final WindowState imWindow = mInputMethodWindow;
11061 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011062 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011063 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011064 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11065 mLayoutNeeded = true;
11066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011067 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011068 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011069 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11070 // Client will do the layout, but we need to assign layers
11071 // for handleNewWindowLocked() below.
11072 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011073 }
11074 }
Jeff Brown349703e2010-06-22 01:27:15 -070011075
11076 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11077 // If we defer assigning layers, then the caller is responsible for
11078 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011079 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011081 return true;
11082 }
11083 return false;
11084 }
Jeff Brown349703e2010-06-22 01:27:15 -070011085
Jeff Brown3a22cd92011-01-21 13:59:04 -080011086 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11087 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011088 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011089
11090 private WindowState computeFocusedWindowLocked() {
11091 WindowState result = null;
11092 WindowState win;
11093
11094 int i = mWindows.size() - 1;
11095 int nextAppIndex = mAppTokens.size()-1;
11096 WindowToken nextApp = nextAppIndex >= 0
11097 ? mAppTokens.get(nextAppIndex) : null;
11098
11099 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011100 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011101
Joe Onorato8a9b2202010-02-26 18:56:32 -080011102 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011103 TAG, "Looking for focus: " + i
11104 + " = " + win
11105 + ", flags=" + win.mAttrs.flags
11106 + ", canReceive=" + win.canReceiveKeys());
11107
11108 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011110 // If this window's application has been removed, just skip it.
11111 if (thisApp != null && thisApp.removed) {
11112 i--;
11113 continue;
11114 }
Romain Guy06882f82009-06-10 13:36:04 -070011115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011116 // If there is a focused app, don't allow focus to go to any
11117 // windows below it. If this is an application window, step
11118 // through the app tokens until we find its app.
11119 if (thisApp != null && nextApp != null && thisApp != nextApp
11120 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11121 int origAppIndex = nextAppIndex;
11122 while (nextAppIndex > 0) {
11123 if (nextApp == mFocusedApp) {
11124 // Whoops, we are below the focused app... no focus
11125 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011126 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011127 TAG, "Reached focused app: " + mFocusedApp);
11128 return null;
11129 }
11130 nextAppIndex--;
11131 nextApp = mAppTokens.get(nextAppIndex);
11132 if (nextApp == thisApp) {
11133 break;
11134 }
11135 }
11136 if (thisApp != nextApp) {
11137 // Uh oh, the app token doesn't exist! This shouldn't
11138 // happen, but if it does we can get totally hosed...
11139 // so restart at the original app.
11140 nextAppIndex = origAppIndex;
11141 nextApp = mAppTokens.get(nextAppIndex);
11142 }
11143 }
11144
11145 // Dispatch to this window if it is wants key events.
11146 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011147 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011148 TAG, "Found focus @ " + i + " = " + win);
11149 result = win;
11150 break;
11151 }
11152
11153 i--;
11154 }
11155
11156 return result;
11157 }
11158
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011159 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011160 if (mDisplayFrozen) {
11161 return;
11162 }
Romain Guy06882f82009-06-10 13:36:04 -070011163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011164 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011166 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011167 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011168 if (mFreezeGcPending != 0) {
11169 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011170 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011171 mH.removeMessages(H.FORCE_GC);
11172 Runtime.getRuntime().gc();
11173 mFreezeGcPending = now;
11174 }
11175 } else {
11176 mFreezeGcPending = now;
11177 }
Romain Guy06882f82009-06-10 13:36:04 -070011178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011179 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011180
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011181 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011182
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011183 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11184 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011185 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011186 mAppTransitionReady = true;
11187 }
Romain Guy06882f82009-06-10 13:36:04 -070011188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011189 if (PROFILE_ORIENTATION) {
11190 File file = new File("/data/system/frozen");
11191 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11192 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011193
11194 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011195 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11196 mScreenRotationAnimation.kill();
11197 mScreenRotationAnimation = null;
11198 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011199 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011200 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011201 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011202 }
11203 } else {
11204 Surface.freezeDisplay(0);
11205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011206 }
Romain Guy06882f82009-06-10 13:36:04 -070011207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011208 private void stopFreezingDisplayLocked() {
11209 if (!mDisplayFrozen) {
11210 return;
11211 }
Romain Guy06882f82009-06-10 13:36:04 -070011212
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011213 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11214 return;
11215 }
11216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011217 mDisplayFrozen = false;
11218 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11219 if (PROFILE_ORIENTATION) {
11220 Debug.stopMethodTracing();
11221 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011222
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011223 boolean updateRotation = false;
11224
Dianne Hackborna1111872010-11-23 20:55:11 -080011225 if (CUSTOM_SCREEN_ROTATION) {
11226 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011227 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11228 mTransitionAnimationScale)) {
11229 requestAnimationLocked(0);
11230 } else {
11231 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011232 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011233 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011234 }
11235 } else {
11236 Surface.unfreezeDisplay(0);
11237 }
Romain Guy06882f82009-06-10 13:36:04 -070011238
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011239 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011240
Christopher Tateb696aee2010-04-02 19:08:30 -070011241 // While the display is frozen we don't re-compute the orientation
11242 // to avoid inconsistent states. However, something interesting
11243 // could have actually changed during that time so re-evaluate it
11244 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011245 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011246 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11247 }
11248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011249 // A little kludge: a lot could have happened while the
11250 // display was frozen, so now that we are coming back we
11251 // do a gc so that any remote references the system
11252 // processes holds on others can be released if they are
11253 // no longer needed.
11254 mH.removeMessages(H.FORCE_GC);
11255 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11256 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011258 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011259
11260 if (updateRotation) {
11261 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11262 boolean changed = setRotationUncheckedLocked(
11263 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11264 if (changed) {
11265 sendNewConfiguration();
11266 }
11267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011268 }
Romain Guy06882f82009-06-10 13:36:04 -070011269
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011270 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11271 DisplayMetrics dm) {
11272 if (index < tokens.length) {
11273 String str = tokens[index];
11274 if (str != null && str.length() > 0) {
11275 try {
11276 int val = Integer.parseInt(str);
11277 return val;
11278 } catch (Exception e) {
11279 }
11280 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011281 }
11282 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11283 return defDps;
11284 }
11285 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11286 return val;
11287 }
11288
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011289 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011290 final String[] mTokens;
11291 final String mText;
11292 final Paint mTextPaint;
11293 final int mTextWidth;
11294 final int mTextHeight;
11295 final int mTextAscent;
11296 final int mTextDescent;
11297 final int mDeltaX;
11298 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011299
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011300 Surface mSurface;
11301 int mLastDW;
11302 int mLastDH;
11303 boolean mDrawNeeded;
11304
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011305 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011306 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011307 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011308
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011309 if (false) {
11310 Log.i(TAG, "*********************** WATERMARK");
11311 for (int i=0; i<tokens.length; i++) {
11312 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11313 }
11314 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011315
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011316 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011317
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011318 StringBuilder builder = new StringBuilder(32);
11319 int len = mTokens[0].length();
11320 len = len & ~1;
11321 for (int i=0; i<len; i+=2) {
11322 int c1 = mTokens[0].charAt(i);
11323 int c2 = mTokens[0].charAt(i+1);
11324 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11325 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11326 else c1 -= '0';
11327 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11328 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11329 else c2 -= '0';
11330 builder.append((char)(255-((c1*16)+c2)));
11331 }
11332 mText = builder.toString();
11333 if (false) {
11334 Log.i(TAG, "Final text: " + mText);
11335 }
11336
11337 int fontSize = getPropertyInt(tokens, 1,
11338 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11339
11340 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11341 mTextPaint.setTextSize(fontSize);
11342 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11343
11344 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11345 mTextWidth = (int)mTextPaint.measureText(mText);
11346 mTextAscent = fm.ascent;
11347 mTextDescent = fm.descent;
11348 mTextHeight = fm.descent - fm.ascent;
11349
11350 mDeltaX = getPropertyInt(tokens, 2,
11351 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11352 mDeltaY = getPropertyInt(tokens, 3,
11353 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11354 int shadowColor = getPropertyInt(tokens, 4,
11355 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11356 int color = getPropertyInt(tokens, 5,
11357 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11358 int shadowRadius = getPropertyInt(tokens, 6,
11359 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11360 int shadowDx = getPropertyInt(tokens, 8,
11361 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11362 int shadowDy = getPropertyInt(tokens, 9,
11363 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11364
11365 mTextPaint.setColor(color);
11366 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011367
11368 try {
11369 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011370 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011371 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011372 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011373 mSurface.show();
11374 } catch (OutOfResourcesException e) {
11375 }
11376 }
11377
11378 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011379 if (mLastDW != dw || mLastDH != dh) {
11380 mLastDW = dw;
11381 mLastDH = dh;
11382 mSurface.setSize(dw, dh);
11383 mDrawNeeded = true;
11384 }
11385 }
11386
11387 void drawIfNeeded() {
11388 if (mDrawNeeded) {
11389 final int dw = mLastDW;
11390 final int dh = mLastDH;
11391
11392 mDrawNeeded = false;
11393 Rect dirty = new Rect(0, 0, dw, dh);
11394 Canvas c = null;
11395 try {
11396 c = mSurface.lockCanvas(dirty);
11397 } catch (IllegalArgumentException e) {
11398 } catch (OutOfResourcesException e) {
11399 }
11400 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011401 c.drawColor(0, PorterDuff.Mode.CLEAR);
11402
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011403 int deltaX = mDeltaX;
11404 int deltaY = mDeltaY;
11405
11406 // deltaX shouldn't be close to a round fraction of our
11407 // x step, or else things will line up too much.
11408 int div = (dw+mTextWidth)/deltaX;
11409 int rem = (dw+mTextWidth) - (div*deltaX);
11410 int qdelta = deltaX/4;
11411 if (rem < qdelta || rem > (deltaX-qdelta)) {
11412 deltaX += deltaX/3;
11413 }
11414
11415 int y = -mTextHeight;
11416 int x = -mTextWidth;
11417 while (y < (dh+mTextHeight)) {
11418 c.drawText(mText, x, y, mTextPaint);
11419 x += deltaX;
11420 if (x >= dw) {
11421 x -= (dw+mTextWidth);
11422 y += deltaY;
11423 }
11424 }
11425 mSurface.unlockCanvasAndPost(c);
11426 }
11427 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011428 }
11429 }
11430
11431 void createWatermark() {
11432 if (mWatermark != null) {
11433 return;
11434 }
11435
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011436 File file = new File("/system/etc/setup.conf");
11437 FileInputStream in = null;
11438 try {
11439 in = new FileInputStream(file);
11440 DataInputStream ind = new DataInputStream(in);
11441 String line = ind.readLine();
11442 if (line != null) {
11443 String[] toks = line.split("%");
11444 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011445 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011446 }
11447 }
11448 } catch (FileNotFoundException e) {
11449 } catch (IOException e) {
11450 } finally {
11451 if (in != null) {
11452 try {
11453 in.close();
11454 } catch (IOException e) {
11455 }
11456 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011457 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011458 }
11459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011460 @Override
11461 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11462 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11463 != PackageManager.PERMISSION_GRANTED) {
11464 pw.println("Permission Denial: can't dump WindowManager from from pid="
11465 + Binder.getCallingPid()
11466 + ", uid=" + Binder.getCallingUid());
11467 return;
11468 }
Romain Guy06882f82009-06-10 13:36:04 -070011469
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011470 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011471 pw.println(" ");
11472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011473 synchronized(mWindowMap) {
11474 pw.println("Current Window Manager state:");
11475 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011476 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011477 pw.print(" Window #"); pw.print(i); pw.print(' ');
11478 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011479 w.dump(pw, " ");
11480 }
11481 if (mInputMethodDialogs.size() > 0) {
11482 pw.println(" ");
11483 pw.println(" Input method dialogs:");
11484 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11485 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011486 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011487 }
11488 }
11489 if (mPendingRemove.size() > 0) {
11490 pw.println(" ");
11491 pw.println(" Remove pending for:");
11492 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11493 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011494 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11495 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011496 w.dump(pw, " ");
11497 }
11498 }
11499 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11500 pw.println(" ");
11501 pw.println(" Windows force removing:");
11502 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11503 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011504 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11505 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011506 w.dump(pw, " ");
11507 }
11508 }
11509 if (mDestroySurface.size() > 0) {
11510 pw.println(" ");
11511 pw.println(" Windows waiting to destroy their surface:");
11512 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11513 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011514 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11515 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011516 w.dump(pw, " ");
11517 }
11518 }
11519 if (mLosingFocus.size() > 0) {
11520 pw.println(" ");
11521 pw.println(" Windows losing focus:");
11522 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11523 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011524 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11525 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011526 w.dump(pw, " ");
11527 }
11528 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011529 if (mResizingWindows.size() > 0) {
11530 pw.println(" ");
11531 pw.println(" Windows waiting to resize:");
11532 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11533 WindowState w = mResizingWindows.get(i);
11534 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11535 pw.print(w); pw.println(":");
11536 w.dump(pw, " ");
11537 }
11538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011539 if (mSessions.size() > 0) {
11540 pw.println(" ");
11541 pw.println(" All active sessions:");
11542 Iterator<Session> it = mSessions.iterator();
11543 while (it.hasNext()) {
11544 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011545 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011546 s.dump(pw, " ");
11547 }
11548 }
11549 if (mTokenMap.size() > 0) {
11550 pw.println(" ");
11551 pw.println(" All tokens:");
11552 Iterator<WindowToken> it = mTokenMap.values().iterator();
11553 while (it.hasNext()) {
11554 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011555 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011556 token.dump(pw, " ");
11557 }
11558 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011559 if (mWallpaperTokens.size() > 0) {
11560 pw.println(" ");
11561 pw.println(" Wallpaper tokens:");
11562 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11563 WindowToken token = mWallpaperTokens.get(i);
11564 pw.print(" Wallpaper #"); pw.print(i);
11565 pw.print(' '); pw.print(token); pw.println(':');
11566 token.dump(pw, " ");
11567 }
11568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011569 if (mAppTokens.size() > 0) {
11570 pw.println(" ");
11571 pw.println(" Application tokens in Z order:");
11572 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011573 pw.print(" App #"); pw.print(i); pw.print(": ");
11574 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011575 }
11576 }
11577 if (mFinishedStarting.size() > 0) {
11578 pw.println(" ");
11579 pw.println(" Finishing start of application tokens:");
11580 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11581 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011582 pw.print(" Finished Starting #"); pw.print(i);
11583 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011584 token.dump(pw, " ");
11585 }
11586 }
11587 if (mExitingTokens.size() > 0) {
11588 pw.println(" ");
11589 pw.println(" Exiting tokens:");
11590 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11591 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011592 pw.print(" Exiting #"); pw.print(i);
11593 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011594 token.dump(pw, " ");
11595 }
11596 }
11597 if (mExitingAppTokens.size() > 0) {
11598 pw.println(" ");
11599 pw.println(" Exiting application tokens:");
11600 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11601 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011602 pw.print(" Exiting App #"); pw.print(i);
11603 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011604 token.dump(pw, " ");
11605 }
11606 }
11607 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011608 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11609 pw.print(" mLastFocus="); pw.println(mLastFocus);
11610 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11611 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11612 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011613 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011614 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11615 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11616 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11617 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011618 if (mWindowDetachedWallpaper != null) {
11619 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11620 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011621 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11622 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11623 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011624 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11625 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11626 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11627 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011628 if (mDimAnimator != null) {
11629 mDimAnimator.printTo(pw);
11630 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011631 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011632 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011633 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011634 pw.print(mInputMethodAnimLayerAdjustment);
11635 pw.print(" mWallpaperAnimLayerAdjustment=");
11636 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011637 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11638 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011639 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11640 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011641 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11642 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011643 pw.print(" mRotation="); pw.print(mRotation);
11644 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11645 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011646 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11647 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011648 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11649 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11650 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11651 pw.print(" mNextAppTransition=0x");
11652 pw.print(Integer.toHexString(mNextAppTransition));
11653 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011654 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011655 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011656 if (mNextAppTransitionPackage != null) {
11657 pw.print(" mNextAppTransitionPackage=");
11658 pw.print(mNextAppTransitionPackage);
11659 pw.print(", mNextAppTransitionEnter=0x");
11660 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11661 pw.print(", mNextAppTransitionExit=0x");
11662 pw.print(Integer.toHexString(mNextAppTransitionExit));
11663 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011664 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11665 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11666 if (mOpeningApps.size() > 0) {
11667 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11668 }
11669 if (mClosingApps.size() > 0) {
11670 pw.print(" mClosingApps="); pw.println(mClosingApps);
11671 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011672 if (mToTopApps.size() > 0) {
11673 pw.print(" mToTopApps="); pw.println(mToTopApps);
11674 }
11675 if (mToBottomApps.size() > 0) {
11676 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11677 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011678 if (mDisplay != null) {
11679 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11680 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11681 } else {
11682 pw.println(" NO DISPLAY");
11683 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011684 pw.println(" Policy:");
11685 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011686 }
11687 }
11688
Jeff Brown349703e2010-06-22 01:27:15 -070011689 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011690 public void monitor() {
11691 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011692 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011694
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011695 /**
11696 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011697 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011698 */
11699 private static class DimAnimator {
11700 Surface mDimSurface;
11701 boolean mDimShown = false;
11702 float mDimCurrentAlpha;
11703 float mDimTargetAlpha;
11704 float mDimDeltaPerMs;
11705 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011706
11707 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011708
11709 DimAnimator (SurfaceSession session) {
11710 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011711 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011712 + mDimSurface + ": CREATE");
11713 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011714 mDimSurface = new Surface(session, 0,
11715 "DimSurface",
11716 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011717 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011718 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011719 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011720 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011721 }
11722 }
11723 }
11724
11725 /**
11726 * Show the dim surface.
11727 */
11728 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011729 if (!mDimShown) {
11730 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11731 dw + "x" + dh + ")");
11732 mDimShown = true;
11733 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011734 mLastDimWidth = dw;
11735 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011736 mDimSurface.setPosition(0, 0);
11737 mDimSurface.setSize(dw, dh);
11738 mDimSurface.show();
11739 } catch (RuntimeException e) {
11740 Slog.w(TAG, "Failure showing dim surface", e);
11741 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011742 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11743 mLastDimWidth = dw;
11744 mLastDimHeight = dh;
11745 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011746 }
11747 }
11748
11749 /**
11750 * Set's the dim surface's layer and update dim parameters that will be used in
11751 * {@link updateSurface} after all windows are examined.
11752 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011753 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011754 mDimSurface.setLayer(w.mAnimLayer-1);
11755
11756 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011757 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011758 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011759 if (mDimTargetAlpha != target) {
11760 // If the desired dim level has changed, then
11761 // start an animation to it.
11762 mLastDimAnimTime = currentTime;
11763 long duration = (w.mAnimating && w.mAnimation != null)
11764 ? w.mAnimation.computeDurationHint()
11765 : DEFAULT_DIM_DURATION;
11766 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011767 TypedValue tv = new TypedValue();
11768 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11769 tv, true);
11770 if (tv.type == TypedValue.TYPE_FRACTION) {
11771 duration = (long)tv.getFraction((float)duration, (float)duration);
11772 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11773 && tv.type <= TypedValue.TYPE_LAST_INT) {
11774 duration = tv.data;
11775 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011776 }
11777 if (duration < 1) {
11778 // Don't divide by zero
11779 duration = 1;
11780 }
11781 mDimTargetAlpha = target;
11782 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11783 }
11784 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011785
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011786 /**
11787 * Updating the surface's alpha. Returns true if the animation continues, or returns
11788 * false when the animation is finished and the dim surface is hidden.
11789 */
11790 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11791 if (!dimming) {
11792 if (mDimTargetAlpha != 0) {
11793 mLastDimAnimTime = currentTime;
11794 mDimTargetAlpha = 0;
11795 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11796 }
11797 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011798
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011799 boolean animating = false;
11800 if (mLastDimAnimTime != 0) {
11801 mDimCurrentAlpha += mDimDeltaPerMs
11802 * (currentTime-mLastDimAnimTime);
11803 boolean more = true;
11804 if (displayFrozen) {
11805 // If the display is frozen, there is no reason to animate.
11806 more = false;
11807 } else if (mDimDeltaPerMs > 0) {
11808 if (mDimCurrentAlpha > mDimTargetAlpha) {
11809 more = false;
11810 }
11811 } else if (mDimDeltaPerMs < 0) {
11812 if (mDimCurrentAlpha < mDimTargetAlpha) {
11813 more = false;
11814 }
11815 } else {
11816 more = false;
11817 }
11818
11819 // Do we need to continue animating?
11820 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011821 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011822 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11823 mLastDimAnimTime = currentTime;
11824 mDimSurface.setAlpha(mDimCurrentAlpha);
11825 animating = true;
11826 } else {
11827 mDimCurrentAlpha = mDimTargetAlpha;
11828 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011829 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011830 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11831 mDimSurface.setAlpha(mDimCurrentAlpha);
11832 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011833 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011834 + ": HIDE");
11835 try {
11836 mDimSurface.hide();
11837 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011838 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011839 }
11840 mDimShown = false;
11841 }
11842 }
11843 }
11844 return animating;
11845 }
11846
11847 public void printTo(PrintWriter pw) {
11848 pw.print(" mDimShown="); pw.print(mDimShown);
11849 pw.print(" current="); pw.print(mDimCurrentAlpha);
11850 pw.print(" target="); pw.print(mDimTargetAlpha);
11851 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11852 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11853 }
11854 }
11855
11856 /**
11857 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11858 * This is used for opening/closing transition for apps in compatible mode.
11859 */
11860 private static class FadeInOutAnimation extends Animation {
11861 int mWidth;
11862 boolean mFadeIn;
11863
11864 public FadeInOutAnimation(boolean fadeIn) {
11865 setInterpolator(new AccelerateInterpolator());
11866 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11867 mFadeIn = fadeIn;
11868 }
11869
11870 @Override
11871 protected void applyTransformation(float interpolatedTime, Transformation t) {
11872 float x = interpolatedTime;
11873 if (!mFadeIn) {
11874 x = 1.0f - x; // reverse the interpolation for fade out
11875 }
11876 if (x < 0.5) {
11877 // move the window out of the screen.
11878 t.getMatrix().setTranslate(mWidth, 0);
11879 } else {
11880 t.getMatrix().setTranslate(0, 0);// show
11881 t.setAlpha((x - 0.5f) * 2);
11882 }
11883 }
11884
11885 @Override
11886 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11887 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11888 mWidth = width;
11889 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011890
11891 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011892 public int getZAdjustment() {
11893 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011894 }
11895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011896}