blob: 7a3ef1481714437a79b633fa4184e007c6a38cf9 [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 Hackborncb8f0e02010-12-16 11:15:18 -08005104 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005105 return null;
5106 }
5107
5108 // The screenshot API does not apply the current screen rotation.
5109 rot = mDisplay.getRotation();
5110 int fw = frame.width();
5111 int fh = frame.height();
5112
5113 // First try reducing to fit in x dimension.
5114 scale = maxWidth/(float)fw;
5115 sw = maxWidth;
5116 sh = (int)(fh*scale);
5117 if (sh > maxHeight) {
5118 // y dimension became too long; constrain by that.
5119 scale = maxHeight/(float)fh;
5120 sw = (int)(fw*scale);
5121 sh = maxHeight;
5122 }
5123
5124 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005125 dw = (int)(dw*scale);
5126 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005127 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5128 int tmp = dw;
5129 dw = dh;
5130 dh = tmp;
5131 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5132 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005133 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005134 }
5135
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005136 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005137 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5138 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005139 return null;
5140 }
5141
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005142 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5143 Matrix matrix = new Matrix();
5144 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5145 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5146 Canvas canvas = new Canvas(bm);
5147 canvas.drawBitmap(rawss, matrix, null);
5148
5149 rawss.recycle();
5150 return bm;
5151 }
5152
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005153 public void freezeRotation() {
5154 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5155 "setRotation()")) {
5156 throw new SecurityException("Requires SET_ORIENTATION permission");
5157 }
5158
5159 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5160 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5161 }
5162
5163 public void thawRotation() {
5164 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5165 "setRotation()")) {
5166 throw new SecurityException("Requires SET_ORIENTATION permission");
5167 }
5168
5169 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5170 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5171 }
5172
Romain Guy06882f82009-06-10 13:36:04 -07005173 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005174 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005175 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005176 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005177 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 }
5179
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005180 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005181 }
Romain Guy06882f82009-06-10 13:36:04 -07005182
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005183 public void setRotationUnchecked(int rotation,
5184 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005185 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005186 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005188 long origId = Binder.clearCallingIdentity();
5189 boolean changed;
5190 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005191 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005192 }
Romain Guy06882f82009-06-10 13:36:04 -07005193
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005194 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005195 sendNewConfiguration();
5196 }
Romain Guy06882f82009-06-10 13:36:04 -07005197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005198 Binder.restoreCallingIdentity(origId);
5199 }
Romain Guy06882f82009-06-10 13:36:04 -07005200
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005201 /**
5202 * Apply a new rotation to the screen, respecting the requests of
5203 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5204 * re-evaluate the desired rotation.
5205 *
5206 * Returns null if the rotation has been changed. In this case YOU
5207 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5208 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005209 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005210 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005211 // Potential rotation during a drag. Don't do the rotation now, but make
5212 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005213 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5214 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5215 mDeferredRotation = rotation;
5216 mDeferredRotationAnimFlags = animFlags;
5217 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005218 return false;
5219 }
5220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005221 boolean changed;
5222 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005223 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5224 rotation = mDeferredRotation;
5225 mRequestedRotation = rotation;
5226 mLastRotationFlags = mDeferredRotationAnimFlags;
5227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 rotation = mRequestedRotation;
5229 } else {
5230 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005231 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005232 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005233 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005234 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005235 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005236 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005237 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005241 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005242 "Rotation changed to " + rotation
5243 + " from " + mRotation
5244 + " (forceApp=" + mForcedAppOrientation
5245 + ", req=" + mRequestedRotation + ")");
5246 mRotation = rotation;
5247 mWindowsFreezingScreen = true;
5248 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5249 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5250 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005251 mWaitingForConfig = true;
5252 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005253 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005254 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005255 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005257 if (CUSTOM_SCREEN_ROTATION) {
5258 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005259 if (!inTransaction) {
5260 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5261 ">>> OPEN TRANSACTION setRotationUnchecked");
5262 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005263 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005264 try {
5265 if (mScreenRotationAnimation != null) {
5266 mScreenRotationAnimation.setRotation(rotation);
5267 }
5268 } finally {
5269 if (!inTransaction) {
5270 Surface.closeTransaction();
5271 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5272 "<<< CLOSE TRANSACTION setRotationUnchecked");
5273 }
5274 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005275 Surface.setOrientation(0, rotation, animFlags);
5276 Surface.unfreezeDisplay(0);
5277 } else {
5278 Surface.setOrientation(0, rotation, animFlags);
5279 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005280 }
5281 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005282 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005283 if (w.mSurface != null) {
5284 w.mOrientationChanging = true;
5285 }
5286 }
5287 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5288 try {
5289 mRotationWatchers.get(i).onRotationChanged(rotation);
5290 } catch (RemoteException e) {
5291 }
5292 }
5293 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005295 return changed;
5296 }
Romain Guy06882f82009-06-10 13:36:04 -07005297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005298 public int getRotation() {
5299 return mRotation;
5300 }
5301
5302 public int watchRotation(IRotationWatcher watcher) {
5303 final IBinder watcherBinder = watcher.asBinder();
5304 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5305 public void binderDied() {
5306 synchronized (mWindowMap) {
5307 for (int i=0; i<mRotationWatchers.size(); i++) {
5308 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005309 IRotationWatcher removed = mRotationWatchers.remove(i);
5310 if (removed != null) {
5311 removed.asBinder().unlinkToDeath(this, 0);
5312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 i--;
5314 }
5315 }
5316 }
5317 }
5318 };
Romain Guy06882f82009-06-10 13:36:04 -07005319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005320 synchronized (mWindowMap) {
5321 try {
5322 watcher.asBinder().linkToDeath(dr, 0);
5323 mRotationWatchers.add(watcher);
5324 } catch (RemoteException e) {
5325 // Client died, no cleanup needed.
5326 }
Romain Guy06882f82009-06-10 13:36:04 -07005327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005328 return mRotation;
5329 }
5330 }
5331
5332 /**
5333 * Starts the view server on the specified port.
5334 *
5335 * @param port The port to listener to.
5336 *
5337 * @return True if the server was successfully started, false otherwise.
5338 *
5339 * @see com.android.server.ViewServer
5340 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5341 */
5342 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005343 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005344 return false;
5345 }
5346
5347 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5348 return false;
5349 }
5350
5351 if (port < 1024) {
5352 return false;
5353 }
5354
5355 if (mViewServer != null) {
5356 if (!mViewServer.isRunning()) {
5357 try {
5358 return mViewServer.start();
5359 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005360 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005361 }
5362 }
5363 return false;
5364 }
5365
5366 try {
5367 mViewServer = new ViewServer(this, port);
5368 return mViewServer.start();
5369 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005370 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005371 }
5372 return false;
5373 }
5374
Romain Guy06882f82009-06-10 13:36:04 -07005375 private boolean isSystemSecure() {
5376 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5377 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5378 }
5379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 /**
5381 * Stops the view server if it exists.
5382 *
5383 * @return True if the server stopped, false if it wasn't started or
5384 * couldn't be stopped.
5385 *
5386 * @see com.android.server.ViewServer
5387 */
5388 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005389 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005390 return false;
5391 }
5392
5393 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5394 return false;
5395 }
5396
5397 if (mViewServer != null) {
5398 return mViewServer.stop();
5399 }
5400 return false;
5401 }
5402
5403 /**
5404 * Indicates whether the view server is running.
5405 *
5406 * @return True if the server is running, false otherwise.
5407 *
5408 * @see com.android.server.ViewServer
5409 */
5410 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005411 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005412 return false;
5413 }
5414
5415 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5416 return false;
5417 }
5418
5419 return mViewServer != null && mViewServer.isRunning();
5420 }
5421
5422 /**
5423 * Lists all availble windows in the system. The listing is written in the
5424 * specified Socket's output stream with the following syntax:
5425 * windowHashCodeInHexadecimal windowName
5426 * Each line of the ouput represents a different window.
5427 *
5428 * @param client The remote client to send the listing to.
5429 * @return False if an error occured, true otherwise.
5430 */
5431 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005432 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005433 return false;
5434 }
5435
5436 boolean result = true;
5437
Jeff Browne33348b2010-07-15 23:54:05 -07005438 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005439 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005440 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005441 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005442 }
5443
5444 BufferedWriter out = null;
5445
5446 // Any uncaught exception will crash the system process
5447 try {
5448 OutputStream clientStream = client.getOutputStream();
5449 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5450
5451 final int count = windows.length;
5452 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005453 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005454 out.write(Integer.toHexString(System.identityHashCode(w)));
5455 out.write(' ');
5456 out.append(w.mAttrs.getTitle());
5457 out.write('\n');
5458 }
5459
5460 out.write("DONE.\n");
5461 out.flush();
5462 } catch (Exception e) {
5463 result = false;
5464 } finally {
5465 if (out != null) {
5466 try {
5467 out.close();
5468 } catch (IOException e) {
5469 result = false;
5470 }
5471 }
5472 }
5473
5474 return result;
5475 }
5476
5477 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005478 * Returns the focused window in the following format:
5479 * windowHashCodeInHexadecimal windowName
5480 *
5481 * @param client The remote client to send the listing to.
5482 * @return False if an error occurred, true otherwise.
5483 */
5484 boolean viewServerGetFocusedWindow(Socket client) {
5485 if (isSystemSecure()) {
5486 return false;
5487 }
5488
5489 boolean result = true;
5490
5491 WindowState focusedWindow = getFocusedWindow();
5492
5493 BufferedWriter out = null;
5494
5495 // Any uncaught exception will crash the system process
5496 try {
5497 OutputStream clientStream = client.getOutputStream();
5498 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5499
5500 if(focusedWindow != null) {
5501 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5502 out.write(' ');
5503 out.append(focusedWindow.mAttrs.getTitle());
5504 }
5505 out.write('\n');
5506 out.flush();
5507 } catch (Exception e) {
5508 result = false;
5509 } finally {
5510 if (out != null) {
5511 try {
5512 out.close();
5513 } catch (IOException e) {
5514 result = false;
5515 }
5516 }
5517 }
5518
5519 return result;
5520 }
5521
5522 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005523 * Sends a command to a target window. The result of the command, if any, will be
5524 * written in the output stream of the specified socket.
5525 *
5526 * The parameters must follow this syntax:
5527 * windowHashcode extra
5528 *
5529 * Where XX is the length in characeters of the windowTitle.
5530 *
5531 * The first parameter is the target window. The window with the specified hashcode
5532 * will be the target. If no target can be found, nothing happens. The extra parameters
5533 * will be delivered to the target window and as parameters to the command itself.
5534 *
5535 * @param client The remote client to sent the result, if any, to.
5536 * @param command The command to execute.
5537 * @param parameters The command parameters.
5538 *
5539 * @return True if the command was successfully delivered, false otherwise. This does
5540 * not indicate whether the command itself was successful.
5541 */
5542 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005543 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005544 return false;
5545 }
5546
5547 boolean success = true;
5548 Parcel data = null;
5549 Parcel reply = null;
5550
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005551 BufferedWriter out = null;
5552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005553 // Any uncaught exception will crash the system process
5554 try {
5555 // Find the hashcode of the window
5556 int index = parameters.indexOf(' ');
5557 if (index == -1) {
5558 index = parameters.length();
5559 }
5560 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005561 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005562
5563 // Extract the command's parameter after the window description
5564 if (index < parameters.length()) {
5565 parameters = parameters.substring(index + 1);
5566 } else {
5567 parameters = "";
5568 }
5569
5570 final WindowManagerService.WindowState window = findWindow(hashCode);
5571 if (window == null) {
5572 return false;
5573 }
5574
5575 data = Parcel.obtain();
5576 data.writeInterfaceToken("android.view.IWindow");
5577 data.writeString(command);
5578 data.writeString(parameters);
5579 data.writeInt(1);
5580 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5581
5582 reply = Parcel.obtain();
5583
5584 final IBinder binder = window.mClient.asBinder();
5585 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5586 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5587
5588 reply.readException();
5589
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005590 if (!client.isOutputShutdown()) {
5591 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5592 out.write("DONE\n");
5593 out.flush();
5594 }
5595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005596 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005597 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005598 success = false;
5599 } finally {
5600 if (data != null) {
5601 data.recycle();
5602 }
5603 if (reply != null) {
5604 reply.recycle();
5605 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005606 if (out != null) {
5607 try {
5608 out.close();
5609 } catch (IOException e) {
5610
5611 }
5612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005613 }
5614
5615 return success;
5616 }
5617
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005618 public void addWindowChangeListener(WindowChangeListener listener) {
5619 synchronized(mWindowMap) {
5620 mWindowChangeListeners.add(listener);
5621 }
5622 }
5623
5624 public void removeWindowChangeListener(WindowChangeListener listener) {
5625 synchronized(mWindowMap) {
5626 mWindowChangeListeners.remove(listener);
5627 }
5628 }
5629
5630 private void notifyWindowsChanged() {
5631 WindowChangeListener[] windowChangeListeners;
5632 synchronized(mWindowMap) {
5633 if(mWindowChangeListeners.isEmpty()) {
5634 return;
5635 }
5636 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5637 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5638 }
5639 int N = windowChangeListeners.length;
5640 for(int i = 0; i < N; i++) {
5641 windowChangeListeners[i].windowsChanged();
5642 }
5643 }
5644
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005645 private void notifyFocusChanged() {
5646 WindowChangeListener[] windowChangeListeners;
5647 synchronized(mWindowMap) {
5648 if(mWindowChangeListeners.isEmpty()) {
5649 return;
5650 }
5651 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5652 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5653 }
5654 int N = windowChangeListeners.length;
5655 for(int i = 0; i < N; i++) {
5656 windowChangeListeners[i].focusChanged();
5657 }
5658 }
5659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005660 private WindowState findWindow(int hashCode) {
5661 if (hashCode == -1) {
5662 return getFocusedWindow();
5663 }
5664
5665 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005666 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005667 final int count = windows.size();
5668
5669 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005670 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 if (System.identityHashCode(w) == hashCode) {
5672 return w;
5673 }
5674 }
5675 }
5676
5677 return null;
5678 }
5679
5680 /*
5681 * Instruct the Activity Manager to fetch the current configuration and broadcast
5682 * that to config-changed listeners if appropriate.
5683 */
5684 void sendNewConfiguration() {
5685 try {
5686 mActivityManager.updateConfiguration(null);
5687 } catch (RemoteException e) {
5688 }
5689 }
Romain Guy06882f82009-06-10 13:36:04 -07005690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005691 public Configuration computeNewConfiguration() {
5692 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005693 Configuration config = computeNewConfigurationLocked();
5694 if (config == null && mWaitingForConfig) {
5695 // Nothing changed but we are waiting for something... stop that!
5696 mWaitingForConfig = false;
5697 performLayoutAndPlaceSurfacesLocked();
5698 }
5699 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005700 }
5701 }
Romain Guy06882f82009-06-10 13:36:04 -07005702
Dianne Hackbornc485a602009-03-24 22:39:49 -07005703 Configuration computeNewConfigurationLocked() {
5704 Configuration config = new Configuration();
5705 if (!computeNewConfigurationLocked(config)) {
5706 return null;
5707 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005708 return config;
5709 }
Romain Guy06882f82009-06-10 13:36:04 -07005710
Dianne Hackbornc485a602009-03-24 22:39:49 -07005711 boolean computeNewConfigurationLocked(Configuration config) {
5712 if (mDisplay == null) {
5713 return false;
5714 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005715
5716 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005717
5718 // Use the effective "visual" dimensions based on current rotation
5719 final boolean rotated = (mRotation == Surface.ROTATION_90
5720 || mRotation == Surface.ROTATION_270);
5721 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5722 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5723
Dianne Hackbornc485a602009-03-24 22:39:49 -07005724 int orientation = Configuration.ORIENTATION_SQUARE;
5725 if (dw < dh) {
5726 orientation = Configuration.ORIENTATION_PORTRAIT;
5727 } else if (dw > dh) {
5728 orientation = Configuration.ORIENTATION_LANDSCAPE;
5729 }
5730 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005731
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005732 DisplayMetrics dm = new DisplayMetrics();
5733 mDisplay.getMetrics(dm);
5734 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5735
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005736 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005737 // Note we only do this once because at this point we don't
5738 // expect the screen to change in this way at runtime, and want
5739 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005740 int longSize = dw;
5741 int shortSize = dh;
5742 if (longSize < shortSize) {
5743 int tmp = longSize;
5744 longSize = shortSize;
5745 shortSize = tmp;
5746 }
5747 longSize = (int)(longSize/dm.density);
5748 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005749
Dianne Hackborn723738c2009-06-25 19:48:04 -07005750 // These semi-magic numbers define our compatibility modes for
5751 // applications with different screens. Don't change unless you
5752 // make sure to test lots and lots of apps!
5753 if (longSize < 470) {
5754 // This is shorter than an HVGA normal density screen (which
5755 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005756 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5757 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005758 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005759 // What size is this screen screen?
5760 if (longSize >= 800 && shortSize >= 600) {
5761 // SVGA or larger screens at medium density are the point
5762 // at which we consider it to be an extra large screen.
5763 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005764 } else if (longSize >= 530 && shortSize >= 400) {
5765 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005766 // at which we consider it to be a large screen.
5767 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5768 } else {
5769 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Dianne Hackborne97a12e2011-01-29 13:22:02 -08005770 }
5771
5772 // If this screen is wider than normal HVGA, or taller
5773 // than FWVGA, then for old apps we want to run in size
5774 // compatibility mode.
5775 if (shortSize > 321 || longSize > 570) {
5776 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005778
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005779 // Is this a long screen?
5780 if (((longSize*3)/5) >= (shortSize-1)) {
5781 // Anything wider than WVGA (5:3) is considering to be long.
5782 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5783 } else {
5784 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5785 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005786 }
5787 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005788 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005789
Jeff Brown597eec82011-01-31 17:12:25 -08005790 // Determine whether a hard keyboard is available and enabled.
Jeff Brown2992ea72011-01-28 22:04:14 -08005791 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5792 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5793 mHardKeyboardAvailable = hardKeyboardAvailable;
5794 mHardKeyboardEnabled = hardKeyboardAvailable;
5795
5796 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5797 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5798 }
5799 if (!mHardKeyboardEnabled) {
5800 config.keyboard = Configuration.KEYBOARD_NOKEYS;
Jeff Brown2992ea72011-01-28 22:04:14 -08005801 }
Jeff Brown597eec82011-01-31 17:12:25 -08005802
5803 // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden
5804 // based on whether a hard or soft keyboard is present, whether navigation keys
5805 // are present and the lid switch state.
5806 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5807 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5808 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
5809 mPolicy.adjustConfigurationLw(config);
Dianne Hackbornc485a602009-03-24 22:39:49 -07005810 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005812
Jeff Brown2992ea72011-01-28 22:04:14 -08005813 public boolean isHardKeyboardAvailable() {
5814 synchronized (mWindowMap) {
5815 return mHardKeyboardAvailable;
5816 }
5817 }
5818
5819 public boolean isHardKeyboardEnabled() {
5820 synchronized (mWindowMap) {
5821 return mHardKeyboardEnabled;
5822 }
5823 }
5824
5825 public void setHardKeyboardEnabled(boolean enabled) {
5826 synchronized (mWindowMap) {
5827 if (mHardKeyboardEnabled != enabled) {
5828 mHardKeyboardEnabled = enabled;
5829 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5830 }
5831 }
5832 }
5833
5834 public void setOnHardKeyboardStatusChangeListener(
5835 OnHardKeyboardStatusChangeListener listener) {
5836 synchronized (mWindowMap) {
5837 mHardKeyboardStatusChangeListener = listener;
5838 }
5839 }
5840
5841 void notifyHardKeyboardStatusChange() {
5842 final boolean available, enabled;
5843 final OnHardKeyboardStatusChangeListener listener;
5844 synchronized (mWindowMap) {
5845 listener = mHardKeyboardStatusChangeListener;
5846 available = mHardKeyboardAvailable;
5847 enabled = mHardKeyboardEnabled;
5848 }
5849 if (listener != null) {
5850 listener.onHardKeyboardStatusChange(available, enabled);
5851 }
5852 }
5853
Christopher Tatea53146c2010-09-07 11:57:52 -07005854 // -------------------------------------------------------------
5855 // Drag and drop
5856 // -------------------------------------------------------------
5857
5858 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005859 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005860 if (DEBUG_DRAG) {
5861 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005862 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005863 + " asbinder=" + window.asBinder());
5864 }
5865
5866 final int callerPid = Binder.getCallingPid();
5867 final long origId = Binder.clearCallingIdentity();
5868 IBinder token = null;
5869
5870 try {
5871 synchronized (mWindowMap) {
5872 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005873 if (mDragState == null) {
5874 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5875 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5876 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005877 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005878 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005879 // TODO: preserve flags param in DragState
5880 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005881 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005882 token = mDragState.mToken = new Binder();
5883
5884 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005885 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5886 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005887 mH.sendMessageDelayed(msg, 5000);
5888 } else {
5889 Slog.w(TAG, "Drag already in progress");
5890 }
5891 } catch (Surface.OutOfResourcesException e) {
5892 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5893 if (mDragState != null) {
5894 mDragState.reset();
5895 mDragState = null;
5896 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005897 }
5898 }
5899 } finally {
5900 Binder.restoreCallingIdentity(origId);
5901 }
5902
5903 return token;
5904 }
5905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005906 // -------------------------------------------------------------
5907 // Input Events and Focus Management
5908 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005909
Jeff Brown349703e2010-06-22 01:27:15 -07005910 InputMonitor mInputMonitor = new InputMonitor();
5911
5912 /* Tracks the progress of input dispatch and ensures that input dispatch state
5913 * is kept in sync with changes in window focus, visibility, registration, and
5914 * other relevant Window Manager state transitions. */
5915 final class InputMonitor {
5916 // Current window with input focus for keys and other non-touch events. May be null.
5917 private WindowState mInputFocus;
5918
5919 // When true, prevents input dispatch from proceeding until set to false again.
5920 private boolean mInputDispatchFrozen;
5921
5922 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5923 private boolean mInputDispatchEnabled = true;
5924
Jeff Brown3a22cd92011-01-21 13:59:04 -08005925 // When true, need to call updateInputWindowsLw().
5926 private boolean mUpdateInputWindowsNeeded = true;
5927
Jeff Brown349703e2010-06-22 01:27:15 -07005928 // Temporary list of windows information to provide to the input dispatcher.
5929 private InputWindowList mTempInputWindows = new InputWindowList();
5930
5931 // Temporary input application object to provide to the input dispatcher.
5932 private InputApplication mTempInputApplication = new InputApplication();
5933
Jeff Brownb09abc12011-01-13 21:08:27 -08005934 // Set to true when the first input device configuration change notification
5935 // is received to indicate that the input devices are ready.
5936 private final Object mInputDevicesReadyMonitor = new Object();
5937 private boolean mInputDevicesReady;
5938
Jeff Brown349703e2010-06-22 01:27:15 -07005939 /* Notifies the window manager about a broken input channel.
5940 *
5941 * Called by the InputManager.
5942 */
Jeff Brown928e0542011-01-10 11:17:36 -08005943 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5944 if (inputWindowHandle == null) {
5945 return;
5946 }
5947
Jeff Brown349703e2010-06-22 01:27:15 -07005948 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005949 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005950 Slog.i(TAG, "WINDOW DIED " + windowState);
5951 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005952 }
5953 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005954
Jeff Brown519e0242010-09-15 15:18:56 -07005955 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005956 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005957 *
5958 * Called by the InputManager.
5959 */
Jeff Brown928e0542011-01-10 11:17:36 -08005960 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5961 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005962 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005963 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005964 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005965 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005966 if (windowState != null) {
5967 Slog.i(TAG, "Input event dispatching timed out sending to "
5968 + windowState.mAttrs.getTitle());
5969 appWindowToken = windowState.mAppToken;
5970 }
Jeff Brown349703e2010-06-22 01:27:15 -07005971 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005972 }
5973
Jeff Brown928e0542011-01-10 11:17:36 -08005974 if (appWindowToken == null && inputApplicationHandle != null) {
5975 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005976 Slog.i(TAG, "Input event dispatching timed out sending to application "
5977 + appWindowToken.stringName);
5978 }
Jeff Brown349703e2010-06-22 01:27:15 -07005979
Jeff Brown519e0242010-09-15 15:18:56 -07005980 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005981 try {
5982 // Notify the activity manager about the timeout and let it decide whether
5983 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005984 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005985 if (! abort) {
5986 // The activity manager declined to abort dispatching.
5987 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005988 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005989 }
Jeff Brown349703e2010-06-22 01:27:15 -07005990 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005991 }
5992 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005993 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005994 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005995
Chris Tatea32dcf72010-10-14 12:13:50 -07005996 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005997 final InputWindow inputWindow = windowList.add();
5998 inputWindow.inputChannel = mDragState.mServerChannel;
5999 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08006000 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07006001 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
6002 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6003 inputWindow.visible = true;
6004 inputWindow.canReceiveKeys = false;
6005 inputWindow.hasFocus = true;
6006 inputWindow.hasWallpaper = false;
6007 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07006008 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006009 inputWindow.ownerPid = Process.myPid();
6010 inputWindow.ownerUid = Process.myUid();
6011
6012 // The drag window covers the entire display
6013 inputWindow.frameLeft = 0;
6014 inputWindow.frameTop = 0;
6015 inputWindow.frameRight = mDisplay.getWidth();
6016 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07006017
Jeff Brownfbf09772011-01-16 14:06:57 -08006018 // The drag window cannot receive new touches.
6019 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07006020 }
6021
Jeff Brown3a22cd92011-01-21 13:59:04 -08006022 public void setUpdateInputWindowsNeededLw() {
6023 mUpdateInputWindowsNeeded = true;
6024 }
6025
Jeff Brown349703e2010-06-22 01:27:15 -07006026 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08006027 public void updateInputWindowsLw(boolean force) {
6028 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006029 return;
6030 }
6031 mUpdateInputWindowsNeeded = false;
6032
Jeff Brown349703e2010-06-22 01:27:15 -07006033 // Populate the input window list with information about all of the windows that
6034 // could potentially receive input.
6035 // As an optimization, we could try to prune the list of windows but this turns
6036 // out to be difficult because only the native code knows for sure which window
6037 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07006038 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07006039
6040 // If there's a drag in flight, provide a pseudowindow to catch drag input
6041 final boolean inDrag = (mDragState != null);
6042 if (inDrag) {
6043 if (DEBUG_DRAG) {
6044 Log.d(TAG, "Inserting drag window");
6045 }
Chris Tatea32dcf72010-10-14 12:13:50 -07006046 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07006047 }
6048
Jeff Brown7fbdc842010-06-17 20:52:56 -07006049 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07006050 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006051 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07006052 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07006053 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07006054 continue;
6055 }
6056
Jeff Brown349703e2010-06-22 01:27:15 -07006057 final int flags = child.mAttrs.flags;
6058 final int type = child.mAttrs.type;
6059
6060 final boolean hasFocus = (child == mInputFocus);
6061 final boolean isVisible = child.isVisibleLw();
6062 final boolean hasWallpaper = (child == mWallpaperTarget)
6063 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07006064
6065 // If there's a drag in progress and 'child' is a potential drop target,
6066 // make sure it's been told about the drag
6067 if (inDrag && isVisible) {
6068 mDragState.sendDragStartedIfNeededLw(child);
6069 }
6070
Jeff Brown349703e2010-06-22 01:27:15 -07006071 // Add a window to our list of input windows.
6072 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006073 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006074 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006075 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006076 inputWindow.layoutParamsFlags = flags;
6077 inputWindow.layoutParamsType = type;
6078 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6079 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006080 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006081 inputWindow.hasFocus = hasFocus;
6082 inputWindow.hasWallpaper = hasWallpaper;
6083 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006084 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006085 inputWindow.ownerPid = child.mSession.mPid;
6086 inputWindow.ownerUid = child.mSession.mUid;
6087
6088 final Rect frame = child.mFrame;
6089 inputWindow.frameLeft = frame.left;
6090 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006091 inputWindow.frameRight = frame.right;
6092 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006093
6094 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006095 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006096
Jeff Brown349703e2010-06-22 01:27:15 -07006097 // Send windows to native code.
6098 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006099
Jeff Brown349703e2010-06-22 01:27:15 -07006100 // Clear the list in preparation for the next round.
6101 // Also avoids keeping InputChannel objects referenced unnecessarily.
6102 mTempInputWindows.clear();
6103 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006104
6105 /* Notifies that the input device configuration has changed. */
6106 public void notifyConfigurationChanged() {
6107 sendNewConfiguration();
6108
6109 synchronized (mInputDevicesReadyMonitor) {
6110 if (!mInputDevicesReady) {
6111 mInputDevicesReady = true;
6112 mInputDevicesReadyMonitor.notifyAll();
6113 }
6114 }
6115 }
6116
6117 /* Waits until the built-in input devices have been configured. */
6118 public boolean waitForInputDevicesReady(long timeoutMillis) {
6119 synchronized (mInputDevicesReadyMonitor) {
6120 if (!mInputDevicesReady) {
6121 try {
6122 mInputDevicesReadyMonitor.wait(timeoutMillis);
6123 } catch (InterruptedException ex) {
6124 }
6125 }
6126 return mInputDevicesReady;
6127 }
6128 }
6129
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006130 /* Notifies that the lid switch changed state. */
6131 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6132 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6133 }
6134
Jeff Brown349703e2010-06-22 01:27:15 -07006135 /* Provides an opportunity for the window manager policy to intercept early key
6136 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006137 public int interceptKeyBeforeQueueing(
6138 KeyEvent event, int policyFlags, boolean isScreenOn) {
6139 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006140 }
6141
6142 /* Provides an opportunity for the window manager policy to process a key before
6143 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006144 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006145 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006146 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006147 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006148 }
6149
Jeff Brown3915bb82010-11-05 15:02:16 -07006150 /* Provides an opportunity for the window manager policy to process a key that
6151 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006152 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006153 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006154 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006155 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006156 }
6157
Jeff Brown349703e2010-06-22 01:27:15 -07006158 /* Called when the current input focus changes.
6159 * Layer assignment is assumed to be complete by the time this is called.
6160 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006161 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006162 if (DEBUG_INPUT) {
6163 Slog.d(TAG, "Input focus has changed to " + newWindow);
6164 }
6165
6166 if (newWindow != mInputFocus) {
6167 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006168 // Displaying a window implicitly causes dispatching to be unpaused.
6169 // This is to protect against bugs if someone pauses dispatching but
6170 // forgets to resume.
6171 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006172 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006173
Jeff Brown349703e2010-06-22 01:27:15 -07006174 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006175 setUpdateInputWindowsNeededLw();
6176
6177 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006178 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006179 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006180 }
6181 }
6182
Jeff Brown349703e2010-06-22 01:27:15 -07006183 public void setFocusedAppLw(AppWindowToken newApp) {
6184 // Focused app has changed.
6185 if (newApp == null) {
6186 mInputManager.setFocusedApplication(null);
6187 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006188 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006189 mTempInputApplication.name = newApp.toString();
6190 mTempInputApplication.dispatchingTimeoutNanos =
6191 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006192
Jeff Brown349703e2010-06-22 01:27:15 -07006193 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006194
6195 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006196 }
6197 }
6198
Jeff Brown349703e2010-06-22 01:27:15 -07006199 public void pauseDispatchingLw(WindowToken window) {
6200 if (! window.paused) {
6201 if (DEBUG_INPUT) {
6202 Slog.v(TAG, "Pausing WindowToken " + window);
6203 }
6204
6205 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006206 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006207 }
6208 }
6209
6210 public void resumeDispatchingLw(WindowToken window) {
6211 if (window.paused) {
6212 if (DEBUG_INPUT) {
6213 Slog.v(TAG, "Resuming WindowToken " + window);
6214 }
6215
6216 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006217 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006218 }
6219 }
6220
6221 public void freezeInputDispatchingLw() {
6222 if (! mInputDispatchFrozen) {
6223 if (DEBUG_INPUT) {
6224 Slog.v(TAG, "Freezing input dispatching");
6225 }
6226
6227 mInputDispatchFrozen = true;
6228 updateInputDispatchModeLw();
6229 }
6230 }
6231
6232 public void thawInputDispatchingLw() {
6233 if (mInputDispatchFrozen) {
6234 if (DEBUG_INPUT) {
6235 Slog.v(TAG, "Thawing input dispatching");
6236 }
6237
6238 mInputDispatchFrozen = false;
6239 updateInputDispatchModeLw();
6240 }
6241 }
6242
6243 public void setEventDispatchingLw(boolean enabled) {
6244 if (mInputDispatchEnabled != enabled) {
6245 if (DEBUG_INPUT) {
6246 Slog.v(TAG, "Setting event dispatching to " + enabled);
6247 }
6248
6249 mInputDispatchEnabled = enabled;
6250 updateInputDispatchModeLw();
6251 }
6252 }
6253
6254 private void updateInputDispatchModeLw() {
6255 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6256 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006259 public void pauseKeyDispatching(IBinder _token) {
6260 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6261 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006262 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006263 }
6264
6265 synchronized (mWindowMap) {
6266 WindowToken token = mTokenMap.get(_token);
6267 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006268 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006269 }
6270 }
6271 }
6272
6273 public void resumeKeyDispatching(IBinder _token) {
6274 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6275 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006276 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 }
6278
6279 synchronized (mWindowMap) {
6280 WindowToken token = mTokenMap.get(_token);
6281 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006282 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006283 }
6284 }
6285 }
6286
6287 public void setEventDispatching(boolean enabled) {
6288 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6289 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006290 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 }
6292
6293 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006294 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 }
6296 }
Romain Guy06882f82009-06-10 13:36:04 -07006297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006298 /**
6299 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006300 * Even when sync is false, this method may block while waiting for current
6301 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006302 *
6303 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 * {@link SystemClock#uptimeMillis()} as the timebase.)
6305 * @param sync If true, wait for the event to be completed before returning to the caller.
6306 * @return Returns true if event was dispatched, false if it was dropped for any reason
6307 */
6308 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6309 long downTime = ev.getDownTime();
6310 long eventTime = ev.getEventTime();
6311
6312 int action = ev.getAction();
6313 int code = ev.getKeyCode();
6314 int repeatCount = ev.getRepeatCount();
6315 int metaState = ev.getMetaState();
6316 int deviceId = ev.getDeviceId();
6317 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006318 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006319 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006320
6321 if (source == InputDevice.SOURCE_UNKNOWN) {
6322 source = InputDevice.SOURCE_KEYBOARD;
6323 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324
6325 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6326 if (downTime == 0) downTime = eventTime;
6327
6328 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006329 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006330
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006331 final int pid = Binder.getCallingPid();
6332 final int uid = Binder.getCallingUid();
6333 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006334
Jeff Brownbbda99d2010-07-28 15:48:59 -07006335 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6336 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6337 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6338 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006339
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006340 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006341 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 }
6343
6344 /**
6345 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006346 * Even when sync is false, this method may block while waiting for current
6347 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006348 *
6349 * @param ev A motion event describing the pointer (touch) action. (As noted in
6350 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 * {@link SystemClock#uptimeMillis()} as the timebase.)
6352 * @param sync If true, wait for the event to be completed before returning to the caller.
6353 * @return Returns true if event was dispatched, false if it was dropped for any reason
6354 */
6355 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006356 final int pid = Binder.getCallingPid();
6357 final int uid = Binder.getCallingUid();
6358 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006359
Jeff Brownc5ed5912010-07-14 18:48:53 -07006360 MotionEvent newEvent = MotionEvent.obtain(ev);
6361 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6362 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6363 }
6364
Jeff Brownbbda99d2010-07-28 15:48:59 -07006365 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6366 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6367 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6368 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006369
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006370 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006371 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 }
Romain Guy06882f82009-06-10 13:36:04 -07006373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 /**
6375 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006376 * Even when sync is false, this method may block while waiting for current
6377 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006378 *
6379 * @param ev A motion event describing the trackball action. (As noted in
6380 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006381 * {@link SystemClock#uptimeMillis()} as the timebase.)
6382 * @param sync If true, wait for the event to be completed before returning to the caller.
6383 * @return Returns true if event was dispatched, false if it was dropped for any reason
6384 */
6385 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006386 final int pid = Binder.getCallingPid();
6387 final int uid = Binder.getCallingUid();
6388 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006389
Jeff Brownc5ed5912010-07-14 18:48:53 -07006390 MotionEvent newEvent = MotionEvent.obtain(ev);
6391 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6392 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6393 }
6394
Jeff Brownbbda99d2010-07-28 15:48:59 -07006395 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6396 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6397 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6398 INJECTION_TIMEOUT_MILLIS);
6399
6400 Binder.restoreCallingIdentity(ident);
6401 return reportInjectionResult(result);
6402 }
6403
6404 /**
6405 * Inject an input event into the UI without waiting for dispatch to commence.
6406 * This variant is useful for fire-and-forget input event injection. It does not
6407 * block any longer than it takes to enqueue the input event.
6408 *
6409 * @param ev An input event. (Be sure to set the input source correctly.)
6410 * @return Returns true if event was dispatched, false if it was dropped for any reason
6411 */
6412 public boolean injectInputEventNoWait(InputEvent ev) {
6413 final int pid = Binder.getCallingPid();
6414 final int uid = Binder.getCallingUid();
6415 final long ident = Binder.clearCallingIdentity();
6416
6417 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6418 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6419 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006420
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006421 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006422 return reportInjectionResult(result);
6423 }
6424
6425 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006426 switch (result) {
6427 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6428 Slog.w(TAG, "Input event injection permission denied.");
6429 throw new SecurityException(
6430 "Injecting to another application requires INJECT_EVENTS permission");
6431 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006432 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006433 return true;
6434 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6435 Slog.w(TAG, "Input event injection timed out.");
6436 return false;
6437 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6438 default:
6439 Slog.w(TAG, "Input event injection failed.");
6440 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 }
Romain Guy06882f82009-06-10 13:36:04 -07006443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006444 private WindowState getFocusedWindow() {
6445 synchronized (mWindowMap) {
6446 return getFocusedWindowLocked();
6447 }
6448 }
6449
6450 private WindowState getFocusedWindowLocked() {
6451 return mCurrentFocus;
6452 }
Romain Guy06882f82009-06-10 13:36:04 -07006453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006455 if (!mInputMonitor.waitForInputDevicesReady(
6456 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6457 Slog.w(TAG, "Devices still not ready after waiting "
6458 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6459 + " milliseconds before attempting to detect safe mode.");
6460 }
6461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 mSafeMode = mPolicy.detectSafeMode();
6463 return mSafeMode;
6464 }
Romain Guy06882f82009-06-10 13:36:04 -07006465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006467 synchronized(mWindowMap) {
6468 if (mDisplay != null) {
6469 throw new IllegalStateException("Display already initialized");
6470 }
6471 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6472 mDisplay = wm.getDefaultDisplay();
6473 mInitialDisplayWidth = mDisplay.getWidth();
6474 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006475 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6476 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006477 }
6478
6479 try {
6480 mActivityManager.updateConfiguration(null);
6481 } catch (RemoteException e) {
6482 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006483
6484 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006485 }
6486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 // -------------------------------------------------------------
6488 // Client Session State
6489 // -------------------------------------------------------------
6490
6491 private final class Session extends IWindowSession.Stub
6492 implements IBinder.DeathRecipient {
6493 final IInputMethodClient mClient;
6494 final IInputContext mInputContext;
6495 final int mUid;
6496 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006497 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 SurfaceSession mSurfaceSession;
6499 int mNumWindow = 0;
6500 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 public Session(IInputMethodClient client, IInputContext inputContext) {
6503 mClient = client;
6504 mInputContext = inputContext;
6505 mUid = Binder.getCallingUid();
6506 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006507 StringBuilder sb = new StringBuilder();
6508 sb.append("Session{");
6509 sb.append(Integer.toHexString(System.identityHashCode(this)));
6510 sb.append(" uid ");
6511 sb.append(mUid);
6512 sb.append("}");
6513 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 synchronized (mWindowMap) {
6516 if (mInputMethodManager == null && mHaveInputMethods) {
6517 IBinder b = ServiceManager.getService(
6518 Context.INPUT_METHOD_SERVICE);
6519 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6520 }
6521 }
6522 long ident = Binder.clearCallingIdentity();
6523 try {
6524 // Note: it is safe to call in to the input method manager
6525 // here because we are not holding our lock.
6526 if (mInputMethodManager != null) {
6527 mInputMethodManager.addClient(client, inputContext,
6528 mUid, mPid);
6529 } else {
6530 client.setUsingInputMethod(false);
6531 }
6532 client.asBinder().linkToDeath(this, 0);
6533 } catch (RemoteException e) {
6534 // The caller has died, so we can just forget about this.
6535 try {
6536 if (mInputMethodManager != null) {
6537 mInputMethodManager.removeClient(client);
6538 }
6539 } catch (RemoteException ee) {
6540 }
6541 } finally {
6542 Binder.restoreCallingIdentity(ident);
6543 }
6544 }
Romain Guy06882f82009-06-10 13:36:04 -07006545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006546 @Override
6547 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6548 throws RemoteException {
6549 try {
6550 return super.onTransact(code, data, reply, flags);
6551 } catch (RuntimeException e) {
6552 // Log all 'real' exceptions thrown to the caller
6553 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006554 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006555 }
6556 throw e;
6557 }
6558 }
6559
6560 public void binderDied() {
6561 // Note: it is safe to call in to the input method manager
6562 // here because we are not holding our lock.
6563 try {
6564 if (mInputMethodManager != null) {
6565 mInputMethodManager.removeClient(mClient);
6566 }
6567 } catch (RemoteException e) {
6568 }
6569 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006570 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 mClientDead = true;
6572 killSessionLocked();
6573 }
6574 }
6575
6576 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006577 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6578 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6579 outInputChannel);
6580 }
6581
6582 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006584 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 }
Romain Guy06882f82009-06-10 13:36:04 -07006586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 public void remove(IWindow window) {
6588 removeWindow(this, window);
6589 }
Romain Guy06882f82009-06-10 13:36:04 -07006590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006591 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6592 int requestedWidth, int requestedHeight, int viewFlags,
6593 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006594 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006595 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6596 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006598 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006599 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6600 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006601 }
Romain Guy06882f82009-06-10 13:36:04 -07006602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 public void setTransparentRegion(IWindow window, Region region) {
6604 setTransparentRegionWindow(this, window, region);
6605 }
Romain Guy06882f82009-06-10 13:36:04 -07006606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006607 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006608 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006610 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006611 }
Romain Guy06882f82009-06-10 13:36:04 -07006612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6614 getWindowDisplayFrame(this, window, outDisplayFrame);
6615 }
Romain Guy06882f82009-06-10 13:36:04 -07006616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006617 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006618 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 TAG, "IWindow finishDrawing called for " + window);
6620 finishDrawingWindow(this, window);
6621 }
6622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006623 public void setInTouchMode(boolean mode) {
6624 synchronized(mWindowMap) {
6625 mInTouchMode = mode;
6626 }
6627 }
6628
6629 public boolean getInTouchMode() {
6630 synchronized(mWindowMap) {
6631 return mInTouchMode;
6632 }
6633 }
6634
6635 public boolean performHapticFeedback(IWindow window, int effectId,
6636 boolean always) {
6637 synchronized(mWindowMap) {
6638 long ident = Binder.clearCallingIdentity();
6639 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006640 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006641 windowForClientLocked(this, window, true),
6642 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006643 } finally {
6644 Binder.restoreCallingIdentity(ident);
6645 }
6646 }
6647 }
Romain Guy06882f82009-06-10 13:36:04 -07006648
Christopher Tatea53146c2010-09-07 11:57:52 -07006649 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006650 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006651 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006652 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006653 width, height, outSurface);
6654 }
6655
6656 public boolean performDrag(IWindow window, IBinder dragToken,
6657 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6658 ClipData data) {
6659 if (DEBUG_DRAG) {
6660 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6661 }
6662
6663 synchronized (mWindowMap) {
6664 if (mDragState == null) {
6665 Slog.w(TAG, "No drag prepared");
6666 throw new IllegalStateException("performDrag() without prepareDrag()");
6667 }
6668
6669 if (dragToken != mDragState.mToken) {
6670 Slog.w(TAG, "Performing mismatched drag");
6671 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6672 }
6673
6674 WindowState callingWin = windowForClientLocked(null, window, false);
6675 if (callingWin == null) {
6676 Slog.w(TAG, "Bad requesting window " + window);
6677 return false; // !!! TODO: throw here?
6678 }
6679
6680 // !!! TODO: if input is not still focused on the initiating window, fail
6681 // the drag initiation (e.g. an alarm window popped up just as the application
6682 // called performDrag()
6683
6684 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6685
Christopher Tate2c095f32010-10-04 14:13:40 -07006686 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6687 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006688
Chris Tateb478f462010-10-15 16:02:26 -07006689 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6690 // the actual drag event dispatch stuff in the dragstate
6691
Christopher Tatea53146c2010-09-07 11:57:52 -07006692 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006693 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006694 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6695 mDragState.mServerChannel)) {
6696 Slog.e(TAG, "Unable to transfer touch focus");
6697 mDragState.unregister();
6698 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006699 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006700 return false;
6701 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006702
6703 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006704 mDragState.mCurrentX = touchX;
6705 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006706 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006707
6708 // remember the thumb offsets for later
6709 mDragState.mThumbOffsetX = thumbCenterX;
6710 mDragState.mThumbOffsetY = thumbCenterY;
6711
6712 // Make the surface visible at the proper location
6713 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006714 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006715 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006716 try {
6717 surface.setPosition((int)(touchX - thumbCenterX),
6718 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006719 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006720 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006721 surface.show();
6722 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006723 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006724 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006725 }
6726 }
6727
6728 return true; // success!
6729 }
6730
Chris Tated4533f142010-10-19 15:15:08 -07006731 public void reportDropResult(IWindow window, boolean consumed) {
6732 IBinder token = window.asBinder();
6733 if (DEBUG_DRAG) {
6734 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6735 }
6736
6737 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006738 long ident = Binder.clearCallingIdentity();
6739 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006740 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006741 Slog.w(TAG, "Invalid drop-result claim by " + window);
6742 throw new IllegalStateException("reportDropResult() by non-recipient");
6743 }
6744
6745 // The right window has responded, even if it's no longer around,
6746 // so be sure to halt the timeout even if the later WindowState
6747 // lookup fails.
6748 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6749 WindowState callingWin = windowForClientLocked(null, window, false);
6750 if (callingWin == null) {
6751 Slog.w(TAG, "Bad result-reporting window " + window);
6752 return; // !!! TODO: throw here?
6753 }
6754
6755 mDragState.mDragResult = consumed;
6756 mDragState.endDragLw();
6757 } finally {
6758 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006759 }
Chris Tated4533f142010-10-19 15:15:08 -07006760 }
6761 }
6762
Christopher Tatea53146c2010-09-07 11:57:52 -07006763 public void dragRecipientEntered(IWindow window) {
6764 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006765 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006766 }
6767 }
6768
6769 public void dragRecipientExited(IWindow window) {
6770 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006771 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006772 }
6773 }
6774
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006775 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006776 synchronized(mWindowMap) {
6777 long ident = Binder.clearCallingIdentity();
6778 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006779 setWindowWallpaperPositionLocked(
6780 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006781 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006782 } finally {
6783 Binder.restoreCallingIdentity(ident);
6784 }
6785 }
6786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006787
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006788 public void wallpaperOffsetsComplete(IBinder window) {
6789 WindowManagerService.this.wallpaperOffsetsComplete(window);
6790 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006791
Dianne Hackborn75804932009-10-20 20:15:20 -07006792 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6793 int z, Bundle extras, boolean sync) {
6794 synchronized(mWindowMap) {
6795 long ident = Binder.clearCallingIdentity();
6796 try {
6797 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006798 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006799 action, x, y, z, extras, sync);
6800 } finally {
6801 Binder.restoreCallingIdentity(ident);
6802 }
6803 }
6804 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006805
Dianne Hackborn75804932009-10-20 20:15:20 -07006806 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6807 WindowManagerService.this.wallpaperCommandComplete(window, result);
6808 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 void windowAddedLocked() {
6811 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006812 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006813 TAG, "First window added to " + this + ", creating SurfaceSession");
6814 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006815 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006816 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006817 mSessions.add(this);
6818 }
6819 mNumWindow++;
6820 }
6821
6822 void windowRemovedLocked() {
6823 mNumWindow--;
6824 killSessionLocked();
6825 }
Romain Guy06882f82009-06-10 13:36:04 -07006826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 void killSessionLocked() {
6828 if (mNumWindow <= 0 && mClientDead) {
6829 mSessions.remove(this);
6830 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006831 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006832 TAG, "Last window removed from " + this
6833 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006834 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006835 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 try {
6837 mSurfaceSession.kill();
6838 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006839 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 + mSurfaceSession + " in session " + this
6841 + ": " + e.toString());
6842 }
6843 mSurfaceSession = null;
6844 }
6845 }
6846 }
Romain Guy06882f82009-06-10 13:36:04 -07006847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006849 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6850 pw.print(" mClientDead="); pw.print(mClientDead);
6851 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 }
6853
6854 @Override
6855 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006856 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 }
6858 }
6859
6860 // -------------------------------------------------------------
6861 // Client Window State
6862 // -------------------------------------------------------------
6863
6864 private final class WindowState implements WindowManagerPolicy.WindowState {
6865 final Session mSession;
6866 final IWindow mClient;
6867 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006868 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 AppWindowToken mAppToken;
6870 AppWindowToken mTargetAppToken;
6871 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6872 final DeathRecipient mDeathRecipient;
6873 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006874 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 final int mBaseLayer;
6876 final int mSubLayer;
6877 final boolean mLayoutAttached;
6878 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006879 final boolean mIsWallpaper;
6880 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006881 int mViewVisibility;
6882 boolean mPolicyVisibility = true;
6883 boolean mPolicyVisibilityAfterAnim = true;
6884 boolean mAppFreezing;
6885 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006886 boolean mReportDestroySurface;
6887 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006888 boolean mAttachedHidden; // is our parent window hidden?
6889 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006890 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 int mRequestedWidth;
6892 int mRequestedHeight;
6893 int mLastRequestedWidth;
6894 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006895 int mLayer;
6896 int mAnimLayer;
6897 int mLastLayer;
6898 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006899 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006900 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006902 int mLayoutSeq = -1;
6903
6904 Configuration mConfiguration = null;
6905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006906 // Actual frame shown on-screen (may be modified by animation)
6907 final Rect mShownFrame = new Rect();
6908 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006910 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006911 * Set when we have changed the size of the surface, to know that
6912 * we must tell them application to resize (and thus redraw itself).
6913 */
6914 boolean mSurfaceResized;
6915
6916 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006917 * Insets that determine the actually visible area
6918 */
6919 final Rect mVisibleInsets = new Rect();
6920 final Rect mLastVisibleInsets = new Rect();
6921 boolean mVisibleInsetsChanged;
6922
6923 /**
6924 * Insets that are covered by system windows
6925 */
6926 final Rect mContentInsets = new Rect();
6927 final Rect mLastContentInsets = new Rect();
6928 boolean mContentInsetsChanged;
6929
6930 /**
6931 * Set to true if we are waiting for this window to receive its
6932 * given internal insets before laying out other windows based on it.
6933 */
6934 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 /**
6937 * These are the content insets that were given during layout for
6938 * this window, to be applied to windows behind it.
6939 */
6940 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006942 /**
6943 * These are the visible insets that were given during layout for
6944 * this window, to be applied to windows behind it.
6945 */
6946 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006948 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006949 * This is the given touchable area relative to the window frame, or null if none.
6950 */
6951 final Region mGivenTouchableRegion = new Region();
6952
6953 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006954 * Flag indicating whether the touchable region should be adjusted by
6955 * the visible insets; if false the area outside the visible insets is
6956 * NOT touchable, so we must use those to adjust the frame during hit
6957 * tests.
6958 */
6959 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006961 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006962 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6964 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6965 float mHScale=1, mVScale=1;
6966 float mLastHScale=1, mLastVScale=1;
6967 final Matrix mTmpMatrix = new Matrix();
6968
6969 // "Real" frame that the application sees.
6970 final Rect mFrame = new Rect();
6971 final Rect mLastFrame = new Rect();
6972
6973 final Rect mContainingFrame = new Rect();
6974 final Rect mDisplayFrame = new Rect();
6975 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006976 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 final Rect mVisibleFrame = new Rect();
6978
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006979 boolean mContentChanged;
6980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 float mShownAlpha = 1;
6982 float mAlpha = 1;
6983 float mLastAlpha = 1;
6984
6985 // Set to true if, when the window gets displayed, it should perform
6986 // an enter animation.
6987 boolean mEnterAnimationPending;
6988
6989 // Currently running animation.
6990 boolean mAnimating;
6991 boolean mLocalAnimating;
6992 Animation mAnimation;
6993 boolean mAnimationIsEntrance;
6994 boolean mHasTransformation;
6995 boolean mHasLocalTransformation;
6996 final Transformation mTransformation = new Transformation();
6997
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006998 // If a window showing a wallpaper: the requested offset for the
6999 // wallpaper; if a wallpaper window: the currently applied offset.
7000 float mWallpaperX = -1;
7001 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007002
7003 // If a window showing a wallpaper: what fraction of the offset
7004 // range corresponds to a full virtual screen.
7005 float mWallpaperXStep = -1;
7006 float mWallpaperYStep = -1;
7007
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007008 // Wallpaper windows: pixels offset based on above variables.
7009 int mXOffset;
7010 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007012 // This is set after IWindowSession.relayout() has been called at
7013 // least once for the window. It allows us to detect the situation
7014 // where we don't yet have a surface, but should have one soon, so
7015 // we can give the window focus before waiting for the relayout.
7016 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 // This is set after the Surface has been created but before the
7019 // window has been drawn. During this time the surface is hidden.
7020 boolean mDrawPending;
7021
7022 // This is set after the window has finished drawing for the first
7023 // time but before its surface is shown. The surface will be
7024 // displayed when the next layout is run.
7025 boolean mCommitDrawPending;
7026
7027 // This is set during the time after the window's drawing has been
7028 // committed, and before its surface is actually shown. It is used
7029 // to delay showing the surface until all windows in a token are ready
7030 // to be shown.
7031 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007033 // Set when the window has been shown in the screen the first time.
7034 boolean mHasDrawn;
7035
7036 // Currently running an exit animation?
7037 boolean mExiting;
7038
7039 // Currently on the mDestroySurface list?
7040 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007042 // Completely remove from window manager after exit animation?
7043 boolean mRemoveOnExit;
7044
7045 // Set when the orientation is changing and this window has not yet
7046 // been updated for the new orientation.
7047 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 // Is this window now (or just being) removed?
7050 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007051
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007052 // Temp for keeping track of windows that have been removed when
7053 // rebuilding window list.
7054 boolean mRebuilding;
7055
Dianne Hackborn16064f92010-03-25 00:47:24 -07007056 // For debugging, this is the last information given to the surface flinger.
7057 boolean mSurfaceShown;
7058 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7059 int mSurfaceLayer;
7060 float mSurfaceAlpha;
7061
Jeff Brown928e0542011-01-10 11:17:36 -08007062 // Input channel and input window handle used by the input dispatcher.
7063 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007064 InputChannel mInputChannel;
7065
Mattias Petersson1622eee2010-12-21 10:15:11 +01007066 // Used to improve performance of toString()
7067 String mStringNameCache;
7068 CharSequence mLastTitle;
7069 boolean mWasPaused;
7070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007071 WindowState(Session s, IWindow c, WindowToken token,
7072 WindowState attachedWindow, WindowManager.LayoutParams a,
7073 int viewVisibility) {
7074 mSession = s;
7075 mClient = c;
7076 mToken = token;
7077 mAttrs.copyFrom(a);
7078 mViewVisibility = viewVisibility;
7079 DeathRecipient deathRecipient = new DeathRecipient();
7080 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007081 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007082 TAG, "Window " + this + " client=" + c.asBinder()
7083 + " token=" + token + " (" + mAttrs.token + ")");
7084 try {
7085 c.asBinder().linkToDeath(deathRecipient, 0);
7086 } catch (RemoteException e) {
7087 mDeathRecipient = null;
7088 mAttachedWindow = null;
7089 mLayoutAttached = false;
7090 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007091 mIsWallpaper = false;
7092 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007093 mBaseLayer = 0;
7094 mSubLayer = 0;
7095 return;
7096 }
7097 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7100 mAttrs.type <= LAST_SUB_WINDOW)) {
7101 // The multiplier here is to reserve space for multiple
7102 // windows in the same type layer.
7103 mBaseLayer = mPolicy.windowTypeToLayerLw(
7104 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7105 + TYPE_LAYER_OFFSET;
7106 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7107 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007108 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007109 mAttachedWindow.mChildWindows.add(this);
7110 mLayoutAttached = mAttrs.type !=
7111 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7112 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7113 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007114 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7115 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007116 } else {
7117 // The multiplier here is to reserve space for multiple
7118 // windows in the same type layer.
7119 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7120 * TYPE_LAYER_MULTIPLIER
7121 + TYPE_LAYER_OFFSET;
7122 mSubLayer = 0;
7123 mAttachedWindow = null;
7124 mLayoutAttached = false;
7125 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7126 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007127 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7128 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007129 }
7130
7131 WindowState appWin = this;
7132 while (appWin.mAttachedWindow != null) {
7133 appWin = mAttachedWindow;
7134 }
7135 WindowToken appToken = appWin.mToken;
7136 while (appToken.appWindowToken == null) {
7137 WindowToken parent = mTokenMap.get(appToken.token);
7138 if (parent == null || appToken == parent) {
7139 break;
7140 }
7141 appToken = parent;
7142 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007143 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007144 mAppToken = appToken.appWindowToken;
7145
7146 mSurface = null;
7147 mRequestedWidth = 0;
7148 mRequestedHeight = 0;
7149 mLastRequestedWidth = 0;
7150 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007151 mXOffset = 0;
7152 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007153 mLayer = 0;
7154 mAnimLayer = 0;
7155 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007156 mInputWindowHandle = new InputWindowHandle(
7157 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007158 }
7159
7160 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007161 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 TAG, "Attaching " + this + " token=" + mToken
7163 + ", list=" + mToken.windows);
7164 mSession.windowAddedLocked();
7165 }
7166
7167 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7168 mHaveFrame = true;
7169
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007170 final Rect container = mContainingFrame;
7171 container.set(pf);
7172
7173 final Rect display = mDisplayFrame;
7174 display.set(df);
7175
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007176 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007177 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007178 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7179 display.intersect(mCompatibleScreenFrame);
7180 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007181 }
7182
7183 final int pw = container.right - container.left;
7184 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007185
7186 int w,h;
7187 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7188 w = mAttrs.width < 0 ? pw : mAttrs.width;
7189 h = mAttrs.height< 0 ? ph : mAttrs.height;
7190 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007191 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7192 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 }
Romain Guy06882f82009-06-10 13:36:04 -07007194
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007195 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007196 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7197 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007198 mParentFrame.set(pf);
7199 mContentChanged = true;
7200 }
7201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 final Rect content = mContentFrame;
7203 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 final Rect visible = mVisibleFrame;
7206 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007208 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007209 final int fw = frame.width();
7210 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007212 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7213 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7214
7215 Gravity.apply(mAttrs.gravity, w, h, container,
7216 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7217 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7218
7219 //System.out.println("Out: " + mFrame);
7220
7221 // Now make sure the window fits in the overall display.
7222 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007224 // Make sure the content and visible frames are inside of the
7225 // final window frame.
7226 if (content.left < frame.left) content.left = frame.left;
7227 if (content.top < frame.top) content.top = frame.top;
7228 if (content.right > frame.right) content.right = frame.right;
7229 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7230 if (visible.left < frame.left) visible.left = frame.left;
7231 if (visible.top < frame.top) visible.top = frame.top;
7232 if (visible.right > frame.right) visible.right = frame.right;
7233 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235 final Rect contentInsets = mContentInsets;
7236 contentInsets.left = content.left-frame.left;
7237 contentInsets.top = content.top-frame.top;
7238 contentInsets.right = frame.right-content.right;
7239 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007241 final Rect visibleInsets = mVisibleInsets;
7242 visibleInsets.left = visible.left-frame.left;
7243 visibleInsets.top = visible.top-frame.top;
7244 visibleInsets.right = frame.right-visible.right;
7245 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007246
Dianne Hackborn284ac932009-08-28 10:34:25 -07007247 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7248 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007249 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007250 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 if (localLOGV) {
7253 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7254 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007255 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007256 + mRequestedWidth + ", mRequestedheight="
7257 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7258 + "): frame=" + mFrame.toShortString()
7259 + " ci=" + contentInsets.toShortString()
7260 + " vi=" + visibleInsets.toShortString());
7261 //}
7262 }
7263 }
Romain Guy06882f82009-06-10 13:36:04 -07007264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 public Rect getFrameLw() {
7266 return mFrame;
7267 }
7268
7269 public Rect getShownFrameLw() {
7270 return mShownFrame;
7271 }
7272
7273 public Rect getDisplayFrameLw() {
7274 return mDisplayFrame;
7275 }
7276
7277 public Rect getContentFrameLw() {
7278 return mContentFrame;
7279 }
7280
7281 public Rect getVisibleFrameLw() {
7282 return mVisibleFrame;
7283 }
7284
7285 public boolean getGivenInsetsPendingLw() {
7286 return mGivenInsetsPending;
7287 }
7288
7289 public Rect getGivenContentInsetsLw() {
7290 return mGivenContentInsets;
7291 }
Romain Guy06882f82009-06-10 13:36:04 -07007292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 public Rect getGivenVisibleInsetsLw() {
7294 return mGivenVisibleInsets;
7295 }
Romain Guy06882f82009-06-10 13:36:04 -07007296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007297 public WindowManager.LayoutParams getAttrs() {
7298 return mAttrs;
7299 }
7300
7301 public int getSurfaceLayer() {
7302 return mLayer;
7303 }
Romain Guy06882f82009-06-10 13:36:04 -07007304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 public IApplicationToken getAppToken() {
7306 return mAppToken != null ? mAppToken.appToken : null;
7307 }
Jeff Brown349703e2010-06-22 01:27:15 -07007308
7309 public long getInputDispatchingTimeoutNanos() {
7310 return mAppToken != null
7311 ? mAppToken.inputDispatchingTimeoutNanos
7312 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7313 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007314
7315 public boolean hasAppShownWindows() {
7316 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7317 }
7318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007320 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 TAG, "Setting animation in " + this + ": " + anim);
7322 mAnimating = false;
7323 mLocalAnimating = false;
7324 mAnimation = anim;
7325 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7326 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7327 }
7328
7329 public void clearAnimation() {
7330 if (mAnimation != null) {
7331 mAnimating = true;
7332 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007333 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 mAnimation = null;
7335 }
7336 }
Romain Guy06882f82009-06-10 13:36:04 -07007337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 Surface createSurfaceLocked() {
7339 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007340 mReportDestroySurface = false;
7341 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007342 mDrawPending = true;
7343 mCommitDrawPending = false;
7344 mReadyToShow = false;
7345 if (mAppToken != null) {
7346 mAppToken.allDrawn = false;
7347 }
7348
7349 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350
7351 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7352 flags |= Surface.SECURE;
7353 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007354 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 TAG, "Creating surface in session "
7356 + mSession.mSurfaceSession + " window " + this
7357 + " w=" + mFrame.width()
7358 + " h=" + mFrame.height() + " format="
7359 + mAttrs.format + " flags=" + flags);
7360
7361 int w = mFrame.width();
7362 int h = mFrame.height();
7363 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7364 // for a scaled surface, we always want the requested
7365 // size.
7366 w = mRequestedWidth;
7367 h = mRequestedHeight;
7368 }
7369
Romain Guy9825ec62009-10-01 00:58:09 -07007370 // Something is wrong and SurfaceFlinger will not like this,
7371 // try to revert to sane values
7372 if (w <= 0) w = 1;
7373 if (h <= 0) h = 1;
7374
Dianne Hackborn16064f92010-03-25 00:47:24 -07007375 mSurfaceShown = false;
7376 mSurfaceLayer = 0;
7377 mSurfaceAlpha = 1;
7378 mSurfaceX = 0;
7379 mSurfaceY = 0;
7380 mSurfaceW = w;
7381 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007383 final boolean isHwAccelerated = (mAttrs.flags &
7384 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7385 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7386 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7387 flags |= Surface.OPAQUE;
7388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007389 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007390 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007391 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007392 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007393 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007394 + mSurface + " IN SESSION "
7395 + mSession.mSurfaceSession
7396 + ": pid=" + mSession.mPid + " format="
7397 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007398 + Integer.toHexString(flags)
7399 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007401 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 reclaimSomeSurfaceMemoryLocked(this, "create");
7403 return null;
7404 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007405 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 return null;
7407 }
Romain Guy06882f82009-06-10 13:36:04 -07007408
Joe Onorato8a9b2202010-02-26 18:56:32 -08007409 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 TAG, "Got surface: " + mSurface
7411 + ", set left=" + mFrame.left + " top=" + mFrame.top
7412 + ", animLayer=" + mAnimLayer);
7413 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007414 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7415 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007416 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7417 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 }
7419 Surface.openTransaction();
7420 try {
7421 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007422 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007423 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007424 mSurface.setPosition(mSurfaceX, mSurfaceY);
7425 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007427 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 mSurface.hide();
7429 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007430 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 mSurface.setFlags(Surface.SURFACE_DITHER,
7432 Surface.SURFACE_DITHER);
7433 }
7434 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007435 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7437 }
7438 mLastHidden = true;
7439 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007441 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007443 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007444 TAG, "Created surface " + this);
7445 }
7446 return mSurface;
7447 }
Romain Guy06882f82009-06-10 13:36:04 -07007448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 if (mAppToken != null && this == mAppToken.startingWindow) {
7451 mAppToken.startingDisplayed = false;
7452 }
Romain Guy06882f82009-06-10 13:36:04 -07007453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007454 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007455 mDrawPending = false;
7456 mCommitDrawPending = false;
7457 mReadyToShow = false;
7458
7459 int i = mChildWindows.size();
7460 while (i > 0) {
7461 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007462 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007463 c.mAttachedHidden = true;
7464 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007465
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007466 if (mReportDestroySurface) {
7467 mReportDestroySurface = false;
7468 mSurfacePendingDestroy = true;
7469 try {
7470 mClient.dispatchGetNewSurface();
7471 // We'll really destroy on the next time around.
7472 return;
7473 } catch (RemoteException e) {
7474 }
7475 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007478 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007479 RuntimeException e = null;
7480 if (!HIDE_STACK_CRAWLS) {
7481 e = new RuntimeException();
7482 e.fillInStackTrace();
7483 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007484 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007485 + mSurface + ", session " + mSession, e);
7486 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007487 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007488 RuntimeException e = null;
7489 if (!HIDE_STACK_CRAWLS) {
7490 e = new RuntimeException();
7491 e.fillInStackTrace();
7492 }
7493 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007495 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007496 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007497 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 + " surface " + mSurface + " session " + mSession
7499 + ": " + e.toString());
7500 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007501
Dianne Hackborn16064f92010-03-25 00:47:24 -07007502 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 }
7505 }
7506
7507 boolean finishDrawingLocked() {
7508 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007509 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 TAG, "finishDrawingLocked: " + mSurface);
7511 mCommitDrawPending = true;
7512 mDrawPending = false;
7513 return true;
7514 }
7515 return false;
7516 }
7517
7518 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007519 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007520 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007521 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007522 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523 }
7524 mCommitDrawPending = false;
7525 mReadyToShow = true;
7526 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7527 final AppWindowToken atoken = mAppToken;
7528 if (atoken == null || atoken.allDrawn || starting) {
7529 performShowLocked();
7530 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007531 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 }
7533
7534 // This must be called while inside a transaction.
7535 boolean performShowLocked() {
7536 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007537 RuntimeException e = null;
7538 if (!HIDE_STACK_CRAWLS) {
7539 e = new RuntimeException();
7540 e.fillInStackTrace();
7541 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007542 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7544 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7545 }
7546 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007547 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7548 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007549 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007550 + " during animation: policyVis=" + mPolicyVisibility
7551 + " attHidden=" + mAttachedHidden
7552 + " tok.hiddenRequested="
7553 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007554 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007555 + (mAppToken != null ? mAppToken.hidden : false)
7556 + " animating=" + mAnimating
7557 + " tok animating="
7558 + (mAppToken != null ? mAppToken.animating : false));
7559 if (!showSurfaceRobustlyLocked(this)) {
7560 return false;
7561 }
7562 mLastAlpha = -1;
7563 mHasDrawn = true;
7564 mLastHidden = false;
7565 mReadyToShow = false;
7566 enableScreenIfNeededLocked();
7567
7568 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007570 int i = mChildWindows.size();
7571 while (i > 0) {
7572 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007573 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007574 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007575 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007576 if (c.mSurface != null) {
7577 c.performShowLocked();
7578 // It hadn't been shown, which means layout not
7579 // performed on it, so now we want to make sure to
7580 // do a layout. If called from within the transaction
7581 // loop, this will cause it to restart with a new
7582 // layout.
7583 mLayoutNeeded = true;
7584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 }
7586 }
Romain Guy06882f82009-06-10 13:36:04 -07007587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 if (mAttrs.type != TYPE_APPLICATION_STARTING
7589 && mAppToken != null) {
7590 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007591
Dianne Hackborn248b1882009-09-16 16:46:44 -07007592 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007593 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007594 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007595 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007596 // If this initial window is animating, stop it -- we
7597 // will do an animation to reveal it from behind the
7598 // starting window, so there is no need for it to also
7599 // be doing its own stuff.
7600 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007601 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007602 mAnimation = null;
7603 // Make sure we clean up the animation.
7604 mAnimating = true;
7605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 mFinishedStarting.add(mAppToken);
7607 mH.sendEmptyMessage(H.FINISHED_STARTING);
7608 }
7609 mAppToken.updateReportedVisibilityLocked();
7610 }
7611 }
7612 return true;
7613 }
Romain Guy06882f82009-06-10 13:36:04 -07007614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007615 // This must be called while inside a transaction. Returns true if
7616 // there is more animation to run.
7617 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007618 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007619 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7622 mHasTransformation = true;
7623 mHasLocalTransformation = true;
7624 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007625 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 TAG, "Starting animation in " + this +
7627 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7628 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7629 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7630 mAnimation.setStartTime(currentTime);
7631 mLocalAnimating = true;
7632 mAnimating = true;
7633 }
7634 mTransformation.clear();
7635 final boolean more = mAnimation.getTransformation(
7636 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007637 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 TAG, "Stepped animation in " + this +
7639 ": more=" + more + ", xform=" + mTransformation);
7640 if (more) {
7641 // we're not done!
7642 return true;
7643 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007644 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007645 TAG, "Finished animation in " + this +
7646 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007647
7648 if (mAnimation != null) {
7649 mAnimation.cancel();
7650 mAnimation = null;
7651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007652 //WindowManagerService.this.dump();
7653 }
7654 mHasLocalTransformation = false;
7655 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007656 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 // When our app token is animating, we kind-of pretend like
7658 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7659 // part of this check means that we will only do this if
7660 // our window is not currently exiting, or it is not
7661 // locally animating itself. The idea being that one that
7662 // is exiting and doing a local animation should be removed
7663 // once that animation is done.
7664 mAnimating = true;
7665 mHasTransformation = true;
7666 mTransformation.clear();
7667 return false;
7668 } else if (mHasTransformation) {
7669 // Little trick to get through the path below to act like
7670 // we have finished an animation.
7671 mAnimating = true;
7672 } else if (isAnimating()) {
7673 mAnimating = true;
7674 }
7675 } else if (mAnimation != null) {
7676 // If the display is frozen, and there is a pending animation,
7677 // clear it and make sure we run the cleanup code.
7678 mAnimating = true;
7679 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007680 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007681 mAnimation = null;
7682 }
Romain Guy06882f82009-06-10 13:36:04 -07007683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 if (!mAnimating && !mLocalAnimating) {
7685 return false;
7686 }
7687
Joe Onorato8a9b2202010-02-26 18:56:32 -08007688 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 TAG, "Animation done in " + this + ": exiting=" + mExiting
7690 + ", reportedVisible="
7691 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007693 mAnimating = false;
7694 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007695 if (mAnimation != null) {
7696 mAnimation.cancel();
7697 mAnimation = null;
7698 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007699 mAnimLayer = mLayer;
7700 if (mIsImWindow) {
7701 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007702 } else if (mIsWallpaper) {
7703 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007705 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 + " anim layer: " + mAnimLayer);
7707 mHasTransformation = false;
7708 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007709 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7710 if (DEBUG_VISIBILITY) {
7711 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7712 + mPolicyVisibilityAfterAnim);
7713 }
7714 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7715 if (!mPolicyVisibility) {
7716 if (mCurrentFocus == this) {
7717 mFocusMayChange = true;
7718 }
7719 // Window is no longer visible -- make sure if we were waiting
7720 // for it to be displayed before enabling the display, that
7721 // we allow the display to be enabled now.
7722 enableScreenIfNeededLocked();
7723 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007724 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007725 mTransformation.clear();
7726 if (mHasDrawn
7727 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7728 && mAppToken != null
7729 && mAppToken.firstWindowDrawn
7730 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007731 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007732 + mToken + ": first real window done animating");
7733 mFinishedStarting.add(mAppToken);
7734 mH.sendEmptyMessage(H.FINISHED_STARTING);
7735 }
Romain Guy06882f82009-06-10 13:36:04 -07007736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 finishExit();
7738
7739 if (mAppToken != null) {
7740 mAppToken.updateReportedVisibilityLocked();
7741 }
7742
7743 return false;
7744 }
7745
7746 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007747 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 TAG, "finishExit in " + this
7749 + ": exiting=" + mExiting
7750 + " remove=" + mRemoveOnExit
7751 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 final int N = mChildWindows.size();
7754 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007755 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007756 }
Romain Guy06882f82009-06-10 13:36:04 -07007757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 if (!mExiting) {
7759 return;
7760 }
Romain Guy06882f82009-06-10 13:36:04 -07007761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007762 if (isWindowAnimating()) {
7763 return;
7764 }
7765
Joe Onorato8a9b2202010-02-26 18:56:32 -08007766 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 TAG, "Exit animation finished in " + this
7768 + ": remove=" + mRemoveOnExit);
7769 if (mSurface != null) {
7770 mDestroySurface.add(this);
7771 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007772 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007773 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 try {
7775 mSurface.hide();
7776 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007777 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007778 }
7779 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007780 }
7781 mExiting = false;
7782 if (mRemoveOnExit) {
7783 mPendingRemove.add(this);
7784 mRemoveOnExit = false;
7785 }
7786 }
Romain Guy06882f82009-06-10 13:36:04 -07007787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007788 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7789 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7790 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7791 if (dtdx < -.000001f || dtdx > .000001f) return false;
7792 if (dsdy < -.000001f || dsdy > .000001f) return false;
7793 return true;
7794 }
Romain Guy06882f82009-06-10 13:36:04 -07007795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 void computeShownFrameLocked() {
7797 final boolean selfTransformation = mHasLocalTransformation;
7798 Transformation attachedTransformation =
7799 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7800 ? mAttachedWindow.mTransformation : null;
7801 Transformation appTransformation =
7802 (mAppToken != null && mAppToken.hasTransformation)
7803 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007804
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007805 // Wallpapers are animated based on the "real" window they
7806 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007807 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007808 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007809 if (mWallpaperTarget.mHasLocalTransformation &&
7810 mWallpaperTarget.mAnimation != null &&
7811 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007812 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007813 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007814 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007815 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007816 }
7817 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007818 mWallpaperTarget.mAppToken.hasTransformation &&
7819 mWallpaperTarget.mAppToken.animation != null &&
7820 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007821 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007822 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007823 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007824 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007825 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007826 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007827
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007828 final boolean screenAnimation = mScreenRotationAnimation != null
7829 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007831 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007832 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 final Rect frame = mFrame;
7834 final float tmpFloats[] = mTmpFloats;
7835 final Matrix tmpMatrix = mTmpMatrix;
7836
7837 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007838 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007839 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007840 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007841 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007842 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007843 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007844 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 }
7846 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007847 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007848 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007849 if (screenAnimation) {
7850 tmpMatrix.postConcat(
7851 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007853
7854 // "convert" it into SurfaceFlinger's format
7855 // (a 2x2 matrix + an offset)
7856 // Here we must not transform the position of the surface
7857 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007858 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007859
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007860 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007861 tmpMatrix.getValues(tmpFloats);
7862 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007863 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7864 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007865 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007866 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7867 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 int w = frame.width();
7869 int h = frame.height();
7870 mShownFrame.set(x, y, x+w, y+h);
7871
7872 // Now set the alpha... but because our current hardware
7873 // can't do alpha transformation on a non-opaque surface,
7874 // turn it off if we are running an animation that is also
7875 // transforming since it is more important to have that
7876 // animation be smooth.
7877 mShownAlpha = mAlpha;
7878 if (!mLimitedAlphaCompositing
7879 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7880 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7881 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007882 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007883 if (selfTransformation) {
7884 mShownAlpha *= mTransformation.getAlpha();
7885 }
7886 if (attachedTransformation != null) {
7887 mShownAlpha *= attachedTransformation.getAlpha();
7888 }
7889 if (appTransformation != null) {
7890 mShownAlpha *= appTransformation.getAlpha();
7891 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007892 if (screenAnimation) {
7893 mShownAlpha *=
7894 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007896 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007897 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 }
Romain Guy06882f82009-06-10 13:36:04 -07007899
Joe Onorato8a9b2202010-02-26 18:56:32 -08007900 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 TAG, "Continuing animation in " + this +
7902 ": " + mShownFrame +
7903 ", alpha=" + mTransformation.getAlpha());
7904 return;
7905 }
Romain Guy06882f82009-06-10 13:36:04 -07007906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007908 if (mXOffset != 0 || mYOffset != 0) {
7909 mShownFrame.offset(mXOffset, mYOffset);
7910 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007911 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007912 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 mDsDx = 1;
7914 mDtDx = 0;
7915 mDsDy = 0;
7916 mDtDy = 1;
7917 }
Romain Guy06882f82009-06-10 13:36:04 -07007918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 /**
7920 * Is this window visible? It is not visible if there is no
7921 * surface, or we are in the process of running an exit animation
7922 * that will remove the surface, or its app token has been hidden.
7923 */
7924 public boolean isVisibleLw() {
7925 final AppWindowToken atoken = mAppToken;
7926 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7927 && (atoken == null || !atoken.hiddenRequested)
7928 && !mExiting && !mDestroying;
7929 }
7930
7931 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007932 * Like {@link #isVisibleLw}, but also counts a window that is currently
7933 * "hidden" behind the keyguard as visible. This allows us to apply
7934 * things like window flags that impact the keyguard.
7935 * XXX I am starting to think we need to have ANOTHER visibility flag
7936 * for this "hidden behind keyguard" state rather than overloading
7937 * mPolicyVisibility. Ungh.
7938 */
7939 public boolean isVisibleOrBehindKeyguardLw() {
7940 final AppWindowToken atoken = mAppToken;
7941 return mSurface != null && !mAttachedHidden
7942 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007943 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007944 && !mExiting && !mDestroying;
7945 }
7946
7947 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007948 * Is this window visible, ignoring its app token? It is not visible
7949 * if there is no surface, or we are in the process of running an exit animation
7950 * that will remove the surface.
7951 */
7952 public boolean isWinVisibleLw() {
7953 final AppWindowToken atoken = mAppToken;
7954 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7955 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7956 && !mExiting && !mDestroying;
7957 }
7958
7959 /**
7960 * The same as isVisible(), but follows the current hidden state of
7961 * the associated app token, not the pending requested hidden state.
7962 */
7963 boolean isVisibleNow() {
7964 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007965 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007966 }
7967
7968 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007969 * Can this window possibly be a drag/drop target? The test here is
7970 * a combination of the above "visible now" with the check that the
7971 * Input Manager uses when discarding windows from input consideration.
7972 */
7973 boolean isPotentialDragTarget() {
7974 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7975 }
7976
7977 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007978 * Same as isVisible(), but we also count it as visible between the
7979 * call to IWindowSession.add() and the first relayout().
7980 */
7981 boolean isVisibleOrAdding() {
7982 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007983 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007984 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7985 && mPolicyVisibility && !mAttachedHidden
7986 && (atoken == null || !atoken.hiddenRequested)
7987 && !mExiting && !mDestroying;
7988 }
7989
7990 /**
7991 * Is this window currently on-screen? It is on-screen either if it
7992 * is visible or it is currently running an animation before no longer
7993 * being visible.
7994 */
7995 boolean isOnScreen() {
7996 final AppWindowToken atoken = mAppToken;
7997 if (atoken != null) {
7998 return mSurface != null && mPolicyVisibility && !mDestroying
7999 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008000 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 } else {
8002 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008003 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 }
8005 }
Romain Guy06882f82009-06-10 13:36:04 -07008006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008007 /**
8008 * Like isOnScreen(), but we don't return true if the window is part
8009 * of a transition that has not yet been started.
8010 */
8011 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008012 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008013 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008014 return false;
8015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008017 final boolean animating = atoken != null
8018 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008020 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8021 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008022 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008023 }
8024
8025 /** Is the window or its container currently animating? */
8026 boolean isAnimating() {
8027 final WindowState attached = mAttachedWindow;
8028 final AppWindowToken atoken = mAppToken;
8029 return mAnimation != null
8030 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008031 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008032 (atoken.animation != null
8033 || atoken.inPendingTransaction));
8034 }
8035
8036 /** Is this window currently animating? */
8037 boolean isWindowAnimating() {
8038 return mAnimation != null;
8039 }
8040
8041 /**
8042 * Like isOnScreen, but returns false if the surface hasn't yet
8043 * been drawn.
8044 */
8045 public boolean isDisplayedLw() {
8046 final AppWindowToken atoken = mAppToken;
8047 return mSurface != null && mPolicyVisibility && !mDestroying
8048 && !mDrawPending && !mCommitDrawPending
8049 && ((!mAttachedHidden &&
8050 (atoken == null || !atoken.hiddenRequested))
8051 || mAnimating);
8052 }
8053
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008054 /**
8055 * Returns true if the window has a surface that it has drawn a
8056 * complete UI in to.
8057 */
8058 public boolean isDrawnLw() {
8059 final AppWindowToken atoken = mAppToken;
8060 return mSurface != null && !mDestroying
8061 && !mDrawPending && !mCommitDrawPending;
8062 }
8063
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008064 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008065 * Return true if the window is opaque and fully drawn. This indicates
8066 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008067 */
8068 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008069 return (mAttrs.format == PixelFormat.OPAQUE
8070 || mAttrs.type == TYPE_WALLPAPER)
8071 && mSurface != null && mAnimation == null
8072 && (mAppToken == null || mAppToken.animation == null)
8073 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008074 }
8075
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008076 /**
8077 * Return whether this window is wanting to have a translation
8078 * animation applied to it for an in-progress move. (Only makes
8079 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8080 */
8081 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008082 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008083 && (mFrame.top != mLastFrame.top
8084 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008085 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008086 && mPolicy.isScreenOn();
8087 }
8088
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008089 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8090 return
8091 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008092 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8093 // only if it's visible
8094 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008095 // and only if the application fills the compatible screen
8096 mFrame.left <= mCompatibleScreenFrame.left &&
8097 mFrame.top <= mCompatibleScreenFrame.top &&
8098 mFrame.right >= mCompatibleScreenFrame.right &&
8099 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008100 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008101 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008102 }
8103
8104 boolean isFullscreen(int screenWidth, int screenHeight) {
8105 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008106 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 }
8108
8109 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008110 disposeInputChannel();
8111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008112 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008113 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008114 mAttachedWindow.mChildWindows.remove(this);
8115 }
8116 destroySurfaceLocked();
8117 mSession.windowRemovedLocked();
8118 try {
8119 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8120 } catch (RuntimeException e) {
8121 // Ignore if it has already been removed (usually because
8122 // we are doing this as part of processing a death note.)
8123 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008124 }
8125
8126 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008127 if (mInputChannel != null) {
8128 mInputManager.unregisterInputChannel(mInputChannel);
8129
8130 mInputChannel.dispose();
8131 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 }
8134
8135 private class DeathRecipient implements IBinder.DeathRecipient {
8136 public void binderDied() {
8137 try {
8138 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008139 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008140 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008141 if (win != null) {
8142 removeWindowLocked(mSession, win);
8143 }
8144 }
8145 } catch (IllegalArgumentException ex) {
8146 // This will happen if the window has already been
8147 // removed.
8148 }
8149 }
8150 }
8151
8152 /** Returns true if this window desires key events. */
8153 public final boolean canReceiveKeys() {
8154 return isVisibleOrAdding()
8155 && (mViewVisibility == View.VISIBLE)
8156 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8157 }
8158
8159 public boolean hasDrawnLw() {
8160 return mHasDrawn;
8161 }
8162
8163 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008164 return showLw(doAnimation, true);
8165 }
8166
8167 boolean showLw(boolean doAnimation, boolean requestAnim) {
8168 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8169 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008170 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008171 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008172 if (doAnimation) {
8173 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8174 + mPolicyVisibility + " mAnimation=" + mAnimation);
8175 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8176 doAnimation = false;
8177 } else if (mPolicyVisibility && mAnimation == null) {
8178 // Check for the case where we are currently visible and
8179 // not animating; we do not want to do animation at such a
8180 // point to become visible when we already are.
8181 doAnimation = false;
8182 }
8183 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008184 mPolicyVisibility = true;
8185 mPolicyVisibilityAfterAnim = true;
8186 if (doAnimation) {
8187 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8188 }
8189 if (requestAnim) {
8190 requestAnimationLocked(0);
8191 }
8192 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008193 }
8194
8195 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008196 return hideLw(doAnimation, true);
8197 }
8198
8199 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008200 if (doAnimation) {
8201 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8202 doAnimation = false;
8203 }
8204 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8206 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008207 if (!current) {
8208 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008209 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008210 if (doAnimation) {
8211 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8212 if (mAnimation == null) {
8213 doAnimation = false;
8214 }
8215 }
8216 if (doAnimation) {
8217 mPolicyVisibilityAfterAnim = false;
8218 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008219 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008220 mPolicyVisibilityAfterAnim = false;
8221 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008222 // Window is no longer visible -- make sure if we were waiting
8223 // for it to be displayed before enabling the display, that
8224 // we allow the display to be enabled now.
8225 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008226 if (mCurrentFocus == this) {
8227 mFocusMayChange = true;
8228 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008229 }
8230 if (requestAnim) {
8231 requestAnimationLocked(0);
8232 }
8233 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008234 }
8235
Jeff Brownfbf09772011-01-16 14:06:57 -08008236 public void getTouchableRegion(Region outRegion) {
8237 final Rect frame = mFrame;
8238 switch (mTouchableInsets) {
8239 default:
8240 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8241 outRegion.set(frame);
8242 break;
8243 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8244 final Rect inset = mGivenContentInsets;
8245 outRegion.set(
8246 frame.left + inset.left, frame.top + inset.top,
8247 frame.right - inset.right, frame.bottom - inset.bottom);
8248 break;
8249 }
8250 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8251 final Rect inset = mGivenVisibleInsets;
8252 outRegion.set(
8253 frame.left + inset.left, frame.top + inset.top,
8254 frame.right - inset.right, frame.bottom - inset.bottom);
8255 break;
8256 }
8257 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8258 final Region givenTouchableRegion = mGivenTouchableRegion;
8259 outRegion.set(givenTouchableRegion);
8260 outRegion.translate(frame.left, frame.top);
8261 break;
8262 }
8263 }
8264 }
8265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008266 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008267 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8268 pw.print(" mClient="); pw.println(mClient.asBinder());
8269 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8270 if (mAttachedWindow != null || mLayoutAttached) {
8271 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8272 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8273 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008274 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8275 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8276 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008277 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8278 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008279 }
8280 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8281 pw.print(" mSubLayer="); pw.print(mSubLayer);
8282 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8283 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8284 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8285 pw.print("="); pw.print(mAnimLayer);
8286 pw.print(" mLastLayer="); pw.println(mLastLayer);
8287 if (mSurface != null) {
8288 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008289 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8290 pw.print(" layer="); pw.print(mSurfaceLayer);
8291 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8292 pw.print(" rect=("); pw.print(mSurfaceX);
8293 pw.print(","); pw.print(mSurfaceY);
8294 pw.print(") "); pw.print(mSurfaceW);
8295 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008296 }
8297 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8298 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8299 if (mAppToken != null) {
8300 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8301 }
8302 if (mTargetAppToken != null) {
8303 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8304 }
8305 pw.print(prefix); pw.print("mViewVisibility=0x");
8306 pw.print(Integer.toHexString(mViewVisibility));
8307 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008308 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8309 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008310 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8311 pw.print(prefix); pw.print("mPolicyVisibility=");
8312 pw.print(mPolicyVisibility);
8313 pw.print(" mPolicyVisibilityAfterAnim=");
8314 pw.print(mPolicyVisibilityAfterAnim);
8315 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8316 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008317 if (!mRelayoutCalled) {
8318 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8319 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008320 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008321 pw.print(" h="); pw.print(mRequestedHeight);
8322 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008323 if (mXOffset != 0 || mYOffset != 0) {
8324 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8325 pw.print(" y="); pw.println(mYOffset);
8326 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008327 pw.print(prefix); pw.print("mGivenContentInsets=");
8328 mGivenContentInsets.printShortString(pw);
8329 pw.print(" mGivenVisibleInsets=");
8330 mGivenVisibleInsets.printShortString(pw);
8331 pw.println();
8332 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8333 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8334 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8335 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008336 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008337 pw.print(prefix); pw.print("mShownFrame=");
8338 mShownFrame.printShortString(pw);
8339 pw.print(" last="); mLastShownFrame.printShortString(pw);
8340 pw.println();
8341 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8342 pw.print(" last="); mLastFrame.printShortString(pw);
8343 pw.println();
8344 pw.print(prefix); pw.print("mContainingFrame=");
8345 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008346 pw.print(" mParentFrame=");
8347 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008348 pw.print(" mDisplayFrame=");
8349 mDisplayFrame.printShortString(pw);
8350 pw.println();
8351 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8352 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8353 pw.println();
8354 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8355 pw.print(" last="); mLastContentInsets.printShortString(pw);
8356 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8357 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8358 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008359 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8360 || mAnimation != null) {
8361 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8362 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8363 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8364 pw.print(" mAnimation="); pw.println(mAnimation);
8365 }
8366 if (mHasTransformation || mHasLocalTransformation) {
8367 pw.print(prefix); pw.print("XForm: has=");
8368 pw.print(mHasTransformation);
8369 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8370 pw.print(" "); mTransformation.printShortString(pw);
8371 pw.println();
8372 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008373 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8374 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8375 pw.print(" mAlpha="); pw.print(mAlpha);
8376 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8377 }
8378 if (mHaveMatrix) {
8379 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8380 pw.print(" mDtDx="); pw.print(mDtDx);
8381 pw.print(" mDsDy="); pw.print(mDsDy);
8382 pw.print(" mDtDy="); pw.println(mDtDy);
8383 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008384 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8385 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8386 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8387 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8388 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8389 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8390 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8391 pw.print(" mDestroying="); pw.print(mDestroying);
8392 pw.print(" mRemoved="); pw.println(mRemoved);
8393 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008394 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008395 pw.print(prefix); pw.print("mOrientationChanging=");
8396 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008397 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8398 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008399 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008400 if (mHScale != 1 || mVScale != 1) {
8401 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8402 pw.print(" mVScale="); pw.println(mVScale);
8403 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008404 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008405 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8406 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8407 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008408 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8409 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8410 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008412 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008413
8414 String makeInputChannelName() {
8415 return Integer.toHexString(System.identityHashCode(this))
8416 + " " + mAttrs.getTitle();
8417 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418
8419 @Override
8420 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008421 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8422 || mWasPaused != mToken.paused) {
8423 mLastTitle = mAttrs.getTitle();
8424 mWasPaused = mToken.paused;
8425 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8426 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8427 }
8428 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008429 }
8430 }
Romain Guy06882f82009-06-10 13:36:04 -07008431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 // -------------------------------------------------------------
8433 // Window Token State
8434 // -------------------------------------------------------------
8435
8436 class WindowToken {
8437 // The actual token.
8438 final IBinder token;
8439
8440 // The type of window this token is for, as per WindowManager.LayoutParams.
8441 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008443 // Set if this token was explicitly added by a client, so should
8444 // not be removed when all windows are removed.
8445 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008446
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008447 // For printing.
8448 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 // If this is an AppWindowToken, this is non-null.
8451 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453 // All of the windows associated with this token.
8454 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8455
8456 // Is key dispatching paused for this token?
8457 boolean paused = false;
8458
8459 // Should this token's windows be hidden?
8460 boolean hidden;
8461
8462 // Temporary for finding which tokens no longer have visible windows.
8463 boolean hasVisible;
8464
Dianne Hackborna8f60182009-09-01 19:01:50 -07008465 // Set to true when this token is in a pending transaction where it
8466 // will be shown.
8467 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008468
Dianne Hackborna8f60182009-09-01 19:01:50 -07008469 // Set to true when this token is in a pending transaction where it
8470 // will be hidden.
8471 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008472
Dianne Hackborna8f60182009-09-01 19:01:50 -07008473 // Set to true when this token is in a pending transaction where its
8474 // windows will be put to the bottom of the list.
8475 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008476
Dianne Hackborna8f60182009-09-01 19:01:50 -07008477 // Set to true when this token is in a pending transaction where its
8478 // windows will be put to the top of the list.
8479 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008481 WindowToken(IBinder _token, int type, boolean _explicit) {
8482 token = _token;
8483 windowType = type;
8484 explicit = _explicit;
8485 }
8486
8487 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008488 pw.print(prefix); pw.print("token="); pw.println(token);
8489 pw.print(prefix); pw.print("windows="); pw.println(windows);
8490 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8491 pw.print(" hidden="); pw.print(hidden);
8492 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008493 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8494 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8495 pw.print(" waitingToHide="); pw.print(waitingToHide);
8496 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8497 pw.print(" sendingToTop="); pw.println(sendingToTop);
8498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008499 }
8500
8501 @Override
8502 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008503 if (stringName == null) {
8504 StringBuilder sb = new StringBuilder();
8505 sb.append("WindowToken{");
8506 sb.append(Integer.toHexString(System.identityHashCode(this)));
8507 sb.append(" token="); sb.append(token); sb.append('}');
8508 stringName = sb.toString();
8509 }
8510 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008511 }
8512 };
8513
8514 class AppWindowToken extends WindowToken {
8515 // Non-null only for application tokens.
8516 final IApplicationToken appToken;
8517
8518 // All of the windows and child windows that are included in this
8519 // application token. Note this list is NOT sorted!
8520 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8521
8522 int groupId = -1;
8523 boolean appFullscreen;
8524 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008525
8526 // The input dispatching timeout for this application token in nanoseconds.
8527 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 // These are used for determining when all windows associated with
8530 // an activity have been drawn, so they can be made visible together
8531 // at the same time.
8532 int lastTransactionSequence = mTransactionSequence-1;
8533 int numInterestingWindows;
8534 int numDrawnWindows;
8535 boolean inPendingTransaction;
8536 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 // Is this token going to be hidden in a little while? If so, it
8539 // won't be taken into account for setting the screen orientation.
8540 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008542 // Is this window's surface needed? This is almost like hidden, except
8543 // it will sometimes be true a little earlier: when the token has
8544 // been shown, but is still waiting for its app transition to execute
8545 // before making its windows shown.
8546 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 // Have we told the window clients to hide themselves?
8549 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008551 // Last visibility state we reported to the app token.
8552 boolean reportedVisible;
8553
8554 // Set to true when the token has been removed from the window mgr.
8555 boolean removed;
8556
8557 // Have we been asked to have this token keep the screen frozen?
8558 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008560 boolean animating;
8561 Animation animation;
8562 boolean hasTransformation;
8563 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008565 // Offset to the window of all layers in the token, for use by
8566 // AppWindowToken animations.
8567 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008569 // Information about an application starting window if displayed.
8570 StartingData startingData;
8571 WindowState startingWindow;
8572 View startingView;
8573 boolean startingDisplayed;
8574 boolean startingMoved;
8575 boolean firstWindowDrawn;
8576
Jeff Brown928e0542011-01-10 11:17:36 -08008577 // Input application handle used by the input dispatcher.
8578 InputApplicationHandle mInputApplicationHandle;
8579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008580 AppWindowToken(IApplicationToken _token) {
8581 super(_token.asBinder(),
8582 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8583 appWindowToken = this;
8584 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008585 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 }
Romain Guy06882f82009-06-10 13:36:04 -07008587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008589 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 TAG, "Setting animation in " + this + ": " + anim);
8591 animation = anim;
8592 animating = false;
8593 anim.restrictDuration(MAX_ANIMATION_DURATION);
8594 anim.scaleCurrentDuration(mTransitionAnimationScale);
8595 int zorder = anim.getZAdjustment();
8596 int adj = 0;
8597 if (zorder == Animation.ZORDER_TOP) {
8598 adj = TYPE_LAYER_OFFSET;
8599 } else if (zorder == Animation.ZORDER_BOTTOM) {
8600 adj = -TYPE_LAYER_OFFSET;
8601 }
Romain Guy06882f82009-06-10 13:36:04 -07008602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008603 if (animLayerAdjustment != adj) {
8604 animLayerAdjustment = adj;
8605 updateLayers();
8606 }
8607 }
Romain Guy06882f82009-06-10 13:36:04 -07008608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008609 public void setDummyAnimation() {
8610 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008611 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612 TAG, "Setting dummy animation in " + this);
8613 animation = sDummyAnimation;
8614 }
8615 }
8616
8617 public void clearAnimation() {
8618 if (animation != null) {
8619 animation = null;
8620 animating = true;
8621 }
8622 }
Romain Guy06882f82009-06-10 13:36:04 -07008623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008624 void updateLayers() {
8625 final int N = allAppWindows.size();
8626 final int adj = animLayerAdjustment;
8627 for (int i=0; i<N; i++) {
8628 WindowState w = allAppWindows.get(i);
8629 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008630 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008631 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008632 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008633 setInputMethodAnimLayerAdjustment(adj);
8634 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008635 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008636 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 }
8639 }
Romain Guy06882f82009-06-10 13:36:04 -07008640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 void sendAppVisibilityToClients() {
8642 final int N = allAppWindows.size();
8643 for (int i=0; i<N; i++) {
8644 WindowState win = allAppWindows.get(i);
8645 if (win == startingWindow && clientHidden) {
8646 // Don't hide the starting window.
8647 continue;
8648 }
8649 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008650 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008651 "Setting visibility of " + win + ": " + (!clientHidden));
8652 win.mClient.dispatchAppVisibility(!clientHidden);
8653 } catch (RemoteException e) {
8654 }
8655 }
8656 }
Romain Guy06882f82009-06-10 13:36:04 -07008657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008658 void showAllWindowsLocked() {
8659 final int NW = allAppWindows.size();
8660 for (int i=0; i<NW; i++) {
8661 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008662 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008663 "performing show on: " + w);
8664 w.performShowLocked();
8665 }
8666 }
Romain Guy06882f82009-06-10 13:36:04 -07008667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 // This must be called while inside a transaction.
8669 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008670 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 if (animation == sDummyAnimation) {
8674 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008675 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008676 // when it is really time to animate, this will be set to
8677 // a real animation and the next call will execute normally.
8678 return false;
8679 }
Romain Guy06882f82009-06-10 13:36:04 -07008680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8682 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008683 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008684 TAG, "Starting animation in " + this +
8685 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8686 + " scale=" + mTransitionAnimationScale
8687 + " allDrawn=" + allDrawn + " animating=" + animating);
8688 animation.initialize(dw, dh, dw, dh);
8689 animation.setStartTime(currentTime);
8690 animating = true;
8691 }
8692 transformation.clear();
8693 final boolean more = animation.getTransformation(
8694 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008695 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 TAG, "Stepped animation in " + this +
8697 ": more=" + more + ", xform=" + transformation);
8698 if (more) {
8699 // we're done!
8700 hasTransformation = true;
8701 return true;
8702 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008703 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 TAG, "Finished animation in " + this +
8705 " @ " + currentTime);
8706 animation = null;
8707 }
8708 } else if (animation != null) {
8709 // If the display is frozen, and there is a pending animation,
8710 // clear it and make sure we run the cleanup code.
8711 animating = true;
8712 animation = null;
8713 }
8714
8715 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008717 if (!animating) {
8718 return false;
8719 }
8720
8721 clearAnimation();
8722 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008723 if (animLayerAdjustment != 0) {
8724 animLayerAdjustment = 0;
8725 updateLayers();
8726 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008727 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8728 moveInputMethodWindowsIfNeededLocked(true);
8729 }
Romain Guy06882f82009-06-10 13:36:04 -07008730
Joe Onorato8a9b2202010-02-26 18:56:32 -08008731 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008732 TAG, "Animation done in " + this
8733 + ": reportedVisible=" + reportedVisible);
8734
8735 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 final int N = windows.size();
8738 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008739 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 }
8741 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008743 return false;
8744 }
8745
8746 void updateReportedVisibilityLocked() {
8747 if (appToken == null) {
8748 return;
8749 }
Romain Guy06882f82009-06-10 13:36:04 -07008750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008751 int numInteresting = 0;
8752 int numVisible = 0;
8753 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008754
Joe Onorato8a9b2202010-02-26 18:56:32 -08008755 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008756 final int N = allAppWindows.size();
8757 for (int i=0; i<N; i++) {
8758 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008759 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008760 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008761 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8762 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008763 continue;
8764 }
8765 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008766 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008767 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008769 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008770 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 + " pv=" + win.mPolicyVisibility
8772 + " dp=" + win.mDrawPending
8773 + " cdp=" + win.mCommitDrawPending
8774 + " ah=" + win.mAttachedHidden
8775 + " th="
8776 + (win.mAppToken != null
8777 ? win.mAppToken.hiddenRequested : false)
8778 + " a=" + win.mAnimating);
8779 }
8780 }
8781 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008782 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008783 if (!win.isAnimating()) {
8784 numVisible++;
8785 }
8786 nowGone = false;
8787 } else if (win.isAnimating()) {
8788 nowGone = false;
8789 }
8790 }
Romain Guy06882f82009-06-10 13:36:04 -07008791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008793 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008794 + numInteresting + " visible=" + numVisible);
8795 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008796 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 TAG, "Visibility changed in " + this
8798 + ": vis=" + nowVisible);
8799 reportedVisible = nowVisible;
8800 Message m = mH.obtainMessage(
8801 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8802 nowVisible ? 1 : 0,
8803 nowGone ? 1 : 0,
8804 this);
8805 mH.sendMessage(m);
8806 }
8807 }
Romain Guy06882f82009-06-10 13:36:04 -07008808
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008809 WindowState findMainWindow() {
8810 int j = windows.size();
8811 while (j > 0) {
8812 j--;
8813 WindowState win = windows.get(j);
8814 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8815 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8816 return win;
8817 }
8818 }
8819 return null;
8820 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008822 void dump(PrintWriter pw, String prefix) {
8823 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008824 if (appToken != null) {
8825 pw.print(prefix); pw.println("app=true");
8826 }
8827 if (allAppWindows.size() > 0) {
8828 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8829 }
8830 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008831 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008832 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8833 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8834 pw.print(" clientHidden="); pw.print(clientHidden);
8835 pw.print(" willBeHidden="); pw.print(willBeHidden);
8836 pw.print(" reportedVisible="); pw.println(reportedVisible);
8837 if (paused || freezingScreen) {
8838 pw.print(prefix); pw.print("paused="); pw.print(paused);
8839 pw.print(" freezingScreen="); pw.println(freezingScreen);
8840 }
8841 if (numInterestingWindows != 0 || numDrawnWindows != 0
8842 || inPendingTransaction || allDrawn) {
8843 pw.print(prefix); pw.print("numInterestingWindows=");
8844 pw.print(numInterestingWindows);
8845 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8846 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8847 pw.print(" allDrawn="); pw.println(allDrawn);
8848 }
8849 if (animating || animation != null) {
8850 pw.print(prefix); pw.print("animating="); pw.print(animating);
8851 pw.print(" animation="); pw.println(animation);
8852 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008853 if (hasTransformation) {
8854 pw.print(prefix); pw.print("XForm: ");
8855 transformation.printShortString(pw);
8856 pw.println();
8857 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008858 if (animLayerAdjustment != 0) {
8859 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8860 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008861 if (startingData != null || removed || firstWindowDrawn) {
8862 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8863 pw.print(" removed="); pw.print(removed);
8864 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8865 }
8866 if (startingWindow != null || startingView != null
8867 || startingDisplayed || startingMoved) {
8868 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8869 pw.print(" startingView="); pw.print(startingView);
8870 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8871 pw.print(" startingMoved"); pw.println(startingMoved);
8872 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 }
8874
8875 @Override
8876 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008877 if (stringName == null) {
8878 StringBuilder sb = new StringBuilder();
8879 sb.append("AppWindowToken{");
8880 sb.append(Integer.toHexString(System.identityHashCode(this)));
8881 sb.append(" token="); sb.append(token); sb.append('}');
8882 stringName = sb.toString();
8883 }
8884 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 }
8886 }
Romain Guy06882f82009-06-10 13:36:04 -07008887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008888 // -------------------------------------------------------------
8889 // DummyAnimation
8890 // -------------------------------------------------------------
8891
8892 // This is an animation that does nothing: it just immediately finishes
8893 // itself every time it is called. It is used as a stub animation in cases
8894 // where we want to synchronize multiple things that may be animating.
8895 static final class DummyAnimation extends Animation {
8896 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8897 return false;
8898 }
8899 }
8900 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008902 // -------------------------------------------------------------
8903 // Async Handler
8904 // -------------------------------------------------------------
8905
8906 static final class StartingData {
8907 final String pkg;
8908 final int theme;
8909 final CharSequence nonLocalizedLabel;
8910 final int labelRes;
8911 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008912 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008914 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008915 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008916 pkg = _pkg;
8917 theme = _theme;
8918 nonLocalizedLabel = _nonLocalizedLabel;
8919 labelRes = _labelRes;
8920 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008921 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008922 }
8923 }
8924
8925 private final class H extends Handler {
8926 public static final int REPORT_FOCUS_CHANGE = 2;
8927 public static final int REPORT_LOSING_FOCUS = 3;
8928 public static final int ANIMATE = 4;
8929 public static final int ADD_STARTING = 5;
8930 public static final int REMOVE_STARTING = 6;
8931 public static final int FINISHED_STARTING = 7;
8932 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8934 public static final int HOLD_SCREEN_CHANGED = 12;
8935 public static final int APP_TRANSITION_TIMEOUT = 13;
8936 public static final int PERSIST_ANIMATION_SCALE = 14;
8937 public static final int FORCE_GC = 15;
8938 public static final int ENABLE_SCREEN = 16;
8939 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008940 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008941 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008942 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008943 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08008944 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07008945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008946 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008948 public H() {
8949 }
Romain Guy06882f82009-06-10 13:36:04 -07008950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008951 @Override
8952 public void handleMessage(Message msg) {
8953 switch (msg.what) {
8954 case REPORT_FOCUS_CHANGE: {
8955 WindowState lastFocus;
8956 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008958 synchronized(mWindowMap) {
8959 lastFocus = mLastFocus;
8960 newFocus = mCurrentFocus;
8961 if (lastFocus == newFocus) {
8962 // Focus is not changing, so nothing to do.
8963 return;
8964 }
8965 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008966 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 // + " to " + newFocus);
8968 if (newFocus != null && lastFocus != null
8969 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008970 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008971 mLosingFocus.add(lastFocus);
8972 lastFocus = null;
8973 }
8974 }
8975
8976 if (lastFocus != newFocus) {
8977 //System.out.println("Changing focus from " + lastFocus
8978 // + " to " + newFocus);
8979 if (newFocus != null) {
8980 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008981 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008982 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8983 } catch (RemoteException e) {
8984 // Ignore if process has died.
8985 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008986 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 }
8988
8989 if (lastFocus != null) {
8990 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008991 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008992 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8993 } catch (RemoteException e) {
8994 // Ignore if process has died.
8995 }
8996 }
Joe Onorato664644d2011-01-23 17:53:23 -08008997
8998 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008999 }
9000 } break;
9001
9002 case REPORT_LOSING_FOCUS: {
9003 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07009004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009005 synchronized(mWindowMap) {
9006 losers = mLosingFocus;
9007 mLosingFocus = new ArrayList<WindowState>();
9008 }
9009
9010 final int N = losers.size();
9011 for (int i=0; i<N; i++) {
9012 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009013 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009014 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
9015 } catch (RemoteException e) {
9016 // Ignore if process has died.
9017 }
9018 }
9019 } break;
9020
9021 case ANIMATE: {
9022 synchronized(mWindowMap) {
9023 mAnimationPending = false;
9024 performLayoutAndPlaceSurfacesLocked();
9025 }
9026 } break;
9027
9028 case ADD_STARTING: {
9029 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9030 final StartingData sd = wtoken.startingData;
9031
9032 if (sd == null) {
9033 // Animation has been canceled... do nothing.
9034 return;
9035 }
Romain Guy06882f82009-06-10 13:36:04 -07009036
Joe Onorato8a9b2202010-02-26 18:56:32 -08009037 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009038 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07009039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009040 View view = null;
9041 try {
9042 view = mPolicy.addStartingWindow(
9043 wtoken.token, sd.pkg,
9044 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08009045 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009046 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009047 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009048 }
9049
9050 if (view != null) {
9051 boolean abort = false;
9052
9053 synchronized(mWindowMap) {
9054 if (wtoken.removed || wtoken.startingData == null) {
9055 // If the window was successfully added, then
9056 // we need to remove it.
9057 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009058 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009059 "Aborted starting " + wtoken
9060 + ": removed=" + wtoken.removed
9061 + " startingData=" + wtoken.startingData);
9062 wtoken.startingWindow = null;
9063 wtoken.startingData = null;
9064 abort = true;
9065 }
9066 } else {
9067 wtoken.startingView = view;
9068 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009069 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009070 "Added starting " + wtoken
9071 + ": startingWindow="
9072 + wtoken.startingWindow + " startingView="
9073 + wtoken.startingView);
9074 }
9075
9076 if (abort) {
9077 try {
9078 mPolicy.removeStartingWindow(wtoken.token, view);
9079 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009080 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009081 }
9082 }
9083 }
9084 } break;
9085
9086 case REMOVE_STARTING: {
9087 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9088 IBinder token = null;
9089 View view = null;
9090 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009091 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009092 + wtoken + ": startingWindow="
9093 + wtoken.startingWindow + " startingView="
9094 + wtoken.startingView);
9095 if (wtoken.startingWindow != null) {
9096 view = wtoken.startingView;
9097 token = wtoken.token;
9098 wtoken.startingData = null;
9099 wtoken.startingView = null;
9100 wtoken.startingWindow = null;
9101 }
9102 }
9103 if (view != null) {
9104 try {
9105 mPolicy.removeStartingWindow(token, view);
9106 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009107 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009108 }
9109 }
9110 } break;
9111
9112 case FINISHED_STARTING: {
9113 IBinder token = null;
9114 View view = null;
9115 while (true) {
9116 synchronized (mWindowMap) {
9117 final int N = mFinishedStarting.size();
9118 if (N <= 0) {
9119 break;
9120 }
9121 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9122
Joe Onorato8a9b2202010-02-26 18:56:32 -08009123 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124 "Finished starting " + wtoken
9125 + ": startingWindow=" + wtoken.startingWindow
9126 + " startingView=" + wtoken.startingView);
9127
9128 if (wtoken.startingWindow == null) {
9129 continue;
9130 }
9131
9132 view = wtoken.startingView;
9133 token = wtoken.token;
9134 wtoken.startingData = null;
9135 wtoken.startingView = null;
9136 wtoken.startingWindow = null;
9137 }
9138
9139 try {
9140 mPolicy.removeStartingWindow(token, view);
9141 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009142 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 }
9144 }
9145 } break;
9146
9147 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9148 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9149
9150 boolean nowVisible = msg.arg1 != 0;
9151 boolean nowGone = msg.arg2 != 0;
9152
9153 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009154 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009155 TAG, "Reporting visible in " + wtoken
9156 + " visible=" + nowVisible
9157 + " gone=" + nowGone);
9158 if (nowVisible) {
9159 wtoken.appToken.windowsVisible();
9160 } else {
9161 wtoken.appToken.windowsGone();
9162 }
9163 } catch (RemoteException ex) {
9164 }
9165 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009167 case WINDOW_FREEZE_TIMEOUT: {
9168 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009169 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009170 int i = mWindows.size();
9171 while (i > 0) {
9172 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009173 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 if (w.mOrientationChanging) {
9175 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009176 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009177 }
9178 }
9179 performLayoutAndPlaceSurfacesLocked();
9180 }
9181 break;
9182 }
Romain Guy06882f82009-06-10 13:36:04 -07009183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 case HOLD_SCREEN_CHANGED: {
9185 Session oldHold;
9186 Session newHold;
9187 synchronized (mWindowMap) {
9188 oldHold = mLastReportedHold;
9189 newHold = (Session)msg.obj;
9190 mLastReportedHold = newHold;
9191 }
Romain Guy06882f82009-06-10 13:36:04 -07009192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009193 if (oldHold != newHold) {
9194 try {
9195 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009196 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009197 "window",
9198 BatteryStats.WAKE_TYPE_WINDOW);
9199 }
9200 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009201 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202 "window",
9203 BatteryStats.WAKE_TYPE_WINDOW);
9204 }
9205 } catch (RemoteException e) {
9206 }
9207 }
9208 break;
9209 }
Romain Guy06882f82009-06-10 13:36:04 -07009210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 case APP_TRANSITION_TIMEOUT: {
9212 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009213 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009214 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009215 "*** APP TRANSITION TIMEOUT");
9216 mAppTransitionReady = true;
9217 mAppTransitionTimeout = true;
9218 performLayoutAndPlaceSurfacesLocked();
9219 }
9220 }
9221 break;
9222 }
Romain Guy06882f82009-06-10 13:36:04 -07009223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224 case PERSIST_ANIMATION_SCALE: {
9225 Settings.System.putFloat(mContext.getContentResolver(),
9226 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9227 Settings.System.putFloat(mContext.getContentResolver(),
9228 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9229 break;
9230 }
Romain Guy06882f82009-06-10 13:36:04 -07009231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009232 case FORCE_GC: {
9233 synchronized(mWindowMap) {
9234 if (mAnimationPending) {
9235 // If we are animating, don't do the gc now but
9236 // delay a bit so we don't interrupt the animation.
9237 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9238 2000);
9239 return;
9240 }
9241 // If we are currently rotating the display, it will
9242 // schedule a new message when done.
9243 if (mDisplayFrozen) {
9244 return;
9245 }
9246 mFreezeGcPending = 0;
9247 }
9248 Runtime.getRuntime().gc();
9249 break;
9250 }
Romain Guy06882f82009-06-10 13:36:04 -07009251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009252 case ENABLE_SCREEN: {
9253 performEnableScreen();
9254 break;
9255 }
Romain Guy06882f82009-06-10 13:36:04 -07009256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 case APP_FREEZE_TIMEOUT: {
9258 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009259 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 int i = mAppTokens.size();
9261 while (i > 0) {
9262 i--;
9263 AppWindowToken tok = mAppTokens.get(i);
9264 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009265 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009266 unsetAppFreezingScreenLocked(tok, true, true);
9267 }
9268 }
9269 }
9270 break;
9271 }
Romain Guy06882f82009-06-10 13:36:04 -07009272
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009273 case SEND_NEW_CONFIGURATION: {
9274 removeMessages(SEND_NEW_CONFIGURATION);
9275 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009276 break;
9277 }
Romain Guy06882f82009-06-10 13:36:04 -07009278
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009279 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009280 if (mWindowsChanged) {
9281 synchronized (mWindowMap) {
9282 mWindowsChanged = false;
9283 }
9284 notifyWindowsChanged();
9285 }
9286 break;
9287 }
9288
Christopher Tatea53146c2010-09-07 11:57:52 -07009289 case DRAG_START_TIMEOUT: {
9290 IBinder win = (IBinder)msg.obj;
9291 if (DEBUG_DRAG) {
9292 Slog.w(TAG, "Timeout starting drag by win " + win);
9293 }
9294 synchronized (mWindowMap) {
9295 // !!! TODO: ANR the app that has failed to start the drag in time
9296 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009297 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009298 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009299 mDragState.reset();
9300 mDragState = null;
9301 }
9302 }
Chris Tated4533f142010-10-19 15:15:08 -07009303 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009304 }
9305
Chris Tated4533f142010-10-19 15:15:08 -07009306 case DRAG_END_TIMEOUT: {
9307 IBinder win = (IBinder)msg.obj;
9308 if (DEBUG_DRAG) {
9309 Slog.w(TAG, "Timeout ending drag to win " + win);
9310 }
9311 synchronized (mWindowMap) {
9312 // !!! TODO: ANR the drag-receiving app
9313 mDragState.mDragResult = false;
9314 mDragState.endDragLw();
9315 }
9316 break;
9317 }
Jeff Brown2992ea72011-01-28 22:04:14 -08009318
9319 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
9320 notifyHardKeyboardStatusChange();
9321 break;
9322 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 }
9324 }
9325 }
9326
9327 // -------------------------------------------------------------
9328 // IWindowManager API
9329 // -------------------------------------------------------------
9330
9331 public IWindowSession openSession(IInputMethodClient client,
9332 IInputContext inputContext) {
9333 if (client == null) throw new IllegalArgumentException("null client");
9334 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009335 Session session = new Session(client, inputContext);
9336 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009337 }
9338
9339 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9340 synchronized (mWindowMap) {
9341 // The focus for the client is the window immediately below
9342 // where we would place the input method window.
9343 int idx = findDesiredInputMethodWindowIndexLocked(false);
9344 WindowState imFocus;
9345 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009346 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009347 //Log.i(TAG, "Desired input method target: " + imFocus);
9348 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9349 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009350 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009351 // This may be a starting window, in which case we still want
9352 // to count it as okay.
9353 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9354 && imFocus.mAppToken != null) {
9355 // The client has definitely started, so it really should
9356 // have a window in this app token. Let's look for it.
9357 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9358 WindowState w = imFocus.mAppToken.windows.get(i);
9359 if (w != imFocus) {
9360 //Log.i(TAG, "Switching to real app window: " + w);
9361 imFocus = w;
9362 break;
9363 }
9364 }
9365 }
9366 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9367 //if (imFocus.mSession.mClient != null) {
9368 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9369 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9370 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009371 if (imFocus.mSession.mClient != null &&
9372 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9373 return true;
9374 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009375
9376 // Okay, how about this... what is the current focus?
9377 // It seems in some cases we may not have moved the IM
9378 // target window, such as when it was in a pop-up window,
9379 // so let's also look at the current focus. (An example:
9380 // go to Gmail, start searching so the keyboard goes up,
9381 // press home. Sometimes the IME won't go down.)
9382 // Would be nice to fix this more correctly, but it's
9383 // way at the end of a release, and this should be good enough.
9384 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9385 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9386 return true;
9387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388 }
9389 }
9390 }
9391 return false;
9392 }
Romain Guy06882f82009-06-10 13:36:04 -07009393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009394 // -------------------------------------------------------------
9395 // Internals
9396 // -------------------------------------------------------------
9397
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009398 final WindowState windowForClientLocked(Session session, IWindow client,
9399 boolean throwOnError) {
9400 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009401 }
Romain Guy06882f82009-06-10 13:36:04 -07009402
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009403 final WindowState windowForClientLocked(Session session, IBinder client,
9404 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009405 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009406 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 TAG, "Looking up client " + client + ": " + win);
9408 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009409 RuntimeException ex = new IllegalArgumentException(
9410 "Requested window " + client + " does not exist");
9411 if (throwOnError) {
9412 throw ex;
9413 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009414 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 return null;
9416 }
9417 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009418 RuntimeException ex = new IllegalArgumentException(
9419 "Requested window " + client + " is in session " +
9420 win.mSession + ", not " + session);
9421 if (throwOnError) {
9422 throw ex;
9423 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009424 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009425 return null;
9426 }
9427
9428 return win;
9429 }
9430
Dianne Hackborna8f60182009-09-01 19:01:50 -07009431 final void rebuildAppWindowListLocked() {
9432 int NW = mWindows.size();
9433 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009434 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009435 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009436
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009437 if (mRebuildTmp.length < NW) {
9438 mRebuildTmp = new WindowState[NW+10];
9439 }
9440
Dianne Hackborna8f60182009-09-01 19:01:50 -07009441 // First remove all existing app windows.
9442 i=0;
9443 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009444 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009445 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009446 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009447 win.mRebuilding = true;
9448 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009449 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009450 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009451 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009452 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009453 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009454 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009455 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9456 && lastWallpaper == i-1) {
9457 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009458 }
9459 i++;
9460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009461
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009462 // The wallpaper window(s) typically live at the bottom of the stack,
9463 // so skip them before adding app tokens.
9464 lastWallpaper++;
9465 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009466
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009467 // First add all of the exiting app tokens... these are no longer
9468 // in the main app list, but still have windows shown. We put them
9469 // in the back because now that the animation is over we no longer
9470 // will care about them.
9471 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009472 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009473 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9474 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009475
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009476 // And add in the still active app tokens in Z order.
9477 NT = mAppTokens.size();
9478 for (int j=0; j<NT; j++) {
9479 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009480 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009481
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009482 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009483 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009484 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009485 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009486 for (i=0; i<numRemoved; i++) {
9487 WindowState ws = mRebuildTmp[i];
9488 if (ws.mRebuilding) {
9489 StringWriter sw = new StringWriter();
9490 PrintWriter pw = new PrintWriter(sw);
9491 ws.dump(pw, "");
9492 pw.flush();
9493 Slog.w(TAG, "This window was lost: " + ws);
9494 Slog.w(TAG, sw.toString());
9495 }
9496 }
9497 Slog.w(TAG, "Current app token list:");
9498 dumpAppTokensLocked();
9499 Slog.w(TAG, "Final window list:");
9500 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009501 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009502 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009504 private final void assignLayersLocked() {
9505 int N = mWindows.size();
9506 int curBaseLayer = 0;
9507 int curLayer = 0;
9508 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009509
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009510 if (DEBUG_LAYERS) {
9511 RuntimeException here = new RuntimeException("here");
9512 here.fillInStackTrace();
9513 Log.v(TAG, "Assigning layers", here);
9514 }
9515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009517 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009518 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9519 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009520 curLayer += WINDOW_LAYER_MULTIPLIER;
9521 w.mLayer = curLayer;
9522 } else {
9523 curBaseLayer = curLayer = w.mBaseLayer;
9524 w.mLayer = curLayer;
9525 }
9526 if (w.mTargetAppToken != null) {
9527 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9528 } else if (w.mAppToken != null) {
9529 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9530 } else {
9531 w.mAnimLayer = w.mLayer;
9532 }
9533 if (w.mIsImWindow) {
9534 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009535 } else if (w.mIsWallpaper) {
9536 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009537 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009538 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 + w.mAnimLayer);
9540 //System.out.println(
9541 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9542 }
9543 }
9544
9545 private boolean mInLayout = false;
9546 private final void performLayoutAndPlaceSurfacesLocked() {
9547 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009548 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009549 throw new RuntimeException("Recursive call!");
9550 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009551 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 return;
9553 }
9554
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009555 if (mWaitingForConfig) {
9556 // Our configuration has changed (most likely rotation), but we
9557 // don't yet have the complete configuration to report to
9558 // applications. Don't do any window layout until we have it.
9559 return;
9560 }
9561
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009562 if (mDisplay == null) {
9563 // Not yet initialized, nothing to do.
9564 return;
9565 }
9566
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009567 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009568 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009569
9570 try {
9571 if (mForceRemoves != null) {
9572 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009573 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009574 for (int i=0; i<mForceRemoves.size(); i++) {
9575 WindowState ws = mForceRemoves.get(i);
9576 Slog.i(TAG, "Force removing: " + ws);
9577 removeWindowInnerLocked(ws.mSession, ws);
9578 }
9579 mForceRemoves = null;
9580 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9581 Object tmp = new Object();
9582 synchronized (tmp) {
9583 try {
9584 tmp.wait(250);
9585 } catch (InterruptedException e) {
9586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009587 }
9588 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009589 } catch (RuntimeException e) {
9590 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009591 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 try {
9594 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009595
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009596 int N = mPendingRemove.size();
9597 if (N > 0) {
9598 if (mPendingRemoveTmp.length < N) {
9599 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009601 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009602 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009603 for (int i=0; i<N; i++) {
9604 WindowState w = mPendingRemoveTmp[i];
9605 removeWindowInnerLocked(w.mSession, w);
9606 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009607
9608 mInLayout = false;
9609 assignLayersLocked();
9610 mLayoutNeeded = true;
9611 performLayoutAndPlaceSurfacesLocked();
9612
9613 } else {
9614 mInLayout = false;
9615 if (mLayoutNeeded) {
9616 requestAnimationLocked(0);
9617 }
9618 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009619 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009620 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9621 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009623 } catch (RuntimeException e) {
9624 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009625 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009626 }
9627 }
9628
Jeff Brown3a22cd92011-01-21 13:59:04 -08009629 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009630 if (!mLayoutNeeded) {
9631 return 0;
9632 }
9633
9634 mLayoutNeeded = false;
9635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009636 final int dw = mDisplay.getWidth();
9637 final int dh = mDisplay.getHeight();
9638
9639 final int N = mWindows.size();
9640 int i;
9641
Joe Onorato8a9b2202010-02-26 18:56:32 -08009642 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009643 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9644
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009645 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009646
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009647 int seq = mLayoutSeq+1;
9648 if (seq < 0) seq = 0;
9649 mLayoutSeq = seq;
9650
9651 // First perform layout of any root windows (not attached
9652 // to another window).
9653 int topAttached = -1;
9654 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009655 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009656
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009657 // Don't do layout of a window if it is not visible, or
9658 // soon won't be visible, to avoid wasting time and funky
9659 // changes while a window is animating away.
9660 final AppWindowToken atoken = win.mAppToken;
9661 final boolean gone = win.mViewVisibility == View.GONE
9662 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009663 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009664 || (atoken != null && atoken.hiddenRequested)
9665 || win.mAttachedHidden
9666 || win.mExiting || win.mDestroying;
9667
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009668 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9669 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009670 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9671 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009672 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009673 + win.mViewVisibility + " mRelayoutCalled="
9674 + win.mRelayoutCalled + " hidden="
9675 + win.mRootToken.hidden + " hiddenRequested="
9676 + (atoken != null && atoken.hiddenRequested)
9677 + " mAttachedHidden=" + win.mAttachedHidden);
9678 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009679
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009680 // If this view is GONE, then skip it -- keep the current
9681 // frame, and let the caller know so they can ignore it
9682 // if they want. (We do the normal layout for INVISIBLE
9683 // windows, since that means "perform layout as normal,
9684 // just don't display").
9685 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009686 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009687 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009688 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009689 win.mContentChanged = false;
9690 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009691 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9692 win.mLayoutSeq = seq;
9693 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9694 + win.mFrame + " mContainingFrame="
9695 + win.mContainingFrame + " mDisplayFrame="
9696 + win.mDisplayFrame);
9697 } else {
9698 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009699 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009700 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009701 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009702
9703 // Now perform layout of attached windows, which usually
9704 // depend on the position of the window they are attached to.
9705 // XXX does not deal with windows that are attached to windows
9706 // that are themselves attached.
9707 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009708 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009709
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009710 if (win.mLayoutAttached) {
9711 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9712 + " mHaveFrame=" + win.mHaveFrame
9713 + " mViewVisibility=" + win.mViewVisibility
9714 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009715 // If this view is GONE, then skip it -- keep the current
9716 // frame, and let the caller know so they can ignore it
9717 // if they want. (We do the normal layout for INVISIBLE
9718 // windows, since that means "perform layout as normal,
9719 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009720 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9721 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009722 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009723 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009724 win.mContentChanged = false;
9725 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009726 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9727 win.mLayoutSeq = seq;
9728 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9729 + win.mFrame + " mContainingFrame="
9730 + win.mContainingFrame + " mDisplayFrame="
9731 + win.mDisplayFrame);
9732 }
9733 }
9734 }
Jeff Brown349703e2010-06-22 01:27:15 -07009735
9736 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009737 mInputMonitor.setUpdateInputWindowsNeededLw();
9738 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009739 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009740 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009741
9742 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009743 }
Romain Guy06882f82009-06-10 13:36:04 -07009744
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009745 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 private final void performLayoutAndPlaceSurfacesLockedInner(
9747 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009748 if (mDisplay == null) {
9749 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9750 return;
9751 }
9752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 final long currentTime = SystemClock.uptimeMillis();
9754 final int dw = mDisplay.getWidth();
9755 final int dh = mDisplay.getHeight();
9756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009757 int i;
9758
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009759 if (mFocusMayChange) {
9760 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009761 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9762 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009763 }
9764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 // Initialize state of exiting tokens.
9766 for (i=mExitingTokens.size()-1; i>=0; i--) {
9767 mExitingTokens.get(i).hasVisible = false;
9768 }
9769
9770 // Initialize state of exiting applications.
9771 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9772 mExitingAppTokens.get(i).hasVisible = false;
9773 }
9774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 boolean orientationChangeComplete = true;
9776 Session holdScreen = null;
9777 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009778 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009779 boolean focusDisplayed = false;
9780 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009781 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009782 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009783
9784 if (mFxSession == null) {
9785 mFxSession = new SurfaceSession();
9786 createWatermark = true;
9787 }
9788
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009789 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009790
9791 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009792
9793 if (createWatermark) {
9794 createWatermark();
9795 }
9796 if (mWatermark != null) {
9797 mWatermark.positionSurface(dw, dh);
9798 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009799 if (mStrictModeFlash != null) {
9800 mStrictModeFlash.positionSurface(dw, dh);
9801 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009803 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009804 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009805 int repeats = 0;
9806 int changes = 0;
9807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009809 repeats++;
9810 if (repeats > 6) {
9811 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9812 mLayoutNeeded = false;
9813 break;
9814 }
9815
9816 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9817 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9818 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9819 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9820 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9821 assignLayersLocked();
9822 mLayoutNeeded = true;
9823 }
9824 }
9825 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9826 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009827 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009828 mLayoutNeeded = true;
9829 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9830 }
9831 }
9832 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9833 mLayoutNeeded = true;
9834 }
9835 }
9836
9837 // FIRST LOOP: Perform a layout, if needed.
9838 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009839 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009840 if (changes != 0) {
9841 continue;
9842 }
9843 } else {
9844 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9845 changes = 0;
9846 }
9847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 final int transactionSequence = ++mTransactionSequence;
9849
9850 // Update animations of all applications, including those
9851 // associated with exiting/removed apps
9852 boolean tokensAnimating = false;
9853 final int NAT = mAppTokens.size();
9854 for (i=0; i<NAT; i++) {
9855 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9856 tokensAnimating = true;
9857 }
9858 }
9859 final int NEAT = mExitingAppTokens.size();
9860 for (i=0; i<NEAT; i++) {
9861 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9862 tokensAnimating = true;
9863 }
9864 }
9865
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009866 // SECOND LOOP: Execute animations and update visibility of windows.
9867
Joe Onorato8a9b2202010-02-26 18:56:32 -08009868 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009869 + transactionSequence + " tokensAnimating="
9870 + tokensAnimating);
9871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009873
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009874 if (mScreenRotationAnimation != null) {
9875 if (mScreenRotationAnimation.isAnimating()) {
9876 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9877 animating = true;
9878 } else {
9879 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009880 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009881 }
9882 }
9883 }
9884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009886 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009887 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009888 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889
9890 mPolicy.beginAnimationLw(dw, dh);
9891
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009892 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009894 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009895 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896
9897 final WindowManager.LayoutParams attrs = w.mAttrs;
9898
9899 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009900 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009901 if (w.commitFinishDrawingLocked(currentTime)) {
9902 if ((w.mAttrs.flags
9903 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009904 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009905 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009906 wallpaperMayChange = true;
9907 }
9908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009909
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009910 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009911
9912 int animDw = dw;
9913 int animDh = dh;
9914
9915 // If the window has moved due to its containing
9916 // content frame changing, then we'd like to animate
9917 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009918 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009919 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009920 // Frame has moved, containing content frame
9921 // has also moved, and we're not currently animating...
9922 // let's do something.
9923 Animation a = AnimationUtils.loadAnimation(mContext,
9924 com.android.internal.R.anim.window_move_from_decor);
9925 w.setAnimation(a);
9926 animDw = w.mLastFrame.left - w.mFrame.left;
9927 animDh = w.mLastFrame.top - w.mFrame.top;
9928 }
9929
9930 // Execute animation.
9931 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9932 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009933
9934 // If this window is animating, make a note that we have
9935 // an animating window and take care of a request to run
9936 // a detached wallpaper animation.
9937 if (nowAnimating) {
9938 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9939 windowDetachedWallpaper = w;
9940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009941 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009942 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009943
9944 // If this window's app token is running a detached wallpaper
9945 // animation, make a note so we can ensure the wallpaper is
9946 // displayed behind it.
9947 if (w.mAppToken != null && w.mAppToken.animation != null
9948 && w.mAppToken.animation.getDetachWallpaper()) {
9949 windowDetachedWallpaper = w;
9950 }
9951
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009952 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9953 wallpaperMayChange = true;
9954 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009955
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009956 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009957 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009958 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009959 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009960 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009961 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009962 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009963 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9964 forceHiding = true;
9965 }
9966 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9967 boolean changed;
9968 if (forceHiding) {
9969 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009970 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9971 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009972 } else {
9973 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009974 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9975 "Now policy shown: " + w);
9976 if (changed) {
9977 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009978 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009979 // Assume we will need to animate. If
9980 // we don't (because the wallpaper will
9981 // stay with the lock screen), then we will
9982 // clean up later.
9983 Animation a = mPolicy.createForceHideEnterAnimation();
9984 if (a != null) {
9985 w.setAnimation(a);
9986 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009987 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009988 if (mCurrentFocus == null ||
9989 mCurrentFocus.mLayer < w.mLayer) {
9990 // We are showing on to of the current
9991 // focus, so re-evaluate focus to make
9992 // sure it is correct.
9993 mFocusMayChange = true;
9994 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009995 }
9996 }
9997 if (changed && (attrs.flags
9998 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9999 wallpaperMayChange = true;
10000 }
10001 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 mPolicy.animatingWindowLw(w, attrs);
10004 }
10005
10006 final AppWindowToken atoken = w.mAppToken;
10007 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
10008 if (atoken.lastTransactionSequence != transactionSequence) {
10009 atoken.lastTransactionSequence = transactionSequence;
10010 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
10011 atoken.startingDisplayed = false;
10012 }
10013 if ((w.isOnScreen() || w.mAttrs.type
10014 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
10015 && !w.mExiting && !w.mDestroying) {
10016 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010017 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010018 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010019 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010020 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010021 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010022 + " pv=" + w.mPolicyVisibility
10023 + " dp=" + w.mDrawPending
10024 + " cdp=" + w.mCommitDrawPending
10025 + " ah=" + w.mAttachedHidden
10026 + " th=" + atoken.hiddenRequested
10027 + " a=" + w.mAnimating);
10028 }
10029 }
10030 if (w != atoken.startingWindow) {
10031 if (!atoken.freezingScreen || !w.mAppFreezing) {
10032 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010033 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010034 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010035 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036 "tokenMayBeDrawn: " + atoken
10037 + " freezingScreen=" + atoken.freezingScreen
10038 + " mAppFreezing=" + w.mAppFreezing);
10039 tokenMayBeDrawn = true;
10040 }
10041 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010042 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010043 atoken.startingDisplayed = true;
10044 }
10045 }
10046 } else if (w.mReadyToShow) {
10047 w.performShowLocked();
10048 }
10049 }
10050
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010051 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010052
10053 if (tokenMayBeDrawn) {
10054 // See if any windows have been drawn, so they (and others
10055 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010056 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010057 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010058 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010059 if (wtoken.freezingScreen) {
10060 int numInteresting = wtoken.numInterestingWindows;
10061 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010062 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 "allDrawn: " + wtoken
10064 + " interesting=" + numInteresting
10065 + " drawn=" + wtoken.numDrawnWindows);
10066 wtoken.showAllWindowsLocked();
10067 unsetAppFreezingScreenLocked(wtoken, false, true);
10068 orientationChangeComplete = true;
10069 }
10070 } else if (!wtoken.allDrawn) {
10071 int numInteresting = wtoken.numInterestingWindows;
10072 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010073 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074 "allDrawn: " + wtoken
10075 + " interesting=" + numInteresting
10076 + " drawn=" + wtoken.numDrawnWindows);
10077 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010078 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010079
10080 // We can now show all of the drawn windows!
10081 if (!mOpeningApps.contains(wtoken)) {
10082 wtoken.showAllWindowsLocked();
10083 }
10084 }
10085 }
10086 }
10087 }
10088
10089 // If we are ready to perform an app transition, check through
10090 // all of the app tokens to be shown and see if they are ready
10091 // to go.
10092 if (mAppTransitionReady) {
10093 int NN = mOpeningApps.size();
10094 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010095 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010096 "Checking " + NN + " opening apps (frozen="
10097 + mDisplayFrozen + " timeout="
10098 + mAppTransitionTimeout + ")...");
10099 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10100 // If the display isn't frozen, wait to do anything until
10101 // all of the apps are ready. Otherwise just go because
10102 // we'll unfreeze the display when everyone is ready.
10103 for (i=0; i<NN && goodToGo; i++) {
10104 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010105 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 "Check opening app" + wtoken + ": allDrawn="
10107 + wtoken.allDrawn + " startingDisplayed="
10108 + wtoken.startingDisplayed);
10109 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10110 && !wtoken.startingMoved) {
10111 goodToGo = false;
10112 }
10113 }
10114 }
10115 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010116 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 int transit = mNextAppTransition;
10118 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010119 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010120 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010121 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010122 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010123 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 mAppTransitionTimeout = false;
10125 mStartingIconInTransition = false;
10126 mSkipAppTransitionAnimation = false;
10127
10128 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10129
Dianne Hackborna8f60182009-09-01 19:01:50 -070010130 // If there are applications waiting to come to the
10131 // top of the stack, now is the time to move their windows.
10132 // (Note that we don't do apps going to the bottom
10133 // here -- we want to keep their windows in the old
10134 // Z-order until the animation completes.)
10135 if (mToTopApps.size() > 0) {
10136 NN = mAppTokens.size();
10137 for (i=0; i<NN; i++) {
10138 AppWindowToken wtoken = mAppTokens.get(i);
10139 if (wtoken.sendingToTop) {
10140 wtoken.sendingToTop = false;
10141 moveAppWindowsLocked(wtoken, NN, false);
10142 }
10143 }
10144 mToTopApps.clear();
10145 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010146
Dianne Hackborn25994b42009-09-04 14:21:19 -070010147 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010148
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010149 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010150 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010151
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010152 // The top-most window will supply the layout params,
10153 // and we will determine it below.
10154 LayoutParams animLp = null;
10155 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010156 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010157
Joe Onorato8a9b2202010-02-26 18:56:32 -080010158 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010159 "New wallpaper target=" + mWallpaperTarget
10160 + ", lower target=" + mLowerWallpaperTarget
10161 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010162 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010163 // Do a first pass through the tokens for two
10164 // things:
10165 // (1) Determine if both the closing and opening
10166 // app token sets are wallpaper targets, in which
10167 // case special animations are needed
10168 // (since the wallpaper needs to stay static
10169 // behind them).
10170 // (2) Find the layout params of the top-most
10171 // application window in the tokens, which is
10172 // what will control the animation theme.
10173 final int NC = mClosingApps.size();
10174 NN = NC + mOpeningApps.size();
10175 for (i=0; i<NN; i++) {
10176 AppWindowToken wtoken;
10177 int mode;
10178 if (i < NC) {
10179 wtoken = mClosingApps.get(i);
10180 mode = 1;
10181 } else {
10182 wtoken = mOpeningApps.get(i-NC);
10183 mode = 2;
10184 }
10185 if (mLowerWallpaperTarget != null) {
10186 if (mLowerWallpaperTarget.mAppToken == wtoken
10187 || mUpperWallpaperTarget.mAppToken == wtoken) {
10188 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010189 }
10190 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010191 if (wtoken.appFullscreen) {
10192 WindowState ws = wtoken.findMainWindow();
10193 if (ws != null) {
10194 // If this is a compatibility mode
10195 // window, we will always use its anim.
10196 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10197 animLp = ws.mAttrs;
10198 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010199 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010200 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010201 bestAnimLayer = ws.mLayer;
10202 }
10203 fullscreenAnim = true;
10204 }
10205 } else if (!fullscreenAnim) {
10206 WindowState ws = wtoken.findMainWindow();
10207 if (ws != null) {
10208 if (ws.mLayer > bestAnimLayer) {
10209 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010210 bestAnimLayer = ws.mLayer;
10211 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010212 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010213 }
10214 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010215
Dianne Hackborn25994b42009-09-04 14:21:19 -070010216 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010217 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010218 "Wallpaper animation!");
10219 switch (transit) {
10220 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10221 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10222 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10223 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10224 break;
10225 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10226 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10227 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10228 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10229 break;
10230 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010231 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010232 "New transit: " + transit);
10233 } else if (oldWallpaper != null) {
10234 // We are transitioning from an activity with
10235 // a wallpaper to one without.
10236 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010237 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010238 "New transit away from wallpaper: " + transit);
10239 } else if (mWallpaperTarget != null) {
10240 // We are transitioning from an activity without
10241 // a wallpaper to now showing the wallpaper
10242 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010243 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010244 "New transit into wallpaper: " + transit);
10245 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010246
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010247 // If all closing windows are obscured, then there is
10248 // no need to do an animation. This is the case, for
10249 // example, when this transition is being done behind
10250 // the lock screen.
10251 if (!mPolicy.allowAppAnimationsLw()) {
10252 animLp = null;
10253 }
10254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010255 NN = mOpeningApps.size();
10256 for (i=0; i<NN; i++) {
10257 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010258 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010259 "Now opening app" + wtoken);
10260 wtoken.reportedVisible = false;
10261 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010262 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010263 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010264 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010265 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 wtoken.showAllWindowsLocked();
10267 }
10268 NN = mClosingApps.size();
10269 for (i=0; i<NN; i++) {
10270 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010271 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 "Now closing app" + wtoken);
10273 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010274 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010275 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010276 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010277 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 // Force the allDrawn flag, because we want to start
10279 // this guy's animations regardless of whether it's
10280 // gotten drawn.
10281 wtoken.allDrawn = true;
10282 }
10283
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010284 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 mOpeningApps.clear();
10287 mClosingApps.clear();
10288
10289 // This has changed the visibility of windows, so perform
10290 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010291 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10292 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010294 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10295 assignLayersLocked();
10296 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010297 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10298 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010299 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010300 }
10301 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010302
Dianne Hackborn16064f92010-03-25 00:47:24 -070010303 int adjResult = 0;
10304
Dianne Hackborna8f60182009-09-01 19:01:50 -070010305 if (!animating && mAppTransitionRunning) {
10306 // We have finished the animation of an app transition. To do
10307 // this, we have delayed a lot of operations like showing and
10308 // hiding apps, moving apps in Z-order, etc. The app token list
10309 // reflects the correct Z-order, but the window list may now
10310 // be out of sync with it. So here we will just rebuild the
10311 // entire app window list. Fun!
10312 mAppTransitionRunning = false;
10313 // Clear information about apps that were moving.
10314 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010315
Dianne Hackborna8f60182009-09-01 19:01:50 -070010316 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010317 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010318 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010319 moveInputMethodWindowsIfNeededLocked(false);
10320 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010321 // Since the window list has been rebuilt, focus might
10322 // have to be recomputed since the actual order of windows
10323 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010324 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010325 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010326
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010327 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010328 // At this point, there was a window with a wallpaper that
10329 // was force hiding other windows behind it, but now it
10330 // is going away. This may be simple -- just animate
10331 // away the wallpaper and its window -- or it may be
10332 // hard -- the wallpaper now needs to be shown behind
10333 // something that was hidden.
10334 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010335 if (mLowerWallpaperTarget != null
10336 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010337 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010338 "wallpaperForceHiding changed with lower="
10339 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010340 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010341 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10342 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10343 if (mLowerWallpaperTarget.mAppToken.hidden) {
10344 // The lower target has become hidden before we
10345 // actually started the animation... let's completely
10346 // re-evaluate everything.
10347 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010348 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010349 }
10350 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010351 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010352 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010353 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010354 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010355 + " NEW: " + mWallpaperTarget
10356 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010357 if (mLowerWallpaperTarget == null) {
10358 // Whoops, we don't need a special wallpaper animation.
10359 // Clear them out.
10360 forceHiding = false;
10361 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010362 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010363 if (w.mSurface != null) {
10364 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010365 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010366 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010367 forceHiding = true;
10368 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10369 if (!w.mAnimating) {
10370 // We set the animation above so it
10371 // is not yet running.
10372 w.clearAnimation();
10373 }
10374 }
10375 }
10376 }
10377 }
10378 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010379
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010380 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10381 if (DEBUG_WALLPAPER) Slog.v(TAG,
10382 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10383 + windowDetachedWallpaper);
10384 mWindowDetachedWallpaper = windowDetachedWallpaper;
10385 wallpaperMayChange = true;
10386 }
10387
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010388 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010389 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010390 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010391 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010393
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010394 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010395 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010396 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010397 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010398 assignLayersLocked();
10399 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010400 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010401 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010402 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010404
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010405 if (mFocusMayChange) {
10406 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010407 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10408 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010409 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010410 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010411 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010412 }
10413
10414 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010415 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010416 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010417
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010418 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10419 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010420 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421
10422 // THIRD LOOP: Update the surfaces of all windows.
10423
10424 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10425
10426 boolean obscured = false;
10427 boolean blurring = false;
10428 boolean dimming = false;
10429 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010430 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010431 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010433 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010436 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437
10438 boolean displayed = false;
10439 final WindowManager.LayoutParams attrs = w.mAttrs;
10440 final int attrFlags = attrs.flags;
10441
10442 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010443 // XXX NOTE: The logic here could be improved. We have
10444 // the decision about whether to resize a window separated
10445 // from whether to hide the surface. This can cause us to
10446 // resize a surface even if we are going to hide it. You
10447 // can see this by (1) holding device in landscape mode on
10448 // home screen; (2) tapping browser icon (device will rotate
10449 // to landscape; (3) tap home. The wallpaper will be resized
10450 // in step 2 but then immediately hidden, causing us to
10451 // have to resize and then redraw it again in step 3. It
10452 // would be nice to figure out how to avoid this, but it is
10453 // difficult because we do need to resize surfaces in some
10454 // cases while they are hidden such as when first showing a
10455 // window.
10456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010458 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 TAG, "Placing surface #" + i + " " + w.mSurface
10460 + ": new=" + w.mShownFrame + ", old="
10461 + w.mLastShownFrame);
10462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 int width, height;
10464 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010465 // for a scaled surface, we just want to use
10466 // the requested size.
10467 width = w.mRequestedWidth;
10468 height = w.mRequestedHeight;
10469 w.mLastRequestedWidth = width;
10470 w.mLastRequestedHeight = height;
10471 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010472 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 width = w.mShownFrame.width();
10474 height = w.mShownFrame.height();
10475 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010476 }
10477
Jeff Brownfbae7222011-01-23 13:07:25 -080010478 if (w.mSurface != null) {
10479 if (w.mSurfaceX != w.mShownFrame.left
10480 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010481 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010482 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010483 "POS " + w.mShownFrame.left
10484 + ", " + w.mShownFrame.top, null);
10485 w.mSurfaceX = w.mShownFrame.left;
10486 w.mSurfaceY = w.mShownFrame.top;
10487 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10488 } catch (RuntimeException e) {
10489 Slog.w(TAG, "Error positioning surface of " + w
10490 + " pos=(" + w.mShownFrame.left
10491 + "," + w.mShownFrame.top + ")", e);
10492 if (!recoveringMemory) {
10493 reclaimSomeSurfaceMemoryLocked(w, "position");
10494 }
10495 }
10496 }
10497
10498 if (width < 1) {
10499 width = 1;
10500 }
10501 if (height < 1) {
10502 height = 1;
10503 }
10504
10505 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10506 try {
10507 if (SHOW_TRANSACTIONS) logSurface(w,
10508 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010509 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010510 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010511 w.mSurfaceW = width;
10512 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010514 } catch (RuntimeException e) {
10515 // If something goes wrong with the surface (such
10516 // as running out of memory), don't take down the
10517 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010518 Slog.e(TAG, "Error resizing surface of " + w
10519 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010520 if (!recoveringMemory) {
10521 reclaimSomeSurfaceMemoryLocked(w, "size");
10522 }
10523 }
10524 }
10525 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010526
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010527 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010528 w.mContentInsetsChanged =
10529 !w.mLastContentInsets.equals(w.mContentInsets);
10530 w.mVisibleInsetsChanged =
10531 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010532 boolean configChanged =
10533 w.mConfiguration != mCurConfiguration
10534 && (w.mConfiguration == null
10535 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010536 if (DEBUG_CONFIGURATION && configChanged) {
10537 Slog.v(TAG, "Win " + w + " config changed: "
10538 + mCurConfiguration);
10539 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010540 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010541 + ": configChanged=" + configChanged
10542 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010543 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10544 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010545 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010546 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010547 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010548 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010549 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10550 Slog.v(TAG, "Resize reasons: "
10551 + "frameChanged=" + frameChanged
10552 + " contentInsetsChanged=" + w.mContentInsetsChanged
10553 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10554 + " surfaceResized=" + w.mSurfaceResized
10555 + " configChanged=" + configChanged);
10556 }
10557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010558 w.mLastFrame.set(w.mFrame);
10559 w.mLastContentInsets.set(w.mContentInsets);
10560 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010561 // If the screen is currently frozen, then keep
10562 // it frozen until this window draws at its new
10563 // orientation.
10564 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010565 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010566 "Resizing while display frozen: " + w);
10567 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010568 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010569 mWindowsFreezingScreen = true;
10570 // XXX should probably keep timeout from
10571 // when we first froze the display.
10572 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10573 mH.sendMessageDelayed(mH.obtainMessage(
10574 H.WINDOW_FREEZE_TIMEOUT), 2000);
10575 }
10576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010577 // If the orientation is changing, then we need to
10578 // hold off on unfreezing the display until this
10579 // window has been redrawn; to do that, we need
10580 // to go through the process of getting informed
10581 // by the application when it has finished drawing.
10582 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010583 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 "Orientation start waiting for draw in "
10585 + w + ", surface " + w.mSurface);
10586 w.mDrawPending = true;
10587 w.mCommitDrawPending = false;
10588 w.mReadyToShow = false;
10589 if (w.mAppToken != null) {
10590 w.mAppToken.allDrawn = false;
10591 }
10592 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010593 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 "Resizing window " + w + " to " + w.mFrame);
10595 mResizingWindows.add(w);
10596 } else if (w.mOrientationChanging) {
10597 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010598 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 "Orientation not waiting for draw in "
10600 + w + ", surface " + w.mSurface);
10601 w.mOrientationChanging = false;
10602 }
10603 }
10604 }
10605
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010606 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010607 if (!w.mLastHidden) {
10608 //dump();
10609 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010610 if (SHOW_TRANSACTIONS) logSurface(w,
10611 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010612 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010613 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010614 try {
10615 w.mSurface.hide();
10616 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010617 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010618 }
10619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 }
10621 // If we are waiting for this window to handle an
10622 // orientation change, well, it is hidden, so
10623 // doesn't really matter. Note that this does
10624 // introduce a potential glitch if the window
10625 // becomes unhidden before it has drawn for the
10626 // new orientation.
10627 if (w.mOrientationChanging) {
10628 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010629 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010630 "Orientation change skips hidden " + w);
10631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 } else if (w.mLastLayer != w.mAnimLayer
10633 || w.mLastAlpha != w.mShownAlpha
10634 || w.mLastDsDx != w.mDsDx
10635 || w.mLastDtDx != w.mDtDx
10636 || w.mLastDsDy != w.mDsDy
10637 || w.mLastDtDy != w.mDtDy
10638 || w.mLastHScale != w.mHScale
10639 || w.mLastVScale != w.mVScale
10640 || w.mLastHidden) {
10641 displayed = true;
10642 w.mLastAlpha = w.mShownAlpha;
10643 w.mLastLayer = w.mAnimLayer;
10644 w.mLastDsDx = w.mDsDx;
10645 w.mLastDtDx = w.mDtDx;
10646 w.mLastDsDy = w.mDsDy;
10647 w.mLastDtDy = w.mDtDy;
10648 w.mLastHScale = w.mHScale;
10649 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010650 if (SHOW_TRANSACTIONS) logSurface(w,
10651 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010652 + " matrix=[" + (w.mDsDx*w.mHScale)
10653 + "," + (w.mDtDx*w.mVScale)
10654 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010655 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010656 if (w.mSurface != null) {
10657 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010658 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010660 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010661 w.mSurface.setLayer(w.mAnimLayer);
10662 w.mSurface.setMatrix(
10663 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10664 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10665 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010666 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010667 if (!recoveringMemory) {
10668 reclaimSomeSurfaceMemoryLocked(w, "update");
10669 }
10670 }
10671 }
10672
10673 if (w.mLastHidden && !w.mDrawPending
10674 && !w.mCommitDrawPending
10675 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010676 if (SHOW_TRANSACTIONS) logSurface(w,
10677 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010678 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010679 + " during relayout");
10680 if (showSurfaceRobustlyLocked(w)) {
10681 w.mHasDrawn = true;
10682 w.mLastHidden = false;
10683 } else {
10684 w.mOrientationChanging = false;
10685 }
10686 }
10687 if (w.mSurface != null) {
10688 w.mToken.hasVisible = true;
10689 }
10690 } else {
10691 displayed = true;
10692 }
10693
10694 if (displayed) {
10695 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010696 if (attrs.width == LayoutParams.MATCH_PARENT
10697 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010698 covered = true;
10699 }
10700 }
10701 if (w.mOrientationChanging) {
10702 if (w.mDrawPending || w.mCommitDrawPending) {
10703 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010704 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010705 "Orientation continue waiting for draw in " + w);
10706 } else {
10707 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010708 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010709 "Orientation change complete in " + w);
10710 }
10711 }
10712 w.mToken.hasVisible = true;
10713 }
10714 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010715 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010716 "Orientation change skips hidden " + w);
10717 w.mOrientationChanging = false;
10718 }
10719
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010720 if (w.mContentChanged) {
10721 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10722 w.mContentChanged = false;
10723 }
10724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010725 final boolean canBeSeen = w.isDisplayedLw();
10726
10727 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10728 focusDisplayed = true;
10729 }
10730
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010731 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010733 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010734 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 if (w.mSurface != null) {
10736 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10737 holdScreen = w.mSession;
10738 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010739 if (!syswin && w.mAttrs.screenBrightness >= 0
10740 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010741 screenBrightness = w.mAttrs.screenBrightness;
10742 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010743 if (!syswin && w.mAttrs.buttonBrightness >= 0
10744 && buttonBrightness < 0) {
10745 buttonBrightness = w.mAttrs.buttonBrightness;
10746 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010747 if (canBeSeen
10748 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10749 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10750 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010751 syswin = true;
10752 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010753 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010754
Dianne Hackborn25994b42009-09-04 14:21:19 -070010755 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10756 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010757 // This window completely covers everything behind it,
10758 // so we want to leave all of them as unblurred (for
10759 // performance reasons).
10760 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010761 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010762 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010763 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010764 obscured = true;
10765 if (mBackgroundFillerSurface == null) {
10766 try {
10767 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010768 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010769 0, dw, dh,
10770 PixelFormat.OPAQUE,
10771 Surface.FX_SURFACE_NORMAL);
10772 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010773 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010774 }
10775 }
10776 try {
10777 mBackgroundFillerSurface.setPosition(0, 0);
10778 mBackgroundFillerSurface.setSize(dw, dh);
10779 // Using the same layer as Dim because they will never be shown at the
10780 // same time.
10781 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10782 mBackgroundFillerSurface.show();
10783 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010784 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010785 }
10786 backgroundFillerShown = true;
10787 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010788 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010789 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010790 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010791 + ": blurring=" + blurring
10792 + " obscured=" + obscured
10793 + " displayed=" + displayed);
10794 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10795 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010796 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010798 if (mDimAnimator == null) {
10799 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010800 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010801 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010802 mDimAnimator.updateParameters(mContext.getResources(),
10803 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010804 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010805 }
10806 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10807 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010808 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010809 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010810 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010811 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010812 + mBlurSurface + ": CREATE");
10813 try {
Romain Guy06882f82009-06-10 13:36:04 -070010814 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010815 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010816 -1, 16, 16,
10817 PixelFormat.OPAQUE,
10818 Surface.FX_SURFACE_BLUR);
10819 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010820 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010821 }
10822 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010823 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010824 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10825 + mBlurSurface + ": pos=(0,0) (" +
10826 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010827 mBlurSurface.setPosition(0, 0);
10828 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010829 mBlurSurface.setLayer(w.mAnimLayer-2);
10830 if (!mBlurShown) {
10831 try {
10832 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10833 + mBlurSurface + ": SHOW");
10834 mBlurSurface.show();
10835 } catch (RuntimeException e) {
10836 Slog.w(TAG, "Failure showing blur surface", e);
10837 }
10838 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010839 }
10840 }
10841 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010842 }
10843 }
10844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010845
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010846 if (obscuredChanged && mWallpaperTarget == w) {
10847 // This is the wallpaper target and its obscured state
10848 // changed... make sure the current wallaper's visibility
10849 // has been updated accordingly.
10850 updateWallpaperVisibilityLocked();
10851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010853
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010854 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10855 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010856 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010857 try {
10858 mBackgroundFillerSurface.hide();
10859 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010860 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010861 }
10862 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010863
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010864 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010865 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10866 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010867 }
Romain Guy06882f82009-06-10 13:36:04 -070010868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010869 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010870 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 + ": HIDE");
10872 try {
10873 mBlurSurface.hide();
10874 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010875 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010876 }
10877 mBlurShown = false;
10878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010879 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010880 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010881 }
10882
10883 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010884
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010885 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10886
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010887 if (mWatermark != null) {
10888 mWatermark.drawIfNeeded();
10889 }
10890
Joe Onorato8a9b2202010-02-26 18:56:32 -080010891 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010892 "With display frozen, orientationChangeComplete="
10893 + orientationChangeComplete);
10894 if (orientationChangeComplete) {
10895 if (mWindowsFreezingScreen) {
10896 mWindowsFreezingScreen = false;
10897 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10898 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010899 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010900 }
Romain Guy06882f82009-06-10 13:36:04 -070010901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010902 i = mResizingWindows.size();
10903 if (i > 0) {
10904 do {
10905 i--;
10906 WindowState win = mResizingWindows.get(i);
10907 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010908 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10909 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010910 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010911 boolean configChanged =
10912 win.mConfiguration != mCurConfiguration
10913 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010914 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10915 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10916 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010917 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010918 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010919 + " / " + mCurConfiguration + " / 0x"
10920 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010921 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010922 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010923 win.mClient.resized(win.mFrame.width(),
10924 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010925 win.mLastVisibleInsets, win.mDrawPending,
10926 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010927 win.mContentInsetsChanged = false;
10928 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010929 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010930 } catch (RemoteException e) {
10931 win.mOrientationChanging = false;
10932 }
10933 } while (i > 0);
10934 mResizingWindows.clear();
10935 }
Romain Guy06882f82009-06-10 13:36:04 -070010936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010937 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010938 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 i = mDestroySurface.size();
10940 if (i > 0) {
10941 do {
10942 i--;
10943 WindowState win = mDestroySurface.get(i);
10944 win.mDestroying = false;
10945 if (mInputMethodWindow == win) {
10946 mInputMethodWindow = null;
10947 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010948 if (win == mWallpaperTarget) {
10949 wallpaperDestroyed = true;
10950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010951 win.destroySurfaceLocked();
10952 } while (i > 0);
10953 mDestroySurface.clear();
10954 }
10955
10956 // Time to remove any exiting tokens?
10957 for (i=mExitingTokens.size()-1; i>=0; i--) {
10958 WindowToken token = mExitingTokens.get(i);
10959 if (!token.hasVisible) {
10960 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010961 if (token.windowType == TYPE_WALLPAPER) {
10962 mWallpaperTokens.remove(token);
10963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010964 }
10965 }
10966
10967 // Time to remove any exiting applications?
10968 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10969 AppWindowToken token = mExitingAppTokens.get(i);
10970 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010971 // Make sure there is no animation running on this token,
10972 // so any windows associated with it will be removed as
10973 // soon as their animations are complete
10974 token.animation = null;
10975 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010976 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10977 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010978 mAppTokens.remove(token);
10979 mExitingAppTokens.remove(i);
10980 }
10981 }
10982
Dianne Hackborna8f60182009-09-01 19:01:50 -070010983 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010984
Dianne Hackborna8f60182009-09-01 19:01:50 -070010985 if (!animating && mAppTransitionRunning) {
10986 // We have finished the animation of an app transition. To do
10987 // this, we have delayed a lot of operations like showing and
10988 // hiding apps, moving apps in Z-order, etc. The app token list
10989 // reflects the correct Z-order, but the window list may now
10990 // be out of sync with it. So here we will just rebuild the
10991 // entire app window list. Fun!
10992 mAppTransitionRunning = false;
10993 needRelayout = true;
10994 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010995 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010996 // Clear information about apps that were moving.
10997 mToBottomApps.clear();
10998 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011000 if (focusDisplayed) {
11001 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
11002 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011003 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011004 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011005 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011006 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011007 requestAnimationLocked(0);
11008 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011009 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
11010 }
Jeff Browneb857f12010-07-16 10:06:33 -070011011
Jeff Brown3a22cd92011-01-21 13:59:04 -080011012 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080011013 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070011014
Jeff Brown8e03b752010-06-13 19:16:55 -070011015 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080011016 if (!mDisplayFrozen) {
11017 if (screenBrightness < 0 || screenBrightness > 1.0f) {
11018 mPowerManager.setScreenBrightnessOverride(-1);
11019 } else {
11020 mPowerManager.setScreenBrightnessOverride((int)
11021 (screenBrightness * Power.BRIGHTNESS_ON));
11022 }
11023 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
11024 mPowerManager.setButtonBrightnessOverride(-1);
11025 } else {
11026 mPowerManager.setButtonBrightnessOverride((int)
11027 (buttonBrightness * Power.BRIGHTNESS_ON));
11028 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050011029 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011030 if (holdScreen != mHoldingScreenOn) {
11031 mHoldingScreenOn = holdScreen;
11032 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
11033 mH.sendMessage(m);
11034 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011035
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011036 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011037 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011038 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
11039 LocalPowerManager.BUTTON_EVENT, true);
11040 mTurnOnScreen = false;
11041 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011042
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011043 if (updateRotation) {
11044 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11045 boolean changed = setRotationUncheckedLocked(
11046 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11047 if (changed) {
11048 sendNewConfiguration();
11049 }
11050 }
11051
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011052 // Check to see if we are now in a state where the screen should
11053 // be enabled, because the window obscured flags have changed.
11054 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011055 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070011056
11057 /**
11058 * Must be called with the main window manager lock held.
11059 */
11060 void setHoldScreenLocked(boolean holding) {
11061 boolean state = mHoldingScreenWakeLock.isHeld();
11062 if (holding != state) {
11063 if (holding) {
11064 mHoldingScreenWakeLock.acquire();
11065 } else {
11066 mPolicy.screenOnStoppedLw();
11067 mHoldingScreenWakeLock.release();
11068 }
11069 }
11070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011071
11072 void requestAnimationLocked(long delay) {
11073 if (!mAnimationPending) {
11074 mAnimationPending = true;
11075 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
11076 }
11077 }
Romain Guy06882f82009-06-10 13:36:04 -070011078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011079 /**
11080 * Have the surface flinger show a surface, robustly dealing with
11081 * error conditions. In particular, if there is not enough memory
11082 * to show the surface, then we will try to get rid of other surfaces
11083 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011084 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011085 * @return Returns true if the surface was successfully shown.
11086 */
11087 boolean showSurfaceRobustlyLocked(WindowState win) {
11088 try {
11089 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011090 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011091 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011092 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011093 if (DEBUG_VISIBILITY) Slog.v(TAG,
11094 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011095 win.mTurnOnScreen = false;
11096 mTurnOnScreen = true;
11097 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011098 }
11099 return true;
11100 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011101 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011102 }
Romain Guy06882f82009-06-10 13:36:04 -070011103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011104 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011106 return false;
11107 }
Romain Guy06882f82009-06-10 13:36:04 -070011108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011109 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11110 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011111
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011112 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011113 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 if (mForceRemoves == null) {
11116 mForceRemoves = new ArrayList<WindowState>();
11117 }
Romain Guy06882f82009-06-10 13:36:04 -070011118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011119 long callingIdentity = Binder.clearCallingIdentity();
11120 try {
11121 // There was some problem... first, do a sanity check of the
11122 // window list to make sure we haven't left any dangling surfaces
11123 // around.
11124 int N = mWindows.size();
11125 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011126 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011127 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011128 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011129 if (ws.mSurface != null) {
11130 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011131 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011132 + ws + " surface=" + ws.mSurface
11133 + " token=" + win.mToken
11134 + " pid=" + ws.mSession.mPid
11135 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011136 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011137 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011138 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011139 ws.mSurface = null;
11140 mForceRemoves.add(ws);
11141 i--;
11142 N--;
11143 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011144 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011145 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011146 + ws + " surface=" + ws.mSurface
11147 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011148 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011149 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011150 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011151 ws.mSurface = null;
11152 leakedSurface = true;
11153 }
11154 }
11155 }
Romain Guy06882f82009-06-10 13:36:04 -070011156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011157 boolean killedApps = false;
11158 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011159 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011160 SparseIntArray pidCandidates = new SparseIntArray();
11161 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011162 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011163 if (ws.mSurface != null) {
11164 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11165 }
11166 }
11167 if (pidCandidates.size() > 0) {
11168 int[] pids = new int[pidCandidates.size()];
11169 for (int i=0; i<pids.length; i++) {
11170 pids[i] = pidCandidates.keyAt(i);
11171 }
11172 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011173 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011174 killedApps = true;
11175 }
11176 } catch (RemoteException e) {
11177 }
11178 }
11179 }
Romain Guy06882f82009-06-10 13:36:04 -070011180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011181 if (leakedSurface || killedApps) {
11182 // We managed to reclaim some memory, so get rid of the trouble
11183 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011184 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011185 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011186 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011187 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011188 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011189 win.mSurface = null;
11190 }
Romain Guy06882f82009-06-10 13:36:04 -070011191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011192 try {
11193 win.mClient.dispatchGetNewSurface();
11194 } catch (RemoteException e) {
11195 }
11196 }
11197 } finally {
11198 Binder.restoreCallingIdentity(callingIdentity);
11199 }
11200 }
Romain Guy06882f82009-06-10 13:36:04 -070011201
Jeff Brown3a22cd92011-01-21 13:59:04 -080011202 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011203 WindowState newFocus = computeFocusedWindowLocked();
11204 if (mCurrentFocus != newFocus) {
11205 // This check makes sure that we don't already have the focus
11206 // change message pending.
11207 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11208 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011209 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011210 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11211 final WindowState oldFocus = mCurrentFocus;
11212 mCurrentFocus = newFocus;
11213 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011215 final WindowState imWindow = mInputMethodWindow;
11216 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011217 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011218 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011219 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11220 mLayoutNeeded = true;
11221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011222 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011223 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011224 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11225 // Client will do the layout, but we need to assign layers
11226 // for handleNewWindowLocked() below.
11227 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011228 }
11229 }
Jeff Brown349703e2010-06-22 01:27:15 -070011230
11231 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11232 // If we defer assigning layers, then the caller is responsible for
11233 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011234 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011236 return true;
11237 }
11238 return false;
11239 }
Jeff Brown349703e2010-06-22 01:27:15 -070011240
Jeff Brown3a22cd92011-01-21 13:59:04 -080011241 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11242 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011244
11245 private WindowState computeFocusedWindowLocked() {
11246 WindowState result = null;
11247 WindowState win;
11248
11249 int i = mWindows.size() - 1;
11250 int nextAppIndex = mAppTokens.size()-1;
11251 WindowToken nextApp = nextAppIndex >= 0
11252 ? mAppTokens.get(nextAppIndex) : null;
11253
11254 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011255 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011256
Joe Onorato8a9b2202010-02-26 18:56:32 -080011257 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011258 TAG, "Looking for focus: " + i
11259 + " = " + win
11260 + ", flags=" + win.mAttrs.flags
11261 + ", canReceive=" + win.canReceiveKeys());
11262
11263 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011265 // If this window's application has been removed, just skip it.
11266 if (thisApp != null && thisApp.removed) {
11267 i--;
11268 continue;
11269 }
Romain Guy06882f82009-06-10 13:36:04 -070011270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011271 // If there is a focused app, don't allow focus to go to any
11272 // windows below it. If this is an application window, step
11273 // through the app tokens until we find its app.
11274 if (thisApp != null && nextApp != null && thisApp != nextApp
11275 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11276 int origAppIndex = nextAppIndex;
11277 while (nextAppIndex > 0) {
11278 if (nextApp == mFocusedApp) {
11279 // Whoops, we are below the focused app... no focus
11280 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011281 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011282 TAG, "Reached focused app: " + mFocusedApp);
11283 return null;
11284 }
11285 nextAppIndex--;
11286 nextApp = mAppTokens.get(nextAppIndex);
11287 if (nextApp == thisApp) {
11288 break;
11289 }
11290 }
11291 if (thisApp != nextApp) {
11292 // Uh oh, the app token doesn't exist! This shouldn't
11293 // happen, but if it does we can get totally hosed...
11294 // so restart at the original app.
11295 nextAppIndex = origAppIndex;
11296 nextApp = mAppTokens.get(nextAppIndex);
11297 }
11298 }
11299
11300 // Dispatch to this window if it is wants key events.
11301 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011302 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011303 TAG, "Found focus @ " + i + " = " + win);
11304 result = win;
11305 break;
11306 }
11307
11308 i--;
11309 }
11310
11311 return result;
11312 }
11313
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011314 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011315 if (mDisplayFrozen) {
11316 return;
11317 }
Romain Guy06882f82009-06-10 13:36:04 -070011318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011319 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011321 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011322 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011323 if (mFreezeGcPending != 0) {
11324 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011325 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011326 mH.removeMessages(H.FORCE_GC);
11327 Runtime.getRuntime().gc();
11328 mFreezeGcPending = now;
11329 }
11330 } else {
11331 mFreezeGcPending = now;
11332 }
Romain Guy06882f82009-06-10 13:36:04 -070011333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011334 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011335
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011336 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011337
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011338 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11339 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011340 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011341 mAppTransitionReady = true;
11342 }
Romain Guy06882f82009-06-10 13:36:04 -070011343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011344 if (PROFILE_ORIENTATION) {
11345 File file = new File("/data/system/frozen");
11346 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11347 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011348
11349 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011350 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11351 mScreenRotationAnimation.kill();
11352 mScreenRotationAnimation = null;
11353 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011354 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011355 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011356 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011357 }
11358 } else {
11359 Surface.freezeDisplay(0);
11360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011361 }
Romain Guy06882f82009-06-10 13:36:04 -070011362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011363 private void stopFreezingDisplayLocked() {
11364 if (!mDisplayFrozen) {
11365 return;
11366 }
Romain Guy06882f82009-06-10 13:36:04 -070011367
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011368 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11369 return;
11370 }
11371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011372 mDisplayFrozen = false;
11373 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11374 if (PROFILE_ORIENTATION) {
11375 Debug.stopMethodTracing();
11376 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011377
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011378 boolean updateRotation = false;
11379
Dianne Hackborna1111872010-11-23 20:55:11 -080011380 if (CUSTOM_SCREEN_ROTATION) {
11381 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011382 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11383 mTransitionAnimationScale)) {
11384 requestAnimationLocked(0);
11385 } else {
11386 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011387 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011388 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011389 }
11390 } else {
11391 Surface.unfreezeDisplay(0);
11392 }
Romain Guy06882f82009-06-10 13:36:04 -070011393
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011394 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011395
Dianne Hackborn420829e2011-01-28 11:30:35 -080011396 boolean configChanged;
11397
Christopher Tateb696aee2010-04-02 19:08:30 -070011398 // While the display is frozen we don't re-compute the orientation
11399 // to avoid inconsistent states. However, something interesting
11400 // could have actually changed during that time so re-evaluate it
11401 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -080011402 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -070011403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011404 // A little kludge: a lot could have happened while the
11405 // display was frozen, so now that we are coming back we
11406 // do a gc so that any remote references the system
11407 // processes holds on others can be released if they are
11408 // no longer needed.
11409 mH.removeMessages(H.FORCE_GC);
11410 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11411 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011413 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011414
11415 if (updateRotation) {
11416 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -080011417 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011418 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -080011419 }
11420
11421 if (configChanged) {
11422 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011423 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011424 }
Romain Guy06882f82009-06-10 13:36:04 -070011425
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011426 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11427 DisplayMetrics dm) {
11428 if (index < tokens.length) {
11429 String str = tokens[index];
11430 if (str != null && str.length() > 0) {
11431 try {
11432 int val = Integer.parseInt(str);
11433 return val;
11434 } catch (Exception e) {
11435 }
11436 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011437 }
11438 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11439 return defDps;
11440 }
11441 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11442 return val;
11443 }
11444
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011445 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011446 final String[] mTokens;
11447 final String mText;
11448 final Paint mTextPaint;
11449 final int mTextWidth;
11450 final int mTextHeight;
11451 final int mTextAscent;
11452 final int mTextDescent;
11453 final int mDeltaX;
11454 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011455
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011456 Surface mSurface;
11457 int mLastDW;
11458 int mLastDH;
11459 boolean mDrawNeeded;
11460
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011461 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011462 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011463 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011464
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011465 if (false) {
11466 Log.i(TAG, "*********************** WATERMARK");
11467 for (int i=0; i<tokens.length; i++) {
11468 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11469 }
11470 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011471
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011472 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011473
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011474 StringBuilder builder = new StringBuilder(32);
11475 int len = mTokens[0].length();
11476 len = len & ~1;
11477 for (int i=0; i<len; i+=2) {
11478 int c1 = mTokens[0].charAt(i);
11479 int c2 = mTokens[0].charAt(i+1);
11480 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11481 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11482 else c1 -= '0';
11483 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11484 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11485 else c2 -= '0';
11486 builder.append((char)(255-((c1*16)+c2)));
11487 }
11488 mText = builder.toString();
11489 if (false) {
11490 Log.i(TAG, "Final text: " + mText);
11491 }
11492
11493 int fontSize = getPropertyInt(tokens, 1,
11494 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11495
11496 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11497 mTextPaint.setTextSize(fontSize);
11498 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11499
11500 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11501 mTextWidth = (int)mTextPaint.measureText(mText);
11502 mTextAscent = fm.ascent;
11503 mTextDescent = fm.descent;
11504 mTextHeight = fm.descent - fm.ascent;
11505
11506 mDeltaX = getPropertyInt(tokens, 2,
11507 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11508 mDeltaY = getPropertyInt(tokens, 3,
11509 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11510 int shadowColor = getPropertyInt(tokens, 4,
11511 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11512 int color = getPropertyInt(tokens, 5,
11513 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11514 int shadowRadius = getPropertyInt(tokens, 6,
11515 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11516 int shadowDx = getPropertyInt(tokens, 8,
11517 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11518 int shadowDy = getPropertyInt(tokens, 9,
11519 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11520
11521 mTextPaint.setColor(color);
11522 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011523
11524 try {
11525 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011526 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011527 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011528 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011529 mSurface.show();
11530 } catch (OutOfResourcesException e) {
11531 }
11532 }
11533
11534 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011535 if (mLastDW != dw || mLastDH != dh) {
11536 mLastDW = dw;
11537 mLastDH = dh;
11538 mSurface.setSize(dw, dh);
11539 mDrawNeeded = true;
11540 }
11541 }
11542
11543 void drawIfNeeded() {
11544 if (mDrawNeeded) {
11545 final int dw = mLastDW;
11546 final int dh = mLastDH;
11547
11548 mDrawNeeded = false;
11549 Rect dirty = new Rect(0, 0, dw, dh);
11550 Canvas c = null;
11551 try {
11552 c = mSurface.lockCanvas(dirty);
11553 } catch (IllegalArgumentException e) {
11554 } catch (OutOfResourcesException e) {
11555 }
11556 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011557 c.drawColor(0, PorterDuff.Mode.CLEAR);
11558
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011559 int deltaX = mDeltaX;
11560 int deltaY = mDeltaY;
11561
11562 // deltaX shouldn't be close to a round fraction of our
11563 // x step, or else things will line up too much.
11564 int div = (dw+mTextWidth)/deltaX;
11565 int rem = (dw+mTextWidth) - (div*deltaX);
11566 int qdelta = deltaX/4;
11567 if (rem < qdelta || rem > (deltaX-qdelta)) {
11568 deltaX += deltaX/3;
11569 }
11570
11571 int y = -mTextHeight;
11572 int x = -mTextWidth;
11573 while (y < (dh+mTextHeight)) {
11574 c.drawText(mText, x, y, mTextPaint);
11575 x += deltaX;
11576 if (x >= dw) {
11577 x -= (dw+mTextWidth);
11578 y += deltaY;
11579 }
11580 }
11581 mSurface.unlockCanvasAndPost(c);
11582 }
11583 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011584 }
11585 }
11586
11587 void createWatermark() {
11588 if (mWatermark != null) {
11589 return;
11590 }
11591
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011592 File file = new File("/system/etc/setup.conf");
11593 FileInputStream in = null;
11594 try {
11595 in = new FileInputStream(file);
11596 DataInputStream ind = new DataInputStream(in);
11597 String line = ind.readLine();
11598 if (line != null) {
11599 String[] toks = line.split("%");
11600 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011601 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011602 }
11603 }
11604 } catch (FileNotFoundException e) {
11605 } catch (IOException e) {
11606 } finally {
11607 if (in != null) {
11608 try {
11609 in.close();
11610 } catch (IOException e) {
11611 }
11612 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011613 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011614 }
11615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011616 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011617 public void statusBarVisibilityChanged(int visibility) {
11618 synchronized (mWindowMap) {
11619 final int N = mWindows.size();
11620 for (int i = 0; i < N; i++) {
11621 WindowState ws = mWindows.get(i);
11622 try {
11623 if (ws.getAttrs().hasSystemUiListeners) {
11624 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11625 }
11626 } catch (RemoteException e) {
11627 // so sorry
11628 }
11629 }
11630 }
11631 }
11632
11633 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011634 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11635 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11636 != PackageManager.PERMISSION_GRANTED) {
11637 pw.println("Permission Denial: can't dump WindowManager from from pid="
11638 + Binder.getCallingPid()
11639 + ", uid=" + Binder.getCallingUid());
11640 return;
11641 }
Romain Guy06882f82009-06-10 13:36:04 -070011642
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011643 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011644 pw.println(" ");
11645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011646 synchronized(mWindowMap) {
11647 pw.println("Current Window Manager state:");
11648 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011649 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011650 pw.print(" Window #"); pw.print(i); pw.print(' ');
11651 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011652 w.dump(pw, " ");
11653 }
11654 if (mInputMethodDialogs.size() > 0) {
11655 pw.println(" ");
11656 pw.println(" Input method dialogs:");
11657 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11658 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011659 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011660 }
11661 }
11662 if (mPendingRemove.size() > 0) {
11663 pw.println(" ");
11664 pw.println(" Remove pending for:");
11665 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11666 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011667 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11668 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011669 w.dump(pw, " ");
11670 }
11671 }
11672 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11673 pw.println(" ");
11674 pw.println(" Windows force removing:");
11675 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11676 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011677 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11678 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011679 w.dump(pw, " ");
11680 }
11681 }
11682 if (mDestroySurface.size() > 0) {
11683 pw.println(" ");
11684 pw.println(" Windows waiting to destroy their surface:");
11685 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11686 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011687 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11688 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011689 w.dump(pw, " ");
11690 }
11691 }
11692 if (mLosingFocus.size() > 0) {
11693 pw.println(" ");
11694 pw.println(" Windows losing focus:");
11695 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11696 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011697 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11698 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011699 w.dump(pw, " ");
11700 }
11701 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011702 if (mResizingWindows.size() > 0) {
11703 pw.println(" ");
11704 pw.println(" Windows waiting to resize:");
11705 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11706 WindowState w = mResizingWindows.get(i);
11707 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11708 pw.print(w); pw.println(":");
11709 w.dump(pw, " ");
11710 }
11711 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011712 if (mSessions.size() > 0) {
11713 pw.println(" ");
11714 pw.println(" All active sessions:");
11715 Iterator<Session> it = mSessions.iterator();
11716 while (it.hasNext()) {
11717 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011718 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011719 s.dump(pw, " ");
11720 }
11721 }
11722 if (mTokenMap.size() > 0) {
11723 pw.println(" ");
11724 pw.println(" All tokens:");
11725 Iterator<WindowToken> it = mTokenMap.values().iterator();
11726 while (it.hasNext()) {
11727 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011728 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011729 token.dump(pw, " ");
11730 }
11731 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011732 if (mWallpaperTokens.size() > 0) {
11733 pw.println(" ");
11734 pw.println(" Wallpaper tokens:");
11735 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11736 WindowToken token = mWallpaperTokens.get(i);
11737 pw.print(" Wallpaper #"); pw.print(i);
11738 pw.print(' '); pw.print(token); pw.println(':');
11739 token.dump(pw, " ");
11740 }
11741 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011742 if (mAppTokens.size() > 0) {
11743 pw.println(" ");
11744 pw.println(" Application tokens in Z order:");
11745 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011746 pw.print(" App #"); pw.print(i); pw.print(": ");
11747 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011748 }
11749 }
11750 if (mFinishedStarting.size() > 0) {
11751 pw.println(" ");
11752 pw.println(" Finishing start of application tokens:");
11753 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11754 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011755 pw.print(" Finished Starting #"); pw.print(i);
11756 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011757 token.dump(pw, " ");
11758 }
11759 }
11760 if (mExitingTokens.size() > 0) {
11761 pw.println(" ");
11762 pw.println(" Exiting tokens:");
11763 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11764 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011765 pw.print(" Exiting #"); pw.print(i);
11766 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011767 token.dump(pw, " ");
11768 }
11769 }
11770 if (mExitingAppTokens.size() > 0) {
11771 pw.println(" ");
11772 pw.println(" Exiting application tokens:");
11773 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11774 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011775 pw.print(" Exiting App #"); pw.print(i);
11776 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011777 token.dump(pw, " ");
11778 }
11779 }
11780 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011781 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11782 pw.print(" mLastFocus="); pw.println(mLastFocus);
11783 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11784 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11785 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011786 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011787 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11788 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11789 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11790 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011791 if (mWindowDetachedWallpaper != null) {
11792 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11793 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011794 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11795 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11796 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011797 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11798 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11799 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11800 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011801 if (mDimAnimator != null) {
11802 mDimAnimator.printTo(pw);
11803 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011804 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011805 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011806 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011807 pw.print(mInputMethodAnimLayerAdjustment);
11808 pw.print(" mWallpaperAnimLayerAdjustment=");
11809 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011810 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11811 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011812 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11813 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011814 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11815 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011816 pw.print(" mRotation="); pw.print(mRotation);
11817 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11818 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011819 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11820 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011821 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11822 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11823 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11824 pw.print(" mNextAppTransition=0x");
11825 pw.print(Integer.toHexString(mNextAppTransition));
11826 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011827 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011828 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011829 if (mNextAppTransitionPackage != null) {
11830 pw.print(" mNextAppTransitionPackage=");
11831 pw.print(mNextAppTransitionPackage);
11832 pw.print(", mNextAppTransitionEnter=0x");
11833 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11834 pw.print(", mNextAppTransitionExit=0x");
11835 pw.print(Integer.toHexString(mNextAppTransitionExit));
11836 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011837 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11838 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11839 if (mOpeningApps.size() > 0) {
11840 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11841 }
11842 if (mClosingApps.size() > 0) {
11843 pw.print(" mClosingApps="); pw.println(mClosingApps);
11844 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011845 if (mToTopApps.size() > 0) {
11846 pw.print(" mToTopApps="); pw.println(mToTopApps);
11847 }
11848 if (mToBottomApps.size() > 0) {
11849 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11850 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011851 if (mDisplay != null) {
11852 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11853 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11854 } else {
11855 pw.println(" NO DISPLAY");
11856 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011857 pw.println(" Policy:");
11858 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011859 }
11860 }
11861
Jeff Brown349703e2010-06-22 01:27:15 -070011862 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011863 public void monitor() {
11864 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011865 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011867
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011868 /**
11869 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011870 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011871 */
11872 private static class DimAnimator {
11873 Surface mDimSurface;
11874 boolean mDimShown = false;
11875 float mDimCurrentAlpha;
11876 float mDimTargetAlpha;
11877 float mDimDeltaPerMs;
11878 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011879
11880 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011881
11882 DimAnimator (SurfaceSession session) {
11883 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011884 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011885 + mDimSurface + ": CREATE");
11886 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011887 mDimSurface = new Surface(session, 0,
11888 "DimSurface",
11889 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011890 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011891 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011892 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011893 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011894 }
11895 }
11896 }
11897
11898 /**
11899 * Show the dim surface.
11900 */
11901 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011902 if (!mDimShown) {
11903 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11904 dw + "x" + dh + ")");
11905 mDimShown = true;
11906 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011907 mLastDimWidth = dw;
11908 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011909 mDimSurface.setPosition(0, 0);
11910 mDimSurface.setSize(dw, dh);
11911 mDimSurface.show();
11912 } catch (RuntimeException e) {
11913 Slog.w(TAG, "Failure showing dim surface", e);
11914 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011915 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11916 mLastDimWidth = dw;
11917 mLastDimHeight = dh;
11918 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011919 }
11920 }
11921
11922 /**
11923 * Set's the dim surface's layer and update dim parameters that will be used in
11924 * {@link updateSurface} after all windows are examined.
11925 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011926 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011927 mDimSurface.setLayer(w.mAnimLayer-1);
11928
11929 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011930 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011931 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011932 if (mDimTargetAlpha != target) {
11933 // If the desired dim level has changed, then
11934 // start an animation to it.
11935 mLastDimAnimTime = currentTime;
11936 long duration = (w.mAnimating && w.mAnimation != null)
11937 ? w.mAnimation.computeDurationHint()
11938 : DEFAULT_DIM_DURATION;
11939 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011940 TypedValue tv = new TypedValue();
11941 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11942 tv, true);
11943 if (tv.type == TypedValue.TYPE_FRACTION) {
11944 duration = (long)tv.getFraction((float)duration, (float)duration);
11945 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11946 && tv.type <= TypedValue.TYPE_LAST_INT) {
11947 duration = tv.data;
11948 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011949 }
11950 if (duration < 1) {
11951 // Don't divide by zero
11952 duration = 1;
11953 }
11954 mDimTargetAlpha = target;
11955 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11956 }
11957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011958
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011959 /**
11960 * Updating the surface's alpha. Returns true if the animation continues, or returns
11961 * false when the animation is finished and the dim surface is hidden.
11962 */
11963 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11964 if (!dimming) {
11965 if (mDimTargetAlpha != 0) {
11966 mLastDimAnimTime = currentTime;
11967 mDimTargetAlpha = 0;
11968 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11969 }
11970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011971
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011972 boolean animating = false;
11973 if (mLastDimAnimTime != 0) {
11974 mDimCurrentAlpha += mDimDeltaPerMs
11975 * (currentTime-mLastDimAnimTime);
11976 boolean more = true;
11977 if (displayFrozen) {
11978 // If the display is frozen, there is no reason to animate.
11979 more = false;
11980 } else if (mDimDeltaPerMs > 0) {
11981 if (mDimCurrentAlpha > mDimTargetAlpha) {
11982 more = false;
11983 }
11984 } else if (mDimDeltaPerMs < 0) {
11985 if (mDimCurrentAlpha < mDimTargetAlpha) {
11986 more = false;
11987 }
11988 } else {
11989 more = false;
11990 }
11991
11992 // Do we need to continue animating?
11993 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011994 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011995 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11996 mLastDimAnimTime = currentTime;
11997 mDimSurface.setAlpha(mDimCurrentAlpha);
11998 animating = true;
11999 } else {
12000 mDimCurrentAlpha = mDimTargetAlpha;
12001 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080012002 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012003 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
12004 mDimSurface.setAlpha(mDimCurrentAlpha);
12005 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012006 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012007 + ": HIDE");
12008 try {
12009 mDimSurface.hide();
12010 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012011 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012012 }
12013 mDimShown = false;
12014 }
12015 }
12016 }
12017 return animating;
12018 }
12019
12020 public void printTo(PrintWriter pw) {
12021 pw.print(" mDimShown="); pw.print(mDimShown);
12022 pw.print(" current="); pw.print(mDimCurrentAlpha);
12023 pw.print(" target="); pw.print(mDimTargetAlpha);
12024 pw.print(" delta="); pw.print(mDimDeltaPerMs);
12025 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
12026 }
12027 }
12028
12029 /**
12030 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
12031 * This is used for opening/closing transition for apps in compatible mode.
12032 */
12033 private static class FadeInOutAnimation extends Animation {
12034 int mWidth;
12035 boolean mFadeIn;
12036
12037 public FadeInOutAnimation(boolean fadeIn) {
12038 setInterpolator(new AccelerateInterpolator());
12039 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
12040 mFadeIn = fadeIn;
12041 }
12042
12043 @Override
12044 protected void applyTransformation(float interpolatedTime, Transformation t) {
12045 float x = interpolatedTime;
12046 if (!mFadeIn) {
12047 x = 1.0f - x; // reverse the interpolation for fade out
12048 }
12049 if (x < 0.5) {
12050 // move the window out of the screen.
12051 t.getMatrix().setTranslate(mWidth, 0);
12052 } else {
12053 t.getMatrix().setTranslate(0, 0);// show
12054 t.setAlpha((x - 0.5f) * 2);
12055 }
12056 }
12057
12058 @Override
12059 public void initialize(int width, int height, int parentWidth, int parentHeight) {
12060 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
12061 mWidth = width;
12062 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012063
12064 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070012065 public int getZAdjustment() {
12066 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012067 }
12068 }
Jeff Brown2992ea72011-01-28 22:04:14 -080012069
12070 public interface OnHardKeyboardStatusChangeListener {
12071 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
12072 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012073}