blob: e1c03d4fe6679b24661e9a59fe1e79c7b4b40fab [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;
Joe Onoratoac0ee892011-01-30 15:38:30 -080050import android.app.StatusBarManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070053import android.content.ClipData;
54import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070056import android.content.Intent;
57import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070060import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080062import android.content.res.Resources;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080063import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070068import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069import android.graphics.Rect;
70import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070071import android.graphics.Typeface;
72import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.BatteryStats;
74import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070075import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.Debug;
77import android.os.Handler;
78import android.os.IBinder;
79import android.os.LocalPowerManager;
80import android.os.Looper;
81import android.os.Message;
82import android.os.Parcel;
83import android.os.ParcelFileDescriptor;
84import android.os.Power;
85import android.os.PowerManager;
86import android.os.Process;
87import android.os.RemoteException;
88import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070089import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.os.SystemClock;
91import android.os.SystemProperties;
92import android.os.TokenWatcher;
93import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070094import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070096import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080097import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070099import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700101import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.Gravity;
103import android.view.IApplicationToken;
104import android.view.IOnKeyguardExitResult;
105import android.view.IRotationWatcher;
106import android.view.IWindow;
107import android.view.IWindowManager;
108import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700109import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700111import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700112import android.view.InputHandler;
113import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.KeyEvent;
115import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.Surface;
117import android.view.SurfaceSession;
118import android.view.View;
119import android.view.ViewTreeObserver;
120import android.view.WindowManager;
121import android.view.WindowManagerImpl;
122import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700123import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700125import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import android.view.animation.Animation;
127import android.view.animation.AnimationUtils;
128import android.view.animation.Transformation;
129
130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800153 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 static final boolean DEBUG_FOCUS = false;
155 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800156 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800157 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean DEBUG_LAYERS = false;
159 static final boolean DEBUG_INPUT = false;
160 static final boolean DEBUG_INPUT_METHOD = false;
161 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700162 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800163 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700165 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 static final boolean DEBUG_APP_TRANSITIONS = false;
167 static final boolean DEBUG_STARTING_WINDOW = false;
168 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700169 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800170 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700172 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 static final boolean PROFILE_ORIENTATION = false;
175 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700176 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to multiply the policy's type layer, to reserve room
179 * for multiple windows of the same type and Z-ordering adjustment
180 * with TYPE_LAYER_OFFSET. */
181 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
184 * or below others in the same layer. */
185 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 /** How much to increment the layer for each window, to reserve room
188 * for effect surfaces between them.
189 */
190 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 /** The maximum length we will accept for a loaded animation duration:
193 * this is 10 seconds.
194 */
195 static final int MAX_ANIMATION_DURATION = 10*1000;
196
197 /** Amount of time (in milliseconds) to animate the dim surface from one
198 * value to another, when no window animation is driving it.
199 */
200 static final int DEFAULT_DIM_DURATION = 200;
201
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700202 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
203 * compatible windows.
204 */
205 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
206
Dianne Hackborna1111872010-11-23 20:55:11 -0800207 /**
208 * If true, the window manager will do its own custom freezing and general
209 * management of the screen during rotation.
210 */
211 static final boolean CUSTOM_SCREEN_ROTATION = true;
212
Jeff Brown7fbdc842010-06-17 20:52:56 -0700213 // Maximum number of milliseconds to wait for input event injection.
214 // FIXME is this value reasonable?
215 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800216
217 // Maximum number of milliseconds to wait for input devices to be enumerated before
218 // proceding with safe mode detection.
219 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700220
221 // Default input dispatching timeout in nanoseconds.
222 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 static final int UPDATE_FOCUS_NORMAL = 0;
225 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
226 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
227 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700230 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
232 /**
233 * Condition waited on by {@link #reenableKeyguard} to know the call to
234 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 * This is set to true only if mKeyguardTokenWatcher.acquired() has
236 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500238 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239
Jim Miller284b62e2010-06-08 14:27:42 -0700240 private static final int ALLOW_DISABLE_YES = 1;
241 private static final int ALLOW_DISABLE_NO = 0;
242 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
243 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
244
Mike Lockwood983ee092009-11-22 01:42:24 -0500245 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
246 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700248 if (shouldAllowDisableKeyguard()) {
249 mPolicy.enableKeyguard(false);
250 mKeyguardDisabled = true;
251 } else {
252 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
255 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700256 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500257 synchronized (mKeyguardTokenWatcher) {
258 mKeyguardDisabled = false;
259 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 }
261 }
262 };
263
Jim Miller284b62e2010-06-08 14:27:42 -0700264 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
265 @Override
266 public void onReceive(Context context, Intent intent) {
267 mPolicy.enableKeyguard(true);
268 synchronized(mKeyguardTokenWatcher) {
269 // lazily evaluate this next time we're asked to disable keyguard
270 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
271 mKeyguardDisabled = false;
272 }
273 }
274 };
275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final Context mContext;
277
278 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
283
284 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 /**
289 * All currently active sessions with clients.
290 */
291 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 /**
294 * Mapping from an IWindow IBinder to the server's Window object.
295 * This is also used as the lock for all of our state.
296 */
297 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
298
299 /**
300 * Mapping from a token IBinder to a WindowToken object.
301 */
302 final HashMap<IBinder, WindowToken> mTokenMap =
303 new HashMap<IBinder, WindowToken>();
304
305 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 * Window tokens that are in the process of exiting, but still
307 * on screen for animations.
308 */
309 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
310
311 /**
312 * Z-ordered (bottom-most first) list of all application tokens, for
313 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800314 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 */
316 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
317
318 /**
319 * Application tokens that are in the process of exiting, but still
320 * on screen for animations.
321 */
322 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
323
324 /**
325 * List of window tokens that have finished starting their application,
326 * and now need to have the policy remove their windows.
327 */
328 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
329
330 /**
331 * Z-ordered (bottom-most first) list of all Window objects.
332 */
Jeff Browne33348b2010-07-15 23:54:05 -0700333 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334
335 /**
336 * Windows that are being resized. Used so we can tell the client about
337 * the resize after closing the transaction in which we resized the
338 * underlying surface.
339 */
340 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
341
342 /**
343 * Windows whose animations have ended and now must be removed.
344 */
345 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
346
347 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800348 * Used when processing mPendingRemove to avoid working on the original array.
349 */
350 WindowState[] mPendingRemoveTmp = new WindowState[20];
351
352 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 * Windows whose surface should be destroyed.
354 */
355 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
356
357 /**
358 * Windows that have lost input focus and are waiting for the new
359 * focus window to be displayed before they are told about this.
360 */
361 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
362
363 /**
364 * This is set when we have run out of memory, and will either be an empty
365 * list or contain windows that need to be force removed.
366 */
367 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700368
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800369 /**
370 * Used when rebuilding window list to keep track of windows that have
371 * been removed.
372 */
373 WindowState[] mRebuildTmp = new WindowState[20];
374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700378 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 Surface mBlurSurface;
380 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700381 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800382 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800383 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 final float[] mTmpFloats = new float[9];
388
389 boolean mSafeMode;
390 boolean mDisplayEnabled = false;
391 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700392 int mInitialDisplayWidth = 0;
393 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 int mRotation = 0;
395 int mRequestedRotation = 0;
396 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700397 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 ArrayList<IRotationWatcher> mRotationWatchers
399 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800400 int mDeferredRotation;
401 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 boolean mLayoutNeeded = true;
404 boolean mAnimationPending = false;
405 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 boolean mWindowsFreezingScreen = false;
408 long mFreezeGcPending = 0;
409 int mAppsFreezingScreen = 0;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 int mLayoutSeq = 0;
412
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800413 // State while inside of layoutAndPlaceSurfacesLocked().
414 boolean mFocusMayChange;
415
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800416 Configuration mCurConfiguration = new Configuration();
417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // This is held as long as we have the screen frozen, to give us time to
419 // perform a rotation animation when turning off shows the lock screen which
420 // changes the orientation.
421 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 // State management of app transitions. When we are preparing for a
424 // transition, mNextAppTransition will be the kind of transition to
425 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
426 // mOpeningApps and mClosingApps are the lists of tokens that will be
427 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700428 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700429 String mNextAppTransitionPackage;
430 int mNextAppTransitionEnter;
431 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700433 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 boolean mAppTransitionTimeout = false;
435 boolean mStartingIconInTransition = false;
436 boolean mSkipAppTransitionAnimation = false;
437 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
438 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700439 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
440 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 H mH = new H();
445
446 WindowState mCurrentFocus = null;
447 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 // This just indicates the window the input method is on top of, not
450 // necessarily the window its input is going to.
451 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 boolean mInputMethodTargetWaitingAnim;
453 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 WindowState mInputMethodWindow = null;
456 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
457
Jeff Brown2992ea72011-01-28 22:04:14 -0800458 boolean mHardKeyboardAvailable;
459 boolean mHardKeyboardEnabled;
460 OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
461
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700462 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800463
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700464 // If non-null, this is the currently visible window that is associated
465 // with the wallpaper.
466 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700467 // If non-null, we are in the middle of animating from one wallpaper target
468 // to another, and this is the lower one in Z-order.
469 WindowState mLowerWallpaperTarget = null;
470 // If non-null, we are in the middle of animating from one wallpaper target
471 // to another, and this is the higher one in Z-order.
472 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800473 // Window currently running an animation that has requested it be detached
474 // from the wallpaper. This means we need to ensure the wallpaper is
475 // visible behind it in case it animates in a way that would allow it to be
476 // seen.
477 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700478 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700479 float mLastWallpaperX = -1;
480 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800481 float mLastWallpaperXStep = -1;
482 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700483 // This is set when we are waiting for a wallpaper to tell us it is done
484 // changing its scroll position.
485 WindowState mWaitingOnWallpaper;
486 // The last time we had a timeout when waiting for a wallpaper.
487 long mLastWallpaperTimeoutTime;
488 // We give a wallpaper up to 150ms to finish scrolling.
489 static final long WALLPAPER_TIMEOUT = 150;
490 // Time we wait after a timeout before trying to wait again.
491 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 AppWindowToken mFocusedApp = null;
494
495 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 float mWindowAnimationScale = 1.0f;
498 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700499
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700500 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501
502 // Who is holding the screen on.
503 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700504 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700505
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700506 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700509 * Drag/drop state
510 */
511 class DragState {
512 IBinder mToken;
513 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800514 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700515 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700516 ClipData mData;
517 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700518 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700519 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700520 float mThumbOffsetX, mThumbOffsetY;
521 InputChannel mServerChannel, mClientChannel;
522 WindowState mTargetWindow;
523 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700524 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700525
Jeff Brownfbf09772011-01-16 14:06:57 -0800526 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700527
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800528 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700529 mToken = token;
530 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800531 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700532 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700533 mNotifiedWindows = new ArrayList<WindowState>();
534 }
535
536 void reset() {
537 if (mSurface != null) {
538 mSurface.destroy();
539 }
540 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800541 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700542 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700543 mToken = null;
544 mData = null;
545 mThumbOffsetX = mThumbOffsetY = 0;
546 mNotifiedWindows = null;
547 }
548
549 void register() {
550 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
551 if (mClientChannel != null) {
552 Slog.e(TAG, "Duplicate register of drag input channel");
553 } else {
554 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
555 mServerChannel = channels[0];
556 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800557 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700558 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
559 mH.getLooper().getQueue());
560 }
561 }
562
563 void unregister() {
564 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
565 if (mClientChannel == null) {
566 Slog.e(TAG, "Unregister of nonexistent drag input channel");
567 } else {
568 mInputManager.unregisterInputChannel(mServerChannel);
569 InputQueue.unregisterInputChannel(mClientChannel);
570 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700571 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700572 mClientChannel = null;
573 mServerChannel = null;
574 }
575 }
576
Chris Tatea32dcf72010-10-14 12:13:50 -0700577 int getDragLayerLw() {
578 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
579 * TYPE_LAYER_MULTIPLIER
580 + TYPE_LAYER_OFFSET;
581 }
582
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 /* call out to each visible window/session informing it about the drag
584 */
Chris Tateb8203e92010-10-12 14:23:21 -0700585 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700586 // Cache a base-class instance of the clip metadata so that parceling
587 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800588 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700590 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700591
592 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700593 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 }
595
Christopher Tate2c095f32010-10-04 14:13:40 -0700596 final int N = mWindows.size();
597 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700598 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700599 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700600 }
601
602 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
603 * designated window is potentially a drop recipient. There are race situations
604 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
605 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700606 *
607 * This method clones the 'event' parameter if it's being delivered to the same
608 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700609 */
Chris Tateb478f462010-10-15 16:02:26 -0700610 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
611 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700612 // Don't actually send the event if the drag is supposed to be pinned
613 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800614 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700615 final IBinder winBinder = newWin.mClient.asBinder();
616 if (winBinder != mLocalWin) {
617 if (DEBUG_DRAG) {
618 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
619 }
620 return;
621 }
622 }
623
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700624 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700625 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
626 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800627 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700628 try {
629 newWin.mClient.dispatchDragEvent(event);
630 // track each window that we've notified that the drag is starting
631 mNotifiedWindows.add(newWin);
632 } catch (RemoteException e) {
633 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700634 } finally {
635 // if the callee was local, the dispatch has already recycled the event
636 if (Process.myPid() != newWin.mSession.mPid) {
637 event.recycle();
638 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700639 }
640 }
641 }
642
643 /* helper - construct and send a DRAG_STARTED event only if the window has not
644 * previously been notified, i.e. it became visible after the drag operation
645 * was begun. This is a rare case.
646 */
647 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700648 if (mDragInProgress) {
649 // If we have sent the drag-started, we needn't do so again
650 for (WindowState ws : mNotifiedWindows) {
651 if (ws == newWin) {
652 return;
653 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700654 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700655 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700656 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700657 }
Chris Tateb478f462010-10-15 16:02:26 -0700658 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700659 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700660 }
661
Chris Tated4533f142010-10-19 15:15:08 -0700662 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700663 if (DEBUG_DRAG) {
664 Slog.d(TAG, "broadcasting DRAG_ENDED");
665 }
Chris Tated4533f142010-10-19 15:15:08 -0700666 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800667 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700668 for (WindowState ws: mNotifiedWindows) {
669 try {
670 ws.mClient.dispatchDragEvent(evt);
671 } catch (RemoteException e) {
672 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700673 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700674 }
Chris Tated4533f142010-10-19 15:15:08 -0700675 mNotifiedWindows.clear();
676 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700677 evt.recycle();
678 }
679
Chris Tated4533f142010-10-19 15:15:08 -0700680 void endDragLw() {
681 mDragState.broadcastDragEndedLw();
682
683 // stop intercepting input
684 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -0800685 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tated4533f142010-10-19 15:15:08 -0700686
687 // free our resources and drop all the object references
688 mDragState.reset();
689 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800690
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800691 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
692 boolean changed = setRotationUncheckedLocked(
693 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
694 if (changed) {
695 sendNewConfiguration();
Christopher Tateccd24de2011-01-12 15:02:55 -0800696 }
Chris Tated4533f142010-10-19 15:15:08 -0700697 }
698
Christopher Tatea53146c2010-09-07 11:57:52 -0700699 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700700 final int myPid = Process.myPid();
701
702 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800703 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800704 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800705 try {
706 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
707 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800708 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800709 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
710 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700711
712 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700713 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800714 if (touchedWin == null) {
715 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
716 return;
717 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800718 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700719 final IBinder touchedBinder = touchedWin.mClient.asBinder();
720 if (touchedBinder != mLocalWin) {
721 // This drag is pinned only to the originating window, but the drag
722 // point is outside that window. Pretend it's over empty space.
723 touchedWin = null;
724 }
725 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700726 try {
727 // have we dragged over a new window?
728 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
729 if (DEBUG_DRAG) {
730 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
731 }
732 // force DRAG_EXITED_EVENT if appropriate
733 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700734 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800735 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700736 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700737 if (myPid != mTargetWindow.mSession.mPid) {
738 evt.recycle();
739 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700740 }
741 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700742 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
744 }
745 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700746 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800747 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700748 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700749 if (myPid != touchedWin.mSession.mPid) {
750 evt.recycle();
751 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700752 }
753 } catch (RemoteException e) {
754 Slog.w(TAG, "can't send drag notification to windows");
755 }
756 mTargetWindow = touchedWin;
757 }
758
Chris Tated4533f142010-10-19 15:15:08 -0700759 // Tell the drop target about the data. Returns 'true' if we can immediately
760 // dispatch the global drag-ended message, 'false' if we need to wait for a
761 // result from the recipient.
762 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700763 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700764 if (touchedWin == null) {
765 // "drop" outside a valid window -- no recipient to apply a
766 // timeout to, and we can send the drag-ended message immediately.
767 mDragResult = false;
768 return true;
769 }
770
771 if (DEBUG_DRAG) {
772 Slog.d(TAG, "sending DROP to " + touchedWin);
773 }
774 final int myPid = Process.myPid();
775 final IBinder token = touchedWin.mClient.asBinder();
776 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
777 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800778 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700779 try {
780 touchedWin.mClient.dispatchDragEvent(evt);
781
782 // 5 second timeout for this window to respond to the drop
783 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
784 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
785 mH.sendMessageDelayed(msg, 5000);
786 } catch (RemoteException e) {
787 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
788 return true;
789 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700790 if (myPid != touchedWin.mSession.mPid) {
791 evt.recycle();
792 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700793 }
Chris Tated4533f142010-10-19 15:15:08 -0700794 mToken = token;
795 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700796 }
797
798 // Find the visible, touch-deliverable window under the given point
799 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
800 WindowState touchedWin = null;
801 final int x = (int) xf;
802 final int y = (int) yf;
803 final ArrayList<WindowState> windows = mWindows;
804 final int N = windows.size();
805 for (int i = N - 1; i >= 0; i--) {
806 WindowState child = windows.get(i);
807 final int flags = child.mAttrs.flags;
808 if (!child.isVisibleLw()) {
809 // not visible == don't tell about drags
810 continue;
811 }
812 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
813 // not touchable == don't tell about drags
814 continue;
815 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800816
817 child.getTouchableRegion(mTmpRegion);
818
Christopher Tatea53146c2010-09-07 11:57:52 -0700819 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800820 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
821 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
822 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700823 // Found it
824 touchedWin = child;
825 break;
826 }
827 }
828
829 return touchedWin;
830 }
831 }
832
833 DragState mDragState = null;
834 private final InputHandler mDragInputHandler = new BaseInputHandler() {
835 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700836 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
837 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700838 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700839 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
840 && mDragState != null) {
841 boolean endDrag = false;
842 final float newX = event.getRawX();
843 final float newY = event.getRawY();
844
Christopher Tatea53146c2010-09-07 11:57:52 -0700845 switch (event.getAction()) {
846 case MotionEvent.ACTION_DOWN: {
847 if (DEBUG_DRAG) {
848 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
849 }
850 } break;
851
852 case MotionEvent.ACTION_MOVE: {
853 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700854 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700855 mDragState.notifyMoveLw(newX, newY);
856 }
857 } break;
858
859 case MotionEvent.ACTION_UP: {
860 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
861 + newX + "," + newY);
862 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700863 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700864 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700865 } break;
866
867 case MotionEvent.ACTION_CANCEL: {
868 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
869 endDrag = true;
870 } break;
871 }
872
873 if (endDrag) {
874 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
875 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700876 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700877 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700878 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700879 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700880
881 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700882 }
883 } catch (Exception e) {
884 Slog.e(TAG, "Exception caught by drag handleMotion", e);
885 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700886 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700887 }
888 }
889 };
890
891 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 * Whether the UI is currently running in touch mode (not showing
893 * navigational focus because the user is directly pressing the screen).
894 */
895 boolean mInTouchMode = false;
896
897 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700898 private ArrayList<WindowChangeListener> mWindowChangeListeners =
899 new ArrayList<WindowChangeListener>();
900 private boolean mWindowsChanged = false;
901
902 public interface WindowChangeListener {
903 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700904 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906
Dianne Hackbornc485a602009-03-24 22:39:49 -0700907 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700908 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700909
910 // The frame use to limit the size of the app running in compatibility mode.
911 Rect mCompatibleScreenFrame = new Rect();
912 // The surface used to fill the outer rim of the app running in compatibility mode.
913 Surface mBackgroundFillerSurface = null;
914 boolean mBackgroundFillerShown = false;
915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 public static WindowManagerService main(Context context,
917 PowerManagerService pm, boolean haveInputMethods) {
918 WMThread thr = new WMThread(context, pm, haveInputMethods);
919 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 synchronized (thr) {
922 while (thr.mService == null) {
923 try {
924 thr.wait();
925 } catch (InterruptedException e) {
926 }
927 }
928 }
Romain Guy06882f82009-06-10 13:36:04 -0700929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 return thr.mService;
931 }
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 static class WMThread extends Thread {
934 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 private final Context mContext;
937 private final PowerManagerService mPM;
938 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 public WMThread(Context context, PowerManagerService pm,
941 boolean haveInputMethods) {
942 super("WindowManager");
943 mContext = context;
944 mPM = pm;
945 mHaveInputMethods = haveInputMethods;
946 }
Romain Guy06882f82009-06-10 13:36:04 -0700947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 public void run() {
949 Looper.prepare();
950 WindowManagerService s = new WindowManagerService(mContext, mPM,
951 mHaveInputMethods);
952 android.os.Process.setThreadPriority(
953 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700954 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 synchronized (this) {
957 mService = s;
958 notifyAll();
959 }
Romain Guy06882f82009-06-10 13:36:04 -0700960
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700961 // For debug builds, log event loop stalls to dropbox for analysis.
962 if (StrictMode.conditionallyEnableDebugLogging()) {
963 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
964 }
965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 Looper.loop();
967 }
968 }
969
970 static class PolicyThread extends Thread {
971 private final WindowManagerPolicy mPolicy;
972 private final WindowManagerService mService;
973 private final Context mContext;
974 private final PowerManagerService mPM;
975 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 public PolicyThread(WindowManagerPolicy policy,
978 WindowManagerService service, Context context,
979 PowerManagerService pm) {
980 super("WindowManagerPolicy");
981 mPolicy = policy;
982 mService = service;
983 mContext = context;
984 mPM = pm;
985 }
Romain Guy06882f82009-06-10 13:36:04 -0700986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 public void run() {
988 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800989 WindowManagerPolicyThread.set(this, Looper.myLooper());
990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800992 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 android.os.Process.setThreadPriority(
994 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700995 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 synchronized (this) {
999 mRunning = true;
1000 notifyAll();
1001 }
Romain Guy06882f82009-06-10 13:36:04 -07001002
Brad Fitzpatrickec062f62010-11-03 09:56:54 -07001003 // For debug builds, log event loop stalls to dropbox for analysis.
1004 if (StrictMode.conditionallyEnableDebugLogging()) {
1005 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1006 }
1007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 Looper.loop();
1009 }
1010 }
1011
1012 private WindowManagerService(Context context, PowerManagerService pm,
1013 boolean haveInputMethods) {
1014 mContext = context;
1015 mHaveInputMethods = haveInputMethods;
1016 mLimitedAlphaCompositing = context.getResources().getBoolean(
1017 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 mPowerManager = pm;
1020 mPowerManager.setPolicy(mPolicy);
1021 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1022 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1023 "SCREEN_FROZEN");
1024 mScreenFrozenLock.setReferenceCounted(false);
1025
1026 mActivityManager = ActivityManagerNative.getDefault();
1027 mBatteryStats = BatteryStatsService.getService();
1028
1029 // Get persisted window scale setting
1030 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1031 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1032 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1033 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001034
Jim Miller284b62e2010-06-08 14:27:42 -07001035 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1036 IntentFilter filter = new IntentFilter();
1037 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1038 mContext.registerReceiver(mBroadcastReceiver, filter);
1039
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001040 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1041 "KEEP_SCREEN_ON_FLAG");
1042 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043
Jeff Browne33348b2010-07-15 23:54:05 -07001044 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1047 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 synchronized (thr) {
1050 while (!thr.mRunning) {
1051 try {
1052 thr.wait();
1053 } catch (InterruptedException e) {
1054 }
1055 }
1056 }
Romain Guy06882f82009-06-10 13:36:04 -07001057
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001058 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 // Add ourself to the Watchdog monitors.
1061 Watchdog.getInstance().addMonitor(this);
1062 }
1063
1064 @Override
1065 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1066 throws RemoteException {
1067 try {
1068 return super.onTransact(code, data, reply, flags);
1069 } catch (RuntimeException e) {
1070 // The window manager only throws security exceptions, so let's
1071 // log all others.
1072 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001073 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 }
1075 throw e;
1076 }
1077 }
1078
Jeff Browne33348b2010-07-15 23:54:05 -07001079 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001081 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 TAG, "Adding window " + window + " at "
1083 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1084 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001085 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
1087
Jeff Browne33348b2010-07-15 23:54:05 -07001088 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001090 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 TAG, "Adding window " + window + " at "
1092 + i + " of " + mWindows.size() + " (before " + pos + ")");
1093 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001094 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096
1097 //This method finds out the index of a window that has the same app token as
1098 //win. used for z ordering the windows in mWindows
1099 private int findIdxBasedOnAppTokens(WindowState win) {
1100 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001101 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 int jmax = localmWindows.size();
1103 if(jmax == 0) {
1104 return -1;
1105 }
1106 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001107 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 if(wentry.mAppToken == win.mAppToken) {
1109 return j;
1110 }
1111 }
1112 return -1;
1113 }
Romain Guy06882f82009-06-10 13:36:04 -07001114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1116 final IWindow client = win.mClient;
1117 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001118 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 final int N = localmWindows.size();
1121 final WindowState attached = win.mAttachedWindow;
1122 int i;
1123 if (attached == null) {
1124 int tokenWindowsPos = token.windows.size();
1125 if (token.appWindowToken != null) {
1126 int index = tokenWindowsPos-1;
1127 if (index >= 0) {
1128 // If this application has existing windows, we
1129 // simply place the new window on top of them... but
1130 // keep the starting window on top.
1131 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1132 // Base windows go behind everything else.
1133 placeWindowBefore(token.windows.get(0), win);
1134 tokenWindowsPos = 0;
1135 } else {
1136 AppWindowToken atoken = win.mAppToken;
1137 if (atoken != null &&
1138 token.windows.get(index) == atoken.startingWindow) {
1139 placeWindowBefore(token.windows.get(index), win);
1140 tokenWindowsPos--;
1141 } else {
1142 int newIdx = findIdxBasedOnAppTokens(win);
1143 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001144 //there is a window above this one associated with the same
1145 //apptoken note that the window could be a floating window
1146 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001148 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1149 Slog.v(TAG, "Adding window " + win + " at "
1150 + (newIdx+1) + " of " + N);
1151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001153 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001154 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 }
1156 }
1157 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001158 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 TAG, "Figuring out where to add app window "
1160 + client.asBinder() + " (token=" + token + ")");
1161 // Figure out where the window should go, based on the
1162 // order of applications.
1163 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001164 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 for (i=NA-1; i>=0; i--) {
1166 AppWindowToken t = mAppTokens.get(i);
1167 if (t == token) {
1168 i--;
1169 break;
1170 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001171
Dianne Hackborna8f60182009-09-01 19:01:50 -07001172 // We haven't reached the token yet; if this token
1173 // is not going to the bottom and has windows, we can
1174 // use it as an anchor for when we do reach the token.
1175 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 pos = t.windows.get(0);
1177 }
1178 }
1179 // We now know the index into the apps. If we found
1180 // an app window above, that gives us the position; else
1181 // we need to look some more.
1182 if (pos != null) {
1183 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001184 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 if (atoken != null) {
1186 final int NC = atoken.windows.size();
1187 if (NC > 0) {
1188 WindowState bottom = atoken.windows.get(0);
1189 if (bottom.mSubLayer < 0) {
1190 pos = bottom;
1191 }
1192 }
1193 }
1194 placeWindowBefore(pos, win);
1195 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001196 // Continue looking down until we find the first
1197 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 while (i >= 0) {
1199 AppWindowToken t = mAppTokens.get(i);
1200 final int NW = t.windows.size();
1201 if (NW > 0) {
1202 pos = t.windows.get(NW-1);
1203 break;
1204 }
1205 i--;
1206 }
1207 if (pos != null) {
1208 // Move in front of any windows attached to this
1209 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001210 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 if (atoken != null) {
1212 final int NC = atoken.windows.size();
1213 if (NC > 0) {
1214 WindowState top = atoken.windows.get(NC-1);
1215 if (top.mSubLayer >= 0) {
1216 pos = top;
1217 }
1218 }
1219 }
1220 placeWindowAfter(pos, win);
1221 } else {
1222 // Just search for the start of this layer.
1223 final int myLayer = win.mBaseLayer;
1224 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001225 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 if (w.mBaseLayer > myLayer) {
1227 break;
1228 }
1229 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001230 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1231 Slog.v(TAG, "Adding window " + win + " at "
1232 + i + " of " + N);
1233 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001235 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 }
1237 }
1238 }
1239 } else {
1240 // Figure out where window should go, based on layer.
1241 final int myLayer = win.mBaseLayer;
1242 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001243 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 i++;
1245 break;
1246 }
1247 }
1248 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001249 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001250 TAG, "Adding window " + win + " at "
1251 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001253 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 }
1255 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001256 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 token.windows.add(tokenWindowsPos, win);
1258 }
1259
1260 } else {
1261 // Figure out this window's ordering relative to the window
1262 // it is attached to.
1263 final int NA = token.windows.size();
1264 final int sublayer = win.mSubLayer;
1265 int largestSublayer = Integer.MIN_VALUE;
1266 WindowState windowWithLargestSublayer = null;
1267 for (i=0; i<NA; i++) {
1268 WindowState w = token.windows.get(i);
1269 final int wSublayer = w.mSubLayer;
1270 if (wSublayer >= largestSublayer) {
1271 largestSublayer = wSublayer;
1272 windowWithLargestSublayer = w;
1273 }
1274 if (sublayer < 0) {
1275 // For negative sublayers, we go below all windows
1276 // in the same sublayer.
1277 if (wSublayer >= sublayer) {
1278 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001279 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 token.windows.add(i, win);
1281 }
1282 placeWindowBefore(
1283 wSublayer >= 0 ? attached : w, win);
1284 break;
1285 }
1286 } else {
1287 // For positive sublayers, we go above all windows
1288 // in the same sublayer.
1289 if (wSublayer > sublayer) {
1290 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001291 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 token.windows.add(i, win);
1293 }
1294 placeWindowBefore(w, win);
1295 break;
1296 }
1297 }
1298 }
1299 if (i >= NA) {
1300 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001301 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 token.windows.add(win);
1303 }
1304 if (sublayer < 0) {
1305 placeWindowBefore(attached, win);
1306 } else {
1307 placeWindowAfter(largestSublayer >= 0
1308 ? windowWithLargestSublayer
1309 : attached,
1310 win);
1311 }
1312 }
1313 }
Romain Guy06882f82009-06-10 13:36:04 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 if (win.mAppToken != null && addToToken) {
1316 win.mAppToken.allAppWindows.add(win);
1317 }
1318 }
Romain Guy06882f82009-06-10 13:36:04 -07001319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 static boolean canBeImeTarget(WindowState w) {
1321 final int fl = w.mAttrs.flags
1322 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001323 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1324 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1325 if (DEBUG_INPUT_METHOD) {
1326 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1327 if (!w.isVisibleOrAdding()) {
1328 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1329 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1330 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1331 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1332 if (w.mAppToken != null) {
1333 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1334 }
1335 }
1336 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 return w.isVisibleOrAdding();
1338 }
1339 return false;
1340 }
Romain Guy06882f82009-06-10 13:36:04 -07001341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001343 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 final int N = localmWindows.size();
1345 WindowState w = null;
1346 int i = N;
1347 while (i > 0) {
1348 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001349 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001350
Dianne Hackborne75d8722011-01-27 19:37:40 -08001351 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1352 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001354 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 // Yet more tricksyness! If this window is a "starting"
1357 // window, we do actually want to be on top of it, but
1358 // it is not -really- where input will go. So if the caller
1359 // is not actually looking to move the IME, look down below
1360 // for a real window to target...
1361 if (!willMove
1362 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1363 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001364 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1366 i--;
1367 w = wb;
1368 }
1369 }
1370 break;
1371 }
1372 }
Romain Guy06882f82009-06-10 13:36:04 -07001373
Dianne Hackborne75d8722011-01-27 19:37:40 -08001374 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1375
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001376 // Now, a special case -- if the last target's window is in the
1377 // process of exiting, and is above the new target, keep on the
1378 // last target to avoid flicker. Consider for example a Dialog with
1379 // the IME shown: when the Dialog is dismissed, we want to keep
1380 // the IME above it until it is completely gone so it doesn't drop
1381 // behind the dialog or its full-screen scrim.
1382 if (mInputMethodTarget != null && w != null
1383 && mInputMethodTarget.isDisplayedLw()
1384 && mInputMethodTarget.mExiting) {
1385 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1386 w = mInputMethodTarget;
1387 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001388 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001389 }
1390 }
Romain Guy06882f82009-06-10 13:36:04 -07001391
Joe Onorato8a9b2202010-02-26 18:56:32 -08001392 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 if (willMove && w != null) {
1396 final WindowState curTarget = mInputMethodTarget;
1397 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 // Now some fun for dealing with window animations that
1400 // modify the Z order. We need to look at all windows below
1401 // the current target that are in this app, finding the highest
1402 // visible one in layering.
1403 AppWindowToken token = curTarget.mAppToken;
1404 WindowState highestTarget = null;
1405 int highestPos = 0;
1406 if (token.animating || token.animation != null) {
1407 int pos = 0;
1408 pos = localmWindows.indexOf(curTarget);
1409 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001410 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 if (win.mAppToken != token) {
1412 break;
1413 }
1414 if (!win.mRemoved) {
1415 if (highestTarget == null || win.mAnimLayer >
1416 highestTarget.mAnimLayer) {
1417 highestTarget = win;
1418 highestPos = pos;
1419 }
1420 }
1421 pos--;
1422 }
1423 }
Romain Guy06882f82009-06-10 13:36:04 -07001424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001426 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 + mNextAppTransition + " " + highestTarget
1428 + " animating=" + highestTarget.isAnimating()
1429 + " layer=" + highestTarget.mAnimLayer
1430 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001431
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001432 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 // If we are currently setting up for an animation,
1434 // hold everything until we can find out what will happen.
1435 mInputMethodTargetWaitingAnim = true;
1436 mInputMethodTarget = highestTarget;
1437 return highestPos + 1;
1438 } else if (highestTarget.isAnimating() &&
1439 highestTarget.mAnimLayer > w.mAnimLayer) {
1440 // If the window we are currently targeting is involved
1441 // with an animation, and it is on top of the next target
1442 // we will be over, then hold off on moving until
1443 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001444 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 mInputMethodTarget = highestTarget;
1446 return highestPos + 1;
1447 }
1448 }
1449 }
1450 }
Romain Guy06882f82009-06-10 13:36:04 -07001451
Joe Onorato8a9b2202010-02-26 18:56:32 -08001452 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 if (w != null) {
1454 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001455 if (DEBUG_INPUT_METHOD) {
1456 RuntimeException e = null;
1457 if (!HIDE_STACK_CRAWLS) {
1458 e = new RuntimeException();
1459 e.fillInStackTrace();
1460 }
1461 Slog.w(TAG, "Moving IM target from "
1462 + mInputMethodTarget + " to " + w, e);
1463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001465 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 if (w.mAppToken != null) {
1467 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1468 } else {
1469 setInputMethodAnimLayerAdjustment(0);
1470 }
1471 }
1472 return i+1;
1473 }
1474 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001475 if (DEBUG_INPUT_METHOD) {
1476 RuntimeException e = null;
1477 if (!HIDE_STACK_CRAWLS) {
1478 e = new RuntimeException();
1479 e.fillInStackTrace();
1480 }
1481 Slog.w(TAG, "Moving IM target from "
1482 + mInputMethodTarget + " to null", e);
1483 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 mInputMethodTarget = null;
1485 setInputMethodAnimLayerAdjustment(0);
1486 }
1487 return -1;
1488 }
Romain Guy06882f82009-06-10 13:36:04 -07001489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 void addInputMethodWindowToListLocked(WindowState win) {
1491 int pos = findDesiredInputMethodWindowIndexLocked(true);
1492 if (pos >= 0) {
1493 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001494 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001495 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001497 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 moveInputMethodDialogsLocked(pos+1);
1499 return;
1500 }
1501 win.mTargetAppToken = null;
1502 addWindowToListInOrderLocked(win, true);
1503 moveInputMethodDialogsLocked(pos);
1504 }
Romain Guy06882f82009-06-10 13:36:04 -07001505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 mInputMethodAnimLayerAdjustment = adj;
1509 WindowState imw = mInputMethodWindow;
1510 if (imw != null) {
1511 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001512 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 + " anim layer: " + imw.mAnimLayer);
1514 int wi = imw.mChildWindows.size();
1515 while (wi > 0) {
1516 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001517 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001519 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 + " anim layer: " + cw.mAnimLayer);
1521 }
1522 }
1523 int di = mInputMethodDialogs.size();
1524 while (di > 0) {
1525 di --;
1526 imw = mInputMethodDialogs.get(di);
1527 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001528 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 + " anim layer: " + imw.mAnimLayer);
1530 }
1531 }
Romain Guy06882f82009-06-10 13:36:04 -07001532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1534 int wpos = mWindows.indexOf(win);
1535 if (wpos >= 0) {
1536 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001537 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001539 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 int NC = win.mChildWindows.size();
1541 while (NC > 0) {
1542 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001543 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 int cpos = mWindows.indexOf(cw);
1545 if (cpos >= 0) {
1546 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001547 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001548 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 mWindows.remove(cpos);
1550 }
1551 }
1552 }
1553 return interestingPos;
1554 }
Romain Guy06882f82009-06-10 13:36:04 -07001555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 private void reAddWindowToListInOrderLocked(WindowState win) {
1557 addWindowToListInOrderLocked(win, false);
1558 // This is a hack to get all of the child windows added as well
1559 // at the right position. Child windows should be rare and
1560 // this case should be rare, so it shouldn't be that big a deal.
1561 int wpos = mWindows.indexOf(win);
1562 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001563 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001564 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001566 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 reAddWindowLocked(wpos, win);
1568 }
1569 }
Romain Guy06882f82009-06-10 13:36:04 -07001570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 void logWindowList(String prefix) {
1572 int N = mWindows.size();
1573 while (N > 0) {
1574 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001575 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 }
1577 }
Romain Guy06882f82009-06-10 13:36:04 -07001578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 void moveInputMethodDialogsLocked(int pos) {
1580 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 for (int i=0; i<N; i++) {
1585 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1586 }
1587 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001588 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 logWindowList(" ");
1590 }
Romain Guy06882f82009-06-10 13:36:04 -07001591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 if (pos >= 0) {
1593 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1594 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001595 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 if (wp == mInputMethodWindow) {
1597 pos++;
1598 }
1599 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001600 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 for (int i=0; i<N; i++) {
1602 WindowState win = dialogs.get(i);
1603 win.mTargetAppToken = targetAppToken;
1604 pos = reAddWindowLocked(pos, win);
1605 }
1606 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001607 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 logWindowList(" ");
1609 }
1610 return;
1611 }
1612 for (int i=0; i<N; i++) {
1613 WindowState win = dialogs.get(i);
1614 win.mTargetAppToken = null;
1615 reAddWindowToListInOrderLocked(win);
1616 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001617 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 logWindowList(" ");
1619 }
1620 }
1621 }
Romain Guy06882f82009-06-10 13:36:04 -07001622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1624 final WindowState imWin = mInputMethodWindow;
1625 final int DN = mInputMethodDialogs.size();
1626 if (imWin == null && DN == 0) {
1627 return false;
1628 }
Romain Guy06882f82009-06-10 13:36:04 -07001629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1631 if (imPos >= 0) {
1632 // In this case, the input method windows are to be placed
1633 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 // First check to see if the input method windows are already
1636 // located here, and contiguous.
1637 final int N = mWindows.size();
1638 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001639 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 // Figure out the actual input method window that should be
1642 // at the bottom of their stack.
1643 WindowState baseImWin = imWin != null
1644 ? imWin : mInputMethodDialogs.get(0);
1645 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001646 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 if (cw.mSubLayer < 0) baseImWin = cw;
1648 }
Romain Guy06882f82009-06-10 13:36:04 -07001649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 if (firstImWin == baseImWin) {
1651 // The windows haven't moved... but are they still contiguous?
1652 // First find the top IM window.
1653 int pos = imPos+1;
1654 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001655 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 break;
1657 }
1658 pos++;
1659 }
1660 pos++;
1661 // Now there should be no more input method windows above.
1662 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001663 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001664 break;
1665 }
1666 pos++;
1667 }
1668 if (pos >= N) {
1669 // All is good!
1670 return false;
1671 }
1672 }
Romain Guy06882f82009-06-10 13:36:04 -07001673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 if (imWin != null) {
1675 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001676 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 logWindowList(" ");
1678 }
1679 imPos = tmpRemoveWindowLocked(imPos, imWin);
1680 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001681 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 logWindowList(" ");
1683 }
1684 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1685 reAddWindowLocked(imPos, imWin);
1686 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001687 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 logWindowList(" ");
1689 }
1690 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1691 } else {
1692 moveInputMethodDialogsLocked(imPos);
1693 }
Romain Guy06882f82009-06-10 13:36:04 -07001694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 } else {
1696 // In this case, the input method windows go in a fixed layer,
1697 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 tmpRemoveWindowLocked(0, imWin);
1702 imWin.mTargetAppToken = null;
1703 reAddWindowToListInOrderLocked(imWin);
1704 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001705 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 logWindowList(" ");
1707 }
1708 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1709 } else {
1710 moveInputMethodDialogsLocked(-1);;
1711 }
Romain Guy06882f82009-06-10 13:36:04 -07001712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 }
Romain Guy06882f82009-06-10 13:36:04 -07001714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 if (needAssignLayers) {
1716 assignLayersLocked();
1717 }
Romain Guy06882f82009-06-10 13:36:04 -07001718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 return true;
1720 }
Romain Guy06882f82009-06-10 13:36:04 -07001721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 void adjustInputMethodDialogsLocked() {
1723 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1724 }
Romain Guy06882f82009-06-10 13:36:04 -07001725
Dianne Hackborn25994b42009-09-04 14:21:19 -07001726 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001727 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001728 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1729 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1730 ? wallpaperTarget.mAppToken.animation : null)
1731 + " upper=" + mUpperWallpaperTarget
1732 + " lower=" + mLowerWallpaperTarget);
1733 return (wallpaperTarget != null
1734 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1735 && wallpaperTarget.mAppToken.animation != null)))
1736 || mUpperWallpaperTarget != null
1737 || mLowerWallpaperTarget != null;
1738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001740 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1741 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001743 int adjustWallpaperWindowsLocked() {
1744 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 final int dw = mDisplay.getWidth();
1747 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001749 // First find top-most window that has asked to be on top of the
1750 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001751 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001752 int N = localmWindows.size();
1753 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001754 WindowState foundW = null;
1755 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001756 WindowState topCurW = null;
1757 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001758 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001759 int i = N;
1760 while (i > 0) {
1761 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001762 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001763 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1764 if (topCurW == null) {
1765 topCurW = w;
1766 topCurI = i;
1767 }
1768 continue;
1769 }
1770 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001771 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001772 // If this window's app token is hidden and not animating,
1773 // it is of no interest to us.
1774 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001775 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001776 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001777 continue;
1778 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001779 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001780 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001781 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1782 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001783 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001784 && (mWallpaperTarget == w
1785 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001786 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001787 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001788 foundW = w;
1789 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001790 if (w == mWallpaperTarget && ((w.mAppToken != null
1791 && w.mAppToken.animation != null)
1792 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001793 // The current wallpaper target is animating, so we'll
1794 // look behind it for another possible target and figure
1795 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001796 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001797 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001798 continue;
1799 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001800 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001801 } else if (w == mWindowDetachedWallpaper) {
1802 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001803 }
1804 }
1805
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001806 if (foundW == null && windowDetachedI >= 0) {
1807 if (DEBUG_WALLPAPER) Slog.v(TAG,
1808 "Found animating detached wallpaper activity: #" + i + "=" + w);
1809 foundW = w;
1810 foundI = windowDetachedI;
1811 }
1812
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001813 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001814 // If we are currently waiting for an app transition, and either
1815 // the current target or the next target are involved with it,
1816 // then hold off on doing anything with the wallpaper.
1817 // Note that we are checking here for just whether the target
1818 // is part of an app token... which is potentially overly aggressive
1819 // (the app token may not be involved in the transition), but good
1820 // enough (we'll just wait until whatever transition is pending
1821 // executes).
1822 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001823 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001824 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001825 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001826 }
1827 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001828 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001830 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001831 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001832 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001833
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001834 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001835 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001836 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001837 + " oldTarget: " + mWallpaperTarget);
1838 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001839
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001840 mLowerWallpaperTarget = null;
1841 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001842
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001843 WindowState oldW = mWallpaperTarget;
1844 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 // Now what is happening... if the current and new targets are
1847 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001848 if (foundW != null && oldW != null) {
1849 boolean oldAnim = oldW.mAnimation != null
1850 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1851 boolean foundAnim = foundW.mAnimation != null
1852 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001855 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001856 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001857 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001858 int oldI = localmWindows.indexOf(oldW);
1859 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001861 }
1862 if (oldI >= 0) {
1863 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001865 + "=" + oldW + "; new#" + foundI
1866 + "=" + foundW);
1867 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001868
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001869 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001870 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001871 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001872 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001873 }
1874 mWallpaperTarget = oldW;
1875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001876
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001877 // Now set the upper and lower wallpaper targets
1878 // correctly, and make sure that we are positioning
1879 // the wallpaper below the lower.
1880 if (foundI > oldI) {
1881 // The new target is on top of the old one.
1882 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001883 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001884 }
1885 mUpperWallpaperTarget = foundW;
1886 mLowerWallpaperTarget = oldW;
1887 foundW = oldW;
1888 foundI = oldI;
1889 } else {
1890 // The new target is below the old one.
1891 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001892 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001893 }
1894 mUpperWallpaperTarget = oldW;
1895 mLowerWallpaperTarget = foundW;
1896 }
1897 }
1898 }
1899 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001900
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001901 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001902 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001903 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1904 || (mLowerWallpaperTarget.mAppToken != null
1905 && mLowerWallpaperTarget.mAppToken.animation != null);
1906 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1907 || (mUpperWallpaperTarget.mAppToken != null
1908 && mUpperWallpaperTarget.mAppToken.animation != null);
1909 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001910 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001911 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001912 }
1913 mLowerWallpaperTarget = null;
1914 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001915 }
1916 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001917
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001918 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001919 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001920 // The window is visible to the compositor... but is it visible
1921 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001922 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001923 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001924
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001925 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001926 // its layer adjustment. Only do this if we are not transfering
1927 // between two wallpaper targets.
1928 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001929 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001930 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001931
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001932 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1933 * TYPE_LAYER_MULTIPLIER
1934 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001935
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001936 // Now w is the window we are supposed to be behind... but we
1937 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001938 // AND any starting window associated with it, AND below the
1939 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001940 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001941 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001942 if (wb.mBaseLayer < maxLayer &&
1943 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001944 (foundW.mAttachedWindow == null ||
1945 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001946 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001947 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001948 // This window is not related to the previous one in any
1949 // interesting way, so stop here.
1950 break;
1951 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001952 foundW = wb;
1953 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001954 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001955 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001956 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001958
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001959 if (foundW == null && topCurW != null) {
1960 // There is no wallpaper target, so it goes at the bottom.
1961 // We will assume it is the same place as last time, if known.
1962 foundW = topCurW;
1963 foundI = topCurI+1;
1964 } else {
1965 // Okay i is the position immediately above the wallpaper. Look at
1966 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001967 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001968 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001969
Dianne Hackborn284ac932009-08-28 10:34:25 -07001970 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001971 if (mWallpaperTarget.mWallpaperX >= 0) {
1972 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001973 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001974 }
1975 if (mWallpaperTarget.mWallpaperY >= 0) {
1976 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001977 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001978 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001979 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001980
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001981 // Start stepping backwards from here, ensuring that our wallpaper windows
1982 // are correctly placed.
1983 int curTokenIndex = mWallpaperTokens.size();
1984 while (curTokenIndex > 0) {
1985 curTokenIndex--;
1986 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001987 if (token.hidden == visible) {
1988 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1989 token.hidden = !visible;
1990 // Need to do a layout to ensure the wallpaper now has the
1991 // correct size.
1992 mLayoutNeeded = true;
1993 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001994
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001995 int curWallpaperIndex = token.windows.size();
1996 while (curWallpaperIndex > 0) {
1997 curWallpaperIndex--;
1998 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001999
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002000 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002001 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002002 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002003
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002004 // First, make sure the client has the current visibility
2005 // state.
2006 if (wallpaper.mWallpaperVisible != visible) {
2007 wallpaper.mWallpaperVisible = visible;
2008 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002009 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002010 "Setting visibility of wallpaper " + wallpaper
2011 + ": " + visible);
2012 wallpaper.mClient.dispatchAppVisibility(visible);
2013 } catch (RemoteException e) {
2014 }
2015 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002016
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002017 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002019 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002021 // First, if this window is at the current index, then all
2022 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002023 if (wallpaper == foundW) {
2024 foundI--;
2025 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002026 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002027 continue;
2028 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002029
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002030 // The window didn't match... the current wallpaper window,
2031 // wherever it is, is in the wrong place, so make sure it is
2032 // not in the list.
2033 int oldIndex = localmWindows.indexOf(wallpaper);
2034 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002035 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002036 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002037 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002038 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002039 if (oldIndex < foundI) {
2040 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002041 }
2042 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002043
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002044 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002045 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2046 Slog.v(TAG, "Moving wallpaper " + wallpaper
2047 + " from " + oldIndex + " to " + foundI);
2048 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002049
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002050 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002051 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002052 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002053 }
2054 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002055
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002056 return changed;
2057 }
2058
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002059 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002060 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002061 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002062 mWallpaperAnimLayerAdjustment = adj;
2063 int curTokenIndex = mWallpaperTokens.size();
2064 while (curTokenIndex > 0) {
2065 curTokenIndex--;
2066 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2067 int curWallpaperIndex = token.windows.size();
2068 while (curWallpaperIndex > 0) {
2069 curWallpaperIndex--;
2070 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2071 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002072 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002073 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002074 }
2075 }
2076 }
2077
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002078 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2079 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002080 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002081 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002082 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002083 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002084 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2085 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2086 changed = wallpaperWin.mXOffset != offset;
2087 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002088 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002089 + wallpaperWin + " x: " + offset);
2090 wallpaperWin.mXOffset = offset;
2091 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002092 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002093 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002094 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002095 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002096 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002097
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002098 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002099 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002100 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2101 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2102 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002103 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002104 + wallpaperWin + " y: " + offset);
2105 changed = true;
2106 wallpaperWin.mYOffset = offset;
2107 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002108 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002109 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002110 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002111 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002112 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002113
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002114 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002115 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002116 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002117 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2118 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002119 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002120 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002121 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002122 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002123 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2124 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002125 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002126 if (mWaitingOnWallpaper != null) {
2127 long start = SystemClock.uptimeMillis();
2128 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2129 < start) {
2130 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002131 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002132 "Waiting for offset complete...");
2133 mWindowMap.wait(WALLPAPER_TIMEOUT);
2134 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002135 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002136 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002137 if ((start+WALLPAPER_TIMEOUT)
2138 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002139 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002140 + wallpaperWin);
2141 mLastWallpaperTimeoutTime = start;
2142 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002143 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002144 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002145 }
2146 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002147 } catch (RemoteException e) {
2148 }
2149 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002150
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002151 return changed;
2152 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002153
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002154 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002155 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002156 if (mWaitingOnWallpaper != null &&
2157 mWaitingOnWallpaper.mClient.asBinder() == window) {
2158 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002159 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002160 }
2161 }
2162 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002163
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002164 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002165 final int dw = mDisplay.getWidth();
2166 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002167
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002168 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002169
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002170 WindowState target = mWallpaperTarget;
2171 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002172 if (target.mWallpaperX >= 0) {
2173 mLastWallpaperX = target.mWallpaperX;
2174 } else if (changingTarget.mWallpaperX >= 0) {
2175 mLastWallpaperX = changingTarget.mWallpaperX;
2176 }
2177 if (target.mWallpaperY >= 0) {
2178 mLastWallpaperY = target.mWallpaperY;
2179 } else if (changingTarget.mWallpaperY >= 0) {
2180 mLastWallpaperY = changingTarget.mWallpaperY;
2181 }
2182 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002183
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002184 int curTokenIndex = mWallpaperTokens.size();
2185 while (curTokenIndex > 0) {
2186 curTokenIndex--;
2187 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2188 int curWallpaperIndex = token.windows.size();
2189 while (curWallpaperIndex > 0) {
2190 curWallpaperIndex--;
2191 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2192 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2193 wallpaper.computeShownFrameLocked();
2194 changed = true;
2195 // We only want to be synchronous with one wallpaper.
2196 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002197 }
2198 }
2199 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002200
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002201 return changed;
2202 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002203
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002204 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002205 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002206 final int dw = mDisplay.getWidth();
2207 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002208
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002209 int curTokenIndex = mWallpaperTokens.size();
2210 while (curTokenIndex > 0) {
2211 curTokenIndex--;
2212 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002213 if (token.hidden == visible) {
2214 token.hidden = !visible;
2215 // Need to do a layout to ensure the wallpaper now has the
2216 // correct size.
2217 mLayoutNeeded = true;
2218 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002219
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002220 int curWallpaperIndex = token.windows.size();
2221 while (curWallpaperIndex > 0) {
2222 curWallpaperIndex--;
2223 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2224 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002225 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002226 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002227
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002228 if (wallpaper.mWallpaperVisible != visible) {
2229 wallpaper.mWallpaperVisible = visible;
2230 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002231 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002232 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002233 + ": " + visible);
2234 wallpaper.mClient.dispatchAppVisibility(visible);
2235 } catch (RemoteException e) {
2236 }
2237 }
2238 }
2239 }
2240 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 public int addWindow(Session session, IWindow client,
2243 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002244 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 int res = mPolicy.checkAddPermission(attrs);
2246 if (res != WindowManagerImpl.ADD_OKAY) {
2247 return res;
2248 }
Romain Guy06882f82009-06-10 13:36:04 -07002249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 boolean reportNewConfig = false;
2251 WindowState attachedWindow = null;
2252 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002253 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002257 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 }
Romain Guy06882f82009-06-10 13:36:04 -07002259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002261 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2263 }
2264
2265 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002266 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002268 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 + attrs.token + ". Aborting.");
2270 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2271 }
2272 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2273 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002274 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 + attrs.token + ". Aborting.");
2276 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2277 }
2278 }
2279
2280 boolean addToken = false;
2281 WindowToken token = mTokenMap.get(attrs.token);
2282 if (token == null) {
2283 if (attrs.type >= FIRST_APPLICATION_WINDOW
2284 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add application 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 }
2289 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002290 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 + attrs.token + ". Aborting.");
2292 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2293 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002294 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002295 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002296 + attrs.token + ". Aborting.");
2297 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 token = new WindowToken(attrs.token, -1, false);
2300 addToken = true;
2301 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2302 && attrs.type <= LAST_APPLICATION_WINDOW) {
2303 AppWindowToken atoken = token.appWindowToken;
2304 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002305 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 + token + ". Aborting.");
2307 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2308 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002309 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 + token + ". Aborting.");
2311 return WindowManagerImpl.ADD_APP_EXITING;
2312 }
2313 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2314 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002315 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2317 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2318 }
2319 } else if (attrs.type == TYPE_INPUT_METHOD) {
2320 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002321 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 + attrs.token + ". Aborting.");
2323 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2324 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002325 } else if (attrs.type == TYPE_WALLPAPER) {
2326 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002327 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002328 + attrs.token + ". Aborting.");
2329 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2330 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 }
2332
2333 win = new WindowState(session, client, token,
2334 attachedWindow, attrs, viewVisibility);
2335 if (win.mDeathRecipient == null) {
2336 // Client has apparently died, so there is no reason to
2337 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002338 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 + " that is dead, aborting.");
2340 return WindowManagerImpl.ADD_APP_EXITING;
2341 }
2342
2343 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 res = mPolicy.prepareAddWindowLw(win, attrs);
2346 if (res != WindowManagerImpl.ADD_OKAY) {
2347 return res;
2348 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002349
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002350 if (outInputChannel != null) {
2351 String name = win.makeInputChannelName();
2352 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2353 win.mInputChannel = inputChannels[0];
2354 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2355
Jeff Brown928e0542011-01-10 11:17:36 -08002356 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358
2359 // From now on, no exceptions or errors allowed!
2360
2361 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002362
Dianne Hackborn5132b372010-07-29 12:51:35 -07002363 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 if (addToken) {
2366 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 }
2368 win.attach();
2369 mWindowMap.put(client.asBinder(), win);
2370
2371 if (attrs.type == TYPE_APPLICATION_STARTING &&
2372 token.appWindowToken != null) {
2373 token.appWindowToken.startingWindow = win;
2374 }
2375
2376 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 if (attrs.type == TYPE_INPUT_METHOD) {
2379 mInputMethodWindow = win;
2380 addInputMethodWindowToListLocked(win);
2381 imMayMove = false;
2382 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2383 mInputMethodDialogs.add(win);
2384 addWindowToListInOrderLocked(win, true);
2385 adjustInputMethodDialogsLocked();
2386 imMayMove = false;
2387 } else {
2388 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002389 if (attrs.type == TYPE_WALLPAPER) {
2390 mLastWallpaperTimeoutTime = 0;
2391 adjustWallpaperWindowsLocked();
2392 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002393 adjustWallpaperWindowsLocked();
2394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 }
Romain Guy06882f82009-06-10 13:36:04 -07002396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 if (mInTouchMode) {
2402 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2403 }
2404 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2405 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2406 }
Romain Guy06882f82009-06-10 13:36:04 -07002407
Jeff Brown2e44b072011-01-24 15:21:56 -08002408 mInputMonitor.setUpdateInputWindowsNeededLw();
2409
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002410 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002412 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2413 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002414 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 imMayMove = false;
2416 }
2417 }
Romain Guy06882f82009-06-10 13:36:04 -07002418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002420 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 }
Romain Guy06882f82009-06-10 13:36:04 -07002422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 assignLayersLocked();
2424 // Don't do layout here, the window must call
2425 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 //dump();
2428
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002429 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002430 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002431 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002432 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002433
Joe Onorato8a9b2202010-02-26 18:56:32 -08002434 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 TAG, "New client " + client.asBinder()
2436 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002437
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002438 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002439 reportNewConfig = true;
2440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 }
2442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 if (reportNewConfig) {
2444 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 return res;
2450 }
Romain Guy06882f82009-06-10 13:36:04 -07002451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 public void removeWindow(Session session, IWindow client) {
2453 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002454 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 if (win == null) {
2456 return;
2457 }
2458 removeWindowLocked(session, win);
2459 }
2460 }
Romain Guy06882f82009-06-10 13:36:04 -07002461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 public void removeWindowLocked(Session session, WindowState win) {
2463
Joe Onorato8a9b2202010-02-26 18:56:32 -08002464 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 TAG, "Remove " + win + " client="
2466 + Integer.toHexString(System.identityHashCode(
2467 win.mClient.asBinder()))
2468 + ", surface=" + win.mSurface);
2469
2470 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002471
2472 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002473
Joe Onorato8a9b2202010-02-26 18:56:32 -08002474 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2476 + " mExiting=" + win.mExiting
2477 + " isAnimating=" + win.isAnimating()
2478 + " app-animation="
2479 + (win.mAppToken != null ? win.mAppToken.animation : null)
2480 + " inPendingTransaction="
2481 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2482 + " mDisplayFrozen=" + mDisplayFrozen);
2483 // Visibility of the removed window. Will be used later to update orientation later on.
2484 boolean wasVisible = false;
2485 // First, see if we need to run an animation. If we do, we have
2486 // to hold off on removing the window until the animation is done.
2487 // If the display is frozen, just remove immediately, since the
2488 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002489 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 // If we are not currently running the exit animation, we
2491 // need to see about starting one.
2492 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2495 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2496 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2497 }
2498 // Try starting an animation.
2499 if (applyAnimationLocked(win, transit, false)) {
2500 win.mExiting = true;
2501 }
2502 }
2503 if (win.mExiting || win.isAnimating()) {
2504 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002505 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 win.mExiting = true;
2507 win.mRemoveOnExit = true;
2508 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002509 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2510 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002512 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 if (win.mAppToken != null) {
2514 win.mAppToken.updateReportedVisibilityLocked();
2515 }
2516 //dump();
2517 Binder.restoreCallingIdentity(origId);
2518 return;
2519 }
2520 }
2521
2522 removeWindowInnerLocked(session, win);
2523 // Removing a visible window will effect the computed orientation
2524 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002525 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002526 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002527 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002528 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002530 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 Binder.restoreCallingIdentity(origId);
2532 }
Romain Guy06882f82009-06-10 13:36:04 -07002533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002535 if (win.mRemoved) {
2536 // Nothing to do.
2537 return;
2538 }
2539
2540 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2541 WindowState cwin = win.mChildWindows.get(i);
2542 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2543 + win);
2544 removeWindowInnerLocked(cwin.mSession, cwin);
2545 }
2546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 if (mInputMethodTarget == win) {
2550 moveInputMethodWindowsIfNeededLocked(false);
2551 }
Romain Guy06882f82009-06-10 13:36:04 -07002552
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002553 if (false) {
2554 RuntimeException e = new RuntimeException("here");
2555 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002556 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 mPolicy.removeWindowLw(win);
2560 win.removeLocked();
2561
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002562 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 mWindowMap.remove(win.mClient.asBinder());
2564 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002565 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002566 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002567 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568
2569 if (mInputMethodWindow == win) {
2570 mInputMethodWindow = null;
2571 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2572 mInputMethodDialogs.remove(win);
2573 }
Romain Guy06882f82009-06-10 13:36:04 -07002574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 final WindowToken token = win.mToken;
2576 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002577 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 token.windows.remove(win);
2579 if (atoken != null) {
2580 atoken.allAppWindows.remove(win);
2581 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002582 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 TAG, "**** Removing window " + win + ": count="
2584 + token.windows.size());
2585 if (token.windows.size() == 0) {
2586 if (!token.explicit) {
2587 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 } else if (atoken != null) {
2589 atoken.firstWindowDrawn = false;
2590 }
2591 }
2592
2593 if (atoken != null) {
2594 if (atoken.startingWindow == win) {
2595 atoken.startingWindow = null;
2596 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2597 // If this is the last window and we had requested a starting
2598 // transition window, well there is no point now.
2599 atoken.startingData = null;
2600 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2601 // If this is the last window except for a starting transition
2602 // window, we need to get rid of the starting transition.
2603 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002604 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 + ": no more real windows");
2606 }
2607 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2608 mH.sendMessage(m);
2609 }
2610 }
Romain Guy06882f82009-06-10 13:36:04 -07002611
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002612 if (win.mAttrs.type == TYPE_WALLPAPER) {
2613 mLastWallpaperTimeoutTime = 0;
2614 adjustWallpaperWindowsLocked();
2615 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002616 adjustWallpaperWindowsLocked();
2617 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 if (!mInLayout) {
2620 assignLayersLocked();
2621 mLayoutNeeded = true;
2622 performLayoutAndPlaceSurfacesLocked();
2623 if (win.mAppToken != null) {
2624 win.mAppToken.updateReportedVisibilityLocked();
2625 }
2626 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002627
Jeff Brown2e44b072011-01-24 15:21:56 -08002628 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 }
2630
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002631 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2632 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2633 + ": " + msg + " / " + w.mAttrs.getTitle();
2634 if (where != null) {
2635 Slog.i(TAG, str, where);
2636 } else {
2637 Slog.i(TAG, str);
2638 }
2639 }
2640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2642 long origId = Binder.clearCallingIdentity();
2643 try {
2644 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002645 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002647 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2648 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 Surface.openTransaction();
2650 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002651 if (SHOW_TRANSACTIONS) logSurface(w,
2652 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 w.mSurface.setTransparentRegionHint(region);
2654 } finally {
2655 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002656 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2657 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 }
2659 }
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(origId);
2663 }
2664 }
2665
2666 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002667 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002668 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 long origId = Binder.clearCallingIdentity();
2670 try {
2671 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002672 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002673 if (w != null) {
2674 w.mGivenInsetsPending = false;
2675 w.mGivenContentInsets.set(contentInsets);
2676 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002677 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678 w.mTouchableInsets = touchableInsets;
2679 mLayoutNeeded = true;
2680 performLayoutAndPlaceSurfacesLocked();
2681 }
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(origId);
2685 }
2686 }
Romain Guy06882f82009-06-10 13:36:04 -07002687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 public void getWindowDisplayFrame(Session session, IWindow client,
2689 Rect outDisplayFrame) {
2690 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002691 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 if (win == null) {
2693 outDisplayFrame.setEmpty();
2694 return;
2695 }
2696 outDisplayFrame.set(win.mDisplayFrame);
2697 }
2698 }
2699
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002700 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2701 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002702 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2703 window.mWallpaperX = x;
2704 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002705 window.mWallpaperXStep = xStep;
2706 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002707 if (updateWallpaperOffsetLocked(window, true)) {
2708 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002709 }
2710 }
2711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002712
Dianne Hackborn75804932009-10-20 20:15:20 -07002713 void wallpaperCommandComplete(IBinder window, Bundle result) {
2714 synchronized (mWindowMap) {
2715 if (mWaitingOnWallpaper != null &&
2716 mWaitingOnWallpaper.mClient.asBinder() == window) {
2717 mWaitingOnWallpaper = null;
2718 mWindowMap.notifyAll();
2719 }
2720 }
2721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002722
Dianne Hackborn75804932009-10-20 20:15:20 -07002723 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2724 String action, int x, int y, int z, Bundle extras, boolean sync) {
2725 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2726 || window == mUpperWallpaperTarget) {
2727 boolean doWait = sync;
2728 int curTokenIndex = mWallpaperTokens.size();
2729 while (curTokenIndex > 0) {
2730 curTokenIndex--;
2731 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2732 int curWallpaperIndex = token.windows.size();
2733 while (curWallpaperIndex > 0) {
2734 curWallpaperIndex--;
2735 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2736 try {
2737 wallpaper.mClient.dispatchWallpaperCommand(action,
2738 x, y, z, extras, sync);
2739 // We only want to be synchronous with one wallpaper.
2740 sync = false;
2741 } catch (RemoteException e) {
2742 }
2743 }
2744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002745
Dianne Hackborn75804932009-10-20 20:15:20 -07002746 if (doWait) {
2747 // XXX Need to wait for result.
2748 }
2749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002750
Dianne Hackborn75804932009-10-20 20:15:20 -07002751 return null;
2752 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 public int relayoutWindow(Session session, IWindow client,
2755 WindowManager.LayoutParams attrs, int requestedWidth,
2756 int requestedHeight, int viewVisibility, boolean insetsPending,
2757 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002758 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 boolean displayed = false;
2760 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002761 boolean configChanged;
Joe Onoratoac0ee892011-01-30 15:38:30 -08002762
2763 // if they don't have this permission, mask out the status bar bits
2764 if (attrs != null) {
2765 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
2766 != PackageManager.PERMISSION_GRANTED) {
2767 attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2768 attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
2769 }
2770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002774 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 if (win == null) {
2776 return 0;
2777 }
2778 win.mRequestedWidth = requestedWidth;
2779 win.mRequestedHeight = requestedHeight;
2780
2781 if (attrs != null) {
2782 mPolicy.adjustWindowParamsLw(attrs);
2783 }
Romain Guy06882f82009-06-10 13:36:04 -07002784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 int attrChanges = 0;
2786 int flagChanges = 0;
2787 if (attrs != null) {
2788 flagChanges = win.mAttrs.flags ^= attrs.flags;
2789 attrChanges = win.mAttrs.copyFrom(attrs);
2790 }
2791
Joe Onorato8a9b2202010-02-26 18:56:32 -08002792 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793
2794 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2795 win.mAlpha = attrs.alpha;
2796 }
2797
2798 final boolean scaledWindow =
2799 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2800
2801 if (scaledWindow) {
2802 // requested{Width|Height} Surface's physical size
2803 // attrs.{width|height} Size on screen
2804 win.mHScale = (attrs.width != requestedWidth) ?
2805 (attrs.width / (float)requestedWidth) : 1.0f;
2806 win.mVScale = (attrs.height != requestedHeight) ?
2807 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002808 } else {
2809 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 }
2811
2812 boolean imMayMove = (flagChanges&(
2813 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2814 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 boolean focusMayChange = win.mViewVisibility != viewVisibility
2817 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2818 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002819
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002820 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2821 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 win.mRelayoutCalled = true;
2824 final int oldVisibility = win.mViewVisibility;
2825 win.mViewVisibility = viewVisibility;
2826 if (viewVisibility == View.VISIBLE &&
2827 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2828 displayed = !win.isVisibleLw();
2829 if (win.mExiting) {
2830 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002831 if (win.mAnimation != null) {
2832 win.mAnimation.cancel();
2833 win.mAnimation = null;
2834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 }
2836 if (win.mDestroying) {
2837 win.mDestroying = false;
2838 mDestroySurface.remove(win);
2839 }
2840 if (oldVisibility == View.GONE) {
2841 win.mEnterAnimationPending = true;
2842 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002843 if (displayed) {
2844 if (win.mSurface != null && !win.mDrawPending
2845 && !win.mCommitDrawPending && !mDisplayFrozen
2846 && mPolicy.isScreenOn()) {
2847 applyEnterAnimationLocked(win);
2848 }
2849 if ((win.mAttrs.flags
2850 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2851 if (DEBUG_VISIBILITY) Slog.v(TAG,
2852 "Relayout window turning screen on: " + win);
2853 win.mTurnOnScreen = true;
2854 }
2855 int diff = 0;
2856 if (win.mConfiguration != mCurConfiguration
2857 && (win.mConfiguration == null
2858 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2859 win.mConfiguration = mCurConfiguration;
2860 if (DEBUG_CONFIGURATION) {
2861 Slog.i(TAG, "Window " + win + " visible with new config: "
2862 + win.mConfiguration + " / 0x"
2863 + Integer.toHexString(diff));
2864 }
2865 outConfig.setTo(mCurConfiguration);
2866 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002867 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2869 // To change the format, we need to re-build the surface.
2870 win.destroySurfaceLocked();
2871 displayed = true;
2872 }
2873 try {
2874 Surface surface = win.createSurfaceLocked();
2875 if (surface != null) {
2876 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002877 win.mReportDestroySurface = false;
2878 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002879 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002880 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002882 // For some reason there isn't a surface. Clear the
2883 // caller's object so they see the same state.
2884 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 }
2886 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002887 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002888
Joe Onorato8a9b2202010-02-26 18:56:32 -08002889 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002890 + client + " (" + win.mAttrs.getTitle() + ")",
2891 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 Binder.restoreCallingIdentity(origId);
2893 return 0;
2894 }
2895 if (displayed) {
2896 focusMayChange = true;
2897 }
2898 if (win.mAttrs.type == TYPE_INPUT_METHOD
2899 && mInputMethodWindow == null) {
2900 mInputMethodWindow = win;
2901 imMayMove = true;
2902 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002903 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2904 && win.mAppToken != null
2905 && win.mAppToken.startingWindow != null) {
2906 // Special handling of starting window over the base
2907 // window of the app: propagate lock screen flags to it,
2908 // to provide the correct semantics while starting.
2909 final int mask =
2910 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002911 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2912 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002913 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2914 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 } else {
2917 win.mEnterAnimationPending = false;
2918 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002919 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002920 + ": mExiting=" + win.mExiting
2921 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 // If we are not currently running the exit animation, we
2923 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002924 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 // Try starting an animation; if there isn't one, we
2926 // can destroy the surface right away.
2927 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2928 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2929 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2930 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002931 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002933 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 } else if (win.isAnimating()) {
2936 // Currently in a hide animation... turn this into
2937 // an exit.
2938 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002939 } else if (win == mWallpaperTarget) {
2940 // If the wallpaper is currently behind this
2941 // window, we need to change both of them inside
2942 // of a transaction to avoid artifacts.
2943 win.mExiting = true;
2944 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 } else {
2946 if (mInputMethodWindow == win) {
2947 mInputMethodWindow = null;
2948 }
2949 win.destroySurfaceLocked();
2950 }
2951 }
2952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002953
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002954 if (win.mSurface == null || (win.getAttrs().flags
2955 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2956 || win.mSurfacePendingDestroy) {
2957 // We are being called from a local process, which
2958 // means outSurface holds its current surface. Ensure the
2959 // surface object is cleared, but we don't want it actually
2960 // destroyed at this point.
2961 win.mSurfacePendingDestroy = false;
2962 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002963 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002964 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002965 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002966 "Keeping surface, will report destroy: " + win);
2967 win.mReportDestroySurface = true;
2968 outSurface.copyFrom(win.mSurface);
2969 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 }
2971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 if (focusMayChange) {
2973 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002974 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2975 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 imMayMove = false;
2977 }
2978 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2979 }
Romain Guy06882f82009-06-10 13:36:04 -07002980
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002981 // updateFocusedWindowLocked() already assigned layers so we only need to
2982 // reassign them at this point if the IM window state gets shuffled
2983 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002986 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2987 // Little hack here -- we -should- be able to rely on the
2988 // function to return true if the IME has moved and needs
2989 // its layer recomputed. However, if the IME was hidden
2990 // and isn't actually moved in the list, its layer may be
2991 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 assignLayers = true;
2993 }
2994 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002995 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002996 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002997 assignLayers = true;
2998 }
2999 }
Romain Guy06882f82009-06-10 13:36:04 -07003000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 mLayoutNeeded = true;
3002 win.mGivenInsetsPending = insetsPending;
3003 if (assignLayers) {
3004 assignLayersLocked();
3005 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003006 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07003008 if (displayed && win.mIsWallpaper) {
3009 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07003010 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07003011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 if (win.mAppToken != null) {
3013 win.mAppToken.updateReportedVisibilityLocked();
3014 }
3015 outFrame.set(win.mFrame);
3016 outContentInsets.set(win.mContentInsets);
3017 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003018 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003020 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 + ", requestedHeight=" + requestedHeight
3022 + ", viewVisibility=" + viewVisibility
3023 + "\nRelayout returning frame=" + outFrame
3024 + ", surface=" + outSurface);
3025
Joe Onorato8a9b2202010-02-26 18:56:32 -08003026 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3028
3029 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003030
Jeff Brown2e44b072011-01-24 15:21:56 -08003031 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 }
3033
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003034 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 sendNewConfiguration();
3036 }
Romain Guy06882f82009-06-10 13:36:04 -07003037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3041 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3042 }
3043
3044 public void finishDrawingWindow(Session session, IWindow client) {
3045 final long origId = Binder.clearCallingIdentity();
3046 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003047 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003049 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3050 adjustWallpaperWindowsLocked();
3051 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003052 mLayoutNeeded = true;
3053 performLayoutAndPlaceSurfacesLocked();
3054 }
3055 }
3056 Binder.restoreCallingIdentity(origId);
3057 }
3058
3059 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003060 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 + (lp != null ? lp.packageName : null)
3062 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3063 if (lp != null && lp.windowAnimations != 0) {
3064 // If this is a system resource, don't try to load it from the
3065 // application resources. It is nice to avoid loading application
3066 // resources if we can.
3067 String packageName = lp.packageName != null ? lp.packageName : "android";
3068 int resId = lp.windowAnimations;
3069 if ((resId&0xFF000000) == 0x01000000) {
3070 packageName = "android";
3071 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003072 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 + packageName);
3074 return AttributeCache.instance().get(packageName, resId,
3075 com.android.internal.R.styleable.WindowAnimation);
3076 }
3077 return null;
3078 }
Romain Guy06882f82009-06-10 13:36:04 -07003079
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003080 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003081 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003082 + packageName + " resId=0x" + Integer.toHexString(resId));
3083 if (packageName != null) {
3084 if ((resId&0xFF000000) == 0x01000000) {
3085 packageName = "android";
3086 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003087 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003088 + packageName);
3089 return AttributeCache.instance().get(packageName, resId,
3090 com.android.internal.R.styleable.WindowAnimation);
3091 }
3092 return null;
3093 }
3094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 private void applyEnterAnimationLocked(WindowState win) {
3096 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3097 if (win.mEnterAnimationPending) {
3098 win.mEnterAnimationPending = false;
3099 transit = WindowManagerPolicy.TRANSIT_ENTER;
3100 }
3101
3102 applyAnimationLocked(win, transit, true);
3103 }
3104
3105 private boolean applyAnimationLocked(WindowState win,
3106 int transit, boolean isEntrance) {
3107 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3108 // If we are trying to apply an animation, but already running
3109 // an animation of the same type, then just leave that one alone.
3110 return true;
3111 }
Romain Guy06882f82009-06-10 13:36:04 -07003112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003113 // Only apply an animation if the display isn't frozen. If it is
3114 // frozen, there is no reason to animate and it can cause strange
3115 // artifacts when we unfreeze the display if some different animation
3116 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003117 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 int anim = mPolicy.selectAnimationLw(win, transit);
3119 int attr = -1;
3120 Animation a = null;
3121 if (anim != 0) {
3122 a = AnimationUtils.loadAnimation(mContext, anim);
3123 } else {
3124 switch (transit) {
3125 case WindowManagerPolicy.TRANSIT_ENTER:
3126 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3127 break;
3128 case WindowManagerPolicy.TRANSIT_EXIT:
3129 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3130 break;
3131 case WindowManagerPolicy.TRANSIT_SHOW:
3132 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3133 break;
3134 case WindowManagerPolicy.TRANSIT_HIDE:
3135 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3136 break;
3137 }
3138 if (attr >= 0) {
3139 a = loadAnimation(win.mAttrs, attr);
3140 }
3141 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003142 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3144 + " mAnimation=" + win.mAnimation
3145 + " isEntrance=" + isEntrance);
3146 if (a != null) {
3147 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003148 RuntimeException e = null;
3149 if (!HIDE_STACK_CRAWLS) {
3150 e = new RuntimeException();
3151 e.fillInStackTrace();
3152 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003153 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 }
3155 win.setAnimation(a);
3156 win.mAnimationIsEntrance = isEntrance;
3157 }
3158 } else {
3159 win.clearAnimation();
3160 }
3161
3162 return win.mAnimation != null;
3163 }
3164
3165 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3166 int anim = 0;
3167 Context context = mContext;
3168 if (animAttr >= 0) {
3169 AttributeCache.Entry ent = getCachedAnimations(lp);
3170 if (ent != null) {
3171 context = ent.context;
3172 anim = ent.array.getResourceId(animAttr, 0);
3173 }
3174 }
3175 if (anim != 0) {
3176 return AnimationUtils.loadAnimation(context, anim);
3177 }
3178 return null;
3179 }
Romain Guy06882f82009-06-10 13:36:04 -07003180
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003181 private Animation loadAnimation(String packageName, int resId) {
3182 int anim = 0;
3183 Context context = mContext;
3184 if (resId >= 0) {
3185 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3186 if (ent != null) {
3187 context = ent.context;
3188 anim = resId;
3189 }
3190 }
3191 if (anim != 0) {
3192 return AnimationUtils.loadAnimation(context, anim);
3193 }
3194 return null;
3195 }
3196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 private boolean applyAnimationLocked(AppWindowToken wtoken,
3198 WindowManager.LayoutParams lp, int transit, boolean enter) {
3199 // Only apply an animation if the display isn't frozen. If it is
3200 // frozen, there is no reason to animate and it can cause strange
3201 // artifacts when we unfreeze the display if some different animation
3202 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003203 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003204 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003205 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003206 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003207 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003208 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003209 } else if (mNextAppTransitionPackage != null) {
3210 a = loadAnimation(mNextAppTransitionPackage, enter ?
3211 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003212 } else {
3213 int animAttr = 0;
3214 switch (transit) {
3215 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3216 animAttr = enter
3217 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3218 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3219 break;
3220 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3221 animAttr = enter
3222 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3223 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3224 break;
3225 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3226 animAttr = enter
3227 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3228 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3229 break;
3230 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3231 animAttr = enter
3232 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3233 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3234 break;
3235 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3236 animAttr = enter
3237 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3238 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3239 break;
3240 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3241 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003242 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003243 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3244 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003245 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003246 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003247 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3248 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003249 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003250 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003251 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003252 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3253 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3254 break;
3255 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3256 animAttr = enter
3257 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3258 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3259 break;
3260 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3261 animAttr = enter
3262 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3263 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003264 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003265 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003266 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003267 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003268 + " anim=" + a
3269 + " animAttr=0x" + Integer.toHexString(animAttr)
3270 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 if (a != null) {
3273 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003274 RuntimeException e = null;
3275 if (!HIDE_STACK_CRAWLS) {
3276 e = new RuntimeException();
3277 e.fillInStackTrace();
3278 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003279 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 }
3281 wtoken.setAnimation(a);
3282 }
3283 } else {
3284 wtoken.clearAnimation();
3285 }
3286
3287 return wtoken.animation != null;
3288 }
3289
3290 // -------------------------------------------------------------
3291 // Application Window Tokens
3292 // -------------------------------------------------------------
3293
3294 public void validateAppTokens(List tokens) {
3295 int v = tokens.size()-1;
3296 int m = mAppTokens.size()-1;
3297 while (v >= 0 && m >= 0) {
3298 AppWindowToken wtoken = mAppTokens.get(m);
3299 if (wtoken.removed) {
3300 m--;
3301 continue;
3302 }
3303 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3306 }
3307 v--;
3308 m--;
3309 }
3310 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003311 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 v--;
3313 }
3314 while (m >= 0) {
3315 AppWindowToken wtoken = mAppTokens.get(m);
3316 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003317 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 }
3319 m--;
3320 }
3321 }
3322
3323 boolean checkCallingPermission(String permission, String func) {
3324 // Quick check: if the calling permission is me, it's all okay.
3325 if (Binder.getCallingPid() == Process.myPid()) {
3326 return true;
3327 }
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 if (mContext.checkCallingPermission(permission)
3330 == PackageManager.PERMISSION_GRANTED) {
3331 return true;
3332 }
3333 String msg = "Permission Denial: " + func + " from pid="
3334 + Binder.getCallingPid()
3335 + ", uid=" + Binder.getCallingUid()
3336 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003337 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 return false;
3339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 AppWindowToken findAppWindowToken(IBinder token) {
3342 WindowToken wtoken = mTokenMap.get(token);
3343 if (wtoken == null) {
3344 return null;
3345 }
3346 return wtoken.appWindowToken;
3347 }
Romain Guy06882f82009-06-10 13:36:04 -07003348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 public void addWindowToken(IBinder token, int type) {
3350 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3351 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003352 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 synchronized(mWindowMap) {
3356 WindowToken wtoken = mTokenMap.get(token);
3357 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003358 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 return;
3360 }
3361 wtoken = new WindowToken(token, type, true);
3362 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003363 if (type == TYPE_WALLPAPER) {
3364 mWallpaperTokens.add(wtoken);
3365 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 }
3367 }
Romain Guy06882f82009-06-10 13:36:04 -07003368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 public void removeWindowToken(IBinder token) {
3370 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3371 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003372 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 }
3374
3375 final long origId = Binder.clearCallingIdentity();
3376 synchronized(mWindowMap) {
3377 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 if (wtoken != null) {
3379 boolean delayed = false;
3380 if (!wtoken.hidden) {
3381 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 final int N = wtoken.windows.size();
3384 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 for (int i=0; i<N; i++) {
3387 WindowState win = wtoken.windows.get(i);
3388
3389 if (win.isAnimating()) {
3390 delayed = true;
3391 }
Romain Guy06882f82009-06-10 13:36:04 -07003392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 if (win.isVisibleNow()) {
3394 applyAnimationLocked(win,
3395 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003396 changed = true;
3397 }
3398 }
3399
3400 if (changed) {
3401 mLayoutNeeded = true;
3402 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003403 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3404 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 }
Romain Guy06882f82009-06-10 13:36:04 -07003406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 if (delayed) {
3408 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003409 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3410 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 }
3412 }
Romain Guy06882f82009-06-10 13:36:04 -07003413
Jeff Brown2e44b072011-01-24 15:21:56 -08003414 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003416 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 }
3418 }
3419 Binder.restoreCallingIdentity(origId);
3420 }
3421
3422 public void addAppToken(int addPos, IApplicationToken token,
3423 int groupId, int requestedOrientation, boolean fullscreen) {
3424 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3425 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003426 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003427 }
Jeff Brown349703e2010-06-22 01:27:15 -07003428
3429 // Get the dispatching timeout here while we are not holding any locks so that it
3430 // can be cached by the AppWindowToken. The timeout value is used later by the
3431 // input dispatcher in code that does hold locks. If we did not cache the value
3432 // here we would run the chance of introducing a deadlock between the window manager
3433 // (which holds locks while updating the input dispatcher state) and the activity manager
3434 // (which holds locks while querying the application token).
3435 long inputDispatchingTimeoutNanos;
3436 try {
3437 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3438 } catch (RemoteException ex) {
3439 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3440 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3441 }
Romain Guy06882f82009-06-10 13:36:04 -07003442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 synchronized(mWindowMap) {
3444 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3445 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003446 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447 return;
3448 }
3449 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003450 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451 wtoken.groupId = groupId;
3452 wtoken.appFullscreen = fullscreen;
3453 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003454 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003455 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458 // Application tokens start out hidden.
3459 wtoken.hidden = true;
3460 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003462 //dump();
3463 }
3464 }
Romain Guy06882f82009-06-10 13:36:04 -07003465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 public void setAppGroupId(IBinder token, int groupId) {
3467 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3468 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003469 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 }
3471
3472 synchronized(mWindowMap) {
3473 AppWindowToken wtoken = findAppWindowToken(token);
3474 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003475 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 return;
3477 }
3478 wtoken.groupId = groupId;
3479 }
3480 }
Romain Guy06882f82009-06-10 13:36:04 -07003481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 public int getOrientationFromWindowsLocked() {
3483 int pos = mWindows.size() - 1;
3484 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003485 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 pos--;
3487 if (wtoken.mAppToken != null) {
3488 // We hit an application window. so the orientation will be determined by the
3489 // app window. No point in continuing further.
3490 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3491 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003492 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 continue;
3494 }
3495 int req = wtoken.mAttrs.screenOrientation;
3496 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3497 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3498 continue;
3499 } else {
3500 return req;
3501 }
3502 }
3503 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3504 }
Romain Guy06882f82009-06-10 13:36:04 -07003505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003507 int pos = mAppTokens.size() - 1;
3508 int curGroup = 0;
3509 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3510 boolean findingBehind = false;
3511 boolean haveGroup = false;
3512 boolean lastFullscreen = false;
3513 while (pos >= 0) {
3514 AppWindowToken wtoken = mAppTokens.get(pos);
3515 pos--;
3516 // if we're about to tear down this window and not seek for
3517 // the behind activity, don't use it for orientation
3518 if (!findingBehind
3519 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3520 continue;
3521 }
3522
3523 if (!haveGroup) {
3524 // We ignore any hidden applications on the top.
3525 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003526 continue;
3527 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003528 haveGroup = true;
3529 curGroup = wtoken.groupId;
3530 lastOrientation = wtoken.requestedOrientation;
3531 } else if (curGroup != wtoken.groupId) {
3532 // If we have hit a new application group, and the bottom
3533 // of the previous group didn't explicitly say to use
3534 // the orientation behind it, and the last app was
3535 // full screen, then we'll stick with the
3536 // user's orientation.
3537 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3538 && lastFullscreen) {
3539 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003542 int or = wtoken.requestedOrientation;
3543 // If this application is fullscreen, and didn't explicitly say
3544 // to use the orientation behind it, then just take whatever
3545 // orientation it has and ignores whatever is under it.
3546 lastFullscreen = wtoken.appFullscreen;
3547 if (lastFullscreen
3548 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3549 return or;
3550 }
3551 // If this application has requested an explicit orientation,
3552 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003553 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3554 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003555 return or;
3556 }
3557 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3558 }
3559 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 }
Romain Guy06882f82009-06-10 13:36:04 -07003561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003563 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003564 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3565 "updateOrientationFromAppTokens()")) {
3566 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003568
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003569 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003571
3572 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003573 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003574 if (freezeThisOneIfNeeded != null) {
3575 AppWindowToken wtoken = findAppWindowToken(
3576 freezeThisOneIfNeeded);
3577 if (wtoken != null) {
3578 startAppFreezingScreenLocked(wtoken,
3579 ActivityInfo.CONFIG_ORIENTATION);
3580 }
3581 }
3582 config = computeNewConfigurationLocked();
3583
3584 } else if (currentConfig != null) {
3585 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003586 // state mismatches the activity manager's, update it,
3587 // disregarding font scale, which should remain set to
3588 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003589 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003590 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003591 if (computeNewConfigurationLocked(mTempConfiguration)) {
3592 if (currentConfig.diff(mTempConfiguration) != 0) {
3593 mWaitingForConfig = true;
3594 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003595 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003596 config = new Configuration(mTempConfiguration);
3597 }
3598 }
3599 }
3600 }
3601
Dianne Hackborncfaef692009-06-15 14:24:44 -07003602 Binder.restoreCallingIdentity(ident);
3603 return config;
3604 }
3605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003607 * Determine the new desired orientation of the display, returning
3608 * a non-null new Configuration if it has changed from the current
3609 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3610 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3611 * SCREEN. This will typically be done for you if you call
3612 * sendNewConfiguration().
3613 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 * The orientation is computed from non-application windows first. If none of
3615 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003616 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3618 * android.os.IBinder)
3619 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003620 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3621 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003622 // If the display is frozen, some activities may be in the middle
3623 // of restarting, and thus have removed their old window. If the
3624 // window has the flag to hide the lock screen, then the lock screen
3625 // can re-appear and inflict its own orientation on us. Keep the
3626 // orientation stable until this all settles down.
3627 return false;
3628 }
3629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 long ident = Binder.clearCallingIdentity();
3632 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003633 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 mForcedAppOrientation = req;
3637 //send a message to Policy indicating orientation change to take
3638 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003639 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003640 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003641 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3642 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003643 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 }
3645 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003646
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003647 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 } finally {
3649 Binder.restoreCallingIdentity(ident);
3650 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 }
Romain Guy06882f82009-06-10 13:36:04 -07003652
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003653 int computeForcedAppOrientationLocked() {
3654 int req = getOrientationFromWindowsLocked();
3655 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3656 req = getOrientationFromAppTokensLocked();
3657 }
3658 return req;
3659 }
Romain Guy06882f82009-06-10 13:36:04 -07003660
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003661 public void setNewConfiguration(Configuration config) {
3662 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3663 "setNewConfiguration()")) {
3664 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3665 }
3666
3667 synchronized(mWindowMap) {
3668 mCurConfiguration = new Configuration(config);
3669 mWaitingForConfig = false;
3670 performLayoutAndPlaceSurfacesLocked();
3671 }
3672 }
3673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3675 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3676 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003677 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 }
Romain Guy06882f82009-06-10 13:36:04 -07003679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 synchronized(mWindowMap) {
3681 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3682 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003683 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 return;
3685 }
Romain Guy06882f82009-06-10 13:36:04 -07003686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 wtoken.requestedOrientation = requestedOrientation;
3688 }
3689 }
Romain Guy06882f82009-06-10 13:36:04 -07003690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 public int getAppOrientation(IApplicationToken token) {
3692 synchronized(mWindowMap) {
3693 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3694 if (wtoken == null) {
3695 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3696 }
Romain Guy06882f82009-06-10 13:36:04 -07003697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 return wtoken.requestedOrientation;
3699 }
3700 }
Romain Guy06882f82009-06-10 13:36:04 -07003701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3703 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3704 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003705 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 }
3707
3708 synchronized(mWindowMap) {
3709 boolean changed = false;
3710 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003711 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 changed = mFocusedApp != null;
3713 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003714 if (changed) {
3715 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003717 } else {
3718 AppWindowToken newFocus = findAppWindowToken(token);
3719 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003720 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 return;
3722 }
3723 changed = mFocusedApp != newFocus;
3724 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003725 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003726 if (changed) {
3727 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 }
3730
3731 if (moveFocusNow && changed) {
3732 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003733 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 Binder.restoreCallingIdentity(origId);
3735 }
3736 }
3737 }
3738
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003739 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3741 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003742 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 }
Romain Guy06882f82009-06-10 13:36:04 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003746 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 TAG, "Prepare app transition: transit=" + transit
3748 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003749 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003750 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3751 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003752 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003753 } else if (!alwaysKeepCurrent) {
3754 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3755 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3756 // Opening a new task always supersedes a close for the anim.
3757 mNextAppTransition = transit;
3758 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3759 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3760 // Opening a new activity always supersedes a close for the anim.
3761 mNextAppTransition = transit;
3762 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 }
3764 mAppTransitionReady = false;
3765 mAppTransitionTimeout = false;
3766 mStartingIconInTransition = false;
3767 mSkipAppTransitionAnimation = false;
3768 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3769 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3770 5000);
3771 }
3772 }
3773 }
3774
3775 public int getPendingAppTransition() {
3776 return mNextAppTransition;
3777 }
Romain Guy06882f82009-06-10 13:36:04 -07003778
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003779 public void overridePendingAppTransition(String packageName,
3780 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003781 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003782 mNextAppTransitionPackage = packageName;
3783 mNextAppTransitionEnter = enterAnim;
3784 mNextAppTransitionExit = exitAnim;
3785 }
3786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 public void executeAppTransition() {
3789 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3790 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003791 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 }
Romain Guy06882f82009-06-10 13:36:04 -07003793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003795 if (DEBUG_APP_TRANSITIONS) {
3796 RuntimeException e = new RuntimeException("here");
3797 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003798 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003799 + mNextAppTransition, e);
3800 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003801 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 mAppTransitionReady = true;
3803 final long origId = Binder.clearCallingIdentity();
3804 performLayoutAndPlaceSurfacesLocked();
3805 Binder.restoreCallingIdentity(origId);
3806 }
3807 }
3808 }
3809
3810 public void setAppStartingWindow(IBinder token, String pkg,
3811 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003812 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3814 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003815 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 }
3817
3818 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003819 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3821 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 AppWindowToken wtoken = findAppWindowToken(token);
3824 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003825 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 return;
3827 }
3828
3829 // If the display is frozen, we won't do anything until the
3830 // actual window is displayed so there is no reason to put in
3831 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003832 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 return;
3834 }
Romain Guy06882f82009-06-10 13:36:04 -07003835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 if (wtoken.startingData != null) {
3837 return;
3838 }
Romain Guy06882f82009-06-10 13:36:04 -07003839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 if (transferFrom != null) {
3841 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3842 if (ttoken != null) {
3843 WindowState startingWindow = ttoken.startingWindow;
3844 if (startingWindow != null) {
3845 if (mStartingIconInTransition) {
3846 // In this case, the starting icon has already
3847 // been displayed, so start letting windows get
3848 // shown immediately without any more transitions.
3849 mSkipAppTransitionAnimation = true;
3850 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003851 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 "Moving existing starting from " + ttoken
3853 + " to " + wtoken);
3854 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 // Transfer the starting window over to the new
3857 // token.
3858 wtoken.startingData = ttoken.startingData;
3859 wtoken.startingView = ttoken.startingView;
3860 wtoken.startingWindow = startingWindow;
3861 ttoken.startingData = null;
3862 ttoken.startingView = null;
3863 ttoken.startingWindow = null;
3864 ttoken.startingMoved = true;
3865 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003866 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003868 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003869 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003870 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003871 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003872 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3873 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 ttoken.windows.remove(startingWindow);
3875 ttoken.allAppWindows.remove(startingWindow);
3876 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 // Propagate other interesting state between the
3879 // tokens. If the old token is displayed, we should
3880 // immediately force the new one to be displayed. If
3881 // it is animating, we need to move that animation to
3882 // the new one.
3883 if (ttoken.allDrawn) {
3884 wtoken.allDrawn = true;
3885 }
3886 if (ttoken.firstWindowDrawn) {
3887 wtoken.firstWindowDrawn = true;
3888 }
3889 if (!ttoken.hidden) {
3890 wtoken.hidden = false;
3891 wtoken.hiddenRequested = false;
3892 wtoken.willBeHidden = false;
3893 }
3894 if (wtoken.clientHidden != ttoken.clientHidden) {
3895 wtoken.clientHidden = ttoken.clientHidden;
3896 wtoken.sendAppVisibilityToClients();
3897 }
3898 if (ttoken.animation != null) {
3899 wtoken.animation = ttoken.animation;
3900 wtoken.animating = ttoken.animating;
3901 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3902 ttoken.animation = null;
3903 ttoken.animLayerAdjustment = 0;
3904 wtoken.updateLayers();
3905 ttoken.updateLayers();
3906 }
Romain Guy06882f82009-06-10 13:36:04 -07003907
Jeff Brown3a22cd92011-01-21 13:59:04 -08003908 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3909 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 mLayoutNeeded = true;
3911 performLayoutAndPlaceSurfacesLocked();
3912 Binder.restoreCallingIdentity(origId);
3913 return;
3914 } else if (ttoken.startingData != null) {
3915 // The previous app was getting ready to show a
3916 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003917 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 "Moving pending starting from " + ttoken
3919 + " to " + wtoken);
3920 wtoken.startingData = ttoken.startingData;
3921 ttoken.startingData = null;
3922 ttoken.startingMoved = true;
3923 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3924 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3925 // want to process the message ASAP, before any other queued
3926 // messages.
3927 mH.sendMessageAtFrontOfQueue(m);
3928 return;
3929 }
3930 }
3931 }
3932
3933 // There is no existing starting window, and the caller doesn't
3934 // want us to create one, so that's it!
3935 if (!createIfNeeded) {
3936 return;
3937 }
Romain Guy06882f82009-06-10 13:36:04 -07003938
Dianne Hackborn284ac932009-08-28 10:34:25 -07003939 // If this is a translucent or wallpaper window, then don't
3940 // show a starting window -- the current effect (a full-screen
3941 // opaque starting window that fades away to the real contents
3942 // when it is ready) does not work for this.
3943 if (theme != 0) {
3944 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3945 com.android.internal.R.styleable.Window);
3946 if (ent.array.getBoolean(
3947 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3948 return;
3949 }
3950 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003951 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3952 return;
3953 }
3954 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003955 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3956 return;
3957 }
3958 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 mStartingIconInTransition = true;
3961 wtoken.startingData = new StartingData(
3962 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003963 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3965 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3966 // want to process the message ASAP, before any other queued
3967 // messages.
3968 mH.sendMessageAtFrontOfQueue(m);
3969 }
3970 }
3971
3972 public void setAppWillBeHidden(IBinder token) {
3973 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3974 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003975 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 }
3977
3978 AppWindowToken wtoken;
3979
3980 synchronized(mWindowMap) {
3981 wtoken = findAppWindowToken(token);
3982 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003983 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 -08003984 return;
3985 }
3986 wtoken.willBeHidden = true;
3987 }
3988 }
Romain Guy06882f82009-06-10 13:36:04 -07003989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3991 boolean visible, int transit, boolean performLayout) {
3992 boolean delayed = false;
3993
3994 if (wtoken.clientHidden == visible) {
3995 wtoken.clientHidden = !visible;
3996 wtoken.sendAppVisibilityToClients();
3997 }
Romain Guy06882f82009-06-10 13:36:04 -07003998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 wtoken.willBeHidden = false;
4000 if (wtoken.hidden == visible) {
4001 final int N = wtoken.allAppWindows.size();
4002 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
4005 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07004006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07004008
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004009 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 if (wtoken.animation == sDummyAnimation) {
4011 wtoken.animation = null;
4012 }
4013 applyAnimationLocked(wtoken, lp, transit, visible);
4014 changed = true;
4015 if (wtoken.animation != null) {
4016 delayed = runningAppAnimation = true;
4017 }
4018 }
Romain Guy06882f82009-06-10 13:36:04 -07004019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004020 for (int i=0; i<N; i++) {
4021 WindowState win = wtoken.allAppWindows.get(i);
4022 if (win == wtoken.startingWindow) {
4023 continue;
4024 }
4025
4026 if (win.isAnimating()) {
4027 delayed = true;
4028 }
Romain Guy06882f82009-06-10 13:36:04 -07004029
Joe Onorato8a9b2202010-02-26 18:56:32 -08004030 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 //win.dump(" ");
4032 if (visible) {
4033 if (!win.isVisibleNow()) {
4034 if (!runningAppAnimation) {
4035 applyAnimationLocked(win,
4036 WindowManagerPolicy.TRANSIT_ENTER, true);
4037 }
4038 changed = true;
4039 }
4040 } else if (win.isVisibleNow()) {
4041 if (!runningAppAnimation) {
4042 applyAnimationLocked(win,
4043 WindowManagerPolicy.TRANSIT_EXIT, false);
4044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 changed = true;
4046 }
4047 }
4048
4049 wtoken.hidden = wtoken.hiddenRequested = !visible;
4050 if (!visible) {
4051 unsetAppFreezingScreenLocked(wtoken, true, true);
4052 } else {
4053 // If we are being set visible, and the starting window is
4054 // not yet displayed, then make sure it doesn't get displayed.
4055 WindowState swin = wtoken.startingWindow;
4056 if (swin != null && (swin.mDrawPending
4057 || swin.mCommitDrawPending)) {
4058 swin.mPolicyVisibility = false;
4059 swin.mPolicyVisibilityAfterAnim = false;
4060 }
4061 }
Romain Guy06882f82009-06-10 13:36:04 -07004062
Joe Onorato8a9b2202010-02-26 18:56:32 -08004063 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4065 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004066
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004067 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004069 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004070 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004071 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4072 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004073 performLayoutAndPlaceSurfacesLocked();
4074 }
Jeff Brown2e44b072011-01-24 15:21:56 -08004075 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 }
4077 }
4078
4079 if (wtoken.animation != null) {
4080 delayed = true;
4081 }
Romain Guy06882f82009-06-10 13:36:04 -07004082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 return delayed;
4084 }
4085
4086 public void setAppVisibility(IBinder token, boolean visible) {
4087 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4088 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004089 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004090 }
4091
4092 AppWindowToken wtoken;
4093
4094 synchronized(mWindowMap) {
4095 wtoken = findAppWindowToken(token);
4096 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004097 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 return;
4099 }
4100
4101 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004102 RuntimeException e = null;
4103 if (!HIDE_STACK_CRAWLS) {
4104 e = new RuntimeException();
4105 e.fillInStackTrace();
4106 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004107 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 + "): mNextAppTransition=" + mNextAppTransition
4109 + " hidden=" + wtoken.hidden
4110 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4111 }
Romain Guy06882f82009-06-10 13:36:04 -07004112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 // If we are preparing an app transition, then delay changing
4114 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004115 if (!mDisplayFrozen && mPolicy.isScreenOn()
4116 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 // Already in requested state, don't do anything more.
4118 if (wtoken.hiddenRequested != visible) {
4119 return;
4120 }
4121 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004122
Joe Onorato8a9b2202010-02-26 18:56:32 -08004123 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 TAG, "Setting dummy animation on: " + wtoken);
4125 wtoken.setDummyAnimation();
4126 mOpeningApps.remove(wtoken);
4127 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004128 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 wtoken.inPendingTransaction = true;
4130 if (visible) {
4131 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 wtoken.startingDisplayed = false;
4133 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004134
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004135 // If the token is currently hidden (should be the
4136 // common case), then we need to set up to wait for
4137 // its windows to be ready.
4138 if (wtoken.hidden) {
4139 wtoken.allDrawn = false;
4140 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004141
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004142 if (wtoken.clientHidden) {
4143 // In the case where we are making an app visible
4144 // but holding off for a transition, we still need
4145 // to tell the client to make its windows visible so
4146 // they get drawn. Otherwise, we will wait on
4147 // performing the transition until all windows have
4148 // been drawn, they never will be, and we are sad.
4149 wtoken.clientHidden = false;
4150 wtoken.sendAppVisibilityToClients();
4151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 }
4153 } else {
4154 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004155
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004156 // If the token is currently visible (should be the
4157 // common case), then set up to wait for it to be hidden.
4158 if (!wtoken.hidden) {
4159 wtoken.waitingToHide = true;
4160 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 }
4162 return;
4163 }
Romain Guy06882f82009-06-10 13:36:04 -07004164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004166 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004167 wtoken.updateReportedVisibilityLocked();
4168 Binder.restoreCallingIdentity(origId);
4169 }
4170 }
4171
4172 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4173 boolean unfreezeSurfaceNow, boolean force) {
4174 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004175 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004176 + " force=" + force);
4177 final int N = wtoken.allAppWindows.size();
4178 boolean unfrozeWindows = false;
4179 for (int i=0; i<N; i++) {
4180 WindowState w = wtoken.allAppWindows.get(i);
4181 if (w.mAppFreezing) {
4182 w.mAppFreezing = false;
4183 if (w.mSurface != null && !w.mOrientationChanging) {
4184 w.mOrientationChanging = true;
4185 }
4186 unfrozeWindows = true;
4187 }
4188 }
4189 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004190 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191 wtoken.freezingScreen = false;
4192 mAppsFreezingScreen--;
4193 }
4194 if (unfreezeSurfaceNow) {
4195 if (unfrozeWindows) {
4196 mLayoutNeeded = true;
4197 performLayoutAndPlaceSurfacesLocked();
4198 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004199 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 }
4201 }
4202 }
Romain Guy06882f82009-06-10 13:36:04 -07004203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4205 int configChanges) {
4206 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004207 RuntimeException e = null;
4208 if (!HIDE_STACK_CRAWLS) {
4209 e = new RuntimeException();
4210 e.fillInStackTrace();
4211 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004212 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 + ": hidden=" + wtoken.hidden + " freezing="
4214 + wtoken.freezingScreen, e);
4215 }
4216 if (!wtoken.hiddenRequested) {
4217 if (!wtoken.freezingScreen) {
4218 wtoken.freezingScreen = true;
4219 mAppsFreezingScreen++;
4220 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004221 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004222 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4223 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4224 5000);
4225 }
4226 }
4227 final int N = wtoken.allAppWindows.size();
4228 for (int i=0; i<N; i++) {
4229 WindowState w = wtoken.allAppWindows.get(i);
4230 w.mAppFreezing = true;
4231 }
4232 }
4233 }
Romain Guy06882f82009-06-10 13:36:04 -07004234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004235 public void startAppFreezingScreen(IBinder token, int configChanges) {
4236 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4237 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004238 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004239 }
4240
4241 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004242 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004243 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 return;
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 AppWindowToken wtoken = findAppWindowToken(token);
4248 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004249 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 return;
4251 }
4252 final long origId = Binder.clearCallingIdentity();
4253 startAppFreezingScreenLocked(wtoken, configChanges);
4254 Binder.restoreCallingIdentity(origId);
4255 }
4256 }
Romain Guy06882f82009-06-10 13:36:04 -07004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 public void stopAppFreezingScreen(IBinder token, boolean force) {
4259 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4260 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004261 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 }
4263
4264 synchronized(mWindowMap) {
4265 AppWindowToken wtoken = findAppWindowToken(token);
4266 if (wtoken == null || wtoken.appToken == null) {
4267 return;
4268 }
4269 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004270 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4272 unsetAppFreezingScreenLocked(wtoken, true, force);
4273 Binder.restoreCallingIdentity(origId);
4274 }
4275 }
Romain Guy06882f82009-06-10 13:36:04 -07004276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 public void removeAppToken(IBinder token) {
4278 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4279 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004280 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 }
4282
4283 AppWindowToken wtoken = null;
4284 AppWindowToken startingToken = null;
4285 boolean delayed = false;
4286
4287 final long origId = Binder.clearCallingIdentity();
4288 synchronized(mWindowMap) {
4289 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004291 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004292 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 wtoken.inPendingTransaction = false;
4294 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004295 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 if (mClosingApps.contains(wtoken)) {
4297 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004298 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004300 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 delayed = true;
4302 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004303 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 TAG, "Removing app " + wtoken + " delayed=" + delayed
4305 + " animation=" + wtoken.animation
4306 + " animating=" + wtoken.animating);
4307 if (delayed) {
4308 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004309 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4310 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004312 } else {
4313 // Make sure there is no animation running on this token,
4314 // so any windows associated with it will be removed as
4315 // soon as their animations are complete
4316 wtoken.animation = null;
4317 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004319 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4320 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 mAppTokens.remove(wtoken);
4322 wtoken.removed = true;
4323 if (wtoken.startingData != null) {
4324 startingToken = wtoken;
4325 }
4326 unsetAppFreezingScreenLocked(wtoken, true, true);
4327 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004328 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004330 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004331 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
4333 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004334 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 }
Romain Guy06882f82009-06-10 13:36:04 -07004336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 if (!delayed && wtoken != null) {
4338 wtoken.updateReportedVisibilityLocked();
4339 }
4340 }
4341 Binder.restoreCallingIdentity(origId);
4342
4343 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004344 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 + startingToken + ": app token removed");
4346 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4347 mH.sendMessage(m);
4348 }
4349 }
4350
4351 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4352 final int NW = token.windows.size();
4353 for (int i=0; i<NW; i++) {
4354 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004355 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004357 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 int j = win.mChildWindows.size();
4359 while (j > 0) {
4360 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004361 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004363 "Tmp removing child window " + cwin);
4364 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
4366 }
4367 return NW > 0;
4368 }
4369
4370 void dumpAppTokensLocked() {
4371 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004372 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 }
4374 }
Romain Guy06882f82009-06-10 13:36:04 -07004375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 void dumpWindowsLocked() {
4377 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004378 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 }
4380 }
Romain Guy06882f82009-06-10 13:36:04 -07004381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004382 private int findWindowOffsetLocked(int tokenPos) {
4383 final int NW = mWindows.size();
4384
4385 if (tokenPos >= mAppTokens.size()) {
4386 int i = NW;
4387 while (i > 0) {
4388 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004389 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 if (win.getAppToken() != null) {
4391 return i+1;
4392 }
4393 }
4394 }
4395
4396 while (tokenPos > 0) {
4397 // Find the first app token below the new position that has
4398 // a window displayed.
4399 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004400 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004402 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004403 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004404 "Skipping token -- currently sending to bottom");
4405 tokenPos--;
4406 continue;
4407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 int i = wtoken.windows.size();
4409 while (i > 0) {
4410 i--;
4411 WindowState win = wtoken.windows.get(i);
4412 int j = win.mChildWindows.size();
4413 while (j > 0) {
4414 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004415 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004416 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 for (int pos=NW-1; pos>=0; pos--) {
4418 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004419 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 "Found child win @" + (pos+1));
4421 return pos+1;
4422 }
4423 }
4424 }
4425 }
4426 for (int pos=NW-1; pos>=0; pos--) {
4427 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004428 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004429 return pos+1;
4430 }
4431 }
4432 }
4433 tokenPos--;
4434 }
4435
4436 return 0;
4437 }
4438
4439 private final int reAddWindowLocked(int index, WindowState win) {
4440 final int NCW = win.mChildWindows.size();
4441 boolean added = false;
4442 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004443 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004446 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004447 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 mWindows.add(index, win);
4449 index++;
4450 added = true;
4451 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004452 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004453 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004454 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 mWindows.add(index, cwin);
4456 index++;
4457 }
4458 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004459 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004460 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004461 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 mWindows.add(index, win);
4463 index++;
4464 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004465 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 return index;
4467 }
Romain Guy06882f82009-06-10 13:36:04 -07004468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4470 final int NW = token.windows.size();
4471 for (int i=0; i<NW; i++) {
4472 index = reAddWindowLocked(index, token.windows.get(i));
4473 }
4474 return index;
4475 }
4476
4477 public void moveAppToken(int index, IBinder token) {
4478 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4479 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004480 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 }
4482
4483 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004484 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 if (DEBUG_REORDER) dumpAppTokensLocked();
4486 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004487 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4488 "Start moving token " + wtoken + " initially at "
4489 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004491 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 + token + " (" + wtoken + ")");
4493 return;
4494 }
4495 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004496 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004497 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004500 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004501 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 if (DEBUG_REORDER) dumpWindowsLocked();
4503 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004504 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 if (DEBUG_REORDER) dumpWindowsLocked();
4506 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004507 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004509 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4510 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004512 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004514 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 }
4516 Binder.restoreCallingIdentity(origId);
4517 }
4518 }
4519
4520 private void removeAppTokensLocked(List<IBinder> tokens) {
4521 // XXX This should be done more efficiently!
4522 // (take advantage of the fact that both lists should be
4523 // ordered in the same way.)
4524 int N = tokens.size();
4525 for (int i=0; i<N; i++) {
4526 IBinder token = tokens.get(i);
4527 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004528 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4529 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004531 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 + token + " (" + wtoken + ")");
4533 i--;
4534 N--;
4535 }
4536 }
4537 }
4538
Dianne Hackborna8f60182009-09-01 19:01:50 -07004539 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4540 boolean updateFocusAndLayout) {
4541 // First remove all of the windows from the list.
4542 tmpRemoveAppWindowsLocked(wtoken);
4543
4544 // Where to start adding?
4545 int pos = findWindowOffsetLocked(tokenPos);
4546
4547 // And now add them back at the correct place.
4548 pos = reAddAppWindowsLocked(pos, wtoken);
4549
4550 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004551 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004552 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4553 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004554 assignLayersLocked();
4555 }
4556 mLayoutNeeded = true;
4557 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004558 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004559 }
4560 }
4561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004562 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4563 // First remove all of the windows from the list.
4564 final int N = tokens.size();
4565 int i;
4566 for (i=0; i<N; i++) {
4567 WindowToken token = mTokenMap.get(tokens.get(i));
4568 if (token != null) {
4569 tmpRemoveAppWindowsLocked(token);
4570 }
4571 }
4572
4573 // Where to start adding?
4574 int pos = findWindowOffsetLocked(tokenPos);
4575
4576 // And now add them back at the correct place.
4577 for (i=0; i<N; i++) {
4578 WindowToken token = mTokenMap.get(tokens.get(i));
4579 if (token != null) {
4580 pos = reAddAppWindowsLocked(pos, token);
4581 }
4582 }
4583
Jeff Brown2e44b072011-01-24 15:21:56 -08004584 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004585 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4586 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004587 assignLayersLocked();
4588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004589 mLayoutNeeded = true;
4590 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004591 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592
4593 //dump();
4594 }
4595
4596 public void moveAppTokensToTop(List<IBinder> tokens) {
4597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4598 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 }
4601
4602 final long origId = Binder.clearCallingIdentity();
4603 synchronized(mWindowMap) {
4604 removeAppTokensLocked(tokens);
4605 final int N = tokens.size();
4606 for (int i=0; i<N; i++) {
4607 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4608 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004609 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4610 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004612 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004613 mToTopApps.remove(wt);
4614 mToBottomApps.remove(wt);
4615 mToTopApps.add(wt);
4616 wt.sendingToBottom = false;
4617 wt.sendingToTop = true;
4618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004619 }
4620 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004621
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004622 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004623 moveAppWindowsLocked(tokens, mAppTokens.size());
4624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004625 }
4626 Binder.restoreCallingIdentity(origId);
4627 }
4628
4629 public void moveAppTokensToBottom(List<IBinder> tokens) {
4630 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4631 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004632 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
4634
4635 final long origId = Binder.clearCallingIdentity();
4636 synchronized(mWindowMap) {
4637 removeAppTokensLocked(tokens);
4638 final int N = tokens.size();
4639 int pos = 0;
4640 for (int i=0; i<N; i++) {
4641 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4642 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004643 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4644 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004646 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004647 mToTopApps.remove(wt);
4648 mToBottomApps.remove(wt);
4649 mToBottomApps.add(i, wt);
4650 wt.sendingToTop = false;
4651 wt.sendingToBottom = true;
4652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 pos++;
4654 }
4655 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004656
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004657 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004658 moveAppWindowsLocked(tokens, 0);
4659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 }
4661 Binder.restoreCallingIdentity(origId);
4662 }
4663
4664 // -------------------------------------------------------------
4665 // Misc IWindowSession methods
4666 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004667
Jim Miller284b62e2010-06-08 14:27:42 -07004668 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004669 {
Jim Miller284b62e2010-06-08 14:27:42 -07004670 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4671 // called before DevicePolicyManagerService has started.
4672 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4673 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4674 Context.DEVICE_POLICY_SERVICE);
4675 if (dpm != null) {
4676 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4677 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4678 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4679 }
Jim Millerd6b57052010-06-07 17:52:42 -07004680 }
Jim Miller284b62e2010-06-08 14:27:42 -07004681 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004682 }
4683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004685 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 != PackageManager.PERMISSION_GRANTED) {
4687 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4688 }
Jim Millerd6b57052010-06-07 17:52:42 -07004689
Jim Miller284b62e2010-06-08 14:27:42 -07004690 synchronized (mKeyguardTokenWatcher) {
4691 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004692 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 }
4694
4695 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004696 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 != PackageManager.PERMISSION_GRANTED) {
4698 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4699 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700
Jim Miller284b62e2010-06-08 14:27:42 -07004701 synchronized (mKeyguardTokenWatcher) {
4702 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004703
Jim Miller284b62e2010-06-08 14:27:42 -07004704 if (!mKeyguardTokenWatcher.isAcquired()) {
4705 // If we are the last one to reenable the keyguard wait until
4706 // we have actually finished reenabling until returning.
4707 // It is possible that reenableKeyguard() can be called before
4708 // the previous disableKeyguard() is handled, in which case
4709 // neither mKeyguardTokenWatcher.acquired() or released() would
4710 // be called. In that case mKeyguardDisabled will be false here
4711 // and we have nothing to wait for.
4712 while (mKeyguardDisabled) {
4713 try {
4714 mKeyguardTokenWatcher.wait();
4715 } catch (InterruptedException e) {
4716 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 }
4718 }
4719 }
4720 }
4721 }
4722
4723 /**
4724 * @see android.app.KeyguardManager#exitKeyguardSecurely
4725 */
4726 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004727 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004728 != PackageManager.PERMISSION_GRANTED) {
4729 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4730 }
4731 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4732 public void onKeyguardExitResult(boolean success) {
4733 try {
4734 callback.onKeyguardExitResult(success);
4735 } catch (RemoteException e) {
4736 // Client has died, we don't care.
4737 }
4738 }
4739 });
4740 }
4741
4742 public boolean inKeyguardRestrictedInputMode() {
4743 return mPolicy.inKeyguardRestrictedKeyInputMode();
4744 }
Romain Guy06882f82009-06-10 13:36:04 -07004745
Dianne Hackbornffa42482009-09-23 22:20:11 -07004746 public void closeSystemDialogs(String reason) {
4747 synchronized(mWindowMap) {
4748 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004749 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004750 if (w.mSurface != null) {
4751 try {
4752 w.mClient.closeSystemDialogs(reason);
4753 } catch (RemoteException e) {
4754 }
4755 }
4756 }
4757 }
4758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004760 static float fixScale(float scale) {
4761 if (scale < 0) scale = 0;
4762 else if (scale > 20) scale = 20;
4763 return Math.abs(scale);
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 public void setAnimationScale(int which, float scale) {
4767 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4768 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004769 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 }
4771
4772 if (scale < 0) scale = 0;
4773 else if (scale > 20) scale = 20;
4774 scale = Math.abs(scale);
4775 switch (which) {
4776 case 0: mWindowAnimationScale = fixScale(scale); break;
4777 case 1: mTransitionAnimationScale = fixScale(scale); break;
4778 }
Romain Guy06882f82009-06-10 13:36:04 -07004779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004780 // Persist setting
4781 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4782 }
Romain Guy06882f82009-06-10 13:36:04 -07004783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004784 public void setAnimationScales(float[] scales) {
4785 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4786 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004787 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 }
4789
4790 if (scales != null) {
4791 if (scales.length >= 1) {
4792 mWindowAnimationScale = fixScale(scales[0]);
4793 }
4794 if (scales.length >= 2) {
4795 mTransitionAnimationScale = fixScale(scales[1]);
4796 }
4797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 // Persist setting
4800 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4801 }
Romain Guy06882f82009-06-10 13:36:04 -07004802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 public float getAnimationScale(int which) {
4804 switch (which) {
4805 case 0: return mWindowAnimationScale;
4806 case 1: return mTransitionAnimationScale;
4807 }
4808 return 0;
4809 }
Romain Guy06882f82009-06-10 13:36:04 -07004810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 public float[] getAnimationScales() {
4812 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4813 }
Romain Guy06882f82009-06-10 13:36:04 -07004814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 public int getSwitchState(int sw) {
4816 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4817 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004818 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004819 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004820 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 }
Romain Guy06882f82009-06-10 13:36:04 -07004822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 public int getSwitchStateForDevice(int devid, int sw) {
4824 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4825 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004826 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004828 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 }
Romain Guy06882f82009-06-10 13:36:04 -07004830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 public int getScancodeState(int sw) {
4832 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4833 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004834 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004835 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004836 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 }
Romain Guy06882f82009-06-10 13:36:04 -07004838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 public int getScancodeStateForDevice(int devid, int sw) {
4840 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4841 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004842 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004843 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004844 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 }
Romain Guy06882f82009-06-10 13:36:04 -07004846
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004847 public int getTrackballScancodeState(int sw) {
4848 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4849 "getTrackballScancodeState()")) {
4850 throw new SecurityException("Requires READ_INPUT_STATE permission");
4851 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004852 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004853 }
4854
4855 public int getDPadScancodeState(int sw) {
4856 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4857 "getDPadScancodeState()")) {
4858 throw new SecurityException("Requires READ_INPUT_STATE permission");
4859 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004860 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004861 }
4862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 public int getKeycodeState(int sw) {
4864 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4865 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004866 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004868 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004869 }
Romain Guy06882f82009-06-10 13:36:04 -07004870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 public int getKeycodeStateForDevice(int devid, int sw) {
4872 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4873 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004874 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004875 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004876 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004877 }
Romain Guy06882f82009-06-10 13:36:04 -07004878
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004879 public int getTrackballKeycodeState(int sw) {
4880 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4881 "getTrackballKeycodeState()")) {
4882 throw new SecurityException("Requires READ_INPUT_STATE permission");
4883 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004884 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004885 }
4886
4887 public int getDPadKeycodeState(int sw) {
4888 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4889 "getDPadKeycodeState()")) {
4890 throw new SecurityException("Requires READ_INPUT_STATE permission");
4891 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004892 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004893 }
Jeff Browna41ca772010-08-11 14:46:32 -07004894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004896 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 }
Romain Guy06882f82009-06-10 13:36:04 -07004898
Jeff Browna41ca772010-08-11 14:46:32 -07004899 public InputChannel monitorInput(String inputChannelName) {
4900 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4901 "monitorInput()")) {
4902 throw new SecurityException("Requires READ_INPUT_STATE permission");
4903 }
4904 return mInputManager.monitorInput(inputChannelName);
4905 }
4906
Jeff Brown8d608662010-08-30 03:02:23 -07004907 public InputDevice getInputDevice(int deviceId) {
4908 return mInputManager.getInputDevice(deviceId);
4909 }
4910
4911 public int[] getInputDeviceIds() {
4912 return mInputManager.getInputDeviceIds();
4913 }
4914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 public void enableScreenAfterBoot() {
4916 synchronized(mWindowMap) {
4917 if (mSystemBooted) {
4918 return;
4919 }
4920 mSystemBooted = true;
4921 }
Romain Guy06882f82009-06-10 13:36:04 -07004922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004923 performEnableScreen();
4924 }
Romain Guy06882f82009-06-10 13:36:04 -07004925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 public void enableScreenIfNeededLocked() {
4927 if (mDisplayEnabled) {
4928 return;
4929 }
4930 if (!mSystemBooted) {
4931 return;
4932 }
4933 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4934 }
Romain Guy06882f82009-06-10 13:36:04 -07004935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 public void performEnableScreen() {
4937 synchronized(mWindowMap) {
4938 if (mDisplayEnabled) {
4939 return;
4940 }
4941 if (!mSystemBooted) {
4942 return;
4943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 // Don't enable the screen until all existing windows
4946 // have been drawn.
4947 final int N = mWindows.size();
4948 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004949 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004950 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 return;
4952 }
4953 }
Romain Guy06882f82009-06-10 13:36:04 -07004954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 mDisplayEnabled = true;
4956 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004957 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004958 StringWriter sw = new StringWriter();
4959 PrintWriter pw = new PrintWriter(sw);
4960 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004961 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 }
4963 try {
4964 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4965 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004966 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004967 Parcel data = Parcel.obtain();
4968 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4969 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4970 data, null, 0);
4971 data.recycle();
4972 }
4973 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004974 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 }
4976 }
Romain Guy06882f82009-06-10 13:36:04 -07004977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004978 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004981 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4982 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 }
Romain Guy06882f82009-06-10 13:36:04 -07004984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004985 public void setInTouchMode(boolean mode) {
4986 synchronized(mWindowMap) {
4987 mInTouchMode = mode;
4988 }
4989 }
4990
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004991 // TODO: more accounting of which pid(s) turned it on, keep count,
4992 // only allow disables from pids which have count on, etc.
4993 public void showStrictModeViolation(boolean on) {
4994 int pid = Binder.getCallingPid();
4995 synchronized(mWindowMap) {
4996 // Ignoring requests to enable the red border from clients
4997 // which aren't on screen. (e.g. Broadcast Receivers in
4998 // the background..)
4999 if (on) {
5000 boolean isVisible = false;
5001 for (WindowState ws : mWindows) {
5002 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
5003 isVisible = true;
5004 break;
5005 }
5006 }
5007 if (!isVisible) {
5008 return;
5009 }
5010 }
5011
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005012 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005013 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005014 try {
5015 if (mStrictModeFlash == null) {
5016 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
5017 }
5018 mStrictModeFlash.setVisibility(on);
5019 } finally {
5020 Surface.closeTransaction();
5021 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005022 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005023 }
5024 }
5025
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005026 public void setStrictModeVisualIndicatorPreference(String value) {
5027 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5028 }
5029
Dianne Hackbornd2835932010-12-13 16:28:46 -08005030 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005031 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5032 "screenshotApplications()")) {
5033 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5034 }
5035
5036 Bitmap rawss;
5037
Dianne Hackbornd2835932010-12-13 16:28:46 -08005038 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005039 final Rect frame = new Rect();
5040
5041 float scale;
5042 int sw, sh, dw, dh;
5043 int rot;
5044
5045 synchronized(mWindowMap) {
5046 long ident = Binder.clearCallingIdentity();
5047
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005048 dw = mDisplay.getWidth();
5049 dh = mDisplay.getHeight();
5050
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005051 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5052 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5053 + TYPE_LAYER_OFFSET;
5054 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5055
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005056 boolean isImeTarget = mInputMethodTarget != null
5057 && mInputMethodTarget.mAppToken != null
5058 && mInputMethodTarget.mAppToken.appToken != null
5059 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
5060
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005061 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005062 boolean including = false;
5063 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005064 WindowState ws = mWindows.get(i);
5065 if (ws.mSurface == null) {
5066 continue;
5067 }
5068 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08005069 continue;
5070 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005071 // When we will skip windows: when we are not including
5072 // ones behind a window we didn't skip, and we are actually
5073 // taking a screenshot of a specific app.
5074 if (!including && appToken != null) {
5075 // Also, we can possibly skip this window if it is not
5076 // an IME target or the application for the screenshot
5077 // is not the current IME target.
5078 if (!ws.mIsImWindow || !isImeTarget) {
5079 // And finally, this window is of no interest if it
5080 // is not associated with the screenshot app.
5081 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
5082 continue;
5083 }
5084 }
5085 }
5086
5087 // We keep on including windows until we go past a full-screen
5088 // window.
5089 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
5090
Dianne Hackbornd2835932010-12-13 16:28:46 -08005091 if (maxLayer < ws.mAnimLayer) {
5092 maxLayer = ws.mAnimLayer;
5093 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005094 final Rect wf = ws.mFrame;
5095 final Rect cr = ws.mContentInsets;
5096 int left = wf.left + cr.left;
5097 int top = wf.top + cr.top;
5098 int right = wf.right - cr.right;
5099 int bottom = wf.bottom - cr.bottom;
5100 frame.union(left, top, right, bottom);
5101 }
5102 Binder.restoreCallingIdentity(ident);
5103
Dianne Hackborndd962ee2011-02-02 11:11:50 -08005104 // Constrain frame to the screen size.
5105 frame.intersect(0, 0, dw, dh);
5106
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005107 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005108 return null;
5109 }
5110
5111 // The screenshot API does not apply the current screen rotation.
5112 rot = mDisplay.getRotation();
5113 int fw = frame.width();
5114 int fh = frame.height();
5115
5116 // First try reducing to fit in x dimension.
5117 scale = maxWidth/(float)fw;
5118 sw = maxWidth;
5119 sh = (int)(fh*scale);
5120 if (sh > maxHeight) {
5121 // y dimension became too long; constrain by that.
5122 scale = maxHeight/(float)fh;
5123 sw = (int)(fw*scale);
5124 sh = maxHeight;
5125 }
5126
5127 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005128 dw = (int)(dw*scale);
5129 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005130 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5131 int tmp = dw;
5132 dw = dh;
5133 dh = tmp;
5134 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5135 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005136 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005137 }
5138
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005139 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005140 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5141 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005142 return null;
5143 }
5144
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005145 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5146 Matrix matrix = new Matrix();
5147 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5148 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5149 Canvas canvas = new Canvas(bm);
5150 canvas.drawBitmap(rawss, matrix, null);
5151
5152 rawss.recycle();
5153 return bm;
5154 }
5155
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005156 public void freezeRotation() {
5157 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5158 "setRotation()")) {
5159 throw new SecurityException("Requires SET_ORIENTATION permission");
5160 }
5161
5162 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5163 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5164 }
5165
5166 public void thawRotation() {
5167 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5168 "setRotation()")) {
5169 throw new SecurityException("Requires SET_ORIENTATION permission");
5170 }
5171
5172 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5173 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5174 }
5175
Romain Guy06882f82009-06-10 13:36:04 -07005176 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005177 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005179 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005180 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005181 }
5182
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005183 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 }
Romain Guy06882f82009-06-10 13:36:04 -07005185
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005186 public void setRotationUnchecked(int rotation,
5187 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005188 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005191 long origId = Binder.clearCallingIdentity();
5192 boolean changed;
5193 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005194 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005195 }
Romain Guy06882f82009-06-10 13:36:04 -07005196
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005197 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 sendNewConfiguration();
5199 }
Romain Guy06882f82009-06-10 13:36:04 -07005200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 Binder.restoreCallingIdentity(origId);
5202 }
Romain Guy06882f82009-06-10 13:36:04 -07005203
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005204 /**
5205 * Apply a new rotation to the screen, respecting the requests of
5206 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5207 * re-evaluate the desired rotation.
5208 *
5209 * Returns null if the rotation has been changed. In this case YOU
5210 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5211 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005212 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005213 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005214 // Potential rotation during a drag. Don't do the rotation now, but make
5215 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005216 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5217 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5218 mDeferredRotation = rotation;
5219 mDeferredRotationAnimFlags = animFlags;
5220 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005221 return false;
5222 }
5223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 boolean changed;
5225 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005226 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5227 rotation = mDeferredRotation;
5228 mRequestedRotation = rotation;
5229 mLastRotationFlags = mDeferredRotationAnimFlags;
5230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 rotation = mRequestedRotation;
5232 } else {
5233 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005234 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005235 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005236 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005237 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005238 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005239 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005240 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005243 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005244 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 "Rotation changed to " + rotation
5246 + " from " + mRotation
5247 + " (forceApp=" + mForcedAppOrientation
5248 + ", req=" + mRequestedRotation + ")");
5249 mRotation = rotation;
5250 mWindowsFreezingScreen = true;
5251 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5252 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5253 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005254 mWaitingForConfig = true;
5255 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005256 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005257 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005258 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005259 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005260 if (CUSTOM_SCREEN_ROTATION) {
5261 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005262 if (!inTransaction) {
5263 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5264 ">>> OPEN TRANSACTION setRotationUnchecked");
5265 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005266 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005267 try {
5268 if (mScreenRotationAnimation != null) {
5269 mScreenRotationAnimation.setRotation(rotation);
5270 }
5271 } finally {
5272 if (!inTransaction) {
5273 Surface.closeTransaction();
5274 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5275 "<<< CLOSE TRANSACTION setRotationUnchecked");
5276 }
5277 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005278 Surface.setOrientation(0, rotation, animFlags);
5279 Surface.unfreezeDisplay(0);
5280 } else {
5281 Surface.setOrientation(0, rotation, animFlags);
5282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005283 }
5284 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005285 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005286 if (w.mSurface != null) {
5287 w.mOrientationChanging = true;
5288 }
5289 }
5290 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5291 try {
5292 mRotationWatchers.get(i).onRotationChanged(rotation);
5293 } catch (RemoteException e) {
5294 }
5295 }
5296 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005298 return changed;
5299 }
Romain Guy06882f82009-06-10 13:36:04 -07005300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005301 public int getRotation() {
5302 return mRotation;
5303 }
5304
5305 public int watchRotation(IRotationWatcher watcher) {
5306 final IBinder watcherBinder = watcher.asBinder();
5307 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5308 public void binderDied() {
5309 synchronized (mWindowMap) {
5310 for (int i=0; i<mRotationWatchers.size(); i++) {
5311 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005312 IRotationWatcher removed = mRotationWatchers.remove(i);
5313 if (removed != null) {
5314 removed.asBinder().unlinkToDeath(this, 0);
5315 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005316 i--;
5317 }
5318 }
5319 }
5320 }
5321 };
Romain Guy06882f82009-06-10 13:36:04 -07005322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 synchronized (mWindowMap) {
5324 try {
5325 watcher.asBinder().linkToDeath(dr, 0);
5326 mRotationWatchers.add(watcher);
5327 } catch (RemoteException e) {
5328 // Client died, no cleanup needed.
5329 }
Romain Guy06882f82009-06-10 13:36:04 -07005330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005331 return mRotation;
5332 }
5333 }
5334
5335 /**
5336 * Starts the view server on the specified port.
5337 *
5338 * @param port The port to listener to.
5339 *
5340 * @return True if the server was successfully started, false otherwise.
5341 *
5342 * @see com.android.server.ViewServer
5343 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5344 */
5345 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005346 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 return false;
5348 }
5349
5350 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5351 return false;
5352 }
5353
5354 if (port < 1024) {
5355 return false;
5356 }
5357
5358 if (mViewServer != null) {
5359 if (!mViewServer.isRunning()) {
5360 try {
5361 return mViewServer.start();
5362 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005363 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005364 }
5365 }
5366 return false;
5367 }
5368
5369 try {
5370 mViewServer = new ViewServer(this, port);
5371 return mViewServer.start();
5372 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005373 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374 }
5375 return false;
5376 }
5377
Romain Guy06882f82009-06-10 13:36:04 -07005378 private boolean isSystemSecure() {
5379 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5380 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5381 }
5382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005383 /**
5384 * Stops the view server if it exists.
5385 *
5386 * @return True if the server stopped, false if it wasn't started or
5387 * couldn't be stopped.
5388 *
5389 * @see com.android.server.ViewServer
5390 */
5391 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005392 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 return false;
5394 }
5395
5396 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5397 return false;
5398 }
5399
5400 if (mViewServer != null) {
5401 return mViewServer.stop();
5402 }
5403 return false;
5404 }
5405
5406 /**
5407 * Indicates whether the view server is running.
5408 *
5409 * @return True if the server is running, false otherwise.
5410 *
5411 * @see com.android.server.ViewServer
5412 */
5413 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005414 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005415 return false;
5416 }
5417
5418 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5419 return false;
5420 }
5421
5422 return mViewServer != null && mViewServer.isRunning();
5423 }
5424
5425 /**
5426 * Lists all availble windows in the system. The listing is written in the
5427 * specified Socket's output stream with the following syntax:
5428 * windowHashCodeInHexadecimal windowName
5429 * Each line of the ouput represents a different window.
5430 *
5431 * @param client The remote client to send the listing to.
5432 * @return False if an error occured, true otherwise.
5433 */
5434 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005435 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 return false;
5437 }
5438
5439 boolean result = true;
5440
Jeff Browne33348b2010-07-15 23:54:05 -07005441 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005443 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005444 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445 }
5446
5447 BufferedWriter out = null;
5448
5449 // Any uncaught exception will crash the system process
5450 try {
5451 OutputStream clientStream = client.getOutputStream();
5452 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5453
5454 final int count = windows.length;
5455 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005456 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 out.write(Integer.toHexString(System.identityHashCode(w)));
5458 out.write(' ');
5459 out.append(w.mAttrs.getTitle());
5460 out.write('\n');
5461 }
5462
5463 out.write("DONE.\n");
5464 out.flush();
5465 } catch (Exception e) {
5466 result = false;
5467 } finally {
5468 if (out != null) {
5469 try {
5470 out.close();
5471 } catch (IOException e) {
5472 result = false;
5473 }
5474 }
5475 }
5476
5477 return result;
5478 }
5479
5480 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005481 * Returns the focused window in the following format:
5482 * windowHashCodeInHexadecimal windowName
5483 *
5484 * @param client The remote client to send the listing to.
5485 * @return False if an error occurred, true otherwise.
5486 */
5487 boolean viewServerGetFocusedWindow(Socket client) {
5488 if (isSystemSecure()) {
5489 return false;
5490 }
5491
5492 boolean result = true;
5493
5494 WindowState focusedWindow = getFocusedWindow();
5495
5496 BufferedWriter out = null;
5497
5498 // Any uncaught exception will crash the system process
5499 try {
5500 OutputStream clientStream = client.getOutputStream();
5501 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5502
5503 if(focusedWindow != null) {
5504 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5505 out.write(' ');
5506 out.append(focusedWindow.mAttrs.getTitle());
5507 }
5508 out.write('\n');
5509 out.flush();
5510 } catch (Exception e) {
5511 result = false;
5512 } finally {
5513 if (out != null) {
5514 try {
5515 out.close();
5516 } catch (IOException e) {
5517 result = false;
5518 }
5519 }
5520 }
5521
5522 return result;
5523 }
5524
5525 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005526 * Sends a command to a target window. The result of the command, if any, will be
5527 * written in the output stream of the specified socket.
5528 *
5529 * The parameters must follow this syntax:
5530 * windowHashcode extra
5531 *
5532 * Where XX is the length in characeters of the windowTitle.
5533 *
5534 * The first parameter is the target window. The window with the specified hashcode
5535 * will be the target. If no target can be found, nothing happens. The extra parameters
5536 * will be delivered to the target window and as parameters to the command itself.
5537 *
5538 * @param client The remote client to sent the result, if any, to.
5539 * @param command The command to execute.
5540 * @param parameters The command parameters.
5541 *
5542 * @return True if the command was successfully delivered, false otherwise. This does
5543 * not indicate whether the command itself was successful.
5544 */
5545 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005546 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547 return false;
5548 }
5549
5550 boolean success = true;
5551 Parcel data = null;
5552 Parcel reply = null;
5553
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005554 BufferedWriter out = null;
5555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005556 // Any uncaught exception will crash the system process
5557 try {
5558 // Find the hashcode of the window
5559 int index = parameters.indexOf(' ');
5560 if (index == -1) {
5561 index = parameters.length();
5562 }
5563 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005564 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005565
5566 // Extract the command's parameter after the window description
5567 if (index < parameters.length()) {
5568 parameters = parameters.substring(index + 1);
5569 } else {
5570 parameters = "";
5571 }
5572
5573 final WindowManagerService.WindowState window = findWindow(hashCode);
5574 if (window == null) {
5575 return false;
5576 }
5577
5578 data = Parcel.obtain();
5579 data.writeInterfaceToken("android.view.IWindow");
5580 data.writeString(command);
5581 data.writeString(parameters);
5582 data.writeInt(1);
5583 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5584
5585 reply = Parcel.obtain();
5586
5587 final IBinder binder = window.mClient.asBinder();
5588 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5589 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5590
5591 reply.readException();
5592
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005593 if (!client.isOutputShutdown()) {
5594 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5595 out.write("DONE\n");
5596 out.flush();
5597 }
5598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005599 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005600 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005601 success = false;
5602 } finally {
5603 if (data != null) {
5604 data.recycle();
5605 }
5606 if (reply != null) {
5607 reply.recycle();
5608 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005609 if (out != null) {
5610 try {
5611 out.close();
5612 } catch (IOException e) {
5613
5614 }
5615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 }
5617
5618 return success;
5619 }
5620
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005621 public void addWindowChangeListener(WindowChangeListener listener) {
5622 synchronized(mWindowMap) {
5623 mWindowChangeListeners.add(listener);
5624 }
5625 }
5626
5627 public void removeWindowChangeListener(WindowChangeListener listener) {
5628 synchronized(mWindowMap) {
5629 mWindowChangeListeners.remove(listener);
5630 }
5631 }
5632
5633 private void notifyWindowsChanged() {
5634 WindowChangeListener[] windowChangeListeners;
5635 synchronized(mWindowMap) {
5636 if(mWindowChangeListeners.isEmpty()) {
5637 return;
5638 }
5639 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5640 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5641 }
5642 int N = windowChangeListeners.length;
5643 for(int i = 0; i < N; i++) {
5644 windowChangeListeners[i].windowsChanged();
5645 }
5646 }
5647
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005648 private void notifyFocusChanged() {
5649 WindowChangeListener[] windowChangeListeners;
5650 synchronized(mWindowMap) {
5651 if(mWindowChangeListeners.isEmpty()) {
5652 return;
5653 }
5654 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5655 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5656 }
5657 int N = windowChangeListeners.length;
5658 for(int i = 0; i < N; i++) {
5659 windowChangeListeners[i].focusChanged();
5660 }
5661 }
5662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005663 private WindowState findWindow(int hashCode) {
5664 if (hashCode == -1) {
5665 return getFocusedWindow();
5666 }
5667
5668 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005669 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005670 final int count = windows.size();
5671
5672 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005673 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005674 if (System.identityHashCode(w) == hashCode) {
5675 return w;
5676 }
5677 }
5678 }
5679
5680 return null;
5681 }
5682
5683 /*
5684 * Instruct the Activity Manager to fetch the current configuration and broadcast
5685 * that to config-changed listeners if appropriate.
5686 */
5687 void sendNewConfiguration() {
5688 try {
5689 mActivityManager.updateConfiguration(null);
5690 } catch (RemoteException e) {
5691 }
5692 }
Romain Guy06882f82009-06-10 13:36:04 -07005693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005694 public Configuration computeNewConfiguration() {
5695 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005696 Configuration config = computeNewConfigurationLocked();
5697 if (config == null && mWaitingForConfig) {
5698 // Nothing changed but we are waiting for something... stop that!
5699 mWaitingForConfig = false;
5700 performLayoutAndPlaceSurfacesLocked();
5701 }
5702 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005703 }
5704 }
Romain Guy06882f82009-06-10 13:36:04 -07005705
Dianne Hackbornc485a602009-03-24 22:39:49 -07005706 Configuration computeNewConfigurationLocked() {
5707 Configuration config = new Configuration();
5708 if (!computeNewConfigurationLocked(config)) {
5709 return null;
5710 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005711 return config;
5712 }
Romain Guy06882f82009-06-10 13:36:04 -07005713
Dianne Hackbornc485a602009-03-24 22:39:49 -07005714 boolean computeNewConfigurationLocked(Configuration config) {
5715 if (mDisplay == null) {
5716 return false;
5717 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005718
5719 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005720
5721 // Use the effective "visual" dimensions based on current rotation
5722 final boolean rotated = (mRotation == Surface.ROTATION_90
5723 || mRotation == Surface.ROTATION_270);
5724 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5725 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5726
Dianne Hackbornc485a602009-03-24 22:39:49 -07005727 int orientation = Configuration.ORIENTATION_SQUARE;
5728 if (dw < dh) {
5729 orientation = Configuration.ORIENTATION_PORTRAIT;
5730 } else if (dw > dh) {
5731 orientation = Configuration.ORIENTATION_LANDSCAPE;
5732 }
5733 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005734
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005735 DisplayMetrics dm = new DisplayMetrics();
5736 mDisplay.getMetrics(dm);
5737 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5738
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005739 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005740 // Note we only do this once because at this point we don't
5741 // expect the screen to change in this way at runtime, and want
5742 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005743 int longSize = dw;
5744 int shortSize = dh;
5745 if (longSize < shortSize) {
5746 int tmp = longSize;
5747 longSize = shortSize;
5748 shortSize = tmp;
5749 }
5750 longSize = (int)(longSize/dm.density);
5751 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005752
Dianne Hackborn723738c2009-06-25 19:48:04 -07005753 // These semi-magic numbers define our compatibility modes for
5754 // applications with different screens. Don't change unless you
5755 // make sure to test lots and lots of apps!
5756 if (longSize < 470) {
5757 // This is shorter than an HVGA normal density screen (which
5758 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005759 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5760 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005761 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005762 // What size is this screen screen?
5763 if (longSize >= 800 && shortSize >= 600) {
5764 // SVGA or larger screens at medium density are the point
5765 // at which we consider it to be an extra large screen.
5766 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005767 } else if (longSize >= 530 && shortSize >= 400) {
5768 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005769 // at which we consider it to be a large screen.
5770 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5771 } else {
5772 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborne97a12e2011-01-29 13:22:02 -08005773 }
5774
5775 // If this screen is wider than normal HVGA, or taller
5776 // than FWVGA, then for old apps we want to run in size
5777 // compatibility mode.
5778 if (shortSize > 321 || longSize > 570) {
5779 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005780 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005781
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005782 // Is this a long screen?
5783 if (((longSize*3)/5) >= (shortSize-1)) {
5784 // Anything wider than WVGA (5:3) is considering to be long.
5785 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5786 } else {
5787 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5788 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005789 }
5790 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005791 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005792
Jeff Brown597eec82011-01-31 17:12:25 -08005793 // Determine whether a hard keyboard is available and enabled.
Jeff Brown2992ea72011-01-28 22:04:14 -08005794 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5795 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5796 mHardKeyboardAvailable = hardKeyboardAvailable;
5797 mHardKeyboardEnabled = hardKeyboardAvailable;
5798
5799 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5800 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5801 }
5802 if (!mHardKeyboardEnabled) {
5803 config.keyboard = Configuration.KEYBOARD_NOKEYS;
Jeff Brown2992ea72011-01-28 22:04:14 -08005804 }
Jeff Brown597eec82011-01-31 17:12:25 -08005805
5806 // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
5807 // based on whether a hard or soft keyboard is present, whether navigation keys
5808 // are present and the lid switch state.
5809 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5810 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5811 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
5812 mPolicy.adjustConfigurationLw(config);
Dianne Hackbornc485a602009-03-24 22:39:49 -07005813 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005814 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005815
Jeff Brown2992ea72011-01-28 22:04:14 -08005816 public boolean isHardKeyboardAvailable() {
5817 synchronized (mWindowMap) {
5818 return mHardKeyboardAvailable;
5819 }
5820 }
5821
5822 public boolean isHardKeyboardEnabled() {
5823 synchronized (mWindowMap) {
5824 return mHardKeyboardEnabled;
5825 }
5826 }
5827
5828 public void setHardKeyboardEnabled(boolean enabled) {
5829 synchronized (mWindowMap) {
5830 if (mHardKeyboardEnabled != enabled) {
5831 mHardKeyboardEnabled = enabled;
5832 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5833 }
5834 }
5835 }
5836
5837 public void setOnHardKeyboardStatusChangeListener(
5838 OnHardKeyboardStatusChangeListener listener) {
5839 synchronized (mWindowMap) {
5840 mHardKeyboardStatusChangeListener = listener;
5841 }
5842 }
5843
5844 void notifyHardKeyboardStatusChange() {
5845 final boolean available, enabled;
5846 final OnHardKeyboardStatusChangeListener listener;
5847 synchronized (mWindowMap) {
5848 listener = mHardKeyboardStatusChangeListener;
5849 available = mHardKeyboardAvailable;
5850 enabled = mHardKeyboardEnabled;
5851 }
5852 if (listener != null) {
5853 listener.onHardKeyboardStatusChange(available, enabled);
5854 }
5855 }
5856
Christopher Tatea53146c2010-09-07 11:57:52 -07005857 // -------------------------------------------------------------
5858 // Drag and drop
5859 // -------------------------------------------------------------
5860
5861 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005862 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005863 if (DEBUG_DRAG) {
5864 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005865 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005866 + " asbinder=" + window.asBinder());
5867 }
5868
5869 final int callerPid = Binder.getCallingPid();
5870 final long origId = Binder.clearCallingIdentity();
5871 IBinder token = null;
5872
5873 try {
5874 synchronized (mWindowMap) {
5875 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005876 if (mDragState == null) {
5877 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5878 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5879 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005880 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005881 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005882 // TODO: preserve flags param in DragState
5883 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005884 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005885 token = mDragState.mToken = new Binder();
5886
5887 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005888 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5889 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005890 mH.sendMessageDelayed(msg, 5000);
5891 } else {
5892 Slog.w(TAG, "Drag already in progress");
5893 }
5894 } catch (Surface.OutOfResourcesException e) {
5895 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5896 if (mDragState != null) {
5897 mDragState.reset();
5898 mDragState = null;
5899 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005900 }
5901 }
5902 } finally {
5903 Binder.restoreCallingIdentity(origId);
5904 }
5905
5906 return token;
5907 }
5908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005909 // -------------------------------------------------------------
5910 // Input Events and Focus Management
5911 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005912
Jeff Brown349703e2010-06-22 01:27:15 -07005913 InputMonitor mInputMonitor = new InputMonitor();
5914
5915 /* Tracks the progress of input dispatch and ensures that input dispatch state
5916 * is kept in sync with changes in window focus, visibility, registration, and
5917 * other relevant Window Manager state transitions. */
5918 final class InputMonitor {
5919 // Current window with input focus for keys and other non-touch events. May be null.
5920 private WindowState mInputFocus;
5921
5922 // When true, prevents input dispatch from proceeding until set to false again.
5923 private boolean mInputDispatchFrozen;
5924
5925 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5926 private boolean mInputDispatchEnabled = true;
5927
Jeff Brown3a22cd92011-01-21 13:59:04 -08005928 // When true, need to call updateInputWindowsLw().
5929 private boolean mUpdateInputWindowsNeeded = true;
5930
Jeff Brown349703e2010-06-22 01:27:15 -07005931 // Temporary list of windows information to provide to the input dispatcher.
5932 private InputWindowList mTempInputWindows = new InputWindowList();
5933
5934 // Temporary input application object to provide to the input dispatcher.
5935 private InputApplication mTempInputApplication = new InputApplication();
5936
Jeff Brownb09abc12011-01-13 21:08:27 -08005937 // Set to true when the first input device configuration change notification
5938 // is received to indicate that the input devices are ready.
5939 private final Object mInputDevicesReadyMonitor = new Object();
5940 private boolean mInputDevicesReady;
5941
Jeff Brown349703e2010-06-22 01:27:15 -07005942 /* Notifies the window manager about a broken input channel.
5943 *
5944 * Called by the InputManager.
5945 */
Jeff Brown928e0542011-01-10 11:17:36 -08005946 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5947 if (inputWindowHandle == null) {
5948 return;
5949 }
5950
Jeff Brown349703e2010-06-22 01:27:15 -07005951 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005952 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005953 Slog.i(TAG, "WINDOW DIED " + windowState);
5954 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005955 }
5956 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005957
Jeff Brown519e0242010-09-15 15:18:56 -07005958 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005959 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005960 *
5961 * Called by the InputManager.
5962 */
Jeff Brown928e0542011-01-10 11:17:36 -08005963 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5964 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005965 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005966 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005967 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005968 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005969 if (windowState != null) {
5970 Slog.i(TAG, "Input event dispatching timed out sending to "
5971 + windowState.mAttrs.getTitle());
5972 appWindowToken = windowState.mAppToken;
5973 }
Jeff Brown349703e2010-06-22 01:27:15 -07005974 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005975 }
5976
Jeff Brown928e0542011-01-10 11:17:36 -08005977 if (appWindowToken == null && inputApplicationHandle != null) {
5978 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005979 Slog.i(TAG, "Input event dispatching timed out sending to application "
5980 + appWindowToken.stringName);
5981 }
Jeff Brown349703e2010-06-22 01:27:15 -07005982
Jeff Brown519e0242010-09-15 15:18:56 -07005983 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005984 try {
5985 // Notify the activity manager about the timeout and let it decide whether
5986 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005987 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005988 if (! abort) {
5989 // The activity manager declined to abort dispatching.
5990 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005991 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005992 }
Jeff Brown349703e2010-06-22 01:27:15 -07005993 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005994 }
5995 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005996 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005997 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005998
Chris Tatea32dcf72010-10-14 12:13:50 -07005999 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07006000 final InputWindow inputWindow = windowList.add();
6001 inputWindow.inputChannel = mDragState.mServerChannel;
6002 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08006003 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07006004 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
6005 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6006 inputWindow.visible = true;
6007 inputWindow.canReceiveKeys = false;
6008 inputWindow.hasFocus = true;
6009 inputWindow.hasWallpaper = false;
6010 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07006011 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006012 inputWindow.ownerPid = Process.myPid();
6013 inputWindow.ownerUid = Process.myUid();
6014
6015 // The drag window covers the entire display
6016 inputWindow.frameLeft = 0;
6017 inputWindow.frameTop = 0;
6018 inputWindow.frameRight = mDisplay.getWidth();
6019 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07006020
Jeff Brownfbf09772011-01-16 14:06:57 -08006021 // The drag window cannot receive new touches.
6022 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07006023 }
6024
Jeff Brown3a22cd92011-01-21 13:59:04 -08006025 public void setUpdateInputWindowsNeededLw() {
6026 mUpdateInputWindowsNeeded = true;
6027 }
6028
Jeff Brown349703e2010-06-22 01:27:15 -07006029 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08006030 public void updateInputWindowsLw(boolean force) {
6031 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006032 return;
6033 }
6034 mUpdateInputWindowsNeeded = false;
6035
Jeff Brown349703e2010-06-22 01:27:15 -07006036 // Populate the input window list with information about all of the windows that
6037 // could potentially receive input.
6038 // As an optimization, we could try to prune the list of windows but this turns
6039 // out to be difficult because only the native code knows for sure which window
6040 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07006041 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07006042
6043 // If there's a drag in flight, provide a pseudowindow to catch drag input
6044 final boolean inDrag = (mDragState != null);
6045 if (inDrag) {
6046 if (DEBUG_DRAG) {
6047 Log.d(TAG, "Inserting drag window");
6048 }
Chris Tatea32dcf72010-10-14 12:13:50 -07006049 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07006050 }
6051
Jeff Brown7fbdc842010-06-17 20:52:56 -07006052 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07006053 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006054 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07006055 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07006056 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07006057 continue;
6058 }
6059
Jeff Brown349703e2010-06-22 01:27:15 -07006060 final int flags = child.mAttrs.flags;
6061 final int type = child.mAttrs.type;
6062
6063 final boolean hasFocus = (child == mInputFocus);
6064 final boolean isVisible = child.isVisibleLw();
6065 final boolean hasWallpaper = (child == mWallpaperTarget)
6066 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07006067
6068 // If there's a drag in progress and 'child' is a potential drop target,
6069 // make sure it's been told about the drag
6070 if (inDrag && isVisible) {
6071 mDragState.sendDragStartedIfNeededLw(child);
6072 }
6073
Jeff Brown349703e2010-06-22 01:27:15 -07006074 // Add a window to our list of input windows.
6075 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006076 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006077 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006078 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006079 inputWindow.layoutParamsFlags = flags;
6080 inputWindow.layoutParamsType = type;
6081 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6082 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006083 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006084 inputWindow.hasFocus = hasFocus;
6085 inputWindow.hasWallpaper = hasWallpaper;
6086 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006087 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006088 inputWindow.ownerPid = child.mSession.mPid;
6089 inputWindow.ownerUid = child.mSession.mUid;
6090
6091 final Rect frame = child.mFrame;
6092 inputWindow.frameLeft = frame.left;
6093 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006094 inputWindow.frameRight = frame.right;
6095 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006096
6097 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006098 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006099
Jeff Brown349703e2010-06-22 01:27:15 -07006100 // Send windows to native code.
6101 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006102
Jeff Brown349703e2010-06-22 01:27:15 -07006103 // Clear the list in preparation for the next round.
6104 // Also avoids keeping InputChannel objects referenced unnecessarily.
6105 mTempInputWindows.clear();
6106 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006107
6108 /* Notifies that the input device configuration has changed. */
6109 public void notifyConfigurationChanged() {
6110 sendNewConfiguration();
6111
6112 synchronized (mInputDevicesReadyMonitor) {
6113 if (!mInputDevicesReady) {
6114 mInputDevicesReady = true;
6115 mInputDevicesReadyMonitor.notifyAll();
6116 }
6117 }
6118 }
6119
6120 /* Waits until the built-in input devices have been configured. */
6121 public boolean waitForInputDevicesReady(long timeoutMillis) {
6122 synchronized (mInputDevicesReadyMonitor) {
6123 if (!mInputDevicesReady) {
6124 try {
6125 mInputDevicesReadyMonitor.wait(timeoutMillis);
6126 } catch (InterruptedException ex) {
6127 }
6128 }
6129 return mInputDevicesReady;
6130 }
6131 }
6132
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006133 /* Notifies that the lid switch changed state. */
6134 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6135 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6136 }
6137
Jeff Brown349703e2010-06-22 01:27:15 -07006138 /* Provides an opportunity for the window manager policy to intercept early key
6139 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006140 public int interceptKeyBeforeQueueing(
6141 KeyEvent event, int policyFlags, boolean isScreenOn) {
6142 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006143 }
6144
6145 /* Provides an opportunity for the window manager policy to process a key before
6146 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006147 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006148 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006149 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006150 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006151 }
6152
Jeff Brown3915bb82010-11-05 15:02:16 -07006153 /* Provides an opportunity for the window manager policy to process a key that
6154 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006155 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006156 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006157 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006158 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006159 }
6160
Jeff Brown349703e2010-06-22 01:27:15 -07006161 /* Called when the current input focus changes.
6162 * Layer assignment is assumed to be complete by the time this is called.
6163 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006164 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006165 if (DEBUG_INPUT) {
6166 Slog.d(TAG, "Input focus has changed to " + newWindow);
6167 }
6168
6169 if (newWindow != mInputFocus) {
6170 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006171 // Displaying a window implicitly causes dispatching to be unpaused.
6172 // This is to protect against bugs if someone pauses dispatching but
6173 // forgets to resume.
6174 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006175 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006176
Jeff Brown349703e2010-06-22 01:27:15 -07006177 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006178 setUpdateInputWindowsNeededLw();
6179
6180 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006181 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006182 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006183 }
6184 }
6185
Jeff Brown349703e2010-06-22 01:27:15 -07006186 public void setFocusedAppLw(AppWindowToken newApp) {
6187 // Focused app has changed.
6188 if (newApp == null) {
6189 mInputManager.setFocusedApplication(null);
6190 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006191 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006192 mTempInputApplication.name = newApp.toString();
6193 mTempInputApplication.dispatchingTimeoutNanos =
6194 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006195
Jeff Brown349703e2010-06-22 01:27:15 -07006196 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006197
6198 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006199 }
6200 }
6201
Jeff Brown349703e2010-06-22 01:27:15 -07006202 public void pauseDispatchingLw(WindowToken window) {
6203 if (! window.paused) {
6204 if (DEBUG_INPUT) {
6205 Slog.v(TAG, "Pausing WindowToken " + window);
6206 }
6207
6208 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006209 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006210 }
6211 }
6212
6213 public void resumeDispatchingLw(WindowToken window) {
6214 if (window.paused) {
6215 if (DEBUG_INPUT) {
6216 Slog.v(TAG, "Resuming WindowToken " + window);
6217 }
6218
6219 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006220 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006221 }
6222 }
6223
6224 public void freezeInputDispatchingLw() {
6225 if (! mInputDispatchFrozen) {
6226 if (DEBUG_INPUT) {
6227 Slog.v(TAG, "Freezing input dispatching");
6228 }
6229
6230 mInputDispatchFrozen = true;
6231 updateInputDispatchModeLw();
6232 }
6233 }
6234
6235 public void thawInputDispatchingLw() {
6236 if (mInputDispatchFrozen) {
6237 if (DEBUG_INPUT) {
6238 Slog.v(TAG, "Thawing input dispatching");
6239 }
6240
6241 mInputDispatchFrozen = false;
6242 updateInputDispatchModeLw();
6243 }
6244 }
6245
6246 public void setEventDispatchingLw(boolean enabled) {
6247 if (mInputDispatchEnabled != enabled) {
6248 if (DEBUG_INPUT) {
6249 Slog.v(TAG, "Setting event dispatching to " + enabled);
6250 }
6251
6252 mInputDispatchEnabled = enabled;
6253 updateInputDispatchModeLw();
6254 }
6255 }
6256
6257 private void updateInputDispatchModeLw() {
6258 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6259 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006262 public void pauseKeyDispatching(IBinder _token) {
6263 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6264 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006265 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 }
6267
6268 synchronized (mWindowMap) {
6269 WindowToken token = mTokenMap.get(_token);
6270 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006271 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006272 }
6273 }
6274 }
6275
6276 public void resumeKeyDispatching(IBinder _token) {
6277 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6278 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006279 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006280 }
6281
6282 synchronized (mWindowMap) {
6283 WindowToken token = mTokenMap.get(_token);
6284 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006285 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006286 }
6287 }
6288 }
6289
6290 public void setEventDispatching(boolean enabled) {
6291 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6292 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006293 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 }
6295
6296 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006297 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006298 }
6299 }
Romain Guy06882f82009-06-10 13:36:04 -07006300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006301 /**
6302 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006303 * Even when sync is false, this method may block while waiting for current
6304 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006305 *
6306 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 * {@link SystemClock#uptimeMillis()} as the timebase.)
6308 * @param sync If true, wait for the event to be completed before returning to the caller.
6309 * @return Returns true if event was dispatched, false if it was dropped for any reason
6310 */
6311 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6312 long downTime = ev.getDownTime();
6313 long eventTime = ev.getEventTime();
6314
6315 int action = ev.getAction();
6316 int code = ev.getKeyCode();
6317 int repeatCount = ev.getRepeatCount();
6318 int metaState = ev.getMetaState();
6319 int deviceId = ev.getDeviceId();
6320 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006321 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006322 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006323
6324 if (source == InputDevice.SOURCE_UNKNOWN) {
6325 source = InputDevice.SOURCE_KEYBOARD;
6326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327
6328 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6329 if (downTime == 0) downTime = eventTime;
6330
6331 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006332 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006333
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006334 final int pid = Binder.getCallingPid();
6335 final int uid = Binder.getCallingUid();
6336 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006337
Jeff Brownbbda99d2010-07-28 15:48:59 -07006338 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6339 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6340 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6341 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006342
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006343 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006344 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006345 }
6346
6347 /**
6348 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006349 * Even when sync is false, this method may block while waiting for current
6350 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006351 *
6352 * @param ev A motion event describing the pointer (touch) action. (As noted in
6353 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 * {@link SystemClock#uptimeMillis()} as the timebase.)
6355 * @param sync If true, wait for the event to be completed before returning to the caller.
6356 * @return Returns true if event was dispatched, false if it was dropped for any reason
6357 */
6358 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006359 final int pid = Binder.getCallingPid();
6360 final int uid = Binder.getCallingUid();
6361 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006362
Jeff Brownc5ed5912010-07-14 18:48:53 -07006363 MotionEvent newEvent = MotionEvent.obtain(ev);
6364 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6365 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6366 }
6367
Jeff Brownbbda99d2010-07-28 15:48:59 -07006368 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6369 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6370 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6371 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006372
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006373 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006374 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 }
Romain Guy06882f82009-06-10 13:36:04 -07006376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 /**
6378 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006379 * Even when sync is false, this method may block while waiting for current
6380 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006381 *
6382 * @param ev A motion event describing the trackball action. (As noted in
6383 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006384 * {@link SystemClock#uptimeMillis()} as the timebase.)
6385 * @param sync If true, wait for the event to be completed before returning to the caller.
6386 * @return Returns true if event was dispatched, false if it was dropped for any reason
6387 */
6388 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006389 final int pid = Binder.getCallingPid();
6390 final int uid = Binder.getCallingUid();
6391 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006392
Jeff Brownc5ed5912010-07-14 18:48:53 -07006393 MotionEvent newEvent = MotionEvent.obtain(ev);
6394 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6395 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6396 }
6397
Jeff Brownbbda99d2010-07-28 15:48:59 -07006398 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6399 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6400 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6401 INJECTION_TIMEOUT_MILLIS);
6402
6403 Binder.restoreCallingIdentity(ident);
6404 return reportInjectionResult(result);
6405 }
6406
6407 /**
6408 * Inject an input event into the UI without waiting for dispatch to commence.
6409 * This variant is useful for fire-and-forget input event injection. It does not
6410 * block any longer than it takes to enqueue the input event.
6411 *
6412 * @param ev An input event. (Be sure to set the input source correctly.)
6413 * @return Returns true if event was dispatched, false if it was dropped for any reason
6414 */
6415 public boolean injectInputEventNoWait(InputEvent ev) {
6416 final int pid = Binder.getCallingPid();
6417 final int uid = Binder.getCallingUid();
6418 final long ident = Binder.clearCallingIdentity();
6419
6420 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6421 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6422 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006423
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006424 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006425 return reportInjectionResult(result);
6426 }
6427
6428 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006429 switch (result) {
6430 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6431 Slog.w(TAG, "Input event injection permission denied.");
6432 throw new SecurityException(
6433 "Injecting to another application requires INJECT_EVENTS permission");
6434 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006435 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006436 return true;
6437 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6438 Slog.w(TAG, "Input event injection timed out.");
6439 return false;
6440 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6441 default:
6442 Slog.w(TAG, "Input event injection failed.");
6443 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006445 }
Romain Guy06882f82009-06-10 13:36:04 -07006446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447 private WindowState getFocusedWindow() {
6448 synchronized (mWindowMap) {
6449 return getFocusedWindowLocked();
6450 }
6451 }
6452
6453 private WindowState getFocusedWindowLocked() {
6454 return mCurrentFocus;
6455 }
Romain Guy06882f82009-06-10 13:36:04 -07006456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006457 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006458 if (!mInputMonitor.waitForInputDevicesReady(
6459 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6460 Slog.w(TAG, "Devices still not ready after waiting "
6461 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6462 + " milliseconds before attempting to detect safe mode.");
6463 }
6464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 mSafeMode = mPolicy.detectSafeMode();
6466 return mSafeMode;
6467 }
Romain Guy06882f82009-06-10 13:36:04 -07006468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006470 synchronized(mWindowMap) {
6471 if (mDisplay != null) {
6472 throw new IllegalStateException("Display already initialized");
6473 }
6474 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6475 mDisplay = wm.getDefaultDisplay();
6476 mInitialDisplayWidth = mDisplay.getWidth();
6477 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006478 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6479 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006480 }
6481
6482 try {
6483 mActivityManager.updateConfiguration(null);
6484 } catch (RemoteException e) {
6485 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006486
6487 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006488 }
6489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006490 // -------------------------------------------------------------
6491 // Client Session State
6492 // -------------------------------------------------------------
6493
6494 private final class Session extends IWindowSession.Stub
6495 implements IBinder.DeathRecipient {
6496 final IInputMethodClient mClient;
6497 final IInputContext mInputContext;
6498 final int mUid;
6499 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006500 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006501 SurfaceSession mSurfaceSession;
6502 int mNumWindow = 0;
6503 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 public Session(IInputMethodClient client, IInputContext inputContext) {
6506 mClient = client;
6507 mInputContext = inputContext;
6508 mUid = Binder.getCallingUid();
6509 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006510 StringBuilder sb = new StringBuilder();
6511 sb.append("Session{");
6512 sb.append(Integer.toHexString(System.identityHashCode(this)));
6513 sb.append(" uid ");
6514 sb.append(mUid);
6515 sb.append("}");
6516 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006518 synchronized (mWindowMap) {
6519 if (mInputMethodManager == null && mHaveInputMethods) {
6520 IBinder b = ServiceManager.getService(
6521 Context.INPUT_METHOD_SERVICE);
6522 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6523 }
6524 }
6525 long ident = Binder.clearCallingIdentity();
6526 try {
6527 // Note: it is safe to call in to the input method manager
6528 // here because we are not holding our lock.
6529 if (mInputMethodManager != null) {
6530 mInputMethodManager.addClient(client, inputContext,
6531 mUid, mPid);
6532 } else {
6533 client.setUsingInputMethod(false);
6534 }
6535 client.asBinder().linkToDeath(this, 0);
6536 } catch (RemoteException e) {
6537 // The caller has died, so we can just forget about this.
6538 try {
6539 if (mInputMethodManager != null) {
6540 mInputMethodManager.removeClient(client);
6541 }
6542 } catch (RemoteException ee) {
6543 }
6544 } finally {
6545 Binder.restoreCallingIdentity(ident);
6546 }
6547 }
Romain Guy06882f82009-06-10 13:36:04 -07006548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006549 @Override
6550 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6551 throws RemoteException {
6552 try {
6553 return super.onTransact(code, data, reply, flags);
6554 } catch (RuntimeException e) {
6555 // Log all 'real' exceptions thrown to the caller
6556 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006557 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 }
6559 throw e;
6560 }
6561 }
6562
6563 public void binderDied() {
6564 // Note: it is safe to call in to the input method manager
6565 // here because we are not holding our lock.
6566 try {
6567 if (mInputMethodManager != null) {
6568 mInputMethodManager.removeClient(mClient);
6569 }
6570 } catch (RemoteException e) {
6571 }
6572 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006573 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 mClientDead = true;
6575 killSessionLocked();
6576 }
6577 }
6578
6579 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006580 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6581 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6582 outInputChannel);
6583 }
6584
6585 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006586 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006587 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 }
Romain Guy06882f82009-06-10 13:36:04 -07006589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 public void remove(IWindow window) {
6591 removeWindow(this, window);
6592 }
Romain Guy06882f82009-06-10 13:36:04 -07006593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6595 int requestedWidth, int requestedHeight, int viewFlags,
6596 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006597 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006598 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6599 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006601 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006602 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6603 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006604 }
Romain Guy06882f82009-06-10 13:36:04 -07006605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 public void setTransparentRegion(IWindow window, Region region) {
6607 setTransparentRegionWindow(this, window, region);
6608 }
Romain Guy06882f82009-06-10 13:36:04 -07006609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006610 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006611 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006612 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006613 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006614 }
Romain Guy06882f82009-06-10 13:36:04 -07006615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006616 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6617 getWindowDisplayFrame(this, window, outDisplayFrame);
6618 }
Romain Guy06882f82009-06-10 13:36:04 -07006619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006621 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006622 TAG, "IWindow finishDrawing called for " + window);
6623 finishDrawingWindow(this, window);
6624 }
6625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006626 public void setInTouchMode(boolean mode) {
6627 synchronized(mWindowMap) {
6628 mInTouchMode = mode;
6629 }
6630 }
6631
6632 public boolean getInTouchMode() {
6633 synchronized(mWindowMap) {
6634 return mInTouchMode;
6635 }
6636 }
6637
6638 public boolean performHapticFeedback(IWindow window, int effectId,
6639 boolean always) {
6640 synchronized(mWindowMap) {
6641 long ident = Binder.clearCallingIdentity();
6642 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006643 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006644 windowForClientLocked(this, window, true),
6645 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006646 } finally {
6647 Binder.restoreCallingIdentity(ident);
6648 }
6649 }
6650 }
Romain Guy06882f82009-06-10 13:36:04 -07006651
Christopher Tatea53146c2010-09-07 11:57:52 -07006652 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006653 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006654 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006655 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006656 width, height, outSurface);
6657 }
6658
6659 public boolean performDrag(IWindow window, IBinder dragToken,
6660 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6661 ClipData data) {
6662 if (DEBUG_DRAG) {
6663 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6664 }
6665
6666 synchronized (mWindowMap) {
6667 if (mDragState == null) {
6668 Slog.w(TAG, "No drag prepared");
6669 throw new IllegalStateException("performDrag() without prepareDrag()");
6670 }
6671
6672 if (dragToken != mDragState.mToken) {
6673 Slog.w(TAG, "Performing mismatched drag");
6674 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6675 }
6676
6677 WindowState callingWin = windowForClientLocked(null, window, false);
6678 if (callingWin == null) {
6679 Slog.w(TAG, "Bad requesting window " + window);
6680 return false; // !!! TODO: throw here?
6681 }
6682
6683 // !!! TODO: if input is not still focused on the initiating window, fail
6684 // the drag initiation (e.g. an alarm window popped up just as the application
6685 // called performDrag()
6686
6687 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6688
Christopher Tate2c095f32010-10-04 14:13:40 -07006689 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6690 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006691
Chris Tateb478f462010-10-15 16:02:26 -07006692 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6693 // the actual drag event dispatch stuff in the dragstate
6694
Christopher Tatea53146c2010-09-07 11:57:52 -07006695 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006696 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006697 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6698 mDragState.mServerChannel)) {
6699 Slog.e(TAG, "Unable to transfer touch focus");
6700 mDragState.unregister();
6701 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006702 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006703 return false;
6704 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006705
6706 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006707 mDragState.mCurrentX = touchX;
6708 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006709 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006710
6711 // remember the thumb offsets for later
6712 mDragState.mThumbOffsetX = thumbCenterX;
6713 mDragState.mThumbOffsetY = thumbCenterY;
6714
6715 // Make the surface visible at the proper location
6716 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006717 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006718 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006719 try {
6720 surface.setPosition((int)(touchX - thumbCenterX),
6721 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006722 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006723 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006724 surface.show();
6725 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006726 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006727 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006728 }
6729 }
6730
6731 return true; // success!
6732 }
6733
Chris Tated4533f142010-10-19 15:15:08 -07006734 public void reportDropResult(IWindow window, boolean consumed) {
6735 IBinder token = window.asBinder();
6736 if (DEBUG_DRAG) {
6737 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6738 }
6739
6740 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006741 long ident = Binder.clearCallingIdentity();
6742 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006743 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006744 Slog.w(TAG, "Invalid drop-result claim by " + window);
6745 throw new IllegalStateException("reportDropResult() by non-recipient");
6746 }
6747
6748 // The right window has responded, even if it's no longer around,
6749 // so be sure to halt the timeout even if the later WindowState
6750 // lookup fails.
6751 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6752 WindowState callingWin = windowForClientLocked(null, window, false);
6753 if (callingWin == null) {
6754 Slog.w(TAG, "Bad result-reporting window " + window);
6755 return; // !!! TODO: throw here?
6756 }
6757
6758 mDragState.mDragResult = consumed;
6759 mDragState.endDragLw();
6760 } finally {
6761 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006762 }
Chris Tated4533f142010-10-19 15:15:08 -07006763 }
6764 }
6765
Christopher Tatea53146c2010-09-07 11:57:52 -07006766 public void dragRecipientEntered(IWindow window) {
6767 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006768 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006769 }
6770 }
6771
6772 public void dragRecipientExited(IWindow window) {
6773 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006774 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006775 }
6776 }
6777
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006778 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006779 synchronized(mWindowMap) {
6780 long ident = Binder.clearCallingIdentity();
6781 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006782 setWindowWallpaperPositionLocked(
6783 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006784 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006785 } finally {
6786 Binder.restoreCallingIdentity(ident);
6787 }
6788 }
6789 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006790
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006791 public void wallpaperOffsetsComplete(IBinder window) {
6792 WindowManagerService.this.wallpaperOffsetsComplete(window);
6793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006794
Dianne Hackborn75804932009-10-20 20:15:20 -07006795 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6796 int z, Bundle extras, boolean sync) {
6797 synchronized(mWindowMap) {
6798 long ident = Binder.clearCallingIdentity();
6799 try {
6800 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006801 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006802 action, x, y, z, extras, sync);
6803 } finally {
6804 Binder.restoreCallingIdentity(ident);
6805 }
6806 }
6807 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006808
Dianne Hackborn75804932009-10-20 20:15:20 -07006809 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6810 WindowManagerService.this.wallpaperCommandComplete(window, result);
6811 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006813 void windowAddedLocked() {
6814 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006815 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006816 TAG, "First window added to " + this + ", creating SurfaceSession");
6817 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006818 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006819 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006820 mSessions.add(this);
6821 }
6822 mNumWindow++;
6823 }
6824
6825 void windowRemovedLocked() {
6826 mNumWindow--;
6827 killSessionLocked();
6828 }
Romain Guy06882f82009-06-10 13:36:04 -07006829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006830 void killSessionLocked() {
6831 if (mNumWindow <= 0 && mClientDead) {
6832 mSessions.remove(this);
6833 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006834 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006835 TAG, "Last window removed from " + this
6836 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006837 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006838 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 try {
6840 mSurfaceSession.kill();
6841 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006842 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006843 + mSurfaceSession + " in session " + this
6844 + ": " + e.toString());
6845 }
6846 mSurfaceSession = null;
6847 }
6848 }
6849 }
Romain Guy06882f82009-06-10 13:36:04 -07006850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006852 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6853 pw.print(" mClientDead="); pw.print(mClientDead);
6854 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006855 }
6856
6857 @Override
6858 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006859 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 }
6861 }
6862
6863 // -------------------------------------------------------------
6864 // Client Window State
6865 // -------------------------------------------------------------
6866
6867 private final class WindowState implements WindowManagerPolicy.WindowState {
6868 final Session mSession;
6869 final IWindow mClient;
6870 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006871 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006872 AppWindowToken mAppToken;
6873 AppWindowToken mTargetAppToken;
6874 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6875 final DeathRecipient mDeathRecipient;
6876 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006877 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 final int mBaseLayer;
6879 final int mSubLayer;
6880 final boolean mLayoutAttached;
6881 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006882 final boolean mIsWallpaper;
6883 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006884 int mViewVisibility;
6885 boolean mPolicyVisibility = true;
6886 boolean mPolicyVisibilityAfterAnim = true;
6887 boolean mAppFreezing;
6888 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006889 boolean mReportDestroySurface;
6890 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 boolean mAttachedHidden; // is our parent window hidden?
6892 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006893 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006894 int mRequestedWidth;
6895 int mRequestedHeight;
6896 int mLastRequestedWidth;
6897 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898 int mLayer;
6899 int mAnimLayer;
6900 int mLastLayer;
6901 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006902 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006903 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006904
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006905 int mLayoutSeq = -1;
6906
6907 Configuration mConfiguration = null;
6908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 // Actual frame shown on-screen (may be modified by animation)
6910 final Rect mShownFrame = new Rect();
6911 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006913 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006914 * Set when we have changed the size of the surface, to know that
6915 * we must tell them application to resize (and thus redraw itself).
6916 */
6917 boolean mSurfaceResized;
6918
6919 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006920 * Insets that determine the actually visible area
6921 */
6922 final Rect mVisibleInsets = new Rect();
6923 final Rect mLastVisibleInsets = new Rect();
6924 boolean mVisibleInsetsChanged;
6925
6926 /**
6927 * Insets that are covered by system windows
6928 */
6929 final Rect mContentInsets = new Rect();
6930 final Rect mLastContentInsets = new Rect();
6931 boolean mContentInsetsChanged;
6932
6933 /**
6934 * Set to true if we are waiting for this window to receive its
6935 * given internal insets before laying out other windows based on it.
6936 */
6937 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 /**
6940 * These are the content insets that were given during layout for
6941 * this window, to be applied to windows behind it.
6942 */
6943 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 /**
6946 * These are the visible insets that were given during layout for
6947 * this window, to be applied to windows behind it.
6948 */
6949 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006952 * This is the given touchable area relative to the window frame, or null if none.
6953 */
6954 final Region mGivenTouchableRegion = new Region();
6955
6956 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 * Flag indicating whether the touchable region should be adjusted by
6958 * the visible insets; if false the area outside the visible insets is
6959 * NOT touchable, so we must use those to adjust the frame during hit
6960 * tests.
6961 */
6962 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006964 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006965 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006966 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6967 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6968 float mHScale=1, mVScale=1;
6969 float mLastHScale=1, mLastVScale=1;
6970 final Matrix mTmpMatrix = new Matrix();
6971
6972 // "Real" frame that the application sees.
6973 final Rect mFrame = new Rect();
6974 final Rect mLastFrame = new Rect();
6975
6976 final Rect mContainingFrame = new Rect();
6977 final Rect mDisplayFrame = new Rect();
6978 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006979 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006980 final Rect mVisibleFrame = new Rect();
6981
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006982 boolean mContentChanged;
6983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 float mShownAlpha = 1;
6985 float mAlpha = 1;
6986 float mLastAlpha = 1;
6987
6988 // Set to true if, when the window gets displayed, it should perform
6989 // an enter animation.
6990 boolean mEnterAnimationPending;
6991
6992 // Currently running animation.
6993 boolean mAnimating;
6994 boolean mLocalAnimating;
6995 Animation mAnimation;
6996 boolean mAnimationIsEntrance;
6997 boolean mHasTransformation;
6998 boolean mHasLocalTransformation;
6999 final Transformation mTransformation = new Transformation();
7000
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007001 // If a window showing a wallpaper: the requested offset for the
7002 // wallpaper; if a wallpaper window: the currently applied offset.
7003 float mWallpaperX = -1;
7004 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007005
7006 // If a window showing a wallpaper: what fraction of the offset
7007 // range corresponds to a full virtual screen.
7008 float mWallpaperXStep = -1;
7009 float mWallpaperYStep = -1;
7010
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007011 // Wallpaper windows: pixels offset based on above variables.
7012 int mXOffset;
7013 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007015 // This is set after IWindowSession.relayout() has been called at
7016 // least once for the window. It allows us to detect the situation
7017 // where we don't yet have a surface, but should have one soon, so
7018 // we can give the window focus before waiting for the relayout.
7019 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007021 // This is set after the Surface has been created but before the
7022 // window has been drawn. During this time the surface is hidden.
7023 boolean mDrawPending;
7024
7025 // This is set after the window has finished drawing for the first
7026 // time but before its surface is shown. The surface will be
7027 // displayed when the next layout is run.
7028 boolean mCommitDrawPending;
7029
7030 // This is set during the time after the window's drawing has been
7031 // committed, and before its surface is actually shown. It is used
7032 // to delay showing the surface until all windows in a token are ready
7033 // to be shown.
7034 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 // Set when the window has been shown in the screen the first time.
7037 boolean mHasDrawn;
7038
7039 // Currently running an exit animation?
7040 boolean mExiting;
7041
7042 // Currently on the mDestroySurface list?
7043 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 // Completely remove from window manager after exit animation?
7046 boolean mRemoveOnExit;
7047
7048 // Set when the orientation is changing and this window has not yet
7049 // been updated for the new orientation.
7050 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007052 // Is this window now (or just being) removed?
7053 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007054
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007055 // Temp for keeping track of windows that have been removed when
7056 // rebuilding window list.
7057 boolean mRebuilding;
7058
Dianne Hackborn16064f92010-03-25 00:47:24 -07007059 // For debugging, this is the last information given to the surface flinger.
7060 boolean mSurfaceShown;
7061 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7062 int mSurfaceLayer;
7063 float mSurfaceAlpha;
7064
Jeff Brown928e0542011-01-10 11:17:36 -08007065 // Input channel and input window handle used by the input dispatcher.
7066 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007067 InputChannel mInputChannel;
7068
Mattias Petersson1622eee2010-12-21 10:15:11 +01007069 // Used to improve performance of toString()
7070 String mStringNameCache;
7071 CharSequence mLastTitle;
7072 boolean mWasPaused;
7073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074 WindowState(Session s, IWindow c, WindowToken token,
7075 WindowState attachedWindow, WindowManager.LayoutParams a,
7076 int viewVisibility) {
7077 mSession = s;
7078 mClient = c;
7079 mToken = token;
7080 mAttrs.copyFrom(a);
7081 mViewVisibility = viewVisibility;
7082 DeathRecipient deathRecipient = new DeathRecipient();
7083 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007084 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007085 TAG, "Window " + this + " client=" + c.asBinder()
7086 + " token=" + token + " (" + mAttrs.token + ")");
7087 try {
7088 c.asBinder().linkToDeath(deathRecipient, 0);
7089 } catch (RemoteException e) {
7090 mDeathRecipient = null;
7091 mAttachedWindow = null;
7092 mLayoutAttached = false;
7093 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007094 mIsWallpaper = false;
7095 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 mBaseLayer = 0;
7097 mSubLayer = 0;
7098 return;
7099 }
7100 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7103 mAttrs.type <= LAST_SUB_WINDOW)) {
7104 // The multiplier here is to reserve space for multiple
7105 // windows in the same type layer.
7106 mBaseLayer = mPolicy.windowTypeToLayerLw(
7107 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7108 + TYPE_LAYER_OFFSET;
7109 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7110 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007111 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007112 mAttachedWindow.mChildWindows.add(this);
7113 mLayoutAttached = mAttrs.type !=
7114 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7115 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7116 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007117 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7118 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007119 } else {
7120 // The multiplier here is to reserve space for multiple
7121 // windows in the same type layer.
7122 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7123 * TYPE_LAYER_MULTIPLIER
7124 + TYPE_LAYER_OFFSET;
7125 mSubLayer = 0;
7126 mAttachedWindow = null;
7127 mLayoutAttached = false;
7128 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7129 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007130 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7131 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007132 }
7133
7134 WindowState appWin = this;
7135 while (appWin.mAttachedWindow != null) {
7136 appWin = mAttachedWindow;
7137 }
7138 WindowToken appToken = appWin.mToken;
7139 while (appToken.appWindowToken == null) {
7140 WindowToken parent = mTokenMap.get(appToken.token);
7141 if (parent == null || appToken == parent) {
7142 break;
7143 }
7144 appToken = parent;
7145 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007146 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007147 mAppToken = appToken.appWindowToken;
7148
7149 mSurface = null;
7150 mRequestedWidth = 0;
7151 mRequestedHeight = 0;
7152 mLastRequestedWidth = 0;
7153 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007154 mXOffset = 0;
7155 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 mLayer = 0;
7157 mAnimLayer = 0;
7158 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007159 mInputWindowHandle = new InputWindowHandle(
7160 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007161 }
7162
7163 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007164 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 TAG, "Attaching " + this + " token=" + mToken
7166 + ", list=" + mToken.windows);
7167 mSession.windowAddedLocked();
7168 }
7169
7170 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7171 mHaveFrame = true;
7172
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007173 final Rect container = mContainingFrame;
7174 container.set(pf);
7175
7176 final Rect display = mDisplayFrame;
7177 display.set(df);
7178
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007179 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007180 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007181 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7182 display.intersect(mCompatibleScreenFrame);
7183 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007184 }
7185
7186 final int pw = container.right - container.left;
7187 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007188
7189 int w,h;
7190 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7191 w = mAttrs.width < 0 ? pw : mAttrs.width;
7192 h = mAttrs.height< 0 ? ph : mAttrs.height;
7193 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007194 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7195 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 }
Romain Guy06882f82009-06-10 13:36:04 -07007197
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007198 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007199 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7200 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007201 mParentFrame.set(pf);
7202 mContentChanged = true;
7203 }
7204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 final Rect content = mContentFrame;
7206 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007208 final Rect visible = mVisibleFrame;
7209 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007211 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007212 final int fw = frame.width();
7213 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007215 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7216 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7217
7218 Gravity.apply(mAttrs.gravity, w, h, container,
7219 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7220 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7221
7222 //System.out.println("Out: " + mFrame);
7223
7224 // Now make sure the window fits in the overall display.
7225 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007227 // Make sure the content and visible frames are inside of the
7228 // final window frame.
7229 if (content.left < frame.left) content.left = frame.left;
7230 if (content.top < frame.top) content.top = frame.top;
7231 if (content.right > frame.right) content.right = frame.right;
7232 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7233 if (visible.left < frame.left) visible.left = frame.left;
7234 if (visible.top < frame.top) visible.top = frame.top;
7235 if (visible.right > frame.right) visible.right = frame.right;
7236 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007238 final Rect contentInsets = mContentInsets;
7239 contentInsets.left = content.left-frame.left;
7240 contentInsets.top = content.top-frame.top;
7241 contentInsets.right = frame.right-content.right;
7242 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007244 final Rect visibleInsets = mVisibleInsets;
7245 visibleInsets.left = visible.left-frame.left;
7246 visibleInsets.top = visible.top-frame.top;
7247 visibleInsets.right = frame.right-visible.right;
7248 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007249
Dianne Hackborn284ac932009-08-28 10:34:25 -07007250 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7251 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007252 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007253 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007255 if (localLOGV) {
7256 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7257 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007258 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 + mRequestedWidth + ", mRequestedheight="
7260 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7261 + "): frame=" + mFrame.toShortString()
7262 + " ci=" + contentInsets.toShortString()
7263 + " vi=" + visibleInsets.toShortString());
7264 //}
7265 }
7266 }
Romain Guy06882f82009-06-10 13:36:04 -07007267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 public Rect getFrameLw() {
7269 return mFrame;
7270 }
7271
7272 public Rect getShownFrameLw() {
7273 return mShownFrame;
7274 }
7275
7276 public Rect getDisplayFrameLw() {
7277 return mDisplayFrame;
7278 }
7279
7280 public Rect getContentFrameLw() {
7281 return mContentFrame;
7282 }
7283
7284 public Rect getVisibleFrameLw() {
7285 return mVisibleFrame;
7286 }
7287
7288 public boolean getGivenInsetsPendingLw() {
7289 return mGivenInsetsPending;
7290 }
7291
7292 public Rect getGivenContentInsetsLw() {
7293 return mGivenContentInsets;
7294 }
Romain Guy06882f82009-06-10 13:36:04 -07007295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007296 public Rect getGivenVisibleInsetsLw() {
7297 return mGivenVisibleInsets;
7298 }
Romain Guy06882f82009-06-10 13:36:04 -07007299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 public WindowManager.LayoutParams getAttrs() {
7301 return mAttrs;
7302 }
7303
7304 public int getSurfaceLayer() {
7305 return mLayer;
7306 }
Romain Guy06882f82009-06-10 13:36:04 -07007307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007308 public IApplicationToken getAppToken() {
7309 return mAppToken != null ? mAppToken.appToken : null;
7310 }
Jeff Brown349703e2010-06-22 01:27:15 -07007311
7312 public long getInputDispatchingTimeoutNanos() {
7313 return mAppToken != null
7314 ? mAppToken.inputDispatchingTimeoutNanos
7315 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317
7318 public boolean hasAppShownWindows() {
7319 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7320 }
7321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007322 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007323 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007324 TAG, "Setting animation in " + this + ": " + anim);
7325 mAnimating = false;
7326 mLocalAnimating = false;
7327 mAnimation = anim;
7328 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7329 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7330 }
7331
7332 public void clearAnimation() {
7333 if (mAnimation != null) {
7334 mAnimating = true;
7335 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007336 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007337 mAnimation = null;
7338 }
7339 }
Romain Guy06882f82009-06-10 13:36:04 -07007340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007341 Surface createSurfaceLocked() {
7342 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007343 mReportDestroySurface = false;
7344 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 mDrawPending = true;
7346 mCommitDrawPending = false;
7347 mReadyToShow = false;
7348 if (mAppToken != null) {
7349 mAppToken.allDrawn = false;
7350 }
7351
7352 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353
7354 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7355 flags |= Surface.SECURE;
7356 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007357 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 TAG, "Creating surface in session "
7359 + mSession.mSurfaceSession + " window " + this
7360 + " w=" + mFrame.width()
7361 + " h=" + mFrame.height() + " format="
7362 + mAttrs.format + " flags=" + flags);
7363
7364 int w = mFrame.width();
7365 int h = mFrame.height();
7366 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7367 // for a scaled surface, we always want the requested
7368 // size.
7369 w = mRequestedWidth;
7370 h = mRequestedHeight;
7371 }
7372
Romain Guy9825ec62009-10-01 00:58:09 -07007373 // Something is wrong and SurfaceFlinger will not like this,
7374 // try to revert to sane values
7375 if (w <= 0) w = 1;
7376 if (h <= 0) h = 1;
7377
Dianne Hackborn16064f92010-03-25 00:47:24 -07007378 mSurfaceShown = false;
7379 mSurfaceLayer = 0;
7380 mSurfaceAlpha = 1;
7381 mSurfaceX = 0;
7382 mSurfaceY = 0;
7383 mSurfaceW = w;
7384 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007386 final boolean isHwAccelerated = (mAttrs.flags &
7387 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7388 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7389 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7390 flags |= Surface.OPAQUE;
7391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007393 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007394 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007395 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007396 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007397 + mSurface + " IN SESSION "
7398 + mSession.mSurfaceSession
7399 + ": pid=" + mSession.mPid + " format="
7400 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007401 + Integer.toHexString(flags)
7402 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007403 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007404 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 reclaimSomeSurfaceMemoryLocked(this, "create");
7406 return null;
7407 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007408 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 return null;
7410 }
Romain Guy06882f82009-06-10 13:36:04 -07007411
Joe Onorato8a9b2202010-02-26 18:56:32 -08007412 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 TAG, "Got surface: " + mSurface
7414 + ", set left=" + mFrame.left + " top=" + mFrame.top
7415 + ", animLayer=" + mAnimLayer);
7416 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007417 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7418 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007419 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7420 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 }
7422 Surface.openTransaction();
7423 try {
7424 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007425 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007426 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007427 mSurface.setPosition(mSurfaceX, mSurfaceY);
7428 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007430 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 mSurface.hide();
7432 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007433 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007434 mSurface.setFlags(Surface.SURFACE_DITHER,
7435 Surface.SURFACE_DITHER);
7436 }
7437 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007438 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7440 }
7441 mLastHidden = true;
7442 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007444 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007446 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 TAG, "Created surface " + this);
7448 }
7449 return mSurface;
7450 }
Romain Guy06882f82009-06-10 13:36:04 -07007451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007453 if (mAppToken != null && this == mAppToken.startingWindow) {
7454 mAppToken.startingDisplayed = false;
7455 }
Romain Guy06882f82009-06-10 13:36:04 -07007456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007457 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007458 mDrawPending = false;
7459 mCommitDrawPending = false;
7460 mReadyToShow = false;
7461
7462 int i = mChildWindows.size();
7463 while (i > 0) {
7464 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007465 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007466 c.mAttachedHidden = true;
7467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007468
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007469 if (mReportDestroySurface) {
7470 mReportDestroySurface = false;
7471 mSurfacePendingDestroy = true;
7472 try {
7473 mClient.dispatchGetNewSurface();
7474 // We'll really destroy on the next time around.
7475 return;
7476 } catch (RemoteException e) {
7477 }
7478 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007481 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007482 RuntimeException e = null;
7483 if (!HIDE_STACK_CRAWLS) {
7484 e = new RuntimeException();
7485 e.fillInStackTrace();
7486 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007487 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007488 + mSurface + ", session " + mSession, e);
7489 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007491 RuntimeException e = null;
7492 if (!HIDE_STACK_CRAWLS) {
7493 e = new RuntimeException();
7494 e.fillInStackTrace();
7495 }
7496 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007498 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007500 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 + " surface " + mSurface + " session " + mSession
7502 + ": " + e.toString());
7503 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007504
Dianne Hackborn16064f92010-03-25 00:47:24 -07007505 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007506 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 }
7508 }
7509
7510 boolean finishDrawingLocked() {
7511 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007512 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 TAG, "finishDrawingLocked: " + mSurface);
7514 mCommitDrawPending = true;
7515 mDrawPending = false;
7516 return true;
7517 }
7518 return false;
7519 }
7520
7521 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007522 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007523 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007525 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 }
7527 mCommitDrawPending = false;
7528 mReadyToShow = true;
7529 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7530 final AppWindowToken atoken = mAppToken;
7531 if (atoken == null || atoken.allDrawn || starting) {
7532 performShowLocked();
7533 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007534 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 }
7536
7537 // This must be called while inside a transaction.
7538 boolean performShowLocked() {
7539 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007540 RuntimeException e = null;
7541 if (!HIDE_STACK_CRAWLS) {
7542 e = new RuntimeException();
7543 e.fillInStackTrace();
7544 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007545 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7547 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7548 }
7549 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007550 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7551 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007552 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 + " during animation: policyVis=" + mPolicyVisibility
7554 + " attHidden=" + mAttachedHidden
7555 + " tok.hiddenRequested="
7556 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007557 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 + (mAppToken != null ? mAppToken.hidden : false)
7559 + " animating=" + mAnimating
7560 + " tok animating="
7561 + (mAppToken != null ? mAppToken.animating : false));
7562 if (!showSurfaceRobustlyLocked(this)) {
7563 return false;
7564 }
7565 mLastAlpha = -1;
7566 mHasDrawn = true;
7567 mLastHidden = false;
7568 mReadyToShow = false;
7569 enableScreenIfNeededLocked();
7570
7571 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 int i = mChildWindows.size();
7574 while (i > 0) {
7575 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007576 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007577 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007578 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007579 if (c.mSurface != null) {
7580 c.performShowLocked();
7581 // It hadn't been shown, which means layout not
7582 // performed on it, so now we want to make sure to
7583 // do a layout. If called from within the transaction
7584 // loop, this will cause it to restart with a new
7585 // layout.
7586 mLayoutNeeded = true;
7587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 }
7589 }
Romain Guy06882f82009-06-10 13:36:04 -07007590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 if (mAttrs.type != TYPE_APPLICATION_STARTING
7592 && mAppToken != null) {
7593 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007594
Dianne Hackborn248b1882009-09-16 16:46:44 -07007595 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007596 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007597 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007599 // If this initial window is animating, stop it -- we
7600 // will do an animation to reveal it from behind the
7601 // starting window, so there is no need for it to also
7602 // be doing its own stuff.
7603 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007604 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007605 mAnimation = null;
7606 // Make sure we clean up the animation.
7607 mAnimating = true;
7608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 mFinishedStarting.add(mAppToken);
7610 mH.sendEmptyMessage(H.FINISHED_STARTING);
7611 }
7612 mAppToken.updateReportedVisibilityLocked();
7613 }
7614 }
7615 return true;
7616 }
Romain Guy06882f82009-06-10 13:36:04 -07007617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 // This must be called while inside a transaction. Returns true if
7619 // there is more animation to run.
7620 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007621 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007624 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7625 mHasTransformation = true;
7626 mHasLocalTransformation = true;
7627 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007628 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 TAG, "Starting animation in " + this +
7630 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7631 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7632 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7633 mAnimation.setStartTime(currentTime);
7634 mLocalAnimating = true;
7635 mAnimating = true;
7636 }
7637 mTransformation.clear();
7638 final boolean more = mAnimation.getTransformation(
7639 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007640 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007641 TAG, "Stepped animation in " + this +
7642 ": more=" + more + ", xform=" + mTransformation);
7643 if (more) {
7644 // we're not done!
7645 return true;
7646 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007647 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007648 TAG, "Finished animation in " + this +
7649 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007650
7651 if (mAnimation != null) {
7652 mAnimation.cancel();
7653 mAnimation = null;
7654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007655 //WindowManagerService.this.dump();
7656 }
7657 mHasLocalTransformation = false;
7658 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007659 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 // When our app token is animating, we kind-of pretend like
7661 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7662 // part of this check means that we will only do this if
7663 // our window is not currently exiting, or it is not
7664 // locally animating itself. The idea being that one that
7665 // is exiting and doing a local animation should be removed
7666 // once that animation is done.
7667 mAnimating = true;
7668 mHasTransformation = true;
7669 mTransformation.clear();
7670 return false;
7671 } else if (mHasTransformation) {
7672 // Little trick to get through the path below to act like
7673 // we have finished an animation.
7674 mAnimating = true;
7675 } else if (isAnimating()) {
7676 mAnimating = true;
7677 }
7678 } else if (mAnimation != null) {
7679 // If the display is frozen, and there is a pending animation,
7680 // clear it and make sure we run the cleanup code.
7681 mAnimating = true;
7682 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007683 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 mAnimation = null;
7685 }
Romain Guy06882f82009-06-10 13:36:04 -07007686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007687 if (!mAnimating && !mLocalAnimating) {
7688 return false;
7689 }
7690
Joe Onorato8a9b2202010-02-26 18:56:32 -08007691 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 TAG, "Animation done in " + this + ": exiting=" + mExiting
7693 + ", reportedVisible="
7694 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 mAnimating = false;
7697 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007698 if (mAnimation != null) {
7699 mAnimation.cancel();
7700 mAnimation = null;
7701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 mAnimLayer = mLayer;
7703 if (mIsImWindow) {
7704 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007705 } else if (mIsWallpaper) {
7706 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007707 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007708 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 + " anim layer: " + mAnimLayer);
7710 mHasTransformation = false;
7711 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007712 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7713 if (DEBUG_VISIBILITY) {
7714 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7715 + mPolicyVisibilityAfterAnim);
7716 }
7717 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7718 if (!mPolicyVisibility) {
7719 if (mCurrentFocus == this) {
7720 mFocusMayChange = true;
7721 }
7722 // Window is no longer visible -- make sure if we were waiting
7723 // for it to be displayed before enabling the display, that
7724 // we allow the display to be enabled now.
7725 enableScreenIfNeededLocked();
7726 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 mTransformation.clear();
7729 if (mHasDrawn
7730 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7731 && mAppToken != null
7732 && mAppToken.firstWindowDrawn
7733 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007734 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007735 + mToken + ": first real window done animating");
7736 mFinishedStarting.add(mAppToken);
7737 mH.sendEmptyMessage(H.FINISHED_STARTING);
7738 }
Romain Guy06882f82009-06-10 13:36:04 -07007739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007740 finishExit();
7741
7742 if (mAppToken != null) {
7743 mAppToken.updateReportedVisibilityLocked();
7744 }
7745
7746 return false;
7747 }
7748
7749 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007750 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007751 TAG, "finishExit in " + this
7752 + ": exiting=" + mExiting
7753 + " remove=" + mRemoveOnExit
7754 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 final int N = mChildWindows.size();
7757 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007758 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 }
Romain Guy06882f82009-06-10 13:36:04 -07007760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 if (!mExiting) {
7762 return;
7763 }
Romain Guy06882f82009-06-10 13:36:04 -07007764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007765 if (isWindowAnimating()) {
7766 return;
7767 }
7768
Joe Onorato8a9b2202010-02-26 18:56:32 -08007769 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 TAG, "Exit animation finished in " + this
7771 + ": remove=" + mRemoveOnExit);
7772 if (mSurface != null) {
7773 mDestroySurface.add(this);
7774 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007775 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007776 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 try {
7778 mSurface.hide();
7779 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007780 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007781 }
7782 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 }
7784 mExiting = false;
7785 if (mRemoveOnExit) {
7786 mPendingRemove.add(this);
7787 mRemoveOnExit = false;
7788 }
7789 }
Romain Guy06882f82009-06-10 13:36:04 -07007790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007791 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7792 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7793 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7794 if (dtdx < -.000001f || dtdx > .000001f) return false;
7795 if (dsdy < -.000001f || dsdy > .000001f) return false;
7796 return true;
7797 }
Romain Guy06882f82009-06-10 13:36:04 -07007798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007799 void computeShownFrameLocked() {
7800 final boolean selfTransformation = mHasLocalTransformation;
7801 Transformation attachedTransformation =
7802 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7803 ? mAttachedWindow.mTransformation : null;
7804 Transformation appTransformation =
7805 (mAppToken != null && mAppToken.hasTransformation)
7806 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007807
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007808 // Wallpapers are animated based on the "real" window they
7809 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007810 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007811 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007812 if (mWallpaperTarget.mHasLocalTransformation &&
7813 mWallpaperTarget.mAnimation != null &&
7814 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007815 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007816 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007817 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007818 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007819 }
7820 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007821 mWallpaperTarget.mAppToken.hasTransformation &&
7822 mWallpaperTarget.mAppToken.animation != null &&
7823 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007824 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007825 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007826 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007827 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007828 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007829 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007830
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007831 final boolean screenAnimation = mScreenRotationAnimation != null
7832 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007834 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007835 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007836 final Rect frame = mFrame;
7837 final float tmpFloats[] = mTmpFloats;
7838 final Matrix tmpMatrix = mTmpMatrix;
7839
7840 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007841 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007843 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007844 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007845 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007847 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007848 }
7849 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007850 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007852 if (screenAnimation) {
7853 tmpMatrix.postConcat(
7854 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7855 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007856
7857 // "convert" it into SurfaceFlinger's format
7858 // (a 2x2 matrix + an offset)
7859 // Here we must not transform the position of the surface
7860 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007861 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007862
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007863 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007864 tmpMatrix.getValues(tmpFloats);
7865 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007866 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7867 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007869 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7870 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007871 int w = frame.width();
7872 int h = frame.height();
7873 mShownFrame.set(x, y, x+w, y+h);
7874
7875 // Now set the alpha... but because our current hardware
7876 // can't do alpha transformation on a non-opaque surface,
7877 // turn it off if we are running an animation that is also
7878 // transforming since it is more important to have that
7879 // animation be smooth.
7880 mShownAlpha = mAlpha;
7881 if (!mLimitedAlphaCompositing
7882 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7883 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7884 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007885 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 if (selfTransformation) {
7887 mShownAlpha *= mTransformation.getAlpha();
7888 }
7889 if (attachedTransformation != null) {
7890 mShownAlpha *= attachedTransformation.getAlpha();
7891 }
7892 if (appTransformation != null) {
7893 mShownAlpha *= appTransformation.getAlpha();
7894 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007895 if (screenAnimation) {
7896 mShownAlpha *=
7897 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7898 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007899 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007900 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 }
Romain Guy06882f82009-06-10 13:36:04 -07007902
Joe Onorato8a9b2202010-02-26 18:56:32 -08007903 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007904 TAG, "Continuing animation in " + this +
7905 ": " + mShownFrame +
7906 ", alpha=" + mTransformation.getAlpha());
7907 return;
7908 }
Romain Guy06882f82009-06-10 13:36:04 -07007909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007910 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007911 if (mXOffset != 0 || mYOffset != 0) {
7912 mShownFrame.offset(mXOffset, mYOffset);
7913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007914 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007915 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 mDsDx = 1;
7917 mDtDx = 0;
7918 mDsDy = 0;
7919 mDtDy = 1;
7920 }
Romain Guy06882f82009-06-10 13:36:04 -07007921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007922 /**
7923 * Is this window visible? It is not visible if there is no
7924 * surface, or we are in the process of running an exit animation
7925 * that will remove the surface, or its app token has been hidden.
7926 */
7927 public boolean isVisibleLw() {
7928 final AppWindowToken atoken = mAppToken;
7929 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7930 && (atoken == null || !atoken.hiddenRequested)
7931 && !mExiting && !mDestroying;
7932 }
7933
7934 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007935 * Like {@link #isVisibleLw}, but also counts a window that is currently
7936 * "hidden" behind the keyguard as visible. This allows us to apply
7937 * things like window flags that impact the keyguard.
7938 * XXX I am starting to think we need to have ANOTHER visibility flag
7939 * for this "hidden behind keyguard" state rather than overloading
7940 * mPolicyVisibility. Ungh.
7941 */
7942 public boolean isVisibleOrBehindKeyguardLw() {
7943 final AppWindowToken atoken = mAppToken;
7944 return mSurface != null && !mAttachedHidden
7945 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007946 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007947 && !mExiting && !mDestroying;
7948 }
7949
7950 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 * Is this window visible, ignoring its app token? It is not visible
7952 * if there is no surface, or we are in the process of running an exit animation
7953 * that will remove the surface.
7954 */
7955 public boolean isWinVisibleLw() {
7956 final AppWindowToken atoken = mAppToken;
7957 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7958 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7959 && !mExiting && !mDestroying;
7960 }
7961
7962 /**
7963 * The same as isVisible(), but follows the current hidden state of
7964 * the associated app token, not the pending requested hidden state.
7965 */
7966 boolean isVisibleNow() {
7967 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007968 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007969 }
7970
7971 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007972 * Can this window possibly be a drag/drop target? The test here is
7973 * a combination of the above "visible now" with the check that the
7974 * Input Manager uses when discarding windows from input consideration.
7975 */
7976 boolean isPotentialDragTarget() {
7977 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7978 }
7979
7980 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007981 * Same as isVisible(), but we also count it as visible between the
7982 * call to IWindowSession.add() and the first relayout().
7983 */
7984 boolean isVisibleOrAdding() {
7985 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007986 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007987 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7988 && mPolicyVisibility && !mAttachedHidden
7989 && (atoken == null || !atoken.hiddenRequested)
7990 && !mExiting && !mDestroying;
7991 }
7992
7993 /**
7994 * Is this window currently on-screen? It is on-screen either if it
7995 * is visible or it is currently running an animation before no longer
7996 * being visible.
7997 */
7998 boolean isOnScreen() {
7999 final AppWindowToken atoken = mAppToken;
8000 if (atoken != null) {
8001 return mSurface != null && mPolicyVisibility && !mDestroying
8002 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008003 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 } else {
8005 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008006 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008007 }
8008 }
Romain Guy06882f82009-06-10 13:36:04 -07008009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008010 /**
8011 * Like isOnScreen(), but we don't return true if the window is part
8012 * of a transition that has not yet been started.
8013 */
8014 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008015 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008016 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008017 return false;
8018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008020 final boolean animating = atoken != null
8021 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008023 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8024 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008025 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008026 }
8027
8028 /** Is the window or its container currently animating? */
8029 boolean isAnimating() {
8030 final WindowState attached = mAttachedWindow;
8031 final AppWindowToken atoken = mAppToken;
8032 return mAnimation != null
8033 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008034 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 (atoken.animation != null
8036 || atoken.inPendingTransaction));
8037 }
8038
8039 /** Is this window currently animating? */
8040 boolean isWindowAnimating() {
8041 return mAnimation != null;
8042 }
8043
8044 /**
8045 * Like isOnScreen, but returns false if the surface hasn't yet
8046 * been drawn.
8047 */
8048 public boolean isDisplayedLw() {
8049 final AppWindowToken atoken = mAppToken;
8050 return mSurface != null && mPolicyVisibility && !mDestroying
8051 && !mDrawPending && !mCommitDrawPending
8052 && ((!mAttachedHidden &&
8053 (atoken == null || !atoken.hiddenRequested))
8054 || mAnimating);
8055 }
8056
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008057 /**
8058 * Returns true if the window has a surface that it has drawn a
8059 * complete UI in to.
8060 */
8061 public boolean isDrawnLw() {
8062 final AppWindowToken atoken = mAppToken;
8063 return mSurface != null && !mDestroying
8064 && !mDrawPending && !mCommitDrawPending;
8065 }
8066
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008067 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008068 * Return true if the window is opaque and fully drawn. This indicates
8069 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008070 */
8071 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008072 return (mAttrs.format == PixelFormat.OPAQUE
8073 || mAttrs.type == TYPE_WALLPAPER)
8074 && mSurface != null && mAnimation == null
8075 && (mAppToken == null || mAppToken.animation == null)
8076 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008077 }
8078
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008079 /**
8080 * Return whether this window is wanting to have a translation
8081 * animation applied to it for an in-progress move. (Only makes
8082 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8083 */
8084 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008085 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008086 && (mFrame.top != mLastFrame.top
8087 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008088 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008089 && mPolicy.isScreenOn();
8090 }
8091
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008092 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8093 return
8094 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008095 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8096 // only if it's visible
8097 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008098 // and only if the application fills the compatible screen
8099 mFrame.left <= mCompatibleScreenFrame.left &&
8100 mFrame.top <= mCompatibleScreenFrame.top &&
8101 mFrame.right >= mCompatibleScreenFrame.right &&
8102 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008103 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008104 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008105 }
8106
8107 boolean isFullscreen(int screenWidth, int screenHeight) {
8108 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008109 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008110 }
8111
8112 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008113 disposeInputChannel();
8114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008115 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008116 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008117 mAttachedWindow.mChildWindows.remove(this);
8118 }
8119 destroySurfaceLocked();
8120 mSession.windowRemovedLocked();
8121 try {
8122 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8123 } catch (RuntimeException e) {
8124 // Ignore if it has already been removed (usually because
8125 // we are doing this as part of processing a death note.)
8126 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008127 }
8128
8129 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008130 if (mInputChannel != null) {
8131 mInputManager.unregisterInputChannel(mInputChannel);
8132
8133 mInputChannel.dispose();
8134 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008136 }
8137
8138 private class DeathRecipient implements IBinder.DeathRecipient {
8139 public void binderDied() {
8140 try {
8141 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008142 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008143 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008144 if (win != null) {
8145 removeWindowLocked(mSession, win);
8146 }
8147 }
8148 } catch (IllegalArgumentException ex) {
8149 // This will happen if the window has already been
8150 // removed.
8151 }
8152 }
8153 }
8154
8155 /** Returns true if this window desires key events. */
8156 public final boolean canReceiveKeys() {
8157 return isVisibleOrAdding()
8158 && (mViewVisibility == View.VISIBLE)
8159 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8160 }
8161
8162 public boolean hasDrawnLw() {
8163 return mHasDrawn;
8164 }
8165
8166 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008167 return showLw(doAnimation, true);
8168 }
8169
8170 boolean showLw(boolean doAnimation, boolean requestAnim) {
8171 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8172 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008173 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008174 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008175 if (doAnimation) {
8176 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8177 + mPolicyVisibility + " mAnimation=" + mAnimation);
8178 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8179 doAnimation = false;
8180 } else if (mPolicyVisibility && mAnimation == null) {
8181 // Check for the case where we are currently visible and
8182 // not animating; we do not want to do animation at such a
8183 // point to become visible when we already are.
8184 doAnimation = false;
8185 }
8186 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008187 mPolicyVisibility = true;
8188 mPolicyVisibilityAfterAnim = true;
8189 if (doAnimation) {
8190 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8191 }
8192 if (requestAnim) {
8193 requestAnimationLocked(0);
8194 }
8195 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008196 }
8197
8198 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008199 return hideLw(doAnimation, true);
8200 }
8201
8202 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008203 if (doAnimation) {
8204 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8205 doAnimation = false;
8206 }
8207 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008208 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8209 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008210 if (!current) {
8211 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008213 if (doAnimation) {
8214 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8215 if (mAnimation == null) {
8216 doAnimation = false;
8217 }
8218 }
8219 if (doAnimation) {
8220 mPolicyVisibilityAfterAnim = false;
8221 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008222 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008223 mPolicyVisibilityAfterAnim = false;
8224 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008225 // Window is no longer visible -- make sure if we were waiting
8226 // for it to be displayed before enabling the display, that
8227 // we allow the display to be enabled now.
8228 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008229 if (mCurrentFocus == this) {
8230 mFocusMayChange = true;
8231 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008232 }
8233 if (requestAnim) {
8234 requestAnimationLocked(0);
8235 }
8236 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008237 }
8238
Jeff Brownfbf09772011-01-16 14:06:57 -08008239 public void getTouchableRegion(Region outRegion) {
8240 final Rect frame = mFrame;
8241 switch (mTouchableInsets) {
8242 default:
8243 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8244 outRegion.set(frame);
8245 break;
8246 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8247 final Rect inset = mGivenContentInsets;
8248 outRegion.set(
8249 frame.left + inset.left, frame.top + inset.top,
8250 frame.right - inset.right, frame.bottom - inset.bottom);
8251 break;
8252 }
8253 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8254 final Rect inset = mGivenVisibleInsets;
8255 outRegion.set(
8256 frame.left + inset.left, frame.top + inset.top,
8257 frame.right - inset.right, frame.bottom - inset.bottom);
8258 break;
8259 }
8260 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8261 final Region givenTouchableRegion = mGivenTouchableRegion;
8262 outRegion.set(givenTouchableRegion);
8263 outRegion.translate(frame.left, frame.top);
8264 break;
8265 }
8266 }
8267 }
8268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008269 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008270 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8271 pw.print(" mClient="); pw.println(mClient.asBinder());
8272 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8273 if (mAttachedWindow != null || mLayoutAttached) {
8274 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8275 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8276 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008277 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8278 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8279 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008280 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8281 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008282 }
8283 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8284 pw.print(" mSubLayer="); pw.print(mSubLayer);
8285 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8286 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8287 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8288 pw.print("="); pw.print(mAnimLayer);
8289 pw.print(" mLastLayer="); pw.println(mLastLayer);
8290 if (mSurface != null) {
8291 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008292 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8293 pw.print(" layer="); pw.print(mSurfaceLayer);
8294 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8295 pw.print(" rect=("); pw.print(mSurfaceX);
8296 pw.print(","); pw.print(mSurfaceY);
8297 pw.print(") "); pw.print(mSurfaceW);
8298 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008299 }
8300 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8301 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8302 if (mAppToken != null) {
8303 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8304 }
8305 if (mTargetAppToken != null) {
8306 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8307 }
8308 pw.print(prefix); pw.print("mViewVisibility=0x");
8309 pw.print(Integer.toHexString(mViewVisibility));
8310 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008311 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8312 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008313 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8314 pw.print(prefix); pw.print("mPolicyVisibility=");
8315 pw.print(mPolicyVisibility);
8316 pw.print(" mPolicyVisibilityAfterAnim=");
8317 pw.print(mPolicyVisibilityAfterAnim);
8318 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8319 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008320 if (!mRelayoutCalled) {
8321 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8322 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008323 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008324 pw.print(" h="); pw.print(mRequestedHeight);
8325 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008326 if (mXOffset != 0 || mYOffset != 0) {
8327 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8328 pw.print(" y="); pw.println(mYOffset);
8329 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008330 pw.print(prefix); pw.print("mGivenContentInsets=");
8331 mGivenContentInsets.printShortString(pw);
8332 pw.print(" mGivenVisibleInsets=");
8333 mGivenVisibleInsets.printShortString(pw);
8334 pw.println();
8335 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8336 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8337 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8338 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008339 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008340 pw.print(prefix); pw.print("mShownFrame=");
8341 mShownFrame.printShortString(pw);
8342 pw.print(" last="); mLastShownFrame.printShortString(pw);
8343 pw.println();
8344 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8345 pw.print(" last="); mLastFrame.printShortString(pw);
8346 pw.println();
8347 pw.print(prefix); pw.print("mContainingFrame=");
8348 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008349 pw.print(" mParentFrame=");
8350 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008351 pw.print(" mDisplayFrame=");
8352 mDisplayFrame.printShortString(pw);
8353 pw.println();
8354 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8355 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8356 pw.println();
8357 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8358 pw.print(" last="); mLastContentInsets.printShortString(pw);
8359 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8360 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8361 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008362 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8363 || mAnimation != null) {
8364 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8365 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8366 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8367 pw.print(" mAnimation="); pw.println(mAnimation);
8368 }
8369 if (mHasTransformation || mHasLocalTransformation) {
8370 pw.print(prefix); pw.print("XForm: has=");
8371 pw.print(mHasTransformation);
8372 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8373 pw.print(" "); mTransformation.printShortString(pw);
8374 pw.println();
8375 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008376 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8377 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8378 pw.print(" mAlpha="); pw.print(mAlpha);
8379 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8380 }
8381 if (mHaveMatrix) {
8382 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8383 pw.print(" mDtDx="); pw.print(mDtDx);
8384 pw.print(" mDsDy="); pw.print(mDsDy);
8385 pw.print(" mDtDy="); pw.println(mDtDy);
8386 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008387 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8388 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8389 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8390 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8391 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8392 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8393 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8394 pw.print(" mDestroying="); pw.print(mDestroying);
8395 pw.print(" mRemoved="); pw.println(mRemoved);
8396 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008397 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008398 pw.print(prefix); pw.print("mOrientationChanging=");
8399 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008400 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8401 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008402 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008403 if (mHScale != 1 || mVScale != 1) {
8404 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8405 pw.print(" mVScale="); pw.println(mVScale);
8406 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008407 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008408 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8409 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8410 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008411 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8412 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8413 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008416
8417 String makeInputChannelName() {
8418 return Integer.toHexString(System.identityHashCode(this))
8419 + " " + mAttrs.getTitle();
8420 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008421
8422 @Override
8423 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008424 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8425 || mWasPaused != mToken.paused) {
8426 mLastTitle = mAttrs.getTitle();
8427 mWasPaused = mToken.paused;
8428 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8429 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8430 }
8431 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 }
8433 }
Romain Guy06882f82009-06-10 13:36:04 -07008434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008435 // -------------------------------------------------------------
8436 // Window Token State
8437 // -------------------------------------------------------------
8438
8439 class WindowToken {
8440 // The actual token.
8441 final IBinder token;
8442
8443 // The type of window this token is for, as per WindowManager.LayoutParams.
8444 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008446 // Set if this token was explicitly added by a client, so should
8447 // not be removed when all windows are removed.
8448 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008449
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008450 // For printing.
8451 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453 // If this is an AppWindowToken, this is non-null.
8454 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008456 // All of the windows associated with this token.
8457 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8458
8459 // Is key dispatching paused for this token?
8460 boolean paused = false;
8461
8462 // Should this token's windows be hidden?
8463 boolean hidden;
8464
8465 // Temporary for finding which tokens no longer have visible windows.
8466 boolean hasVisible;
8467
Dianne Hackborna8f60182009-09-01 19:01:50 -07008468 // Set to true when this token is in a pending transaction where it
8469 // will be shown.
8470 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008471
Dianne Hackborna8f60182009-09-01 19:01:50 -07008472 // Set to true when this token is in a pending transaction where it
8473 // will be hidden.
8474 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008475
Dianne Hackborna8f60182009-09-01 19:01:50 -07008476 // Set to true when this token is in a pending transaction where its
8477 // windows will be put to the bottom of the list.
8478 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008479
Dianne Hackborna8f60182009-09-01 19:01:50 -07008480 // Set to true when this token is in a pending transaction where its
8481 // windows will be put to the top of the list.
8482 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008484 WindowToken(IBinder _token, int type, boolean _explicit) {
8485 token = _token;
8486 windowType = type;
8487 explicit = _explicit;
8488 }
8489
8490 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008491 pw.print(prefix); pw.print("token="); pw.println(token);
8492 pw.print(prefix); pw.print("windows="); pw.println(windows);
8493 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8494 pw.print(" hidden="); pw.print(hidden);
8495 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008496 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8497 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8498 pw.print(" waitingToHide="); pw.print(waitingToHide);
8499 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8500 pw.print(" sendingToTop="); pw.println(sendingToTop);
8501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008502 }
8503
8504 @Override
8505 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008506 if (stringName == null) {
8507 StringBuilder sb = new StringBuilder();
8508 sb.append("WindowToken{");
8509 sb.append(Integer.toHexString(System.identityHashCode(this)));
8510 sb.append(" token="); sb.append(token); sb.append('}');
8511 stringName = sb.toString();
8512 }
8513 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 }
8515 };
8516
8517 class AppWindowToken extends WindowToken {
8518 // Non-null only for application tokens.
8519 final IApplicationToken appToken;
8520
8521 // All of the windows and child windows that are included in this
8522 // application token. Note this list is NOT sorted!
8523 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8524
8525 int groupId = -1;
8526 boolean appFullscreen;
8527 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008528
8529 // The input dispatching timeout for this application token in nanoseconds.
8530 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008532 // These are used for determining when all windows associated with
8533 // an activity have been drawn, so they can be made visible together
8534 // at the same time.
8535 int lastTransactionSequence = mTransactionSequence-1;
8536 int numInterestingWindows;
8537 int numDrawnWindows;
8538 boolean inPendingTransaction;
8539 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541 // Is this token going to be hidden in a little while? If so, it
8542 // won't be taken into account for setting the screen orientation.
8543 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 // Is this window's surface needed? This is almost like hidden, except
8546 // it will sometimes be true a little earlier: when the token has
8547 // been shown, but is still waiting for its app transition to execute
8548 // before making its windows shown.
8549 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 // Have we told the window clients to hide themselves?
8552 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008554 // Last visibility state we reported to the app token.
8555 boolean reportedVisible;
8556
8557 // Set to true when the token has been removed from the window mgr.
8558 boolean removed;
8559
8560 // Have we been asked to have this token keep the screen frozen?
8561 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563 boolean animating;
8564 Animation animation;
8565 boolean hasTransformation;
8566 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 // Offset to the window of all layers in the token, for use by
8569 // AppWindowToken animations.
8570 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572 // Information about an application starting window if displayed.
8573 StartingData startingData;
8574 WindowState startingWindow;
8575 View startingView;
8576 boolean startingDisplayed;
8577 boolean startingMoved;
8578 boolean firstWindowDrawn;
8579
Jeff Brown928e0542011-01-10 11:17:36 -08008580 // Input application handle used by the input dispatcher.
8581 InputApplicationHandle mInputApplicationHandle;
8582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 AppWindowToken(IApplicationToken _token) {
8584 super(_token.asBinder(),
8585 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8586 appWindowToken = this;
8587 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008588 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008589 }
Romain Guy06882f82009-06-10 13:36:04 -07008590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008591 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008592 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008593 TAG, "Setting animation in " + this + ": " + anim);
8594 animation = anim;
8595 animating = false;
8596 anim.restrictDuration(MAX_ANIMATION_DURATION);
8597 anim.scaleCurrentDuration(mTransitionAnimationScale);
8598 int zorder = anim.getZAdjustment();
8599 int adj = 0;
8600 if (zorder == Animation.ZORDER_TOP) {
8601 adj = TYPE_LAYER_OFFSET;
8602 } else if (zorder == Animation.ZORDER_BOTTOM) {
8603 adj = -TYPE_LAYER_OFFSET;
8604 }
Romain Guy06882f82009-06-10 13:36:04 -07008605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 if (animLayerAdjustment != adj) {
8607 animLayerAdjustment = adj;
8608 updateLayers();
8609 }
8610 }
Romain Guy06882f82009-06-10 13:36:04 -07008611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612 public void setDummyAnimation() {
8613 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008614 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008615 TAG, "Setting dummy animation in " + this);
8616 animation = sDummyAnimation;
8617 }
8618 }
8619
8620 public void clearAnimation() {
8621 if (animation != null) {
8622 animation = null;
8623 animating = true;
8624 }
8625 }
Romain Guy06882f82009-06-10 13:36:04 -07008626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 void updateLayers() {
8628 final int N = allAppWindows.size();
8629 final int adj = animLayerAdjustment;
8630 for (int i=0; i<N; i++) {
8631 WindowState w = allAppWindows.get(i);
8632 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008633 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008634 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008635 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008636 setInputMethodAnimLayerAdjustment(adj);
8637 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008638 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008639 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 }
8642 }
Romain Guy06882f82009-06-10 13:36:04 -07008643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008644 void sendAppVisibilityToClients() {
8645 final int N = allAppWindows.size();
8646 for (int i=0; i<N; i++) {
8647 WindowState win = allAppWindows.get(i);
8648 if (win == startingWindow && clientHidden) {
8649 // Don't hide the starting window.
8650 continue;
8651 }
8652 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008653 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 "Setting visibility of " + win + ": " + (!clientHidden));
8655 win.mClient.dispatchAppVisibility(!clientHidden);
8656 } catch (RemoteException e) {
8657 }
8658 }
8659 }
Romain Guy06882f82009-06-10 13:36:04 -07008660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 void showAllWindowsLocked() {
8662 final int NW = allAppWindows.size();
8663 for (int i=0; i<NW; i++) {
8664 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008665 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 "performing show on: " + w);
8667 w.performShowLocked();
8668 }
8669 }
Romain Guy06882f82009-06-10 13:36:04 -07008670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 // This must be called while inside a transaction.
8672 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008673 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008674 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008676 if (animation == sDummyAnimation) {
8677 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008678 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 // when it is really time to animate, this will be set to
8680 // a real animation and the next call will execute normally.
8681 return false;
8682 }
Romain Guy06882f82009-06-10 13:36:04 -07008683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008684 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8685 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008686 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008687 TAG, "Starting animation in " + this +
8688 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8689 + " scale=" + mTransitionAnimationScale
8690 + " allDrawn=" + allDrawn + " animating=" + animating);
8691 animation.initialize(dw, dh, dw, dh);
8692 animation.setStartTime(currentTime);
8693 animating = true;
8694 }
8695 transformation.clear();
8696 final boolean more = animation.getTransformation(
8697 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008698 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008699 TAG, "Stepped animation in " + this +
8700 ": more=" + more + ", xform=" + transformation);
8701 if (more) {
8702 // we're done!
8703 hasTransformation = true;
8704 return true;
8705 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008706 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008707 TAG, "Finished animation in " + this +
8708 " @ " + currentTime);
8709 animation = null;
8710 }
8711 } else if (animation != null) {
8712 // If the display is frozen, and there is a pending animation,
8713 // clear it and make sure we run the cleanup code.
8714 animating = true;
8715 animation = null;
8716 }
8717
8718 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008720 if (!animating) {
8721 return false;
8722 }
8723
8724 clearAnimation();
8725 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008726 if (animLayerAdjustment != 0) {
8727 animLayerAdjustment = 0;
8728 updateLayers();
8729 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008730 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8731 moveInputMethodWindowsIfNeededLocked(true);
8732 }
Romain Guy06882f82009-06-10 13:36:04 -07008733
Joe Onorato8a9b2202010-02-26 18:56:32 -08008734 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008735 TAG, "Animation done in " + this
8736 + ": reportedVisible=" + reportedVisible);
8737
8738 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 final int N = windows.size();
8741 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008742 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008743 }
8744 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 return false;
8747 }
8748
8749 void updateReportedVisibilityLocked() {
8750 if (appToken == null) {
8751 return;
8752 }
Romain Guy06882f82009-06-10 13:36:04 -07008753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008754 int numInteresting = 0;
8755 int numVisible = 0;
8756 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008757
Joe Onorato8a9b2202010-02-26 18:56:32 -08008758 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008759 final int N = allAppWindows.size();
8760 for (int i=0; i<N; i++) {
8761 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008762 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008763 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008764 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8765 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008766 continue;
8767 }
8768 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008769 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008770 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008772 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008773 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008774 + " pv=" + win.mPolicyVisibility
8775 + " dp=" + win.mDrawPending
8776 + " cdp=" + win.mCommitDrawPending
8777 + " ah=" + win.mAttachedHidden
8778 + " th="
8779 + (win.mAppToken != null
8780 ? win.mAppToken.hiddenRequested : false)
8781 + " a=" + win.mAnimating);
8782 }
8783 }
8784 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008785 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 if (!win.isAnimating()) {
8787 numVisible++;
8788 }
8789 nowGone = false;
8790 } else if (win.isAnimating()) {
8791 nowGone = false;
8792 }
8793 }
Romain Guy06882f82009-06-10 13:36:04 -07008794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008795 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008796 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 + numInteresting + " visible=" + numVisible);
8798 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008799 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008800 TAG, "Visibility changed in " + this
8801 + ": vis=" + nowVisible);
8802 reportedVisible = nowVisible;
8803 Message m = mH.obtainMessage(
8804 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8805 nowVisible ? 1 : 0,
8806 nowGone ? 1 : 0,
8807 this);
8808 mH.sendMessage(m);
8809 }
8810 }
Romain Guy06882f82009-06-10 13:36:04 -07008811
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008812 WindowState findMainWindow() {
8813 int j = windows.size();
8814 while (j > 0) {
8815 j--;
8816 WindowState win = windows.get(j);
8817 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8818 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8819 return win;
8820 }
8821 }
8822 return null;
8823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 void dump(PrintWriter pw, String prefix) {
8826 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008827 if (appToken != null) {
8828 pw.print(prefix); pw.println("app=true");
8829 }
8830 if (allAppWindows.size() > 0) {
8831 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8832 }
8833 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008834 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008835 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8836 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8837 pw.print(" clientHidden="); pw.print(clientHidden);
8838 pw.print(" willBeHidden="); pw.print(willBeHidden);
8839 pw.print(" reportedVisible="); pw.println(reportedVisible);
8840 if (paused || freezingScreen) {
8841 pw.print(prefix); pw.print("paused="); pw.print(paused);
8842 pw.print(" freezingScreen="); pw.println(freezingScreen);
8843 }
8844 if (numInterestingWindows != 0 || numDrawnWindows != 0
8845 || inPendingTransaction || allDrawn) {
8846 pw.print(prefix); pw.print("numInterestingWindows=");
8847 pw.print(numInterestingWindows);
8848 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8849 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8850 pw.print(" allDrawn="); pw.println(allDrawn);
8851 }
8852 if (animating || animation != null) {
8853 pw.print(prefix); pw.print("animating="); pw.print(animating);
8854 pw.print(" animation="); pw.println(animation);
8855 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008856 if (hasTransformation) {
8857 pw.print(prefix); pw.print("XForm: ");
8858 transformation.printShortString(pw);
8859 pw.println();
8860 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008861 if (animLayerAdjustment != 0) {
8862 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8863 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008864 if (startingData != null || removed || firstWindowDrawn) {
8865 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8866 pw.print(" removed="); pw.print(removed);
8867 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8868 }
8869 if (startingWindow != null || startingView != null
8870 || startingDisplayed || startingMoved) {
8871 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8872 pw.print(" startingView="); pw.print(startingView);
8873 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8874 pw.print(" startingMoved"); pw.println(startingMoved);
8875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008876 }
8877
8878 @Override
8879 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008880 if (stringName == null) {
8881 StringBuilder sb = new StringBuilder();
8882 sb.append("AppWindowToken{");
8883 sb.append(Integer.toHexString(System.identityHashCode(this)));
8884 sb.append(" token="); sb.append(token); sb.append('}');
8885 stringName = sb.toString();
8886 }
8887 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008888 }
8889 }
Romain Guy06882f82009-06-10 13:36:04 -07008890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 // -------------------------------------------------------------
8892 // DummyAnimation
8893 // -------------------------------------------------------------
8894
8895 // This is an animation that does nothing: it just immediately finishes
8896 // itself every time it is called. It is used as a stub animation in cases
8897 // where we want to synchronize multiple things that may be animating.
8898 static final class DummyAnimation extends Animation {
8899 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8900 return false;
8901 }
8902 }
8903 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 // -------------------------------------------------------------
8906 // Async Handler
8907 // -------------------------------------------------------------
8908
8909 static final class StartingData {
8910 final String pkg;
8911 final int theme;
8912 final CharSequence nonLocalizedLabel;
8913 final int labelRes;
8914 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008915 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008917 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008918 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008919 pkg = _pkg;
8920 theme = _theme;
8921 nonLocalizedLabel = _nonLocalizedLabel;
8922 labelRes = _labelRes;
8923 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008924 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008925 }
8926 }
8927
8928 private final class H extends Handler {
8929 public static final int REPORT_FOCUS_CHANGE = 2;
8930 public static final int REPORT_LOSING_FOCUS = 3;
8931 public static final int ANIMATE = 4;
8932 public static final int ADD_STARTING = 5;
8933 public static final int REMOVE_STARTING = 6;
8934 public static final int FINISHED_STARTING = 7;
8935 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008936 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8937 public static final int HOLD_SCREEN_CHANGED = 12;
8938 public static final int APP_TRANSITION_TIMEOUT = 13;
8939 public static final int PERSIST_ANIMATION_SCALE = 14;
8940 public static final int FORCE_GC = 15;
8941 public static final int ENABLE_SCREEN = 16;
8942 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008943 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008944 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008945 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008946 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08008947 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07008948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008949 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008951 public H() {
8952 }
Romain Guy06882f82009-06-10 13:36:04 -07008953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 @Override
8955 public void handleMessage(Message msg) {
8956 switch (msg.what) {
8957 case REPORT_FOCUS_CHANGE: {
8958 WindowState lastFocus;
8959 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008961 synchronized(mWindowMap) {
8962 lastFocus = mLastFocus;
8963 newFocus = mCurrentFocus;
8964 if (lastFocus == newFocus) {
8965 // Focus is not changing, so nothing to do.
8966 return;
8967 }
8968 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008969 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008970 // + " to " + newFocus);
8971 if (newFocus != null && lastFocus != null
8972 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008973 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008974 mLosingFocus.add(lastFocus);
8975 lastFocus = null;
8976 }
8977 }
8978
8979 if (lastFocus != newFocus) {
8980 //System.out.println("Changing focus from " + lastFocus
8981 // + " to " + newFocus);
8982 if (newFocus != null) {
8983 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008984 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008985 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8986 } catch (RemoteException e) {
8987 // Ignore if process has died.
8988 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008989 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008990 }
8991
8992 if (lastFocus != null) {
8993 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8996 } catch (RemoteException e) {
8997 // Ignore if process has died.
8998 }
8999 }
Joe Onorato664644d2011-01-23 17:53:23 -08009000
9001 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 }
9003 } break;
9004
9005 case REPORT_LOSING_FOCUS: {
9006 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07009007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 synchronized(mWindowMap) {
9009 losers = mLosingFocus;
9010 mLosingFocus = new ArrayList<WindowState>();
9011 }
9012
9013 final int N = losers.size();
9014 for (int i=0; i<N; i++) {
9015 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009016 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009017 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
9018 } catch (RemoteException e) {
9019 // Ignore if process has died.
9020 }
9021 }
9022 } break;
9023
9024 case ANIMATE: {
9025 synchronized(mWindowMap) {
9026 mAnimationPending = false;
9027 performLayoutAndPlaceSurfacesLocked();
9028 }
9029 } break;
9030
9031 case ADD_STARTING: {
9032 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9033 final StartingData sd = wtoken.startingData;
9034
9035 if (sd == null) {
9036 // Animation has been canceled... do nothing.
9037 return;
9038 }
Romain Guy06882f82009-06-10 13:36:04 -07009039
Joe Onorato8a9b2202010-02-26 18:56:32 -08009040 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009041 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07009042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 View view = null;
9044 try {
9045 view = mPolicy.addStartingWindow(
9046 wtoken.token, sd.pkg,
9047 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08009048 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009049 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009050 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009051 }
9052
9053 if (view != null) {
9054 boolean abort = false;
9055
9056 synchronized(mWindowMap) {
9057 if (wtoken.removed || wtoken.startingData == null) {
9058 // If the window was successfully added, then
9059 // we need to remove it.
9060 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009061 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009062 "Aborted starting " + wtoken
9063 + ": removed=" + wtoken.removed
9064 + " startingData=" + wtoken.startingData);
9065 wtoken.startingWindow = null;
9066 wtoken.startingData = null;
9067 abort = true;
9068 }
9069 } else {
9070 wtoken.startingView = view;
9071 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009072 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009073 "Added starting " + wtoken
9074 + ": startingWindow="
9075 + wtoken.startingWindow + " startingView="
9076 + wtoken.startingView);
9077 }
9078
9079 if (abort) {
9080 try {
9081 mPolicy.removeStartingWindow(wtoken.token, view);
9082 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009083 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009084 }
9085 }
9086 }
9087 } break;
9088
9089 case REMOVE_STARTING: {
9090 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9091 IBinder token = null;
9092 View view = null;
9093 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009094 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009095 + wtoken + ": startingWindow="
9096 + wtoken.startingWindow + " startingView="
9097 + wtoken.startingView);
9098 if (wtoken.startingWindow != null) {
9099 view = wtoken.startingView;
9100 token = wtoken.token;
9101 wtoken.startingData = null;
9102 wtoken.startingView = null;
9103 wtoken.startingWindow = null;
9104 }
9105 }
9106 if (view != null) {
9107 try {
9108 mPolicy.removeStartingWindow(token, view);
9109 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009110 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 }
9112 }
9113 } break;
9114
9115 case FINISHED_STARTING: {
9116 IBinder token = null;
9117 View view = null;
9118 while (true) {
9119 synchronized (mWindowMap) {
9120 final int N = mFinishedStarting.size();
9121 if (N <= 0) {
9122 break;
9123 }
9124 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9125
Joe Onorato8a9b2202010-02-26 18:56:32 -08009126 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009127 "Finished starting " + wtoken
9128 + ": startingWindow=" + wtoken.startingWindow
9129 + " startingView=" + wtoken.startingView);
9130
9131 if (wtoken.startingWindow == null) {
9132 continue;
9133 }
9134
9135 view = wtoken.startingView;
9136 token = wtoken.token;
9137 wtoken.startingData = null;
9138 wtoken.startingView = null;
9139 wtoken.startingWindow = null;
9140 }
9141
9142 try {
9143 mPolicy.removeStartingWindow(token, view);
9144 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009145 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009146 }
9147 }
9148 } break;
9149
9150 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9151 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9152
9153 boolean nowVisible = msg.arg1 != 0;
9154 boolean nowGone = msg.arg2 != 0;
9155
9156 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009157 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009158 TAG, "Reporting visible in " + wtoken
9159 + " visible=" + nowVisible
9160 + " gone=" + nowGone);
9161 if (nowVisible) {
9162 wtoken.appToken.windowsVisible();
9163 } else {
9164 wtoken.appToken.windowsGone();
9165 }
9166 } catch (RemoteException ex) {
9167 }
9168 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009170 case WINDOW_FREEZE_TIMEOUT: {
9171 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009172 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009173 int i = mWindows.size();
9174 while (i > 0) {
9175 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009176 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009177 if (w.mOrientationChanging) {
9178 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009179 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009180 }
9181 }
9182 performLayoutAndPlaceSurfacesLocked();
9183 }
9184 break;
9185 }
Romain Guy06882f82009-06-10 13:36:04 -07009186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009187 case HOLD_SCREEN_CHANGED: {
9188 Session oldHold;
9189 Session newHold;
9190 synchronized (mWindowMap) {
9191 oldHold = mLastReportedHold;
9192 newHold = (Session)msg.obj;
9193 mLastReportedHold = newHold;
9194 }
Romain Guy06882f82009-06-10 13:36:04 -07009195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009196 if (oldHold != newHold) {
9197 try {
9198 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009199 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009200 "window",
9201 BatteryStats.WAKE_TYPE_WINDOW);
9202 }
9203 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009204 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 "window",
9206 BatteryStats.WAKE_TYPE_WINDOW);
9207 }
9208 } catch (RemoteException e) {
9209 }
9210 }
9211 break;
9212 }
Romain Guy06882f82009-06-10 13:36:04 -07009213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009214 case APP_TRANSITION_TIMEOUT: {
9215 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009216 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009217 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 "*** APP TRANSITION TIMEOUT");
9219 mAppTransitionReady = true;
9220 mAppTransitionTimeout = true;
9221 performLayoutAndPlaceSurfacesLocked();
9222 }
9223 }
9224 break;
9225 }
Romain Guy06882f82009-06-10 13:36:04 -07009226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009227 case PERSIST_ANIMATION_SCALE: {
9228 Settings.System.putFloat(mContext.getContentResolver(),
9229 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9230 Settings.System.putFloat(mContext.getContentResolver(),
9231 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9232 break;
9233 }
Romain Guy06882f82009-06-10 13:36:04 -07009234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009235 case FORCE_GC: {
9236 synchronized(mWindowMap) {
9237 if (mAnimationPending) {
9238 // If we are animating, don't do the gc now but
9239 // delay a bit so we don't interrupt the animation.
9240 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9241 2000);
9242 return;
9243 }
9244 // If we are currently rotating the display, it will
9245 // schedule a new message when done.
9246 if (mDisplayFrozen) {
9247 return;
9248 }
9249 mFreezeGcPending = 0;
9250 }
9251 Runtime.getRuntime().gc();
9252 break;
9253 }
Romain Guy06882f82009-06-10 13:36:04 -07009254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009255 case ENABLE_SCREEN: {
9256 performEnableScreen();
9257 break;
9258 }
Romain Guy06882f82009-06-10 13:36:04 -07009259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 case APP_FREEZE_TIMEOUT: {
9261 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009262 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009263 int i = mAppTokens.size();
9264 while (i > 0) {
9265 i--;
9266 AppWindowToken tok = mAppTokens.get(i);
9267 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009268 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009269 unsetAppFreezingScreenLocked(tok, true, true);
9270 }
9271 }
9272 }
9273 break;
9274 }
Romain Guy06882f82009-06-10 13:36:04 -07009275
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009276 case SEND_NEW_CONFIGURATION: {
9277 removeMessages(SEND_NEW_CONFIGURATION);
9278 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009279 break;
9280 }
Romain Guy06882f82009-06-10 13:36:04 -07009281
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009282 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009283 if (mWindowsChanged) {
9284 synchronized (mWindowMap) {
9285 mWindowsChanged = false;
9286 }
9287 notifyWindowsChanged();
9288 }
9289 break;
9290 }
9291
Christopher Tatea53146c2010-09-07 11:57:52 -07009292 case DRAG_START_TIMEOUT: {
9293 IBinder win = (IBinder)msg.obj;
9294 if (DEBUG_DRAG) {
9295 Slog.w(TAG, "Timeout starting drag by win " + win);
9296 }
9297 synchronized (mWindowMap) {
9298 // !!! TODO: ANR the app that has failed to start the drag in time
9299 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009300 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009301 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009302 mDragState.reset();
9303 mDragState = null;
9304 }
9305 }
Chris Tated4533f142010-10-19 15:15:08 -07009306 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009307 }
9308
Chris Tated4533f142010-10-19 15:15:08 -07009309 case DRAG_END_TIMEOUT: {
9310 IBinder win = (IBinder)msg.obj;
9311 if (DEBUG_DRAG) {
9312 Slog.w(TAG, "Timeout ending drag to win " + win);
9313 }
9314 synchronized (mWindowMap) {
9315 // !!! TODO: ANR the drag-receiving app
9316 mDragState.mDragResult = false;
9317 mDragState.endDragLw();
9318 }
9319 break;
9320 }
Jeff Brown2992ea72011-01-28 22:04:14 -08009321
9322 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
9323 notifyHardKeyboardStatusChange();
9324 break;
9325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009326 }
9327 }
9328 }
9329
9330 // -------------------------------------------------------------
9331 // IWindowManager API
9332 // -------------------------------------------------------------
9333
9334 public IWindowSession openSession(IInputMethodClient client,
9335 IInputContext inputContext) {
9336 if (client == null) throw new IllegalArgumentException("null client");
9337 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009338 Session session = new Session(client, inputContext);
9339 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009340 }
9341
9342 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9343 synchronized (mWindowMap) {
9344 // The focus for the client is the window immediately below
9345 // where we would place the input method window.
9346 int idx = findDesiredInputMethodWindowIndexLocked(false);
9347 WindowState imFocus;
9348 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009349 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009350 //Log.i(TAG, "Desired input method target: " + imFocus);
9351 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9352 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009353 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009354 // This may be a starting window, in which case we still want
9355 // to count it as okay.
9356 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9357 && imFocus.mAppToken != null) {
9358 // The client has definitely started, so it really should
9359 // have a window in this app token. Let's look for it.
9360 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9361 WindowState w = imFocus.mAppToken.windows.get(i);
9362 if (w != imFocus) {
9363 //Log.i(TAG, "Switching to real app window: " + w);
9364 imFocus = w;
9365 break;
9366 }
9367 }
9368 }
9369 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9370 //if (imFocus.mSession.mClient != null) {
9371 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9372 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9373 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374 if (imFocus.mSession.mClient != null &&
9375 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9376 return true;
9377 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009378
9379 // Okay, how about this... what is the current focus?
9380 // It seems in some cases we may not have moved the IM
9381 // target window, such as when it was in a pop-up window,
9382 // so let's also look at the current focus. (An example:
9383 // go to Gmail, start searching so the keyboard goes up,
9384 // press home. Sometimes the IME won't go down.)
9385 // Would be nice to fix this more correctly, but it's
9386 // way at the end of a release, and this should be good enough.
9387 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9388 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9389 return true;
9390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009391 }
9392 }
9393 }
9394 return false;
9395 }
Romain Guy06882f82009-06-10 13:36:04 -07009396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009397 // -------------------------------------------------------------
9398 // Internals
9399 // -------------------------------------------------------------
9400
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009401 final WindowState windowForClientLocked(Session session, IWindow client,
9402 boolean throwOnError) {
9403 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 }
Romain Guy06882f82009-06-10 13:36:04 -07009405
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009406 final WindowState windowForClientLocked(Session session, IBinder client,
9407 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009408 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009409 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 TAG, "Looking up client " + client + ": " + win);
9411 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009412 RuntimeException ex = new IllegalArgumentException(
9413 "Requested window " + client + " does not exist");
9414 if (throwOnError) {
9415 throw ex;
9416 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009417 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009418 return null;
9419 }
9420 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009421 RuntimeException ex = new IllegalArgumentException(
9422 "Requested window " + client + " is in session " +
9423 win.mSession + ", not " + session);
9424 if (throwOnError) {
9425 throw ex;
9426 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009427 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009428 return null;
9429 }
9430
9431 return win;
9432 }
9433
Dianne Hackborna8f60182009-09-01 19:01:50 -07009434 final void rebuildAppWindowListLocked() {
9435 int NW = mWindows.size();
9436 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009437 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009438 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009439
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009440 if (mRebuildTmp.length < NW) {
9441 mRebuildTmp = new WindowState[NW+10];
9442 }
9443
Dianne Hackborna8f60182009-09-01 19:01:50 -07009444 // First remove all existing app windows.
9445 i=0;
9446 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009447 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009448 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009449 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009450 win.mRebuilding = true;
9451 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009452 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009453 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009454 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009455 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009456 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009457 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009458 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9459 && lastWallpaper == i-1) {
9460 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009461 }
9462 i++;
9463 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009464
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009465 // The wallpaper window(s) typically live at the bottom of the stack,
9466 // so skip them before adding app tokens.
9467 lastWallpaper++;
9468 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009469
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009470 // First add all of the exiting app tokens... these are no longer
9471 // in the main app list, but still have windows shown. We put them
9472 // in the back because now that the animation is over we no longer
9473 // will care about them.
9474 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009475 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009476 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9477 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009478
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009479 // And add in the still active app tokens in Z order.
9480 NT = mAppTokens.size();
9481 for (int j=0; j<NT; j++) {
9482 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009484
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009485 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009486 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009487 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009488 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009489 for (i=0; i<numRemoved; i++) {
9490 WindowState ws = mRebuildTmp[i];
9491 if (ws.mRebuilding) {
9492 StringWriter sw = new StringWriter();
9493 PrintWriter pw = new PrintWriter(sw);
9494 ws.dump(pw, "");
9495 pw.flush();
9496 Slog.w(TAG, "This window was lost: " + ws);
9497 Slog.w(TAG, sw.toString());
9498 }
9499 }
9500 Slog.w(TAG, "Current app token list:");
9501 dumpAppTokensLocked();
9502 Slog.w(TAG, "Final window list:");
9503 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009504 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009505 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507 private final void assignLayersLocked() {
9508 int N = mWindows.size();
9509 int curBaseLayer = 0;
9510 int curLayer = 0;
9511 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009512
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009513 if (DEBUG_LAYERS) {
9514 RuntimeException here = new RuntimeException("here");
9515 here.fillInStackTrace();
9516 Log.v(TAG, "Assigning layers", here);
9517 }
9518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009520 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009521 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9522 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 curLayer += WINDOW_LAYER_MULTIPLIER;
9524 w.mLayer = curLayer;
9525 } else {
9526 curBaseLayer = curLayer = w.mBaseLayer;
9527 w.mLayer = curLayer;
9528 }
9529 if (w.mTargetAppToken != null) {
9530 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9531 } else if (w.mAppToken != null) {
9532 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9533 } else {
9534 w.mAnimLayer = w.mLayer;
9535 }
9536 if (w.mIsImWindow) {
9537 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009538 } else if (w.mIsWallpaper) {
9539 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009540 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009541 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009542 + w.mAnimLayer);
9543 //System.out.println(
9544 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9545 }
9546 }
9547
9548 private boolean mInLayout = false;
9549 private final void performLayoutAndPlaceSurfacesLocked() {
9550 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009551 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 throw new RuntimeException("Recursive call!");
9553 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009554 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009555 return;
9556 }
9557
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009558 if (mWaitingForConfig) {
9559 // Our configuration has changed (most likely rotation), but we
9560 // don't yet have the complete configuration to report to
9561 // applications. Don't do any window layout until we have it.
9562 return;
9563 }
9564
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009565 if (mDisplay == null) {
9566 // Not yet initialized, nothing to do.
9567 return;
9568 }
9569
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009570 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009571 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009572
9573 try {
9574 if (mForceRemoves != null) {
9575 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009576 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009577 for (int i=0; i<mForceRemoves.size(); i++) {
9578 WindowState ws = mForceRemoves.get(i);
9579 Slog.i(TAG, "Force removing: " + ws);
9580 removeWindowInnerLocked(ws.mSession, ws);
9581 }
9582 mForceRemoves = null;
9583 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9584 Object tmp = new Object();
9585 synchronized (tmp) {
9586 try {
9587 tmp.wait(250);
9588 } catch (InterruptedException e) {
9589 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009590 }
9591 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009592 } catch (RuntimeException e) {
9593 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596 try {
9597 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009598
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009599 int N = mPendingRemove.size();
9600 if (N > 0) {
9601 if (mPendingRemoveTmp.length < N) {
9602 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009604 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009606 for (int i=0; i<N; i++) {
9607 WindowState w = mPendingRemoveTmp[i];
9608 removeWindowInnerLocked(w.mSession, w);
9609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009610
9611 mInLayout = false;
9612 assignLayersLocked();
9613 mLayoutNeeded = true;
9614 performLayoutAndPlaceSurfacesLocked();
9615
9616 } else {
9617 mInLayout = false;
9618 if (mLayoutNeeded) {
9619 requestAnimationLocked(0);
9620 }
9621 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009622 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009623 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9624 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009625 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009626 } catch (RuntimeException e) {
9627 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009628 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009629 }
9630 }
9631
Jeff Brown3a22cd92011-01-21 13:59:04 -08009632 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009633 if (!mLayoutNeeded) {
9634 return 0;
9635 }
9636
9637 mLayoutNeeded = false;
9638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009639 final int dw = mDisplay.getWidth();
9640 final int dh = mDisplay.getHeight();
9641
9642 final int N = mWindows.size();
9643 int i;
9644
Joe Onorato8a9b2202010-02-26 18:56:32 -08009645 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009646 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9647
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009648 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009649
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009650 int seq = mLayoutSeq+1;
9651 if (seq < 0) seq = 0;
9652 mLayoutSeq = seq;
9653
9654 // First perform layout of any root windows (not attached
9655 // to another window).
9656 int topAttached = -1;
9657 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009658 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009660 // Don't do layout of a window if it is not visible, or
9661 // soon won't be visible, to avoid wasting time and funky
9662 // changes while a window is animating away.
9663 final AppWindowToken atoken = win.mAppToken;
9664 final boolean gone = win.mViewVisibility == View.GONE
9665 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009666 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009667 || (atoken != null && atoken.hiddenRequested)
9668 || win.mAttachedHidden
9669 || win.mExiting || win.mDestroying;
9670
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009671 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9672 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009673 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9674 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009675 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009676 + win.mViewVisibility + " mRelayoutCalled="
9677 + win.mRelayoutCalled + " hidden="
9678 + win.mRootToken.hidden + " hiddenRequested="
9679 + (atoken != null && atoken.hiddenRequested)
9680 + " mAttachedHidden=" + win.mAttachedHidden);
9681 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009682
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009683 // If this view is GONE, then skip it -- keep the current
9684 // frame, and let the caller know so they can ignore it
9685 // if they want. (We do the normal layout for INVISIBLE
9686 // windows, since that means "perform layout as normal,
9687 // just don't display").
9688 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009689 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009690 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009691 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009692 win.mContentChanged = false;
9693 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009694 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9695 win.mLayoutSeq = seq;
9696 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9697 + win.mFrame + " mContainingFrame="
9698 + win.mContainingFrame + " mDisplayFrame="
9699 + win.mDisplayFrame);
9700 } else {
9701 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009702 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009704 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009705
9706 // Now perform layout of attached windows, which usually
9707 // depend on the position of the window they are attached to.
9708 // XXX does not deal with windows that are attached to windows
9709 // that are themselves attached.
9710 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009711 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009712
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009713 if (win.mLayoutAttached) {
9714 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9715 + " mHaveFrame=" + win.mHaveFrame
9716 + " mViewVisibility=" + win.mViewVisibility
9717 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009718 // If this view is GONE, then skip it -- keep the current
9719 // frame, and let the caller know so they can ignore it
9720 // if they want. (We do the normal layout for INVISIBLE
9721 // windows, since that means "perform layout as normal,
9722 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009723 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9724 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009725 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009726 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009727 win.mContentChanged = false;
9728 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009729 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9730 win.mLayoutSeq = seq;
9731 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9732 + win.mFrame + " mContainingFrame="
9733 + win.mContainingFrame + " mDisplayFrame="
9734 + win.mDisplayFrame);
9735 }
9736 }
9737 }
Jeff Brown349703e2010-06-22 01:27:15 -07009738
9739 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009740 mInputMonitor.setUpdateInputWindowsNeededLw();
9741 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009742 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009743 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009744
9745 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 }
Romain Guy06882f82009-06-10 13:36:04 -07009747
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009748 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009749 private final void performLayoutAndPlaceSurfacesLockedInner(
9750 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009751 if (mDisplay == null) {
9752 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9753 return;
9754 }
9755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009756 final long currentTime = SystemClock.uptimeMillis();
9757 final int dw = mDisplay.getWidth();
9758 final int dh = mDisplay.getHeight();
9759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009760 int i;
9761
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009762 if (mFocusMayChange) {
9763 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009764 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9765 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009766 }
9767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009768 // Initialize state of exiting tokens.
9769 for (i=mExitingTokens.size()-1; i>=0; i--) {
9770 mExitingTokens.get(i).hasVisible = false;
9771 }
9772
9773 // Initialize state of exiting applications.
9774 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9775 mExitingAppTokens.get(i).hasVisible = false;
9776 }
9777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009778 boolean orientationChangeComplete = true;
9779 Session holdScreen = null;
9780 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009781 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 boolean focusDisplayed = false;
9783 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009784 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009785 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009786
9787 if (mFxSession == null) {
9788 mFxSession = new SurfaceSession();
9789 createWatermark = true;
9790 }
9791
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009792 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009793
9794 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009795
9796 if (createWatermark) {
9797 createWatermark();
9798 }
9799 if (mWatermark != null) {
9800 mWatermark.positionSurface(dw, dh);
9801 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009802 if (mStrictModeFlash != null) {
9803 mStrictModeFlash.positionSurface(dw, dh);
9804 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009807 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009808 int repeats = 0;
9809 int changes = 0;
9810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009812 repeats++;
9813 if (repeats > 6) {
9814 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9815 mLayoutNeeded = false;
9816 break;
9817 }
9818
9819 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9820 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9821 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9822 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9823 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9824 assignLayersLocked();
9825 mLayoutNeeded = true;
9826 }
9827 }
9828 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9829 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009830 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009831 mLayoutNeeded = true;
9832 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9833 }
9834 }
9835 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9836 mLayoutNeeded = true;
9837 }
9838 }
9839
9840 // FIRST LOOP: Perform a layout, if needed.
9841 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009842 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009843 if (changes != 0) {
9844 continue;
9845 }
9846 } else {
9847 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9848 changes = 0;
9849 }
9850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 final int transactionSequence = ++mTransactionSequence;
9852
9853 // Update animations of all applications, including those
9854 // associated with exiting/removed apps
9855 boolean tokensAnimating = false;
9856 final int NAT = mAppTokens.size();
9857 for (i=0; i<NAT; i++) {
9858 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9859 tokensAnimating = true;
9860 }
9861 }
9862 final int NEAT = mExitingAppTokens.size();
9863 for (i=0; i<NEAT; i++) {
9864 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9865 tokensAnimating = true;
9866 }
9867 }
9868
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009869 // SECOND LOOP: Execute animations and update visibility of windows.
9870
Joe Onorato8a9b2202010-02-26 18:56:32 -08009871 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009872 + transactionSequence + " tokensAnimating="
9873 + tokensAnimating);
9874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009875 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009877 if (mScreenRotationAnimation != null) {
9878 if (mScreenRotationAnimation.isAnimating()) {
9879 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9880 animating = true;
9881 } else {
9882 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009883 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009884 }
9885 }
9886 }
9887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009888 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009889 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009890 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009891 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892
9893 mPolicy.beginAnimationLw(dw, dh);
9894
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009895 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009897 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009898 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899
9900 final WindowManager.LayoutParams attrs = w.mAttrs;
9901
9902 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009903 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009904 if (w.commitFinishDrawingLocked(currentTime)) {
9905 if ((w.mAttrs.flags
9906 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009907 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009908 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009909 wallpaperMayChange = true;
9910 }
9911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009912
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009913 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009914
9915 int animDw = dw;
9916 int animDh = dh;
9917
9918 // If the window has moved due to its containing
9919 // content frame changing, then we'd like to animate
9920 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009921 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009922 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009923 // Frame has moved, containing content frame
9924 // has also moved, and we're not currently animating...
9925 // let's do something.
9926 Animation a = AnimationUtils.loadAnimation(mContext,
9927 com.android.internal.R.anim.window_move_from_decor);
9928 w.setAnimation(a);
9929 animDw = w.mLastFrame.left - w.mFrame.left;
9930 animDh = w.mLastFrame.top - w.mFrame.top;
9931 }
9932
9933 // Execute animation.
9934 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9935 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009936
9937 // If this window is animating, make a note that we have
9938 // an animating window and take care of a request to run
9939 // a detached wallpaper animation.
9940 if (nowAnimating) {
9941 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9942 windowDetachedWallpaper = w;
9943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009945 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009946
9947 // If this window's app token is running a detached wallpaper
9948 // animation, make a note so we can ensure the wallpaper is
9949 // displayed behind it.
9950 if (w.mAppToken != null && w.mAppToken.animation != null
9951 && w.mAppToken.animation.getDetachWallpaper()) {
9952 windowDetachedWallpaper = w;
9953 }
9954
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009955 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9956 wallpaperMayChange = true;
9957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009958
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009959 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009960 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009961 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009962 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009963 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009964 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009965 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009966 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9967 forceHiding = true;
9968 }
9969 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9970 boolean changed;
9971 if (forceHiding) {
9972 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009973 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9974 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009975 } else {
9976 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009977 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9978 "Now policy shown: " + w);
9979 if (changed) {
9980 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009981 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009982 // Assume we will need to animate. If
9983 // we don't (because the wallpaper will
9984 // stay with the lock screen), then we will
9985 // clean up later.
9986 Animation a = mPolicy.createForceHideEnterAnimation();
9987 if (a != null) {
9988 w.setAnimation(a);
9989 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009990 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009991 if (mCurrentFocus == null ||
9992 mCurrentFocus.mLayer < w.mLayer) {
9993 // We are showing on to of the current
9994 // focus, so re-evaluate focus to make
9995 // sure it is correct.
9996 mFocusMayChange = true;
9997 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009998 }
9999 }
10000 if (changed && (attrs.flags
10001 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
10002 wallpaperMayChange = true;
10003 }
10004 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 mPolicy.animatingWindowLw(w, attrs);
10007 }
10008
10009 final AppWindowToken atoken = w.mAppToken;
10010 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
10011 if (atoken.lastTransactionSequence != transactionSequence) {
10012 atoken.lastTransactionSequence = transactionSequence;
10013 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
10014 atoken.startingDisplayed = false;
10015 }
10016 if ((w.isOnScreen() || w.mAttrs.type
10017 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
10018 && !w.mExiting && !w.mDestroying) {
10019 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010020 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010021 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010022 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010023 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010024 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 + " pv=" + w.mPolicyVisibility
10026 + " dp=" + w.mDrawPending
10027 + " cdp=" + w.mCommitDrawPending
10028 + " ah=" + w.mAttachedHidden
10029 + " th=" + atoken.hiddenRequested
10030 + " a=" + w.mAnimating);
10031 }
10032 }
10033 if (w != atoken.startingWindow) {
10034 if (!atoken.freezingScreen || !w.mAppFreezing) {
10035 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010036 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010037 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010038 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010039 "tokenMayBeDrawn: " + atoken
10040 + " freezingScreen=" + atoken.freezingScreen
10041 + " mAppFreezing=" + w.mAppFreezing);
10042 tokenMayBeDrawn = true;
10043 }
10044 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010045 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 atoken.startingDisplayed = true;
10047 }
10048 }
10049 } else if (w.mReadyToShow) {
10050 w.performShowLocked();
10051 }
10052 }
10053
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010054 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055
10056 if (tokenMayBeDrawn) {
10057 // See if any windows have been drawn, so they (and others
10058 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010059 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010060 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010061 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010062 if (wtoken.freezingScreen) {
10063 int numInteresting = wtoken.numInterestingWindows;
10064 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010065 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010066 "allDrawn: " + wtoken
10067 + " interesting=" + numInteresting
10068 + " drawn=" + wtoken.numDrawnWindows);
10069 wtoken.showAllWindowsLocked();
10070 unsetAppFreezingScreenLocked(wtoken, false, true);
10071 orientationChangeComplete = true;
10072 }
10073 } else if (!wtoken.allDrawn) {
10074 int numInteresting = wtoken.numInterestingWindows;
10075 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010076 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010077 "allDrawn: " + wtoken
10078 + " interesting=" + numInteresting
10079 + " drawn=" + wtoken.numDrawnWindows);
10080 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010081 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010082
10083 // We can now show all of the drawn windows!
10084 if (!mOpeningApps.contains(wtoken)) {
10085 wtoken.showAllWindowsLocked();
10086 }
10087 }
10088 }
10089 }
10090 }
10091
10092 // If we are ready to perform an app transition, check through
10093 // all of the app tokens to be shown and see if they are ready
10094 // to go.
10095 if (mAppTransitionReady) {
10096 int NN = mOpeningApps.size();
10097 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010098 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010099 "Checking " + NN + " opening apps (frozen="
10100 + mDisplayFrozen + " timeout="
10101 + mAppTransitionTimeout + ")...");
10102 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10103 // If the display isn't frozen, wait to do anything until
10104 // all of the apps are ready. Otherwise just go because
10105 // we'll unfreeze the display when everyone is ready.
10106 for (i=0; i<NN && goodToGo; i++) {
10107 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010108 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010109 "Check opening app" + wtoken + ": allDrawn="
10110 + wtoken.allDrawn + " startingDisplayed="
10111 + wtoken.startingDisplayed);
10112 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10113 && !wtoken.startingMoved) {
10114 goodToGo = false;
10115 }
10116 }
10117 }
10118 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010119 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010120 int transit = mNextAppTransition;
10121 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010122 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010124 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010125 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010126 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010127 mAppTransitionTimeout = false;
10128 mStartingIconInTransition = false;
10129 mSkipAppTransitionAnimation = false;
10130
10131 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10132
Dianne Hackborna8f60182009-09-01 19:01:50 -070010133 // If there are applications waiting to come to the
10134 // top of the stack, now is the time to move their windows.
10135 // (Note that we don't do apps going to the bottom
10136 // here -- we want to keep their windows in the old
10137 // Z-order until the animation completes.)
10138 if (mToTopApps.size() > 0) {
10139 NN = mAppTokens.size();
10140 for (i=0; i<NN; i++) {
10141 AppWindowToken wtoken = mAppTokens.get(i);
10142 if (wtoken.sendingToTop) {
10143 wtoken.sendingToTop = false;
10144 moveAppWindowsLocked(wtoken, NN, false);
10145 }
10146 }
10147 mToTopApps.clear();
10148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010149
Dianne Hackborn25994b42009-09-04 14:21:19 -070010150 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010151
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010152 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010153 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010154
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010155 // The top-most window will supply the layout params,
10156 // and we will determine it below.
10157 LayoutParams animLp = null;
10158 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010159 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010160
Joe Onorato8a9b2202010-02-26 18:56:32 -080010161 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010162 "New wallpaper target=" + mWallpaperTarget
10163 + ", lower target=" + mLowerWallpaperTarget
10164 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010165 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010166 // Do a first pass through the tokens for two
10167 // things:
10168 // (1) Determine if both the closing and opening
10169 // app token sets are wallpaper targets, in which
10170 // case special animations are needed
10171 // (since the wallpaper needs to stay static
10172 // behind them).
10173 // (2) Find the layout params of the top-most
10174 // application window in the tokens, which is
10175 // what will control the animation theme.
10176 final int NC = mClosingApps.size();
10177 NN = NC + mOpeningApps.size();
10178 for (i=0; i<NN; i++) {
10179 AppWindowToken wtoken;
10180 int mode;
10181 if (i < NC) {
10182 wtoken = mClosingApps.get(i);
10183 mode = 1;
10184 } else {
10185 wtoken = mOpeningApps.get(i-NC);
10186 mode = 2;
10187 }
10188 if (mLowerWallpaperTarget != null) {
10189 if (mLowerWallpaperTarget.mAppToken == wtoken
10190 || mUpperWallpaperTarget.mAppToken == wtoken) {
10191 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010192 }
10193 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010194 if (wtoken.appFullscreen) {
10195 WindowState ws = wtoken.findMainWindow();
10196 if (ws != null) {
10197 // If this is a compatibility mode
10198 // window, we will always use its anim.
10199 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10200 animLp = ws.mAttrs;
10201 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010202 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010203 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010204 bestAnimLayer = ws.mLayer;
10205 }
10206 fullscreenAnim = true;
10207 }
10208 } else if (!fullscreenAnim) {
10209 WindowState ws = wtoken.findMainWindow();
10210 if (ws != null) {
10211 if (ws.mLayer > bestAnimLayer) {
10212 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010213 bestAnimLayer = ws.mLayer;
10214 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010215 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010216 }
10217 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010218
Dianne Hackborn25994b42009-09-04 14:21:19 -070010219 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010220 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010221 "Wallpaper animation!");
10222 switch (transit) {
10223 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10224 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10225 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10226 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10227 break;
10228 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10229 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10230 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10231 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10232 break;
10233 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010234 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010235 "New transit: " + transit);
10236 } else if (oldWallpaper != null) {
10237 // We are transitioning from an activity with
10238 // a wallpaper to one without.
10239 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010240 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010241 "New transit away from wallpaper: " + transit);
10242 } else if (mWallpaperTarget != null) {
10243 // We are transitioning from an activity without
10244 // a wallpaper to now showing the wallpaper
10245 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010246 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010247 "New transit into wallpaper: " + transit);
10248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010249
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010250 // If all closing windows are obscured, then there is
10251 // no need to do an animation. This is the case, for
10252 // example, when this transition is being done behind
10253 // the lock screen.
10254 if (!mPolicy.allowAppAnimationsLw()) {
10255 animLp = null;
10256 }
10257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010258 NN = mOpeningApps.size();
10259 for (i=0; i<NN; i++) {
10260 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010261 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010262 "Now opening app" + wtoken);
10263 wtoken.reportedVisible = false;
10264 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010265 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010266 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010267 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010268 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 wtoken.showAllWindowsLocked();
10270 }
10271 NN = mClosingApps.size();
10272 for (i=0; i<NN; i++) {
10273 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010274 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275 "Now closing app" + wtoken);
10276 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010277 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010278 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010280 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010281 // Force the allDrawn flag, because we want to start
10282 // this guy's animations regardless of whether it's
10283 // gotten drawn.
10284 wtoken.allDrawn = true;
10285 }
10286
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010287 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 mOpeningApps.clear();
10290 mClosingApps.clear();
10291
10292 // This has changed the visibility of windows, so perform
10293 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010294 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10295 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010296 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010297 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10298 assignLayersLocked();
10299 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010300 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10301 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010302 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010303 }
10304 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010305
Dianne Hackborn16064f92010-03-25 00:47:24 -070010306 int adjResult = 0;
10307
Dianne Hackborna8f60182009-09-01 19:01:50 -070010308 if (!animating && mAppTransitionRunning) {
10309 // We have finished the animation of an app transition. To do
10310 // this, we have delayed a lot of operations like showing and
10311 // hiding apps, moving apps in Z-order, etc. The app token list
10312 // reflects the correct Z-order, but the window list may now
10313 // be out of sync with it. So here we will just rebuild the
10314 // entire app window list. Fun!
10315 mAppTransitionRunning = false;
10316 // Clear information about apps that were moving.
10317 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010318
Dianne Hackborna8f60182009-09-01 19:01:50 -070010319 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010320 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010321 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010322 moveInputMethodWindowsIfNeededLocked(false);
10323 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010324 // Since the window list has been rebuilt, focus might
10325 // have to be recomputed since the actual order of windows
10326 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010327 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010328 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010329
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010330 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010331 // At this point, there was a window with a wallpaper that
10332 // was force hiding other windows behind it, but now it
10333 // is going away. This may be simple -- just animate
10334 // away the wallpaper and its window -- or it may be
10335 // hard -- the wallpaper now needs to be shown behind
10336 // something that was hidden.
10337 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010338 if (mLowerWallpaperTarget != null
10339 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010340 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010341 "wallpaperForceHiding changed with lower="
10342 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010343 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010344 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10345 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10346 if (mLowerWallpaperTarget.mAppToken.hidden) {
10347 // The lower target has become hidden before we
10348 // actually started the animation... let's completely
10349 // re-evaluate everything.
10350 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010351 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010352 }
10353 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010354 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010355 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010356 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010357 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010358 + " NEW: " + mWallpaperTarget
10359 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010360 if (mLowerWallpaperTarget == null) {
10361 // Whoops, we don't need a special wallpaper animation.
10362 // Clear them out.
10363 forceHiding = false;
10364 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010365 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010366 if (w.mSurface != null) {
10367 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010368 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010369 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010370 forceHiding = true;
10371 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10372 if (!w.mAnimating) {
10373 // We set the animation above so it
10374 // is not yet running.
10375 w.clearAnimation();
10376 }
10377 }
10378 }
10379 }
10380 }
10381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010382
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010383 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10384 if (DEBUG_WALLPAPER) Slog.v(TAG,
10385 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10386 + windowDetachedWallpaper);
10387 mWindowDetachedWallpaper = windowDetachedWallpaper;
10388 wallpaperMayChange = true;
10389 }
10390
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010391 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010392 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010393 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010394 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010395 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010396
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010397 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010398 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010399 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010400 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010401 assignLayersLocked();
10402 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010403 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010404 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010405 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010406 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010407
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010408 if (mFocusMayChange) {
10409 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010410 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10411 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010412 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010413 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010414 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010415 }
10416
10417 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010418 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010419 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010420
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010421 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10422 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010423 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010424
10425 // THIRD LOOP: Update the surfaces of all windows.
10426
10427 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10428
10429 boolean obscured = false;
10430 boolean blurring = false;
10431 boolean dimming = false;
10432 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010433 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010434 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010436 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010438 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010439 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010440
10441 boolean displayed = false;
10442 final WindowManager.LayoutParams attrs = w.mAttrs;
10443 final int attrFlags = attrs.flags;
10444
10445 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010446 // XXX NOTE: The logic here could be improved. We have
10447 // the decision about whether to resize a window separated
10448 // from whether to hide the surface. This can cause us to
10449 // resize a surface even if we are going to hide it. You
10450 // can see this by (1) holding device in landscape mode on
10451 // home screen; (2) tapping browser icon (device will rotate
10452 // to landscape; (3) tap home. The wallpaper will be resized
10453 // in step 2 but then immediately hidden, causing us to
10454 // have to resize and then redraw it again in step 3. It
10455 // would be nice to figure out how to avoid this, but it is
10456 // difficult because we do need to resize surfaces in some
10457 // cases while they are hidden such as when first showing a
10458 // window.
10459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010461 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010462 TAG, "Placing surface #" + i + " " + w.mSurface
10463 + ": new=" + w.mShownFrame + ", old="
10464 + w.mLastShownFrame);
10465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 int width, height;
10467 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 // for a scaled surface, we just want to use
10469 // the requested size.
10470 width = w.mRequestedWidth;
10471 height = w.mRequestedHeight;
10472 w.mLastRequestedWidth = width;
10473 w.mLastRequestedHeight = height;
10474 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010476 width = w.mShownFrame.width();
10477 height = w.mShownFrame.height();
10478 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010479 }
10480
Jeff Brownfbae7222011-01-23 13:07:25 -080010481 if (w.mSurface != null) {
10482 if (w.mSurfaceX != w.mShownFrame.left
10483 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010484 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010485 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010486 "POS " + w.mShownFrame.left
10487 + ", " + w.mShownFrame.top, null);
10488 w.mSurfaceX = w.mShownFrame.left;
10489 w.mSurfaceY = w.mShownFrame.top;
10490 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10491 } catch (RuntimeException e) {
10492 Slog.w(TAG, "Error positioning surface of " + w
10493 + " pos=(" + w.mShownFrame.left
10494 + "," + w.mShownFrame.top + ")", e);
10495 if (!recoveringMemory) {
10496 reclaimSomeSurfaceMemoryLocked(w, "position");
10497 }
10498 }
10499 }
10500
10501 if (width < 1) {
10502 width = 1;
10503 }
10504 if (height < 1) {
10505 height = 1;
10506 }
10507
10508 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10509 try {
10510 if (SHOW_TRANSACTIONS) logSurface(w,
10511 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010512 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010513 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010514 w.mSurfaceW = width;
10515 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010517 } catch (RuntimeException e) {
10518 // If something goes wrong with the surface (such
10519 // as running out of memory), don't take down the
10520 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010521 Slog.e(TAG, "Error resizing surface of " + w
10522 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010523 if (!recoveringMemory) {
10524 reclaimSomeSurfaceMemoryLocked(w, "size");
10525 }
10526 }
10527 }
10528 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010529
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010530 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 w.mContentInsetsChanged =
10532 !w.mLastContentInsets.equals(w.mContentInsets);
10533 w.mVisibleInsetsChanged =
10534 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010535 boolean configChanged =
10536 w.mConfiguration != mCurConfiguration
10537 && (w.mConfiguration == null
10538 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010539 if (DEBUG_CONFIGURATION && configChanged) {
10540 Slog.v(TAG, "Win " + w + " config changed: "
10541 + mCurConfiguration);
10542 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010543 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010544 + ": configChanged=" + configChanged
10545 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010546 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10547 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010549 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010550 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010551 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010552 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10553 Slog.v(TAG, "Resize reasons: "
10554 + "frameChanged=" + frameChanged
10555 + " contentInsetsChanged=" + w.mContentInsetsChanged
10556 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10557 + " surfaceResized=" + w.mSurfaceResized
10558 + " configChanged=" + configChanged);
10559 }
10560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010561 w.mLastFrame.set(w.mFrame);
10562 w.mLastContentInsets.set(w.mContentInsets);
10563 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010564 // If the screen is currently frozen, then keep
10565 // it frozen until this window draws at its new
10566 // orientation.
10567 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010568 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010569 "Resizing while display frozen: " + w);
10570 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010571 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010572 mWindowsFreezingScreen = true;
10573 // XXX should probably keep timeout from
10574 // when we first froze the display.
10575 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10576 mH.sendMessageDelayed(mH.obtainMessage(
10577 H.WINDOW_FREEZE_TIMEOUT), 2000);
10578 }
10579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 // If the orientation is changing, then we need to
10581 // hold off on unfreezing the display until this
10582 // window has been redrawn; to do that, we need
10583 // to go through the process of getting informed
10584 // by the application when it has finished drawing.
10585 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010586 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010587 "Orientation start waiting for draw in "
10588 + w + ", surface " + w.mSurface);
10589 w.mDrawPending = true;
10590 w.mCommitDrawPending = false;
10591 w.mReadyToShow = false;
10592 if (w.mAppToken != null) {
10593 w.mAppToken.allDrawn = false;
10594 }
10595 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010596 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010597 "Resizing window " + w + " to " + w.mFrame);
10598 mResizingWindows.add(w);
10599 } else if (w.mOrientationChanging) {
10600 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010601 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010602 "Orientation not waiting for draw in "
10603 + w + ", surface " + w.mSurface);
10604 w.mOrientationChanging = false;
10605 }
10606 }
10607 }
10608
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010609 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010610 if (!w.mLastHidden) {
10611 //dump();
10612 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010613 if (SHOW_TRANSACTIONS) logSurface(w,
10614 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010615 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010616 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010617 try {
10618 w.mSurface.hide();
10619 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010620 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010621 }
10622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010623 }
10624 // If we are waiting for this window to handle an
10625 // orientation change, well, it is hidden, so
10626 // doesn't really matter. Note that this does
10627 // introduce a potential glitch if the window
10628 // becomes unhidden before it has drawn for the
10629 // new orientation.
10630 if (w.mOrientationChanging) {
10631 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010632 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010633 "Orientation change skips hidden " + w);
10634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010635 } else if (w.mLastLayer != w.mAnimLayer
10636 || w.mLastAlpha != w.mShownAlpha
10637 || w.mLastDsDx != w.mDsDx
10638 || w.mLastDtDx != w.mDtDx
10639 || w.mLastDsDy != w.mDsDy
10640 || w.mLastDtDy != w.mDtDy
10641 || w.mLastHScale != w.mHScale
10642 || w.mLastVScale != w.mVScale
10643 || w.mLastHidden) {
10644 displayed = true;
10645 w.mLastAlpha = w.mShownAlpha;
10646 w.mLastLayer = w.mAnimLayer;
10647 w.mLastDsDx = w.mDsDx;
10648 w.mLastDtDx = w.mDtDx;
10649 w.mLastDsDy = w.mDsDy;
10650 w.mLastDtDy = w.mDtDy;
10651 w.mLastHScale = w.mHScale;
10652 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010653 if (SHOW_TRANSACTIONS) logSurface(w,
10654 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010655 + " matrix=[" + (w.mDsDx*w.mHScale)
10656 + "," + (w.mDtDx*w.mVScale)
10657 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010658 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 if (w.mSurface != null) {
10660 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010661 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010662 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010663 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 w.mSurface.setLayer(w.mAnimLayer);
10665 w.mSurface.setMatrix(
10666 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10667 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10668 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010669 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 if (!recoveringMemory) {
10671 reclaimSomeSurfaceMemoryLocked(w, "update");
10672 }
10673 }
10674 }
10675
10676 if (w.mLastHidden && !w.mDrawPending
10677 && !w.mCommitDrawPending
10678 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010679 if (SHOW_TRANSACTIONS) logSurface(w,
10680 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010681 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010682 + " during relayout");
10683 if (showSurfaceRobustlyLocked(w)) {
10684 w.mHasDrawn = true;
10685 w.mLastHidden = false;
10686 } else {
10687 w.mOrientationChanging = false;
10688 }
10689 }
10690 if (w.mSurface != null) {
10691 w.mToken.hasVisible = true;
10692 }
10693 } else {
10694 displayed = true;
10695 }
10696
10697 if (displayed) {
10698 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010699 if (attrs.width == LayoutParams.MATCH_PARENT
10700 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010701 covered = true;
10702 }
10703 }
10704 if (w.mOrientationChanging) {
10705 if (w.mDrawPending || w.mCommitDrawPending) {
10706 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010707 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010708 "Orientation continue waiting for draw in " + w);
10709 } else {
10710 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010711 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010712 "Orientation change complete in " + w);
10713 }
10714 }
10715 w.mToken.hasVisible = true;
10716 }
10717 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010718 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010719 "Orientation change skips hidden " + w);
10720 w.mOrientationChanging = false;
10721 }
10722
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010723 if (w.mContentChanged) {
10724 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10725 w.mContentChanged = false;
10726 }
10727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010728 final boolean canBeSeen = w.isDisplayedLw();
10729
10730 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10731 focusDisplayed = true;
10732 }
10733
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010734 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010736 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010737 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 if (w.mSurface != null) {
10739 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10740 holdScreen = w.mSession;
10741 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010742 if (!syswin && w.mAttrs.screenBrightness >= 0
10743 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010744 screenBrightness = w.mAttrs.screenBrightness;
10745 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010746 if (!syswin && w.mAttrs.buttonBrightness >= 0
10747 && buttonBrightness < 0) {
10748 buttonBrightness = w.mAttrs.buttonBrightness;
10749 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010750 if (canBeSeen
10751 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10752 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10753 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010754 syswin = true;
10755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010756 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010757
Dianne Hackborn25994b42009-09-04 14:21:19 -070010758 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10759 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010760 // This window completely covers everything behind it,
10761 // so we want to leave all of them as unblurred (for
10762 // performance reasons).
10763 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010764 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010765 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010766 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010767 obscured = true;
10768 if (mBackgroundFillerSurface == null) {
10769 try {
10770 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010771 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010772 0, dw, dh,
10773 PixelFormat.OPAQUE,
10774 Surface.FX_SURFACE_NORMAL);
10775 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010776 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010777 }
10778 }
10779 try {
10780 mBackgroundFillerSurface.setPosition(0, 0);
10781 mBackgroundFillerSurface.setSize(dw, dh);
10782 // Using the same layer as Dim because they will never be shown at the
10783 // same time.
10784 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10785 mBackgroundFillerSurface.show();
10786 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010787 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010788 }
10789 backgroundFillerShown = true;
10790 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010791 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010792 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010793 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010794 + ": blurring=" + blurring
10795 + " obscured=" + obscured
10796 + " displayed=" + displayed);
10797 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10798 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010799 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010800 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010801 if (mDimAnimator == null) {
10802 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010803 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010804 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010805 mDimAnimator.updateParameters(mContext.getResources(),
10806 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010807 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010808 }
10809 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10810 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010811 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010812 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010814 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010815 + mBlurSurface + ": CREATE");
10816 try {
Romain Guy06882f82009-06-10 13:36:04 -070010817 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010818 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010819 -1, 16, 16,
10820 PixelFormat.OPAQUE,
10821 Surface.FX_SURFACE_BLUR);
10822 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010823 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010824 }
10825 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010826 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010827 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10828 + mBlurSurface + ": pos=(0,0) (" +
10829 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010830 mBlurSurface.setPosition(0, 0);
10831 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010832 mBlurSurface.setLayer(w.mAnimLayer-2);
10833 if (!mBlurShown) {
10834 try {
10835 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10836 + mBlurSurface + ": SHOW");
10837 mBlurSurface.show();
10838 } catch (RuntimeException e) {
10839 Slog.w(TAG, "Failure showing blur surface", e);
10840 }
10841 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010842 }
10843 }
10844 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845 }
10846 }
10847 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010848
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010849 if (obscuredChanged && mWallpaperTarget == w) {
10850 // This is the wallpaper target and its obscured state
10851 // changed... make sure the current wallaper's visibility
10852 // has been updated accordingly.
10853 updateWallpaperVisibilityLocked();
10854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010855 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010856
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010857 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10858 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010859 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010860 try {
10861 mBackgroundFillerSurface.hide();
10862 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010863 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010864 }
10865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010867 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010868 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10869 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010870 }
Romain Guy06882f82009-06-10 13:36:04 -070010871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010872 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010873 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010874 + ": HIDE");
10875 try {
10876 mBlurSurface.hide();
10877 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010878 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010879 }
10880 mBlurShown = false;
10881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010882 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010883 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 }
10885
10886 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010887
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010888 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10889
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010890 if (mWatermark != null) {
10891 mWatermark.drawIfNeeded();
10892 }
10893
Joe Onorato8a9b2202010-02-26 18:56:32 -080010894 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010895 "With display frozen, orientationChangeComplete="
10896 + orientationChangeComplete);
10897 if (orientationChangeComplete) {
10898 if (mWindowsFreezingScreen) {
10899 mWindowsFreezingScreen = false;
10900 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10901 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010902 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010903 }
Romain Guy06882f82009-06-10 13:36:04 -070010904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010905 i = mResizingWindows.size();
10906 if (i > 0) {
10907 do {
10908 i--;
10909 WindowState win = mResizingWindows.get(i);
10910 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010911 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10912 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010913 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010914 boolean configChanged =
10915 win.mConfiguration != mCurConfiguration
10916 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010917 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10918 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10919 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010920 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010921 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010922 + " / " + mCurConfiguration + " / 0x"
10923 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010924 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010925 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 win.mClient.resized(win.mFrame.width(),
10927 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010928 win.mLastVisibleInsets, win.mDrawPending,
10929 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010930 win.mContentInsetsChanged = false;
10931 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010932 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010933 } catch (RemoteException e) {
10934 win.mOrientationChanging = false;
10935 }
10936 } while (i > 0);
10937 mResizingWindows.clear();
10938 }
Romain Guy06882f82009-06-10 13:36:04 -070010939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010940 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010941 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010942 i = mDestroySurface.size();
10943 if (i > 0) {
10944 do {
10945 i--;
10946 WindowState win = mDestroySurface.get(i);
10947 win.mDestroying = false;
10948 if (mInputMethodWindow == win) {
10949 mInputMethodWindow = null;
10950 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010951 if (win == mWallpaperTarget) {
10952 wallpaperDestroyed = true;
10953 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010954 win.destroySurfaceLocked();
10955 } while (i > 0);
10956 mDestroySurface.clear();
10957 }
10958
10959 // Time to remove any exiting tokens?
10960 for (i=mExitingTokens.size()-1; i>=0; i--) {
10961 WindowToken token = mExitingTokens.get(i);
10962 if (!token.hasVisible) {
10963 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010964 if (token.windowType == TYPE_WALLPAPER) {
10965 mWallpaperTokens.remove(token);
10966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010967 }
10968 }
10969
10970 // Time to remove any exiting applications?
10971 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10972 AppWindowToken token = mExitingAppTokens.get(i);
10973 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010974 // Make sure there is no animation running on this token,
10975 // so any windows associated with it will be removed as
10976 // soon as their animations are complete
10977 token.animation = null;
10978 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010979 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10980 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010981 mAppTokens.remove(token);
10982 mExitingAppTokens.remove(i);
10983 }
10984 }
10985
Dianne Hackborna8f60182009-09-01 19:01:50 -070010986 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010987
Dianne Hackborna8f60182009-09-01 19:01:50 -070010988 if (!animating && mAppTransitionRunning) {
10989 // We have finished the animation of an app transition. To do
10990 // this, we have delayed a lot of operations like showing and
10991 // hiding apps, moving apps in Z-order, etc. The app token list
10992 // reflects the correct Z-order, but the window list may now
10993 // be out of sync with it. So here we will just rebuild the
10994 // entire app window list. Fun!
10995 mAppTransitionRunning = false;
10996 needRelayout = true;
10997 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010998 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010999 // Clear information about apps that were moving.
11000 mToBottomApps.clear();
11001 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011003 if (focusDisplayed) {
11004 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
11005 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011006 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011007 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011008 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011009 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011010 requestAnimationLocked(0);
11011 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011012 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
11013 }
Jeff Browneb857f12010-07-16 10:06:33 -070011014
Jeff Brown3a22cd92011-01-21 13:59:04 -080011015 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080011016 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070011017
Jeff Brown8e03b752010-06-13 19:16:55 -070011018 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080011019 if (!mDisplayFrozen) {
11020 if (screenBrightness < 0 || screenBrightness > 1.0f) {
11021 mPowerManager.setScreenBrightnessOverride(-1);
11022 } else {
11023 mPowerManager.setScreenBrightnessOverride((int)
11024 (screenBrightness * Power.BRIGHTNESS_ON));
11025 }
11026 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
11027 mPowerManager.setButtonBrightnessOverride(-1);
11028 } else {
11029 mPowerManager.setButtonBrightnessOverride((int)
11030 (buttonBrightness * Power.BRIGHTNESS_ON));
11031 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050011032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011033 if (holdScreen != mHoldingScreenOn) {
11034 mHoldingScreenOn = holdScreen;
11035 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
11036 mH.sendMessage(m);
11037 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011038
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011039 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011040 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011041 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
11042 LocalPowerManager.BUTTON_EVENT, true);
11043 mTurnOnScreen = false;
11044 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011045
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011046 if (updateRotation) {
11047 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11048 boolean changed = setRotationUncheckedLocked(
11049 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11050 if (changed) {
11051 sendNewConfiguration();
11052 }
11053 }
11054
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011055 // Check to see if we are now in a state where the screen should
11056 // be enabled, because the window obscured flags have changed.
11057 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011058 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070011059
11060 /**
11061 * Must be called with the main window manager lock held.
11062 */
11063 void setHoldScreenLocked(boolean holding) {
11064 boolean state = mHoldingScreenWakeLock.isHeld();
11065 if (holding != state) {
11066 if (holding) {
11067 mHoldingScreenWakeLock.acquire();
11068 } else {
11069 mPolicy.screenOnStoppedLw();
11070 mHoldingScreenWakeLock.release();
11071 }
11072 }
11073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011074
11075 void requestAnimationLocked(long delay) {
11076 if (!mAnimationPending) {
11077 mAnimationPending = true;
11078 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
11079 }
11080 }
Romain Guy06882f82009-06-10 13:36:04 -070011081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011082 /**
11083 * Have the surface flinger show a surface, robustly dealing with
11084 * error conditions. In particular, if there is not enough memory
11085 * to show the surface, then we will try to get rid of other surfaces
11086 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011087 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011088 * @return Returns true if the surface was successfully shown.
11089 */
11090 boolean showSurfaceRobustlyLocked(WindowState win) {
11091 try {
11092 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011093 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011094 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011095 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011096 if (DEBUG_VISIBILITY) Slog.v(TAG,
11097 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011098 win.mTurnOnScreen = false;
11099 mTurnOnScreen = true;
11100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011101 }
11102 return true;
11103 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011104 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011105 }
Romain Guy06882f82009-06-10 13:36:04 -070011106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011107 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011109 return false;
11110 }
Romain Guy06882f82009-06-10 13:36:04 -070011111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011112 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11113 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011114
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011115 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011116 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011118 if (mForceRemoves == null) {
11119 mForceRemoves = new ArrayList<WindowState>();
11120 }
Romain Guy06882f82009-06-10 13:36:04 -070011121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011122 long callingIdentity = Binder.clearCallingIdentity();
11123 try {
11124 // There was some problem... first, do a sanity check of the
11125 // window list to make sure we haven't left any dangling surfaces
11126 // around.
11127 int N = mWindows.size();
11128 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011129 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011130 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011131 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011132 if (ws.mSurface != null) {
11133 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011134 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011135 + ws + " surface=" + ws.mSurface
11136 + " token=" + win.mToken
11137 + " pid=" + ws.mSession.mPid
11138 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011139 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011140 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011141 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011142 ws.mSurface = null;
11143 mForceRemoves.add(ws);
11144 i--;
11145 N--;
11146 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011147 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011148 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011149 + ws + " surface=" + ws.mSurface
11150 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011151 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011152 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011153 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011154 ws.mSurface = null;
11155 leakedSurface = true;
11156 }
11157 }
11158 }
Romain Guy06882f82009-06-10 13:36:04 -070011159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011160 boolean killedApps = false;
11161 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011162 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011163 SparseIntArray pidCandidates = new SparseIntArray();
11164 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011165 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011166 if (ws.mSurface != null) {
11167 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11168 }
11169 }
11170 if (pidCandidates.size() > 0) {
11171 int[] pids = new int[pidCandidates.size()];
11172 for (int i=0; i<pids.length; i++) {
11173 pids[i] = pidCandidates.keyAt(i);
11174 }
11175 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011176 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011177 killedApps = true;
11178 }
11179 } catch (RemoteException e) {
11180 }
11181 }
11182 }
Romain Guy06882f82009-06-10 13:36:04 -070011183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011184 if (leakedSurface || killedApps) {
11185 // We managed to reclaim some memory, so get rid of the trouble
11186 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011187 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011188 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011189 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011190 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011191 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011192 win.mSurface = null;
11193 }
Romain Guy06882f82009-06-10 13:36:04 -070011194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011195 try {
11196 win.mClient.dispatchGetNewSurface();
11197 } catch (RemoteException e) {
11198 }
11199 }
11200 } finally {
11201 Binder.restoreCallingIdentity(callingIdentity);
11202 }
11203 }
Romain Guy06882f82009-06-10 13:36:04 -070011204
Jeff Brown3a22cd92011-01-21 13:59:04 -080011205 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011206 WindowState newFocus = computeFocusedWindowLocked();
11207 if (mCurrentFocus != newFocus) {
11208 // This check makes sure that we don't already have the focus
11209 // change message pending.
11210 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11211 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011212 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011213 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11214 final WindowState oldFocus = mCurrentFocus;
11215 mCurrentFocus = newFocus;
11216 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011218 final WindowState imWindow = mInputMethodWindow;
11219 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011220 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011221 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011222 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11223 mLayoutNeeded = true;
11224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011225 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011226 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011227 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11228 // Client will do the layout, but we need to assign layers
11229 // for handleNewWindowLocked() below.
11230 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011231 }
11232 }
Jeff Brown349703e2010-06-22 01:27:15 -070011233
11234 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11235 // If we defer assigning layers, then the caller is responsible for
11236 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011237 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011239 return true;
11240 }
11241 return false;
11242 }
Jeff Brown349703e2010-06-22 01:27:15 -070011243
Jeff Brown3a22cd92011-01-21 13:59:04 -080011244 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11245 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011247
11248 private WindowState computeFocusedWindowLocked() {
11249 WindowState result = null;
11250 WindowState win;
11251
11252 int i = mWindows.size() - 1;
11253 int nextAppIndex = mAppTokens.size()-1;
11254 WindowToken nextApp = nextAppIndex >= 0
11255 ? mAppTokens.get(nextAppIndex) : null;
11256
11257 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011258 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011259
Joe Onorato8a9b2202010-02-26 18:56:32 -080011260 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011261 TAG, "Looking for focus: " + i
11262 + " = " + win
11263 + ", flags=" + win.mAttrs.flags
11264 + ", canReceive=" + win.canReceiveKeys());
11265
11266 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011268 // If this window's application has been removed, just skip it.
11269 if (thisApp != null && thisApp.removed) {
11270 i--;
11271 continue;
11272 }
Romain Guy06882f82009-06-10 13:36:04 -070011273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011274 // If there is a focused app, don't allow focus to go to any
11275 // windows below it. If this is an application window, step
11276 // through the app tokens until we find its app.
11277 if (thisApp != null && nextApp != null && thisApp != nextApp
11278 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11279 int origAppIndex = nextAppIndex;
11280 while (nextAppIndex > 0) {
11281 if (nextApp == mFocusedApp) {
11282 // Whoops, we are below the focused app... no focus
11283 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011284 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011285 TAG, "Reached focused app: " + mFocusedApp);
11286 return null;
11287 }
11288 nextAppIndex--;
11289 nextApp = mAppTokens.get(nextAppIndex);
11290 if (nextApp == thisApp) {
11291 break;
11292 }
11293 }
11294 if (thisApp != nextApp) {
11295 // Uh oh, the app token doesn't exist! This shouldn't
11296 // happen, but if it does we can get totally hosed...
11297 // so restart at the original app.
11298 nextAppIndex = origAppIndex;
11299 nextApp = mAppTokens.get(nextAppIndex);
11300 }
11301 }
11302
11303 // Dispatch to this window if it is wants key events.
11304 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011305 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011306 TAG, "Found focus @ " + i + " = " + win);
11307 result = win;
11308 break;
11309 }
11310
11311 i--;
11312 }
11313
11314 return result;
11315 }
11316
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011317 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011318 if (mDisplayFrozen) {
11319 return;
11320 }
Romain Guy06882f82009-06-10 13:36:04 -070011321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011322 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011324 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011325 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011326 if (mFreezeGcPending != 0) {
11327 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011328 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011329 mH.removeMessages(H.FORCE_GC);
11330 Runtime.getRuntime().gc();
11331 mFreezeGcPending = now;
11332 }
11333 } else {
11334 mFreezeGcPending = now;
11335 }
Romain Guy06882f82009-06-10 13:36:04 -070011336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011337 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011338
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011339 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011340
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011341 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11342 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011343 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011344 mAppTransitionReady = true;
11345 }
Romain Guy06882f82009-06-10 13:36:04 -070011346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011347 if (PROFILE_ORIENTATION) {
11348 File file = new File("/data/system/frozen");
11349 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11350 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011351
11352 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011353 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11354 mScreenRotationAnimation.kill();
11355 mScreenRotationAnimation = null;
11356 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011357 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011358 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011359 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011360 }
11361 } else {
11362 Surface.freezeDisplay(0);
11363 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011364 }
Romain Guy06882f82009-06-10 13:36:04 -070011365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011366 private void stopFreezingDisplayLocked() {
11367 if (!mDisplayFrozen) {
11368 return;
11369 }
Romain Guy06882f82009-06-10 13:36:04 -070011370
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011371 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11372 return;
11373 }
11374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011375 mDisplayFrozen = false;
11376 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11377 if (PROFILE_ORIENTATION) {
11378 Debug.stopMethodTracing();
11379 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011380
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011381 boolean updateRotation = false;
11382
Dianne Hackborna1111872010-11-23 20:55:11 -080011383 if (CUSTOM_SCREEN_ROTATION) {
11384 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011385 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11386 mTransitionAnimationScale)) {
11387 requestAnimationLocked(0);
11388 } else {
11389 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011390 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011391 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011392 }
11393 } else {
11394 Surface.unfreezeDisplay(0);
11395 }
Romain Guy06882f82009-06-10 13:36:04 -070011396
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011397 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011398
Dianne Hackborn420829e2011-01-28 11:30:35 -080011399 boolean configChanged;
11400
Christopher Tateb696aee2010-04-02 19:08:30 -070011401 // While the display is frozen we don't re-compute the orientation
11402 // to avoid inconsistent states. However, something interesting
11403 // could have actually changed during that time so re-evaluate it
11404 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -080011405 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -070011406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011407 // A little kludge: a lot could have happened while the
11408 // display was frozen, so now that we are coming back we
11409 // do a gc so that any remote references the system
11410 // processes holds on others can be released if they are
11411 // no longer needed.
11412 mH.removeMessages(H.FORCE_GC);
11413 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11414 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011416 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011417
11418 if (updateRotation) {
11419 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -080011420 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011421 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -080011422 }
11423
11424 if (configChanged) {
11425 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011427 }
Romain Guy06882f82009-06-10 13:36:04 -070011428
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011429 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11430 DisplayMetrics dm) {
11431 if (index < tokens.length) {
11432 String str = tokens[index];
11433 if (str != null && str.length() > 0) {
11434 try {
11435 int val = Integer.parseInt(str);
11436 return val;
11437 } catch (Exception e) {
11438 }
11439 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011440 }
11441 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11442 return defDps;
11443 }
11444 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11445 return val;
11446 }
11447
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011448 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011449 final String[] mTokens;
11450 final String mText;
11451 final Paint mTextPaint;
11452 final int mTextWidth;
11453 final int mTextHeight;
11454 final int mTextAscent;
11455 final int mTextDescent;
11456 final int mDeltaX;
11457 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011458
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011459 Surface mSurface;
11460 int mLastDW;
11461 int mLastDH;
11462 boolean mDrawNeeded;
11463
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011464 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011465 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011466 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011467
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011468 if (false) {
11469 Log.i(TAG, "*********************** WATERMARK");
11470 for (int i=0; i<tokens.length; i++) {
11471 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11472 }
11473 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011474
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011475 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011476
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011477 StringBuilder builder = new StringBuilder(32);
11478 int len = mTokens[0].length();
11479 len = len & ~1;
11480 for (int i=0; i<len; i+=2) {
11481 int c1 = mTokens[0].charAt(i);
11482 int c2 = mTokens[0].charAt(i+1);
11483 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11484 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11485 else c1 -= '0';
11486 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11487 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11488 else c2 -= '0';
11489 builder.append((char)(255-((c1*16)+c2)));
11490 }
11491 mText = builder.toString();
11492 if (false) {
11493 Log.i(TAG, "Final text: " + mText);
11494 }
11495
11496 int fontSize = getPropertyInt(tokens, 1,
11497 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11498
11499 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11500 mTextPaint.setTextSize(fontSize);
11501 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11502
11503 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11504 mTextWidth = (int)mTextPaint.measureText(mText);
11505 mTextAscent = fm.ascent;
11506 mTextDescent = fm.descent;
11507 mTextHeight = fm.descent - fm.ascent;
11508
11509 mDeltaX = getPropertyInt(tokens, 2,
11510 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11511 mDeltaY = getPropertyInt(tokens, 3,
11512 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11513 int shadowColor = getPropertyInt(tokens, 4,
11514 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11515 int color = getPropertyInt(tokens, 5,
11516 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11517 int shadowRadius = getPropertyInt(tokens, 6,
11518 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11519 int shadowDx = getPropertyInt(tokens, 8,
11520 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11521 int shadowDy = getPropertyInt(tokens, 9,
11522 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11523
11524 mTextPaint.setColor(color);
11525 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011526
11527 try {
11528 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011529 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011530 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011531 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011532 mSurface.show();
11533 } catch (OutOfResourcesException e) {
11534 }
11535 }
11536
11537 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011538 if (mLastDW != dw || mLastDH != dh) {
11539 mLastDW = dw;
11540 mLastDH = dh;
11541 mSurface.setSize(dw, dh);
11542 mDrawNeeded = true;
11543 }
11544 }
11545
11546 void drawIfNeeded() {
11547 if (mDrawNeeded) {
11548 final int dw = mLastDW;
11549 final int dh = mLastDH;
11550
11551 mDrawNeeded = false;
11552 Rect dirty = new Rect(0, 0, dw, dh);
11553 Canvas c = null;
11554 try {
11555 c = mSurface.lockCanvas(dirty);
11556 } catch (IllegalArgumentException e) {
11557 } catch (OutOfResourcesException e) {
11558 }
11559 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011560 c.drawColor(0, PorterDuff.Mode.CLEAR);
11561
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011562 int deltaX = mDeltaX;
11563 int deltaY = mDeltaY;
11564
11565 // deltaX shouldn't be close to a round fraction of our
11566 // x step, or else things will line up too much.
11567 int div = (dw+mTextWidth)/deltaX;
11568 int rem = (dw+mTextWidth) - (div*deltaX);
11569 int qdelta = deltaX/4;
11570 if (rem < qdelta || rem > (deltaX-qdelta)) {
11571 deltaX += deltaX/3;
11572 }
11573
11574 int y = -mTextHeight;
11575 int x = -mTextWidth;
11576 while (y < (dh+mTextHeight)) {
11577 c.drawText(mText, x, y, mTextPaint);
11578 x += deltaX;
11579 if (x >= dw) {
11580 x -= (dw+mTextWidth);
11581 y += deltaY;
11582 }
11583 }
11584 mSurface.unlockCanvasAndPost(c);
11585 }
11586 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011587 }
11588 }
11589
11590 void createWatermark() {
11591 if (mWatermark != null) {
11592 return;
11593 }
11594
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011595 File file = new File("/system/etc/setup.conf");
11596 FileInputStream in = null;
11597 try {
11598 in = new FileInputStream(file);
11599 DataInputStream ind = new DataInputStream(in);
11600 String line = ind.readLine();
11601 if (line != null) {
11602 String[] toks = line.split("%");
11603 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011604 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011605 }
11606 }
11607 } catch (FileNotFoundException e) {
11608 } catch (IOException e) {
11609 } finally {
11610 if (in != null) {
11611 try {
11612 in.close();
11613 } catch (IOException e) {
11614 }
11615 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011616 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011617 }
11618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011619 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011620 public void statusBarVisibilityChanged(int visibility) {
11621 synchronized (mWindowMap) {
11622 final int N = mWindows.size();
11623 for (int i = 0; i < N; i++) {
11624 WindowState ws = mWindows.get(i);
11625 try {
11626 if (ws.getAttrs().hasSystemUiListeners) {
11627 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11628 }
11629 } catch (RemoteException e) {
11630 // so sorry
11631 }
11632 }
11633 }
11634 }
11635
11636 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011637 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11638 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11639 != PackageManager.PERMISSION_GRANTED) {
11640 pw.println("Permission Denial: can't dump WindowManager from from pid="
11641 + Binder.getCallingPid()
11642 + ", uid=" + Binder.getCallingUid());
11643 return;
11644 }
Romain Guy06882f82009-06-10 13:36:04 -070011645
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011646 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011647 pw.println(" ");
11648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011649 synchronized(mWindowMap) {
11650 pw.println("Current Window Manager state:");
11651 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011652 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011653 pw.print(" Window #"); pw.print(i); pw.print(' ');
11654 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011655 w.dump(pw, " ");
11656 }
11657 if (mInputMethodDialogs.size() > 0) {
11658 pw.println(" ");
11659 pw.println(" Input method dialogs:");
11660 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11661 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011662 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011663 }
11664 }
11665 if (mPendingRemove.size() > 0) {
11666 pw.println(" ");
11667 pw.println(" Remove pending for:");
11668 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11669 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011670 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11671 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011672 w.dump(pw, " ");
11673 }
11674 }
11675 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11676 pw.println(" ");
11677 pw.println(" Windows force removing:");
11678 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11679 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011680 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11681 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011682 w.dump(pw, " ");
11683 }
11684 }
11685 if (mDestroySurface.size() > 0) {
11686 pw.println(" ");
11687 pw.println(" Windows waiting to destroy their surface:");
11688 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11689 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011690 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11691 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011692 w.dump(pw, " ");
11693 }
11694 }
11695 if (mLosingFocus.size() > 0) {
11696 pw.println(" ");
11697 pw.println(" Windows losing focus:");
11698 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11699 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011700 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11701 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011702 w.dump(pw, " ");
11703 }
11704 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011705 if (mResizingWindows.size() > 0) {
11706 pw.println(" ");
11707 pw.println(" Windows waiting to resize:");
11708 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11709 WindowState w = mResizingWindows.get(i);
11710 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11711 pw.print(w); pw.println(":");
11712 w.dump(pw, " ");
11713 }
11714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011715 if (mSessions.size() > 0) {
11716 pw.println(" ");
11717 pw.println(" All active sessions:");
11718 Iterator<Session> it = mSessions.iterator();
11719 while (it.hasNext()) {
11720 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011721 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011722 s.dump(pw, " ");
11723 }
11724 }
11725 if (mTokenMap.size() > 0) {
11726 pw.println(" ");
11727 pw.println(" All tokens:");
11728 Iterator<WindowToken> it = mTokenMap.values().iterator();
11729 while (it.hasNext()) {
11730 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011731 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011732 token.dump(pw, " ");
11733 }
11734 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011735 if (mWallpaperTokens.size() > 0) {
11736 pw.println(" ");
11737 pw.println(" Wallpaper tokens:");
11738 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11739 WindowToken token = mWallpaperTokens.get(i);
11740 pw.print(" Wallpaper #"); pw.print(i);
11741 pw.print(' '); pw.print(token); pw.println(':');
11742 token.dump(pw, " ");
11743 }
11744 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011745 if (mAppTokens.size() > 0) {
11746 pw.println(" ");
11747 pw.println(" Application tokens in Z order:");
11748 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011749 pw.print(" App #"); pw.print(i); pw.print(": ");
11750 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011751 }
11752 }
11753 if (mFinishedStarting.size() > 0) {
11754 pw.println(" ");
11755 pw.println(" Finishing start of application tokens:");
11756 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11757 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011758 pw.print(" Finished Starting #"); pw.print(i);
11759 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011760 token.dump(pw, " ");
11761 }
11762 }
11763 if (mExitingTokens.size() > 0) {
11764 pw.println(" ");
11765 pw.println(" Exiting tokens:");
11766 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11767 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011768 pw.print(" Exiting #"); pw.print(i);
11769 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011770 token.dump(pw, " ");
11771 }
11772 }
11773 if (mExitingAppTokens.size() > 0) {
11774 pw.println(" ");
11775 pw.println(" Exiting application tokens:");
11776 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11777 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011778 pw.print(" Exiting App #"); pw.print(i);
11779 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011780 token.dump(pw, " ");
11781 }
11782 }
11783 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011784 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11785 pw.print(" mLastFocus="); pw.println(mLastFocus);
11786 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11787 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11788 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011789 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011790 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11791 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11792 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11793 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011794 if (mWindowDetachedWallpaper != null) {
11795 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11796 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011797 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11798 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11799 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011800 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11801 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11802 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11803 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011804 if (mDimAnimator != null) {
11805 mDimAnimator.printTo(pw);
11806 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011807 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011808 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011809 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011810 pw.print(mInputMethodAnimLayerAdjustment);
11811 pw.print(" mWallpaperAnimLayerAdjustment=");
11812 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011813 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11814 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011815 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11816 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011817 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11818 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011819 pw.print(" mRotation="); pw.print(mRotation);
11820 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11821 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011822 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11823 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011824 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11825 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11826 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11827 pw.print(" mNextAppTransition=0x");
11828 pw.print(Integer.toHexString(mNextAppTransition));
11829 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011830 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011831 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011832 if (mNextAppTransitionPackage != null) {
11833 pw.print(" mNextAppTransitionPackage=");
11834 pw.print(mNextAppTransitionPackage);
11835 pw.print(", mNextAppTransitionEnter=0x");
11836 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11837 pw.print(", mNextAppTransitionExit=0x");
11838 pw.print(Integer.toHexString(mNextAppTransitionExit));
11839 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011840 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11841 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11842 if (mOpeningApps.size() > 0) {
11843 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11844 }
11845 if (mClosingApps.size() > 0) {
11846 pw.print(" mClosingApps="); pw.println(mClosingApps);
11847 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011848 if (mToTopApps.size() > 0) {
11849 pw.print(" mToTopApps="); pw.println(mToTopApps);
11850 }
11851 if (mToBottomApps.size() > 0) {
11852 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11853 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011854 if (mDisplay != null) {
11855 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11856 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11857 } else {
11858 pw.println(" NO DISPLAY");
11859 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011860 pw.println(" Policy:");
11861 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011862 }
11863 }
11864
Jeff Brown349703e2010-06-22 01:27:15 -070011865 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011866 public void monitor() {
11867 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011868 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011870
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011871 /**
11872 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011873 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011874 */
11875 private static class DimAnimator {
11876 Surface mDimSurface;
11877 boolean mDimShown = false;
11878 float mDimCurrentAlpha;
11879 float mDimTargetAlpha;
11880 float mDimDeltaPerMs;
11881 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011882
11883 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011884
11885 DimAnimator (SurfaceSession session) {
11886 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011887 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011888 + mDimSurface + ": CREATE");
11889 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011890 mDimSurface = new Surface(session, 0,
11891 "DimSurface",
11892 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011893 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011894 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011895 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011896 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011897 }
11898 }
11899 }
11900
11901 /**
11902 * Show the dim surface.
11903 */
11904 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011905 if (!mDimShown) {
11906 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11907 dw + "x" + dh + ")");
11908 mDimShown = true;
11909 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011910 mLastDimWidth = dw;
11911 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011912 mDimSurface.setPosition(0, 0);
11913 mDimSurface.setSize(dw, dh);
11914 mDimSurface.show();
11915 } catch (RuntimeException e) {
11916 Slog.w(TAG, "Failure showing dim surface", e);
11917 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011918 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11919 mLastDimWidth = dw;
11920 mLastDimHeight = dh;
11921 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011922 }
11923 }
11924
11925 /**
11926 * Set's the dim surface's layer and update dim parameters that will be used in
11927 * {@link updateSurface} after all windows are examined.
11928 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011929 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011930 mDimSurface.setLayer(w.mAnimLayer-1);
11931
11932 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011933 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011934 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011935 if (mDimTargetAlpha != target) {
11936 // If the desired dim level has changed, then
11937 // start an animation to it.
11938 mLastDimAnimTime = currentTime;
11939 long duration = (w.mAnimating && w.mAnimation != null)
11940 ? w.mAnimation.computeDurationHint()
11941 : DEFAULT_DIM_DURATION;
11942 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011943 TypedValue tv = new TypedValue();
11944 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11945 tv, true);
11946 if (tv.type == TypedValue.TYPE_FRACTION) {
11947 duration = (long)tv.getFraction((float)duration, (float)duration);
11948 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11949 && tv.type <= TypedValue.TYPE_LAST_INT) {
11950 duration = tv.data;
11951 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011952 }
11953 if (duration < 1) {
11954 // Don't divide by zero
11955 duration = 1;
11956 }
11957 mDimTargetAlpha = target;
11958 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11959 }
11960 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011961
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011962 /**
11963 * Updating the surface's alpha. Returns true if the animation continues, or returns
11964 * false when the animation is finished and the dim surface is hidden.
11965 */
11966 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11967 if (!dimming) {
11968 if (mDimTargetAlpha != 0) {
11969 mLastDimAnimTime = currentTime;
11970 mDimTargetAlpha = 0;
11971 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11972 }
11973 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011974
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011975 boolean animating = false;
11976 if (mLastDimAnimTime != 0) {
11977 mDimCurrentAlpha += mDimDeltaPerMs
11978 * (currentTime-mLastDimAnimTime);
11979 boolean more = true;
11980 if (displayFrozen) {
11981 // If the display is frozen, there is no reason to animate.
11982 more = false;
11983 } else if (mDimDeltaPerMs > 0) {
11984 if (mDimCurrentAlpha > mDimTargetAlpha) {
11985 more = false;
11986 }
11987 } else if (mDimDeltaPerMs < 0) {
11988 if (mDimCurrentAlpha < mDimTargetAlpha) {
11989 more = false;
11990 }
11991 } else {
11992 more = false;
11993 }
11994
11995 // Do we need to continue animating?
11996 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011997 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011998 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11999 mLastDimAnimTime = currentTime;
12000 mDimSurface.setAlpha(mDimCurrentAlpha);
12001 animating = true;
12002 } else {
12003 mDimCurrentAlpha = mDimTargetAlpha;
12004 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080012005 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012006 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
12007 mDimSurface.setAlpha(mDimCurrentAlpha);
12008 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012009 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012010 + ": HIDE");
12011 try {
12012 mDimSurface.hide();
12013 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012014 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012015 }
12016 mDimShown = false;
12017 }
12018 }
12019 }
12020 return animating;
12021 }
12022
12023 public void printTo(PrintWriter pw) {
12024 pw.print(" mDimShown="); pw.print(mDimShown);
12025 pw.print(" current="); pw.print(mDimCurrentAlpha);
12026 pw.print(" target="); pw.print(mDimTargetAlpha);
12027 pw.print(" delta="); pw.print(mDimDeltaPerMs);
12028 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
12029 }
12030 }
12031
12032 /**
12033 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
12034 * This is used for opening/closing transition for apps in compatible mode.
12035 */
12036 private static class FadeInOutAnimation extends Animation {
12037 int mWidth;
12038 boolean mFadeIn;
12039
12040 public FadeInOutAnimation(boolean fadeIn) {
12041 setInterpolator(new AccelerateInterpolator());
12042 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
12043 mFadeIn = fadeIn;
12044 }
12045
12046 @Override
12047 protected void applyTransformation(float interpolatedTime, Transformation t) {
12048 float x = interpolatedTime;
12049 if (!mFadeIn) {
12050 x = 1.0f - x; // reverse the interpolation for fade out
12051 }
12052 if (x < 0.5) {
12053 // move the window out of the screen.
12054 t.getMatrix().setTranslate(mWidth, 0);
12055 } else {
12056 t.getMatrix().setTranslate(0, 0);// show
12057 t.setAlpha((x - 0.5f) * 2);
12058 }
12059 }
12060
12061 @Override
12062 public void initialize(int width, int height, int parentWidth, int parentHeight) {
12063 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
12064 mWidth = width;
12065 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012066
12067 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070012068 public int getZAdjustment() {
12069 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012070 }
12071 }
Jeff Brown2992ea72011-01-28 22:04:14 -080012072
12073 public interface OnHardKeyboardStatusChangeListener {
12074 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
12075 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012076}