blob: 52d204058655afa9de868e871e27bd680cbe5e66 [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>();
Romain Guy06882f82009-06-10 13:36:04 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mLayoutNeeded = true;
401 boolean mAnimationPending = false;
402 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800403 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 boolean mWindowsFreezingScreen = false;
405 long mFreezeGcPending = 0;
406 int mAppsFreezingScreen = 0;
407
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800408 int mLayoutSeq = 0;
409
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800410 // State while inside of layoutAndPlaceSurfacesLocked().
411 boolean mFocusMayChange;
412
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800413 Configuration mCurConfiguration = new Configuration();
414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 // This is held as long as we have the screen frozen, to give us time to
416 // perform a rotation animation when turning off shows the lock screen which
417 // changes the orientation.
418 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 // State management of app transitions. When we are preparing for a
421 // transition, mNextAppTransition will be the kind of transition to
422 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
423 // mOpeningApps and mClosingApps are the lists of tokens that will be
424 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700425 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700426 String mNextAppTransitionPackage;
427 int mNextAppTransitionEnter;
428 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700430 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionTimeout = false;
432 boolean mStartingIconInTransition = false;
433 boolean mSkipAppTransitionAnimation = false;
434 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700436 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 H mH = new H();
442
443 WindowState mCurrentFocus = null;
444 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 // This just indicates the window the input method is on top of, not
447 // necessarily the window its input is going to.
448 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 boolean mInputMethodTargetWaitingAnim;
450 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 WindowState mInputMethodWindow = null;
453 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
454
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700455 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800456
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 // If non-null, this is the currently visible window that is associated
458 // with the wallpaper.
459 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the lower one in Z-order.
462 WindowState mLowerWallpaperTarget = null;
463 // If non-null, we are in the middle of animating from one wallpaper target
464 // to another, and this is the higher one in Z-order.
465 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800466 // Window currently running an animation that has requested it be detached
467 // from the wallpaper. This means we need to ensure the wallpaper is
468 // visible behind it in case it animates in a way that would allow it to be
469 // seen.
470 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700471 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700472 float mLastWallpaperX = -1;
473 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800474 float mLastWallpaperXStep = -1;
475 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700476 // This is set when we are waiting for a wallpaper to tell us it is done
477 // changing its scroll position.
478 WindowState mWaitingOnWallpaper;
479 // The last time we had a timeout when waiting for a wallpaper.
480 long mLastWallpaperTimeoutTime;
481 // We give a wallpaper up to 150ms to finish scrolling.
482 static final long WALLPAPER_TIMEOUT = 150;
483 // Time we wait after a timeout before trying to wait again.
484 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 AppWindowToken mFocusedApp = null;
487
488 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 float mWindowAnimationScale = 1.0f;
491 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Jeff Brown46b9ac02010-04-22 18:58:52 -0700493 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494
495 // Who is holding the screen on.
496 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700497 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700498
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700499 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700502 * Drag/drop state
503 */
504 class DragState {
505 IBinder mToken;
506 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800507 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700508 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 ClipData mData;
510 ClipDescription mDataDescription;
Chris Tated4533f12010-10-19 15:15:08 -0700511 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700512 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700513 float mThumbOffsetX, mThumbOffsetY;
514 InputChannel mServerChannel, mClientChannel;
515 WindowState mTargetWindow;
516 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700517 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700518
Christopher Tateccd24de2011-01-12 15:02:55 -0800519 boolean mPerformDeferredRotation;
520 int mRotation;
521 int mAnimFlags;
522
Jeff Brownfbf09772011-01-16 14:06:57 -0800523 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700524
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800525 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700526 mToken = token;
527 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800528 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700529 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700530 mNotifiedWindows = new ArrayList<WindowState>();
531 }
532
533 void reset() {
534 if (mSurface != null) {
535 mSurface.destroy();
536 }
537 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800538 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700539 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700540 mToken = null;
541 mData = null;
542 mThumbOffsetX = mThumbOffsetY = 0;
543 mNotifiedWindows = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800544 mPerformDeferredRotation = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700545 }
546
547 void register() {
548 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
549 if (mClientChannel != null) {
550 Slog.e(TAG, "Duplicate register of drag input channel");
551 } else {
552 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
553 mServerChannel = channels[0];
554 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800555 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700556 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
557 mH.getLooper().getQueue());
558 }
559 }
560
561 void unregister() {
562 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
563 if (mClientChannel == null) {
564 Slog.e(TAG, "Unregister of nonexistent drag input channel");
565 } else {
566 mInputManager.unregisterInputChannel(mServerChannel);
567 InputQueue.unregisterInputChannel(mClientChannel);
568 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700569 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700570 mClientChannel = null;
571 mServerChannel = null;
572 }
573 }
574
Chris Tatea32dcf72010-10-14 12:13:50 -0700575 int getDragLayerLw() {
576 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
577 * TYPE_LAYER_MULTIPLIER
578 + TYPE_LAYER_OFFSET;
579 }
580
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 /* call out to each visible window/session informing it about the drag
582 */
Chris Tateb8203e92010-10-12 14:23:21 -0700583 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 // Cache a base-class instance of the clip metadata so that parceling
585 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800586 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700587 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700588 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700589
590 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700591 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700592 }
593
Christopher Tate2c095f32010-10-04 14:13:40 -0700594 final int N = mWindows.size();
595 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700596 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700597 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700598 }
599
600 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
601 * designated window is potentially a drop recipient. There are race situations
602 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
603 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700604 *
605 * This method clones the 'event' parameter if it's being delivered to the same
606 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700607 */
Chris Tateb478f462010-10-15 16:02:26 -0700608 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
609 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700610 // Don't actually send the event if the drag is supposed to be pinned
611 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800612 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700613 final IBinder winBinder = newWin.mClient.asBinder();
614 if (winBinder != mLocalWin) {
615 if (DEBUG_DRAG) {
616 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
617 }
618 return;
619 }
620 }
621
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700622 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700623 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
624 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800625 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700626 try {
627 newWin.mClient.dispatchDragEvent(event);
628 // track each window that we've notified that the drag is starting
629 mNotifiedWindows.add(newWin);
630 } catch (RemoteException e) {
631 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700632 } finally {
633 // if the callee was local, the dispatch has already recycled the event
634 if (Process.myPid() != newWin.mSession.mPid) {
635 event.recycle();
636 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700637 }
638 }
639 }
640
641 /* helper - construct and send a DRAG_STARTED event only if the window has not
642 * previously been notified, i.e. it became visible after the drag operation
643 * was begun. This is a rare case.
644 */
645 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700646 if (mDragInProgress) {
647 // If we have sent the drag-started, we needn't do so again
648 for (WindowState ws : mNotifiedWindows) {
649 if (ws == newWin) {
650 return;
651 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700652 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700653 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700654 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700655 }
Chris Tateb478f462010-10-15 16:02:26 -0700656 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700657 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 }
659
Chris Tated4533f12010-10-19 15:15:08 -0700660 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700661 if (DEBUG_DRAG) {
662 Slog.d(TAG, "broadcasting DRAG_ENDED");
663 }
Chris Tated4533f12010-10-19 15:15:08 -0700664 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800665 0, 0, null, null, null, mDragResult);
Chris Tated4533f12010-10-19 15:15:08 -0700666 for (WindowState ws: mNotifiedWindows) {
667 try {
668 ws.mClient.dispatchDragEvent(evt);
669 } catch (RemoteException e) {
670 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700671 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 }
Chris Tated4533f12010-10-19 15:15:08 -0700673 mNotifiedWindows.clear();
674 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700675 evt.recycle();
676 }
677
Chris Tated4533f12010-10-19 15:15:08 -0700678 void endDragLw() {
679 mDragState.broadcastDragEndedLw();
680
681 // stop intercepting input
682 mDragState.unregister();
Jeff Brown3a22cd92011-01-21 13:59:04 -0800683 mInputMonitor.setUpdateInputWindowsNeededLw();
Chris Tated4533f12010-10-19 15:15:08 -0700684 mInputMonitor.updateInputWindowsLw();
685
Christopher Tateccd24de2011-01-12 15:02:55 -0800686 // Retain the parameters of any deferred rotation operation so
687 // that we can perform it after the reset / unref of the drag state
688 final boolean performRotation = mPerformDeferredRotation;
689 final int rotation = mRotation;
690 final int animFlags = mAnimFlags;
691
Chris Tated4533f12010-10-19 15:15:08 -0700692 // free our resources and drop all the object references
693 mDragState.reset();
694 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800695
696 // Now that we've officially ended the drag, execute any
697 // deferred rotation
698 if (performRotation) {
699 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800700 boolean changed = setRotationUncheckedLocked(rotation, animFlags, false);
Christopher Tateccd24de2011-01-12 15:02:55 -0800701 if (changed) {
702 sendNewConfiguration();
703 }
704 }
Chris Tated4533f12010-10-19 15:15:08 -0700705 }
706
Christopher Tatea53146c2010-09-07 11:57:52 -0700707 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700708 final int myPid = Process.myPid();
709
710 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800711 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800712 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800713 try {
714 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
715 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800716 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800717 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
718 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700719
720 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700721 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800722 if (touchedWin == null) {
723 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
724 return;
725 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800726 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700727 final IBinder touchedBinder = touchedWin.mClient.asBinder();
728 if (touchedBinder != mLocalWin) {
729 // This drag is pinned only to the originating window, but the drag
730 // point is outside that window. Pretend it's over empty space.
731 touchedWin = null;
732 }
733 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700734 try {
735 // have we dragged over a new window?
736 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
737 if (DEBUG_DRAG) {
738 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
739 }
740 // force DRAG_EXITED_EVENT if appropriate
741 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700742 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800743 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700744 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700745 if (myPid != mTargetWindow.mSession.mPid) {
746 evt.recycle();
747 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700748 }
749 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700750 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700751 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
752 }
753 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700754 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800755 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700756 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700757 if (myPid != touchedWin.mSession.mPid) {
758 evt.recycle();
759 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700760 }
761 } catch (RemoteException e) {
762 Slog.w(TAG, "can't send drag notification to windows");
763 }
764 mTargetWindow = touchedWin;
765 }
766
Chris Tated4533f12010-10-19 15:15:08 -0700767 // Tell the drop target about the data. Returns 'true' if we can immediately
768 // dispatch the global drag-ended message, 'false' if we need to wait for a
769 // result from the recipient.
770 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700771 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f12010-10-19 15:15:08 -0700772 if (touchedWin == null) {
773 // "drop" outside a valid window -- no recipient to apply a
774 // timeout to, and we can send the drag-ended message immediately.
775 mDragResult = false;
776 return true;
777 }
778
779 if (DEBUG_DRAG) {
780 Slog.d(TAG, "sending DROP to " + touchedWin);
781 }
782 final int myPid = Process.myPid();
783 final IBinder token = touchedWin.mClient.asBinder();
784 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
785 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800786 null, null, mData, false);
Chris Tated4533f12010-10-19 15:15:08 -0700787 try {
788 touchedWin.mClient.dispatchDragEvent(evt);
789
790 // 5 second timeout for this window to respond to the drop
791 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
792 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
793 mH.sendMessageDelayed(msg, 5000);
794 } catch (RemoteException e) {
795 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
796 return true;
797 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700798 if (myPid != touchedWin.mSession.mPid) {
799 evt.recycle();
800 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700801 }
Chris Tated4533f12010-10-19 15:15:08 -0700802 mToken = token;
803 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700804 }
805
806 // Find the visible, touch-deliverable window under the given point
807 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
808 WindowState touchedWin = null;
809 final int x = (int) xf;
810 final int y = (int) yf;
811 final ArrayList<WindowState> windows = mWindows;
812 final int N = windows.size();
813 for (int i = N - 1; i >= 0; i--) {
814 WindowState child = windows.get(i);
815 final int flags = child.mAttrs.flags;
816 if (!child.isVisibleLw()) {
817 // not visible == don't tell about drags
818 continue;
819 }
820 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
821 // not touchable == don't tell about drags
822 continue;
823 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800824
825 child.getTouchableRegion(mTmpRegion);
826
Christopher Tatea53146c2010-09-07 11:57:52 -0700827 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800828 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
829 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
830 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700831 // Found it
832 touchedWin = child;
833 break;
834 }
835 }
836
837 return touchedWin;
838 }
Christopher Tateccd24de2011-01-12 15:02:55 -0800839
840 void setDeferredRotation(int rotation, int animFlags) {
841 mRotation = rotation;
842 mAnimFlags = animFlags;
843 mPerformDeferredRotation = true;
844 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700845 }
846
847 DragState mDragState = null;
848 private final InputHandler mDragInputHandler = new BaseInputHandler() {
849 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700850 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
851 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700852 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700853 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
854 && mDragState != null) {
855 boolean endDrag = false;
856 final float newX = event.getRawX();
857 final float newY = event.getRawY();
858
Christopher Tatea53146c2010-09-07 11:57:52 -0700859 switch (event.getAction()) {
860 case MotionEvent.ACTION_DOWN: {
861 if (DEBUG_DRAG) {
862 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
863 }
864 } break;
865
866 case MotionEvent.ACTION_MOVE: {
867 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700868 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700869 mDragState.notifyMoveLw(newX, newY);
870 }
871 } break;
872
873 case MotionEvent.ACTION_UP: {
874 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
875 + newX + "," + newY);
876 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700877 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700878 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700879 } break;
880
881 case MotionEvent.ACTION_CANCEL: {
882 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
883 endDrag = true;
884 } break;
885 }
886
887 if (endDrag) {
888 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
889 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700890 synchronized (mWindowMap) {
Chris Tated4533f12010-10-19 15:15:08 -0700891 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700892 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700893 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700894
895 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700896 }
897 } catch (Exception e) {
898 Slog.e(TAG, "Exception caught by drag handleMotion", e);
899 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700900 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700901 }
902 }
903 };
904
905 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 * Whether the UI is currently running in touch mode (not showing
907 * navigational focus because the user is directly pressing the screen).
908 */
909 boolean mInTouchMode = false;
910
911 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700912 private ArrayList<WindowChangeListener> mWindowChangeListeners =
913 new ArrayList<WindowChangeListener>();
914 private boolean mWindowsChanged = false;
915
916 public interface WindowChangeListener {
917 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700918 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920
Dianne Hackbornc485a602009-03-24 22:39:49 -0700921 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700922 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700923
924 // The frame use to limit the size of the app running in compatibility mode.
925 Rect mCompatibleScreenFrame = new Rect();
926 // The surface used to fill the outer rim of the app running in compatibility mode.
927 Surface mBackgroundFillerSurface = null;
928 boolean mBackgroundFillerShown = false;
929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 public static WindowManagerService main(Context context,
931 PowerManagerService pm, boolean haveInputMethods) {
932 WMThread thr = new WMThread(context, pm, haveInputMethods);
933 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 synchronized (thr) {
936 while (thr.mService == null) {
937 try {
938 thr.wait();
939 } catch (InterruptedException e) {
940 }
941 }
942 }
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 return thr.mService;
945 }
Romain Guy06882f82009-06-10 13:36:04 -0700946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 static class WMThread extends Thread {
948 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 private final Context mContext;
951 private final PowerManagerService mPM;
952 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 public WMThread(Context context, PowerManagerService pm,
955 boolean haveInputMethods) {
956 super("WindowManager");
957 mContext = context;
958 mPM = pm;
959 mHaveInputMethods = haveInputMethods;
960 }
Romain Guy06882f82009-06-10 13:36:04 -0700961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 public void run() {
963 Looper.prepare();
964 WindowManagerService s = new WindowManagerService(mContext, mPM,
965 mHaveInputMethods);
966 android.os.Process.setThreadPriority(
967 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700968 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 synchronized (this) {
971 mService = s;
972 notifyAll();
973 }
Romain Guy06882f82009-06-10 13:36:04 -0700974
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700975 // For debug builds, log event loop stalls to dropbox for analysis.
976 if (StrictMode.conditionallyEnableDebugLogging()) {
977 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
978 }
979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 Looper.loop();
981 }
982 }
983
984 static class PolicyThread extends Thread {
985 private final WindowManagerPolicy mPolicy;
986 private final WindowManagerService mService;
987 private final Context mContext;
988 private final PowerManagerService mPM;
989 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 public PolicyThread(WindowManagerPolicy policy,
992 WindowManagerService service, Context context,
993 PowerManagerService pm) {
994 super("WindowManagerPolicy");
995 mPolicy = policy;
996 mService = service;
997 mContext = context;
998 mPM = pm;
999 }
Romain Guy06882f82009-06-10 13:36:04 -07001000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 public void run() {
1002 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -08001003 WindowManagerPolicyThread.set(this, Looper.myLooper());
1004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -08001006 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 android.os.Process.setThreadPriority(
1008 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -07001009 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -07001011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 synchronized (this) {
1013 mRunning = true;
1014 notifyAll();
1015 }
Romain Guy06882f82009-06-10 13:36:04 -07001016
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001017 // For debug builds, log event loop stalls to dropbox for analysis.
1018 if (StrictMode.conditionallyEnableDebugLogging()) {
1019 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1020 }
1021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 Looper.loop();
1023 }
1024 }
1025
1026 private WindowManagerService(Context context, PowerManagerService pm,
1027 boolean haveInputMethods) {
1028 mContext = context;
1029 mHaveInputMethods = haveInputMethods;
1030 mLimitedAlphaCompositing = context.getResources().getBoolean(
1031 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 mPowerManager = pm;
1034 mPowerManager.setPolicy(mPolicy);
1035 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1036 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1037 "SCREEN_FROZEN");
1038 mScreenFrozenLock.setReferenceCounted(false);
1039
1040 mActivityManager = ActivityManagerNative.getDefault();
1041 mBatteryStats = BatteryStatsService.getService();
1042
1043 // Get persisted window scale setting
1044 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1045 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1046 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1047 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001048
Jim Miller284b62e2010-06-08 14:27:42 -07001049 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1050 IntentFilter filter = new IntentFilter();
1051 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1052 mContext.registerReceiver(mBroadcastReceiver, filter);
1053
Jeff Brown46b9ac02010-04-22 18:58:52 -07001054 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1055 "KEEP_SCREEN_ON_FLAG");
1056 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057
Jeff Browne33348b2010-07-15 23:54:05 -07001058 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1061 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 synchronized (thr) {
1064 while (!thr.mRunning) {
1065 try {
1066 thr.wait();
1067 } catch (InterruptedException e) {
1068 }
1069 }
1070 }
Romain Guy06882f82009-06-10 13:36:04 -07001071
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001072 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 // Add ourself to the Watchdog monitors.
1075 Watchdog.getInstance().addMonitor(this);
1076 }
1077
1078 @Override
1079 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1080 throws RemoteException {
1081 try {
1082 return super.onTransact(code, data, reply, flags);
1083 } catch (RuntimeException e) {
1084 // The window manager only throws security exceptions, so let's
1085 // log all others.
1086 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001087 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 }
1089 throw e;
1090 }
1091 }
1092
Jeff Browne33348b2010-07-15 23:54:05 -07001093 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001095 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 TAG, "Adding window " + window + " at "
1097 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1098 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001099 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 }
1101
Jeff Browne33348b2010-07-15 23:54:05 -07001102 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001104 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 TAG, "Adding window " + window + " at "
1106 + i + " of " + mWindows.size() + " (before " + pos + ")");
1107 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001108 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 }
1110
1111 //This method finds out the index of a window that has the same app token as
1112 //win. used for z ordering the windows in mWindows
1113 private int findIdxBasedOnAppTokens(WindowState win) {
1114 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001115 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 int jmax = localmWindows.size();
1117 if(jmax == 0) {
1118 return -1;
1119 }
1120 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001121 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 if(wentry.mAppToken == win.mAppToken) {
1123 return j;
1124 }
1125 }
1126 return -1;
1127 }
Romain Guy06882f82009-06-10 13:36:04 -07001128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1130 final IWindow client = win.mClient;
1131 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001132 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 final int N = localmWindows.size();
1135 final WindowState attached = win.mAttachedWindow;
1136 int i;
1137 if (attached == null) {
1138 int tokenWindowsPos = token.windows.size();
1139 if (token.appWindowToken != null) {
1140 int index = tokenWindowsPos-1;
1141 if (index >= 0) {
1142 // If this application has existing windows, we
1143 // simply place the new window on top of them... but
1144 // keep the starting window on top.
1145 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1146 // Base windows go behind everything else.
1147 placeWindowBefore(token.windows.get(0), win);
1148 tokenWindowsPos = 0;
1149 } else {
1150 AppWindowToken atoken = win.mAppToken;
1151 if (atoken != null &&
1152 token.windows.get(index) == atoken.startingWindow) {
1153 placeWindowBefore(token.windows.get(index), win);
1154 tokenWindowsPos--;
1155 } else {
1156 int newIdx = findIdxBasedOnAppTokens(win);
1157 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001158 //there is a window above this one associated with the same
1159 //apptoken note that the window could be a floating window
1160 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001162 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1163 Slog.v(TAG, "Adding window " + win + " at "
1164 + (newIdx+1) + " of " + N);
1165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001167 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001169 }
1170 }
1171 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001172 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 TAG, "Figuring out where to add app window "
1174 + client.asBinder() + " (token=" + token + ")");
1175 // Figure out where the window should go, based on the
1176 // order of applications.
1177 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001178 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 for (i=NA-1; i>=0; i--) {
1180 AppWindowToken t = mAppTokens.get(i);
1181 if (t == token) {
1182 i--;
1183 break;
1184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001185
Dianne Hackborna8f60182009-09-01 19:01:50 -07001186 // We haven't reached the token yet; if this token
1187 // is not going to the bottom and has windows, we can
1188 // use it as an anchor for when we do reach the token.
1189 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 pos = t.windows.get(0);
1191 }
1192 }
1193 // We now know the index into the apps. If we found
1194 // an app window above, that gives us the position; else
1195 // we need to look some more.
1196 if (pos != null) {
1197 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001198 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 if (atoken != null) {
1200 final int NC = atoken.windows.size();
1201 if (NC > 0) {
1202 WindowState bottom = atoken.windows.get(0);
1203 if (bottom.mSubLayer < 0) {
1204 pos = bottom;
1205 }
1206 }
1207 }
1208 placeWindowBefore(pos, win);
1209 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001210 // Continue looking down until we find the first
1211 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 while (i >= 0) {
1213 AppWindowToken t = mAppTokens.get(i);
1214 final int NW = t.windows.size();
1215 if (NW > 0) {
1216 pos = t.windows.get(NW-1);
1217 break;
1218 }
1219 i--;
1220 }
1221 if (pos != null) {
1222 // Move in front of any windows attached to this
1223 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001224 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 if (atoken != null) {
1226 final int NC = atoken.windows.size();
1227 if (NC > 0) {
1228 WindowState top = atoken.windows.get(NC-1);
1229 if (top.mSubLayer >= 0) {
1230 pos = top;
1231 }
1232 }
1233 }
1234 placeWindowAfter(pos, win);
1235 } else {
1236 // Just search for the start of this layer.
1237 final int myLayer = win.mBaseLayer;
1238 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001239 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 if (w.mBaseLayer > myLayer) {
1241 break;
1242 }
1243 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001244 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1245 Slog.v(TAG, "Adding window " + win + " at "
1246 + i + " of " + N);
1247 }
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 }
1252 }
1253 } else {
1254 // Figure out where window should go, based on layer.
1255 final int myLayer = win.mBaseLayer;
1256 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001257 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 i++;
1259 break;
1260 }
1261 }
1262 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001263 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001264 TAG, "Adding window " + win + " at "
1265 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001267 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 }
1269 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001270 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 token.windows.add(tokenWindowsPos, win);
1272 }
1273
1274 } else {
1275 // Figure out this window's ordering relative to the window
1276 // it is attached to.
1277 final int NA = token.windows.size();
1278 final int sublayer = win.mSubLayer;
1279 int largestSublayer = Integer.MIN_VALUE;
1280 WindowState windowWithLargestSublayer = null;
1281 for (i=0; i<NA; i++) {
1282 WindowState w = token.windows.get(i);
1283 final int wSublayer = w.mSubLayer;
1284 if (wSublayer >= largestSublayer) {
1285 largestSublayer = wSublayer;
1286 windowWithLargestSublayer = w;
1287 }
1288 if (sublayer < 0) {
1289 // For negative sublayers, we go below all windows
1290 // in the same sublayer.
1291 if (wSublayer >= sublayer) {
1292 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001293 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 token.windows.add(i, win);
1295 }
1296 placeWindowBefore(
1297 wSublayer >= 0 ? attached : w, win);
1298 break;
1299 }
1300 } else {
1301 // For positive sublayers, we go above all windows
1302 // in the same sublayer.
1303 if (wSublayer > sublayer) {
1304 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001305 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 token.windows.add(i, win);
1307 }
1308 placeWindowBefore(w, win);
1309 break;
1310 }
1311 }
1312 }
1313 if (i >= NA) {
1314 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001315 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 token.windows.add(win);
1317 }
1318 if (sublayer < 0) {
1319 placeWindowBefore(attached, win);
1320 } else {
1321 placeWindowAfter(largestSublayer >= 0
1322 ? windowWithLargestSublayer
1323 : attached,
1324 win);
1325 }
1326 }
1327 }
Romain Guy06882f82009-06-10 13:36:04 -07001328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 if (win.mAppToken != null && addToToken) {
1330 win.mAppToken.allAppWindows.add(win);
1331 }
1332 }
Romain Guy06882f82009-06-10 13:36:04 -07001333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 static boolean canBeImeTarget(WindowState w) {
1335 final int fl = w.mAttrs.flags
1336 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1337 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1338 return w.isVisibleOrAdding();
1339 }
1340 return false;
1341 }
Romain Guy06882f82009-06-10 13:36:04 -07001342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001344 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 final int N = localmWindows.size();
1346 WindowState w = null;
1347 int i = N;
1348 while (i > 0) {
1349 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001350 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001351
Joe Onorato8a9b2202010-02-26 18:56:32 -08001352 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 // + Integer.toHexString(w.mAttrs.flags));
1354 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001355 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 // Yet more tricksyness! If this window is a "starting"
1358 // window, we do actually want to be on top of it, but
1359 // it is not -really- where input will go. So if the caller
1360 // is not actually looking to move the IME, look down below
1361 // for a real window to target...
1362 if (!willMove
1363 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1364 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001365 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1367 i--;
1368 w = wb;
1369 }
1370 }
1371 break;
1372 }
1373 }
Romain Guy06882f82009-06-10 13:36:04 -07001374
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001375 // Now, a special case -- if the last target's window is in the
1376 // process of exiting, and is above the new target, keep on the
1377 // last target to avoid flicker. Consider for example a Dialog with
1378 // the IME shown: when the Dialog is dismissed, we want to keep
1379 // the IME above it until it is completely gone so it doesn't drop
1380 // behind the dialog or its full-screen scrim.
1381 if (mInputMethodTarget != null && w != null
1382 && mInputMethodTarget.isDisplayedLw()
1383 && mInputMethodTarget.mExiting) {
1384 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1385 w = mInputMethodTarget;
1386 i = localmWindows.indexOf(w);
1387 }
1388 }
Romain Guy06882f82009-06-10 13:36:04 -07001389
Joe Onorato8a9b2202010-02-26 18:56:32 -08001390 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 if (willMove && w != null) {
1394 final WindowState curTarget = mInputMethodTarget;
1395 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001397 // Now some fun for dealing with window animations that
1398 // modify the Z order. We need to look at all windows below
1399 // the current target that are in this app, finding the highest
1400 // visible one in layering.
1401 AppWindowToken token = curTarget.mAppToken;
1402 WindowState highestTarget = null;
1403 int highestPos = 0;
1404 if (token.animating || token.animation != null) {
1405 int pos = 0;
1406 pos = localmWindows.indexOf(curTarget);
1407 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001408 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 if (win.mAppToken != token) {
1410 break;
1411 }
1412 if (!win.mRemoved) {
1413 if (highestTarget == null || win.mAnimLayer >
1414 highestTarget.mAnimLayer) {
1415 highestTarget = win;
1416 highestPos = pos;
1417 }
1418 }
1419 pos--;
1420 }
1421 }
Romain Guy06882f82009-06-10 13:36:04 -07001422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001424 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 + mNextAppTransition + " " + highestTarget
1426 + " animating=" + highestTarget.isAnimating()
1427 + " layer=" + highestTarget.mAnimLayer
1428 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001429
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001430 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 // If we are currently setting up for an animation,
1432 // hold everything until we can find out what will happen.
1433 mInputMethodTargetWaitingAnim = true;
1434 mInputMethodTarget = highestTarget;
1435 return highestPos + 1;
1436 } else if (highestTarget.isAnimating() &&
1437 highestTarget.mAnimLayer > w.mAnimLayer) {
1438 // If the window we are currently targeting is involved
1439 // with an animation, and it is on top of the next target
1440 // we will be over, then hold off on moving until
1441 // that is done.
1442 mInputMethodTarget = highestTarget;
1443 return highestPos + 1;
1444 }
1445 }
1446 }
1447 }
Romain Guy06882f82009-06-10 13:36:04 -07001448
Joe Onorato8a9b2202010-02-26 18:56:32 -08001449 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 if (w != null) {
1451 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001452 if (DEBUG_INPUT_METHOD) {
1453 RuntimeException e = null;
1454 if (!HIDE_STACK_CRAWLS) {
1455 e = new RuntimeException();
1456 e.fillInStackTrace();
1457 }
1458 Slog.w(TAG, "Moving IM target from "
1459 + mInputMethodTarget + " to " + w, e);
1460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 mInputMethodTarget = w;
1462 if (w.mAppToken != null) {
1463 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1464 } else {
1465 setInputMethodAnimLayerAdjustment(0);
1466 }
1467 }
1468 return i+1;
1469 }
1470 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001471 if (DEBUG_INPUT_METHOD) {
1472 RuntimeException e = null;
1473 if (!HIDE_STACK_CRAWLS) {
1474 e = new RuntimeException();
1475 e.fillInStackTrace();
1476 }
1477 Slog.w(TAG, "Moving IM target from "
1478 + mInputMethodTarget + " to null", e);
1479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 mInputMethodTarget = null;
1481 setInputMethodAnimLayerAdjustment(0);
1482 }
1483 return -1;
1484 }
Romain Guy06882f82009-06-10 13:36:04 -07001485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 void addInputMethodWindowToListLocked(WindowState win) {
1487 int pos = findDesiredInputMethodWindowIndexLocked(true);
1488 if (pos >= 0) {
1489 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001490 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001491 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001493 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 moveInputMethodDialogsLocked(pos+1);
1495 return;
1496 }
1497 win.mTargetAppToken = null;
1498 addWindowToListInOrderLocked(win, true);
1499 moveInputMethodDialogsLocked(pos);
1500 }
Romain Guy06882f82009-06-10 13:36:04 -07001501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001503 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 mInputMethodAnimLayerAdjustment = adj;
1505 WindowState imw = mInputMethodWindow;
1506 if (imw != null) {
1507 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001508 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 + " anim layer: " + imw.mAnimLayer);
1510 int wi = imw.mChildWindows.size();
1511 while (wi > 0) {
1512 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001513 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001515 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 + " anim layer: " + cw.mAnimLayer);
1517 }
1518 }
1519 int di = mInputMethodDialogs.size();
1520 while (di > 0) {
1521 di --;
1522 imw = mInputMethodDialogs.get(di);
1523 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001524 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 + " anim layer: " + imw.mAnimLayer);
1526 }
1527 }
Romain Guy06882f82009-06-10 13:36:04 -07001528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1530 int wpos = mWindows.indexOf(win);
1531 if (wpos >= 0) {
1532 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001533 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001535 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 int NC = win.mChildWindows.size();
1537 while (NC > 0) {
1538 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001539 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 int cpos = mWindows.indexOf(cw);
1541 if (cpos >= 0) {
1542 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001544 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 mWindows.remove(cpos);
1546 }
1547 }
1548 }
1549 return interestingPos;
1550 }
Romain Guy06882f82009-06-10 13:36:04 -07001551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 private void reAddWindowToListInOrderLocked(WindowState win) {
1553 addWindowToListInOrderLocked(win, false);
1554 // This is a hack to get all of the child windows added as well
1555 // at the right position. Child windows should be rare and
1556 // this case should be rare, so it shouldn't be that big a deal.
1557 int wpos = mWindows.indexOf(win);
1558 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001559 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001560 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001562 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 reAddWindowLocked(wpos, win);
1564 }
1565 }
Romain Guy06882f82009-06-10 13:36:04 -07001566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 void logWindowList(String prefix) {
1568 int N = mWindows.size();
1569 while (N > 0) {
1570 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001571 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 }
1573 }
Romain Guy06882f82009-06-10 13:36:04 -07001574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 void moveInputMethodDialogsLocked(int pos) {
1576 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001579 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 for (int i=0; i<N; i++) {
1581 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1582 }
1583 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 logWindowList(" ");
1586 }
Romain Guy06882f82009-06-10 13:36:04 -07001587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 if (pos >= 0) {
1589 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1590 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001591 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 if (wp == mInputMethodWindow) {
1593 pos++;
1594 }
1595 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001596 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 for (int i=0; i<N; i++) {
1598 WindowState win = dialogs.get(i);
1599 win.mTargetAppToken = targetAppToken;
1600 pos = reAddWindowLocked(pos, win);
1601 }
1602 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001603 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 logWindowList(" ");
1605 }
1606 return;
1607 }
1608 for (int i=0; i<N; i++) {
1609 WindowState win = dialogs.get(i);
1610 win.mTargetAppToken = null;
1611 reAddWindowToListInOrderLocked(win);
1612 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 logWindowList(" ");
1615 }
1616 }
1617 }
Romain Guy06882f82009-06-10 13:36:04 -07001618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1620 final WindowState imWin = mInputMethodWindow;
1621 final int DN = mInputMethodDialogs.size();
1622 if (imWin == null && DN == 0) {
1623 return false;
1624 }
Romain Guy06882f82009-06-10 13:36:04 -07001625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1627 if (imPos >= 0) {
1628 // In this case, the input method windows are to be placed
1629 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001631 // First check to see if the input method windows are already
1632 // located here, and contiguous.
1633 final int N = mWindows.size();
1634 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001635 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 // Figure out the actual input method window that should be
1638 // at the bottom of their stack.
1639 WindowState baseImWin = imWin != null
1640 ? imWin : mInputMethodDialogs.get(0);
1641 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001642 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 if (cw.mSubLayer < 0) baseImWin = cw;
1644 }
Romain Guy06882f82009-06-10 13:36:04 -07001645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 if (firstImWin == baseImWin) {
1647 // The windows haven't moved... but are they still contiguous?
1648 // First find the top IM window.
1649 int pos = imPos+1;
1650 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001651 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 break;
1653 }
1654 pos++;
1655 }
1656 pos++;
1657 // Now there should be no more input method windows above.
1658 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001659 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 break;
1661 }
1662 pos++;
1663 }
1664 if (pos >= N) {
1665 // All is good!
1666 return false;
1667 }
1668 }
Romain Guy06882f82009-06-10 13:36:04 -07001669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 if (imWin != null) {
1671 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001672 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 logWindowList(" ");
1674 }
1675 imPos = tmpRemoveWindowLocked(imPos, imWin);
1676 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001677 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 logWindowList(" ");
1679 }
1680 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1681 reAddWindowLocked(imPos, imWin);
1682 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001683 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 logWindowList(" ");
1685 }
1686 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1687 } else {
1688 moveInputMethodDialogsLocked(imPos);
1689 }
Romain Guy06882f82009-06-10 13:36:04 -07001690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 } else {
1692 // In this case, the input method windows go in a fixed layer,
1693 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001696 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 tmpRemoveWindowLocked(0, imWin);
1698 imWin.mTargetAppToken = null;
1699 reAddWindowToListInOrderLocked(imWin);
1700 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001701 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702 logWindowList(" ");
1703 }
1704 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1705 } else {
1706 moveInputMethodDialogsLocked(-1);;
1707 }
Romain Guy06882f82009-06-10 13:36:04 -07001708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 }
Romain Guy06882f82009-06-10 13:36:04 -07001710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 if (needAssignLayers) {
1712 assignLayersLocked();
1713 }
Romain Guy06882f82009-06-10 13:36:04 -07001714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 return true;
1716 }
Romain Guy06882f82009-06-10 13:36:04 -07001717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 void adjustInputMethodDialogsLocked() {
1719 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1720 }
Romain Guy06882f82009-06-10 13:36:04 -07001721
Dianne Hackborn25994b42009-09-04 14:21:19 -07001722 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001723 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001724 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1725 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1726 ? wallpaperTarget.mAppToken.animation : null)
1727 + " upper=" + mUpperWallpaperTarget
1728 + " lower=" + mLowerWallpaperTarget);
1729 return (wallpaperTarget != null
1730 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1731 && wallpaperTarget.mAppToken.animation != null)))
1732 || mUpperWallpaperTarget != null
1733 || mLowerWallpaperTarget != null;
1734 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001735
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001736 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1737 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001738
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001739 int adjustWallpaperWindowsLocked() {
1740 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 final int dw = mDisplay.getWidth();
1743 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001745 // First find top-most window that has asked to be on top of the
1746 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001747 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001748 int N = localmWindows.size();
1749 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001750 WindowState foundW = null;
1751 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001752 WindowState topCurW = null;
1753 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001754 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001755 int i = N;
1756 while (i > 0) {
1757 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001758 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001759 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1760 if (topCurW == null) {
1761 topCurW = w;
1762 topCurI = i;
1763 }
1764 continue;
1765 }
1766 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001767 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001768 // If this window's app token is hidden and not animating,
1769 // it is of no interest to us.
1770 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001771 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001772 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001773 continue;
1774 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001775 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001776 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001777 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1778 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001779 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001780 && (mWallpaperTarget == w
1781 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001782 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001783 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001784 foundW = w;
1785 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001786 if (w == mWallpaperTarget && ((w.mAppToken != null
1787 && w.mAppToken.animation != null)
1788 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001789 // The current wallpaper target is animating, so we'll
1790 // look behind it for another possible target and figure
1791 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001792 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001793 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001794 continue;
1795 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001796 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001797 } else if (w == mWindowDetachedWallpaper) {
1798 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001799 }
1800 }
1801
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001802 if (foundW == null && windowDetachedI >= 0) {
1803 if (DEBUG_WALLPAPER) Slog.v(TAG,
1804 "Found animating detached wallpaper activity: #" + i + "=" + w);
1805 foundW = w;
1806 foundI = windowDetachedI;
1807 }
1808
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001809 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001810 // If we are currently waiting for an app transition, and either
1811 // the current target or the next target are involved with it,
1812 // then hold off on doing anything with the wallpaper.
1813 // Note that we are checking here for just whether the target
1814 // is part of an app token... which is potentially overly aggressive
1815 // (the app token may not be involved in the transition), but good
1816 // enough (we'll just wait until whatever transition is pending
1817 // executes).
1818 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001819 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001820 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001821 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001822 }
1823 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001824 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001825 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001826 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001827 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001829
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001830 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001831 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001833 + " oldTarget: " + mWallpaperTarget);
1834 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001835
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001836 mLowerWallpaperTarget = null;
1837 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001838
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001839 WindowState oldW = mWallpaperTarget;
1840 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001842 // Now what is happening... if the current and new targets are
1843 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001844 if (foundW != null && oldW != null) {
1845 boolean oldAnim = oldW.mAnimation != null
1846 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1847 boolean foundAnim = foundW.mAnimation != null
1848 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001849 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001850 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001851 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001852 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001853 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001854 int oldI = localmWindows.indexOf(oldW);
1855 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001856 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001857 }
1858 if (oldI >= 0) {
1859 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001861 + "=" + oldW + "; new#" + foundI
1862 + "=" + foundW);
1863 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001864
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001866 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001867 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001869 }
1870 mWallpaperTarget = oldW;
1871 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001872
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001873 // Now set the upper and lower wallpaper targets
1874 // correctly, and make sure that we are positioning
1875 // the wallpaper below the lower.
1876 if (foundI > oldI) {
1877 // The new target is on top of the old one.
1878 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001879 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001880 }
1881 mUpperWallpaperTarget = foundW;
1882 mLowerWallpaperTarget = oldW;
1883 foundW = oldW;
1884 foundI = oldI;
1885 } else {
1886 // The new target is below the old one.
1887 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001888 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001889 }
1890 mUpperWallpaperTarget = oldW;
1891 mLowerWallpaperTarget = foundW;
1892 }
1893 }
1894 }
1895 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001896
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001897 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001898 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001899 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1900 || (mLowerWallpaperTarget.mAppToken != null
1901 && mLowerWallpaperTarget.mAppToken.animation != null);
1902 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1903 || (mUpperWallpaperTarget.mAppToken != null
1904 && mUpperWallpaperTarget.mAppToken.animation != null);
1905 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001906 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001907 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001908 }
1909 mLowerWallpaperTarget = null;
1910 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001911 }
1912 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001913
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001914 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001915 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001916 // The window is visible to the compositor... but is it visible
1917 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001918 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001919 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001920
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001921 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001922 // its layer adjustment. Only do this if we are not transfering
1923 // between two wallpaper targets.
1924 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001925 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001926 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001927
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001928 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1929 * TYPE_LAYER_MULTIPLIER
1930 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001931
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001932 // Now w is the window we are supposed to be behind... but we
1933 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001934 // AND any starting window associated with it, AND below the
1935 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001936 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001937 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001938 if (wb.mBaseLayer < maxLayer &&
1939 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001940 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001941 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001942 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001943 // This window is not related to the previous one in any
1944 // interesting way, so stop here.
1945 break;
1946 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001947 foundW = wb;
1948 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001949 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001950 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001951 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001954 if (foundW == null && topCurW != null) {
1955 // There is no wallpaper target, so it goes at the bottom.
1956 // We will assume it is the same place as last time, if known.
1957 foundW = topCurW;
1958 foundI = topCurI+1;
1959 } else {
1960 // Okay i is the position immediately above the wallpaper. Look at
1961 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001962 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001963 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001964
Dianne Hackborn284ac932009-08-28 10:34:25 -07001965 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001966 if (mWallpaperTarget.mWallpaperX >= 0) {
1967 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001968 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001969 }
1970 if (mWallpaperTarget.mWallpaperY >= 0) {
1971 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001972 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001973 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001974 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001975
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001976 // Start stepping backwards from here, ensuring that our wallpaper windows
1977 // are correctly placed.
1978 int curTokenIndex = mWallpaperTokens.size();
1979 while (curTokenIndex > 0) {
1980 curTokenIndex--;
1981 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001982 if (token.hidden == visible) {
1983 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1984 token.hidden = !visible;
1985 // Need to do a layout to ensure the wallpaper now has the
1986 // correct size.
1987 mLayoutNeeded = true;
1988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001989
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001990 int curWallpaperIndex = token.windows.size();
1991 while (curWallpaperIndex > 0) {
1992 curWallpaperIndex--;
1993 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001994
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001995 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001996 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001998
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001999 // First, make sure the client has the current visibility
2000 // state.
2001 if (wallpaper.mWallpaperVisible != visible) {
2002 wallpaper.mWallpaperVisible = visible;
2003 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002004 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002005 "Setting visibility of wallpaper " + wallpaper
2006 + ": " + visible);
2007 wallpaper.mClient.dispatchAppVisibility(visible);
2008 } catch (RemoteException e) {
2009 }
2010 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002011
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002012 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002014 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002015
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002016 // First, if this window is at the current index, then all
2017 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002018 if (wallpaper == foundW) {
2019 foundI--;
2020 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002021 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002022 continue;
2023 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002024
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002025 // The window didn't match... the current wallpaper window,
2026 // wherever it is, is in the wrong place, so make sure it is
2027 // not in the list.
2028 int oldIndex = localmWindows.indexOf(wallpaper);
2029 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002030 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002031 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002032 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002033 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002034 if (oldIndex < foundI) {
2035 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002036 }
2037 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002038
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002039 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002040 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2041 Slog.v(TAG, "Moving wallpaper " + wallpaper
2042 + " from " + oldIndex + " to " + foundI);
2043 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002044
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002045 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002046 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002047 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002048 }
2049 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002050
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002051 return changed;
2052 }
2053
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002054 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002055 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002056 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002057 mWallpaperAnimLayerAdjustment = adj;
2058 int curTokenIndex = mWallpaperTokens.size();
2059 while (curTokenIndex > 0) {
2060 curTokenIndex--;
2061 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2062 int curWallpaperIndex = token.windows.size();
2063 while (curWallpaperIndex > 0) {
2064 curWallpaperIndex--;
2065 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2066 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002067 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002068 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002069 }
2070 }
2071 }
2072
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002073 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2074 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002075 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002076 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002077 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002078 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002079 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2080 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2081 changed = wallpaperWin.mXOffset != offset;
2082 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002083 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002084 + wallpaperWin + " x: " + offset);
2085 wallpaperWin.mXOffset = offset;
2086 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002087 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002089 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002090 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002092
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002093 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002094 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002095 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2096 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2097 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002098 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002099 + wallpaperWin + " y: " + offset);
2100 changed = true;
2101 wallpaperWin.mYOffset = offset;
2102 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002103 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002104 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002105 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002106 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002108
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002109 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002110 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002111 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002112 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2113 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002114 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002115 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002116 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002117 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002118 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2119 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002120 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002121 if (mWaitingOnWallpaper != null) {
2122 long start = SystemClock.uptimeMillis();
2123 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2124 < start) {
2125 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002126 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002127 "Waiting for offset complete...");
2128 mWindowMap.wait(WALLPAPER_TIMEOUT);
2129 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002130 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002131 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002132 if ((start+WALLPAPER_TIMEOUT)
2133 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002134 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002135 + wallpaperWin);
2136 mLastWallpaperTimeoutTime = start;
2137 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002138 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002139 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002140 }
2141 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002142 } catch (RemoteException e) {
2143 }
2144 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002145
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002146 return changed;
2147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002148
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002149 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002150 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002151 if (mWaitingOnWallpaper != null &&
2152 mWaitingOnWallpaper.mClient.asBinder() == window) {
2153 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002154 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002155 }
2156 }
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002159 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002160 final int dw = mDisplay.getWidth();
2161 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002162
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002163 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002164
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002165 WindowState target = mWallpaperTarget;
2166 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002167 if (target.mWallpaperX >= 0) {
2168 mLastWallpaperX = target.mWallpaperX;
2169 } else if (changingTarget.mWallpaperX >= 0) {
2170 mLastWallpaperX = changingTarget.mWallpaperX;
2171 }
2172 if (target.mWallpaperY >= 0) {
2173 mLastWallpaperY = target.mWallpaperY;
2174 } else if (changingTarget.mWallpaperY >= 0) {
2175 mLastWallpaperY = changingTarget.mWallpaperY;
2176 }
2177 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002178
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002179 int curTokenIndex = mWallpaperTokens.size();
2180 while (curTokenIndex > 0) {
2181 curTokenIndex--;
2182 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2183 int curWallpaperIndex = token.windows.size();
2184 while (curWallpaperIndex > 0) {
2185 curWallpaperIndex--;
2186 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2187 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2188 wallpaper.computeShownFrameLocked();
2189 changed = true;
2190 // We only want to be synchronous with one wallpaper.
2191 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002192 }
2193 }
2194 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002195
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002196 return changed;
2197 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002198
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002199 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002200 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002201 final int dw = mDisplay.getWidth();
2202 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002203
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002204 int curTokenIndex = mWallpaperTokens.size();
2205 while (curTokenIndex > 0) {
2206 curTokenIndex--;
2207 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002208 if (token.hidden == visible) {
2209 token.hidden = !visible;
2210 // Need to do a layout to ensure the wallpaper now has the
2211 // correct size.
2212 mLayoutNeeded = true;
2213 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002214
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002215 int curWallpaperIndex = token.windows.size();
2216 while (curWallpaperIndex > 0) {
2217 curWallpaperIndex--;
2218 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2219 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002220 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002222
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002223 if (wallpaper.mWallpaperVisible != visible) {
2224 wallpaper.mWallpaperVisible = visible;
2225 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002226 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002227 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002228 + ": " + visible);
2229 wallpaper.mClient.dispatchAppVisibility(visible);
2230 } catch (RemoteException e) {
2231 }
2232 }
2233 }
2234 }
2235 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 public int addWindow(Session session, IWindow client,
2238 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002239 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240 int res = mPolicy.checkAddPermission(attrs);
2241 if (res != WindowManagerImpl.ADD_OKAY) {
2242 return res;
2243 }
Romain Guy06882f82009-06-10 13:36:04 -07002244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 boolean reportNewConfig = false;
2246 WindowState attachedWindow = null;
2247 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002248 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002252 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 }
Romain Guy06882f82009-06-10 13:36:04 -07002254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002256 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2258 }
2259
2260 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002261 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002263 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 + attrs.token + ". Aborting.");
2265 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2266 }
2267 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2268 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002269 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 + attrs.token + ". Aborting.");
2271 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2272 }
2273 }
2274
2275 boolean addToken = false;
2276 WindowToken token = mTokenMap.get(attrs.token);
2277 if (token == null) {
2278 if (attrs.type >= FIRST_APPLICATION_WINDOW
2279 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002280 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 + attrs.token + ". Aborting.");
2282 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2283 }
2284 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 + attrs.token + ". Aborting.");
2287 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2288 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002289 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002290 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002291 + attrs.token + ". Aborting.");
2292 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 token = new WindowToken(attrs.token, -1, false);
2295 addToken = true;
2296 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2297 && attrs.type <= LAST_APPLICATION_WINDOW) {
2298 AppWindowToken atoken = token.appWindowToken;
2299 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002300 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 + token + ". Aborting.");
2302 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2303 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002304 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 + token + ". Aborting.");
2306 return WindowManagerImpl.ADD_APP_EXITING;
2307 }
2308 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2309 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002310 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2312 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2313 }
2314 } else if (attrs.type == TYPE_INPUT_METHOD) {
2315 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002316 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 + attrs.token + ". Aborting.");
2318 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2319 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002320 } else if (attrs.type == TYPE_WALLPAPER) {
2321 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002322 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002323 + attrs.token + ". Aborting.");
2324 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 }
2327
2328 win = new WindowState(session, client, token,
2329 attachedWindow, attrs, viewVisibility);
2330 if (win.mDeathRecipient == null) {
2331 // Client has apparently died, so there is no reason to
2332 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002333 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 + " that is dead, aborting.");
2335 return WindowManagerImpl.ADD_APP_EXITING;
2336 }
2337
2338 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 res = mPolicy.prepareAddWindowLw(win, attrs);
2341 if (res != WindowManagerImpl.ADD_OKAY) {
2342 return res;
2343 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002344
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002345 if (outInputChannel != null) {
2346 String name = win.makeInputChannelName();
2347 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2348 win.mInputChannel = inputChannels[0];
2349 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2350
Jeff Brown928e0542011-01-10 11:17:36 -08002351 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353
2354 // From now on, no exceptions or errors allowed!
2355
2356 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002357
Dianne Hackborn5132b372010-07-29 12:51:35 -07002358 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 if (addToken) {
2361 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 }
2363 win.attach();
2364 mWindowMap.put(client.asBinder(), win);
2365
2366 if (attrs.type == TYPE_APPLICATION_STARTING &&
2367 token.appWindowToken != null) {
2368 token.appWindowToken.startingWindow = win;
2369 }
2370
2371 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 if (attrs.type == TYPE_INPUT_METHOD) {
2374 mInputMethodWindow = win;
2375 addInputMethodWindowToListLocked(win);
2376 imMayMove = false;
2377 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2378 mInputMethodDialogs.add(win);
2379 addWindowToListInOrderLocked(win, true);
2380 adjustInputMethodDialogsLocked();
2381 imMayMove = false;
2382 } else {
2383 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002384 if (attrs.type == TYPE_WALLPAPER) {
2385 mLastWallpaperTimeoutTime = 0;
2386 adjustWallpaperWindowsLocked();
2387 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002388 adjustWallpaperWindowsLocked();
2389 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 }
Romain Guy06882f82009-06-10 13:36:04 -07002391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 if (mInTouchMode) {
2397 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2398 }
2399 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2400 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2401 }
Romain Guy06882f82009-06-10 13:36:04 -07002402
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002403 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002405 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2406 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002407 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 imMayMove = false;
2409 }
2410 }
Romain Guy06882f82009-06-10 13:36:04 -07002411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002413 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 }
Romain Guy06882f82009-06-10 13:36:04 -07002415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 assignLayersLocked();
2417 // Don't do layout here, the window must call
2418 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 //dump();
2421
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002422 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002423 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002424 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002425 mInputMonitor.updateInputWindowsLw();
2426
Joe Onorato8a9b2202010-02-26 18:56:32 -08002427 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 TAG, "New client " + client.asBinder()
2429 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002430
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002431 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002432 reportNewConfig = true;
2433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 }
2435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 if (reportNewConfig) {
2437 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 return res;
2443 }
Romain Guy06882f82009-06-10 13:36:04 -07002444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 public void removeWindow(Session session, IWindow client) {
2446 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002447 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 if (win == null) {
2449 return;
2450 }
2451 removeWindowLocked(session, win);
2452 }
2453 }
Romain Guy06882f82009-06-10 13:36:04 -07002454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 public void removeWindowLocked(Session session, WindowState win) {
2456
Joe Onorato8a9b2202010-02-26 18:56:32 -08002457 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 TAG, "Remove " + win + " client="
2459 + Integer.toHexString(System.identityHashCode(
2460 win.mClient.asBinder()))
2461 + ", surface=" + win.mSurface);
2462
2463 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002464
2465 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002466
Joe Onorato8a9b2202010-02-26 18:56:32 -08002467 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2469 + " mExiting=" + win.mExiting
2470 + " isAnimating=" + win.isAnimating()
2471 + " app-animation="
2472 + (win.mAppToken != null ? win.mAppToken.animation : null)
2473 + " inPendingTransaction="
2474 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2475 + " mDisplayFrozen=" + mDisplayFrozen);
2476 // Visibility of the removed window. Will be used later to update orientation later on.
2477 boolean wasVisible = false;
2478 // First, see if we need to run an animation. If we do, we have
2479 // to hold off on removing the window until the animation is done.
2480 // If the display is frozen, just remove immediately, since the
2481 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002482 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 // If we are not currently running the exit animation, we
2484 // need to see about starting one.
2485 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2488 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2489 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2490 }
2491 // Try starting an animation.
2492 if (applyAnimationLocked(win, transit, false)) {
2493 win.mExiting = true;
2494 }
2495 }
2496 if (win.mExiting || win.isAnimating()) {
2497 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002498 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 win.mExiting = true;
2500 win.mRemoveOnExit = true;
2501 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002502 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2503 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08002505 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 if (win.mAppToken != null) {
2507 win.mAppToken.updateReportedVisibilityLocked();
2508 }
2509 //dump();
2510 Binder.restoreCallingIdentity(origId);
2511 return;
2512 }
2513 }
2514
2515 removeWindowInnerLocked(session, win);
2516 // Removing a visible window will effect the computed orientation
2517 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002518 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002519 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002520 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002521 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002523 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 Binder.restoreCallingIdentity(origId);
2525 }
Romain Guy06882f82009-06-10 13:36:04 -07002526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002528 if (win.mRemoved) {
2529 // Nothing to do.
2530 return;
2531 }
2532
2533 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2534 WindowState cwin = win.mChildWindows.get(i);
2535 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2536 + win);
2537 removeWindowInnerLocked(cwin.mSession, cwin);
2538 }
2539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 if (mInputMethodTarget == win) {
2543 moveInputMethodWindowsIfNeededLocked(false);
2544 }
Romain Guy06882f82009-06-10 13:36:04 -07002545
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002546 if (false) {
2547 RuntimeException e = new RuntimeException("here");
2548 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002549 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 mPolicy.removeWindowLw(win);
2553 win.removeLocked();
2554
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002555 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 mWindowMap.remove(win.mClient.asBinder());
2557 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002558 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002559 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002560 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561
2562 if (mInputMethodWindow == win) {
2563 mInputMethodWindow = null;
2564 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2565 mInputMethodDialogs.remove(win);
2566 }
Romain Guy06882f82009-06-10 13:36:04 -07002567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 final WindowToken token = win.mToken;
2569 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002570 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 token.windows.remove(win);
2572 if (atoken != null) {
2573 atoken.allAppWindows.remove(win);
2574 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002575 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 TAG, "**** Removing window " + win + ": count="
2577 + token.windows.size());
2578 if (token.windows.size() == 0) {
2579 if (!token.explicit) {
2580 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 } else if (atoken != null) {
2582 atoken.firstWindowDrawn = false;
2583 }
2584 }
2585
2586 if (atoken != null) {
2587 if (atoken.startingWindow == win) {
2588 atoken.startingWindow = null;
2589 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2590 // If this is the last window and we had requested a starting
2591 // transition window, well there is no point now.
2592 atoken.startingData = null;
2593 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2594 // If this is the last window except for a starting transition
2595 // window, we need to get rid of the starting transition.
2596 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002597 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 + ": no more real windows");
2599 }
2600 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2601 mH.sendMessage(m);
2602 }
2603 }
Romain Guy06882f82009-06-10 13:36:04 -07002604
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002605 if (win.mAttrs.type == TYPE_WALLPAPER) {
2606 mLastWallpaperTimeoutTime = 0;
2607 adjustWallpaperWindowsLocked();
2608 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002609 adjustWallpaperWindowsLocked();
2610 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 if (!mInLayout) {
2613 assignLayersLocked();
2614 mLayoutNeeded = true;
2615 performLayoutAndPlaceSurfacesLocked();
2616 if (win.mAppToken != null) {
2617 win.mAppToken.updateReportedVisibilityLocked();
2618 }
2619 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002620
Jeff Brown3a22cd92011-01-21 13:59:04 -08002621 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002622 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 }
2624
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002625 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2626 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2627 + ": " + msg + " / " + w.mAttrs.getTitle();
2628 if (where != null) {
2629 Slog.i(TAG, str, where);
2630 } else {
2631 Slog.i(TAG, str);
2632 }
2633 }
2634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2636 long origId = Binder.clearCallingIdentity();
2637 try {
2638 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002639 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002640 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002641 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2642 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 Surface.openTransaction();
2644 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002645 if (SHOW_TRANSACTIONS) logSurface(w,
2646 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 w.mSurface.setTransparentRegionHint(region);
2648 } finally {
2649 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002650 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2651 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 }
2653 }
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(origId);
2657 }
2658 }
2659
2660 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002661 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002662 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002663 long origId = Binder.clearCallingIdentity();
2664 try {
2665 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002666 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 if (w != null) {
2668 w.mGivenInsetsPending = false;
2669 w.mGivenContentInsets.set(contentInsets);
2670 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002671 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 w.mTouchableInsets = touchableInsets;
2673 mLayoutNeeded = true;
2674 performLayoutAndPlaceSurfacesLocked();
2675 }
2676 }
2677 } finally {
2678 Binder.restoreCallingIdentity(origId);
2679 }
2680 }
Romain Guy06882f82009-06-10 13:36:04 -07002681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 public void getWindowDisplayFrame(Session session, IWindow client,
2683 Rect outDisplayFrame) {
2684 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002685 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 if (win == null) {
2687 outDisplayFrame.setEmpty();
2688 return;
2689 }
2690 outDisplayFrame.set(win.mDisplayFrame);
2691 }
2692 }
2693
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002694 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2695 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002696 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2697 window.mWallpaperX = x;
2698 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002699 window.mWallpaperXStep = xStep;
2700 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002701 if (updateWallpaperOffsetLocked(window, true)) {
2702 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002703 }
2704 }
2705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002706
Dianne Hackborn75804932009-10-20 20:15:20 -07002707 void wallpaperCommandComplete(IBinder window, Bundle result) {
2708 synchronized (mWindowMap) {
2709 if (mWaitingOnWallpaper != null &&
2710 mWaitingOnWallpaper.mClient.asBinder() == window) {
2711 mWaitingOnWallpaper = null;
2712 mWindowMap.notifyAll();
2713 }
2714 }
2715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002716
Dianne Hackborn75804932009-10-20 20:15:20 -07002717 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2718 String action, int x, int y, int z, Bundle extras, boolean sync) {
2719 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2720 || window == mUpperWallpaperTarget) {
2721 boolean doWait = sync;
2722 int curTokenIndex = mWallpaperTokens.size();
2723 while (curTokenIndex > 0) {
2724 curTokenIndex--;
2725 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2726 int curWallpaperIndex = token.windows.size();
2727 while (curWallpaperIndex > 0) {
2728 curWallpaperIndex--;
2729 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2730 try {
2731 wallpaper.mClient.dispatchWallpaperCommand(action,
2732 x, y, z, extras, sync);
2733 // We only want to be synchronous with one wallpaper.
2734 sync = false;
2735 } catch (RemoteException e) {
2736 }
2737 }
2738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002739
Dianne Hackborn75804932009-10-20 20:15:20 -07002740 if (doWait) {
2741 // XXX Need to wait for result.
2742 }
2743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002744
Dianne Hackborn75804932009-10-20 20:15:20 -07002745 return null;
2746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 public int relayoutWindow(Session session, IWindow client,
2749 WindowManager.LayoutParams attrs, int requestedWidth,
2750 int requestedHeight, int viewVisibility, boolean insetsPending,
2751 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002752 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 boolean displayed = false;
2754 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002755 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002759 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760 if (win == null) {
2761 return 0;
2762 }
2763 win.mRequestedWidth = requestedWidth;
2764 win.mRequestedHeight = requestedHeight;
2765
2766 if (attrs != null) {
2767 mPolicy.adjustWindowParamsLw(attrs);
2768 }
Romain Guy06882f82009-06-10 13:36:04 -07002769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 int attrChanges = 0;
2771 int flagChanges = 0;
2772 if (attrs != null) {
2773 flagChanges = win.mAttrs.flags ^= attrs.flags;
2774 attrChanges = win.mAttrs.copyFrom(attrs);
2775 }
2776
Joe Onorato8a9b2202010-02-26 18:56:32 -08002777 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002778
2779 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2780 win.mAlpha = attrs.alpha;
2781 }
2782
2783 final boolean scaledWindow =
2784 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2785
2786 if (scaledWindow) {
2787 // requested{Width|Height} Surface's physical size
2788 // attrs.{width|height} Size on screen
2789 win.mHScale = (attrs.width != requestedWidth) ?
2790 (attrs.width / (float)requestedWidth) : 1.0f;
2791 win.mVScale = (attrs.height != requestedHeight) ?
2792 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002793 } else {
2794 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 }
2796
2797 boolean imMayMove = (flagChanges&(
2798 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2799 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 boolean focusMayChange = win.mViewVisibility != viewVisibility
2802 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2803 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002804
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002805 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2806 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 win.mRelayoutCalled = true;
2809 final int oldVisibility = win.mViewVisibility;
2810 win.mViewVisibility = viewVisibility;
2811 if (viewVisibility == View.VISIBLE &&
2812 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2813 displayed = !win.isVisibleLw();
2814 if (win.mExiting) {
2815 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002816 if (win.mAnimation != null) {
2817 win.mAnimation.cancel();
2818 win.mAnimation = null;
2819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 }
2821 if (win.mDestroying) {
2822 win.mDestroying = false;
2823 mDestroySurface.remove(win);
2824 }
2825 if (oldVisibility == View.GONE) {
2826 win.mEnterAnimationPending = true;
2827 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002828 if (displayed) {
2829 if (win.mSurface != null && !win.mDrawPending
2830 && !win.mCommitDrawPending && !mDisplayFrozen
2831 && mPolicy.isScreenOn()) {
2832 applyEnterAnimationLocked(win);
2833 }
2834 if ((win.mAttrs.flags
2835 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2836 if (DEBUG_VISIBILITY) Slog.v(TAG,
2837 "Relayout window turning screen on: " + win);
2838 win.mTurnOnScreen = true;
2839 }
2840 int diff = 0;
2841 if (win.mConfiguration != mCurConfiguration
2842 && (win.mConfiguration == null
2843 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2844 win.mConfiguration = mCurConfiguration;
2845 if (DEBUG_CONFIGURATION) {
2846 Slog.i(TAG, "Window " + win + " visible with new config: "
2847 + win.mConfiguration + " / 0x"
2848 + Integer.toHexString(diff));
2849 }
2850 outConfig.setTo(mCurConfiguration);
2851 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2854 // To change the format, we need to re-build the surface.
2855 win.destroySurfaceLocked();
2856 displayed = true;
2857 }
2858 try {
2859 Surface surface = win.createSurfaceLocked();
2860 if (surface != null) {
2861 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002862 win.mReportDestroySurface = false;
2863 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002864 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002865 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002867 // For some reason there isn't a surface. Clear the
2868 // caller's object so they see the same state.
2869 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 }
2871 } catch (Exception e) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002872 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Browne33348b2010-07-15 23:54:05 -07002873 mInputMonitor.updateInputWindowsLw();
2874
Joe Onorato8a9b2202010-02-26 18:56:32 -08002875 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002876 + client + " (" + win.mAttrs.getTitle() + ")",
2877 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 Binder.restoreCallingIdentity(origId);
2879 return 0;
2880 }
2881 if (displayed) {
2882 focusMayChange = true;
2883 }
2884 if (win.mAttrs.type == TYPE_INPUT_METHOD
2885 && mInputMethodWindow == null) {
2886 mInputMethodWindow = win;
2887 imMayMove = true;
2888 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002889 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2890 && win.mAppToken != null
2891 && win.mAppToken.startingWindow != null) {
2892 // Special handling of starting window over the base
2893 // window of the app: propagate lock screen flags to it,
2894 // to provide the correct semantics while starting.
2895 final int mask =
2896 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002897 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2898 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002899 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2900 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 } else {
2903 win.mEnterAnimationPending = false;
2904 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002905 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002906 + ": mExiting=" + win.mExiting
2907 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 // If we are not currently running the exit animation, we
2909 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002910 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 // Try starting an animation; if there isn't one, we
2912 // can destroy the surface right away.
2913 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2914 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2915 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2916 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002917 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002919 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 } else if (win.isAnimating()) {
2922 // Currently in a hide animation... turn this into
2923 // an exit.
2924 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002925 } else if (win == mWallpaperTarget) {
2926 // If the wallpaper is currently behind this
2927 // window, we need to change both of them inside
2928 // of a transaction to avoid artifacts.
2929 win.mExiting = true;
2930 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 } else {
2932 if (mInputMethodWindow == win) {
2933 mInputMethodWindow = null;
2934 }
2935 win.destroySurfaceLocked();
2936 }
2937 }
2938 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002939
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002940 if (win.mSurface == null || (win.getAttrs().flags
2941 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2942 || win.mSurfacePendingDestroy) {
2943 // We are being called from a local process, which
2944 // means outSurface holds its current surface. Ensure the
2945 // surface object is cleared, but we don't want it actually
2946 // destroyed at this point.
2947 win.mSurfacePendingDestroy = false;
2948 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002949 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002950 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002951 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002952 "Keeping surface, will report destroy: " + win);
2953 win.mReportDestroySurface = true;
2954 outSurface.copyFrom(win.mSurface);
2955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 }
2957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 if (focusMayChange) {
2959 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002960 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2961 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 imMayMove = false;
2963 }
2964 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2965 }
Romain Guy06882f82009-06-10 13:36:04 -07002966
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002967 // updateFocusedWindowLocked() already assigned layers so we only need to
2968 // reassign them at this point if the IM window state gets shuffled
2969 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002972 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2973 // Little hack here -- we -should- be able to rely on the
2974 // function to return true if the IME has moved and needs
2975 // its layer recomputed. However, if the IME was hidden
2976 // and isn't actually moved in the list, its layer may be
2977 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 assignLayers = true;
2979 }
2980 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002981 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002982 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002983 assignLayers = true;
2984 }
2985 }
Romain Guy06882f82009-06-10 13:36:04 -07002986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 mLayoutNeeded = true;
2988 win.mGivenInsetsPending = insetsPending;
2989 if (assignLayers) {
2990 assignLayersLocked();
2991 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002992 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002994 if (displayed && win.mIsWallpaper) {
2995 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002996 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 if (win.mAppToken != null) {
2999 win.mAppToken.updateReportedVisibilityLocked();
3000 }
3001 outFrame.set(win.mFrame);
3002 outContentInsets.set(win.mContentInsets);
3003 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003004 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003006 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 + ", requestedHeight=" + requestedHeight
3008 + ", viewVisibility=" + viewVisibility
3009 + "\nRelayout returning frame=" + outFrame
3010 + ", surface=" + outSurface);
3011
Joe Onorato8a9b2202010-02-26 18:56:32 -08003012 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3014
3015 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003016
Jeff Brown3a22cd92011-01-21 13:59:04 -08003017 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Browne33348b2010-07-15 23:54:05 -07003018 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 }
3020
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003021 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 sendNewConfiguration();
3023 }
Romain Guy06882f82009-06-10 13:36:04 -07003024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3028 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3029 }
3030
3031 public void finishDrawingWindow(Session session, IWindow client) {
3032 final long origId = Binder.clearCallingIdentity();
3033 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003034 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003036 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3037 adjustWallpaperWindowsLocked();
3038 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 mLayoutNeeded = true;
3040 performLayoutAndPlaceSurfacesLocked();
3041 }
3042 }
3043 Binder.restoreCallingIdentity(origId);
3044 }
3045
3046 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003047 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 + (lp != null ? lp.packageName : null)
3049 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3050 if (lp != null && lp.windowAnimations != 0) {
3051 // If this is a system resource, don't try to load it from the
3052 // application resources. It is nice to avoid loading application
3053 // resources if we can.
3054 String packageName = lp.packageName != null ? lp.packageName : "android";
3055 int resId = lp.windowAnimations;
3056 if ((resId&0xFF000000) == 0x01000000) {
3057 packageName = "android";
3058 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003059 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 + packageName);
3061 return AttributeCache.instance().get(packageName, resId,
3062 com.android.internal.R.styleable.WindowAnimation);
3063 }
3064 return null;
3065 }
Romain Guy06882f82009-06-10 13:36:04 -07003066
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003067 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003068 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003069 + packageName + " resId=0x" + Integer.toHexString(resId));
3070 if (packageName != null) {
3071 if ((resId&0xFF000000) == 0x01000000) {
3072 packageName = "android";
3073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003074 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003075 + packageName);
3076 return AttributeCache.instance().get(packageName, resId,
3077 com.android.internal.R.styleable.WindowAnimation);
3078 }
3079 return null;
3080 }
3081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 private void applyEnterAnimationLocked(WindowState win) {
3083 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3084 if (win.mEnterAnimationPending) {
3085 win.mEnterAnimationPending = false;
3086 transit = WindowManagerPolicy.TRANSIT_ENTER;
3087 }
3088
3089 applyAnimationLocked(win, transit, true);
3090 }
3091
3092 private boolean applyAnimationLocked(WindowState win,
3093 int transit, boolean isEntrance) {
3094 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3095 // If we are trying to apply an animation, but already running
3096 // an animation of the same type, then just leave that one alone.
3097 return true;
3098 }
Romain Guy06882f82009-06-10 13:36:04 -07003099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 // Only apply an animation if the display isn't frozen. If it is
3101 // frozen, there is no reason to animate and it can cause strange
3102 // artifacts when we unfreeze the display if some different animation
3103 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003104 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 int anim = mPolicy.selectAnimationLw(win, transit);
3106 int attr = -1;
3107 Animation a = null;
3108 if (anim != 0) {
3109 a = AnimationUtils.loadAnimation(mContext, anim);
3110 } else {
3111 switch (transit) {
3112 case WindowManagerPolicy.TRANSIT_ENTER:
3113 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3114 break;
3115 case WindowManagerPolicy.TRANSIT_EXIT:
3116 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3117 break;
3118 case WindowManagerPolicy.TRANSIT_SHOW:
3119 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3120 break;
3121 case WindowManagerPolicy.TRANSIT_HIDE:
3122 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3123 break;
3124 }
3125 if (attr >= 0) {
3126 a = loadAnimation(win.mAttrs, attr);
3127 }
3128 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003129 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3131 + " mAnimation=" + win.mAnimation
3132 + " isEntrance=" + isEntrance);
3133 if (a != null) {
3134 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003135 RuntimeException e = null;
3136 if (!HIDE_STACK_CRAWLS) {
3137 e = new RuntimeException();
3138 e.fillInStackTrace();
3139 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003140 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 }
3142 win.setAnimation(a);
3143 win.mAnimationIsEntrance = isEntrance;
3144 }
3145 } else {
3146 win.clearAnimation();
3147 }
3148
3149 return win.mAnimation != null;
3150 }
3151
3152 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3153 int anim = 0;
3154 Context context = mContext;
3155 if (animAttr >= 0) {
3156 AttributeCache.Entry ent = getCachedAnimations(lp);
3157 if (ent != null) {
3158 context = ent.context;
3159 anim = ent.array.getResourceId(animAttr, 0);
3160 }
3161 }
3162 if (anim != 0) {
3163 return AnimationUtils.loadAnimation(context, anim);
3164 }
3165 return null;
3166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003168 private Animation loadAnimation(String packageName, int resId) {
3169 int anim = 0;
3170 Context context = mContext;
3171 if (resId >= 0) {
3172 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3173 if (ent != null) {
3174 context = ent.context;
3175 anim = resId;
3176 }
3177 }
3178 if (anim != 0) {
3179 return AnimationUtils.loadAnimation(context, anim);
3180 }
3181 return null;
3182 }
3183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 private boolean applyAnimationLocked(AppWindowToken wtoken,
3185 WindowManager.LayoutParams lp, int transit, boolean enter) {
3186 // Only apply an animation if the display isn't frozen. If it is
3187 // frozen, there is no reason to animate and it can cause strange
3188 // artifacts when we unfreeze the display if some different animation
3189 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003190 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003191 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003192 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003193 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003194 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003195 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003196 } else if (mNextAppTransitionPackage != null) {
3197 a = loadAnimation(mNextAppTransitionPackage, enter ?
3198 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003199 } else {
3200 int animAttr = 0;
3201 switch (transit) {
3202 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3203 animAttr = enter
3204 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3205 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3206 break;
3207 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3208 animAttr = enter
3209 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3210 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3211 break;
3212 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3213 animAttr = enter
3214 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3215 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3216 break;
3217 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3218 animAttr = enter
3219 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3220 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3221 break;
3222 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3223 animAttr = enter
3224 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3225 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3226 break;
3227 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3228 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003229 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003230 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3231 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003232 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003233 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003234 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3235 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003236 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003237 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003238 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003239 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3240 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3241 break;
3242 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3243 animAttr = enter
3244 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3245 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3246 break;
3247 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3248 animAttr = enter
3249 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3250 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003251 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003252 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003253 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003254 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003255 + " anim=" + a
3256 + " animAttr=0x" + Integer.toHexString(animAttr)
3257 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 if (a != null) {
3260 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003261 RuntimeException e = null;
3262 if (!HIDE_STACK_CRAWLS) {
3263 e = new RuntimeException();
3264 e.fillInStackTrace();
3265 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003266 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 }
3268 wtoken.setAnimation(a);
3269 }
3270 } else {
3271 wtoken.clearAnimation();
3272 }
3273
3274 return wtoken.animation != null;
3275 }
3276
3277 // -------------------------------------------------------------
3278 // Application Window Tokens
3279 // -------------------------------------------------------------
3280
3281 public void validateAppTokens(List tokens) {
3282 int v = tokens.size()-1;
3283 int m = mAppTokens.size()-1;
3284 while (v >= 0 && m >= 0) {
3285 AppWindowToken wtoken = mAppTokens.get(m);
3286 if (wtoken.removed) {
3287 m--;
3288 continue;
3289 }
3290 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003291 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3293 }
3294 v--;
3295 m--;
3296 }
3297 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003298 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 v--;
3300 }
3301 while (m >= 0) {
3302 AppWindowToken wtoken = mAppTokens.get(m);
3303 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 }
3306 m--;
3307 }
3308 }
3309
3310 boolean checkCallingPermission(String permission, String func) {
3311 // Quick check: if the calling permission is me, it's all okay.
3312 if (Binder.getCallingPid() == Process.myPid()) {
3313 return true;
3314 }
Romain Guy06882f82009-06-10 13:36:04 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 if (mContext.checkCallingPermission(permission)
3317 == PackageManager.PERMISSION_GRANTED) {
3318 return true;
3319 }
3320 String msg = "Permission Denial: " + func + " from pid="
3321 + Binder.getCallingPid()
3322 + ", uid=" + Binder.getCallingUid()
3323 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003324 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 return false;
3326 }
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 AppWindowToken findAppWindowToken(IBinder token) {
3329 WindowToken wtoken = mTokenMap.get(token);
3330 if (wtoken == null) {
3331 return null;
3332 }
3333 return wtoken.appWindowToken;
3334 }
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 public void addWindowToken(IBinder token, int type) {
3337 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3338 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003339 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 }
Romain Guy06882f82009-06-10 13:36:04 -07003341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 synchronized(mWindowMap) {
3343 WindowToken wtoken = mTokenMap.get(token);
3344 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003345 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 return;
3347 }
3348 wtoken = new WindowToken(token, type, true);
3349 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003350 if (type == TYPE_WALLPAPER) {
3351 mWallpaperTokens.add(wtoken);
3352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 }
3354 }
Romain Guy06882f82009-06-10 13:36:04 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 public void removeWindowToken(IBinder token) {
3357 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3358 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003359 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 }
3361
3362 final long origId = Binder.clearCallingIdentity();
3363 synchronized(mWindowMap) {
3364 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 if (wtoken != null) {
3366 boolean delayed = false;
3367 if (!wtoken.hidden) {
3368 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 final int N = wtoken.windows.size();
3371 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 for (int i=0; i<N; i++) {
3374 WindowState win = wtoken.windows.get(i);
3375
3376 if (win.isAnimating()) {
3377 delayed = true;
3378 }
Romain Guy06882f82009-06-10 13:36:04 -07003379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 if (win.isVisibleNow()) {
3381 applyAnimationLocked(win,
3382 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 changed = true;
3384 }
3385 }
3386
3387 if (changed) {
3388 mLayoutNeeded = true;
3389 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003390 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3391 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 }
Romain Guy06882f82009-06-10 13:36:04 -07003393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394 if (delayed) {
3395 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003396 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3397 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 }
3399 }
Romain Guy06882f82009-06-10 13:36:04 -07003400
Jeff Brown3a22cd92011-01-21 13:59:04 -08003401 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brownc5ed5912010-07-14 18:48:53 -07003402 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003404 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 }
3406 }
3407 Binder.restoreCallingIdentity(origId);
3408 }
3409
3410 public void addAppToken(int addPos, IApplicationToken token,
3411 int groupId, int requestedOrientation, boolean fullscreen) {
3412 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3413 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003414 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 }
Jeff Brown349703e2010-06-22 01:27:15 -07003416
3417 // Get the dispatching timeout here while we are not holding any locks so that it
3418 // can be cached by the AppWindowToken. The timeout value is used later by the
3419 // input dispatcher in code that does hold locks. If we did not cache the value
3420 // here we would run the chance of introducing a deadlock between the window manager
3421 // (which holds locks while updating the input dispatcher state) and the activity manager
3422 // (which holds locks while querying the application token).
3423 long inputDispatchingTimeoutNanos;
3424 try {
3425 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3426 } catch (RemoteException ex) {
3427 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3428 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3429 }
Romain Guy06882f82009-06-10 13:36:04 -07003430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 synchronized(mWindowMap) {
3432 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3433 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003434 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 return;
3436 }
3437 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003438 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 wtoken.groupId = groupId;
3440 wtoken.appFullscreen = fullscreen;
3441 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003442 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 // Application tokens start out hidden.
3447 wtoken.hidden = true;
3448 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 //dump();
3451 }
3452 }
Romain Guy06882f82009-06-10 13:36:04 -07003453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 public void setAppGroupId(IBinder token, int groupId) {
3455 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3456 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003457 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458 }
3459
3460 synchronized(mWindowMap) {
3461 AppWindowToken wtoken = findAppWindowToken(token);
3462 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003463 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 return;
3465 }
3466 wtoken.groupId = groupId;
3467 }
3468 }
Romain Guy06882f82009-06-10 13:36:04 -07003469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 public int getOrientationFromWindowsLocked() {
3471 int pos = mWindows.size() - 1;
3472 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003473 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 pos--;
3475 if (wtoken.mAppToken != null) {
3476 // We hit an application window. so the orientation will be determined by the
3477 // app window. No point in continuing further.
3478 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3479 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003480 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 continue;
3482 }
3483 int req = wtoken.mAttrs.screenOrientation;
3484 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3485 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3486 continue;
3487 } else {
3488 return req;
3489 }
3490 }
3491 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3492 }
Romain Guy06882f82009-06-10 13:36:04 -07003493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003494 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003495 int pos = mAppTokens.size() - 1;
3496 int curGroup = 0;
3497 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3498 boolean findingBehind = false;
3499 boolean haveGroup = false;
3500 boolean lastFullscreen = false;
3501 while (pos >= 0) {
3502 AppWindowToken wtoken = mAppTokens.get(pos);
3503 pos--;
3504 // if we're about to tear down this window and not seek for
3505 // the behind activity, don't use it for orientation
3506 if (!findingBehind
3507 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3508 continue;
3509 }
3510
3511 if (!haveGroup) {
3512 // We ignore any hidden applications on the top.
3513 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003514 continue;
3515 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003516 haveGroup = true;
3517 curGroup = wtoken.groupId;
3518 lastOrientation = wtoken.requestedOrientation;
3519 } else if (curGroup != wtoken.groupId) {
3520 // If we have hit a new application group, and the bottom
3521 // of the previous group didn't explicitly say to use
3522 // the orientation behind it, and the last app was
3523 // full screen, then we'll stick with the
3524 // user's orientation.
3525 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3526 && lastFullscreen) {
3527 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003530 int or = wtoken.requestedOrientation;
3531 // If this application is fullscreen, and didn't explicitly say
3532 // to use the orientation behind it, then just take whatever
3533 // orientation it has and ignores whatever is under it.
3534 lastFullscreen = wtoken.appFullscreen;
3535 if (lastFullscreen
3536 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3537 return or;
3538 }
3539 // If this application has requested an explicit orientation,
3540 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003541 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3542 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003543 return or;
3544 }
3545 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3546 }
3547 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 }
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003551 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003552 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3553 "updateOrientationFromAppTokens()")) {
3554 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3555 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003556
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003557 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003559
3560 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003561 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003562 if (freezeThisOneIfNeeded != null) {
3563 AppWindowToken wtoken = findAppWindowToken(
3564 freezeThisOneIfNeeded);
3565 if (wtoken != null) {
3566 startAppFreezingScreenLocked(wtoken,
3567 ActivityInfo.CONFIG_ORIENTATION);
3568 }
3569 }
3570 config = computeNewConfigurationLocked();
3571
3572 } else if (currentConfig != null) {
3573 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003574 // state mismatches the activity manager's, update it,
3575 // disregarding font scale, which should remain set to
3576 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003577 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003578 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003579 if (computeNewConfigurationLocked(mTempConfiguration)) {
3580 if (currentConfig.diff(mTempConfiguration) != 0) {
3581 mWaitingForConfig = true;
3582 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003583 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003584 config = new Configuration(mTempConfiguration);
3585 }
3586 }
3587 }
3588 }
3589
Dianne Hackborncfaef692009-06-15 14:24:44 -07003590 Binder.restoreCallingIdentity(ident);
3591 return config;
3592 }
3593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003594 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003595 * Determine the new desired orientation of the display, returning
3596 * a non-null new Configuration if it has changed from the current
3597 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3598 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3599 * SCREEN. This will typically be done for you if you call
3600 * sendNewConfiguration().
3601 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 * The orientation is computed from non-application windows first. If none of
3603 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003604 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003605 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3606 * android.os.IBinder)
3607 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003608 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3609 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003610 // If the display is frozen, some activities may be in the middle
3611 // of restarting, and thus have removed their old window. If the
3612 // window has the flag to hide the lock screen, then the lock screen
3613 // can re-appear and inflict its own orientation on us. Keep the
3614 // orientation stable until this all settles down.
3615 return false;
3616 }
3617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 long ident = Binder.clearCallingIdentity();
3620 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003621 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 mForcedAppOrientation = req;
3625 //send a message to Policy indicating orientation change to take
3626 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003627 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003628 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003629 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3630 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003631 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 }
3633 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003634
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003635 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 } finally {
3637 Binder.restoreCallingIdentity(ident);
3638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 }
Romain Guy06882f82009-06-10 13:36:04 -07003640
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003641 int computeForcedAppOrientationLocked() {
3642 int req = getOrientationFromWindowsLocked();
3643 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3644 req = getOrientationFromAppTokensLocked();
3645 }
3646 return req;
3647 }
Romain Guy06882f82009-06-10 13:36:04 -07003648
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003649 public void setNewConfiguration(Configuration config) {
3650 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3651 "setNewConfiguration()")) {
3652 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3653 }
3654
3655 synchronized(mWindowMap) {
3656 mCurConfiguration = new Configuration(config);
3657 mWaitingForConfig = false;
3658 performLayoutAndPlaceSurfacesLocked();
3659 }
3660 }
3661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3663 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3664 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003665 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003666 }
Romain Guy06882f82009-06-10 13:36:04 -07003667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 synchronized(mWindowMap) {
3669 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3670 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003671 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 return;
3673 }
Romain Guy06882f82009-06-10 13:36:04 -07003674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 wtoken.requestedOrientation = requestedOrientation;
3676 }
3677 }
Romain Guy06882f82009-06-10 13:36:04 -07003678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 public int getAppOrientation(IApplicationToken token) {
3680 synchronized(mWindowMap) {
3681 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3682 if (wtoken == null) {
3683 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3684 }
Romain Guy06882f82009-06-10 13:36:04 -07003685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 return wtoken.requestedOrientation;
3687 }
3688 }
Romain Guy06882f82009-06-10 13:36:04 -07003689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3691 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3692 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003693 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 }
3695
3696 synchronized(mWindowMap) {
3697 boolean changed = false;
3698 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003699 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 changed = mFocusedApp != null;
3701 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003702 if (changed) {
3703 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003704 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003705 } else {
3706 AppWindowToken newFocus = findAppWindowToken(token);
3707 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003708 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 return;
3710 }
3711 changed = mFocusedApp != newFocus;
3712 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003713 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003714 if (changed) {
3715 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 }
3718
3719 if (moveFocusNow && changed) {
3720 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003721 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 Binder.restoreCallingIdentity(origId);
3723 }
3724 }
3725 }
3726
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003727 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3729 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003730 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 }
Romain Guy06882f82009-06-10 13:36:04 -07003732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003734 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 TAG, "Prepare app transition: transit=" + transit
3736 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003737 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003738 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3739 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003741 } else if (!alwaysKeepCurrent) {
3742 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3743 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3744 // Opening a new task always supersedes a close for the anim.
3745 mNextAppTransition = transit;
3746 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3747 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3748 // Opening a new activity always supersedes a close for the anim.
3749 mNextAppTransition = transit;
3750 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 }
3752 mAppTransitionReady = false;
3753 mAppTransitionTimeout = false;
3754 mStartingIconInTransition = false;
3755 mSkipAppTransitionAnimation = false;
3756 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3757 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3758 5000);
3759 }
3760 }
3761 }
3762
3763 public int getPendingAppTransition() {
3764 return mNextAppTransition;
3765 }
Romain Guy06882f82009-06-10 13:36:04 -07003766
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003767 public void overridePendingAppTransition(String packageName,
3768 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003769 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003770 mNextAppTransitionPackage = packageName;
3771 mNextAppTransitionEnter = enterAnim;
3772 mNextAppTransitionExit = exitAnim;
3773 }
3774 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003776 public void executeAppTransition() {
3777 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3778 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003779 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 }
Romain Guy06882f82009-06-10 13:36:04 -07003781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003783 if (DEBUG_APP_TRANSITIONS) {
3784 RuntimeException e = new RuntimeException("here");
3785 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003786 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003787 + mNextAppTransition, e);
3788 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003789 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 mAppTransitionReady = true;
3791 final long origId = Binder.clearCallingIdentity();
3792 performLayoutAndPlaceSurfacesLocked();
3793 Binder.restoreCallingIdentity(origId);
3794 }
3795 }
3796 }
3797
3798 public void setAppStartingWindow(IBinder token, String pkg,
3799 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003800 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3802 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003803 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 }
3805
3806 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003807 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3809 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 AppWindowToken wtoken = findAppWindowToken(token);
3812 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003813 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 return;
3815 }
3816
3817 // If the display is frozen, we won't do anything until the
3818 // actual window is displayed so there is no reason to put in
3819 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003820 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 return;
3822 }
Romain Guy06882f82009-06-10 13:36:04 -07003823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 if (wtoken.startingData != null) {
3825 return;
3826 }
Romain Guy06882f82009-06-10 13:36:04 -07003827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 if (transferFrom != null) {
3829 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3830 if (ttoken != null) {
3831 WindowState startingWindow = ttoken.startingWindow;
3832 if (startingWindow != null) {
3833 if (mStartingIconInTransition) {
3834 // In this case, the starting icon has already
3835 // been displayed, so start letting windows get
3836 // shown immediately without any more transitions.
3837 mSkipAppTransitionAnimation = true;
3838 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003839 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 "Moving existing starting from " + ttoken
3841 + " to " + wtoken);
3842 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003844 // Transfer the starting window over to the new
3845 // token.
3846 wtoken.startingData = ttoken.startingData;
3847 wtoken.startingView = ttoken.startingView;
3848 wtoken.startingWindow = startingWindow;
3849 ttoken.startingData = null;
3850 ttoken.startingView = null;
3851 ttoken.startingWindow = null;
3852 ttoken.startingMoved = true;
3853 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003854 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003856 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003857 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003859 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003860 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3861 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 ttoken.windows.remove(startingWindow);
3863 ttoken.allAppWindows.remove(startingWindow);
3864 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003866 // Propagate other interesting state between the
3867 // tokens. If the old token is displayed, we should
3868 // immediately force the new one to be displayed. If
3869 // it is animating, we need to move that animation to
3870 // the new one.
3871 if (ttoken.allDrawn) {
3872 wtoken.allDrawn = true;
3873 }
3874 if (ttoken.firstWindowDrawn) {
3875 wtoken.firstWindowDrawn = true;
3876 }
3877 if (!ttoken.hidden) {
3878 wtoken.hidden = false;
3879 wtoken.hiddenRequested = false;
3880 wtoken.willBeHidden = false;
3881 }
3882 if (wtoken.clientHidden != ttoken.clientHidden) {
3883 wtoken.clientHidden = ttoken.clientHidden;
3884 wtoken.sendAppVisibilityToClients();
3885 }
3886 if (ttoken.animation != null) {
3887 wtoken.animation = ttoken.animation;
3888 wtoken.animating = ttoken.animating;
3889 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3890 ttoken.animation = null;
3891 ttoken.animLayerAdjustment = 0;
3892 wtoken.updateLayers();
3893 ttoken.updateLayers();
3894 }
Romain Guy06882f82009-06-10 13:36:04 -07003895
Jeff Brown3a22cd92011-01-21 13:59:04 -08003896 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3897 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003898 mLayoutNeeded = true;
3899 performLayoutAndPlaceSurfacesLocked();
3900 Binder.restoreCallingIdentity(origId);
3901 return;
3902 } else if (ttoken.startingData != null) {
3903 // The previous app was getting ready to show a
3904 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003905 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003906 "Moving pending starting from " + ttoken
3907 + " to " + wtoken);
3908 wtoken.startingData = ttoken.startingData;
3909 ttoken.startingData = null;
3910 ttoken.startingMoved = true;
3911 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3912 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3913 // want to process the message ASAP, before any other queued
3914 // messages.
3915 mH.sendMessageAtFrontOfQueue(m);
3916 return;
3917 }
3918 }
3919 }
3920
3921 // There is no existing starting window, and the caller doesn't
3922 // want us to create one, so that's it!
3923 if (!createIfNeeded) {
3924 return;
3925 }
Romain Guy06882f82009-06-10 13:36:04 -07003926
Dianne Hackborn284ac932009-08-28 10:34:25 -07003927 // If this is a translucent or wallpaper window, then don't
3928 // show a starting window -- the current effect (a full-screen
3929 // opaque starting window that fades away to the real contents
3930 // when it is ready) does not work for this.
3931 if (theme != 0) {
3932 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3933 com.android.internal.R.styleable.Window);
3934 if (ent.array.getBoolean(
3935 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3936 return;
3937 }
3938 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003939 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3940 return;
3941 }
3942 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003943 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3944 return;
3945 }
3946 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 mStartingIconInTransition = true;
3949 wtoken.startingData = new StartingData(
3950 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003951 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3953 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3954 // want to process the message ASAP, before any other queued
3955 // messages.
3956 mH.sendMessageAtFrontOfQueue(m);
3957 }
3958 }
3959
3960 public void setAppWillBeHidden(IBinder token) {
3961 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3962 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003963 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 }
3965
3966 AppWindowToken wtoken;
3967
3968 synchronized(mWindowMap) {
3969 wtoken = findAppWindowToken(token);
3970 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003971 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 -08003972 return;
3973 }
3974 wtoken.willBeHidden = true;
3975 }
3976 }
Romain Guy06882f82009-06-10 13:36:04 -07003977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3979 boolean visible, int transit, boolean performLayout) {
3980 boolean delayed = false;
3981
3982 if (wtoken.clientHidden == visible) {
3983 wtoken.clientHidden = !visible;
3984 wtoken.sendAppVisibilityToClients();
3985 }
Romain Guy06882f82009-06-10 13:36:04 -07003986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 wtoken.willBeHidden = false;
3988 if (wtoken.hidden == visible) {
3989 final int N = wtoken.allAppWindows.size();
3990 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003991 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3993 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003996
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003997 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 if (wtoken.animation == sDummyAnimation) {
3999 wtoken.animation = null;
4000 }
4001 applyAnimationLocked(wtoken, lp, transit, visible);
4002 changed = true;
4003 if (wtoken.animation != null) {
4004 delayed = runningAppAnimation = true;
4005 }
4006 }
Romain Guy06882f82009-06-10 13:36:04 -07004007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 for (int i=0; i<N; i++) {
4009 WindowState win = wtoken.allAppWindows.get(i);
4010 if (win == wtoken.startingWindow) {
4011 continue;
4012 }
4013
4014 if (win.isAnimating()) {
4015 delayed = true;
4016 }
Romain Guy06882f82009-06-10 13:36:04 -07004017
Joe Onorato8a9b2202010-02-26 18:56:32 -08004018 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 //win.dump(" ");
4020 if (visible) {
4021 if (!win.isVisibleNow()) {
4022 if (!runningAppAnimation) {
4023 applyAnimationLocked(win,
4024 WindowManagerPolicy.TRANSIT_ENTER, true);
4025 }
4026 changed = true;
4027 }
4028 } else if (win.isVisibleNow()) {
4029 if (!runningAppAnimation) {
4030 applyAnimationLocked(win,
4031 WindowManagerPolicy.TRANSIT_EXIT, false);
4032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 changed = true;
4034 }
4035 }
4036
4037 wtoken.hidden = wtoken.hiddenRequested = !visible;
4038 if (!visible) {
4039 unsetAppFreezingScreenLocked(wtoken, true, true);
4040 } else {
4041 // If we are being set visible, and the starting window is
4042 // not yet displayed, then make sure it doesn't get displayed.
4043 WindowState swin = wtoken.startingWindow;
4044 if (swin != null && (swin.mDrawPending
4045 || swin.mCommitDrawPending)) {
4046 swin.mPolicyVisibility = false;
4047 swin.mPolicyVisibilityAfterAnim = false;
4048 }
4049 }
Romain Guy06882f82009-06-10 13:36:04 -07004050
Joe Onorato8a9b2202010-02-26 18:56:32 -08004051 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4053 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004054
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004055 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004056 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004057 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004058 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004059 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4060 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004061 performLayoutAndPlaceSurfacesLocked();
4062 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08004063 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 }
4065 }
4066
4067 if (wtoken.animation != null) {
4068 delayed = true;
4069 }
Romain Guy06882f82009-06-10 13:36:04 -07004070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004071 return delayed;
4072 }
4073
4074 public void setAppVisibility(IBinder token, boolean visible) {
4075 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4076 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004077 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 }
4079
4080 AppWindowToken wtoken;
4081
4082 synchronized(mWindowMap) {
4083 wtoken = findAppWindowToken(token);
4084 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004085 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 return;
4087 }
4088
4089 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004090 RuntimeException e = null;
4091 if (!HIDE_STACK_CRAWLS) {
4092 e = new RuntimeException();
4093 e.fillInStackTrace();
4094 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004095 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 + "): mNextAppTransition=" + mNextAppTransition
4097 + " hidden=" + wtoken.hidden
4098 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4099 }
Romain Guy06882f82009-06-10 13:36:04 -07004100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 // If we are preparing an app transition, then delay changing
4102 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004103 if (!mDisplayFrozen && mPolicy.isScreenOn()
4104 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004105 // Already in requested state, don't do anything more.
4106 if (wtoken.hiddenRequested != visible) {
4107 return;
4108 }
4109 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004110
Joe Onorato8a9b2202010-02-26 18:56:32 -08004111 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 TAG, "Setting dummy animation on: " + wtoken);
4113 wtoken.setDummyAnimation();
4114 mOpeningApps.remove(wtoken);
4115 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004116 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 wtoken.inPendingTransaction = true;
4118 if (visible) {
4119 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004120 wtoken.startingDisplayed = false;
4121 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004122
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004123 // If the token is currently hidden (should be the
4124 // common case), then we need to set up to wait for
4125 // its windows to be ready.
4126 if (wtoken.hidden) {
4127 wtoken.allDrawn = false;
4128 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004129
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004130 if (wtoken.clientHidden) {
4131 // In the case where we are making an app visible
4132 // but holding off for a transition, we still need
4133 // to tell the client to make its windows visible so
4134 // they get drawn. Otherwise, we will wait on
4135 // performing the transition until all windows have
4136 // been drawn, they never will be, and we are sad.
4137 wtoken.clientHidden = false;
4138 wtoken.sendAppVisibilityToClients();
4139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 }
4141 } else {
4142 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004143
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004144 // If the token is currently visible (should be the
4145 // common case), then set up to wait for it to be hidden.
4146 if (!wtoken.hidden) {
4147 wtoken.waitingToHide = true;
4148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 }
4150 return;
4151 }
Romain Guy06882f82009-06-10 13:36:04 -07004152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004154 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004155 wtoken.updateReportedVisibilityLocked();
4156 Binder.restoreCallingIdentity(origId);
4157 }
4158 }
4159
4160 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4161 boolean unfreezeSurfaceNow, boolean force) {
4162 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004163 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 + " force=" + force);
4165 final int N = wtoken.allAppWindows.size();
4166 boolean unfrozeWindows = false;
4167 for (int i=0; i<N; i++) {
4168 WindowState w = wtoken.allAppWindows.get(i);
4169 if (w.mAppFreezing) {
4170 w.mAppFreezing = false;
4171 if (w.mSurface != null && !w.mOrientationChanging) {
4172 w.mOrientationChanging = true;
4173 }
4174 unfrozeWindows = true;
4175 }
4176 }
4177 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004178 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 wtoken.freezingScreen = false;
4180 mAppsFreezingScreen--;
4181 }
4182 if (unfreezeSurfaceNow) {
4183 if (unfrozeWindows) {
4184 mLayoutNeeded = true;
4185 performLayoutAndPlaceSurfacesLocked();
4186 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004187 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 }
4189 }
4190 }
Romain Guy06882f82009-06-10 13:36:04 -07004191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4193 int configChanges) {
4194 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004195 RuntimeException e = null;
4196 if (!HIDE_STACK_CRAWLS) {
4197 e = new RuntimeException();
4198 e.fillInStackTrace();
4199 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004200 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 + ": hidden=" + wtoken.hidden + " freezing="
4202 + wtoken.freezingScreen, e);
4203 }
4204 if (!wtoken.hiddenRequested) {
4205 if (!wtoken.freezingScreen) {
4206 wtoken.freezingScreen = true;
4207 mAppsFreezingScreen++;
4208 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004209 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4211 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4212 5000);
4213 }
4214 }
4215 final int N = wtoken.allAppWindows.size();
4216 for (int i=0; i<N; i++) {
4217 WindowState w = wtoken.allAppWindows.get(i);
4218 w.mAppFreezing = true;
4219 }
4220 }
4221 }
Romain Guy06882f82009-06-10 13:36:04 -07004222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 public void startAppFreezingScreen(IBinder token, int configChanges) {
4224 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4225 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004226 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004227 }
4228
4229 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004230 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004231 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004232 return;
4233 }
Romain Guy06882f82009-06-10 13:36:04 -07004234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 AppWindowToken wtoken = findAppWindowToken(token);
4236 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004237 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 return;
4239 }
4240 final long origId = Binder.clearCallingIdentity();
4241 startAppFreezingScreenLocked(wtoken, configChanges);
4242 Binder.restoreCallingIdentity(origId);
4243 }
4244 }
Romain Guy06882f82009-06-10 13:36:04 -07004245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 public void stopAppFreezingScreen(IBinder token, boolean force) {
4247 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4248 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004249 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 }
4251
4252 synchronized(mWindowMap) {
4253 AppWindowToken wtoken = findAppWindowToken(token);
4254 if (wtoken == null || wtoken.appToken == null) {
4255 return;
4256 }
4257 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004258 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004259 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4260 unsetAppFreezingScreenLocked(wtoken, true, force);
4261 Binder.restoreCallingIdentity(origId);
4262 }
4263 }
Romain Guy06882f82009-06-10 13:36:04 -07004264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 public void removeAppToken(IBinder token) {
4266 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4267 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004268 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 }
4270
4271 AppWindowToken wtoken = null;
4272 AppWindowToken startingToken = null;
4273 boolean delayed = false;
4274
4275 final long origId = Binder.clearCallingIdentity();
4276 synchronized(mWindowMap) {
4277 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004279 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004280 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 wtoken.inPendingTransaction = false;
4282 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004283 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 if (mClosingApps.contains(wtoken)) {
4285 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004286 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004288 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 delayed = true;
4290 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004291 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 TAG, "Removing app " + wtoken + " delayed=" + delayed
4293 + " animation=" + wtoken.animation
4294 + " animating=" + wtoken.animating);
4295 if (delayed) {
4296 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004297 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4298 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004300 } else {
4301 // Make sure there is no animation running on this token,
4302 // so any windows associated with it will be removed as
4303 // soon as their animations are complete
4304 wtoken.animation = null;
4305 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004307 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4308 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 mAppTokens.remove(wtoken);
4310 wtoken.removed = true;
4311 if (wtoken.startingData != null) {
4312 startingToken = wtoken;
4313 }
4314 unsetAppFreezingScreenLocked(wtoken, true, true);
4315 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004316 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004318 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004319 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 }
4321 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004322 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Romain Guy06882f82009-06-10 13:36:04 -07004324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 if (!delayed && wtoken != null) {
4326 wtoken.updateReportedVisibilityLocked();
4327 }
4328 }
4329 Binder.restoreCallingIdentity(origId);
4330
4331 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004332 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 + startingToken + ": app token removed");
4334 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4335 mH.sendMessage(m);
4336 }
4337 }
4338
4339 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4340 final int NW = token.windows.size();
4341 for (int i=0; i<NW; i++) {
4342 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004343 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004345 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 int j = win.mChildWindows.size();
4347 while (j > 0) {
4348 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004349 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004350 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004351 "Tmp removing child window " + cwin);
4352 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004353 }
4354 }
4355 return NW > 0;
4356 }
4357
4358 void dumpAppTokensLocked() {
4359 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004360 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 }
4362 }
Romain Guy06882f82009-06-10 13:36:04 -07004363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 void dumpWindowsLocked() {
4365 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004366 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 }
4368 }
Romain Guy06882f82009-06-10 13:36:04 -07004369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 private int findWindowOffsetLocked(int tokenPos) {
4371 final int NW = mWindows.size();
4372
4373 if (tokenPos >= mAppTokens.size()) {
4374 int i = NW;
4375 while (i > 0) {
4376 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004377 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004378 if (win.getAppToken() != null) {
4379 return i+1;
4380 }
4381 }
4382 }
4383
4384 while (tokenPos > 0) {
4385 // Find the first app token below the new position that has
4386 // a window displayed.
4387 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004388 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004390 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004391 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004392 "Skipping token -- currently sending to bottom");
4393 tokenPos--;
4394 continue;
4395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 int i = wtoken.windows.size();
4397 while (i > 0) {
4398 i--;
4399 WindowState win = wtoken.windows.get(i);
4400 int j = win.mChildWindows.size();
4401 while (j > 0) {
4402 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004403 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004404 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 for (int pos=NW-1; pos>=0; pos--) {
4406 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004407 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 "Found child win @" + (pos+1));
4409 return pos+1;
4410 }
4411 }
4412 }
4413 }
4414 for (int pos=NW-1; pos>=0; pos--) {
4415 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004416 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 return pos+1;
4418 }
4419 }
4420 }
4421 tokenPos--;
4422 }
4423
4424 return 0;
4425 }
4426
4427 private final int reAddWindowLocked(int index, WindowState win) {
4428 final int NCW = win.mChildWindows.size();
4429 boolean added = false;
4430 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004431 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004433 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004434 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004435 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 mWindows.add(index, win);
4437 index++;
4438 added = true;
4439 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004440 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004441 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004442 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 mWindows.add(index, cwin);
4444 index++;
4445 }
4446 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004448 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004449 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004450 mWindows.add(index, win);
4451 index++;
4452 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004453 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 return index;
4455 }
Romain Guy06882f82009-06-10 13:36:04 -07004456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4458 final int NW = token.windows.size();
4459 for (int i=0; i<NW; i++) {
4460 index = reAddWindowLocked(index, token.windows.get(i));
4461 }
4462 return index;
4463 }
4464
4465 public void moveAppToken(int index, IBinder token) {
4466 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4467 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004468 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470
4471 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004472 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 if (DEBUG_REORDER) dumpAppTokensLocked();
4474 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004475 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4476 "Start moving token " + wtoken + " initially at "
4477 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004479 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 + token + " (" + wtoken + ")");
4481 return;
4482 }
4483 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004484 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004485 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004489 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 if (DEBUG_REORDER) dumpWindowsLocked();
4491 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004492 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004493 if (DEBUG_REORDER) dumpWindowsLocked();
4494 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004495 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004497 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4498 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 mLayoutNeeded = true;
4500 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004501 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 }
4503 Binder.restoreCallingIdentity(origId);
4504 }
4505 }
4506
4507 private void removeAppTokensLocked(List<IBinder> tokens) {
4508 // XXX This should be done more efficiently!
4509 // (take advantage of the fact that both lists should be
4510 // ordered in the same way.)
4511 int N = tokens.size();
4512 for (int i=0; i<N; i++) {
4513 IBinder token = tokens.get(i);
4514 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004515 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4516 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004518 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 + token + " (" + wtoken + ")");
4520 i--;
4521 N--;
4522 }
4523 }
4524 }
4525
Dianne Hackborna8f60182009-09-01 19:01:50 -07004526 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4527 boolean updateFocusAndLayout) {
4528 // First remove all of the windows from the list.
4529 tmpRemoveAppWindowsLocked(wtoken);
4530
4531 // Where to start adding?
4532 int pos = findWindowOffsetLocked(tokenPos);
4533
4534 // And now add them back at the correct place.
4535 pos = reAddAppWindowsLocked(pos, wtoken);
4536
4537 if (updateFocusAndLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004538 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4539 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004540 assignLayersLocked();
4541 }
4542 mLayoutNeeded = true;
4543 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004544 mInputMonitor.updateInputWindowsLw();
Dianne Hackborna8f60182009-09-01 19:01:50 -07004545 }
4546 }
4547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4549 // First remove all of the windows from the list.
4550 final int N = tokens.size();
4551 int i;
4552 for (i=0; i<N; i++) {
4553 WindowToken token = mTokenMap.get(tokens.get(i));
4554 if (token != null) {
4555 tmpRemoveAppWindowsLocked(token);
4556 }
4557 }
4558
4559 // Where to start adding?
4560 int pos = findWindowOffsetLocked(tokenPos);
4561
4562 // And now add them back at the correct place.
4563 for (i=0; i<N; i++) {
4564 WindowToken token = mTokenMap.get(tokens.get(i));
4565 if (token != null) {
4566 pos = reAddAppWindowsLocked(pos, token);
4567 }
4568 }
4569
Jeff Brown3a22cd92011-01-21 13:59:04 -08004570 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4571 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004572 assignLayersLocked();
4573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004574 mLayoutNeeded = true;
4575 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004576 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004577
4578 //dump();
4579 }
4580
4581 public void moveAppTokensToTop(List<IBinder> tokens) {
4582 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4583 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004584 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004585 }
4586
4587 final long origId = Binder.clearCallingIdentity();
4588 synchronized(mWindowMap) {
4589 removeAppTokensLocked(tokens);
4590 final int N = tokens.size();
4591 for (int i=0; i<N; i++) {
4592 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4593 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004594 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4595 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004597 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004598 mToTopApps.remove(wt);
4599 mToBottomApps.remove(wt);
4600 mToTopApps.add(wt);
4601 wt.sendingToBottom = false;
4602 wt.sendingToTop = true;
4603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004604 }
4605 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004606
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004607 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004608 moveAppWindowsLocked(tokens, mAppTokens.size());
4609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004610 }
4611 Binder.restoreCallingIdentity(origId);
4612 }
4613
4614 public void moveAppTokensToBottom(List<IBinder> tokens) {
4615 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4616 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004617 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004618 }
4619
4620 final long origId = Binder.clearCallingIdentity();
4621 synchronized(mWindowMap) {
4622 removeAppTokensLocked(tokens);
4623 final int N = tokens.size();
4624 int pos = 0;
4625 for (int i=0; i<N; i++) {
4626 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4627 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004628 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4629 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004631 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004632 mToTopApps.remove(wt);
4633 mToBottomApps.remove(wt);
4634 mToBottomApps.add(i, wt);
4635 wt.sendingToTop = false;
4636 wt.sendingToBottom = true;
4637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004638 pos++;
4639 }
4640 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004641
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004642 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004643 moveAppWindowsLocked(tokens, 0);
4644 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 }
4646 Binder.restoreCallingIdentity(origId);
4647 }
4648
4649 // -------------------------------------------------------------
4650 // Misc IWindowSession methods
4651 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004652
Jim Miller284b62e2010-06-08 14:27:42 -07004653 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004654 {
Jim Miller284b62e2010-06-08 14:27:42 -07004655 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4656 // called before DevicePolicyManagerService has started.
4657 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4658 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4659 Context.DEVICE_POLICY_SERVICE);
4660 if (dpm != null) {
4661 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4662 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4663 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4664 }
Jim Millerd6b57052010-06-07 17:52:42 -07004665 }
Jim Miller284b62e2010-06-08 14:27:42 -07004666 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004667 }
4668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004669 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004670 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004671 != PackageManager.PERMISSION_GRANTED) {
4672 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4673 }
Jim Millerd6b57052010-06-07 17:52:42 -07004674
Jim Miller284b62e2010-06-08 14:27:42 -07004675 synchronized (mKeyguardTokenWatcher) {
4676 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004677 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 }
4679
4680 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004681 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 != PackageManager.PERMISSION_GRANTED) {
4683 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4684 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685
Jim Miller284b62e2010-06-08 14:27:42 -07004686 synchronized (mKeyguardTokenWatcher) {
4687 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004688
Jim Miller284b62e2010-06-08 14:27:42 -07004689 if (!mKeyguardTokenWatcher.isAcquired()) {
4690 // If we are the last one to reenable the keyguard wait until
4691 // we have actually finished reenabling until returning.
4692 // It is possible that reenableKeyguard() can be called before
4693 // the previous disableKeyguard() is handled, in which case
4694 // neither mKeyguardTokenWatcher.acquired() or released() would
4695 // be called. In that case mKeyguardDisabled will be false here
4696 // and we have nothing to wait for.
4697 while (mKeyguardDisabled) {
4698 try {
4699 mKeyguardTokenWatcher.wait();
4700 } catch (InterruptedException e) {
4701 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702 }
4703 }
4704 }
4705 }
4706 }
4707
4708 /**
4709 * @see android.app.KeyguardManager#exitKeyguardSecurely
4710 */
4711 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004712 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004713 != PackageManager.PERMISSION_GRANTED) {
4714 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4715 }
4716 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4717 public void onKeyguardExitResult(boolean success) {
4718 try {
4719 callback.onKeyguardExitResult(success);
4720 } catch (RemoteException e) {
4721 // Client has died, we don't care.
4722 }
4723 }
4724 });
4725 }
4726
4727 public boolean inKeyguardRestrictedInputMode() {
4728 return mPolicy.inKeyguardRestrictedKeyInputMode();
4729 }
Romain Guy06882f82009-06-10 13:36:04 -07004730
Dianne Hackbornffa42482009-09-23 22:20:11 -07004731 public void closeSystemDialogs(String reason) {
4732 synchronized(mWindowMap) {
4733 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004734 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004735 if (w.mSurface != null) {
4736 try {
4737 w.mClient.closeSystemDialogs(reason);
4738 } catch (RemoteException e) {
4739 }
4740 }
4741 }
4742 }
4743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 static float fixScale(float scale) {
4746 if (scale < 0) scale = 0;
4747 else if (scale > 20) scale = 20;
4748 return Math.abs(scale);
4749 }
Romain Guy06882f82009-06-10 13:36:04 -07004750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004751 public void setAnimationScale(int which, float scale) {
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 (scale < 0) scale = 0;
4758 else if (scale > 20) scale = 20;
4759 scale = Math.abs(scale);
4760 switch (which) {
4761 case 0: mWindowAnimationScale = fixScale(scale); break;
4762 case 1: mTransitionAnimationScale = fixScale(scale); break;
4763 }
Romain Guy06882f82009-06-10 13:36:04 -07004764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765 // Persist setting
4766 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 public void setAnimationScales(float[] scales) {
4770 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4771 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004772 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004773 }
4774
4775 if (scales != null) {
4776 if (scales.length >= 1) {
4777 mWindowAnimationScale = fixScale(scales[0]);
4778 }
4779 if (scales.length >= 2) {
4780 mTransitionAnimationScale = fixScale(scales[1]);
4781 }
4782 }
Romain Guy06882f82009-06-10 13:36:04 -07004783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004784 // Persist setting
4785 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4786 }
Romain Guy06882f82009-06-10 13:36:04 -07004787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 public float getAnimationScale(int which) {
4789 switch (which) {
4790 case 0: return mWindowAnimationScale;
4791 case 1: return mTransitionAnimationScale;
4792 }
4793 return 0;
4794 }
Romain Guy06882f82009-06-10 13:36:04 -07004795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 public float[] getAnimationScales() {
4797 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4798 }
Romain Guy06882f82009-06-10 13:36:04 -07004799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004800 public int getSwitchState(int sw) {
4801 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4802 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004803 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004805 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004806 }
Romain Guy06882f82009-06-10 13:36:04 -07004807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 public int getSwitchStateForDevice(int devid, int sw) {
4809 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4810 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004811 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004813 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004814 }
Romain Guy06882f82009-06-10 13:36:04 -07004815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 public int getScancodeState(int sw) {
4817 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4818 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004819 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004821 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004822 }
Romain Guy06882f82009-06-10 13:36:04 -07004823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004824 public int getScancodeStateForDevice(int devid, int sw) {
4825 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4826 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004827 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004828 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004829 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830 }
Romain Guy06882f82009-06-10 13:36:04 -07004831
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004832 public int getTrackballScancodeState(int sw) {
4833 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4834 "getTrackballScancodeState()")) {
4835 throw new SecurityException("Requires READ_INPUT_STATE permission");
4836 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004837 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004838 }
4839
4840 public int getDPadScancodeState(int sw) {
4841 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4842 "getDPadScancodeState()")) {
4843 throw new SecurityException("Requires READ_INPUT_STATE permission");
4844 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004845 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004846 }
4847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 public int getKeycodeState(int sw) {
4849 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4850 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004851 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004853 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004854 }
Romain Guy06882f82009-06-10 13:36:04 -07004855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 public int getKeycodeStateForDevice(int devid, int sw) {
4857 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4858 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004859 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004861 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 }
Romain Guy06882f82009-06-10 13:36:04 -07004863
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004864 public int getTrackballKeycodeState(int sw) {
4865 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4866 "getTrackballKeycodeState()")) {
4867 throw new SecurityException("Requires READ_INPUT_STATE permission");
4868 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004869 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004870 }
4871
4872 public int getDPadKeycodeState(int sw) {
4873 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4874 "getDPadKeycodeState()")) {
4875 throw new SecurityException("Requires READ_INPUT_STATE permission");
4876 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004877 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004878 }
Jeff Browna41ca772010-08-11 14:46:32 -07004879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004881 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004882 }
Romain Guy06882f82009-06-10 13:36:04 -07004883
Jeff Browna41ca772010-08-11 14:46:32 -07004884 public InputChannel monitorInput(String inputChannelName) {
4885 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4886 "monitorInput()")) {
4887 throw new SecurityException("Requires READ_INPUT_STATE permission");
4888 }
4889 return mInputManager.monitorInput(inputChannelName);
4890 }
4891
Jeff Brown8d608662010-08-30 03:02:23 -07004892 public InputDevice getInputDevice(int deviceId) {
4893 return mInputManager.getInputDevice(deviceId);
4894 }
4895
4896 public int[] getInputDeviceIds() {
4897 return mInputManager.getInputDeviceIds();
4898 }
4899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 public void enableScreenAfterBoot() {
4901 synchronized(mWindowMap) {
4902 if (mSystemBooted) {
4903 return;
4904 }
4905 mSystemBooted = true;
4906 }
Romain Guy06882f82009-06-10 13:36:04 -07004907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 performEnableScreen();
4909 }
Romain Guy06882f82009-06-10 13:36:04 -07004910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 public void enableScreenIfNeededLocked() {
4912 if (mDisplayEnabled) {
4913 return;
4914 }
4915 if (!mSystemBooted) {
4916 return;
4917 }
4918 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4919 }
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 public void performEnableScreen() {
4922 synchronized(mWindowMap) {
4923 if (mDisplayEnabled) {
4924 return;
4925 }
4926 if (!mSystemBooted) {
4927 return;
4928 }
Romain Guy06882f82009-06-10 13:36:04 -07004929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 // Don't enable the screen until all existing windows
4931 // have been drawn.
4932 final int N = mWindows.size();
4933 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004934 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004935 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 return;
4937 }
4938 }
Romain Guy06882f82009-06-10 13:36:04 -07004939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004940 mDisplayEnabled = true;
4941 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004942 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004943 StringWriter sw = new StringWriter();
4944 PrintWriter pw = new PrintWriter(sw);
4945 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004946 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 }
4948 try {
4949 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4950 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004951 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 Parcel data = Parcel.obtain();
4953 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4954 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4955 data, null, 0);
4956 data.recycle();
4957 }
4958 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004959 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004960 }
4961 }
Romain Guy06882f82009-06-10 13:36:04 -07004962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004963 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004965 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004966 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4967 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004968 }
Romain Guy06882f82009-06-10 13:36:04 -07004969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004970 public void setInTouchMode(boolean mode) {
4971 synchronized(mWindowMap) {
4972 mInTouchMode = mode;
4973 }
4974 }
4975
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004976 // TODO: more accounting of which pid(s) turned it on, keep count,
4977 // only allow disables from pids which have count on, etc.
4978 public void showStrictModeViolation(boolean on) {
4979 int pid = Binder.getCallingPid();
4980 synchronized(mWindowMap) {
4981 // Ignoring requests to enable the red border from clients
4982 // which aren't on screen. (e.g. Broadcast Receivers in
4983 // the background..)
4984 if (on) {
4985 boolean isVisible = false;
4986 for (WindowState ws : mWindows) {
4987 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4988 isVisible = true;
4989 break;
4990 }
4991 }
4992 if (!isVisible) {
4993 return;
4994 }
4995 }
4996
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004997 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004998 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004999 try {
5000 if (mStrictModeFlash == null) {
5001 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
5002 }
5003 mStrictModeFlash.setVisibility(on);
5004 } finally {
5005 Surface.closeTransaction();
5006 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005007 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005008 }
5009 }
5010
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005011 public void setStrictModeVisualIndicatorPreference(String value) {
5012 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5013 }
5014
Dianne Hackbornd2835932010-12-13 16:28:46 -08005015 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005016 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5017 "screenshotApplications()")) {
5018 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5019 }
5020
5021 Bitmap rawss;
5022
Dianne Hackbornd2835932010-12-13 16:28:46 -08005023 int maxLayer = 0;
5024 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005025 final Rect frame = new Rect();
5026
5027 float scale;
5028 int sw, sh, dw, dh;
5029 int rot;
5030
5031 synchronized(mWindowMap) {
5032 long ident = Binder.clearCallingIdentity();
5033
5034 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5035 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5036 + TYPE_LAYER_OFFSET;
5037 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5038
5039 // Figure out the part of the screen that is actually the app.
5040 for (int i=0; i<mWindows.size(); i++) {
5041 WindowState ws = mWindows.get(i);
5042 if (ws.mSurface == null) {
5043 continue;
5044 }
5045 if (ws.mLayer >= aboveAppLayer) {
5046 break;
5047 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005048 if (appToken != null && (ws.mAppToken == null
5049 || ws.mAppToken.token != appToken)) {
5050 continue;
5051 }
5052 if (maxLayer < ws.mAnimLayer) {
5053 maxLayer = ws.mAnimLayer;
5054 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005055 final Rect wf = ws.mFrame;
5056 final Rect cr = ws.mContentInsets;
5057 int left = wf.left + cr.left;
5058 int top = wf.top + cr.top;
5059 int right = wf.right - cr.right;
5060 int bottom = wf.bottom - cr.bottom;
5061 frame.union(left, top, right, bottom);
5062 }
5063 Binder.restoreCallingIdentity(ident);
5064
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005065 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005066 return null;
5067 }
5068
5069 // The screenshot API does not apply the current screen rotation.
5070 rot = mDisplay.getRotation();
5071 int fw = frame.width();
5072 int fh = frame.height();
5073
5074 // First try reducing to fit in x dimension.
5075 scale = maxWidth/(float)fw;
5076 sw = maxWidth;
5077 sh = (int)(fh*scale);
5078 if (sh > maxHeight) {
5079 // y dimension became too long; constrain by that.
5080 scale = maxHeight/(float)fh;
5081 sw = (int)(fw*scale);
5082 sh = maxHeight;
5083 }
5084
5085 // The screen shot will contain the entire screen.
5086 dw = (int)(mDisplay.getWidth()*scale);
5087 dh = (int)(mDisplay.getHeight()*scale);
5088 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5089 int tmp = dw;
5090 dw = dh;
5091 dh = tmp;
5092 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5093 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005094 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005095 }
5096
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005097 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005098 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5099 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005100 return null;
5101 }
5102
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005103 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5104 Matrix matrix = new Matrix();
5105 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5106 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5107 Canvas canvas = new Canvas(bm);
5108 canvas.drawBitmap(rawss, matrix, null);
5109
5110 rawss.recycle();
5111 return bm;
5112 }
5113
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005114 public void freezeRotation() {
5115 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5116 "setRotation()")) {
5117 throw new SecurityException("Requires SET_ORIENTATION permission");
5118 }
5119
5120 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5121 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5122 }
5123
5124 public void thawRotation() {
5125 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5126 "setRotation()")) {
5127 throw new SecurityException("Requires SET_ORIENTATION permission");
5128 }
5129
5130 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5131 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5132 }
5133
Romain Guy06882f82009-06-10 13:36:04 -07005134 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005135 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005137 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005138 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005139 }
5140
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005141 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005142 }
Romain Guy06882f82009-06-10 13:36:04 -07005143
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005144 public void setRotationUnchecked(int rotation,
5145 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005146 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005147 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005149 long origId = Binder.clearCallingIdentity();
5150 boolean changed;
5151 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005152 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005153 }
Romain Guy06882f82009-06-10 13:36:04 -07005154
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005155 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156 sendNewConfiguration();
5157 }
Romain Guy06882f82009-06-10 13:36:04 -07005158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005159 Binder.restoreCallingIdentity(origId);
5160 }
Romain Guy06882f82009-06-10 13:36:04 -07005161
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005162 /**
5163 * Apply a new rotation to the screen, respecting the requests of
5164 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5165 * re-evaluate the desired rotation.
5166 *
5167 * Returns null if the rotation has been changed. In this case YOU
5168 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5169 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005170 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005171 if (mDragState != null) {
5172 // Potential rotation during a drag. Don't do the rotation now, but make
5173 // a note to perform the rotation later.
5174 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation during drag");
5175 mDragState.setDeferredRotation(rotation, animFlags);
5176 return false;
5177 }
5178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 boolean changed;
5180 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
5181 rotation = mRequestedRotation;
5182 } else {
5183 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005184 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08005186 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005187 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005188 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005189 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005190 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005192 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005193 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005194 "Rotation changed to " + rotation
5195 + " from " + mRotation
5196 + " (forceApp=" + mForcedAppOrientation
5197 + ", req=" + mRequestedRotation + ")");
5198 mRotation = rotation;
5199 mWindowsFreezingScreen = true;
5200 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5201 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5202 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005203 mWaitingForConfig = true;
5204 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005205 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005206 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005207 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005208 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005209 if (CUSTOM_SCREEN_ROTATION) {
5210 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005211 if (!inTransaction) {
5212 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5213 ">>> OPEN TRANSACTION setRotationUnchecked");
5214 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005215 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005216 try {
5217 if (mScreenRotationAnimation != null) {
5218 mScreenRotationAnimation.setRotation(rotation);
5219 }
5220 } finally {
5221 if (!inTransaction) {
5222 Surface.closeTransaction();
5223 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5224 "<<< CLOSE TRANSACTION setRotationUnchecked");
5225 }
5226 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005227 Surface.setOrientation(0, rotation, animFlags);
5228 Surface.unfreezeDisplay(0);
5229 } else {
5230 Surface.setOrientation(0, rotation, animFlags);
5231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005232 }
5233 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005234 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005235 if (w.mSurface != null) {
5236 w.mOrientationChanging = true;
5237 }
5238 }
5239 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5240 try {
5241 mRotationWatchers.get(i).onRotationChanged(rotation);
5242 } catch (RemoteException e) {
5243 }
5244 }
5245 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005247 return changed;
5248 }
Romain Guy06882f82009-06-10 13:36:04 -07005249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005250 public int getRotation() {
5251 return mRotation;
5252 }
5253
5254 public int watchRotation(IRotationWatcher watcher) {
5255 final IBinder watcherBinder = watcher.asBinder();
5256 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5257 public void binderDied() {
5258 synchronized (mWindowMap) {
5259 for (int i=0; i<mRotationWatchers.size(); i++) {
5260 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005261 IRotationWatcher removed = mRotationWatchers.remove(i);
5262 if (removed != null) {
5263 removed.asBinder().unlinkToDeath(this, 0);
5264 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005265 i--;
5266 }
5267 }
5268 }
5269 }
5270 };
Romain Guy06882f82009-06-10 13:36:04 -07005271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005272 synchronized (mWindowMap) {
5273 try {
5274 watcher.asBinder().linkToDeath(dr, 0);
5275 mRotationWatchers.add(watcher);
5276 } catch (RemoteException e) {
5277 // Client died, no cleanup needed.
5278 }
Romain Guy06882f82009-06-10 13:36:04 -07005279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005280 return mRotation;
5281 }
5282 }
5283
5284 /**
5285 * Starts the view server on the specified port.
5286 *
5287 * @param port The port to listener to.
5288 *
5289 * @return True if the server was successfully started, false otherwise.
5290 *
5291 * @see com.android.server.ViewServer
5292 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5293 */
5294 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005295 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005296 return false;
5297 }
5298
5299 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5300 return false;
5301 }
5302
5303 if (port < 1024) {
5304 return false;
5305 }
5306
5307 if (mViewServer != null) {
5308 if (!mViewServer.isRunning()) {
5309 try {
5310 return mViewServer.start();
5311 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005312 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 }
5314 }
5315 return false;
5316 }
5317
5318 try {
5319 mViewServer = new ViewServer(this, port);
5320 return mViewServer.start();
5321 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005322 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 }
5324 return false;
5325 }
5326
Romain Guy06882f82009-06-10 13:36:04 -07005327 private boolean isSystemSecure() {
5328 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5329 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5330 }
5331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005332 /**
5333 * Stops the view server if it exists.
5334 *
5335 * @return True if the server stopped, false if it wasn't started or
5336 * couldn't be stopped.
5337 *
5338 * @see com.android.server.ViewServer
5339 */
5340 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005341 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005342 return false;
5343 }
5344
5345 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5346 return false;
5347 }
5348
5349 if (mViewServer != null) {
5350 return mViewServer.stop();
5351 }
5352 return false;
5353 }
5354
5355 /**
5356 * Indicates whether the view server is running.
5357 *
5358 * @return True if the server is running, false otherwise.
5359 *
5360 * @see com.android.server.ViewServer
5361 */
5362 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005363 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005364 return false;
5365 }
5366
5367 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5368 return false;
5369 }
5370
5371 return mViewServer != null && mViewServer.isRunning();
5372 }
5373
5374 /**
5375 * Lists all availble windows in the system. The listing is written in the
5376 * specified Socket's output stream with the following syntax:
5377 * windowHashCodeInHexadecimal windowName
5378 * Each line of the ouput represents a different window.
5379 *
5380 * @param client The remote client to send the listing to.
5381 * @return False if an error occured, true otherwise.
5382 */
5383 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005384 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 return false;
5386 }
5387
5388 boolean result = true;
5389
Jeff Browne33348b2010-07-15 23:54:05 -07005390 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005391 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005392 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005393 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005394 }
5395
5396 BufferedWriter out = null;
5397
5398 // Any uncaught exception will crash the system process
5399 try {
5400 OutputStream clientStream = client.getOutputStream();
5401 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5402
5403 final int count = windows.length;
5404 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005405 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005406 out.write(Integer.toHexString(System.identityHashCode(w)));
5407 out.write(' ');
5408 out.append(w.mAttrs.getTitle());
5409 out.write('\n');
5410 }
5411
5412 out.write("DONE.\n");
5413 out.flush();
5414 } catch (Exception e) {
5415 result = false;
5416 } finally {
5417 if (out != null) {
5418 try {
5419 out.close();
5420 } catch (IOException e) {
5421 result = false;
5422 }
5423 }
5424 }
5425
5426 return result;
5427 }
5428
5429 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005430 * Returns the focused window in the following format:
5431 * windowHashCodeInHexadecimal windowName
5432 *
5433 * @param client The remote client to send the listing to.
5434 * @return False if an error occurred, true otherwise.
5435 */
5436 boolean viewServerGetFocusedWindow(Socket client) {
5437 if (isSystemSecure()) {
5438 return false;
5439 }
5440
5441 boolean result = true;
5442
5443 WindowState focusedWindow = getFocusedWindow();
5444
5445 BufferedWriter out = null;
5446
5447 // Any uncaught exception will crash the system process
5448 try {
5449 OutputStream clientStream = client.getOutputStream();
5450 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5451
5452 if(focusedWindow != null) {
5453 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5454 out.write(' ');
5455 out.append(focusedWindow.mAttrs.getTitle());
5456 }
5457 out.write('\n');
5458 out.flush();
5459 } catch (Exception e) {
5460 result = false;
5461 } finally {
5462 if (out != null) {
5463 try {
5464 out.close();
5465 } catch (IOException e) {
5466 result = false;
5467 }
5468 }
5469 }
5470
5471 return result;
5472 }
5473
5474 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005475 * Sends a command to a target window. The result of the command, if any, will be
5476 * written in the output stream of the specified socket.
5477 *
5478 * The parameters must follow this syntax:
5479 * windowHashcode extra
5480 *
5481 * Where XX is the length in characeters of the windowTitle.
5482 *
5483 * The first parameter is the target window. The window with the specified hashcode
5484 * will be the target. If no target can be found, nothing happens. The extra parameters
5485 * will be delivered to the target window and as parameters to the command itself.
5486 *
5487 * @param client The remote client to sent the result, if any, to.
5488 * @param command The command to execute.
5489 * @param parameters The command parameters.
5490 *
5491 * @return True if the command was successfully delivered, false otherwise. This does
5492 * not indicate whether the command itself was successful.
5493 */
5494 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005495 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 return false;
5497 }
5498
5499 boolean success = true;
5500 Parcel data = null;
5501 Parcel reply = null;
5502
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005503 BufferedWriter out = null;
5504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005505 // Any uncaught exception will crash the system process
5506 try {
5507 // Find the hashcode of the window
5508 int index = parameters.indexOf(' ');
5509 if (index == -1) {
5510 index = parameters.length();
5511 }
5512 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005513 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005514
5515 // Extract the command's parameter after the window description
5516 if (index < parameters.length()) {
5517 parameters = parameters.substring(index + 1);
5518 } else {
5519 parameters = "";
5520 }
5521
5522 final WindowManagerService.WindowState window = findWindow(hashCode);
5523 if (window == null) {
5524 return false;
5525 }
5526
5527 data = Parcel.obtain();
5528 data.writeInterfaceToken("android.view.IWindow");
5529 data.writeString(command);
5530 data.writeString(parameters);
5531 data.writeInt(1);
5532 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5533
5534 reply = Parcel.obtain();
5535
5536 final IBinder binder = window.mClient.asBinder();
5537 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5538 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5539
5540 reply.readException();
5541
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005542 if (!client.isOutputShutdown()) {
5543 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5544 out.write("DONE\n");
5545 out.flush();
5546 }
5547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005548 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005549 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005550 success = false;
5551 } finally {
5552 if (data != null) {
5553 data.recycle();
5554 }
5555 if (reply != null) {
5556 reply.recycle();
5557 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005558 if (out != null) {
5559 try {
5560 out.close();
5561 } catch (IOException e) {
5562
5563 }
5564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005565 }
5566
5567 return success;
5568 }
5569
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005570 public void addWindowChangeListener(WindowChangeListener listener) {
5571 synchronized(mWindowMap) {
5572 mWindowChangeListeners.add(listener);
5573 }
5574 }
5575
5576 public void removeWindowChangeListener(WindowChangeListener listener) {
5577 synchronized(mWindowMap) {
5578 mWindowChangeListeners.remove(listener);
5579 }
5580 }
5581
5582 private void notifyWindowsChanged() {
5583 WindowChangeListener[] windowChangeListeners;
5584 synchronized(mWindowMap) {
5585 if(mWindowChangeListeners.isEmpty()) {
5586 return;
5587 }
5588 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5589 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5590 }
5591 int N = windowChangeListeners.length;
5592 for(int i = 0; i < N; i++) {
5593 windowChangeListeners[i].windowsChanged();
5594 }
5595 }
5596
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005597 private void notifyFocusChanged() {
5598 WindowChangeListener[] windowChangeListeners;
5599 synchronized(mWindowMap) {
5600 if(mWindowChangeListeners.isEmpty()) {
5601 return;
5602 }
5603 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5604 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5605 }
5606 int N = windowChangeListeners.length;
5607 for(int i = 0; i < N; i++) {
5608 windowChangeListeners[i].focusChanged();
5609 }
5610 }
5611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005612 private WindowState findWindow(int hashCode) {
5613 if (hashCode == -1) {
5614 return getFocusedWindow();
5615 }
5616
5617 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005618 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005619 final int count = windows.size();
5620
5621 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005622 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005623 if (System.identityHashCode(w) == hashCode) {
5624 return w;
5625 }
5626 }
5627 }
5628
5629 return null;
5630 }
5631
5632 /*
5633 * Instruct the Activity Manager to fetch the current configuration and broadcast
5634 * that to config-changed listeners if appropriate.
5635 */
5636 void sendNewConfiguration() {
5637 try {
5638 mActivityManager.updateConfiguration(null);
5639 } catch (RemoteException e) {
5640 }
5641 }
Romain Guy06882f82009-06-10 13:36:04 -07005642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005643 public Configuration computeNewConfiguration() {
5644 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005645 Configuration config = computeNewConfigurationLocked();
5646 if (config == null && mWaitingForConfig) {
5647 // Nothing changed but we are waiting for something... stop that!
5648 mWaitingForConfig = false;
5649 performLayoutAndPlaceSurfacesLocked();
5650 }
5651 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005652 }
5653 }
Romain Guy06882f82009-06-10 13:36:04 -07005654
Dianne Hackbornc485a602009-03-24 22:39:49 -07005655 Configuration computeNewConfigurationLocked() {
5656 Configuration config = new Configuration();
5657 if (!computeNewConfigurationLocked(config)) {
5658 return null;
5659 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005660 return config;
5661 }
Romain Guy06882f82009-06-10 13:36:04 -07005662
Dianne Hackbornc485a602009-03-24 22:39:49 -07005663 boolean computeNewConfigurationLocked(Configuration config) {
5664 if (mDisplay == null) {
5665 return false;
5666 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005667
5668 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005669
5670 // Use the effective "visual" dimensions based on current rotation
5671 final boolean rotated = (mRotation == Surface.ROTATION_90
5672 || mRotation == Surface.ROTATION_270);
5673 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5674 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5675
Dianne Hackbornc485a602009-03-24 22:39:49 -07005676 int orientation = Configuration.ORIENTATION_SQUARE;
5677 if (dw < dh) {
5678 orientation = Configuration.ORIENTATION_PORTRAIT;
5679 } else if (dw > dh) {
5680 orientation = Configuration.ORIENTATION_LANDSCAPE;
5681 }
5682 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005683
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005684 DisplayMetrics dm = new DisplayMetrics();
5685 mDisplay.getMetrics(dm);
5686 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5687
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005688 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005689 // Note we only do this once because at this point we don't
5690 // expect the screen to change in this way at runtime, and want
5691 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005692 int longSize = dw;
5693 int shortSize = dh;
5694 if (longSize < shortSize) {
5695 int tmp = longSize;
5696 longSize = shortSize;
5697 shortSize = tmp;
5698 }
5699 longSize = (int)(longSize/dm.density);
5700 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005701
Dianne Hackborn723738c2009-06-25 19:48:04 -07005702 // These semi-magic numbers define our compatibility modes for
5703 // applications with different screens. Don't change unless you
5704 // make sure to test lots and lots of apps!
5705 if (longSize < 470) {
5706 // This is shorter than an HVGA normal density screen (which
5707 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005708 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5709 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005710 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005711 // What size is this screen screen?
5712 if (longSize >= 800 && shortSize >= 600) {
5713 // SVGA or larger screens at medium density are the point
5714 // at which we consider it to be an extra large screen.
5715 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005716 } else if (longSize >= 530 && shortSize >= 400) {
5717 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005718 // at which we consider it to be a large screen.
5719 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5720 } else {
5721 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005722
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005723 // If this screen is wider than normal HVGA, or taller
5724 // than FWVGA, then for old apps we want to run in size
5725 // compatibility mode.
5726 if (shortSize > 321 || longSize > 570) {
5727 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5728 }
5729 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005730
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005731 // Is this a long screen?
5732 if (((longSize*3)/5) >= (shortSize-1)) {
5733 // Anything wider than WVGA (5:3) is considering to be long.
5734 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5735 } else {
5736 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5737 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005738 }
5739 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005740 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005741
Dianne Hackbornc485a602009-03-24 22:39:49 -07005742 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5743 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5744 mPolicy.adjustConfigurationLw(config);
5745 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005746 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005747
5748 // -------------------------------------------------------------
5749 // Drag and drop
5750 // -------------------------------------------------------------
5751
5752 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005753 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005754 if (DEBUG_DRAG) {
5755 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005756 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005757 + " asbinder=" + window.asBinder());
5758 }
5759
5760 final int callerPid = Binder.getCallingPid();
5761 final long origId = Binder.clearCallingIdentity();
5762 IBinder token = null;
5763
5764 try {
5765 synchronized (mWindowMap) {
5766 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005767 if (mDragState == null) {
5768 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5769 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5770 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005771 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005772 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005773 // TODO: preserve flags param in DragState
5774 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005775 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005776 token = mDragState.mToken = new Binder();
5777
5778 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005779 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5780 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005781 mH.sendMessageDelayed(msg, 5000);
5782 } else {
5783 Slog.w(TAG, "Drag already in progress");
5784 }
5785 } catch (Surface.OutOfResourcesException e) {
5786 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5787 if (mDragState != null) {
5788 mDragState.reset();
5789 mDragState = null;
5790 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005791 }
5792 }
5793 } finally {
5794 Binder.restoreCallingIdentity(origId);
5795 }
5796
5797 return token;
5798 }
5799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005800 // -------------------------------------------------------------
5801 // Input Events and Focus Management
5802 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005803
Jeff Brown349703e2010-06-22 01:27:15 -07005804 InputMonitor mInputMonitor = new InputMonitor();
5805
5806 /* Tracks the progress of input dispatch and ensures that input dispatch state
5807 * is kept in sync with changes in window focus, visibility, registration, and
5808 * other relevant Window Manager state transitions. */
5809 final class InputMonitor {
5810 // Current window with input focus for keys and other non-touch events. May be null.
5811 private WindowState mInputFocus;
5812
5813 // When true, prevents input dispatch from proceeding until set to false again.
5814 private boolean mInputDispatchFrozen;
5815
5816 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5817 private boolean mInputDispatchEnabled = true;
5818
Jeff Brown3a22cd92011-01-21 13:59:04 -08005819 // When true, need to call updateInputWindowsLw().
5820 private boolean mUpdateInputWindowsNeeded = true;
5821
Jeff Brown349703e2010-06-22 01:27:15 -07005822 // Temporary list of windows information to provide to the input dispatcher.
5823 private InputWindowList mTempInputWindows = new InputWindowList();
5824
5825 // Temporary input application object to provide to the input dispatcher.
5826 private InputApplication mTempInputApplication = new InputApplication();
5827
Jeff Brownb09abc12011-01-13 21:08:27 -08005828 // Set to true when the first input device configuration change notification
5829 // is received to indicate that the input devices are ready.
5830 private final Object mInputDevicesReadyMonitor = new Object();
5831 private boolean mInputDevicesReady;
5832
Jeff Brown349703e2010-06-22 01:27:15 -07005833 /* Notifies the window manager about a broken input channel.
5834 *
5835 * Called by the InputManager.
5836 */
Jeff Brown928e0542011-01-10 11:17:36 -08005837 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5838 if (inputWindowHandle == null) {
5839 return;
5840 }
5841
Jeff Brown349703e2010-06-22 01:27:15 -07005842 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005843 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005844 Slog.i(TAG, "WINDOW DIED " + windowState);
5845 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005846 }
5847 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005848
Jeff Brown519e0242010-09-15 15:18:56 -07005849 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005850 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005851 *
5852 * Called by the InputManager.
5853 */
Jeff Brown928e0542011-01-10 11:17:36 -08005854 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5855 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005856 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005857 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005858 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005859 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005860 if (windowState != null) {
5861 Slog.i(TAG, "Input event dispatching timed out sending to "
5862 + windowState.mAttrs.getTitle());
5863 appWindowToken = windowState.mAppToken;
5864 }
Jeff Brown349703e2010-06-22 01:27:15 -07005865 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005866 }
5867
Jeff Brown928e0542011-01-10 11:17:36 -08005868 if (appWindowToken == null && inputApplicationHandle != null) {
5869 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005870 Slog.i(TAG, "Input event dispatching timed out sending to application "
5871 + appWindowToken.stringName);
5872 }
Jeff Brown349703e2010-06-22 01:27:15 -07005873
Jeff Brown519e0242010-09-15 15:18:56 -07005874 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005875 try {
5876 // Notify the activity manager about the timeout and let it decide whether
5877 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005878 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005879 if (! abort) {
5880 // The activity manager declined to abort dispatching.
5881 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005882 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005883 }
Jeff Brown349703e2010-06-22 01:27:15 -07005884 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005885 }
5886 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005887 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005888 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005889
Chris Tatea32dcf72010-10-14 12:13:50 -07005890 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005891 final InputWindow inputWindow = windowList.add();
5892 inputWindow.inputChannel = mDragState.mServerChannel;
5893 inputWindow.name = "drag";
Jeff Brownfbf09772011-01-16 14:06:57 -08005894 inputWindow.layoutParamsFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Christopher Tatea53146c2010-09-07 11:57:52 -07005895 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5896 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5897 inputWindow.visible = true;
5898 inputWindow.canReceiveKeys = false;
5899 inputWindow.hasFocus = true;
5900 inputWindow.hasWallpaper = false;
5901 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005902 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005903 inputWindow.ownerPid = Process.myPid();
5904 inputWindow.ownerUid = Process.myUid();
5905
5906 // The drag window covers the entire display
5907 inputWindow.frameLeft = 0;
5908 inputWindow.frameTop = 0;
5909 inputWindow.frameRight = mDisplay.getWidth();
5910 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005911
Jeff Brownfbf09772011-01-16 14:06:57 -08005912 // The drag window cannot receive new touches.
5913 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07005914 }
5915
Jeff Brown3a22cd92011-01-21 13:59:04 -08005916 public void setUpdateInputWindowsNeededLw() {
5917 mUpdateInputWindowsNeeded = true;
5918 }
5919
Jeff Brown349703e2010-06-22 01:27:15 -07005920 /* Updates the cached window information provided to the input dispatcher. */
5921 public void updateInputWindowsLw() {
Jeff Brown3a22cd92011-01-21 13:59:04 -08005922 if (!mUpdateInputWindowsNeeded) {
5923 return;
5924 }
5925 mUpdateInputWindowsNeeded = false;
5926
Jeff Brown349703e2010-06-22 01:27:15 -07005927 // Populate the input window list with information about all of the windows that
5928 // could potentially receive input.
5929 // As an optimization, we could try to prune the list of windows but this turns
5930 // out to be difficult because only the native code knows for sure which window
5931 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005932 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005933
5934 // If there's a drag in flight, provide a pseudowindow to catch drag input
5935 final boolean inDrag = (mDragState != null);
5936 if (inDrag) {
5937 if (DEBUG_DRAG) {
5938 Log.d(TAG, "Inserting drag window");
5939 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005940 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005941 }
5942
Jeff Brown7fbdc842010-06-17 20:52:56 -07005943 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005944 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005945 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005946 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005947 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005948 continue;
5949 }
5950
Jeff Brown349703e2010-06-22 01:27:15 -07005951 final int flags = child.mAttrs.flags;
5952 final int type = child.mAttrs.type;
5953
5954 final boolean hasFocus = (child == mInputFocus);
5955 final boolean isVisible = child.isVisibleLw();
5956 final boolean hasWallpaper = (child == mWallpaperTarget)
5957 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005958
5959 // If there's a drag in progress and 'child' is a potential drop target,
5960 // make sure it's been told about the drag
5961 if (inDrag && isVisible) {
5962 mDragState.sendDragStartedIfNeededLw(child);
5963 }
5964
Jeff Brown349703e2010-06-22 01:27:15 -07005965 // Add a window to our list of input windows.
5966 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005967 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005968 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005969 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005970 inputWindow.layoutParamsFlags = flags;
5971 inputWindow.layoutParamsType = type;
5972 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5973 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005974 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005975 inputWindow.hasFocus = hasFocus;
5976 inputWindow.hasWallpaper = hasWallpaper;
5977 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005978 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005979 inputWindow.ownerPid = child.mSession.mPid;
5980 inputWindow.ownerUid = child.mSession.mUid;
5981
5982 final Rect frame = child.mFrame;
5983 inputWindow.frameLeft = frame.left;
5984 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005985 inputWindow.frameRight = frame.right;
5986 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08005987
5988 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005989 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005990
Jeff Brown349703e2010-06-22 01:27:15 -07005991 // Send windows to native code.
5992 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005993
Jeff Brown349703e2010-06-22 01:27:15 -07005994 // Clear the list in preparation for the next round.
5995 // Also avoids keeping InputChannel objects referenced unnecessarily.
5996 mTempInputWindows.clear();
5997 }
Jeff Brownb09abc12011-01-13 21:08:27 -08005998
5999 /* Notifies that the input device configuration has changed. */
6000 public void notifyConfigurationChanged() {
6001 sendNewConfiguration();
6002
6003 synchronized (mInputDevicesReadyMonitor) {
6004 if (!mInputDevicesReady) {
6005 mInputDevicesReady = true;
6006 mInputDevicesReadyMonitor.notifyAll();
6007 }
6008 }
6009 }
6010
6011 /* Waits until the built-in input devices have been configured. */
6012 public boolean waitForInputDevicesReady(long timeoutMillis) {
6013 synchronized (mInputDevicesReadyMonitor) {
6014 if (!mInputDevicesReady) {
6015 try {
6016 mInputDevicesReadyMonitor.wait(timeoutMillis);
6017 } catch (InterruptedException ex) {
6018 }
6019 }
6020 return mInputDevicesReady;
6021 }
6022 }
6023
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006024 /* Notifies that the lid switch changed state. */
6025 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6026 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6027 }
6028
Jeff Brown349703e2010-06-22 01:27:15 -07006029 /* Provides an opportunity for the window manager policy to intercept early key
6030 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006031 public int interceptKeyBeforeQueueing(
6032 KeyEvent event, int policyFlags, boolean isScreenOn) {
6033 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006034 }
6035
6036 /* Provides an opportunity for the window manager policy to process a key before
6037 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006038 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006039 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006040 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006041 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006042 }
6043
Jeff Brown3915bb82010-11-05 15:02:16 -07006044 /* Provides an opportunity for the window manager policy to process a key that
6045 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006046 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006047 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006048 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006049 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006050 }
6051
Jeff Brown349703e2010-06-22 01:27:15 -07006052 /* Called when the current input focus changes.
6053 * Layer assignment is assumed to be complete by the time this is called.
6054 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006055 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006056 if (DEBUG_INPUT) {
6057 Slog.d(TAG, "Input focus has changed to " + newWindow);
6058 }
6059
6060 if (newWindow != mInputFocus) {
6061 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006062 // Displaying a window implicitly causes dispatching to be unpaused.
6063 // This is to protect against bugs if someone pauses dispatching but
6064 // forgets to resume.
6065 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006066 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006067
Jeff Brown349703e2010-06-22 01:27:15 -07006068 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006069 setUpdateInputWindowsNeededLw();
6070
6071 if (updateInputWindows) {
6072 updateInputWindowsLw();
6073 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07006074 }
6075 }
6076
Jeff Brown349703e2010-06-22 01:27:15 -07006077 public void setFocusedAppLw(AppWindowToken newApp) {
6078 // Focused app has changed.
6079 if (newApp == null) {
6080 mInputManager.setFocusedApplication(null);
6081 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006082 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006083 mTempInputApplication.name = newApp.toString();
6084 mTempInputApplication.dispatchingTimeoutNanos =
6085 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006086
Jeff Brown349703e2010-06-22 01:27:15 -07006087 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006088
6089 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006090 }
6091 }
6092
Jeff Brown349703e2010-06-22 01:27:15 -07006093 public void pauseDispatchingLw(WindowToken window) {
6094 if (! window.paused) {
6095 if (DEBUG_INPUT) {
6096 Slog.v(TAG, "Pausing WindowToken " + window);
6097 }
6098
6099 window.paused = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006100 setUpdateInputWindowsNeededLw();
Jeff Brown349703e2010-06-22 01:27:15 -07006101 updateInputWindowsLw();
6102 }
6103 }
6104
6105 public void resumeDispatchingLw(WindowToken window) {
6106 if (window.paused) {
6107 if (DEBUG_INPUT) {
6108 Slog.v(TAG, "Resuming WindowToken " + window);
6109 }
6110
6111 window.paused = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006112 setUpdateInputWindowsNeededLw();
Jeff Brown349703e2010-06-22 01:27:15 -07006113 updateInputWindowsLw();
6114 }
6115 }
6116
6117 public void freezeInputDispatchingLw() {
6118 if (! mInputDispatchFrozen) {
6119 if (DEBUG_INPUT) {
6120 Slog.v(TAG, "Freezing input dispatching");
6121 }
6122
6123 mInputDispatchFrozen = true;
6124 updateInputDispatchModeLw();
6125 }
6126 }
6127
6128 public void thawInputDispatchingLw() {
6129 if (mInputDispatchFrozen) {
6130 if (DEBUG_INPUT) {
6131 Slog.v(TAG, "Thawing input dispatching");
6132 }
6133
6134 mInputDispatchFrozen = false;
6135 updateInputDispatchModeLw();
6136 }
6137 }
6138
6139 public void setEventDispatchingLw(boolean enabled) {
6140 if (mInputDispatchEnabled != enabled) {
6141 if (DEBUG_INPUT) {
6142 Slog.v(TAG, "Setting event dispatching to " + enabled);
6143 }
6144
6145 mInputDispatchEnabled = enabled;
6146 updateInputDispatchModeLw();
6147 }
6148 }
6149
6150 private void updateInputDispatchModeLw() {
6151 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6152 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07006153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 public void pauseKeyDispatching(IBinder _token) {
6156 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6157 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006158 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 }
6160
6161 synchronized (mWindowMap) {
6162 WindowToken token = mTokenMap.get(_token);
6163 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006164 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006165 }
6166 }
6167 }
6168
6169 public void resumeKeyDispatching(IBinder _token) {
6170 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6171 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006172 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006173 }
6174
6175 synchronized (mWindowMap) {
6176 WindowToken token = mTokenMap.get(_token);
6177 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006178 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006179 }
6180 }
6181 }
6182
6183 public void setEventDispatching(boolean enabled) {
6184 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6185 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006186 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 }
6188
6189 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006190 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 }
6192 }
Romain Guy06882f82009-06-10 13:36:04 -07006193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006194 /**
6195 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006196 * Even when sync is false, this method may block while waiting for current
6197 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006198 *
6199 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 * {@link SystemClock#uptimeMillis()} as the timebase.)
6201 * @param sync If true, wait for the event to be completed before returning to the caller.
6202 * @return Returns true if event was dispatched, false if it was dropped for any reason
6203 */
6204 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6205 long downTime = ev.getDownTime();
6206 long eventTime = ev.getEventTime();
6207
6208 int action = ev.getAction();
6209 int code = ev.getKeyCode();
6210 int repeatCount = ev.getRepeatCount();
6211 int metaState = ev.getMetaState();
6212 int deviceId = ev.getDeviceId();
6213 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006214 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006215 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006216
6217 if (source == InputDevice.SOURCE_UNKNOWN) {
6218 source = InputDevice.SOURCE_KEYBOARD;
6219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006220
6221 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6222 if (downTime == 0) downTime = eventTime;
6223
6224 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006225 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006226
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006227 final int pid = Binder.getCallingPid();
6228 final int uid = Binder.getCallingUid();
6229 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006230
Jeff Brownbbda99d2010-07-28 15:48:59 -07006231 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6232 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6233 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6234 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006235
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006236 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006237 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006238 }
6239
6240 /**
6241 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006242 * Even when sync is false, this method may block while waiting for current
6243 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006244 *
6245 * @param ev A motion event describing the pointer (touch) action. (As noted in
6246 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006247 * {@link SystemClock#uptimeMillis()} as the timebase.)
6248 * @param sync If true, wait for the event to be completed before returning to the caller.
6249 * @return Returns true if event was dispatched, false if it was dropped for any reason
6250 */
6251 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006252 final int pid = Binder.getCallingPid();
6253 final int uid = Binder.getCallingUid();
6254 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006255
Jeff Brownc5ed5912010-07-14 18:48:53 -07006256 MotionEvent newEvent = MotionEvent.obtain(ev);
6257 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6258 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6259 }
6260
Jeff Brownbbda99d2010-07-28 15:48:59 -07006261 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6262 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6263 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6264 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006265
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006266 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006267 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 }
Romain Guy06882f82009-06-10 13:36:04 -07006269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270 /**
6271 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006272 * Even when sync is false, this method may block while waiting for current
6273 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006274 *
6275 * @param ev A motion event describing the trackball action. (As noted in
6276 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 * {@link SystemClock#uptimeMillis()} as the timebase.)
6278 * @param sync If true, wait for the event to be completed before returning to the caller.
6279 * @return Returns true if event was dispatched, false if it was dropped for any reason
6280 */
6281 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006282 final int pid = Binder.getCallingPid();
6283 final int uid = Binder.getCallingUid();
6284 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006285
Jeff Brownc5ed5912010-07-14 18:48:53 -07006286 MotionEvent newEvent = MotionEvent.obtain(ev);
6287 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6288 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6289 }
6290
Jeff Brownbbda99d2010-07-28 15:48:59 -07006291 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6292 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6293 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6294 INJECTION_TIMEOUT_MILLIS);
6295
6296 Binder.restoreCallingIdentity(ident);
6297 return reportInjectionResult(result);
6298 }
6299
6300 /**
6301 * Inject an input event into the UI without waiting for dispatch to commence.
6302 * This variant is useful for fire-and-forget input event injection. It does not
6303 * block any longer than it takes to enqueue the input event.
6304 *
6305 * @param ev An input event. (Be sure to set the input source correctly.)
6306 * @return Returns true if event was dispatched, false if it was dropped for any reason
6307 */
6308 public boolean injectInputEventNoWait(InputEvent ev) {
6309 final int pid = Binder.getCallingPid();
6310 final int uid = Binder.getCallingUid();
6311 final long ident = Binder.clearCallingIdentity();
6312
6313 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6314 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6315 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006316
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006317 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006318 return reportInjectionResult(result);
6319 }
6320
6321 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006322 switch (result) {
6323 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6324 Slog.w(TAG, "Input event injection permission denied.");
6325 throw new SecurityException(
6326 "Injecting to another application requires INJECT_EVENTS permission");
6327 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006328 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006329 return true;
6330 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6331 Slog.w(TAG, "Input event injection timed out.");
6332 return false;
6333 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6334 default:
6335 Slog.w(TAG, "Input event injection failed.");
6336 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006337 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 }
Romain Guy06882f82009-06-10 13:36:04 -07006339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006340 private WindowState getFocusedWindow() {
6341 synchronized (mWindowMap) {
6342 return getFocusedWindowLocked();
6343 }
6344 }
6345
6346 private WindowState getFocusedWindowLocked() {
6347 return mCurrentFocus;
6348 }
Romain Guy06882f82009-06-10 13:36:04 -07006349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006351 if (!mInputMonitor.waitForInputDevicesReady(
6352 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6353 Slog.w(TAG, "Devices still not ready after waiting "
6354 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6355 + " milliseconds before attempting to detect safe mode.");
6356 }
6357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006358 mSafeMode = mPolicy.detectSafeMode();
6359 return mSafeMode;
6360 }
Romain Guy06882f82009-06-10 13:36:04 -07006361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006362 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006363 synchronized(mWindowMap) {
6364 if (mDisplay != null) {
6365 throw new IllegalStateException("Display already initialized");
6366 }
6367 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6368 mDisplay = wm.getDefaultDisplay();
6369 mInitialDisplayWidth = mDisplay.getWidth();
6370 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006371 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6372 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006373 }
6374
6375 try {
6376 mActivityManager.updateConfiguration(null);
6377 } catch (RemoteException e) {
6378 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006379
6380 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006381 }
6382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 // -------------------------------------------------------------
6384 // Client Session State
6385 // -------------------------------------------------------------
6386
6387 private final class Session extends IWindowSession.Stub
6388 implements IBinder.DeathRecipient {
6389 final IInputMethodClient mClient;
6390 final IInputContext mInputContext;
6391 final int mUid;
6392 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006393 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 SurfaceSession mSurfaceSession;
6395 int mNumWindow = 0;
6396 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 public Session(IInputMethodClient client, IInputContext inputContext) {
6399 mClient = client;
6400 mInputContext = inputContext;
6401 mUid = Binder.getCallingUid();
6402 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006403 StringBuilder sb = new StringBuilder();
6404 sb.append("Session{");
6405 sb.append(Integer.toHexString(System.identityHashCode(this)));
6406 sb.append(" uid ");
6407 sb.append(mUid);
6408 sb.append("}");
6409 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006411 synchronized (mWindowMap) {
6412 if (mInputMethodManager == null && mHaveInputMethods) {
6413 IBinder b = ServiceManager.getService(
6414 Context.INPUT_METHOD_SERVICE);
6415 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6416 }
6417 }
6418 long ident = Binder.clearCallingIdentity();
6419 try {
6420 // Note: it is safe to call in to the input method manager
6421 // here because we are not holding our lock.
6422 if (mInputMethodManager != null) {
6423 mInputMethodManager.addClient(client, inputContext,
6424 mUid, mPid);
6425 } else {
6426 client.setUsingInputMethod(false);
6427 }
6428 client.asBinder().linkToDeath(this, 0);
6429 } catch (RemoteException e) {
6430 // The caller has died, so we can just forget about this.
6431 try {
6432 if (mInputMethodManager != null) {
6433 mInputMethodManager.removeClient(client);
6434 }
6435 } catch (RemoteException ee) {
6436 }
6437 } finally {
6438 Binder.restoreCallingIdentity(ident);
6439 }
6440 }
Romain Guy06882f82009-06-10 13:36:04 -07006441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 @Override
6443 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6444 throws RemoteException {
6445 try {
6446 return super.onTransact(code, data, reply, flags);
6447 } catch (RuntimeException e) {
6448 // Log all 'real' exceptions thrown to the caller
6449 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006450 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 }
6452 throw e;
6453 }
6454 }
6455
6456 public void binderDied() {
6457 // Note: it is safe to call in to the input method manager
6458 // here because we are not holding our lock.
6459 try {
6460 if (mInputMethodManager != null) {
6461 mInputMethodManager.removeClient(mClient);
6462 }
6463 } catch (RemoteException e) {
6464 }
6465 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006466 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 mClientDead = true;
6468 killSessionLocked();
6469 }
6470 }
6471
6472 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006473 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6474 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6475 outInputChannel);
6476 }
6477
6478 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006479 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006480 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 }
Romain Guy06882f82009-06-10 13:36:04 -07006482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 public void remove(IWindow window) {
6484 removeWindow(this, window);
6485 }
Romain Guy06882f82009-06-10 13:36:04 -07006486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6488 int requestedWidth, int requestedHeight, int viewFlags,
6489 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006490 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006491 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6492 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006494 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006495 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6496 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006497 }
Romain Guy06882f82009-06-10 13:36:04 -07006498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 public void setTransparentRegion(IWindow window, Region region) {
6500 setTransparentRegionWindow(this, window, region);
6501 }
Romain Guy06882f82009-06-10 13:36:04 -07006502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006504 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006506 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006507 }
Romain Guy06882f82009-06-10 13:36:04 -07006508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006509 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6510 getWindowDisplayFrame(this, window, outDisplayFrame);
6511 }
Romain Guy06882f82009-06-10 13:36:04 -07006512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006514 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 TAG, "IWindow finishDrawing called for " + window);
6516 finishDrawingWindow(this, window);
6517 }
6518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 public void setInTouchMode(boolean mode) {
6520 synchronized(mWindowMap) {
6521 mInTouchMode = mode;
6522 }
6523 }
6524
6525 public boolean getInTouchMode() {
6526 synchronized(mWindowMap) {
6527 return mInTouchMode;
6528 }
6529 }
6530
6531 public boolean performHapticFeedback(IWindow window, int effectId,
6532 boolean always) {
6533 synchronized(mWindowMap) {
6534 long ident = Binder.clearCallingIdentity();
6535 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006536 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006537 windowForClientLocked(this, window, true),
6538 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006539 } finally {
6540 Binder.restoreCallingIdentity(ident);
6541 }
6542 }
6543 }
Romain Guy06882f82009-06-10 13:36:04 -07006544
Christopher Tatea53146c2010-09-07 11:57:52 -07006545 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006546 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006547 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006548 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006549 width, height, outSurface);
6550 }
6551
6552 public boolean performDrag(IWindow window, IBinder dragToken,
6553 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6554 ClipData data) {
6555 if (DEBUG_DRAG) {
6556 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6557 }
6558
6559 synchronized (mWindowMap) {
6560 if (mDragState == null) {
6561 Slog.w(TAG, "No drag prepared");
6562 throw new IllegalStateException("performDrag() without prepareDrag()");
6563 }
6564
6565 if (dragToken != mDragState.mToken) {
6566 Slog.w(TAG, "Performing mismatched drag");
6567 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6568 }
6569
6570 WindowState callingWin = windowForClientLocked(null, window, false);
6571 if (callingWin == null) {
6572 Slog.w(TAG, "Bad requesting window " + window);
6573 return false; // !!! TODO: throw here?
6574 }
6575
6576 // !!! TODO: if input is not still focused on the initiating window, fail
6577 // the drag initiation (e.g. an alarm window popped up just as the application
6578 // called performDrag()
6579
6580 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6581
Christopher Tate2c095f32010-10-04 14:13:40 -07006582 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6583 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006584
Chris Tateb478f462010-10-15 16:02:26 -07006585 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6586 // the actual drag event dispatch stuff in the dragstate
6587
Christopher Tatea53146c2010-09-07 11:57:52 -07006588 mDragState.register();
Jeff Brown3a22cd92011-01-21 13:59:04 -08006589 mInputMonitor.setUpdateInputWindowsNeededLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006590 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006591 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6592 mDragState.mServerChannel)) {
6593 Slog.e(TAG, "Unable to transfer touch focus");
6594 mDragState.unregister();
6595 mDragState = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006596 mInputMonitor.setUpdateInputWindowsNeededLw();
Chris Tateef70a072010-10-22 19:10:34 -07006597 mInputMonitor.updateInputWindowsLw();
6598 return false;
6599 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006600
6601 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006602 mDragState.mCurrentX = touchX;
6603 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006604 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006605
6606 // remember the thumb offsets for later
6607 mDragState.mThumbOffsetX = thumbCenterX;
6608 mDragState.mThumbOffsetY = thumbCenterY;
6609
6610 // Make the surface visible at the proper location
6611 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006612 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006613 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006614 try {
6615 surface.setPosition((int)(touchX - thumbCenterX),
6616 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006617 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006618 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006619 surface.show();
6620 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006621 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006622 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006623 }
6624 }
6625
6626 return true; // success!
6627 }
6628
Chris Tated4533f12010-10-19 15:15:08 -07006629 public void reportDropResult(IWindow window, boolean consumed) {
6630 IBinder token = window.asBinder();
6631 if (DEBUG_DRAG) {
6632 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6633 }
6634
6635 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006636 long ident = Binder.clearCallingIdentity();
6637 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006638 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006639 Slog.w(TAG, "Invalid drop-result claim by " + window);
6640 throw new IllegalStateException("reportDropResult() by non-recipient");
6641 }
6642
6643 // The right window has responded, even if it's no longer around,
6644 // so be sure to halt the timeout even if the later WindowState
6645 // lookup fails.
6646 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6647 WindowState callingWin = windowForClientLocked(null, window, false);
6648 if (callingWin == null) {
6649 Slog.w(TAG, "Bad result-reporting window " + window);
6650 return; // !!! TODO: throw here?
6651 }
6652
6653 mDragState.mDragResult = consumed;
6654 mDragState.endDragLw();
6655 } finally {
6656 Binder.restoreCallingIdentity(ident);
Chris Tated4533f12010-10-19 15:15:08 -07006657 }
Chris Tated4533f12010-10-19 15:15:08 -07006658 }
6659 }
6660
Christopher Tatea53146c2010-09-07 11:57:52 -07006661 public void dragRecipientEntered(IWindow window) {
6662 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006663 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006664 }
6665 }
6666
6667 public void dragRecipientExited(IWindow window) {
6668 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006669 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006670 }
6671 }
6672
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006673 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006674 synchronized(mWindowMap) {
6675 long ident = Binder.clearCallingIdentity();
6676 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006677 setWindowWallpaperPositionLocked(
6678 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006679 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006680 } finally {
6681 Binder.restoreCallingIdentity(ident);
6682 }
6683 }
6684 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006685
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006686 public void wallpaperOffsetsComplete(IBinder window) {
6687 WindowManagerService.this.wallpaperOffsetsComplete(window);
6688 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006689
Dianne Hackborn75804932009-10-20 20:15:20 -07006690 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6691 int z, Bundle extras, boolean sync) {
6692 synchronized(mWindowMap) {
6693 long ident = Binder.clearCallingIdentity();
6694 try {
6695 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006696 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006697 action, x, y, z, extras, sync);
6698 } finally {
6699 Binder.restoreCallingIdentity(ident);
6700 }
6701 }
6702 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006703
Dianne Hackborn75804932009-10-20 20:15:20 -07006704 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6705 WindowManagerService.this.wallpaperCommandComplete(window, result);
6706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006708 void windowAddedLocked() {
6709 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006710 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006711 TAG, "First window added to " + this + ", creating SurfaceSession");
6712 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006713 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006714 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 mSessions.add(this);
6716 }
6717 mNumWindow++;
6718 }
6719
6720 void windowRemovedLocked() {
6721 mNumWindow--;
6722 killSessionLocked();
6723 }
Romain Guy06882f82009-06-10 13:36:04 -07006724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 void killSessionLocked() {
6726 if (mNumWindow <= 0 && mClientDead) {
6727 mSessions.remove(this);
6728 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006729 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006730 TAG, "Last window removed from " + this
6731 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006732 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006733 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 try {
6735 mSurfaceSession.kill();
6736 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006737 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 + mSurfaceSession + " in session " + this
6739 + ": " + e.toString());
6740 }
6741 mSurfaceSession = null;
6742 }
6743 }
6744 }
Romain Guy06882f82009-06-10 13:36:04 -07006745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006746 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006747 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6748 pw.print(" mClientDead="); pw.print(mClientDead);
6749 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 }
6751
6752 @Override
6753 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006754 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 }
6756 }
6757
6758 // -------------------------------------------------------------
6759 // Client Window State
6760 // -------------------------------------------------------------
6761
6762 private final class WindowState implements WindowManagerPolicy.WindowState {
6763 final Session mSession;
6764 final IWindow mClient;
6765 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006766 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 AppWindowToken mAppToken;
6768 AppWindowToken mTargetAppToken;
6769 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6770 final DeathRecipient mDeathRecipient;
6771 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006772 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 final int mBaseLayer;
6774 final int mSubLayer;
6775 final boolean mLayoutAttached;
6776 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006777 final boolean mIsWallpaper;
6778 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 int mViewVisibility;
6780 boolean mPolicyVisibility = true;
6781 boolean mPolicyVisibilityAfterAnim = true;
6782 boolean mAppFreezing;
6783 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006784 boolean mReportDestroySurface;
6785 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006786 boolean mAttachedHidden; // is our parent window hidden?
6787 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006788 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 int mRequestedWidth;
6790 int mRequestedHeight;
6791 int mLastRequestedWidth;
6792 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006793 int mLayer;
6794 int mAnimLayer;
6795 int mLastLayer;
6796 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006797 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006798 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006799
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006800 int mLayoutSeq = -1;
6801
6802 Configuration mConfiguration = null;
6803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006804 // Actual frame shown on-screen (may be modified by animation)
6805 final Rect mShownFrame = new Rect();
6806 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006808 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006809 * Set when we have changed the size of the surface, to know that
6810 * we must tell them application to resize (and thus redraw itself).
6811 */
6812 boolean mSurfaceResized;
6813
6814 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006815 * Insets that determine the actually visible area
6816 */
6817 final Rect mVisibleInsets = new Rect();
6818 final Rect mLastVisibleInsets = new Rect();
6819 boolean mVisibleInsetsChanged;
6820
6821 /**
6822 * Insets that are covered by system windows
6823 */
6824 final Rect mContentInsets = new Rect();
6825 final Rect mLastContentInsets = new Rect();
6826 boolean mContentInsetsChanged;
6827
6828 /**
6829 * Set to true if we are waiting for this window to receive its
6830 * given internal insets before laying out other windows based on it.
6831 */
6832 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 /**
6835 * These are the content insets that were given during layout for
6836 * this window, to be applied to windows behind it.
6837 */
6838 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 /**
6841 * These are the visible insets that were given during layout for
6842 * this window, to be applied to windows behind it.
6843 */
6844 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006847 * This is the given touchable area relative to the window frame, or null if none.
6848 */
6849 final Region mGivenTouchableRegion = new Region();
6850
6851 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 * Flag indicating whether the touchable region should be adjusted by
6853 * the visible insets; if false the area outside the visible insets is
6854 * NOT touchable, so we must use those to adjust the frame during hit
6855 * tests.
6856 */
6857 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006860 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006861 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6862 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6863 float mHScale=1, mVScale=1;
6864 float mLastHScale=1, mLastVScale=1;
6865 final Matrix mTmpMatrix = new Matrix();
6866
6867 // "Real" frame that the application sees.
6868 final Rect mFrame = new Rect();
6869 final Rect mLastFrame = new Rect();
6870
6871 final Rect mContainingFrame = new Rect();
6872 final Rect mDisplayFrame = new Rect();
6873 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006874 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 final Rect mVisibleFrame = new Rect();
6876
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006877 boolean mContentChanged;
6878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006879 float mShownAlpha = 1;
6880 float mAlpha = 1;
6881 float mLastAlpha = 1;
6882
6883 // Set to true if, when the window gets displayed, it should perform
6884 // an enter animation.
6885 boolean mEnterAnimationPending;
6886
6887 // Currently running animation.
6888 boolean mAnimating;
6889 boolean mLocalAnimating;
6890 Animation mAnimation;
6891 boolean mAnimationIsEntrance;
6892 boolean mHasTransformation;
6893 boolean mHasLocalTransformation;
6894 final Transformation mTransformation = new Transformation();
6895
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006896 // If a window showing a wallpaper: the requested offset for the
6897 // wallpaper; if a wallpaper window: the currently applied offset.
6898 float mWallpaperX = -1;
6899 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006900
6901 // If a window showing a wallpaper: what fraction of the offset
6902 // range corresponds to a full virtual screen.
6903 float mWallpaperXStep = -1;
6904 float mWallpaperYStep = -1;
6905
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006906 // Wallpaper windows: pixels offset based on above variables.
6907 int mXOffset;
6908 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006910 // This is set after IWindowSession.relayout() has been called at
6911 // least once for the window. It allows us to detect the situation
6912 // where we don't yet have a surface, but should have one soon, so
6913 // we can give the window focus before waiting for the relayout.
6914 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006916 // This is set after the Surface has been created but before the
6917 // window has been drawn. During this time the surface is hidden.
6918 boolean mDrawPending;
6919
6920 // This is set after the window has finished drawing for the first
6921 // time but before its surface is shown. The surface will be
6922 // displayed when the next layout is run.
6923 boolean mCommitDrawPending;
6924
6925 // This is set during the time after the window's drawing has been
6926 // committed, and before its surface is actually shown. It is used
6927 // to delay showing the surface until all windows in a token are ready
6928 // to be shown.
6929 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006931 // Set when the window has been shown in the screen the first time.
6932 boolean mHasDrawn;
6933
6934 // Currently running an exit animation?
6935 boolean mExiting;
6936
6937 // Currently on the mDestroySurface list?
6938 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006940 // Completely remove from window manager after exit animation?
6941 boolean mRemoveOnExit;
6942
6943 // Set when the orientation is changing and this window has not yet
6944 // been updated for the new orientation.
6945 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006947 // Is this window now (or just being) removed?
6948 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006949
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006950 // Temp for keeping track of windows that have been removed when
6951 // rebuilding window list.
6952 boolean mRebuilding;
6953
Dianne Hackborn16064f92010-03-25 00:47:24 -07006954 // For debugging, this is the last information given to the surface flinger.
6955 boolean mSurfaceShown;
6956 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6957 int mSurfaceLayer;
6958 float mSurfaceAlpha;
6959
Jeff Brown928e0542011-01-10 11:17:36 -08006960 // Input channel and input window handle used by the input dispatcher.
6961 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006962 InputChannel mInputChannel;
6963
Mattias Petersson1622eee2010-12-21 10:15:11 +01006964 // Used to improve performance of toString()
6965 String mStringNameCache;
6966 CharSequence mLastTitle;
6967 boolean mWasPaused;
6968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 WindowState(Session s, IWindow c, WindowToken token,
6970 WindowState attachedWindow, WindowManager.LayoutParams a,
6971 int viewVisibility) {
6972 mSession = s;
6973 mClient = c;
6974 mToken = token;
6975 mAttrs.copyFrom(a);
6976 mViewVisibility = viewVisibility;
6977 DeathRecipient deathRecipient = new DeathRecipient();
6978 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006979 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006980 TAG, "Window " + this + " client=" + c.asBinder()
6981 + " token=" + token + " (" + mAttrs.token + ")");
6982 try {
6983 c.asBinder().linkToDeath(deathRecipient, 0);
6984 } catch (RemoteException e) {
6985 mDeathRecipient = null;
6986 mAttachedWindow = null;
6987 mLayoutAttached = false;
6988 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006989 mIsWallpaper = false;
6990 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006991 mBaseLayer = 0;
6992 mSubLayer = 0;
6993 return;
6994 }
6995 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006997 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6998 mAttrs.type <= LAST_SUB_WINDOW)) {
6999 // The multiplier here is to reserve space for multiple
7000 // windows in the same type layer.
7001 mBaseLayer = mPolicy.windowTypeToLayerLw(
7002 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7003 + TYPE_LAYER_OFFSET;
7004 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7005 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007006 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007007 mAttachedWindow.mChildWindows.add(this);
7008 mLayoutAttached = mAttrs.type !=
7009 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7010 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7011 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007012 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7013 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 } else {
7015 // The multiplier here is to reserve space for multiple
7016 // windows in the same type layer.
7017 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7018 * TYPE_LAYER_MULTIPLIER
7019 + TYPE_LAYER_OFFSET;
7020 mSubLayer = 0;
7021 mAttachedWindow = null;
7022 mLayoutAttached = false;
7023 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7024 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007025 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7026 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007027 }
7028
7029 WindowState appWin = this;
7030 while (appWin.mAttachedWindow != null) {
7031 appWin = mAttachedWindow;
7032 }
7033 WindowToken appToken = appWin.mToken;
7034 while (appToken.appWindowToken == null) {
7035 WindowToken parent = mTokenMap.get(appToken.token);
7036 if (parent == null || appToken == parent) {
7037 break;
7038 }
7039 appToken = parent;
7040 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007041 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007042 mAppToken = appToken.appWindowToken;
7043
7044 mSurface = null;
7045 mRequestedWidth = 0;
7046 mRequestedHeight = 0;
7047 mLastRequestedWidth = 0;
7048 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007049 mXOffset = 0;
7050 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007051 mLayer = 0;
7052 mAnimLayer = 0;
7053 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007054 mInputWindowHandle = new InputWindowHandle(
7055 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007056 }
7057
7058 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007059 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007060 TAG, "Attaching " + this + " token=" + mToken
7061 + ", list=" + mToken.windows);
7062 mSession.windowAddedLocked();
7063 }
7064
7065 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7066 mHaveFrame = true;
7067
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007068 final Rect container = mContainingFrame;
7069 container.set(pf);
7070
7071 final Rect display = mDisplayFrame;
7072 display.set(df);
7073
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007074 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007075 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007076 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7077 display.intersect(mCompatibleScreenFrame);
7078 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007079 }
7080
7081 final int pw = container.right - container.left;
7082 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083
7084 int w,h;
7085 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7086 w = mAttrs.width < 0 ? pw : mAttrs.width;
7087 h = mAttrs.height< 0 ? ph : mAttrs.height;
7088 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007089 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7090 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 }
Romain Guy06882f82009-06-10 13:36:04 -07007092
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007093 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007094 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7095 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007096 mParentFrame.set(pf);
7097 mContentChanged = true;
7098 }
7099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007100 final Rect content = mContentFrame;
7101 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007103 final Rect visible = mVisibleFrame;
7104 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007107 final int fw = frame.width();
7108 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007110 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7111 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7112
7113 Gravity.apply(mAttrs.gravity, w, h, container,
7114 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7115 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7116
7117 //System.out.println("Out: " + mFrame);
7118
7119 // Now make sure the window fits in the overall display.
7120 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007122 // Make sure the content and visible frames are inside of the
7123 // final window frame.
7124 if (content.left < frame.left) content.left = frame.left;
7125 if (content.top < frame.top) content.top = frame.top;
7126 if (content.right > frame.right) content.right = frame.right;
7127 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7128 if (visible.left < frame.left) visible.left = frame.left;
7129 if (visible.top < frame.top) visible.top = frame.top;
7130 if (visible.right > frame.right) visible.right = frame.right;
7131 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007133 final Rect contentInsets = mContentInsets;
7134 contentInsets.left = content.left-frame.left;
7135 contentInsets.top = content.top-frame.top;
7136 contentInsets.right = frame.right-content.right;
7137 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007139 final Rect visibleInsets = mVisibleInsets;
7140 visibleInsets.left = visible.left-frame.left;
7141 visibleInsets.top = visible.top-frame.top;
7142 visibleInsets.right = frame.right-visible.right;
7143 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007144
Dianne Hackborn284ac932009-08-28 10:34:25 -07007145 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7146 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007147 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 if (localLOGV) {
7151 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7152 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007153 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154 + mRequestedWidth + ", mRequestedheight="
7155 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7156 + "): frame=" + mFrame.toShortString()
7157 + " ci=" + contentInsets.toShortString()
7158 + " vi=" + visibleInsets.toShortString());
7159 //}
7160 }
7161 }
Romain Guy06882f82009-06-10 13:36:04 -07007162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007163 public Rect getFrameLw() {
7164 return mFrame;
7165 }
7166
7167 public Rect getShownFrameLw() {
7168 return mShownFrame;
7169 }
7170
7171 public Rect getDisplayFrameLw() {
7172 return mDisplayFrame;
7173 }
7174
7175 public Rect getContentFrameLw() {
7176 return mContentFrame;
7177 }
7178
7179 public Rect getVisibleFrameLw() {
7180 return mVisibleFrame;
7181 }
7182
7183 public boolean getGivenInsetsPendingLw() {
7184 return mGivenInsetsPending;
7185 }
7186
7187 public Rect getGivenContentInsetsLw() {
7188 return mGivenContentInsets;
7189 }
Romain Guy06882f82009-06-10 13:36:04 -07007190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007191 public Rect getGivenVisibleInsetsLw() {
7192 return mGivenVisibleInsets;
7193 }
Romain Guy06882f82009-06-10 13:36:04 -07007194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 public WindowManager.LayoutParams getAttrs() {
7196 return mAttrs;
7197 }
7198
7199 public int getSurfaceLayer() {
7200 return mLayer;
7201 }
Romain Guy06882f82009-06-10 13:36:04 -07007202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 public IApplicationToken getAppToken() {
7204 return mAppToken != null ? mAppToken.appToken : null;
7205 }
Jeff Brown349703e2010-06-22 01:27:15 -07007206
7207 public long getInputDispatchingTimeoutNanos() {
7208 return mAppToken != null
7209 ? mAppToken.inputDispatchingTimeoutNanos
7210 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7211 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007212
7213 public boolean hasAppShownWindows() {
7214 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7215 }
7216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007217 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007218 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007219 TAG, "Setting animation in " + this + ": " + anim);
7220 mAnimating = false;
7221 mLocalAnimating = false;
7222 mAnimation = anim;
7223 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7224 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7225 }
7226
7227 public void clearAnimation() {
7228 if (mAnimation != null) {
7229 mAnimating = true;
7230 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007231 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 mAnimation = null;
7233 }
7234 }
Romain Guy06882f82009-06-10 13:36:04 -07007235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007236 Surface createSurfaceLocked() {
7237 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007238 mReportDestroySurface = false;
7239 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007240 mDrawPending = true;
7241 mCommitDrawPending = false;
7242 mReadyToShow = false;
7243 if (mAppToken != null) {
7244 mAppToken.allDrawn = false;
7245 }
7246
7247 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248
7249 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7250 flags |= Surface.SECURE;
7251 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007252 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007253 TAG, "Creating surface in session "
7254 + mSession.mSurfaceSession + " window " + this
7255 + " w=" + mFrame.width()
7256 + " h=" + mFrame.height() + " format="
7257 + mAttrs.format + " flags=" + flags);
7258
7259 int w = mFrame.width();
7260 int h = mFrame.height();
7261 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7262 // for a scaled surface, we always want the requested
7263 // size.
7264 w = mRequestedWidth;
7265 h = mRequestedHeight;
7266 }
7267
Romain Guy9825ec62009-10-01 00:58:09 -07007268 // Something is wrong and SurfaceFlinger will not like this,
7269 // try to revert to sane values
7270 if (w <= 0) w = 1;
7271 if (h <= 0) h = 1;
7272
Dianne Hackborn16064f92010-03-25 00:47:24 -07007273 mSurfaceShown = false;
7274 mSurfaceLayer = 0;
7275 mSurfaceAlpha = 1;
7276 mSurfaceX = 0;
7277 mSurfaceY = 0;
7278 mSurfaceW = w;
7279 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007280 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007281 final boolean isHwAccelerated = (mAttrs.flags &
7282 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7283 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7284 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7285 flags |= Surface.OPAQUE;
7286 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007288 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007289 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007290 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007291 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007292 + mSurface + " IN SESSION "
7293 + mSession.mSurfaceSession
7294 + ": pid=" + mSession.mPid + " format="
7295 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007296 + Integer.toHexString(flags)
7297 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007299 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 reclaimSomeSurfaceMemoryLocked(this, "create");
7301 return null;
7302 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007303 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 return null;
7305 }
Romain Guy06882f82009-06-10 13:36:04 -07007306
Joe Onorato8a9b2202010-02-26 18:56:32 -08007307 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007308 TAG, "Got surface: " + mSurface
7309 + ", set left=" + mFrame.left + " top=" + mFrame.top
7310 + ", animLayer=" + mAnimLayer);
7311 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007312 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7313 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007314 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7315 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 }
7317 Surface.openTransaction();
7318 try {
7319 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007320 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007321 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007322 mSurface.setPosition(mSurfaceX, mSurfaceY);
7323 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007324 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007325 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007326 mSurface.hide();
7327 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007328 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 mSurface.setFlags(Surface.SURFACE_DITHER,
7330 Surface.SURFACE_DITHER);
7331 }
7332 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007333 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7335 }
7336 mLastHidden = true;
7337 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007339 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007340 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007341 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 TAG, "Created surface " + this);
7343 }
7344 return mSurface;
7345 }
Romain Guy06882f82009-06-10 13:36:04 -07007346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007348 if (mAppToken != null && this == mAppToken.startingWindow) {
7349 mAppToken.startingDisplayed = false;
7350 }
Romain Guy06882f82009-06-10 13:36:04 -07007351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007353 mDrawPending = false;
7354 mCommitDrawPending = false;
7355 mReadyToShow = false;
7356
7357 int i = mChildWindows.size();
7358 while (i > 0) {
7359 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007360 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007361 c.mAttachedHidden = true;
7362 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007363
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007364 if (mReportDestroySurface) {
7365 mReportDestroySurface = false;
7366 mSurfacePendingDestroy = true;
7367 try {
7368 mClient.dispatchGetNewSurface();
7369 // We'll really destroy on the next time around.
7370 return;
7371 } catch (RemoteException e) {
7372 }
7373 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007375 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007376 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007377 RuntimeException e = null;
7378 if (!HIDE_STACK_CRAWLS) {
7379 e = new RuntimeException();
7380 e.fillInStackTrace();
7381 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007382 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007383 + mSurface + ", session " + mSession, e);
7384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007386 RuntimeException e = null;
7387 if (!HIDE_STACK_CRAWLS) {
7388 e = new RuntimeException();
7389 e.fillInStackTrace();
7390 }
7391 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007393 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007394 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007395 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 + " surface " + mSurface + " session " + mSession
7397 + ": " + e.toString());
7398 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007399
Dianne Hackborn16064f92010-03-25 00:47:24 -07007400 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007401 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 }
7403 }
7404
7405 boolean finishDrawingLocked() {
7406 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007407 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 TAG, "finishDrawingLocked: " + mSurface);
7409 mCommitDrawPending = true;
7410 mDrawPending = false;
7411 return true;
7412 }
7413 return false;
7414 }
7415
7416 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007417 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007418 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007419 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007420 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 }
7422 mCommitDrawPending = false;
7423 mReadyToShow = true;
7424 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7425 final AppWindowToken atoken = mAppToken;
7426 if (atoken == null || atoken.allDrawn || starting) {
7427 performShowLocked();
7428 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007429 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 }
7431
7432 // This must be called while inside a transaction.
7433 boolean performShowLocked() {
7434 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007435 RuntimeException e = null;
7436 if (!HIDE_STACK_CRAWLS) {
7437 e = new RuntimeException();
7438 e.fillInStackTrace();
7439 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007440 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7442 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7443 }
7444 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007445 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7446 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007447 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 + " during animation: policyVis=" + mPolicyVisibility
7449 + " attHidden=" + mAttachedHidden
7450 + " tok.hiddenRequested="
7451 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007452 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 + (mAppToken != null ? mAppToken.hidden : false)
7454 + " animating=" + mAnimating
7455 + " tok animating="
7456 + (mAppToken != null ? mAppToken.animating : false));
7457 if (!showSurfaceRobustlyLocked(this)) {
7458 return false;
7459 }
7460 mLastAlpha = -1;
7461 mHasDrawn = true;
7462 mLastHidden = false;
7463 mReadyToShow = false;
7464 enableScreenIfNeededLocked();
7465
7466 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007468 int i = mChildWindows.size();
7469 while (i > 0) {
7470 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007471 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007472 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007473 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007474 if (c.mSurface != null) {
7475 c.performShowLocked();
7476 // It hadn't been shown, which means layout not
7477 // performed on it, so now we want to make sure to
7478 // do a layout. If called from within the transaction
7479 // loop, this will cause it to restart with a new
7480 // layout.
7481 mLayoutNeeded = true;
7482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 }
7484 }
Romain Guy06882f82009-06-10 13:36:04 -07007485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 if (mAttrs.type != TYPE_APPLICATION_STARTING
7487 && mAppToken != null) {
7488 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007489
Dianne Hackborn248b1882009-09-16 16:46:44 -07007490 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007491 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007492 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007494 // If this initial window is animating, stop it -- we
7495 // will do an animation to reveal it from behind the
7496 // starting window, so there is no need for it to also
7497 // be doing its own stuff.
7498 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007499 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007500 mAnimation = null;
7501 // Make sure we clean up the animation.
7502 mAnimating = true;
7503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 mFinishedStarting.add(mAppToken);
7505 mH.sendEmptyMessage(H.FINISHED_STARTING);
7506 }
7507 mAppToken.updateReportedVisibilityLocked();
7508 }
7509 }
7510 return true;
7511 }
Romain Guy06882f82009-06-10 13:36:04 -07007512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 // This must be called while inside a transaction. Returns true if
7514 // there is more animation to run.
7515 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007516 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7520 mHasTransformation = true;
7521 mHasLocalTransformation = true;
7522 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007523 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 TAG, "Starting animation in " + this +
7525 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7526 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7527 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7528 mAnimation.setStartTime(currentTime);
7529 mLocalAnimating = true;
7530 mAnimating = true;
7531 }
7532 mTransformation.clear();
7533 final boolean more = mAnimation.getTransformation(
7534 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007535 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 TAG, "Stepped animation in " + this +
7537 ": more=" + more + ", xform=" + mTransformation);
7538 if (more) {
7539 // we're not done!
7540 return true;
7541 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007542 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 TAG, "Finished animation in " + this +
7544 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007545
7546 if (mAnimation != null) {
7547 mAnimation.cancel();
7548 mAnimation = null;
7549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 //WindowManagerService.this.dump();
7551 }
7552 mHasLocalTransformation = false;
7553 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007554 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007555 // When our app token is animating, we kind-of pretend like
7556 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7557 // part of this check means that we will only do this if
7558 // our window is not currently exiting, or it is not
7559 // locally animating itself. The idea being that one that
7560 // is exiting and doing a local animation should be removed
7561 // once that animation is done.
7562 mAnimating = true;
7563 mHasTransformation = true;
7564 mTransformation.clear();
7565 return false;
7566 } else if (mHasTransformation) {
7567 // Little trick to get through the path below to act like
7568 // we have finished an animation.
7569 mAnimating = true;
7570 } else if (isAnimating()) {
7571 mAnimating = true;
7572 }
7573 } else if (mAnimation != null) {
7574 // If the display is frozen, and there is a pending animation,
7575 // clear it and make sure we run the cleanup code.
7576 mAnimating = true;
7577 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007578 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007579 mAnimation = null;
7580 }
Romain Guy06882f82009-06-10 13:36:04 -07007581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 if (!mAnimating && !mLocalAnimating) {
7583 return false;
7584 }
7585
Joe Onorato8a9b2202010-02-26 18:56:32 -08007586 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 TAG, "Animation done in " + this + ": exiting=" + mExiting
7588 + ", reportedVisible="
7589 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 mAnimating = false;
7592 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007593 if (mAnimation != null) {
7594 mAnimation.cancel();
7595 mAnimation = null;
7596 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007597 mAnimLayer = mLayer;
7598 if (mIsImWindow) {
7599 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007600 } else if (mIsWallpaper) {
7601 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007603 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007604 + " anim layer: " + mAnimLayer);
7605 mHasTransformation = false;
7606 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007607 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7608 if (DEBUG_VISIBILITY) {
7609 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7610 + mPolicyVisibilityAfterAnim);
7611 }
7612 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7613 if (!mPolicyVisibility) {
7614 if (mCurrentFocus == this) {
7615 mFocusMayChange = true;
7616 }
7617 // Window is no longer visible -- make sure if we were waiting
7618 // for it to be displayed before enabling the display, that
7619 // we allow the display to be enabled now.
7620 enableScreenIfNeededLocked();
7621 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 mTransformation.clear();
7624 if (mHasDrawn
7625 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7626 && mAppToken != null
7627 && mAppToken.firstWindowDrawn
7628 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007629 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007630 + mToken + ": first real window done animating");
7631 mFinishedStarting.add(mAppToken);
7632 mH.sendEmptyMessage(H.FINISHED_STARTING);
7633 }
Romain Guy06882f82009-06-10 13:36:04 -07007634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007635 finishExit();
7636
7637 if (mAppToken != null) {
7638 mAppToken.updateReportedVisibilityLocked();
7639 }
7640
7641 return false;
7642 }
7643
7644 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007645 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007646 TAG, "finishExit in " + this
7647 + ": exiting=" + mExiting
7648 + " remove=" + mRemoveOnExit
7649 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 final int N = mChildWindows.size();
7652 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007653 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007654 }
Romain Guy06882f82009-06-10 13:36:04 -07007655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007656 if (!mExiting) {
7657 return;
7658 }
Romain Guy06882f82009-06-10 13:36:04 -07007659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 if (isWindowAnimating()) {
7661 return;
7662 }
7663
Joe Onorato8a9b2202010-02-26 18:56:32 -08007664 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 TAG, "Exit animation finished in " + this
7666 + ": remove=" + mRemoveOnExit);
7667 if (mSurface != null) {
7668 mDestroySurface.add(this);
7669 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007670 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007671 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007672 try {
7673 mSurface.hide();
7674 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007675 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007676 }
7677 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 }
7679 mExiting = false;
7680 if (mRemoveOnExit) {
7681 mPendingRemove.add(this);
7682 mRemoveOnExit = false;
7683 }
7684 }
Romain Guy06882f82009-06-10 13:36:04 -07007685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7687 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7688 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7689 if (dtdx < -.000001f || dtdx > .000001f) return false;
7690 if (dsdy < -.000001f || dsdy > .000001f) return false;
7691 return true;
7692 }
Romain Guy06882f82009-06-10 13:36:04 -07007693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007694 void computeShownFrameLocked() {
7695 final boolean selfTransformation = mHasLocalTransformation;
7696 Transformation attachedTransformation =
7697 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7698 ? mAttachedWindow.mTransformation : null;
7699 Transformation appTransformation =
7700 (mAppToken != null && mAppToken.hasTransformation)
7701 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007702
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007703 // Wallpapers are animated based on the "real" window they
7704 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007705 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007706 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007707 if (mWallpaperTarget.mHasLocalTransformation &&
7708 mWallpaperTarget.mAnimation != null &&
7709 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007710 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007711 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007712 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007713 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007714 }
7715 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007716 mWallpaperTarget.mAppToken.hasTransformation &&
7717 mWallpaperTarget.mAppToken.animation != null &&
7718 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007719 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007720 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007721 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007722 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007723 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007725
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007726 final boolean screenAnimation = mScreenRotationAnimation != null
7727 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007729 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007730 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007731 final Rect frame = mFrame;
7732 final float tmpFloats[] = mTmpFloats;
7733 final Matrix tmpMatrix = mTmpMatrix;
7734
7735 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007736 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007738 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007739 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007740 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007741 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007742 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 }
7744 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007745 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007746 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007747 if (screenAnimation) {
7748 tmpMatrix.postConcat(
7749 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7750 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751
7752 // "convert" it into SurfaceFlinger's format
7753 // (a 2x2 matrix + an offset)
7754 // Here we must not transform the position of the surface
7755 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007756 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007757
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007758 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 tmpMatrix.getValues(tmpFloats);
7760 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007761 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7762 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007764 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7765 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 int w = frame.width();
7767 int h = frame.height();
7768 mShownFrame.set(x, y, x+w, y+h);
7769
7770 // Now set the alpha... but because our current hardware
7771 // can't do alpha transformation on a non-opaque surface,
7772 // turn it off if we are running an animation that is also
7773 // transforming since it is more important to have that
7774 // animation be smooth.
7775 mShownAlpha = mAlpha;
7776 if (!mLimitedAlphaCompositing
7777 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7778 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7779 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007780 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007781 if (selfTransformation) {
7782 mShownAlpha *= mTransformation.getAlpha();
7783 }
7784 if (attachedTransformation != null) {
7785 mShownAlpha *= attachedTransformation.getAlpha();
7786 }
7787 if (appTransformation != null) {
7788 mShownAlpha *= appTransformation.getAlpha();
7789 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007790 if (screenAnimation) {
7791 mShownAlpha *=
7792 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007794 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007795 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 }
Romain Guy06882f82009-06-10 13:36:04 -07007797
Joe Onorato8a9b2202010-02-26 18:56:32 -08007798 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 TAG, "Continuing animation in " + this +
7800 ": " + mShownFrame +
7801 ", alpha=" + mTransformation.getAlpha());
7802 return;
7803 }
Romain Guy06882f82009-06-10 13:36:04 -07007804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007805 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007806 if (mXOffset != 0 || mYOffset != 0) {
7807 mShownFrame.offset(mXOffset, mYOffset);
7808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007809 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007810 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 mDsDx = 1;
7812 mDtDx = 0;
7813 mDsDy = 0;
7814 mDtDy = 1;
7815 }
Romain Guy06882f82009-06-10 13:36:04 -07007816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007817 /**
7818 * Is this window visible? It is not visible if there is no
7819 * surface, or we are in the process of running an exit animation
7820 * that will remove the surface, or its app token has been hidden.
7821 */
7822 public boolean isVisibleLw() {
7823 final AppWindowToken atoken = mAppToken;
7824 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7825 && (atoken == null || !atoken.hiddenRequested)
7826 && !mExiting && !mDestroying;
7827 }
7828
7829 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007830 * Like {@link #isVisibleLw}, but also counts a window that is currently
7831 * "hidden" behind the keyguard as visible. This allows us to apply
7832 * things like window flags that impact the keyguard.
7833 * XXX I am starting to think we need to have ANOTHER visibility flag
7834 * for this "hidden behind keyguard" state rather than overloading
7835 * mPolicyVisibility. Ungh.
7836 */
7837 public boolean isVisibleOrBehindKeyguardLw() {
7838 final AppWindowToken atoken = mAppToken;
7839 return mSurface != null && !mAttachedHidden
7840 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007841 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007842 && !mExiting && !mDestroying;
7843 }
7844
7845 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 * Is this window visible, ignoring its app token? It is not visible
7847 * if there is no surface, or we are in the process of running an exit animation
7848 * that will remove the surface.
7849 */
7850 public boolean isWinVisibleLw() {
7851 final AppWindowToken atoken = mAppToken;
7852 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7853 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7854 && !mExiting && !mDestroying;
7855 }
7856
7857 /**
7858 * The same as isVisible(), but follows the current hidden state of
7859 * the associated app token, not the pending requested hidden state.
7860 */
7861 boolean isVisibleNow() {
7862 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007863 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007864 }
7865
7866 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007867 * Can this window possibly be a drag/drop target? The test here is
7868 * a combination of the above "visible now" with the check that the
7869 * Input Manager uses when discarding windows from input consideration.
7870 */
7871 boolean isPotentialDragTarget() {
7872 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7873 }
7874
7875 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 * Same as isVisible(), but we also count it as visible between the
7877 * call to IWindowSession.add() and the first relayout().
7878 */
7879 boolean isVisibleOrAdding() {
7880 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007881 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007882 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7883 && mPolicyVisibility && !mAttachedHidden
7884 && (atoken == null || !atoken.hiddenRequested)
7885 && !mExiting && !mDestroying;
7886 }
7887
7888 /**
7889 * Is this window currently on-screen? It is on-screen either if it
7890 * is visible or it is currently running an animation before no longer
7891 * being visible.
7892 */
7893 boolean isOnScreen() {
7894 final AppWindowToken atoken = mAppToken;
7895 if (atoken != null) {
7896 return mSurface != null && mPolicyVisibility && !mDestroying
7897 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007898 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 } else {
7900 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007901 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007902 }
7903 }
Romain Guy06882f82009-06-10 13:36:04 -07007904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007905 /**
7906 * Like isOnScreen(), but we don't return true if the window is part
7907 * of a transition that has not yet been started.
7908 */
7909 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007910 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007911 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007912 return false;
7913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007914 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007915 final boolean animating = atoken != null
7916 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007917 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007918 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7919 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007920 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007921 }
7922
7923 /** Is the window or its container currently animating? */
7924 boolean isAnimating() {
7925 final WindowState attached = mAttachedWindow;
7926 final AppWindowToken atoken = mAppToken;
7927 return mAnimation != null
7928 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007929 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007930 (atoken.animation != null
7931 || atoken.inPendingTransaction));
7932 }
7933
7934 /** Is this window currently animating? */
7935 boolean isWindowAnimating() {
7936 return mAnimation != null;
7937 }
7938
7939 /**
7940 * Like isOnScreen, but returns false if the surface hasn't yet
7941 * been drawn.
7942 */
7943 public boolean isDisplayedLw() {
7944 final AppWindowToken atoken = mAppToken;
7945 return mSurface != null && mPolicyVisibility && !mDestroying
7946 && !mDrawPending && !mCommitDrawPending
7947 && ((!mAttachedHidden &&
7948 (atoken == null || !atoken.hiddenRequested))
7949 || mAnimating);
7950 }
7951
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007952 /**
7953 * Returns true if the window has a surface that it has drawn a
7954 * complete UI in to.
7955 */
7956 public boolean isDrawnLw() {
7957 final AppWindowToken atoken = mAppToken;
7958 return mSurface != null && !mDestroying
7959 && !mDrawPending && !mCommitDrawPending;
7960 }
7961
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007962 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007963 * Return true if the window is opaque and fully drawn. This indicates
7964 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007965 */
7966 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007967 return (mAttrs.format == PixelFormat.OPAQUE
7968 || mAttrs.type == TYPE_WALLPAPER)
7969 && mSurface != null && mAnimation == null
7970 && (mAppToken == null || mAppToken.animation == null)
7971 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007972 }
7973
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007974 /**
7975 * Return whether this window is wanting to have a translation
7976 * animation applied to it for an in-progress move. (Only makes
7977 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7978 */
7979 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007980 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007981 && (mFrame.top != mLastFrame.top
7982 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007983 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007984 && mPolicy.isScreenOn();
7985 }
7986
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007987 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7988 return
7989 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007990 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7991 // only if it's visible
7992 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007993 // and only if the application fills the compatible screen
7994 mFrame.left <= mCompatibleScreenFrame.left &&
7995 mFrame.top <= mCompatibleScreenFrame.top &&
7996 mFrame.right >= mCompatibleScreenFrame.right &&
7997 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007998 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007999 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008000 }
8001
8002 boolean isFullscreen(int screenWidth, int screenHeight) {
8003 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008004 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008005 }
8006
8007 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008008 disposeInputChannel();
8009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008010 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008011 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008012 mAttachedWindow.mChildWindows.remove(this);
8013 }
8014 destroySurfaceLocked();
8015 mSession.windowRemovedLocked();
8016 try {
8017 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8018 } catch (RuntimeException e) {
8019 // Ignore if it has already been removed (usually because
8020 // we are doing this as part of processing a death note.)
8021 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008022 }
8023
8024 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008025 if (mInputChannel != null) {
8026 mInputManager.unregisterInputChannel(mInputChannel);
8027
8028 mInputChannel.dispose();
8029 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07008030 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008031 }
8032
8033 private class DeathRecipient implements IBinder.DeathRecipient {
8034 public void binderDied() {
8035 try {
8036 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008037 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008038 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008039 if (win != null) {
8040 removeWindowLocked(mSession, win);
8041 }
8042 }
8043 } catch (IllegalArgumentException ex) {
8044 // This will happen if the window has already been
8045 // removed.
8046 }
8047 }
8048 }
8049
8050 /** Returns true if this window desires key events. */
8051 public final boolean canReceiveKeys() {
8052 return isVisibleOrAdding()
8053 && (mViewVisibility == View.VISIBLE)
8054 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8055 }
8056
8057 public boolean hasDrawnLw() {
8058 return mHasDrawn;
8059 }
8060
8061 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008062 return showLw(doAnimation, true);
8063 }
8064
8065 boolean showLw(boolean doAnimation, boolean requestAnim) {
8066 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8067 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008068 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008069 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008070 if (doAnimation) {
8071 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8072 + mPolicyVisibility + " mAnimation=" + mAnimation);
8073 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8074 doAnimation = false;
8075 } else if (mPolicyVisibility && mAnimation == null) {
8076 // Check for the case where we are currently visible and
8077 // not animating; we do not want to do animation at such a
8078 // point to become visible when we already are.
8079 doAnimation = false;
8080 }
8081 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008082 mPolicyVisibility = true;
8083 mPolicyVisibilityAfterAnim = true;
8084 if (doAnimation) {
8085 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8086 }
8087 if (requestAnim) {
8088 requestAnimationLocked(0);
8089 }
8090 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008091 }
8092
8093 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008094 return hideLw(doAnimation, true);
8095 }
8096
8097 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008098 if (doAnimation) {
8099 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8100 doAnimation = false;
8101 }
8102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8104 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008105 if (!current) {
8106 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008108 if (doAnimation) {
8109 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8110 if (mAnimation == null) {
8111 doAnimation = false;
8112 }
8113 }
8114 if (doAnimation) {
8115 mPolicyVisibilityAfterAnim = false;
8116 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008117 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008118 mPolicyVisibilityAfterAnim = false;
8119 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008120 // Window is no longer visible -- make sure if we were waiting
8121 // for it to be displayed before enabling the display, that
8122 // we allow the display to be enabled now.
8123 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008124 if (mCurrentFocus == this) {
8125 mFocusMayChange = true;
8126 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008127 }
8128 if (requestAnim) {
8129 requestAnimationLocked(0);
8130 }
8131 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008132 }
8133
Jeff Brownfbf09772011-01-16 14:06:57 -08008134 public void getTouchableRegion(Region outRegion) {
8135 final Rect frame = mFrame;
8136 switch (mTouchableInsets) {
8137 default:
8138 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8139 outRegion.set(frame);
8140 break;
8141 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8142 final Rect inset = mGivenContentInsets;
8143 outRegion.set(
8144 frame.left + inset.left, frame.top + inset.top,
8145 frame.right - inset.right, frame.bottom - inset.bottom);
8146 break;
8147 }
8148 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8149 final Rect inset = mGivenVisibleInsets;
8150 outRegion.set(
8151 frame.left + inset.left, frame.top + inset.top,
8152 frame.right - inset.right, frame.bottom - inset.bottom);
8153 break;
8154 }
8155 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8156 final Region givenTouchableRegion = mGivenTouchableRegion;
8157 outRegion.set(givenTouchableRegion);
8158 outRegion.translate(frame.left, frame.top);
8159 break;
8160 }
8161 }
8162 }
8163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008164 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008165 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8166 pw.print(" mClient="); pw.println(mClient.asBinder());
8167 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8168 if (mAttachedWindow != null || mLayoutAttached) {
8169 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8170 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8171 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008172 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8173 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8174 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008175 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8176 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008177 }
8178 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8179 pw.print(" mSubLayer="); pw.print(mSubLayer);
8180 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8181 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8182 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8183 pw.print("="); pw.print(mAnimLayer);
8184 pw.print(" mLastLayer="); pw.println(mLastLayer);
8185 if (mSurface != null) {
8186 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008187 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8188 pw.print(" layer="); pw.print(mSurfaceLayer);
8189 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8190 pw.print(" rect=("); pw.print(mSurfaceX);
8191 pw.print(","); pw.print(mSurfaceY);
8192 pw.print(") "); pw.print(mSurfaceW);
8193 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008194 }
8195 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8196 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8197 if (mAppToken != null) {
8198 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8199 }
8200 if (mTargetAppToken != null) {
8201 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8202 }
8203 pw.print(prefix); pw.print("mViewVisibility=0x");
8204 pw.print(Integer.toHexString(mViewVisibility));
8205 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008206 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8207 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008208 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8209 pw.print(prefix); pw.print("mPolicyVisibility=");
8210 pw.print(mPolicyVisibility);
8211 pw.print(" mPolicyVisibilityAfterAnim=");
8212 pw.print(mPolicyVisibilityAfterAnim);
8213 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8214 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008215 if (!mRelayoutCalled) {
8216 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8217 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008218 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008219 pw.print(" h="); pw.print(mRequestedHeight);
8220 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008221 if (mXOffset != 0 || mYOffset != 0) {
8222 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8223 pw.print(" y="); pw.println(mYOffset);
8224 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008225 pw.print(prefix); pw.print("mGivenContentInsets=");
8226 mGivenContentInsets.printShortString(pw);
8227 pw.print(" mGivenVisibleInsets=");
8228 mGivenVisibleInsets.printShortString(pw);
8229 pw.println();
8230 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8231 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8232 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8233 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008234 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008235 pw.print(prefix); pw.print("mShownFrame=");
8236 mShownFrame.printShortString(pw);
8237 pw.print(" last="); mLastShownFrame.printShortString(pw);
8238 pw.println();
8239 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8240 pw.print(" last="); mLastFrame.printShortString(pw);
8241 pw.println();
8242 pw.print(prefix); pw.print("mContainingFrame=");
8243 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008244 pw.print(" mParentFrame=");
8245 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008246 pw.print(" mDisplayFrame=");
8247 mDisplayFrame.printShortString(pw);
8248 pw.println();
8249 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8250 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8251 pw.println();
8252 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8253 pw.print(" last="); mLastContentInsets.printShortString(pw);
8254 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8255 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8256 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008257 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8258 || mAnimation != null) {
8259 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8260 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8261 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8262 pw.print(" mAnimation="); pw.println(mAnimation);
8263 }
8264 if (mHasTransformation || mHasLocalTransformation) {
8265 pw.print(prefix); pw.print("XForm: has=");
8266 pw.print(mHasTransformation);
8267 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8268 pw.print(" "); mTransformation.printShortString(pw);
8269 pw.println();
8270 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008271 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8272 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8273 pw.print(" mAlpha="); pw.print(mAlpha);
8274 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8275 }
8276 if (mHaveMatrix) {
8277 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8278 pw.print(" mDtDx="); pw.print(mDtDx);
8279 pw.print(" mDsDy="); pw.print(mDsDy);
8280 pw.print(" mDtDy="); pw.println(mDtDy);
8281 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008282 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8283 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8284 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8285 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8286 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8287 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8288 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8289 pw.print(" mDestroying="); pw.print(mDestroying);
8290 pw.print(" mRemoved="); pw.println(mRemoved);
8291 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008292 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008293 pw.print(prefix); pw.print("mOrientationChanging=");
8294 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008295 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8296 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008297 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008298 if (mHScale != 1 || mVScale != 1) {
8299 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8300 pw.print(" mVScale="); pw.println(mVScale);
8301 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008302 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008303 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8304 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8305 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008306 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8307 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8308 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8309 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008310 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07008311
8312 String makeInputChannelName() {
8313 return Integer.toHexString(System.identityHashCode(this))
8314 + " " + mAttrs.getTitle();
8315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008316
8317 @Override
8318 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008319 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8320 || mWasPaused != mToken.paused) {
8321 mLastTitle = mAttrs.getTitle();
8322 mWasPaused = mToken.paused;
8323 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8324 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8325 }
8326 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008327 }
8328 }
Romain Guy06882f82009-06-10 13:36:04 -07008329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008330 // -------------------------------------------------------------
8331 // Window Token State
8332 // -------------------------------------------------------------
8333
8334 class WindowToken {
8335 // The actual token.
8336 final IBinder token;
8337
8338 // The type of window this token is for, as per WindowManager.LayoutParams.
8339 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008341 // Set if this token was explicitly added by a client, so should
8342 // not be removed when all windows are removed.
8343 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008344
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008345 // For printing.
8346 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008348 // If this is an AppWindowToken, this is non-null.
8349 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008351 // All of the windows associated with this token.
8352 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8353
8354 // Is key dispatching paused for this token?
8355 boolean paused = false;
8356
8357 // Should this token's windows be hidden?
8358 boolean hidden;
8359
8360 // Temporary for finding which tokens no longer have visible windows.
8361 boolean hasVisible;
8362
Dianne Hackborna8f60182009-09-01 19:01:50 -07008363 // Set to true when this token is in a pending transaction where it
8364 // will be shown.
8365 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008366
Dianne Hackborna8f60182009-09-01 19:01:50 -07008367 // Set to true when this token is in a pending transaction where it
8368 // will be hidden.
8369 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008370
Dianne Hackborna8f60182009-09-01 19:01:50 -07008371 // Set to true when this token is in a pending transaction where its
8372 // windows will be put to the bottom of the list.
8373 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008374
Dianne Hackborna8f60182009-09-01 19:01:50 -07008375 // Set to true when this token is in a pending transaction where its
8376 // windows will be put to the top of the list.
8377 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 WindowToken(IBinder _token, int type, boolean _explicit) {
8380 token = _token;
8381 windowType = type;
8382 explicit = _explicit;
8383 }
8384
8385 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008386 pw.print(prefix); pw.print("token="); pw.println(token);
8387 pw.print(prefix); pw.print("windows="); pw.println(windows);
8388 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8389 pw.print(" hidden="); pw.print(hidden);
8390 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008391 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8392 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8393 pw.print(" waitingToHide="); pw.print(waitingToHide);
8394 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8395 pw.print(" sendingToTop="); pw.println(sendingToTop);
8396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 }
8398
8399 @Override
8400 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008401 if (stringName == null) {
8402 StringBuilder sb = new StringBuilder();
8403 sb.append("WindowToken{");
8404 sb.append(Integer.toHexString(System.identityHashCode(this)));
8405 sb.append(" token="); sb.append(token); sb.append('}');
8406 stringName = sb.toString();
8407 }
8408 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 }
8410 };
8411
8412 class AppWindowToken extends WindowToken {
8413 // Non-null only for application tokens.
8414 final IApplicationToken appToken;
8415
8416 // All of the windows and child windows that are included in this
8417 // application token. Note this list is NOT sorted!
8418 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8419
8420 int groupId = -1;
8421 boolean appFullscreen;
8422 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008423
8424 // The input dispatching timeout for this application token in nanoseconds.
8425 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 // These are used for determining when all windows associated with
8428 // an activity have been drawn, so they can be made visible together
8429 // at the same time.
8430 int lastTransactionSequence = mTransactionSequence-1;
8431 int numInterestingWindows;
8432 int numDrawnWindows;
8433 boolean inPendingTransaction;
8434 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 // Is this token going to be hidden in a little while? If so, it
8437 // won't be taken into account for setting the screen orientation.
8438 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 // Is this window's surface needed? This is almost like hidden, except
8441 // it will sometimes be true a little earlier: when the token has
8442 // been shown, but is still waiting for its app transition to execute
8443 // before making its windows shown.
8444 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008446 // Have we told the window clients to hide themselves?
8447 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 // Last visibility state we reported to the app token.
8450 boolean reportedVisible;
8451
8452 // Set to true when the token has been removed from the window mgr.
8453 boolean removed;
8454
8455 // Have we been asked to have this token keep the screen frozen?
8456 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 boolean animating;
8459 Animation animation;
8460 boolean hasTransformation;
8461 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008463 // Offset to the window of all layers in the token, for use by
8464 // AppWindowToken animations.
8465 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 // Information about an application starting window if displayed.
8468 StartingData startingData;
8469 WindowState startingWindow;
8470 View startingView;
8471 boolean startingDisplayed;
8472 boolean startingMoved;
8473 boolean firstWindowDrawn;
8474
Jeff Brown928e0542011-01-10 11:17:36 -08008475 // Input application handle used by the input dispatcher.
8476 InputApplicationHandle mInputApplicationHandle;
8477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008478 AppWindowToken(IApplicationToken _token) {
8479 super(_token.asBinder(),
8480 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8481 appWindowToken = this;
8482 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008483 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008484 }
Romain Guy06882f82009-06-10 13:36:04 -07008485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008486 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008487 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008488 TAG, "Setting animation in " + this + ": " + anim);
8489 animation = anim;
8490 animating = false;
8491 anim.restrictDuration(MAX_ANIMATION_DURATION);
8492 anim.scaleCurrentDuration(mTransitionAnimationScale);
8493 int zorder = anim.getZAdjustment();
8494 int adj = 0;
8495 if (zorder == Animation.ZORDER_TOP) {
8496 adj = TYPE_LAYER_OFFSET;
8497 } else if (zorder == Animation.ZORDER_BOTTOM) {
8498 adj = -TYPE_LAYER_OFFSET;
8499 }
Romain Guy06882f82009-06-10 13:36:04 -07008500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 if (animLayerAdjustment != adj) {
8502 animLayerAdjustment = adj;
8503 updateLayers();
8504 }
8505 }
Romain Guy06882f82009-06-10 13:36:04 -07008506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008507 public void setDummyAnimation() {
8508 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008509 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008510 TAG, "Setting dummy animation in " + this);
8511 animation = sDummyAnimation;
8512 }
8513 }
8514
8515 public void clearAnimation() {
8516 if (animation != null) {
8517 animation = null;
8518 animating = true;
8519 }
8520 }
Romain Guy06882f82009-06-10 13:36:04 -07008521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008522 void updateLayers() {
8523 final int N = allAppWindows.size();
8524 final int adj = animLayerAdjustment;
8525 for (int i=0; i<N; i++) {
8526 WindowState w = allAppWindows.get(i);
8527 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008528 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 + w.mAnimLayer);
8530 if (w == mInputMethodTarget) {
8531 setInputMethodAnimLayerAdjustment(adj);
8532 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008533 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008534 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 }
8537 }
Romain Guy06882f82009-06-10 13:36:04 -07008538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 void sendAppVisibilityToClients() {
8540 final int N = allAppWindows.size();
8541 for (int i=0; i<N; i++) {
8542 WindowState win = allAppWindows.get(i);
8543 if (win == startingWindow && clientHidden) {
8544 // Don't hide the starting window.
8545 continue;
8546 }
8547 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008548 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 "Setting visibility of " + win + ": " + (!clientHidden));
8550 win.mClient.dispatchAppVisibility(!clientHidden);
8551 } catch (RemoteException e) {
8552 }
8553 }
8554 }
Romain Guy06882f82009-06-10 13:36:04 -07008555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 void showAllWindowsLocked() {
8557 final int NW = allAppWindows.size();
8558 for (int i=0; i<NW; i++) {
8559 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008560 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 "performing show on: " + w);
8562 w.performShowLocked();
8563 }
8564 }
Romain Guy06882f82009-06-10 13:36:04 -07008565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 // This must be called while inside a transaction.
8567 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008568 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008569 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008571 if (animation == sDummyAnimation) {
8572 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008573 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 // when it is really time to animate, this will be set to
8575 // a real animation and the next call will execute normally.
8576 return false;
8577 }
Romain Guy06882f82009-06-10 13:36:04 -07008578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8580 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008581 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 TAG, "Starting animation in " + this +
8583 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8584 + " scale=" + mTransitionAnimationScale
8585 + " allDrawn=" + allDrawn + " animating=" + animating);
8586 animation.initialize(dw, dh, dw, dh);
8587 animation.setStartTime(currentTime);
8588 animating = true;
8589 }
8590 transformation.clear();
8591 final boolean more = animation.getTransformation(
8592 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008593 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008594 TAG, "Stepped animation in " + this +
8595 ": more=" + more + ", xform=" + transformation);
8596 if (more) {
8597 // we're done!
8598 hasTransformation = true;
8599 return true;
8600 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008601 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008602 TAG, "Finished animation in " + this +
8603 " @ " + currentTime);
8604 animation = null;
8605 }
8606 } else if (animation != null) {
8607 // If the display is frozen, and there is a pending animation,
8608 // clear it and make sure we run the cleanup code.
8609 animating = true;
8610 animation = null;
8611 }
8612
8613 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008615 if (!animating) {
8616 return false;
8617 }
8618
8619 clearAnimation();
8620 animating = false;
8621 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8622 moveInputMethodWindowsIfNeededLocked(true);
8623 }
Romain Guy06882f82009-06-10 13:36:04 -07008624
Joe Onorato8a9b2202010-02-26 18:56:32 -08008625 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008626 TAG, "Animation done in " + this
8627 + ": reportedVisible=" + reportedVisible);
8628
8629 transformation.clear();
8630 if (animLayerAdjustment != 0) {
8631 animLayerAdjustment = 0;
8632 updateLayers();
8633 }
Romain Guy06882f82009-06-10 13:36:04 -07008634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008635 final int N = windows.size();
8636 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008637 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 }
8639 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 return false;
8642 }
8643
8644 void updateReportedVisibilityLocked() {
8645 if (appToken == null) {
8646 return;
8647 }
Romain Guy06882f82009-06-10 13:36:04 -07008648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008649 int numInteresting = 0;
8650 int numVisible = 0;
8651 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008652
Joe Onorato8a9b2202010-02-26 18:56:32 -08008653 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 final int N = allAppWindows.size();
8655 for (int i=0; i<N; i++) {
8656 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008657 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008658 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008659 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8660 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 continue;
8662 }
8663 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008664 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008665 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008667 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008668 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008669 + " pv=" + win.mPolicyVisibility
8670 + " dp=" + win.mDrawPending
8671 + " cdp=" + win.mCommitDrawPending
8672 + " ah=" + win.mAttachedHidden
8673 + " th="
8674 + (win.mAppToken != null
8675 ? win.mAppToken.hiddenRequested : false)
8676 + " a=" + win.mAnimating);
8677 }
8678 }
8679 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008680 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 if (!win.isAnimating()) {
8682 numVisible++;
8683 }
8684 nowGone = false;
8685 } else if (win.isAnimating()) {
8686 nowGone = false;
8687 }
8688 }
Romain Guy06882f82009-06-10 13:36:04 -07008689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008690 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008691 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008692 + numInteresting + " visible=" + numVisible);
8693 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008694 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008695 TAG, "Visibility changed in " + this
8696 + ": vis=" + nowVisible);
8697 reportedVisible = nowVisible;
8698 Message m = mH.obtainMessage(
8699 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8700 nowVisible ? 1 : 0,
8701 nowGone ? 1 : 0,
8702 this);
8703 mH.sendMessage(m);
8704 }
8705 }
Romain Guy06882f82009-06-10 13:36:04 -07008706
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008707 WindowState findMainWindow() {
8708 int j = windows.size();
8709 while (j > 0) {
8710 j--;
8711 WindowState win = windows.get(j);
8712 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8713 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8714 return win;
8715 }
8716 }
8717 return null;
8718 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008720 void dump(PrintWriter pw, String prefix) {
8721 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008722 if (appToken != null) {
8723 pw.print(prefix); pw.println("app=true");
8724 }
8725 if (allAppWindows.size() > 0) {
8726 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8727 }
8728 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008729 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008730 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8731 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8732 pw.print(" clientHidden="); pw.print(clientHidden);
8733 pw.print(" willBeHidden="); pw.print(willBeHidden);
8734 pw.print(" reportedVisible="); pw.println(reportedVisible);
8735 if (paused || freezingScreen) {
8736 pw.print(prefix); pw.print("paused="); pw.print(paused);
8737 pw.print(" freezingScreen="); pw.println(freezingScreen);
8738 }
8739 if (numInterestingWindows != 0 || numDrawnWindows != 0
8740 || inPendingTransaction || allDrawn) {
8741 pw.print(prefix); pw.print("numInterestingWindows=");
8742 pw.print(numInterestingWindows);
8743 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8744 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8745 pw.print(" allDrawn="); pw.println(allDrawn);
8746 }
8747 if (animating || animation != null) {
8748 pw.print(prefix); pw.print("animating="); pw.print(animating);
8749 pw.print(" animation="); pw.println(animation);
8750 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008751 if (hasTransformation) {
8752 pw.print(prefix); pw.print("XForm: ");
8753 transformation.printShortString(pw);
8754 pw.println();
8755 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008756 if (animLayerAdjustment != 0) {
8757 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8758 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008759 if (startingData != null || removed || firstWindowDrawn) {
8760 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8761 pw.print(" removed="); pw.print(removed);
8762 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8763 }
8764 if (startingWindow != null || startingView != null
8765 || startingDisplayed || startingMoved) {
8766 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8767 pw.print(" startingView="); pw.print(startingView);
8768 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8769 pw.print(" startingMoved"); pw.println(startingMoved);
8770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 }
8772
8773 @Override
8774 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008775 if (stringName == null) {
8776 StringBuilder sb = new StringBuilder();
8777 sb.append("AppWindowToken{");
8778 sb.append(Integer.toHexString(System.identityHashCode(this)));
8779 sb.append(" token="); sb.append(token); sb.append('}');
8780 stringName = sb.toString();
8781 }
8782 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 }
8784 }
Romain Guy06882f82009-06-10 13:36:04 -07008785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 // -------------------------------------------------------------
8787 // DummyAnimation
8788 // -------------------------------------------------------------
8789
8790 // This is an animation that does nothing: it just immediately finishes
8791 // itself every time it is called. It is used as a stub animation in cases
8792 // where we want to synchronize multiple things that may be animating.
8793 static final class DummyAnimation extends Animation {
8794 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8795 return false;
8796 }
8797 }
8798 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008800 // -------------------------------------------------------------
8801 // Async Handler
8802 // -------------------------------------------------------------
8803
8804 static final class StartingData {
8805 final String pkg;
8806 final int theme;
8807 final CharSequence nonLocalizedLabel;
8808 final int labelRes;
8809 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008810 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008812 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008813 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008814 pkg = _pkg;
8815 theme = _theme;
8816 nonLocalizedLabel = _nonLocalizedLabel;
8817 labelRes = _labelRes;
8818 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008819 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008820 }
8821 }
8822
8823 private final class H extends Handler {
8824 public static final int REPORT_FOCUS_CHANGE = 2;
8825 public static final int REPORT_LOSING_FOCUS = 3;
8826 public static final int ANIMATE = 4;
8827 public static final int ADD_STARTING = 5;
8828 public static final int REMOVE_STARTING = 6;
8829 public static final int FINISHED_STARTING = 7;
8830 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008831 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8832 public static final int HOLD_SCREEN_CHANGED = 12;
8833 public static final int APP_TRANSITION_TIMEOUT = 13;
8834 public static final int PERSIST_ANIMATION_SCALE = 14;
8835 public static final int FORCE_GC = 15;
8836 public static final int ENABLE_SCREEN = 16;
8837 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008838 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008839 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008840 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008841 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008845 public H() {
8846 }
Romain Guy06882f82009-06-10 13:36:04 -07008847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008848 @Override
8849 public void handleMessage(Message msg) {
8850 switch (msg.what) {
8851 case REPORT_FOCUS_CHANGE: {
8852 WindowState lastFocus;
8853 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 synchronized(mWindowMap) {
8856 lastFocus = mLastFocus;
8857 newFocus = mCurrentFocus;
8858 if (lastFocus == newFocus) {
8859 // Focus is not changing, so nothing to do.
8860 return;
8861 }
8862 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008863 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008864 // + " to " + newFocus);
8865 if (newFocus != null && lastFocus != null
8866 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008867 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008868 mLosingFocus.add(lastFocus);
8869 lastFocus = null;
8870 }
8871 }
8872
8873 if (lastFocus != newFocus) {
8874 //System.out.println("Changing focus from " + lastFocus
8875 // + " to " + newFocus);
8876 if (newFocus != null) {
8877 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008878 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008879 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8880 } catch (RemoteException e) {
8881 // Ignore if process has died.
8882 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008883 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008884 }
8885
8886 if (lastFocus != null) {
8887 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008888 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008889 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8890 } catch (RemoteException e) {
8891 // Ignore if process has died.
8892 }
8893 }
8894 }
8895 } break;
8896
8897 case REPORT_LOSING_FOCUS: {
8898 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 synchronized(mWindowMap) {
8901 losers = mLosingFocus;
8902 mLosingFocus = new ArrayList<WindowState>();
8903 }
8904
8905 final int N = losers.size();
8906 for (int i=0; i<N; i++) {
8907 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008908 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008909 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8910 } catch (RemoteException e) {
8911 // Ignore if process has died.
8912 }
8913 }
8914 } break;
8915
8916 case ANIMATE: {
8917 synchronized(mWindowMap) {
8918 mAnimationPending = false;
8919 performLayoutAndPlaceSurfacesLocked();
8920 }
8921 } break;
8922
8923 case ADD_STARTING: {
8924 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8925 final StartingData sd = wtoken.startingData;
8926
8927 if (sd == null) {
8928 // Animation has been canceled... do nothing.
8929 return;
8930 }
Romain Guy06882f82009-06-10 13:36:04 -07008931
Joe Onorato8a9b2202010-02-26 18:56:32 -08008932 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008935 View view = null;
8936 try {
8937 view = mPolicy.addStartingWindow(
8938 wtoken.token, sd.pkg,
8939 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008940 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008941 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008942 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 }
8944
8945 if (view != null) {
8946 boolean abort = false;
8947
8948 synchronized(mWindowMap) {
8949 if (wtoken.removed || wtoken.startingData == null) {
8950 // If the window was successfully added, then
8951 // we need to remove it.
8952 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 "Aborted starting " + wtoken
8955 + ": removed=" + wtoken.removed
8956 + " startingData=" + wtoken.startingData);
8957 wtoken.startingWindow = null;
8958 wtoken.startingData = null;
8959 abort = true;
8960 }
8961 } else {
8962 wtoken.startingView = view;
8963 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008964 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008965 "Added starting " + wtoken
8966 + ": startingWindow="
8967 + wtoken.startingWindow + " startingView="
8968 + wtoken.startingView);
8969 }
8970
8971 if (abort) {
8972 try {
8973 mPolicy.removeStartingWindow(wtoken.token, view);
8974 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008975 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 }
8977 }
8978 }
8979 } break;
8980
8981 case REMOVE_STARTING: {
8982 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8983 IBinder token = null;
8984 View view = null;
8985 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008986 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 + wtoken + ": startingWindow="
8988 + wtoken.startingWindow + " startingView="
8989 + wtoken.startingView);
8990 if (wtoken.startingWindow != null) {
8991 view = wtoken.startingView;
8992 token = wtoken.token;
8993 wtoken.startingData = null;
8994 wtoken.startingView = null;
8995 wtoken.startingWindow = null;
8996 }
8997 }
8998 if (view != null) {
8999 try {
9000 mPolicy.removeStartingWindow(token, view);
9001 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009002 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009003 }
9004 }
9005 } break;
9006
9007 case FINISHED_STARTING: {
9008 IBinder token = null;
9009 View view = null;
9010 while (true) {
9011 synchronized (mWindowMap) {
9012 final int N = mFinishedStarting.size();
9013 if (N <= 0) {
9014 break;
9015 }
9016 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9017
Joe Onorato8a9b2202010-02-26 18:56:32 -08009018 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 "Finished starting " + wtoken
9020 + ": startingWindow=" + wtoken.startingWindow
9021 + " startingView=" + wtoken.startingView);
9022
9023 if (wtoken.startingWindow == null) {
9024 continue;
9025 }
9026
9027 view = wtoken.startingView;
9028 token = wtoken.token;
9029 wtoken.startingData = null;
9030 wtoken.startingView = null;
9031 wtoken.startingWindow = null;
9032 }
9033
9034 try {
9035 mPolicy.removeStartingWindow(token, view);
9036 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009037 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009038 }
9039 }
9040 } break;
9041
9042 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9043 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9044
9045 boolean nowVisible = msg.arg1 != 0;
9046 boolean nowGone = msg.arg2 != 0;
9047
9048 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009049 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009050 TAG, "Reporting visible in " + wtoken
9051 + " visible=" + nowVisible
9052 + " gone=" + nowGone);
9053 if (nowVisible) {
9054 wtoken.appToken.windowsVisible();
9055 } else {
9056 wtoken.appToken.windowsGone();
9057 }
9058 } catch (RemoteException ex) {
9059 }
9060 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009062 case WINDOW_FREEZE_TIMEOUT: {
9063 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009064 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009065 int i = mWindows.size();
9066 while (i > 0) {
9067 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009068 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009069 if (w.mOrientationChanging) {
9070 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009071 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009072 }
9073 }
9074 performLayoutAndPlaceSurfacesLocked();
9075 }
9076 break;
9077 }
Romain Guy06882f82009-06-10 13:36:04 -07009078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009079 case HOLD_SCREEN_CHANGED: {
9080 Session oldHold;
9081 Session newHold;
9082 synchronized (mWindowMap) {
9083 oldHold = mLastReportedHold;
9084 newHold = (Session)msg.obj;
9085 mLastReportedHold = newHold;
9086 }
Romain Guy06882f82009-06-10 13:36:04 -07009087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009088 if (oldHold != newHold) {
9089 try {
9090 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009091 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009092 "window",
9093 BatteryStats.WAKE_TYPE_WINDOW);
9094 }
9095 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009096 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009097 "window",
9098 BatteryStats.WAKE_TYPE_WINDOW);
9099 }
9100 } catch (RemoteException e) {
9101 }
9102 }
9103 break;
9104 }
Romain Guy06882f82009-06-10 13:36:04 -07009105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009106 case APP_TRANSITION_TIMEOUT: {
9107 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009108 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009109 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009110 "*** APP TRANSITION TIMEOUT");
9111 mAppTransitionReady = true;
9112 mAppTransitionTimeout = true;
9113 performLayoutAndPlaceSurfacesLocked();
9114 }
9115 }
9116 break;
9117 }
Romain Guy06882f82009-06-10 13:36:04 -07009118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009119 case PERSIST_ANIMATION_SCALE: {
9120 Settings.System.putFloat(mContext.getContentResolver(),
9121 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9122 Settings.System.putFloat(mContext.getContentResolver(),
9123 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9124 break;
9125 }
Romain Guy06882f82009-06-10 13:36:04 -07009126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009127 case FORCE_GC: {
9128 synchronized(mWindowMap) {
9129 if (mAnimationPending) {
9130 // If we are animating, don't do the gc now but
9131 // delay a bit so we don't interrupt the animation.
9132 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9133 2000);
9134 return;
9135 }
9136 // If we are currently rotating the display, it will
9137 // schedule a new message when done.
9138 if (mDisplayFrozen) {
9139 return;
9140 }
9141 mFreezeGcPending = 0;
9142 }
9143 Runtime.getRuntime().gc();
9144 break;
9145 }
Romain Guy06882f82009-06-10 13:36:04 -07009146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009147 case ENABLE_SCREEN: {
9148 performEnableScreen();
9149 break;
9150 }
Romain Guy06882f82009-06-10 13:36:04 -07009151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009152 case APP_FREEZE_TIMEOUT: {
9153 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009154 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009155 int i = mAppTokens.size();
9156 while (i > 0) {
9157 i--;
9158 AppWindowToken tok = mAppTokens.get(i);
9159 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009160 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009161 unsetAppFreezingScreenLocked(tok, true, true);
9162 }
9163 }
9164 }
9165 break;
9166 }
Romain Guy06882f82009-06-10 13:36:04 -07009167
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009168 case SEND_NEW_CONFIGURATION: {
9169 removeMessages(SEND_NEW_CONFIGURATION);
9170 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009171 break;
9172 }
Romain Guy06882f82009-06-10 13:36:04 -07009173
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009174 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009175 if (mWindowsChanged) {
9176 synchronized (mWindowMap) {
9177 mWindowsChanged = false;
9178 }
9179 notifyWindowsChanged();
9180 }
9181 break;
9182 }
9183
Christopher Tatea53146c2010-09-07 11:57:52 -07009184 case DRAG_START_TIMEOUT: {
9185 IBinder win = (IBinder)msg.obj;
9186 if (DEBUG_DRAG) {
9187 Slog.w(TAG, "Timeout starting drag by win " + win);
9188 }
9189 synchronized (mWindowMap) {
9190 // !!! TODO: ANR the app that has failed to start the drag in time
9191 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07009192 mDragState.unregister();
Jeff Brown3a22cd92011-01-21 13:59:04 -08009193 mInputMonitor.setUpdateInputWindowsNeededLw();
Chris Tated4533f12010-10-19 15:15:08 -07009194 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07009195 mDragState.reset();
9196 mDragState = null;
9197 }
9198 }
Chris Tated4533f12010-10-19 15:15:08 -07009199 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009200 }
9201
Chris Tated4533f12010-10-19 15:15:08 -07009202 case DRAG_END_TIMEOUT: {
9203 IBinder win = (IBinder)msg.obj;
9204 if (DEBUG_DRAG) {
9205 Slog.w(TAG, "Timeout ending drag to win " + win);
9206 }
9207 synchronized (mWindowMap) {
9208 // !!! TODO: ANR the drag-receiving app
9209 mDragState.mDragResult = false;
9210 mDragState.endDragLw();
9211 }
9212 break;
9213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009214 }
9215 }
9216 }
9217
9218 // -------------------------------------------------------------
9219 // IWindowManager API
9220 // -------------------------------------------------------------
9221
9222 public IWindowSession openSession(IInputMethodClient client,
9223 IInputContext inputContext) {
9224 if (client == null) throw new IllegalArgumentException("null client");
9225 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07009226 Session session = new Session(client, inputContext);
9227 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009228 }
9229
9230 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9231 synchronized (mWindowMap) {
9232 // The focus for the client is the window immediately below
9233 // where we would place the input method window.
9234 int idx = findDesiredInputMethodWindowIndexLocked(false);
9235 WindowState imFocus;
9236 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009237 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009238 if (imFocus != null) {
9239 if (imFocus.mSession.mClient != null &&
9240 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9241 return true;
9242 }
9243 }
9244 }
9245 }
9246 return false;
9247 }
Romain Guy06882f82009-06-10 13:36:04 -07009248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 // -------------------------------------------------------------
9250 // Internals
9251 // -------------------------------------------------------------
9252
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009253 final WindowState windowForClientLocked(Session session, IWindow client,
9254 boolean throwOnError) {
9255 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009256 }
Romain Guy06882f82009-06-10 13:36:04 -07009257
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009258 final WindowState windowForClientLocked(Session session, IBinder client,
9259 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009261 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 TAG, "Looking up client " + client + ": " + win);
9263 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009264 RuntimeException ex = new IllegalArgumentException(
9265 "Requested window " + client + " does not exist");
9266 if (throwOnError) {
9267 throw ex;
9268 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009269 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 return null;
9271 }
9272 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009273 RuntimeException ex = new IllegalArgumentException(
9274 "Requested window " + client + " is in session " +
9275 win.mSession + ", not " + session);
9276 if (throwOnError) {
9277 throw ex;
9278 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009279 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009280 return null;
9281 }
9282
9283 return win;
9284 }
9285
Dianne Hackborna8f60182009-09-01 19:01:50 -07009286 final void rebuildAppWindowListLocked() {
9287 int NW = mWindows.size();
9288 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009289 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009290 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009291
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009292 if (mRebuildTmp.length < NW) {
9293 mRebuildTmp = new WindowState[NW+10];
9294 }
9295
Dianne Hackborna8f60182009-09-01 19:01:50 -07009296 // First remove all existing app windows.
9297 i=0;
9298 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009299 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009300 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009301 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009302 win.mRebuilding = true;
9303 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009304 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009305 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009306 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009307 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009308 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009309 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009310 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9311 && lastWallpaper == i-1) {
9312 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009313 }
9314 i++;
9315 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009316
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009317 // The wallpaper window(s) typically live at the bottom of the stack,
9318 // so skip them before adding app tokens.
9319 lastWallpaper++;
9320 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009321
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009322 // First add all of the exiting app tokens... these are no longer
9323 // in the main app list, but still have windows shown. We put them
9324 // in the back because now that the animation is over we no longer
9325 // will care about them.
9326 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009327 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009328 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9329 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009330
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009331 // And add in the still active app tokens in Z order.
9332 NT = mAppTokens.size();
9333 for (int j=0; j<NT; j++) {
9334 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009335 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009336
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009337 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009338 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009339 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009340 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009341 for (i=0; i<numRemoved; i++) {
9342 WindowState ws = mRebuildTmp[i];
9343 if (ws.mRebuilding) {
9344 StringWriter sw = new StringWriter();
9345 PrintWriter pw = new PrintWriter(sw);
9346 ws.dump(pw, "");
9347 pw.flush();
9348 Slog.w(TAG, "This window was lost: " + ws);
9349 Slog.w(TAG, sw.toString());
9350 }
9351 }
9352 Slog.w(TAG, "Current app token list:");
9353 dumpAppTokensLocked();
9354 Slog.w(TAG, "Final window list:");
9355 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009356 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009357 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009359 private final void assignLayersLocked() {
9360 int N = mWindows.size();
9361 int curBaseLayer = 0;
9362 int curLayer = 0;
9363 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009364
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009365 if (DEBUG_LAYERS) {
9366 RuntimeException here = new RuntimeException("here");
9367 here.fillInStackTrace();
9368 Log.v(TAG, "Assigning layers", here);
9369 }
9370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009372 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009373 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9374 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009375 curLayer += WINDOW_LAYER_MULTIPLIER;
9376 w.mLayer = curLayer;
9377 } else {
9378 curBaseLayer = curLayer = w.mBaseLayer;
9379 w.mLayer = curLayer;
9380 }
9381 if (w.mTargetAppToken != null) {
9382 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9383 } else if (w.mAppToken != null) {
9384 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9385 } else {
9386 w.mAnimLayer = w.mLayer;
9387 }
9388 if (w.mIsImWindow) {
9389 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009390 } else if (w.mIsWallpaper) {
9391 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009393 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009394 + w.mAnimLayer);
9395 //System.out.println(
9396 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9397 }
9398 }
9399
9400 private boolean mInLayout = false;
9401 private final void performLayoutAndPlaceSurfacesLocked() {
9402 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009403 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 throw new RuntimeException("Recursive call!");
9405 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009406 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 return;
9408 }
9409
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009410 if (mWaitingForConfig) {
9411 // Our configuration has changed (most likely rotation), but we
9412 // don't yet have the complete configuration to report to
9413 // applications. Don't do any window layout until we have it.
9414 return;
9415 }
9416
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009417 if (mDisplay == null) {
9418 // Not yet initialized, nothing to do.
9419 return;
9420 }
9421
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009422 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009423 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009424
9425 try {
9426 if (mForceRemoves != null) {
9427 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009428 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009429 for (int i=0; i<mForceRemoves.size(); i++) {
9430 WindowState ws = mForceRemoves.get(i);
9431 Slog.i(TAG, "Force removing: " + ws);
9432 removeWindowInnerLocked(ws.mSession, ws);
9433 }
9434 mForceRemoves = null;
9435 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9436 Object tmp = new Object();
9437 synchronized (tmp) {
9438 try {
9439 tmp.wait(250);
9440 } catch (InterruptedException e) {
9441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 }
9443 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009444 } catch (RuntimeException e) {
9445 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009446 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009448 try {
9449 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009450
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009451 int N = mPendingRemove.size();
9452 if (N > 0) {
9453 if (mPendingRemoveTmp.length < N) {
9454 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009455 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009456 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009457 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009458 for (int i=0; i<N; i++) {
9459 WindowState w = mPendingRemoveTmp[i];
9460 removeWindowInnerLocked(w.mSession, w);
9461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009462
9463 mInLayout = false;
9464 assignLayersLocked();
9465 mLayoutNeeded = true;
9466 performLayoutAndPlaceSurfacesLocked();
9467
9468 } else {
9469 mInLayout = false;
9470 if (mLayoutNeeded) {
9471 requestAnimationLocked(0);
9472 }
9473 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009474 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009475 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9476 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009477 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009478 } catch (RuntimeException e) {
9479 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009480 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009481 }
9482 }
9483
Jeff Brown3a22cd92011-01-21 13:59:04 -08009484 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009485 if (!mLayoutNeeded) {
9486 return 0;
9487 }
9488
9489 mLayoutNeeded = false;
9490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 final int dw = mDisplay.getWidth();
9492 final int dh = mDisplay.getHeight();
9493
9494 final int N = mWindows.size();
9495 int i;
9496
Joe Onorato8a9b2202010-02-26 18:56:32 -08009497 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009498 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9499
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009500 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009501
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009502 int seq = mLayoutSeq+1;
9503 if (seq < 0) seq = 0;
9504 mLayoutSeq = seq;
9505
9506 // First perform layout of any root windows (not attached
9507 // to another window).
9508 int topAttached = -1;
9509 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009510 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009511
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009512 // Don't do layout of a window if it is not visible, or
9513 // soon won't be visible, to avoid wasting time and funky
9514 // changes while a window is animating away.
9515 final AppWindowToken atoken = win.mAppToken;
9516 final boolean gone = win.mViewVisibility == View.GONE
9517 || !win.mRelayoutCalled
9518 || win.mRootToken.hidden
9519 || (atoken != null && atoken.hiddenRequested)
9520 || win.mAttachedHidden
9521 || win.mExiting || win.mDestroying;
9522
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009523 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9524 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009525 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9526 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009527 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009528 + win.mViewVisibility + " mRelayoutCalled="
9529 + win.mRelayoutCalled + " hidden="
9530 + win.mRootToken.hidden + " hiddenRequested="
9531 + (atoken != null && atoken.hiddenRequested)
9532 + " mAttachedHidden=" + win.mAttachedHidden);
9533 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009534
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009535 // If this view is GONE, then skip it -- keep the current
9536 // frame, and let the caller know so they can ignore it
9537 // if they want. (We do the normal layout for INVISIBLE
9538 // windows, since that means "perform layout as normal,
9539 // just don't display").
9540 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009541 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009542 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009543 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009544 win.mContentChanged = false;
9545 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009546 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9547 win.mLayoutSeq = seq;
9548 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9549 + win.mFrame + " mContainingFrame="
9550 + win.mContainingFrame + " mDisplayFrame="
9551 + win.mDisplayFrame);
9552 } else {
9553 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009554 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009556 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009557
9558 // Now perform layout of attached windows, which usually
9559 // depend on the position of the window they are attached to.
9560 // XXX does not deal with windows that are attached to windows
9561 // that are themselves attached.
9562 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009563 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009564
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009565 if (win.mLayoutAttached) {
9566 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9567 + " mHaveFrame=" + win.mHaveFrame
9568 + " mViewVisibility=" + win.mViewVisibility
9569 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009570 // If this view is GONE, then skip it -- keep the current
9571 // frame, and let the caller know so they can ignore it
9572 // if they want. (We do the normal layout for INVISIBLE
9573 // windows, since that means "perform layout as normal,
9574 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009575 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9576 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009577 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009578 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009579 win.mContentChanged = false;
9580 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009581 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9582 win.mLayoutSeq = seq;
9583 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9584 + win.mFrame + " mContainingFrame="
9585 + win.mContainingFrame + " mDisplayFrame="
9586 + win.mDisplayFrame);
9587 }
9588 }
9589 }
Jeff Brown349703e2010-06-22 01:27:15 -07009590
9591 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009592 mInputMonitor.setUpdateInputWindowsNeededLw();
9593 if (updateInputWindows) {
9594 mInputMonitor.updateInputWindowsLw();
9595 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009596
9597 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009598 }
Romain Guy06882f82009-06-10 13:36:04 -07009599
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009600 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009601 private final void performLayoutAndPlaceSurfacesLockedInner(
9602 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009603 if (mDisplay == null) {
9604 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9605 return;
9606 }
9607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009608 final long currentTime = SystemClock.uptimeMillis();
9609 final int dw = mDisplay.getWidth();
9610 final int dh = mDisplay.getHeight();
9611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009612 int i;
9613
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009614 if (mFocusMayChange) {
9615 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009616 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9617 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009618 }
9619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009620 // Initialize state of exiting tokens.
9621 for (i=mExitingTokens.size()-1; i>=0; i--) {
9622 mExitingTokens.get(i).hasVisible = false;
9623 }
9624
9625 // Initialize state of exiting applications.
9626 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9627 mExitingAppTokens.get(i).hasVisible = false;
9628 }
9629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630 boolean orientationChangeComplete = true;
9631 Session holdScreen = null;
9632 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009633 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009634 boolean focusDisplayed = false;
9635 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009636 boolean createWatermark = false;
9637
9638 if (mFxSession == null) {
9639 mFxSession = new SurfaceSession();
9640 createWatermark = true;
9641 }
9642
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009643 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009644
9645 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009646
9647 if (createWatermark) {
9648 createWatermark();
9649 }
9650 if (mWatermark != null) {
9651 mWatermark.positionSurface(dw, dh);
9652 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009653 if (mStrictModeFlash != null) {
9654 mStrictModeFlash.positionSurface(dw, dh);
9655 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009657 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009658 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009659 int repeats = 0;
9660 int changes = 0;
9661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009662 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009663 repeats++;
9664 if (repeats > 6) {
9665 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9666 mLayoutNeeded = false;
9667 break;
9668 }
9669
9670 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9671 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9672 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9673 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9674 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9675 assignLayersLocked();
9676 mLayoutNeeded = true;
9677 }
9678 }
9679 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9680 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009681 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009682 mLayoutNeeded = true;
9683 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9684 }
9685 }
9686 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9687 mLayoutNeeded = true;
9688 }
9689 }
9690
9691 // FIRST LOOP: Perform a layout, if needed.
9692 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009693 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009694 if (changes != 0) {
9695 continue;
9696 }
9697 } else {
9698 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9699 changes = 0;
9700 }
9701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 final int transactionSequence = ++mTransactionSequence;
9703
9704 // Update animations of all applications, including those
9705 // associated with exiting/removed apps
9706 boolean tokensAnimating = false;
9707 final int NAT = mAppTokens.size();
9708 for (i=0; i<NAT; i++) {
9709 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9710 tokensAnimating = true;
9711 }
9712 }
9713 final int NEAT = mExitingAppTokens.size();
9714 for (i=0; i<NEAT; i++) {
9715 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9716 tokensAnimating = true;
9717 }
9718 }
9719
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009720 // SECOND LOOP: Execute animations and update visibility of windows.
9721
Joe Onorato8a9b2202010-02-26 18:56:32 -08009722 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009723 + transactionSequence + " tokensAnimating="
9724 + tokensAnimating);
9725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009726 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009728 if (mScreenRotationAnimation != null) {
9729 if (mScreenRotationAnimation.isAnimating()) {
9730 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9731 animating = true;
9732 } else {
9733 mScreenRotationAnimation = null;
9734 }
9735 }
9736 }
9737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009739 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009740 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009741 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742
9743 mPolicy.beginAnimationLw(dw, dh);
9744
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009745 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009748 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009749
9750 final WindowManager.LayoutParams attrs = w.mAttrs;
9751
9752 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009753 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009754 if (w.commitFinishDrawingLocked(currentTime)) {
9755 if ((w.mAttrs.flags
9756 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009757 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009758 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009759 wallpaperMayChange = true;
9760 }
9761 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009762
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009763 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009764
9765 int animDw = dw;
9766 int animDh = dh;
9767
9768 // If the window has moved due to its containing
9769 // content frame changing, then we'd like to animate
9770 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009771 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009772 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009773 // Frame has moved, containing content frame
9774 // has also moved, and we're not currently animating...
9775 // let's do something.
9776 Animation a = AnimationUtils.loadAnimation(mContext,
9777 com.android.internal.R.anim.window_move_from_decor);
9778 w.setAnimation(a);
9779 animDw = w.mLastFrame.left - w.mFrame.left;
9780 animDh = w.mLastFrame.top - w.mFrame.top;
9781 }
9782
9783 // Execute animation.
9784 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9785 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009786
9787 // If this window is animating, make a note that we have
9788 // an animating window and take care of a request to run
9789 // a detached wallpaper animation.
9790 if (nowAnimating) {
9791 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9792 windowDetachedWallpaper = w;
9793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009796
9797 // If this window's app token is running a detached wallpaper
9798 // animation, make a note so we can ensure the wallpaper is
9799 // displayed behind it.
9800 if (w.mAppToken != null && w.mAppToken.animation != null
9801 && w.mAppToken.animation.getDetachWallpaper()) {
9802 windowDetachedWallpaper = w;
9803 }
9804
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009805 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9806 wallpaperMayChange = true;
9807 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009808
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009809 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009810 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009811 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009812 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009813 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009814 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009815 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009816 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9817 forceHiding = true;
9818 }
9819 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9820 boolean changed;
9821 if (forceHiding) {
9822 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009823 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9824 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009825 } else {
9826 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009827 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9828 "Now policy shown: " + w);
9829 if (changed) {
9830 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009831 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009832 // Assume we will need to animate. If
9833 // we don't (because the wallpaper will
9834 // stay with the lock screen), then we will
9835 // clean up later.
9836 Animation a = mPolicy.createForceHideEnterAnimation();
9837 if (a != null) {
9838 w.setAnimation(a);
9839 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009840 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009841 if (mCurrentFocus == null ||
9842 mCurrentFocus.mLayer < w.mLayer) {
9843 // We are showing on to of the current
9844 // focus, so re-evaluate focus to make
9845 // sure it is correct.
9846 mFocusMayChange = true;
9847 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009848 }
9849 }
9850 if (changed && (attrs.flags
9851 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9852 wallpaperMayChange = true;
9853 }
9854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856 mPolicy.animatingWindowLw(w, attrs);
9857 }
9858
9859 final AppWindowToken atoken = w.mAppToken;
9860 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9861 if (atoken.lastTransactionSequence != transactionSequence) {
9862 atoken.lastTransactionSequence = transactionSequence;
9863 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9864 atoken.startingDisplayed = false;
9865 }
9866 if ((w.isOnScreen() || w.mAttrs.type
9867 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9868 && !w.mExiting && !w.mDestroying) {
9869 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009870 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009871 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009873 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009874 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009875 + " pv=" + w.mPolicyVisibility
9876 + " dp=" + w.mDrawPending
9877 + " cdp=" + w.mCommitDrawPending
9878 + " ah=" + w.mAttachedHidden
9879 + " th=" + atoken.hiddenRequested
9880 + " a=" + w.mAnimating);
9881 }
9882 }
9883 if (w != atoken.startingWindow) {
9884 if (!atoken.freezingScreen || !w.mAppFreezing) {
9885 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009886 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009888 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889 "tokenMayBeDrawn: " + atoken
9890 + " freezingScreen=" + atoken.freezingScreen
9891 + " mAppFreezing=" + w.mAppFreezing);
9892 tokenMayBeDrawn = true;
9893 }
9894 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009895 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 atoken.startingDisplayed = true;
9897 }
9898 }
9899 } else if (w.mReadyToShow) {
9900 w.performShowLocked();
9901 }
9902 }
9903
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009904 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009905
9906 if (tokenMayBeDrawn) {
9907 // See if any windows have been drawn, so they (and others
9908 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009909 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009910 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009911 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009912 if (wtoken.freezingScreen) {
9913 int numInteresting = wtoken.numInterestingWindows;
9914 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009915 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009916 "allDrawn: " + wtoken
9917 + " interesting=" + numInteresting
9918 + " drawn=" + wtoken.numDrawnWindows);
9919 wtoken.showAllWindowsLocked();
9920 unsetAppFreezingScreenLocked(wtoken, false, true);
9921 orientationChangeComplete = true;
9922 }
9923 } else if (!wtoken.allDrawn) {
9924 int numInteresting = wtoken.numInterestingWindows;
9925 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009926 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009927 "allDrawn: " + wtoken
9928 + " interesting=" + numInteresting
9929 + " drawn=" + wtoken.numDrawnWindows);
9930 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009931 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009932
9933 // We can now show all of the drawn windows!
9934 if (!mOpeningApps.contains(wtoken)) {
9935 wtoken.showAllWindowsLocked();
9936 }
9937 }
9938 }
9939 }
9940 }
9941
9942 // If we are ready to perform an app transition, check through
9943 // all of the app tokens to be shown and see if they are ready
9944 // to go.
9945 if (mAppTransitionReady) {
9946 int NN = mOpeningApps.size();
9947 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009948 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009949 "Checking " + NN + " opening apps (frozen="
9950 + mDisplayFrozen + " timeout="
9951 + mAppTransitionTimeout + ")...");
9952 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9953 // If the display isn't frozen, wait to do anything until
9954 // all of the apps are ready. Otherwise just go because
9955 // we'll unfreeze the display when everyone is ready.
9956 for (i=0; i<NN && goodToGo; i++) {
9957 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009958 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009959 "Check opening app" + wtoken + ": allDrawn="
9960 + wtoken.allDrawn + " startingDisplayed="
9961 + wtoken.startingDisplayed);
9962 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9963 && !wtoken.startingMoved) {
9964 goodToGo = false;
9965 }
9966 }
9967 }
9968 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009969 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009970 int transit = mNextAppTransition;
9971 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009972 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009973 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009974 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009976 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009977 mAppTransitionTimeout = false;
9978 mStartingIconInTransition = false;
9979 mSkipAppTransitionAnimation = false;
9980
9981 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9982
Dianne Hackborna8f60182009-09-01 19:01:50 -07009983 // If there are applications waiting to come to the
9984 // top of the stack, now is the time to move their windows.
9985 // (Note that we don't do apps going to the bottom
9986 // here -- we want to keep their windows in the old
9987 // Z-order until the animation completes.)
9988 if (mToTopApps.size() > 0) {
9989 NN = mAppTokens.size();
9990 for (i=0; i<NN; i++) {
9991 AppWindowToken wtoken = mAppTokens.get(i);
9992 if (wtoken.sendingToTop) {
9993 wtoken.sendingToTop = false;
9994 moveAppWindowsLocked(wtoken, NN, false);
9995 }
9996 }
9997 mToTopApps.clear();
9998 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009999
Dianne Hackborn25994b42009-09-04 14:21:19 -070010000 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010001
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010002 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010003 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010004
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010005 // The top-most window will supply the layout params,
10006 // and we will determine it below.
10007 LayoutParams animLp = null;
10008 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010009 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010010
Joe Onorato8a9b2202010-02-26 18:56:32 -080010011 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010012 "New wallpaper target=" + mWallpaperTarget
10013 + ", lower target=" + mLowerWallpaperTarget
10014 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010015 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010016 // Do a first pass through the tokens for two
10017 // things:
10018 // (1) Determine if both the closing and opening
10019 // app token sets are wallpaper targets, in which
10020 // case special animations are needed
10021 // (since the wallpaper needs to stay static
10022 // behind them).
10023 // (2) Find the layout params of the top-most
10024 // application window in the tokens, which is
10025 // what will control the animation theme.
10026 final int NC = mClosingApps.size();
10027 NN = NC + mOpeningApps.size();
10028 for (i=0; i<NN; i++) {
10029 AppWindowToken wtoken;
10030 int mode;
10031 if (i < NC) {
10032 wtoken = mClosingApps.get(i);
10033 mode = 1;
10034 } else {
10035 wtoken = mOpeningApps.get(i-NC);
10036 mode = 2;
10037 }
10038 if (mLowerWallpaperTarget != null) {
10039 if (mLowerWallpaperTarget.mAppToken == wtoken
10040 || mUpperWallpaperTarget.mAppToken == wtoken) {
10041 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010042 }
10043 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010044 if (wtoken.appFullscreen) {
10045 WindowState ws = wtoken.findMainWindow();
10046 if (ws != null) {
10047 // If this is a compatibility mode
10048 // window, we will always use its anim.
10049 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10050 animLp = ws.mAttrs;
10051 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010052 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010053 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010054 bestAnimLayer = ws.mLayer;
10055 }
10056 fullscreenAnim = true;
10057 }
10058 } else if (!fullscreenAnim) {
10059 WindowState ws = wtoken.findMainWindow();
10060 if (ws != null) {
10061 if (ws.mLayer > bestAnimLayer) {
10062 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010063 bestAnimLayer = ws.mLayer;
10064 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010065 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010066 }
10067 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010068
Dianne Hackborn25994b42009-09-04 14:21:19 -070010069 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010070 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010071 "Wallpaper animation!");
10072 switch (transit) {
10073 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10074 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10075 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10076 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10077 break;
10078 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10079 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10080 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10081 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10082 break;
10083 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010084 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010085 "New transit: " + transit);
10086 } else if (oldWallpaper != null) {
10087 // We are transitioning from an activity with
10088 // a wallpaper to one without.
10089 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010090 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010091 "New transit away from wallpaper: " + transit);
10092 } else if (mWallpaperTarget != null) {
10093 // We are transitioning from an activity without
10094 // a wallpaper to now showing the wallpaper
10095 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010096 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010097 "New transit into wallpaper: " + transit);
10098 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010099
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010100 // If all closing windows are obscured, then there is
10101 // no need to do an animation. This is the case, for
10102 // example, when this transition is being done behind
10103 // the lock screen.
10104 if (!mPolicy.allowAppAnimationsLw()) {
10105 animLp = null;
10106 }
10107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010108 NN = mOpeningApps.size();
10109 for (i=0; i<NN; i++) {
10110 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010111 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 "Now opening app" + wtoken);
10113 wtoken.reportedVisible = false;
10114 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010115 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010116 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010118 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010119 wtoken.showAllWindowsLocked();
10120 }
10121 NN = mClosingApps.size();
10122 for (i=0; i<NN; i++) {
10123 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010124 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010125 "Now closing app" + wtoken);
10126 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010127 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010128 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010130 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010131 // Force the allDrawn flag, because we want to start
10132 // this guy's animations regardless of whether it's
10133 // gotten drawn.
10134 wtoken.allDrawn = true;
10135 }
10136
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010137 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010139 mOpeningApps.clear();
10140 mClosingApps.clear();
10141
10142 // This has changed the visibility of windows, so perform
10143 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010144 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10145 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010146 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010147 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10148 assignLayersLocked();
10149 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010150 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10151 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010152 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010153 }
10154 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010155
Dianne Hackborn16064f92010-03-25 00:47:24 -070010156 int adjResult = 0;
10157
Dianne Hackborna8f60182009-09-01 19:01:50 -070010158 if (!animating && mAppTransitionRunning) {
10159 // We have finished the animation of an app transition. To do
10160 // this, we have delayed a lot of operations like showing and
10161 // hiding apps, moving apps in Z-order, etc. The app token list
10162 // reflects the correct Z-order, but the window list may now
10163 // be out of sync with it. So here we will just rebuild the
10164 // entire app window list. Fun!
10165 mAppTransitionRunning = false;
10166 // Clear information about apps that were moving.
10167 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010168
Dianne Hackborna8f60182009-09-01 19:01:50 -070010169 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010170 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010171 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010172 moveInputMethodWindowsIfNeededLocked(false);
10173 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010174 // Since the window list has been rebuilt, focus might
10175 // have to be recomputed since the actual order of windows
10176 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010177 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010178 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010179
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010180 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010181 // At this point, there was a window with a wallpaper that
10182 // was force hiding other windows behind it, but now it
10183 // is going away. This may be simple -- just animate
10184 // away the wallpaper and its window -- or it may be
10185 // hard -- the wallpaper now needs to be shown behind
10186 // something that was hidden.
10187 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010188 if (mLowerWallpaperTarget != null
10189 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010190 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010191 "wallpaperForceHiding changed with lower="
10192 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010193 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010194 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10195 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10196 if (mLowerWallpaperTarget.mAppToken.hidden) {
10197 // The lower target has become hidden before we
10198 // actually started the animation... let's completely
10199 // re-evaluate everything.
10200 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010201 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010202 }
10203 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010204 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010205 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010206 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010207 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010208 + " NEW: " + mWallpaperTarget
10209 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010210 if (mLowerWallpaperTarget == null) {
10211 // Whoops, we don't need a special wallpaper animation.
10212 // Clear them out.
10213 forceHiding = false;
10214 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010215 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010216 if (w.mSurface != null) {
10217 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010218 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010219 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010220 forceHiding = true;
10221 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10222 if (!w.mAnimating) {
10223 // We set the animation above so it
10224 // is not yet running.
10225 w.clearAnimation();
10226 }
10227 }
10228 }
10229 }
10230 }
10231 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010232
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010233 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10234 if (DEBUG_WALLPAPER) Slog.v(TAG,
10235 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10236 + windowDetachedWallpaper);
10237 mWindowDetachedWallpaper = windowDetachedWallpaper;
10238 wallpaperMayChange = true;
10239 }
10240
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010241 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010242 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010243 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010244 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010245 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010246
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010247 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010248 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010249 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010250 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010251 assignLayersLocked();
10252 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010253 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010254 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010255 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010257
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010258 if (mFocusMayChange) {
10259 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010260 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10261 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010262 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010263 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010264 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010265 }
10266
10267 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010268 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010270
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010271 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10272 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010273 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010274
10275 // THIRD LOOP: Update the surfaces of all windows.
10276
10277 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10278
10279 boolean obscured = false;
10280 boolean blurring = false;
10281 boolean dimming = false;
10282 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010283 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010284 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010285
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010286 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010288 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010289 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290
10291 boolean displayed = false;
10292 final WindowManager.LayoutParams attrs = w.mAttrs;
10293 final int attrFlags = attrs.flags;
10294
10295 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010296 // XXX NOTE: The logic here could be improved. We have
10297 // the decision about whether to resize a window separated
10298 // from whether to hide the surface. This can cause us to
10299 // resize a surface even if we are going to hide it. You
10300 // can see this by (1) holding device in landscape mode on
10301 // home screen; (2) tapping browser icon (device will rotate
10302 // to landscape; (3) tap home. The wallpaper will be resized
10303 // in step 2 but then immediately hidden, causing us to
10304 // have to resize and then redraw it again in step 3. It
10305 // would be nice to figure out how to avoid this, but it is
10306 // difficult because we do need to resize surfaces in some
10307 // cases while they are hidden such as when first showing a
10308 // window.
10309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010310 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010311 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010312 TAG, "Placing surface #" + i + " " + w.mSurface
10313 + ": new=" + w.mShownFrame + ", old="
10314 + w.mLastShownFrame);
10315
10316 boolean resize;
10317 int width, height;
10318 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
10319 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
10320 w.mLastRequestedHeight != w.mRequestedHeight;
10321 // for a scaled surface, we just want to use
10322 // the requested size.
10323 width = w.mRequestedWidth;
10324 height = w.mRequestedHeight;
10325 w.mLastRequestedWidth = width;
10326 w.mLastRequestedHeight = height;
10327 w.mLastShownFrame.set(w.mShownFrame);
10328 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010329 if (SHOW_TRANSACTIONS) logSurface(w,
10330 "POS " + w.mShownFrame.left
10331 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010332 w.mSurfaceX = w.mShownFrame.left;
10333 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010334 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10335 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010336 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010337 if (!recoveringMemory) {
10338 reclaimSomeSurfaceMemoryLocked(w, "position");
10339 }
10340 }
10341 } else {
10342 resize = !w.mLastShownFrame.equals(w.mShownFrame);
10343 width = w.mShownFrame.width();
10344 height = w.mShownFrame.height();
10345 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 }
10347
10348 if (resize) {
10349 if (width < 1) width = 1;
10350 if (height < 1) height = 1;
10351 if (w.mSurface != null) {
10352 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010353 if (SHOW_TRANSACTIONS) logSurface(w,
10354 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010355 + w.mShownFrame.top + " SIZE "
10356 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010357 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010358 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010359 w.mSurfaceW = width;
10360 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010361 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010362 w.mSurfaceX = w.mShownFrame.left;
10363 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010364 w.mSurface.setPosition(w.mShownFrame.left,
10365 w.mShownFrame.top);
10366 } catch (RuntimeException e) {
10367 // If something goes wrong with the surface (such
10368 // as running out of memory), don't take down the
10369 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010370 Slog.e(TAG, "Failure updating surface of " + w
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010371 + " size=(" + width + "x" + height
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010372 + "), pos=(" + w.mShownFrame.left
10373 + "," + w.mShownFrame.top + ")", e);
10374 if (!recoveringMemory) {
10375 reclaimSomeSurfaceMemoryLocked(w, "size");
10376 }
10377 }
10378 }
10379 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010380 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010381 w.mContentInsetsChanged =
10382 !w.mLastContentInsets.equals(w.mContentInsets);
10383 w.mVisibleInsetsChanged =
10384 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010385 boolean configChanged =
10386 w.mConfiguration != mCurConfiguration
10387 && (w.mConfiguration == null
10388 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010389 if (DEBUG_CONFIGURATION && configChanged) {
10390 Slog.v(TAG, "Win " + w + " config changed: "
10391 + mCurConfiguration);
10392 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010393 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010394 + ": configChanged=" + configChanged
10395 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -070010396 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010397 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010398 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010399 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010400 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 w.mLastFrame.set(w.mFrame);
10402 w.mLastContentInsets.set(w.mContentInsets);
10403 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010404 // If the screen is currently frozen, then keep
10405 // it frozen until this window draws at its new
10406 // orientation.
10407 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010408 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010409 "Resizing while display frozen: " + w);
10410 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010411 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010412 mWindowsFreezingScreen = true;
10413 // XXX should probably keep timeout from
10414 // when we first froze the display.
10415 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10416 mH.sendMessageDelayed(mH.obtainMessage(
10417 H.WINDOW_FREEZE_TIMEOUT), 2000);
10418 }
10419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010420 // If the orientation is changing, then we need to
10421 // hold off on unfreezing the display until this
10422 // window has been redrawn; to do that, we need
10423 // to go through the process of getting informed
10424 // by the application when it has finished drawing.
10425 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010426 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427 "Orientation start waiting for draw in "
10428 + w + ", surface " + w.mSurface);
10429 w.mDrawPending = true;
10430 w.mCommitDrawPending = false;
10431 w.mReadyToShow = false;
10432 if (w.mAppToken != null) {
10433 w.mAppToken.allDrawn = false;
10434 }
10435 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010436 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 "Resizing window " + w + " to " + w.mFrame);
10438 mResizingWindows.add(w);
10439 } else if (w.mOrientationChanging) {
10440 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010441 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 "Orientation not waiting for draw in "
10443 + w + ", surface " + w.mSurface);
10444 w.mOrientationChanging = false;
10445 }
10446 }
10447 }
10448
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010449 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 if (!w.mLastHidden) {
10451 //dump();
10452 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010453 if (SHOW_TRANSACTIONS) logSurface(w,
10454 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010456 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 try {
10458 w.mSurface.hide();
10459 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010460 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 }
10462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 }
10464 // If we are waiting for this window to handle an
10465 // orientation change, well, it is hidden, so
10466 // doesn't really matter. Note that this does
10467 // introduce a potential glitch if the window
10468 // becomes unhidden before it has drawn for the
10469 // new orientation.
10470 if (w.mOrientationChanging) {
10471 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010472 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 "Orientation change skips hidden " + w);
10474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 } else if (w.mLastLayer != w.mAnimLayer
10476 || w.mLastAlpha != w.mShownAlpha
10477 || w.mLastDsDx != w.mDsDx
10478 || w.mLastDtDx != w.mDtDx
10479 || w.mLastDsDy != w.mDsDy
10480 || w.mLastDtDy != w.mDtDy
10481 || w.mLastHScale != w.mHScale
10482 || w.mLastVScale != w.mVScale
10483 || w.mLastHidden) {
10484 displayed = true;
10485 w.mLastAlpha = w.mShownAlpha;
10486 w.mLastLayer = w.mAnimLayer;
10487 w.mLastDsDx = w.mDsDx;
10488 w.mLastDtDx = w.mDtDx;
10489 w.mLastDsDy = w.mDsDy;
10490 w.mLastDtDy = w.mDtDy;
10491 w.mLastHScale = w.mHScale;
10492 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010493 if (SHOW_TRANSACTIONS) logSurface(w,
10494 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010495 + " matrix=[" + (w.mDsDx*w.mHScale)
10496 + "," + (w.mDtDx*w.mVScale)
10497 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010498 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 if (w.mSurface != null) {
10500 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010501 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010503 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 w.mSurface.setLayer(w.mAnimLayer);
10505 w.mSurface.setMatrix(
10506 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10507 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10508 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010509 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010510 if (!recoveringMemory) {
10511 reclaimSomeSurfaceMemoryLocked(w, "update");
10512 }
10513 }
10514 }
10515
10516 if (w.mLastHidden && !w.mDrawPending
10517 && !w.mCommitDrawPending
10518 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010519 if (SHOW_TRANSACTIONS) logSurface(w,
10520 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010521 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010522 + " during relayout");
10523 if (showSurfaceRobustlyLocked(w)) {
10524 w.mHasDrawn = true;
10525 w.mLastHidden = false;
10526 } else {
10527 w.mOrientationChanging = false;
10528 }
10529 }
10530 if (w.mSurface != null) {
10531 w.mToken.hasVisible = true;
10532 }
10533 } else {
10534 displayed = true;
10535 }
10536
10537 if (displayed) {
10538 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010539 if (attrs.width == LayoutParams.MATCH_PARENT
10540 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010541 covered = true;
10542 }
10543 }
10544 if (w.mOrientationChanging) {
10545 if (w.mDrawPending || w.mCommitDrawPending) {
10546 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010547 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 "Orientation continue waiting for draw in " + w);
10549 } else {
10550 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010551 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 "Orientation change complete in " + w);
10553 }
10554 }
10555 w.mToken.hasVisible = true;
10556 }
10557 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010558 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010559 "Orientation change skips hidden " + w);
10560 w.mOrientationChanging = false;
10561 }
10562
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010563 if (w.mContentChanged) {
10564 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10565 w.mContentChanged = false;
10566 }
10567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010568 final boolean canBeSeen = w.isDisplayedLw();
10569
10570 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10571 focusDisplayed = true;
10572 }
10573
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010574 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010576 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010577 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 if (w.mSurface != null) {
10579 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10580 holdScreen = w.mSession;
10581 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010582 if (!syswin && w.mAttrs.screenBrightness >= 0
10583 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 screenBrightness = w.mAttrs.screenBrightness;
10585 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010586 if (!syswin && w.mAttrs.buttonBrightness >= 0
10587 && buttonBrightness < 0) {
10588 buttonBrightness = w.mAttrs.buttonBrightness;
10589 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010590 if (canBeSeen
10591 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10592 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10593 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010594 syswin = true;
10595 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010597
Dianne Hackborn25994b42009-09-04 14:21:19 -070010598 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10599 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010600 // This window completely covers everything behind it,
10601 // so we want to leave all of them as unblurred (for
10602 // performance reasons).
10603 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010604 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010605 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010606 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010607 obscured = true;
10608 if (mBackgroundFillerSurface == null) {
10609 try {
10610 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010611 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010612 0, dw, dh,
10613 PixelFormat.OPAQUE,
10614 Surface.FX_SURFACE_NORMAL);
10615 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010616 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010617 }
10618 }
10619 try {
10620 mBackgroundFillerSurface.setPosition(0, 0);
10621 mBackgroundFillerSurface.setSize(dw, dh);
10622 // Using the same layer as Dim because they will never be shown at the
10623 // same time.
10624 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10625 mBackgroundFillerSurface.show();
10626 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010627 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010628 }
10629 backgroundFillerShown = true;
10630 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010631 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010633 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010634 + ": blurring=" + blurring
10635 + " obscured=" + obscured
10636 + " displayed=" + displayed);
10637 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10638 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010639 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010640 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010641 if (mDimAnimator == null) {
10642 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010643 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010644 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010645 mDimAnimator.updateParameters(mContext.getResources(),
10646 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010648 }
10649 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10650 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010651 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010652 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010653 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010654 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 + mBlurSurface + ": CREATE");
10656 try {
Romain Guy06882f82009-06-10 13:36:04 -070010657 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010658 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 -1, 16, 16,
10660 PixelFormat.OPAQUE,
10661 Surface.FX_SURFACE_BLUR);
10662 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010663 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 }
10665 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010667 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10668 + mBlurSurface + ": pos=(0,0) (" +
10669 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 mBlurSurface.setPosition(0, 0);
10671 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010672 mBlurSurface.setLayer(w.mAnimLayer-2);
10673 if (!mBlurShown) {
10674 try {
10675 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10676 + mBlurSurface + ": SHOW");
10677 mBlurSurface.show();
10678 } catch (RuntimeException e) {
10679 Slog.w(TAG, "Failure showing blur surface", e);
10680 }
10681 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010682 }
10683 }
10684 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010685 }
10686 }
10687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010688
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010689 if (obscuredChanged && mWallpaperTarget == w) {
10690 // This is the wallpaper target and its obscured state
10691 // changed... make sure the current wallaper's visibility
10692 // has been updated accordingly.
10693 updateWallpaperVisibilityLocked();
10694 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010695 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010696
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010697 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10698 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010699 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010700 try {
10701 mBackgroundFillerSurface.hide();
10702 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010703 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010704 }
10705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010706
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010707 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010708 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10709 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710 }
Romain Guy06882f82009-06-10 13:36:04 -070010711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010712 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010713 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010714 + ": HIDE");
10715 try {
10716 mBlurSurface.hide();
10717 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010718 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010719 }
10720 mBlurShown = false;
10721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010723 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010724 }
10725
10726 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010727
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010728 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10729
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010730 if (mWatermark != null) {
10731 mWatermark.drawIfNeeded();
10732 }
10733
Joe Onorato8a9b2202010-02-26 18:56:32 -080010734 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 "With display frozen, orientationChangeComplete="
10736 + orientationChangeComplete);
10737 if (orientationChangeComplete) {
10738 if (mWindowsFreezingScreen) {
10739 mWindowsFreezingScreen = false;
10740 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10741 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010742 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010743 }
Romain Guy06882f82009-06-10 13:36:04 -070010744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010745 i = mResizingWindows.size();
10746 if (i > 0) {
10747 do {
10748 i--;
10749 WindowState win = mResizingWindows.get(i);
10750 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010751 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10752 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010753 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010754 boolean configChanged =
10755 win.mConfiguration != mCurConfiguration
10756 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010757 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10758 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10759 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010760 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010761 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010762 + " / " + mCurConfiguration + " / 0x"
10763 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010764 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010765 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010766 win.mClient.resized(win.mFrame.width(),
10767 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010768 win.mLastVisibleInsets, win.mDrawPending,
10769 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 win.mContentInsetsChanged = false;
10771 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010772 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010773 } catch (RemoteException e) {
10774 win.mOrientationChanging = false;
10775 }
10776 } while (i > 0);
10777 mResizingWindows.clear();
10778 }
Romain Guy06882f82009-06-10 13:36:04 -070010779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010780 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010781 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010782 i = mDestroySurface.size();
10783 if (i > 0) {
10784 do {
10785 i--;
10786 WindowState win = mDestroySurface.get(i);
10787 win.mDestroying = false;
10788 if (mInputMethodWindow == win) {
10789 mInputMethodWindow = null;
10790 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010791 if (win == mWallpaperTarget) {
10792 wallpaperDestroyed = true;
10793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010794 win.destroySurfaceLocked();
10795 } while (i > 0);
10796 mDestroySurface.clear();
10797 }
10798
10799 // Time to remove any exiting tokens?
10800 for (i=mExitingTokens.size()-1; i>=0; i--) {
10801 WindowToken token = mExitingTokens.get(i);
10802 if (!token.hasVisible) {
10803 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010804 if (token.windowType == TYPE_WALLPAPER) {
10805 mWallpaperTokens.remove(token);
10806 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010807 }
10808 }
10809
10810 // Time to remove any exiting applications?
10811 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10812 AppWindowToken token = mExitingAppTokens.get(i);
10813 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010814 // Make sure there is no animation running on this token,
10815 // so any windows associated with it will be removed as
10816 // soon as their animations are complete
10817 token.animation = null;
10818 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010819 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10820 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010821 mAppTokens.remove(token);
10822 mExitingAppTokens.remove(i);
10823 }
10824 }
10825
Dianne Hackborna8f60182009-09-01 19:01:50 -070010826 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010827
Dianne Hackborna8f60182009-09-01 19:01:50 -070010828 if (!animating && mAppTransitionRunning) {
10829 // We have finished the animation of an app transition. To do
10830 // this, we have delayed a lot of operations like showing and
10831 // hiding apps, moving apps in Z-order, etc. The app token list
10832 // reflects the correct Z-order, but the window list may now
10833 // be out of sync with it. So here we will just rebuild the
10834 // entire app window list. Fun!
10835 mAppTransitionRunning = false;
10836 needRelayout = true;
10837 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010838 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010839 // Clear information about apps that were moving.
10840 mToBottomApps.clear();
10841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010843 if (focusDisplayed) {
10844 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10845 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010846 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010847 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010848 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010849 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010850 requestAnimationLocked(0);
10851 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010852 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10853 }
Jeff Browneb857f12010-07-16 10:06:33 -070010854
Jeff Brown3a22cd92011-01-21 13:59:04 -080010855 // Finally update all input windows now that the window changes have stabilized.
10856 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Browne33348b2010-07-15 23:54:05 -070010857 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010858
Jeff Brown8e03b752010-06-13 19:16:55 -070010859 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010860 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10861 mPowerManager.setScreenBrightnessOverride(-1);
10862 } else {
10863 mPowerManager.setScreenBrightnessOverride((int)
10864 (screenBrightness * Power.BRIGHTNESS_ON));
10865 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010866 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10867 mPowerManager.setButtonBrightnessOverride(-1);
10868 } else {
10869 mPowerManager.setButtonBrightnessOverride((int)
10870 (buttonBrightness * Power.BRIGHTNESS_ON));
10871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010872 if (holdScreen != mHoldingScreenOn) {
10873 mHoldingScreenOn = holdScreen;
10874 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10875 mH.sendMessage(m);
10876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010877
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010878 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010879 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010880 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10881 LocalPowerManager.BUTTON_EVENT, true);
10882 mTurnOnScreen = false;
10883 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010884
10885 // Check to see if we are now in a state where the screen should
10886 // be enabled, because the window obscured flags have changed.
10887 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010888 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010889
10890 /**
10891 * Must be called with the main window manager lock held.
10892 */
10893 void setHoldScreenLocked(boolean holding) {
10894 boolean state = mHoldingScreenWakeLock.isHeld();
10895 if (holding != state) {
10896 if (holding) {
10897 mHoldingScreenWakeLock.acquire();
10898 } else {
10899 mPolicy.screenOnStoppedLw();
10900 mHoldingScreenWakeLock.release();
10901 }
10902 }
10903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904
10905 void requestAnimationLocked(long delay) {
10906 if (!mAnimationPending) {
10907 mAnimationPending = true;
10908 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10909 }
10910 }
Romain Guy06882f82009-06-10 13:36:04 -070010911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912 /**
10913 * Have the surface flinger show a surface, robustly dealing with
10914 * error conditions. In particular, if there is not enough memory
10915 * to show the surface, then we will try to get rid of other surfaces
10916 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010917 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010918 * @return Returns true if the surface was successfully shown.
10919 */
10920 boolean showSurfaceRobustlyLocked(WindowState win) {
10921 try {
10922 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010923 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010925 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010926 if (DEBUG_VISIBILITY) Slog.v(TAG,
10927 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010928 win.mTurnOnScreen = false;
10929 mTurnOnScreen = true;
10930 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010931 }
10932 return true;
10933 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010934 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010935 }
Romain Guy06882f82009-06-10 13:36:04 -070010936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010937 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 return false;
10940 }
Romain Guy06882f82009-06-10 13:36:04 -070010941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010942 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10943 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010944
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010945 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010946 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010948 if (mForceRemoves == null) {
10949 mForceRemoves = new ArrayList<WindowState>();
10950 }
Romain Guy06882f82009-06-10 13:36:04 -070010951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010952 long callingIdentity = Binder.clearCallingIdentity();
10953 try {
10954 // There was some problem... first, do a sanity check of the
10955 // window list to make sure we haven't left any dangling surfaces
10956 // around.
10957 int N = mWindows.size();
10958 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010959 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010960 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010961 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010962 if (ws.mSurface != null) {
10963 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010964 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010965 + ws + " surface=" + ws.mSurface
10966 + " token=" + win.mToken
10967 + " pid=" + ws.mSession.mPid
10968 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010969 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010970 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010971 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010972 ws.mSurface = null;
10973 mForceRemoves.add(ws);
10974 i--;
10975 N--;
10976 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010977 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010978 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010979 + ws + " surface=" + ws.mSurface
10980 + " token=" + win.mAppToken);
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 leakedSurface = true;
10986 }
10987 }
10988 }
Romain Guy06882f82009-06-10 13:36:04 -070010989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010990 boolean killedApps = false;
10991 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010992 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010993 SparseIntArray pidCandidates = new SparseIntArray();
10994 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010995 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010996 if (ws.mSurface != null) {
10997 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10998 }
10999 }
11000 if (pidCandidates.size() > 0) {
11001 int[] pids = new int[pidCandidates.size()];
11002 for (int i=0; i<pids.length; i++) {
11003 pids[i] = pidCandidates.keyAt(i);
11004 }
11005 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011006 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 killedApps = true;
11008 }
11009 } catch (RemoteException e) {
11010 }
11011 }
11012 }
Romain Guy06882f82009-06-10 13:36:04 -070011013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011014 if (leakedSurface || killedApps) {
11015 // We managed to reclaim some memory, so get rid of the trouble
11016 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011017 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011018 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011019 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011020 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011021 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011022 win.mSurface = null;
11023 }
Romain Guy06882f82009-06-10 13:36:04 -070011024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011025 try {
11026 win.mClient.dispatchGetNewSurface();
11027 } catch (RemoteException e) {
11028 }
11029 }
11030 } finally {
11031 Binder.restoreCallingIdentity(callingIdentity);
11032 }
11033 }
Romain Guy06882f82009-06-10 13:36:04 -070011034
Jeff Brown3a22cd92011-01-21 13:59:04 -080011035 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011036 WindowState newFocus = computeFocusedWindowLocked();
11037 if (mCurrentFocus != newFocus) {
11038 // This check makes sure that we don't already have the focus
11039 // change message pending.
11040 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11041 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011042 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011043 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11044 final WindowState oldFocus = mCurrentFocus;
11045 mCurrentFocus = newFocus;
11046 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011048 final WindowState imWindow = mInputMethodWindow;
11049 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011050 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011051 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011052 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11053 mLayoutNeeded = true;
11054 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011055 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011056 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011057 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11058 // Client will do the layout, but we need to assign layers
11059 // for handleNewWindowLocked() below.
11060 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011061 }
11062 }
Jeff Brown349703e2010-06-22 01:27:15 -070011063
11064 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11065 // If we defer assigning layers, then the caller is responsible for
11066 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011067 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011069 return true;
11070 }
11071 return false;
11072 }
Jeff Brown349703e2010-06-22 01:27:15 -070011073
Jeff Brown3a22cd92011-01-21 13:59:04 -080011074 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11075 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011077
11078 private WindowState computeFocusedWindowLocked() {
11079 WindowState result = null;
11080 WindowState win;
11081
11082 int i = mWindows.size() - 1;
11083 int nextAppIndex = mAppTokens.size()-1;
11084 WindowToken nextApp = nextAppIndex >= 0
11085 ? mAppTokens.get(nextAppIndex) : null;
11086
11087 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011088 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011089
Joe Onorato8a9b2202010-02-26 18:56:32 -080011090 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011091 TAG, "Looking for focus: " + i
11092 + " = " + win
11093 + ", flags=" + win.mAttrs.flags
11094 + ", canReceive=" + win.canReceiveKeys());
11095
11096 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011098 // If this window's application has been removed, just skip it.
11099 if (thisApp != null && thisApp.removed) {
11100 i--;
11101 continue;
11102 }
Romain Guy06882f82009-06-10 13:36:04 -070011103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011104 // If there is a focused app, don't allow focus to go to any
11105 // windows below it. If this is an application window, step
11106 // through the app tokens until we find its app.
11107 if (thisApp != null && nextApp != null && thisApp != nextApp
11108 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11109 int origAppIndex = nextAppIndex;
11110 while (nextAppIndex > 0) {
11111 if (nextApp == mFocusedApp) {
11112 // Whoops, we are below the focused app... no focus
11113 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011114 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 TAG, "Reached focused app: " + mFocusedApp);
11116 return null;
11117 }
11118 nextAppIndex--;
11119 nextApp = mAppTokens.get(nextAppIndex);
11120 if (nextApp == thisApp) {
11121 break;
11122 }
11123 }
11124 if (thisApp != nextApp) {
11125 // Uh oh, the app token doesn't exist! This shouldn't
11126 // happen, but if it does we can get totally hosed...
11127 // so restart at the original app.
11128 nextAppIndex = origAppIndex;
11129 nextApp = mAppTokens.get(nextAppIndex);
11130 }
11131 }
11132
11133 // Dispatch to this window if it is wants key events.
11134 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011135 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011136 TAG, "Found focus @ " + i + " = " + win);
11137 result = win;
11138 break;
11139 }
11140
11141 i--;
11142 }
11143
11144 return result;
11145 }
11146
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011147 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011148 if (mDisplayFrozen) {
11149 return;
11150 }
Romain Guy06882f82009-06-10 13:36:04 -070011151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011152 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011154 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011155 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011156 if (mFreezeGcPending != 0) {
11157 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011158 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011159 mH.removeMessages(H.FORCE_GC);
11160 Runtime.getRuntime().gc();
11161 mFreezeGcPending = now;
11162 }
11163 } else {
11164 mFreezeGcPending = now;
11165 }
Romain Guy06882f82009-06-10 13:36:04 -070011166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011167 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011168
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011169 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011170
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011171 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11172 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011173 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011174 mAppTransitionReady = true;
11175 }
Romain Guy06882f82009-06-10 13:36:04 -070011176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011177 if (PROFILE_ORIENTATION) {
11178 File file = new File("/data/system/frozen");
11179 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11180 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011181
11182 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011183 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11184 mScreenRotationAnimation.kill();
11185 mScreenRotationAnimation = null;
11186 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011187 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011188 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011189 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011190 }
11191 } else {
11192 Surface.freezeDisplay(0);
11193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011194 }
Romain Guy06882f82009-06-10 13:36:04 -070011195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011196 private void stopFreezingDisplayLocked() {
11197 if (!mDisplayFrozen) {
11198 return;
11199 }
Romain Guy06882f82009-06-10 13:36:04 -070011200
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011201 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11202 return;
11203 }
11204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011205 mDisplayFrozen = false;
11206 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11207 if (PROFILE_ORIENTATION) {
11208 Debug.stopMethodTracing();
11209 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011210
11211 if (CUSTOM_SCREEN_ROTATION) {
11212 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011213 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11214 mTransitionAnimationScale)) {
11215 requestAnimationLocked(0);
11216 } else {
11217 mScreenRotationAnimation = null;
11218 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011219 }
11220 } else {
11221 Surface.unfreezeDisplay(0);
11222 }
Romain Guy06882f82009-06-10 13:36:04 -070011223
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011224 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011225
Christopher Tateb696aee2010-04-02 19:08:30 -070011226 // While the display is frozen we don't re-compute the orientation
11227 // to avoid inconsistent states. However, something interesting
11228 // could have actually changed during that time so re-evaluate it
11229 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011230 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011231 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11232 }
11233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011234 // A little kludge: a lot could have happened while the
11235 // display was frozen, so now that we are coming back we
11236 // do a gc so that any remote references the system
11237 // processes holds on others can be released if they are
11238 // no longer needed.
11239 mH.removeMessages(H.FORCE_GC);
11240 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11241 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011243 mScreenFrozenLock.release();
11244 }
Romain Guy06882f82009-06-10 13:36:04 -070011245
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011246 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11247 DisplayMetrics dm) {
11248 if (index < tokens.length) {
11249 String str = tokens[index];
11250 if (str != null && str.length() > 0) {
11251 try {
11252 int val = Integer.parseInt(str);
11253 return val;
11254 } catch (Exception e) {
11255 }
11256 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011257 }
11258 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11259 return defDps;
11260 }
11261 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11262 return val;
11263 }
11264
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011265 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011266 final String[] mTokens;
11267 final String mText;
11268 final Paint mTextPaint;
11269 final int mTextWidth;
11270 final int mTextHeight;
11271 final int mTextAscent;
11272 final int mTextDescent;
11273 final int mDeltaX;
11274 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011275
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011276 Surface mSurface;
11277 int mLastDW;
11278 int mLastDH;
11279 boolean mDrawNeeded;
11280
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011281 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011282 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011283 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011284
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011285 if (false) {
11286 Log.i(TAG, "*********************** WATERMARK");
11287 for (int i=0; i<tokens.length; i++) {
11288 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11289 }
11290 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011291
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011292 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011293
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011294 StringBuilder builder = new StringBuilder(32);
11295 int len = mTokens[0].length();
11296 len = len & ~1;
11297 for (int i=0; i<len; i+=2) {
11298 int c1 = mTokens[0].charAt(i);
11299 int c2 = mTokens[0].charAt(i+1);
11300 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11301 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11302 else c1 -= '0';
11303 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11304 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11305 else c2 -= '0';
11306 builder.append((char)(255-((c1*16)+c2)));
11307 }
11308 mText = builder.toString();
11309 if (false) {
11310 Log.i(TAG, "Final text: " + mText);
11311 }
11312
11313 int fontSize = getPropertyInt(tokens, 1,
11314 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11315
11316 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11317 mTextPaint.setTextSize(fontSize);
11318 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11319
11320 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11321 mTextWidth = (int)mTextPaint.measureText(mText);
11322 mTextAscent = fm.ascent;
11323 mTextDescent = fm.descent;
11324 mTextHeight = fm.descent - fm.ascent;
11325
11326 mDeltaX = getPropertyInt(tokens, 2,
11327 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11328 mDeltaY = getPropertyInt(tokens, 3,
11329 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11330 int shadowColor = getPropertyInt(tokens, 4,
11331 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11332 int color = getPropertyInt(tokens, 5,
11333 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11334 int shadowRadius = getPropertyInt(tokens, 6,
11335 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11336 int shadowDx = getPropertyInt(tokens, 8,
11337 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11338 int shadowDy = getPropertyInt(tokens, 9,
11339 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11340
11341 mTextPaint.setColor(color);
11342 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011343
11344 try {
11345 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011346 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011347 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011348 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011349 mSurface.show();
11350 } catch (OutOfResourcesException e) {
11351 }
11352 }
11353
11354 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011355 if (mLastDW != dw || mLastDH != dh) {
11356 mLastDW = dw;
11357 mLastDH = dh;
11358 mSurface.setSize(dw, dh);
11359 mDrawNeeded = true;
11360 }
11361 }
11362
11363 void drawIfNeeded() {
11364 if (mDrawNeeded) {
11365 final int dw = mLastDW;
11366 final int dh = mLastDH;
11367
11368 mDrawNeeded = false;
11369 Rect dirty = new Rect(0, 0, dw, dh);
11370 Canvas c = null;
11371 try {
11372 c = mSurface.lockCanvas(dirty);
11373 } catch (IllegalArgumentException e) {
11374 } catch (OutOfResourcesException e) {
11375 }
11376 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011377 c.drawColor(0, PorterDuff.Mode.CLEAR);
11378
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011379 int deltaX = mDeltaX;
11380 int deltaY = mDeltaY;
11381
11382 // deltaX shouldn't be close to a round fraction of our
11383 // x step, or else things will line up too much.
11384 int div = (dw+mTextWidth)/deltaX;
11385 int rem = (dw+mTextWidth) - (div*deltaX);
11386 int qdelta = deltaX/4;
11387 if (rem < qdelta || rem > (deltaX-qdelta)) {
11388 deltaX += deltaX/3;
11389 }
11390
11391 int y = -mTextHeight;
11392 int x = -mTextWidth;
11393 while (y < (dh+mTextHeight)) {
11394 c.drawText(mText, x, y, mTextPaint);
11395 x += deltaX;
11396 if (x >= dw) {
11397 x -= (dw+mTextWidth);
11398 y += deltaY;
11399 }
11400 }
11401 mSurface.unlockCanvasAndPost(c);
11402 }
11403 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011404 }
11405 }
11406
11407 void createWatermark() {
11408 if (mWatermark != null) {
11409 return;
11410 }
11411
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011412 File file = new File("/system/etc/setup.conf");
11413 FileInputStream in = null;
11414 try {
11415 in = new FileInputStream(file);
11416 DataInputStream ind = new DataInputStream(in);
11417 String line = ind.readLine();
11418 if (line != null) {
11419 String[] toks = line.split("%");
11420 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011421 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011422 }
11423 }
11424 } catch (FileNotFoundException e) {
11425 } catch (IOException e) {
11426 } finally {
11427 if (in != null) {
11428 try {
11429 in.close();
11430 } catch (IOException e) {
11431 }
11432 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011433 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011434 }
11435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011436 @Override
11437 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11438 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11439 != PackageManager.PERMISSION_GRANTED) {
11440 pw.println("Permission Denial: can't dump WindowManager from from pid="
11441 + Binder.getCallingPid()
11442 + ", uid=" + Binder.getCallingUid());
11443 return;
11444 }
Romain Guy06882f82009-06-10 13:36:04 -070011445
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011446 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011447 pw.println(" ");
11448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011449 synchronized(mWindowMap) {
11450 pw.println("Current Window Manager state:");
11451 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011452 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011453 pw.print(" Window #"); pw.print(i); pw.print(' ');
11454 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011455 w.dump(pw, " ");
11456 }
11457 if (mInputMethodDialogs.size() > 0) {
11458 pw.println(" ");
11459 pw.println(" Input method dialogs:");
11460 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11461 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011462 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011463 }
11464 }
11465 if (mPendingRemove.size() > 0) {
11466 pw.println(" ");
11467 pw.println(" Remove pending for:");
11468 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11469 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011470 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11471 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011472 w.dump(pw, " ");
11473 }
11474 }
11475 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11476 pw.println(" ");
11477 pw.println(" Windows force removing:");
11478 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11479 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011480 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11481 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011482 w.dump(pw, " ");
11483 }
11484 }
11485 if (mDestroySurface.size() > 0) {
11486 pw.println(" ");
11487 pw.println(" Windows waiting to destroy their surface:");
11488 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11489 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011490 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11491 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011492 w.dump(pw, " ");
11493 }
11494 }
11495 if (mLosingFocus.size() > 0) {
11496 pw.println(" ");
11497 pw.println(" Windows losing focus:");
11498 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11499 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011500 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11501 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011502 w.dump(pw, " ");
11503 }
11504 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011505 if (mResizingWindows.size() > 0) {
11506 pw.println(" ");
11507 pw.println(" Windows waiting to resize:");
11508 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11509 WindowState w = mResizingWindows.get(i);
11510 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11511 pw.print(w); pw.println(":");
11512 w.dump(pw, " ");
11513 }
11514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011515 if (mSessions.size() > 0) {
11516 pw.println(" ");
11517 pw.println(" All active sessions:");
11518 Iterator<Session> it = mSessions.iterator();
11519 while (it.hasNext()) {
11520 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011521 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011522 s.dump(pw, " ");
11523 }
11524 }
11525 if (mTokenMap.size() > 0) {
11526 pw.println(" ");
11527 pw.println(" All tokens:");
11528 Iterator<WindowToken> it = mTokenMap.values().iterator();
11529 while (it.hasNext()) {
11530 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011531 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011532 token.dump(pw, " ");
11533 }
11534 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011535 if (mWallpaperTokens.size() > 0) {
11536 pw.println(" ");
11537 pw.println(" Wallpaper tokens:");
11538 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11539 WindowToken token = mWallpaperTokens.get(i);
11540 pw.print(" Wallpaper #"); pw.print(i);
11541 pw.print(' '); pw.print(token); pw.println(':');
11542 token.dump(pw, " ");
11543 }
11544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011545 if (mAppTokens.size() > 0) {
11546 pw.println(" ");
11547 pw.println(" Application tokens in Z order:");
11548 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011549 pw.print(" App #"); pw.print(i); pw.print(": ");
11550 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011551 }
11552 }
11553 if (mFinishedStarting.size() > 0) {
11554 pw.println(" ");
11555 pw.println(" Finishing start of application tokens:");
11556 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11557 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011558 pw.print(" Finished Starting #"); pw.print(i);
11559 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011560 token.dump(pw, " ");
11561 }
11562 }
11563 if (mExitingTokens.size() > 0) {
11564 pw.println(" ");
11565 pw.println(" Exiting tokens:");
11566 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11567 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011568 pw.print(" Exiting #"); pw.print(i);
11569 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011570 token.dump(pw, " ");
11571 }
11572 }
11573 if (mExitingAppTokens.size() > 0) {
11574 pw.println(" ");
11575 pw.println(" Exiting application tokens:");
11576 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11577 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011578 pw.print(" Exiting App #"); pw.print(i);
11579 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011580 token.dump(pw, " ");
11581 }
11582 }
11583 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011584 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11585 pw.print(" mLastFocus="); pw.println(mLastFocus);
11586 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11587 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11588 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011589 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011590 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11591 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11592 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11593 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011594 if (mWindowDetachedWallpaper != null) {
11595 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11596 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011597 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11598 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11599 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011600 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11601 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11602 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11603 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011604 if (mDimAnimator != null) {
11605 mDimAnimator.printTo(pw);
11606 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011607 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011608 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011609 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011610 pw.print(mInputMethodAnimLayerAdjustment);
11611 pw.print(" mWallpaperAnimLayerAdjustment=");
11612 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011613 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11614 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011615 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11616 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011617 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11618 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011619 pw.print(" mRotation="); pw.print(mRotation);
11620 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11621 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11622 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11623 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11624 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11625 pw.print(" mNextAppTransition=0x");
11626 pw.print(Integer.toHexString(mNextAppTransition));
11627 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011628 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011629 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011630 if (mNextAppTransitionPackage != null) {
11631 pw.print(" mNextAppTransitionPackage=");
11632 pw.print(mNextAppTransitionPackage);
11633 pw.print(", mNextAppTransitionEnter=0x");
11634 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11635 pw.print(", mNextAppTransitionExit=0x");
11636 pw.print(Integer.toHexString(mNextAppTransitionExit));
11637 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011638 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11639 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11640 if (mOpeningApps.size() > 0) {
11641 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11642 }
11643 if (mClosingApps.size() > 0) {
11644 pw.print(" mClosingApps="); pw.println(mClosingApps);
11645 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011646 if (mToTopApps.size() > 0) {
11647 pw.print(" mToTopApps="); pw.println(mToTopApps);
11648 }
11649 if (mToBottomApps.size() > 0) {
11650 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11651 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011652 if (mDisplay != null) {
11653 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11654 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11655 } else {
11656 pw.println(" NO DISPLAY");
11657 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011658 pw.println(" Policy:");
11659 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011660 }
11661 }
11662
Jeff Brown349703e2010-06-22 01:27:15 -070011663 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011664 public void monitor() {
11665 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011666 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011667 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011668
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011669 /**
11670 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011671 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011672 */
11673 private static class DimAnimator {
11674 Surface mDimSurface;
11675 boolean mDimShown = false;
11676 float mDimCurrentAlpha;
11677 float mDimTargetAlpha;
11678 float mDimDeltaPerMs;
11679 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011680
11681 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011682
11683 DimAnimator (SurfaceSession session) {
11684 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011685 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011686 + mDimSurface + ": CREATE");
11687 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011688 mDimSurface = new Surface(session, 0,
11689 "DimSurface",
11690 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011691 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011692 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011693 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011694 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011695 }
11696 }
11697 }
11698
11699 /**
11700 * Show the dim surface.
11701 */
11702 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011703 if (!mDimShown) {
11704 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11705 dw + "x" + dh + ")");
11706 mDimShown = true;
11707 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011708 mLastDimWidth = dw;
11709 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011710 mDimSurface.setPosition(0, 0);
11711 mDimSurface.setSize(dw, dh);
11712 mDimSurface.show();
11713 } catch (RuntimeException e) {
11714 Slog.w(TAG, "Failure showing dim surface", e);
11715 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011716 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11717 mLastDimWidth = dw;
11718 mLastDimHeight = dh;
11719 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011720 }
11721 }
11722
11723 /**
11724 * Set's the dim surface's layer and update dim parameters that will be used in
11725 * {@link updateSurface} after all windows are examined.
11726 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011727 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011728 mDimSurface.setLayer(w.mAnimLayer-1);
11729
11730 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011731 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011732 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011733 if (mDimTargetAlpha != target) {
11734 // If the desired dim level has changed, then
11735 // start an animation to it.
11736 mLastDimAnimTime = currentTime;
11737 long duration = (w.mAnimating && w.mAnimation != null)
11738 ? w.mAnimation.computeDurationHint()
11739 : DEFAULT_DIM_DURATION;
11740 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011741 TypedValue tv = new TypedValue();
11742 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11743 tv, true);
11744 if (tv.type == TypedValue.TYPE_FRACTION) {
11745 duration = (long)tv.getFraction((float)duration, (float)duration);
11746 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11747 && tv.type <= TypedValue.TYPE_LAST_INT) {
11748 duration = tv.data;
11749 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011750 }
11751 if (duration < 1) {
11752 // Don't divide by zero
11753 duration = 1;
11754 }
11755 mDimTargetAlpha = target;
11756 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11757 }
11758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011759
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011760 /**
11761 * Updating the surface's alpha. Returns true if the animation continues, or returns
11762 * false when the animation is finished and the dim surface is hidden.
11763 */
11764 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11765 if (!dimming) {
11766 if (mDimTargetAlpha != 0) {
11767 mLastDimAnimTime = currentTime;
11768 mDimTargetAlpha = 0;
11769 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11770 }
11771 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011772
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011773 boolean animating = false;
11774 if (mLastDimAnimTime != 0) {
11775 mDimCurrentAlpha += mDimDeltaPerMs
11776 * (currentTime-mLastDimAnimTime);
11777 boolean more = true;
11778 if (displayFrozen) {
11779 // If the display is frozen, there is no reason to animate.
11780 more = false;
11781 } else if (mDimDeltaPerMs > 0) {
11782 if (mDimCurrentAlpha > mDimTargetAlpha) {
11783 more = false;
11784 }
11785 } else if (mDimDeltaPerMs < 0) {
11786 if (mDimCurrentAlpha < mDimTargetAlpha) {
11787 more = false;
11788 }
11789 } else {
11790 more = false;
11791 }
11792
11793 // Do we need to continue animating?
11794 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011795 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011796 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11797 mLastDimAnimTime = currentTime;
11798 mDimSurface.setAlpha(mDimCurrentAlpha);
11799 animating = true;
11800 } else {
11801 mDimCurrentAlpha = mDimTargetAlpha;
11802 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011803 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011804 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11805 mDimSurface.setAlpha(mDimCurrentAlpha);
11806 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011807 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011808 + ": HIDE");
11809 try {
11810 mDimSurface.hide();
11811 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011812 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011813 }
11814 mDimShown = false;
11815 }
11816 }
11817 }
11818 return animating;
11819 }
11820
11821 public void printTo(PrintWriter pw) {
11822 pw.print(" mDimShown="); pw.print(mDimShown);
11823 pw.print(" current="); pw.print(mDimCurrentAlpha);
11824 pw.print(" target="); pw.print(mDimTargetAlpha);
11825 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11826 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11827 }
11828 }
11829
11830 /**
11831 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11832 * This is used for opening/closing transition for apps in compatible mode.
11833 */
11834 private static class FadeInOutAnimation extends Animation {
11835 int mWidth;
11836 boolean mFadeIn;
11837
11838 public FadeInOutAnimation(boolean fadeIn) {
11839 setInterpolator(new AccelerateInterpolator());
11840 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11841 mFadeIn = fadeIn;
11842 }
11843
11844 @Override
11845 protected void applyTransformation(float interpolatedTime, Transformation t) {
11846 float x = interpolatedTime;
11847 if (!mFadeIn) {
11848 x = 1.0f - x; // reverse the interpolation for fade out
11849 }
11850 if (x < 0.5) {
11851 // move the window out of the screen.
11852 t.getMatrix().setTranslate(mWidth, 0);
11853 } else {
11854 t.getMatrix().setTranslate(0, 0);// show
11855 t.setAlpha((x - 0.5f) * 2);
11856 }
11857 }
11858
11859 @Override
11860 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11861 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11862 mWidth = width;
11863 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011864
11865 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011866 public int getZAdjustment() {
11867 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011868 }
11869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011870}