blob: 2806774d4e781705bc4eeec6f2c77c807c0783c1 [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
Dianne Hackbornc485a602009-03-24 22:39:49 -07005790 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5791 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5792 mPolicy.adjustConfigurationLw(config);
Jeff Brown2992ea72011-01-28 22:04:14 -08005793
5794 // Adjust the hard keyboard configuration based on whether the hard keyboard is enabled.
5795 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
5796 if (hardKeyboardAvailable != mHardKeyboardAvailable) {
5797 mHardKeyboardAvailable = hardKeyboardAvailable;
5798 mHardKeyboardEnabled = hardKeyboardAvailable;
5799
5800 mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5801 mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
5802 }
5803 if (!mHardKeyboardEnabled) {
5804 config.keyboard = Configuration.KEYBOARD_NOKEYS;
5805 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5806 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005807 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005808 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005809
Jeff Brown2992ea72011-01-28 22:04:14 -08005810 public boolean isHardKeyboardAvailable() {
5811 synchronized (mWindowMap) {
5812 return mHardKeyboardAvailable;
5813 }
5814 }
5815
5816 public boolean isHardKeyboardEnabled() {
5817 synchronized (mWindowMap) {
5818 return mHardKeyboardEnabled;
5819 }
5820 }
5821
5822 public void setHardKeyboardEnabled(boolean enabled) {
5823 synchronized (mWindowMap) {
5824 if (mHardKeyboardEnabled != enabled) {
5825 mHardKeyboardEnabled = enabled;
5826 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
5827 }
5828 }
5829 }
5830
5831 public void setOnHardKeyboardStatusChangeListener(
5832 OnHardKeyboardStatusChangeListener listener) {
5833 synchronized (mWindowMap) {
5834 mHardKeyboardStatusChangeListener = listener;
5835 }
5836 }
5837
5838 void notifyHardKeyboardStatusChange() {
5839 final boolean available, enabled;
5840 final OnHardKeyboardStatusChangeListener listener;
5841 synchronized (mWindowMap) {
5842 listener = mHardKeyboardStatusChangeListener;
5843 available = mHardKeyboardAvailable;
5844 enabled = mHardKeyboardEnabled;
5845 }
5846 if (listener != null) {
5847 listener.onHardKeyboardStatusChange(available, enabled);
5848 }
5849 }
5850
Christopher Tatea53146c2010-09-07 11:57:52 -07005851 // -------------------------------------------------------------
5852 // Drag and drop
5853 // -------------------------------------------------------------
5854
5855 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005856 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005857 if (DEBUG_DRAG) {
5858 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005859 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005860 + " asbinder=" + window.asBinder());
5861 }
5862
5863 final int callerPid = Binder.getCallingPid();
5864 final long origId = Binder.clearCallingIdentity();
5865 IBinder token = null;
5866
5867 try {
5868 synchronized (mWindowMap) {
5869 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005870 if (mDragState == null) {
5871 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5872 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5873 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005874 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005875 token = new Binder();
Christopher Tate251602f2011-01-28 17:54:12 -08005876 mDragState = new DragState(token, surface, flags, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005877 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005878 token = mDragState.mToken = new Binder();
5879
5880 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005881 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5882 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005883 mH.sendMessageDelayed(msg, 5000);
5884 } else {
5885 Slog.w(TAG, "Drag already in progress");
5886 }
5887 } catch (Surface.OutOfResourcesException e) {
5888 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5889 if (mDragState != null) {
5890 mDragState.reset();
5891 mDragState = null;
5892 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005893 }
5894 }
5895 } finally {
5896 Binder.restoreCallingIdentity(origId);
5897 }
5898
5899 return token;
5900 }
5901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 // -------------------------------------------------------------
5903 // Input Events and Focus Management
5904 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005905
Jeff Brown349703e2010-06-22 01:27:15 -07005906 InputMonitor mInputMonitor = new InputMonitor();
5907
5908 /* Tracks the progress of input dispatch and ensures that input dispatch state
5909 * is kept in sync with changes in window focus, visibility, registration, and
5910 * other relevant Window Manager state transitions. */
5911 final class InputMonitor {
5912 // Current window with input focus for keys and other non-touch events. May be null.
5913 private WindowState mInputFocus;
5914
5915 // When true, prevents input dispatch from proceeding until set to false again.
5916 private boolean mInputDispatchFrozen;
5917
5918 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5919 private boolean mInputDispatchEnabled = true;
5920
Jeff Brown3a22cd92011-01-21 13:59:04 -08005921 // When true, need to call updateInputWindowsLw().
5922 private boolean mUpdateInputWindowsNeeded = true;
5923
Jeff Brown349703e2010-06-22 01:27:15 -07005924 // Temporary list of windows information to provide to the input dispatcher.
5925 private InputWindowList mTempInputWindows = new InputWindowList();
5926
5927 // Temporary input application object to provide to the input dispatcher.
5928 private InputApplication mTempInputApplication = new InputApplication();
5929
Jeff Brownb09abc12011-01-13 21:08:27 -08005930 // Set to true when the first input device configuration change notification
5931 // is received to indicate that the input devices are ready.
5932 private final Object mInputDevicesReadyMonitor = new Object();
5933 private boolean mInputDevicesReady;
5934
Jeff Brown349703e2010-06-22 01:27:15 -07005935 /* Notifies the window manager about a broken input channel.
5936 *
5937 * Called by the InputManager.
5938 */
Jeff Brown928e0542011-01-10 11:17:36 -08005939 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5940 if (inputWindowHandle == null) {
5941 return;
5942 }
5943
Jeff Brown349703e2010-06-22 01:27:15 -07005944 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005945 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005946 Slog.i(TAG, "WINDOW DIED " + windowState);
5947 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005948 }
5949 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005950
Jeff Brown519e0242010-09-15 15:18:56 -07005951 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005952 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005953 *
5954 * Called by the InputManager.
5955 */
Jeff Brown928e0542011-01-10 11:17:36 -08005956 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5957 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005958 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005959 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005960 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005961 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005962 if (windowState != null) {
5963 Slog.i(TAG, "Input event dispatching timed out sending to "
5964 + windowState.mAttrs.getTitle());
5965 appWindowToken = windowState.mAppToken;
5966 }
Jeff Brown349703e2010-06-22 01:27:15 -07005967 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005968 }
5969
Jeff Brown928e0542011-01-10 11:17:36 -08005970 if (appWindowToken == null && inputApplicationHandle != null) {
5971 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005972 Slog.i(TAG, "Input event dispatching timed out sending to application "
5973 + appWindowToken.stringName);
5974 }
Jeff Brown349703e2010-06-22 01:27:15 -07005975
Jeff Brown519e0242010-09-15 15:18:56 -07005976 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005977 try {
5978 // Notify the activity manager about the timeout and let it decide whether
5979 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005980 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005981 if (! abort) {
5982 // The activity manager declined to abort dispatching.
5983 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005984 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005985 }
Jeff Brown349703e2010-06-22 01:27:15 -07005986 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005987 }
5988 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005989 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005990 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005991
Chris Tatea32dcf72010-10-14 12:13:50 -07005992 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005993 final InputWindow inputWindow = windowList.add();
5994 inputWindow.inputChannel = mDragState.mServerChannel;
5995 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08005996 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07005997 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5998 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5999 inputWindow.visible = true;
6000 inputWindow.canReceiveKeys = false;
6001 inputWindow.hasFocus = true;
6002 inputWindow.hasWallpaper = false;
6003 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07006004 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006005 inputWindow.ownerPid = Process.myPid();
6006 inputWindow.ownerUid = Process.myUid();
6007
6008 // The drag window covers the entire display
6009 inputWindow.frameLeft = 0;
6010 inputWindow.frameTop = 0;
6011 inputWindow.frameRight = mDisplay.getWidth();
6012 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07006013
Jeff Brownfbf09772011-01-16 14:06:57 -08006014 // The drag window cannot receive new touches.
6015 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07006016 }
6017
Jeff Brown3a22cd92011-01-21 13:59:04 -08006018 public void setUpdateInputWindowsNeededLw() {
6019 mUpdateInputWindowsNeeded = true;
6020 }
6021
Jeff Brown349703e2010-06-22 01:27:15 -07006022 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08006023 public void updateInputWindowsLw(boolean force) {
6024 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006025 return;
6026 }
6027 mUpdateInputWindowsNeeded = false;
6028
Jeff Brown349703e2010-06-22 01:27:15 -07006029 // Populate the input window list with information about all of the windows that
6030 // could potentially receive input.
6031 // As an optimization, we could try to prune the list of windows but this turns
6032 // out to be difficult because only the native code knows for sure which window
6033 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07006034 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07006035
6036 // If there's a drag in flight, provide a pseudowindow to catch drag input
6037 final boolean inDrag = (mDragState != null);
6038 if (inDrag) {
6039 if (DEBUG_DRAG) {
6040 Log.d(TAG, "Inserting drag window");
6041 }
Chris Tatea32dcf72010-10-14 12:13:50 -07006042 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07006043 }
6044
Jeff Brown7fbdc842010-06-17 20:52:56 -07006045 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07006046 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006047 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07006048 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07006049 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07006050 continue;
6051 }
6052
Jeff Brown349703e2010-06-22 01:27:15 -07006053 final int flags = child.mAttrs.flags;
6054 final int type = child.mAttrs.type;
6055
6056 final boolean hasFocus = (child == mInputFocus);
6057 final boolean isVisible = child.isVisibleLw();
6058 final boolean hasWallpaper = (child == mWallpaperTarget)
6059 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07006060
6061 // If there's a drag in progress and 'child' is a potential drop target,
6062 // make sure it's been told about the drag
6063 if (inDrag && isVisible) {
6064 mDragState.sendDragStartedIfNeededLw(child);
6065 }
6066
Jeff Brown349703e2010-06-22 01:27:15 -07006067 // Add a window to our list of input windows.
6068 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006069 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006070 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006071 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006072 inputWindow.layoutParamsFlags = flags;
6073 inputWindow.layoutParamsType = type;
6074 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6075 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006076 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006077 inputWindow.hasFocus = hasFocus;
6078 inputWindow.hasWallpaper = hasWallpaper;
6079 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006080 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006081 inputWindow.ownerPid = child.mSession.mPid;
6082 inputWindow.ownerUid = child.mSession.mUid;
6083
6084 final Rect frame = child.mFrame;
6085 inputWindow.frameLeft = frame.left;
6086 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006087 inputWindow.frameRight = frame.right;
6088 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006089
6090 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006091 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006092
Jeff Brown349703e2010-06-22 01:27:15 -07006093 // Send windows to native code.
6094 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006095
Jeff Brown349703e2010-06-22 01:27:15 -07006096 // Clear the list in preparation for the next round.
6097 // Also avoids keeping InputChannel objects referenced unnecessarily.
6098 mTempInputWindows.clear();
6099 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006100
6101 /* Notifies that the input device configuration has changed. */
6102 public void notifyConfigurationChanged() {
6103 sendNewConfiguration();
6104
6105 synchronized (mInputDevicesReadyMonitor) {
6106 if (!mInputDevicesReady) {
6107 mInputDevicesReady = true;
6108 mInputDevicesReadyMonitor.notifyAll();
6109 }
6110 }
6111 }
6112
6113 /* Waits until the built-in input devices have been configured. */
6114 public boolean waitForInputDevicesReady(long timeoutMillis) {
6115 synchronized (mInputDevicesReadyMonitor) {
6116 if (!mInputDevicesReady) {
6117 try {
6118 mInputDevicesReadyMonitor.wait(timeoutMillis);
6119 } catch (InterruptedException ex) {
6120 }
6121 }
6122 return mInputDevicesReady;
6123 }
6124 }
6125
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006126 /* Notifies that the lid switch changed state. */
6127 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6128 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6129 }
6130
Jeff Brown349703e2010-06-22 01:27:15 -07006131 /* Provides an opportunity for the window manager policy to intercept early key
6132 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006133 public int interceptKeyBeforeQueueing(
6134 KeyEvent event, int policyFlags, boolean isScreenOn) {
6135 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006136 }
6137
6138 /* Provides an opportunity for the window manager policy to process a key before
6139 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006140 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006141 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006142 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006143 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006144 }
6145
Jeff Brown3915bb82010-11-05 15:02:16 -07006146 /* Provides an opportunity for the window manager policy to process a key that
6147 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006148 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006149 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006150 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006151 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006152 }
6153
Jeff Brown349703e2010-06-22 01:27:15 -07006154 /* Called when the current input focus changes.
6155 * Layer assignment is assumed to be complete by the time this is called.
6156 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006157 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006158 if (DEBUG_INPUT) {
6159 Slog.d(TAG, "Input focus has changed to " + newWindow);
6160 }
6161
6162 if (newWindow != mInputFocus) {
6163 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006164 // Displaying a window implicitly causes dispatching to be unpaused.
6165 // This is to protect against bugs if someone pauses dispatching but
6166 // forgets to resume.
6167 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006168 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006169
Jeff Brown349703e2010-06-22 01:27:15 -07006170 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006171 setUpdateInputWindowsNeededLw();
6172
6173 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006174 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006175 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006176 }
6177 }
6178
Jeff Brown349703e2010-06-22 01:27:15 -07006179 public void setFocusedAppLw(AppWindowToken newApp) {
6180 // Focused app has changed.
6181 if (newApp == null) {
6182 mInputManager.setFocusedApplication(null);
6183 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006184 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006185 mTempInputApplication.name = newApp.toString();
6186 mTempInputApplication.dispatchingTimeoutNanos =
6187 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006188
Jeff Brown349703e2010-06-22 01:27:15 -07006189 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006190
6191 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006192 }
6193 }
6194
Jeff Brown349703e2010-06-22 01:27:15 -07006195 public void pauseDispatchingLw(WindowToken window) {
6196 if (! window.paused) {
6197 if (DEBUG_INPUT) {
6198 Slog.v(TAG, "Pausing WindowToken " + window);
6199 }
6200
6201 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006202 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006203 }
6204 }
6205
6206 public void resumeDispatchingLw(WindowToken window) {
6207 if (window.paused) {
6208 if (DEBUG_INPUT) {
6209 Slog.v(TAG, "Resuming WindowToken " + window);
6210 }
6211
6212 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006213 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006214 }
6215 }
6216
6217 public void freezeInputDispatchingLw() {
6218 if (! mInputDispatchFrozen) {
6219 if (DEBUG_INPUT) {
6220 Slog.v(TAG, "Freezing input dispatching");
6221 }
6222
6223 mInputDispatchFrozen = true;
6224 updateInputDispatchModeLw();
6225 }
6226 }
6227
6228 public void thawInputDispatchingLw() {
6229 if (mInputDispatchFrozen) {
6230 if (DEBUG_INPUT) {
6231 Slog.v(TAG, "Thawing input dispatching");
6232 }
6233
6234 mInputDispatchFrozen = false;
6235 updateInputDispatchModeLw();
6236 }
6237 }
6238
6239 public void setEventDispatchingLw(boolean enabled) {
6240 if (mInputDispatchEnabled != enabled) {
6241 if (DEBUG_INPUT) {
6242 Slog.v(TAG, "Setting event dispatching to " + enabled);
6243 }
6244
6245 mInputDispatchEnabled = enabled;
6246 updateInputDispatchModeLw();
6247 }
6248 }
6249
6250 private void updateInputDispatchModeLw() {
6251 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6252 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006255 public void pauseKeyDispatching(IBinder _token) {
6256 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6257 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006258 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006259 }
6260
6261 synchronized (mWindowMap) {
6262 WindowToken token = mTokenMap.get(_token);
6263 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006264 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006265 }
6266 }
6267 }
6268
6269 public void resumeKeyDispatching(IBinder _token) {
6270 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6271 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006272 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006273 }
6274
6275 synchronized (mWindowMap) {
6276 WindowToken token = mTokenMap.get(_token);
6277 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006278 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006279 }
6280 }
6281 }
6282
6283 public void setEventDispatching(boolean enabled) {
6284 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6285 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006286 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006287 }
6288
6289 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006290 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 }
6292 }
Romain Guy06882f82009-06-10 13:36:04 -07006293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 /**
6295 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006296 * Even when sync is false, this method may block while waiting for current
6297 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006298 *
6299 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006300 * {@link SystemClock#uptimeMillis()} as the timebase.)
6301 * @param sync If true, wait for the event to be completed before returning to the caller.
6302 * @return Returns true if event was dispatched, false if it was dropped for any reason
6303 */
6304 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6305 long downTime = ev.getDownTime();
6306 long eventTime = ev.getEventTime();
6307
6308 int action = ev.getAction();
6309 int code = ev.getKeyCode();
6310 int repeatCount = ev.getRepeatCount();
6311 int metaState = ev.getMetaState();
6312 int deviceId = ev.getDeviceId();
6313 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006314 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006315 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006316
6317 if (source == InputDevice.SOURCE_UNKNOWN) {
6318 source = InputDevice.SOURCE_KEYBOARD;
6319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006320
6321 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6322 if (downTime == 0) downTime = eventTime;
6323
6324 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006325 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006327 final int pid = Binder.getCallingPid();
6328 final int uid = Binder.getCallingUid();
6329 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006330
Jeff Brownbbda99d2010-07-28 15:48:59 -07006331 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6332 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6333 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6334 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006335
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006336 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006337 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006338 }
6339
6340 /**
6341 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006342 * Even when sync is false, this method may block while waiting for current
6343 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006344 *
6345 * @param ev A motion event describing the pointer (touch) action. (As noted in
6346 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006347 * {@link SystemClock#uptimeMillis()} as the timebase.)
6348 * @param sync If true, wait for the event to be completed before returning to the caller.
6349 * @return Returns true if event was dispatched, false if it was dropped for any reason
6350 */
6351 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006352 final int pid = Binder.getCallingPid();
6353 final int uid = Binder.getCallingUid();
6354 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006355
Jeff Brownc5ed5912010-07-14 18:48:53 -07006356 MotionEvent newEvent = MotionEvent.obtain(ev);
6357 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6358 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6359 }
6360
Jeff Brownbbda99d2010-07-28 15:48:59 -07006361 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6362 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6363 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6364 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006365
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006366 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006367 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006368 }
Romain Guy06882f82009-06-10 13:36:04 -07006369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 /**
6371 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006372 * Even when sync is false, this method may block while waiting for current
6373 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006374 *
6375 * @param ev A motion event describing the trackball action. (As noted in
6376 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 * {@link SystemClock#uptimeMillis()} as the timebase.)
6378 * @param sync If true, wait for the event to be completed before returning to the caller.
6379 * @return Returns true if event was dispatched, false if it was dropped for any reason
6380 */
6381 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006382 final int pid = Binder.getCallingPid();
6383 final int uid = Binder.getCallingUid();
6384 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006385
Jeff Brownc5ed5912010-07-14 18:48:53 -07006386 MotionEvent newEvent = MotionEvent.obtain(ev);
6387 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6388 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6389 }
6390
Jeff Brownbbda99d2010-07-28 15:48:59 -07006391 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6392 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6393 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6394 INJECTION_TIMEOUT_MILLIS);
6395
6396 Binder.restoreCallingIdentity(ident);
6397 return reportInjectionResult(result);
6398 }
6399
6400 /**
6401 * Inject an input event into the UI without waiting for dispatch to commence.
6402 * This variant is useful for fire-and-forget input event injection. It does not
6403 * block any longer than it takes to enqueue the input event.
6404 *
6405 * @param ev An input event. (Be sure to set the input source correctly.)
6406 * @return Returns true if event was dispatched, false if it was dropped for any reason
6407 */
6408 public boolean injectInputEventNoWait(InputEvent ev) {
6409 final int pid = Binder.getCallingPid();
6410 final int uid = Binder.getCallingUid();
6411 final long ident = Binder.clearCallingIdentity();
6412
6413 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6414 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6415 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006416
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006417 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006418 return reportInjectionResult(result);
6419 }
6420
6421 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006422 switch (result) {
6423 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6424 Slog.w(TAG, "Input event injection permission denied.");
6425 throw new SecurityException(
6426 "Injecting to another application requires INJECT_EVENTS permission");
6427 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006428 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006429 return true;
6430 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6431 Slog.w(TAG, "Input event injection timed out.");
6432 return false;
6433 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6434 default:
6435 Slog.w(TAG, "Input event injection failed.");
6436 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006437 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 }
Romain Guy06882f82009-06-10 13:36:04 -07006439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 private WindowState getFocusedWindow() {
6441 synchronized (mWindowMap) {
6442 return getFocusedWindowLocked();
6443 }
6444 }
6445
6446 private WindowState getFocusedWindowLocked() {
6447 return mCurrentFocus;
6448 }
Romain Guy06882f82009-06-10 13:36:04 -07006449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006450 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006451 if (!mInputMonitor.waitForInputDevicesReady(
6452 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6453 Slog.w(TAG, "Devices still not ready after waiting "
6454 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6455 + " milliseconds before attempting to detect safe mode.");
6456 }
6457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 mSafeMode = mPolicy.detectSafeMode();
6459 return mSafeMode;
6460 }
Romain Guy06882f82009-06-10 13:36:04 -07006461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006463 synchronized(mWindowMap) {
6464 if (mDisplay != null) {
6465 throw new IllegalStateException("Display already initialized");
6466 }
6467 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6468 mDisplay = wm.getDefaultDisplay();
6469 mInitialDisplayWidth = mDisplay.getWidth();
6470 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006471 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6472 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006473 }
6474
6475 try {
6476 mActivityManager.updateConfiguration(null);
6477 } catch (RemoteException e) {
6478 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006479
6480 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006481 }
6482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 // -------------------------------------------------------------
6484 // Client Session State
6485 // -------------------------------------------------------------
6486
6487 private final class Session extends IWindowSession.Stub
6488 implements IBinder.DeathRecipient {
6489 final IInputMethodClient mClient;
6490 final IInputContext mInputContext;
6491 final int mUid;
6492 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006493 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 SurfaceSession mSurfaceSession;
6495 int mNumWindow = 0;
6496 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 public Session(IInputMethodClient client, IInputContext inputContext) {
6499 mClient = client;
6500 mInputContext = inputContext;
6501 mUid = Binder.getCallingUid();
6502 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006503 StringBuilder sb = new StringBuilder();
6504 sb.append("Session{");
6505 sb.append(Integer.toHexString(System.identityHashCode(this)));
6506 sb.append(" uid ");
6507 sb.append(mUid);
6508 sb.append("}");
6509 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 synchronized (mWindowMap) {
6512 if (mInputMethodManager == null && mHaveInputMethods) {
6513 IBinder b = ServiceManager.getService(
6514 Context.INPUT_METHOD_SERVICE);
6515 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6516 }
6517 }
6518 long ident = Binder.clearCallingIdentity();
6519 try {
6520 // Note: it is safe to call in to the input method manager
6521 // here because we are not holding our lock.
6522 if (mInputMethodManager != null) {
6523 mInputMethodManager.addClient(client, inputContext,
6524 mUid, mPid);
6525 } else {
6526 client.setUsingInputMethod(false);
6527 }
6528 client.asBinder().linkToDeath(this, 0);
6529 } catch (RemoteException e) {
6530 // The caller has died, so we can just forget about this.
6531 try {
6532 if (mInputMethodManager != null) {
6533 mInputMethodManager.removeClient(client);
6534 }
6535 } catch (RemoteException ee) {
6536 }
6537 } finally {
6538 Binder.restoreCallingIdentity(ident);
6539 }
6540 }
Romain Guy06882f82009-06-10 13:36:04 -07006541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 @Override
6543 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6544 throws RemoteException {
6545 try {
6546 return super.onTransact(code, data, reply, flags);
6547 } catch (RuntimeException e) {
6548 // Log all 'real' exceptions thrown to the caller
6549 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006550 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 }
6552 throw e;
6553 }
6554 }
6555
6556 public void binderDied() {
6557 // Note: it is safe to call in to the input method manager
6558 // here because we are not holding our lock.
6559 try {
6560 if (mInputMethodManager != null) {
6561 mInputMethodManager.removeClient(mClient);
6562 }
6563 } catch (RemoteException e) {
6564 }
6565 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006566 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006567 mClientDead = true;
6568 killSessionLocked();
6569 }
6570 }
6571
6572 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006573 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6574 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6575 outInputChannel);
6576 }
6577
6578 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006579 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006580 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006581 }
Romain Guy06882f82009-06-10 13:36:04 -07006582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 public void remove(IWindow window) {
6584 removeWindow(this, window);
6585 }
Romain Guy06882f82009-06-10 13:36:04 -07006586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6588 int requestedWidth, int requestedHeight, int viewFlags,
6589 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006590 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006591 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6592 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006594 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006595 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6596 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 }
Romain Guy06882f82009-06-10 13:36:04 -07006598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 public void setTransparentRegion(IWindow window, Region region) {
6600 setTransparentRegionWindow(this, window, region);
6601 }
Romain Guy06882f82009-06-10 13:36:04 -07006602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006604 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006605 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006606 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006607 }
Romain Guy06882f82009-06-10 13:36:04 -07006608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6610 getWindowDisplayFrame(this, window, outDisplayFrame);
6611 }
Romain Guy06882f82009-06-10 13:36:04 -07006612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006614 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006615 TAG, "IWindow finishDrawing called for " + window);
6616 finishDrawingWindow(this, window);
6617 }
6618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 public void setInTouchMode(boolean mode) {
6620 synchronized(mWindowMap) {
6621 mInTouchMode = mode;
6622 }
6623 }
6624
6625 public boolean getInTouchMode() {
6626 synchronized(mWindowMap) {
6627 return mInTouchMode;
6628 }
6629 }
6630
6631 public boolean performHapticFeedback(IWindow window, int effectId,
6632 boolean always) {
6633 synchronized(mWindowMap) {
6634 long ident = Binder.clearCallingIdentity();
6635 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006636 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006637 windowForClientLocked(this, window, true),
6638 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006639 } finally {
6640 Binder.restoreCallingIdentity(ident);
6641 }
6642 }
6643 }
Romain Guy06882f82009-06-10 13:36:04 -07006644
Christopher Tatea53146c2010-09-07 11:57:52 -07006645 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006646 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006647 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006648 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006649 width, height, outSurface);
6650 }
6651
6652 public boolean performDrag(IWindow window, IBinder dragToken,
6653 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6654 ClipData data) {
6655 if (DEBUG_DRAG) {
6656 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6657 }
6658
6659 synchronized (mWindowMap) {
6660 if (mDragState == null) {
6661 Slog.w(TAG, "No drag prepared");
6662 throw new IllegalStateException("performDrag() without prepareDrag()");
6663 }
6664
6665 if (dragToken != mDragState.mToken) {
6666 Slog.w(TAG, "Performing mismatched drag");
6667 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6668 }
6669
6670 WindowState callingWin = windowForClientLocked(null, window, false);
6671 if (callingWin == null) {
6672 Slog.w(TAG, "Bad requesting window " + window);
6673 return false; // !!! TODO: throw here?
6674 }
6675
6676 // !!! TODO: if input is not still focused on the initiating window, fail
6677 // the drag initiation (e.g. an alarm window popped up just as the application
6678 // called performDrag()
6679
6680 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6681
Christopher Tate2c095f32010-10-04 14:13:40 -07006682 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6683 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006684
Chris Tateb478f462010-10-15 16:02:26 -07006685 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6686 // the actual drag event dispatch stuff in the dragstate
6687
Christopher Tatea53146c2010-09-07 11:57:52 -07006688 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006689 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006690 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6691 mDragState.mServerChannel)) {
6692 Slog.e(TAG, "Unable to transfer touch focus");
6693 mDragState.unregister();
6694 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006695 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006696 return false;
6697 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006698
6699 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006700 mDragState.mCurrentX = touchX;
6701 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006702 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006703
6704 // remember the thumb offsets for later
6705 mDragState.mThumbOffsetX = thumbCenterX;
6706 mDragState.mThumbOffsetY = thumbCenterY;
6707
6708 // Make the surface visible at the proper location
6709 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006710 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006711 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006712 try {
6713 surface.setPosition((int)(touchX - thumbCenterX),
6714 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006715 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006716 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006717 surface.show();
6718 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006719 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006720 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006721 }
6722 }
6723
6724 return true; // success!
6725 }
6726
Chris Tated4533f142010-10-19 15:15:08 -07006727 public void reportDropResult(IWindow window, boolean consumed) {
6728 IBinder token = window.asBinder();
6729 if (DEBUG_DRAG) {
6730 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6731 }
6732
6733 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006734 long ident = Binder.clearCallingIdentity();
6735 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006736 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006737 Slog.w(TAG, "Invalid drop-result claim by " + window);
6738 throw new IllegalStateException("reportDropResult() by non-recipient");
6739 }
6740
6741 // The right window has responded, even if it's no longer around,
6742 // so be sure to halt the timeout even if the later WindowState
6743 // lookup fails.
6744 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6745 WindowState callingWin = windowForClientLocked(null, window, false);
6746 if (callingWin == null) {
6747 Slog.w(TAG, "Bad result-reporting window " + window);
6748 return; // !!! TODO: throw here?
6749 }
6750
6751 mDragState.mDragResult = consumed;
6752 mDragState.endDragLw();
6753 } finally {
6754 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006755 }
Chris Tated4533f142010-10-19 15:15:08 -07006756 }
6757 }
6758
Christopher Tatea53146c2010-09-07 11:57:52 -07006759 public void dragRecipientEntered(IWindow window) {
6760 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006761 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006762 }
6763 }
6764
6765 public void dragRecipientExited(IWindow window) {
6766 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006767 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006768 }
6769 }
6770
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006771 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006772 synchronized(mWindowMap) {
6773 long ident = Binder.clearCallingIdentity();
6774 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006775 setWindowWallpaperPositionLocked(
6776 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006777 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006778 } finally {
6779 Binder.restoreCallingIdentity(ident);
6780 }
6781 }
6782 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006783
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006784 public void wallpaperOffsetsComplete(IBinder window) {
6785 WindowManagerService.this.wallpaperOffsetsComplete(window);
6786 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006787
Dianne Hackborn75804932009-10-20 20:15:20 -07006788 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6789 int z, Bundle extras, boolean sync) {
6790 synchronized(mWindowMap) {
6791 long ident = Binder.clearCallingIdentity();
6792 try {
6793 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006794 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006795 action, x, y, z, extras, sync);
6796 } finally {
6797 Binder.restoreCallingIdentity(ident);
6798 }
6799 }
6800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006801
Dianne Hackborn75804932009-10-20 20:15:20 -07006802 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6803 WindowManagerService.this.wallpaperCommandComplete(window, result);
6804 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006806 void windowAddedLocked() {
6807 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006808 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006809 TAG, "First window added to " + this + ", creating SurfaceSession");
6810 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006811 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006812 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006813 mSessions.add(this);
6814 }
6815 mNumWindow++;
6816 }
6817
6818 void windowRemovedLocked() {
6819 mNumWindow--;
6820 killSessionLocked();
6821 }
Romain Guy06882f82009-06-10 13:36:04 -07006822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 void killSessionLocked() {
6824 if (mNumWindow <= 0 && mClientDead) {
6825 mSessions.remove(this);
6826 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006827 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006828 TAG, "Last window removed from " + this
6829 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006830 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006831 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006832 try {
6833 mSurfaceSession.kill();
6834 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006835 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 + mSurfaceSession + " in session " + this
6837 + ": " + e.toString());
6838 }
6839 mSurfaceSession = null;
6840 }
6841 }
6842 }
Romain Guy06882f82009-06-10 13:36:04 -07006843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006845 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6846 pw.print(" mClientDead="); pw.print(mClientDead);
6847 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848 }
6849
6850 @Override
6851 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006852 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 }
6854 }
6855
6856 // -------------------------------------------------------------
6857 // Client Window State
6858 // -------------------------------------------------------------
6859
6860 private final class WindowState implements WindowManagerPolicy.WindowState {
6861 final Session mSession;
6862 final IWindow mClient;
6863 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006864 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006865 AppWindowToken mAppToken;
6866 AppWindowToken mTargetAppToken;
6867 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6868 final DeathRecipient mDeathRecipient;
6869 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006870 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 final int mBaseLayer;
6872 final int mSubLayer;
6873 final boolean mLayoutAttached;
6874 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006875 final boolean mIsWallpaper;
6876 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 int mViewVisibility;
6878 boolean mPolicyVisibility = true;
6879 boolean mPolicyVisibilityAfterAnim = true;
6880 boolean mAppFreezing;
6881 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006882 boolean mReportDestroySurface;
6883 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006884 boolean mAttachedHidden; // is our parent window hidden?
6885 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006886 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 int mRequestedWidth;
6888 int mRequestedHeight;
6889 int mLastRequestedWidth;
6890 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 int mLayer;
6892 int mAnimLayer;
6893 int mLastLayer;
6894 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006895 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006896 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006898 int mLayoutSeq = -1;
6899
6900 Configuration mConfiguration = null;
6901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006902 // Actual frame shown on-screen (may be modified by animation)
6903 final Rect mShownFrame = new Rect();
6904 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006906 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006907 * Set when we have changed the size of the surface, to know that
6908 * we must tell them application to resize (and thus redraw itself).
6909 */
6910 boolean mSurfaceResized;
6911
6912 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006913 * Insets that determine the actually visible area
6914 */
6915 final Rect mVisibleInsets = new Rect();
6916 final Rect mLastVisibleInsets = new Rect();
6917 boolean mVisibleInsetsChanged;
6918
6919 /**
6920 * Insets that are covered by system windows
6921 */
6922 final Rect mContentInsets = new Rect();
6923 final Rect mLastContentInsets = new Rect();
6924 boolean mContentInsetsChanged;
6925
6926 /**
6927 * Set to true if we are waiting for this window to receive its
6928 * given internal insets before laying out other windows based on it.
6929 */
6930 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 /**
6933 * These are the content insets that were given during layout for
6934 * this window, to be applied to windows behind it.
6935 */
6936 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006938 /**
6939 * These are the visible insets that were given during layout for
6940 * this window, to be applied to windows behind it.
6941 */
6942 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006944 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006945 * This is the given touchable area relative to the window frame, or null if none.
6946 */
6947 final Region mGivenTouchableRegion = new Region();
6948
6949 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950 * Flag indicating whether the touchable region should be adjusted by
6951 * the visible insets; if false the area outside the visible insets is
6952 * NOT touchable, so we must use those to adjust the frame during hit
6953 * tests.
6954 */
6955 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006958 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6960 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6961 float mHScale=1, mVScale=1;
6962 float mLastHScale=1, mLastVScale=1;
6963 final Matrix mTmpMatrix = new Matrix();
6964
6965 // "Real" frame that the application sees.
6966 final Rect mFrame = new Rect();
6967 final Rect mLastFrame = new Rect();
6968
6969 final Rect mContainingFrame = new Rect();
6970 final Rect mDisplayFrame = new Rect();
6971 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006972 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006973 final Rect mVisibleFrame = new Rect();
6974
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006975 boolean mContentChanged;
6976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 float mShownAlpha = 1;
6978 float mAlpha = 1;
6979 float mLastAlpha = 1;
6980
6981 // Set to true if, when the window gets displayed, it should perform
6982 // an enter animation.
6983 boolean mEnterAnimationPending;
6984
6985 // Currently running animation.
6986 boolean mAnimating;
6987 boolean mLocalAnimating;
6988 Animation mAnimation;
6989 boolean mAnimationIsEntrance;
6990 boolean mHasTransformation;
6991 boolean mHasLocalTransformation;
6992 final Transformation mTransformation = new Transformation();
6993
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006994 // If a window showing a wallpaper: the requested offset for the
6995 // wallpaper; if a wallpaper window: the currently applied offset.
6996 float mWallpaperX = -1;
6997 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006998
6999 // If a window showing a wallpaper: what fraction of the offset
7000 // range corresponds to a full virtual screen.
7001 float mWallpaperXStep = -1;
7002 float mWallpaperYStep = -1;
7003
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007004 // Wallpaper windows: pixels offset based on above variables.
7005 int mXOffset;
7006 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 // This is set after IWindowSession.relayout() has been called at
7009 // least once for the window. It allows us to detect the situation
7010 // where we don't yet have a surface, but should have one soon, so
7011 // we can give the window focus before waiting for the relayout.
7012 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 // This is set after the Surface has been created but before the
7015 // window has been drawn. During this time the surface is hidden.
7016 boolean mDrawPending;
7017
7018 // This is set after the window has finished drawing for the first
7019 // time but before its surface is shown. The surface will be
7020 // displayed when the next layout is run.
7021 boolean mCommitDrawPending;
7022
7023 // This is set during the time after the window's drawing has been
7024 // committed, and before its surface is actually shown. It is used
7025 // to delay showing the surface until all windows in a token are ready
7026 // to be shown.
7027 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 // Set when the window has been shown in the screen the first time.
7030 boolean mHasDrawn;
7031
7032 // Currently running an exit animation?
7033 boolean mExiting;
7034
7035 // Currently on the mDestroySurface list?
7036 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 // Completely remove from window manager after exit animation?
7039 boolean mRemoveOnExit;
7040
7041 // Set when the orientation is changing and this window has not yet
7042 // been updated for the new orientation.
7043 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 // Is this window now (or just being) removed?
7046 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007047
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007048 // Temp for keeping track of windows that have been removed when
7049 // rebuilding window list.
7050 boolean mRebuilding;
7051
Dianne Hackborn16064f92010-03-25 00:47:24 -07007052 // For debugging, this is the last information given to the surface flinger.
7053 boolean mSurfaceShown;
7054 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7055 int mSurfaceLayer;
7056 float mSurfaceAlpha;
7057
Jeff Brown928e0542011-01-10 11:17:36 -08007058 // Input channel and input window handle used by the input dispatcher.
7059 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007060 InputChannel mInputChannel;
7061
Mattias Petersson1622eee2010-12-21 10:15:11 +01007062 // Used to improve performance of toString()
7063 String mStringNameCache;
7064 CharSequence mLastTitle;
7065 boolean mWasPaused;
7066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 WindowState(Session s, IWindow c, WindowToken token,
7068 WindowState attachedWindow, WindowManager.LayoutParams a,
7069 int viewVisibility) {
7070 mSession = s;
7071 mClient = c;
7072 mToken = token;
7073 mAttrs.copyFrom(a);
7074 mViewVisibility = viewVisibility;
7075 DeathRecipient deathRecipient = new DeathRecipient();
7076 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007077 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007078 TAG, "Window " + this + " client=" + c.asBinder()
7079 + " token=" + token + " (" + mAttrs.token + ")");
7080 try {
7081 c.asBinder().linkToDeath(deathRecipient, 0);
7082 } catch (RemoteException e) {
7083 mDeathRecipient = null;
7084 mAttachedWindow = null;
7085 mLayoutAttached = false;
7086 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007087 mIsWallpaper = false;
7088 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007089 mBaseLayer = 0;
7090 mSubLayer = 0;
7091 return;
7092 }
7093 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7096 mAttrs.type <= LAST_SUB_WINDOW)) {
7097 // The multiplier here is to reserve space for multiple
7098 // windows in the same type layer.
7099 mBaseLayer = mPolicy.windowTypeToLayerLw(
7100 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7101 + TYPE_LAYER_OFFSET;
7102 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7103 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007104 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007105 mAttachedWindow.mChildWindows.add(this);
7106 mLayoutAttached = mAttrs.type !=
7107 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7108 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7109 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007110 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7111 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007112 } else {
7113 // The multiplier here is to reserve space for multiple
7114 // windows in the same type layer.
7115 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7116 * TYPE_LAYER_MULTIPLIER
7117 + TYPE_LAYER_OFFSET;
7118 mSubLayer = 0;
7119 mAttachedWindow = null;
7120 mLayoutAttached = false;
7121 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7122 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007123 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7124 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007125 }
7126
7127 WindowState appWin = this;
7128 while (appWin.mAttachedWindow != null) {
7129 appWin = mAttachedWindow;
7130 }
7131 WindowToken appToken = appWin.mToken;
7132 while (appToken.appWindowToken == null) {
7133 WindowToken parent = mTokenMap.get(appToken.token);
7134 if (parent == null || appToken == parent) {
7135 break;
7136 }
7137 appToken = parent;
7138 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007139 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007140 mAppToken = appToken.appWindowToken;
7141
7142 mSurface = null;
7143 mRequestedWidth = 0;
7144 mRequestedHeight = 0;
7145 mLastRequestedWidth = 0;
7146 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007147 mXOffset = 0;
7148 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 mLayer = 0;
7150 mAnimLayer = 0;
7151 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007152 mInputWindowHandle = new InputWindowHandle(
7153 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154 }
7155
7156 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007157 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007158 TAG, "Attaching " + this + " token=" + mToken
7159 + ", list=" + mToken.windows);
7160 mSession.windowAddedLocked();
7161 }
7162
7163 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7164 mHaveFrame = true;
7165
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007166 final Rect container = mContainingFrame;
7167 container.set(pf);
7168
7169 final Rect display = mDisplayFrame;
7170 display.set(df);
7171
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007172 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007173 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007174 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7175 display.intersect(mCompatibleScreenFrame);
7176 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007177 }
7178
7179 final int pw = container.right - container.left;
7180 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181
7182 int w,h;
7183 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7184 w = mAttrs.width < 0 ? pw : mAttrs.width;
7185 h = mAttrs.height< 0 ? ph : mAttrs.height;
7186 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007187 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7188 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007189 }
Romain Guy06882f82009-06-10 13:36:04 -07007190
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007191 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007192 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7193 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007194 mParentFrame.set(pf);
7195 mContentChanged = true;
7196 }
7197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007198 final Rect content = mContentFrame;
7199 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007201 final Rect visible = mVisibleFrame;
7202 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007204 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007205 final int fw = frame.width();
7206 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007208 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7209 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7210
7211 Gravity.apply(mAttrs.gravity, w, h, container,
7212 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7213 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7214
7215 //System.out.println("Out: " + mFrame);
7216
7217 // Now make sure the window fits in the overall display.
7218 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007220 // Make sure the content and visible frames are inside of the
7221 // final window frame.
7222 if (content.left < frame.left) content.left = frame.left;
7223 if (content.top < frame.top) content.top = frame.top;
7224 if (content.right > frame.right) content.right = frame.right;
7225 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7226 if (visible.left < frame.left) visible.left = frame.left;
7227 if (visible.top < frame.top) visible.top = frame.top;
7228 if (visible.right > frame.right) visible.right = frame.right;
7229 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007231 final Rect contentInsets = mContentInsets;
7232 contentInsets.left = content.left-frame.left;
7233 contentInsets.top = content.top-frame.top;
7234 contentInsets.right = frame.right-content.right;
7235 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007237 final Rect visibleInsets = mVisibleInsets;
7238 visibleInsets.left = visible.left-frame.left;
7239 visibleInsets.top = visible.top-frame.top;
7240 visibleInsets.right = frame.right-visible.right;
7241 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007242
Dianne Hackborn284ac932009-08-28 10:34:25 -07007243 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7244 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007245 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 if (localLOGV) {
7249 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7250 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007251 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007252 + mRequestedWidth + ", mRequestedheight="
7253 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7254 + "): frame=" + mFrame.toShortString()
7255 + " ci=" + contentInsets.toShortString()
7256 + " vi=" + visibleInsets.toShortString());
7257 //}
7258 }
7259 }
Romain Guy06882f82009-06-10 13:36:04 -07007260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 public Rect getFrameLw() {
7262 return mFrame;
7263 }
7264
7265 public Rect getShownFrameLw() {
7266 return mShownFrame;
7267 }
7268
7269 public Rect getDisplayFrameLw() {
7270 return mDisplayFrame;
7271 }
7272
7273 public Rect getContentFrameLw() {
7274 return mContentFrame;
7275 }
7276
7277 public Rect getVisibleFrameLw() {
7278 return mVisibleFrame;
7279 }
7280
7281 public boolean getGivenInsetsPendingLw() {
7282 return mGivenInsetsPending;
7283 }
7284
7285 public Rect getGivenContentInsetsLw() {
7286 return mGivenContentInsets;
7287 }
Romain Guy06882f82009-06-10 13:36:04 -07007288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 public Rect getGivenVisibleInsetsLw() {
7290 return mGivenVisibleInsets;
7291 }
Romain Guy06882f82009-06-10 13:36:04 -07007292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 public WindowManager.LayoutParams getAttrs() {
7294 return mAttrs;
7295 }
7296
7297 public int getSurfaceLayer() {
7298 return mLayer;
7299 }
Romain Guy06882f82009-06-10 13:36:04 -07007300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007301 public IApplicationToken getAppToken() {
7302 return mAppToken != null ? mAppToken.appToken : null;
7303 }
Jeff Brown349703e2010-06-22 01:27:15 -07007304
7305 public long getInputDispatchingTimeoutNanos() {
7306 return mAppToken != null
7307 ? mAppToken.inputDispatchingTimeoutNanos
7308 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7309 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310
7311 public boolean hasAppShownWindows() {
7312 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7313 }
7314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007315 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007316 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 TAG, "Setting animation in " + this + ": " + anim);
7318 mAnimating = false;
7319 mLocalAnimating = false;
7320 mAnimation = anim;
7321 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7322 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7323 }
7324
7325 public void clearAnimation() {
7326 if (mAnimation != null) {
7327 mAnimating = true;
7328 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007329 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 mAnimation = null;
7331 }
7332 }
Romain Guy06882f82009-06-10 13:36:04 -07007333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 Surface createSurfaceLocked() {
7335 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007336 mReportDestroySurface = false;
7337 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 mDrawPending = true;
7339 mCommitDrawPending = false;
7340 mReadyToShow = false;
7341 if (mAppToken != null) {
7342 mAppToken.allDrawn = false;
7343 }
7344
7345 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346
7347 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7348 flags |= Surface.SECURE;
7349 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007350 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 TAG, "Creating surface in session "
7352 + mSession.mSurfaceSession + " window " + this
7353 + " w=" + mFrame.width()
7354 + " h=" + mFrame.height() + " format="
7355 + mAttrs.format + " flags=" + flags);
7356
7357 int w = mFrame.width();
7358 int h = mFrame.height();
7359 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7360 // for a scaled surface, we always want the requested
7361 // size.
7362 w = mRequestedWidth;
7363 h = mRequestedHeight;
7364 }
7365
Romain Guy9825ec62009-10-01 00:58:09 -07007366 // Something is wrong and SurfaceFlinger will not like this,
7367 // try to revert to sane values
7368 if (w <= 0) w = 1;
7369 if (h <= 0) h = 1;
7370
Dianne Hackborn16064f92010-03-25 00:47:24 -07007371 mSurfaceShown = false;
7372 mSurfaceLayer = 0;
7373 mSurfaceAlpha = 1;
7374 mSurfaceX = 0;
7375 mSurfaceY = 0;
7376 mSurfaceW = w;
7377 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007379 final boolean isHwAccelerated = (mAttrs.flags &
7380 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7381 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7382 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7383 flags |= Surface.OPAQUE;
7384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007386 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007387 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007388 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007389 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007390 + mSurface + " IN SESSION "
7391 + mSession.mSurfaceSession
7392 + ": pid=" + mSession.mPid + " format="
7393 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007394 + Integer.toHexString(flags)
7395 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007397 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007398 reclaimSomeSurfaceMemoryLocked(this, "create");
7399 return null;
7400 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007401 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007402 return null;
7403 }
Romain Guy06882f82009-06-10 13:36:04 -07007404
Joe Onorato8a9b2202010-02-26 18:56:32 -08007405 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 TAG, "Got surface: " + mSurface
7407 + ", set left=" + mFrame.left + " top=" + mFrame.top
7408 + ", animLayer=" + mAnimLayer);
7409 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007410 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7411 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007412 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7413 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007414 }
7415 Surface.openTransaction();
7416 try {
7417 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007418 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007419 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007420 mSurface.setPosition(mSurfaceX, mSurfaceY);
7421 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007423 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007424 mSurface.hide();
7425 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007426 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 mSurface.setFlags(Surface.SURFACE_DITHER,
7428 Surface.SURFACE_DITHER);
7429 }
7430 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007431 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7433 }
7434 mLastHidden = true;
7435 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007436 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007437 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007439 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 TAG, "Created surface " + this);
7441 }
7442 return mSurface;
7443 }
Romain Guy06882f82009-06-10 13:36:04 -07007444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 if (mAppToken != null && this == mAppToken.startingWindow) {
7447 mAppToken.startingDisplayed = false;
7448 }
Romain Guy06882f82009-06-10 13:36:04 -07007449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007450 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007451 mDrawPending = false;
7452 mCommitDrawPending = false;
7453 mReadyToShow = false;
7454
7455 int i = mChildWindows.size();
7456 while (i > 0) {
7457 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007458 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007459 c.mAttachedHidden = true;
7460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007461
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007462 if (mReportDestroySurface) {
7463 mReportDestroySurface = false;
7464 mSurfacePendingDestroy = true;
7465 try {
7466 mClient.dispatchGetNewSurface();
7467 // We'll really destroy on the next time around.
7468 return;
7469 } catch (RemoteException e) {
7470 }
7471 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007473 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007474 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007475 RuntimeException e = null;
7476 if (!HIDE_STACK_CRAWLS) {
7477 e = new RuntimeException();
7478 e.fillInStackTrace();
7479 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007480 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007481 + mSurface + ", session " + mSession, e);
7482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007484 RuntimeException e = null;
7485 if (!HIDE_STACK_CRAWLS) {
7486 e = new RuntimeException();
7487 e.fillInStackTrace();
7488 }
7489 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007491 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007492 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007493 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 + " surface " + mSurface + " session " + mSession
7495 + ": " + e.toString());
7496 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007497
Dianne Hackborn16064f92010-03-25 00:47:24 -07007498 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 }
7501 }
7502
7503 boolean finishDrawingLocked() {
7504 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007505 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007506 TAG, "finishDrawingLocked: " + mSurface);
7507 mCommitDrawPending = true;
7508 mDrawPending = false;
7509 return true;
7510 }
7511 return false;
7512 }
7513
7514 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007515 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007516 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007518 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007519 }
7520 mCommitDrawPending = false;
7521 mReadyToShow = true;
7522 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7523 final AppWindowToken atoken = mAppToken;
7524 if (atoken == null || atoken.allDrawn || starting) {
7525 performShowLocked();
7526 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007527 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007528 }
7529
7530 // This must be called while inside a transaction.
7531 boolean performShowLocked() {
7532 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007533 RuntimeException e = null;
7534 if (!HIDE_STACK_CRAWLS) {
7535 e = new RuntimeException();
7536 e.fillInStackTrace();
7537 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007538 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007539 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7540 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7541 }
7542 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007543 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7544 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007545 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 + " during animation: policyVis=" + mPolicyVisibility
7547 + " attHidden=" + mAttachedHidden
7548 + " tok.hiddenRequested="
7549 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007550 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 + (mAppToken != null ? mAppToken.hidden : false)
7552 + " animating=" + mAnimating
7553 + " tok animating="
7554 + (mAppToken != null ? mAppToken.animating : false));
7555 if (!showSurfaceRobustlyLocked(this)) {
7556 return false;
7557 }
7558 mLastAlpha = -1;
7559 mHasDrawn = true;
7560 mLastHidden = false;
7561 mReadyToShow = false;
7562 enableScreenIfNeededLocked();
7563
7564 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007566 int i = mChildWindows.size();
7567 while (i > 0) {
7568 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007569 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007570 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007571 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007572 if (c.mSurface != null) {
7573 c.performShowLocked();
7574 // It hadn't been shown, which means layout not
7575 // performed on it, so now we want to make sure to
7576 // do a layout. If called from within the transaction
7577 // loop, this will cause it to restart with a new
7578 // layout.
7579 mLayoutNeeded = true;
7580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007581 }
7582 }
Romain Guy06882f82009-06-10 13:36:04 -07007583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 if (mAttrs.type != TYPE_APPLICATION_STARTING
7585 && mAppToken != null) {
7586 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007587
Dianne Hackborn248b1882009-09-16 16:46:44 -07007588 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007589 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007590 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007592 // If this initial window is animating, stop it -- we
7593 // will do an animation to reveal it from behind the
7594 // starting window, so there is no need for it to also
7595 // be doing its own stuff.
7596 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007597 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007598 mAnimation = null;
7599 // Make sure we clean up the animation.
7600 mAnimating = true;
7601 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 mFinishedStarting.add(mAppToken);
7603 mH.sendEmptyMessage(H.FINISHED_STARTING);
7604 }
7605 mAppToken.updateReportedVisibilityLocked();
7606 }
7607 }
7608 return true;
7609 }
Romain Guy06882f82009-06-10 13:36:04 -07007610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 // This must be called while inside a transaction. Returns true if
7612 // there is more animation to run.
7613 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007614 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007615 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7618 mHasTransformation = true;
7619 mHasLocalTransformation = true;
7620 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007621 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 TAG, "Starting animation in " + this +
7623 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7624 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7625 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7626 mAnimation.setStartTime(currentTime);
7627 mLocalAnimating = true;
7628 mAnimating = true;
7629 }
7630 mTransformation.clear();
7631 final boolean more = mAnimation.getTransformation(
7632 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007633 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007634 TAG, "Stepped animation in " + this +
7635 ": more=" + more + ", xform=" + mTransformation);
7636 if (more) {
7637 // we're not done!
7638 return true;
7639 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007640 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007641 TAG, "Finished animation in " + this +
7642 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007643
7644 if (mAnimation != null) {
7645 mAnimation.cancel();
7646 mAnimation = null;
7647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007648 //WindowManagerService.this.dump();
7649 }
7650 mHasLocalTransformation = false;
7651 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007652 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007653 // When our app token is animating, we kind-of pretend like
7654 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7655 // part of this check means that we will only do this if
7656 // our window is not currently exiting, or it is not
7657 // locally animating itself. The idea being that one that
7658 // is exiting and doing a local animation should be removed
7659 // once that animation is done.
7660 mAnimating = true;
7661 mHasTransformation = true;
7662 mTransformation.clear();
7663 return false;
7664 } else if (mHasTransformation) {
7665 // Little trick to get through the path below to act like
7666 // we have finished an animation.
7667 mAnimating = true;
7668 } else if (isAnimating()) {
7669 mAnimating = true;
7670 }
7671 } else if (mAnimation != null) {
7672 // If the display is frozen, and there is a pending animation,
7673 // clear it and make sure we run the cleanup code.
7674 mAnimating = true;
7675 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007676 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007677 mAnimation = null;
7678 }
Romain Guy06882f82009-06-10 13:36:04 -07007679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007680 if (!mAnimating && !mLocalAnimating) {
7681 return false;
7682 }
7683
Joe Onorato8a9b2202010-02-26 18:56:32 -08007684 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007685 TAG, "Animation done in " + this + ": exiting=" + mExiting
7686 + ", reportedVisible="
7687 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 mAnimating = false;
7690 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007691 if (mAnimation != null) {
7692 mAnimation.cancel();
7693 mAnimation = null;
7694 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007695 mAnimLayer = mLayer;
7696 if (mIsImWindow) {
7697 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007698 } else if (mIsWallpaper) {
7699 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007700 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007701 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 + " anim layer: " + mAnimLayer);
7703 mHasTransformation = false;
7704 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007705 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7706 if (DEBUG_VISIBILITY) {
7707 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7708 + mPolicyVisibilityAfterAnim);
7709 }
7710 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7711 if (!mPolicyVisibility) {
7712 if (mCurrentFocus == this) {
7713 mFocusMayChange = true;
7714 }
7715 // Window is no longer visible -- make sure if we were waiting
7716 // for it to be displayed before enabling the display, that
7717 // we allow the display to be enabled now.
7718 enableScreenIfNeededLocked();
7719 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007721 mTransformation.clear();
7722 if (mHasDrawn
7723 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7724 && mAppToken != null
7725 && mAppToken.firstWindowDrawn
7726 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007727 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 + mToken + ": first real window done animating");
7729 mFinishedStarting.add(mAppToken);
7730 mH.sendEmptyMessage(H.FINISHED_STARTING);
7731 }
Romain Guy06882f82009-06-10 13:36:04 -07007732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007733 finishExit();
7734
7735 if (mAppToken != null) {
7736 mAppToken.updateReportedVisibilityLocked();
7737 }
7738
7739 return false;
7740 }
7741
7742 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007743 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007744 TAG, "finishExit in " + this
7745 + ": exiting=" + mExiting
7746 + " remove=" + mRemoveOnExit
7747 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007749 final int N = mChildWindows.size();
7750 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007751 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007752 }
Romain Guy06882f82009-06-10 13:36:04 -07007753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007754 if (!mExiting) {
7755 return;
7756 }
Romain Guy06882f82009-06-10 13:36:04 -07007757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 if (isWindowAnimating()) {
7759 return;
7760 }
7761
Joe Onorato8a9b2202010-02-26 18:56:32 -08007762 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763 TAG, "Exit animation finished in " + this
7764 + ": remove=" + mRemoveOnExit);
7765 if (mSurface != null) {
7766 mDestroySurface.add(this);
7767 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007768 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007769 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 try {
7771 mSurface.hide();
7772 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007773 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007774 }
7775 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 }
7777 mExiting = false;
7778 if (mRemoveOnExit) {
7779 mPendingRemove.add(this);
7780 mRemoveOnExit = false;
7781 }
7782 }
Romain Guy06882f82009-06-10 13:36:04 -07007783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007784 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7785 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7786 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7787 if (dtdx < -.000001f || dtdx > .000001f) return false;
7788 if (dsdy < -.000001f || dsdy > .000001f) return false;
7789 return true;
7790 }
Romain Guy06882f82009-06-10 13:36:04 -07007791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792 void computeShownFrameLocked() {
7793 final boolean selfTransformation = mHasLocalTransformation;
7794 Transformation attachedTransformation =
7795 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7796 ? mAttachedWindow.mTransformation : null;
7797 Transformation appTransformation =
7798 (mAppToken != null && mAppToken.hasTransformation)
7799 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007800
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007801 // Wallpapers are animated based on the "real" window they
7802 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007803 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007804 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007805 if (mWallpaperTarget.mHasLocalTransformation &&
7806 mWallpaperTarget.mAnimation != null &&
7807 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007808 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007809 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007810 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007811 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007812 }
7813 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007814 mWallpaperTarget.mAppToken.hasTransformation &&
7815 mWallpaperTarget.mAppToken.animation != null &&
7816 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007817 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007818 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007819 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007820 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007821 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007823
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007824 final boolean screenAnimation = mScreenRotationAnimation != null
7825 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007827 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007828 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007829 final Rect frame = mFrame;
7830 final float tmpFloats[] = mTmpFloats;
7831 final Matrix tmpMatrix = mTmpMatrix;
7832
7833 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007834 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007835 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007836 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007837 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007838 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007839 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007840 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007841 }
7842 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007843 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007844 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007845 if (screenAnimation) {
7846 tmpMatrix.postConcat(
7847 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7848 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007849
7850 // "convert" it into SurfaceFlinger's format
7851 // (a 2x2 matrix + an offset)
7852 // Here we must not transform the position of the surface
7853 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007854 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007855
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007856 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007857 tmpMatrix.getValues(tmpFloats);
7858 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007859 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7860 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007861 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007862 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7863 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007864 int w = frame.width();
7865 int h = frame.height();
7866 mShownFrame.set(x, y, x+w, y+h);
7867
7868 // Now set the alpha... but because our current hardware
7869 // can't do alpha transformation on a non-opaque surface,
7870 // turn it off if we are running an animation that is also
7871 // transforming since it is more important to have that
7872 // animation be smooth.
7873 mShownAlpha = mAlpha;
7874 if (!mLimitedAlphaCompositing
7875 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7876 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7877 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007878 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007879 if (selfTransformation) {
7880 mShownAlpha *= mTransformation.getAlpha();
7881 }
7882 if (attachedTransformation != null) {
7883 mShownAlpha *= attachedTransformation.getAlpha();
7884 }
7885 if (appTransformation != null) {
7886 mShownAlpha *= appTransformation.getAlpha();
7887 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007888 if (screenAnimation) {
7889 mShownAlpha *=
7890 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007892 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007893 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 }
Romain Guy06882f82009-06-10 13:36:04 -07007895
Joe Onorato8a9b2202010-02-26 18:56:32 -08007896 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007897 TAG, "Continuing animation in " + this +
7898 ": " + mShownFrame +
7899 ", alpha=" + mTransformation.getAlpha());
7900 return;
7901 }
Romain Guy06882f82009-06-10 13:36:04 -07007902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007903 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007904 if (mXOffset != 0 || mYOffset != 0) {
7905 mShownFrame.offset(mXOffset, mYOffset);
7906 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007908 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007909 mDsDx = 1;
7910 mDtDx = 0;
7911 mDsDy = 0;
7912 mDtDy = 1;
7913 }
Romain Guy06882f82009-06-10 13:36:04 -07007914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007915 /**
7916 * Is this window visible? It is not visible if there is no
7917 * surface, or we are in the process of running an exit animation
7918 * that will remove the surface, or its app token has been hidden.
7919 */
7920 public boolean isVisibleLw() {
7921 final AppWindowToken atoken = mAppToken;
7922 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7923 && (atoken == null || !atoken.hiddenRequested)
7924 && !mExiting && !mDestroying;
7925 }
7926
7927 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007928 * Like {@link #isVisibleLw}, but also counts a window that is currently
7929 * "hidden" behind the keyguard as visible. This allows us to apply
7930 * things like window flags that impact the keyguard.
7931 * XXX I am starting to think we need to have ANOTHER visibility flag
7932 * for this "hidden behind keyguard" state rather than overloading
7933 * mPolicyVisibility. Ungh.
7934 */
7935 public boolean isVisibleOrBehindKeyguardLw() {
7936 final AppWindowToken atoken = mAppToken;
7937 return mSurface != null && !mAttachedHidden
7938 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007939 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007940 && !mExiting && !mDestroying;
7941 }
7942
7943 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007944 * Is this window visible, ignoring its app token? It is not visible
7945 * if there is no surface, or we are in the process of running an exit animation
7946 * that will remove the surface.
7947 */
7948 public boolean isWinVisibleLw() {
7949 final AppWindowToken atoken = mAppToken;
7950 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7951 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7952 && !mExiting && !mDestroying;
7953 }
7954
7955 /**
7956 * The same as isVisible(), but follows the current hidden state of
7957 * the associated app token, not the pending requested hidden state.
7958 */
7959 boolean isVisibleNow() {
7960 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007961 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 }
7963
7964 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007965 * Can this window possibly be a drag/drop target? The test here is
7966 * a combination of the above "visible now" with the check that the
7967 * Input Manager uses when discarding windows from input consideration.
7968 */
7969 boolean isPotentialDragTarget() {
7970 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7971 }
7972
7973 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007974 * Same as isVisible(), but we also count it as visible between the
7975 * call to IWindowSession.add() and the first relayout().
7976 */
7977 boolean isVisibleOrAdding() {
7978 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007979 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7981 && mPolicyVisibility && !mAttachedHidden
7982 && (atoken == null || !atoken.hiddenRequested)
7983 && !mExiting && !mDestroying;
7984 }
7985
7986 /**
7987 * Is this window currently on-screen? It is on-screen either if it
7988 * is visible or it is currently running an animation before no longer
7989 * being visible.
7990 */
7991 boolean isOnScreen() {
7992 final AppWindowToken atoken = mAppToken;
7993 if (atoken != null) {
7994 return mSurface != null && mPolicyVisibility && !mDestroying
7995 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007996 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007997 } else {
7998 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007999 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008000 }
8001 }
Romain Guy06882f82009-06-10 13:36:04 -07008002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 /**
8004 * Like isOnScreen(), but we don't return true if the window is part
8005 * of a transition that has not yet been started.
8006 */
8007 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008008 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008009 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008010 return false;
8011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008012 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008013 final boolean animating = atoken != null
8014 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008015 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008016 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8017 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008018 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008019 }
8020
8021 /** Is the window or its container currently animating? */
8022 boolean isAnimating() {
8023 final WindowState attached = mAttachedWindow;
8024 final AppWindowToken atoken = mAppToken;
8025 return mAnimation != null
8026 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008027 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 (atoken.animation != null
8029 || atoken.inPendingTransaction));
8030 }
8031
8032 /** Is this window currently animating? */
8033 boolean isWindowAnimating() {
8034 return mAnimation != null;
8035 }
8036
8037 /**
8038 * Like isOnScreen, but returns false if the surface hasn't yet
8039 * been drawn.
8040 */
8041 public boolean isDisplayedLw() {
8042 final AppWindowToken atoken = mAppToken;
8043 return mSurface != null && mPolicyVisibility && !mDestroying
8044 && !mDrawPending && !mCommitDrawPending
8045 && ((!mAttachedHidden &&
8046 (atoken == null || !atoken.hiddenRequested))
8047 || mAnimating);
8048 }
8049
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008050 /**
8051 * Returns true if the window has a surface that it has drawn a
8052 * complete UI in to.
8053 */
8054 public boolean isDrawnLw() {
8055 final AppWindowToken atoken = mAppToken;
8056 return mSurface != null && !mDestroying
8057 && !mDrawPending && !mCommitDrawPending;
8058 }
8059
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008060 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008061 * Return true if the window is opaque and fully drawn. This indicates
8062 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008063 */
8064 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008065 return (mAttrs.format == PixelFormat.OPAQUE
8066 || mAttrs.type == TYPE_WALLPAPER)
8067 && mSurface != null && mAnimation == null
8068 && (mAppToken == null || mAppToken.animation == null)
8069 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008070 }
8071
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008072 /**
8073 * Return whether this window is wanting to have a translation
8074 * animation applied to it for an in-progress move. (Only makes
8075 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8076 */
8077 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008078 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008079 && (mFrame.top != mLastFrame.top
8080 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008081 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008082 && mPolicy.isScreenOn();
8083 }
8084
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008085 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8086 return
8087 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008088 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8089 // only if it's visible
8090 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008091 // and only if the application fills the compatible screen
8092 mFrame.left <= mCompatibleScreenFrame.left &&
8093 mFrame.top <= mCompatibleScreenFrame.top &&
8094 mFrame.right >= mCompatibleScreenFrame.right &&
8095 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008096 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008097 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008098 }
8099
8100 boolean isFullscreen(int screenWidth, int screenHeight) {
8101 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008102 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 }
8104
8105 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008106 disposeInputChannel();
8107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008108 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008109 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008110 mAttachedWindow.mChildWindows.remove(this);
8111 }
8112 destroySurfaceLocked();
8113 mSession.windowRemovedLocked();
8114 try {
8115 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8116 } catch (RuntimeException e) {
8117 // Ignore if it has already been removed (usually because
8118 // we are doing this as part of processing a death note.)
8119 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008120 }
8121
8122 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008123 if (mInputChannel != null) {
8124 mInputManager.unregisterInputChannel(mInputChannel);
8125
8126 mInputChannel.dispose();
8127 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008129 }
8130
8131 private class DeathRecipient implements IBinder.DeathRecipient {
8132 public void binderDied() {
8133 try {
8134 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008135 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008136 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 if (win != null) {
8138 removeWindowLocked(mSession, win);
8139 }
8140 }
8141 } catch (IllegalArgumentException ex) {
8142 // This will happen if the window has already been
8143 // removed.
8144 }
8145 }
8146 }
8147
8148 /** Returns true if this window desires key events. */
8149 public final boolean canReceiveKeys() {
8150 return isVisibleOrAdding()
8151 && (mViewVisibility == View.VISIBLE)
8152 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8153 }
8154
8155 public boolean hasDrawnLw() {
8156 return mHasDrawn;
8157 }
8158
8159 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008160 return showLw(doAnimation, true);
8161 }
8162
8163 boolean showLw(boolean doAnimation, boolean requestAnim) {
8164 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8165 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008166 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008167 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008168 if (doAnimation) {
8169 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8170 + mPolicyVisibility + " mAnimation=" + mAnimation);
8171 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8172 doAnimation = false;
8173 } else if (mPolicyVisibility && mAnimation == null) {
8174 // Check for the case where we are currently visible and
8175 // not animating; we do not want to do animation at such a
8176 // point to become visible when we already are.
8177 doAnimation = false;
8178 }
8179 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008180 mPolicyVisibility = true;
8181 mPolicyVisibilityAfterAnim = true;
8182 if (doAnimation) {
8183 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8184 }
8185 if (requestAnim) {
8186 requestAnimationLocked(0);
8187 }
8188 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 }
8190
8191 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008192 return hideLw(doAnimation, true);
8193 }
8194
8195 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008196 if (doAnimation) {
8197 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8198 doAnimation = false;
8199 }
8200 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008201 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8202 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008203 if (!current) {
8204 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008206 if (doAnimation) {
8207 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8208 if (mAnimation == null) {
8209 doAnimation = false;
8210 }
8211 }
8212 if (doAnimation) {
8213 mPolicyVisibilityAfterAnim = false;
8214 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008215 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008216 mPolicyVisibilityAfterAnim = false;
8217 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008218 // Window is no longer visible -- make sure if we were waiting
8219 // for it to be displayed before enabling the display, that
8220 // we allow the display to be enabled now.
8221 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008222 if (mCurrentFocus == this) {
8223 mFocusMayChange = true;
8224 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008225 }
8226 if (requestAnim) {
8227 requestAnimationLocked(0);
8228 }
8229 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008230 }
8231
Jeff Brownfbf09772011-01-16 14:06:57 -08008232 public void getTouchableRegion(Region outRegion) {
8233 final Rect frame = mFrame;
8234 switch (mTouchableInsets) {
8235 default:
8236 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8237 outRegion.set(frame);
8238 break;
8239 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8240 final Rect inset = mGivenContentInsets;
8241 outRegion.set(
8242 frame.left + inset.left, frame.top + inset.top,
8243 frame.right - inset.right, frame.bottom - inset.bottom);
8244 break;
8245 }
8246 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8247 final Rect inset = mGivenVisibleInsets;
8248 outRegion.set(
8249 frame.left + inset.left, frame.top + inset.top,
8250 frame.right - inset.right, frame.bottom - inset.bottom);
8251 break;
8252 }
8253 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8254 final Region givenTouchableRegion = mGivenTouchableRegion;
8255 outRegion.set(givenTouchableRegion);
8256 outRegion.translate(frame.left, frame.top);
8257 break;
8258 }
8259 }
8260 }
8261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008263 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8264 pw.print(" mClient="); pw.println(mClient.asBinder());
8265 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8266 if (mAttachedWindow != null || mLayoutAttached) {
8267 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8268 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8269 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008270 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8271 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8272 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008273 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8274 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008275 }
8276 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8277 pw.print(" mSubLayer="); pw.print(mSubLayer);
8278 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8279 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8280 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8281 pw.print("="); pw.print(mAnimLayer);
8282 pw.print(" mLastLayer="); pw.println(mLastLayer);
8283 if (mSurface != null) {
8284 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008285 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8286 pw.print(" layer="); pw.print(mSurfaceLayer);
8287 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8288 pw.print(" rect=("); pw.print(mSurfaceX);
8289 pw.print(","); pw.print(mSurfaceY);
8290 pw.print(") "); pw.print(mSurfaceW);
8291 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008292 }
8293 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8294 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8295 if (mAppToken != null) {
8296 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8297 }
8298 if (mTargetAppToken != null) {
8299 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8300 }
8301 pw.print(prefix); pw.print("mViewVisibility=0x");
8302 pw.print(Integer.toHexString(mViewVisibility));
8303 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008304 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8305 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008306 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8307 pw.print(prefix); pw.print("mPolicyVisibility=");
8308 pw.print(mPolicyVisibility);
8309 pw.print(" mPolicyVisibilityAfterAnim=");
8310 pw.print(mPolicyVisibilityAfterAnim);
8311 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8312 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008313 if (!mRelayoutCalled) {
8314 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8315 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008316 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008317 pw.print(" h="); pw.print(mRequestedHeight);
8318 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008319 if (mXOffset != 0 || mYOffset != 0) {
8320 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8321 pw.print(" y="); pw.println(mYOffset);
8322 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008323 pw.print(prefix); pw.print("mGivenContentInsets=");
8324 mGivenContentInsets.printShortString(pw);
8325 pw.print(" mGivenVisibleInsets=");
8326 mGivenVisibleInsets.printShortString(pw);
8327 pw.println();
8328 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8329 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8330 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8331 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008332 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008333 pw.print(prefix); pw.print("mShownFrame=");
8334 mShownFrame.printShortString(pw);
8335 pw.print(" last="); mLastShownFrame.printShortString(pw);
8336 pw.println();
8337 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8338 pw.print(" last="); mLastFrame.printShortString(pw);
8339 pw.println();
8340 pw.print(prefix); pw.print("mContainingFrame=");
8341 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008342 pw.print(" mParentFrame=");
8343 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008344 pw.print(" mDisplayFrame=");
8345 mDisplayFrame.printShortString(pw);
8346 pw.println();
8347 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8348 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8349 pw.println();
8350 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8351 pw.print(" last="); mLastContentInsets.printShortString(pw);
8352 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8353 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8354 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008355 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8356 || mAnimation != null) {
8357 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8358 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8359 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8360 pw.print(" mAnimation="); pw.println(mAnimation);
8361 }
8362 if (mHasTransformation || mHasLocalTransformation) {
8363 pw.print(prefix); pw.print("XForm: has=");
8364 pw.print(mHasTransformation);
8365 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8366 pw.print(" "); mTransformation.printShortString(pw);
8367 pw.println();
8368 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008369 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8370 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8371 pw.print(" mAlpha="); pw.print(mAlpha);
8372 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8373 }
8374 if (mHaveMatrix) {
8375 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8376 pw.print(" mDtDx="); pw.print(mDtDx);
8377 pw.print(" mDsDy="); pw.print(mDsDy);
8378 pw.print(" mDtDy="); pw.println(mDtDy);
8379 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008380 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8381 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8382 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8383 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8384 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8385 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8386 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8387 pw.print(" mDestroying="); pw.print(mDestroying);
8388 pw.print(" mRemoved="); pw.println(mRemoved);
8389 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008390 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008391 pw.print(prefix); pw.print("mOrientationChanging=");
8392 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008393 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8394 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008395 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008396 if (mHScale != 1 || mVScale != 1) {
8397 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8398 pw.print(" mVScale="); pw.println(mVScale);
8399 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008400 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008401 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8402 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8403 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008404 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8405 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8406 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008408 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008409
8410 String makeInputChannelName() {
8411 return Integer.toHexString(System.identityHashCode(this))
8412 + " " + mAttrs.getTitle();
8413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414
8415 @Override
8416 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008417 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8418 || mWasPaused != mToken.paused) {
8419 mLastTitle = mAttrs.getTitle();
8420 mWasPaused = mToken.paused;
8421 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8422 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8423 }
8424 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008425 }
8426 }
Romain Guy06882f82009-06-10 13:36:04 -07008427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428 // -------------------------------------------------------------
8429 // Window Token State
8430 // -------------------------------------------------------------
8431
8432 class WindowToken {
8433 // The actual token.
8434 final IBinder token;
8435
8436 // The type of window this token is for, as per WindowManager.LayoutParams.
8437 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008439 // Set if this token was explicitly added by a client, so should
8440 // not be removed when all windows are removed.
8441 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008442
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008443 // For printing.
8444 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008446 // If this is an AppWindowToken, this is non-null.
8447 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 // All of the windows associated with this token.
8450 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8451
8452 // Is key dispatching paused for this token?
8453 boolean paused = false;
8454
8455 // Should this token's windows be hidden?
8456 boolean hidden;
8457
8458 // Temporary for finding which tokens no longer have visible windows.
8459 boolean hasVisible;
8460
Dianne Hackborna8f60182009-09-01 19:01:50 -07008461 // Set to true when this token is in a pending transaction where it
8462 // will be shown.
8463 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008464
Dianne Hackborna8f60182009-09-01 19:01:50 -07008465 // Set to true when this token is in a pending transaction where it
8466 // will be hidden.
8467 boolean waitingToHide;
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 its
8470 // windows will be put to the bottom of the list.
8471 boolean sendingToBottom;
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 top of the list.
8475 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008477 WindowToken(IBinder _token, int type, boolean _explicit) {
8478 token = _token;
8479 windowType = type;
8480 explicit = _explicit;
8481 }
8482
8483 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008484 pw.print(prefix); pw.print("token="); pw.println(token);
8485 pw.print(prefix); pw.print("windows="); pw.println(windows);
8486 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8487 pw.print(" hidden="); pw.print(hidden);
8488 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008489 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8490 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8491 pw.print(" waitingToHide="); pw.print(waitingToHide);
8492 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8493 pw.print(" sendingToTop="); pw.println(sendingToTop);
8494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008495 }
8496
8497 @Override
8498 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008499 if (stringName == null) {
8500 StringBuilder sb = new StringBuilder();
8501 sb.append("WindowToken{");
8502 sb.append(Integer.toHexString(System.identityHashCode(this)));
8503 sb.append(" token="); sb.append(token); sb.append('}');
8504 stringName = sb.toString();
8505 }
8506 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008507 }
8508 };
8509
8510 class AppWindowToken extends WindowToken {
8511 // Non-null only for application tokens.
8512 final IApplicationToken appToken;
8513
8514 // All of the windows and child windows that are included in this
8515 // application token. Note this list is NOT sorted!
8516 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8517
8518 int groupId = -1;
8519 boolean appFullscreen;
8520 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008521
8522 // The input dispatching timeout for this application token in nanoseconds.
8523 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 // These are used for determining when all windows associated with
8526 // an activity have been drawn, so they can be made visible together
8527 // at the same time.
8528 int lastTransactionSequence = mTransactionSequence-1;
8529 int numInterestingWindows;
8530 int numDrawnWindows;
8531 boolean inPendingTransaction;
8532 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 // Is this token going to be hidden in a little while? If so, it
8535 // won't be taken into account for setting the screen orientation.
8536 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 // Is this window's surface needed? This is almost like hidden, except
8539 // it will sometimes be true a little earlier: when the token has
8540 // been shown, but is still waiting for its app transition to execute
8541 // before making its windows shown.
8542 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 // Have we told the window clients to hide themselves?
8545 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008547 // Last visibility state we reported to the app token.
8548 boolean reportedVisible;
8549
8550 // Set to true when the token has been removed from the window mgr.
8551 boolean removed;
8552
8553 // Have we been asked to have this token keep the screen frozen?
8554 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 boolean animating;
8557 Animation animation;
8558 boolean hasTransformation;
8559 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 // Offset to the window of all layers in the token, for use by
8562 // AppWindowToken animations.
8563 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008565 // Information about an application starting window if displayed.
8566 StartingData startingData;
8567 WindowState startingWindow;
8568 View startingView;
8569 boolean startingDisplayed;
8570 boolean startingMoved;
8571 boolean firstWindowDrawn;
8572
Jeff Brown928e0542011-01-10 11:17:36 -08008573 // Input application handle used by the input dispatcher.
8574 InputApplicationHandle mInputApplicationHandle;
8575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008576 AppWindowToken(IApplicationToken _token) {
8577 super(_token.asBinder(),
8578 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8579 appWindowToken = this;
8580 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008581 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008582 }
Romain Guy06882f82009-06-10 13:36:04 -07008583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008584 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008585 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 TAG, "Setting animation in " + this + ": " + anim);
8587 animation = anim;
8588 animating = false;
8589 anim.restrictDuration(MAX_ANIMATION_DURATION);
8590 anim.scaleCurrentDuration(mTransitionAnimationScale);
8591 int zorder = anim.getZAdjustment();
8592 int adj = 0;
8593 if (zorder == Animation.ZORDER_TOP) {
8594 adj = TYPE_LAYER_OFFSET;
8595 } else if (zorder == Animation.ZORDER_BOTTOM) {
8596 adj = -TYPE_LAYER_OFFSET;
8597 }
Romain Guy06882f82009-06-10 13:36:04 -07008598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 if (animLayerAdjustment != adj) {
8600 animLayerAdjustment = adj;
8601 updateLayers();
8602 }
8603 }
Romain Guy06882f82009-06-10 13:36:04 -07008604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008605 public void setDummyAnimation() {
8606 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008607 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008608 TAG, "Setting dummy animation in " + this);
8609 animation = sDummyAnimation;
8610 }
8611 }
8612
8613 public void clearAnimation() {
8614 if (animation != null) {
8615 animation = null;
8616 animating = true;
8617 }
8618 }
Romain Guy06882f82009-06-10 13:36:04 -07008619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 void updateLayers() {
8621 final int N = allAppWindows.size();
8622 final int adj = animLayerAdjustment;
8623 for (int i=0; i<N; i++) {
8624 WindowState w = allAppWindows.get(i);
8625 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008626 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008628 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629 setInputMethodAnimLayerAdjustment(adj);
8630 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008631 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008632 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008633 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008634 }
8635 }
Romain Guy06882f82009-06-10 13:36:04 -07008636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 void sendAppVisibilityToClients() {
8638 final int N = allAppWindows.size();
8639 for (int i=0; i<N; i++) {
8640 WindowState win = allAppWindows.get(i);
8641 if (win == startingWindow && clientHidden) {
8642 // Don't hide the starting window.
8643 continue;
8644 }
8645 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008646 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008647 "Setting visibility of " + win + ": " + (!clientHidden));
8648 win.mClient.dispatchAppVisibility(!clientHidden);
8649 } catch (RemoteException e) {
8650 }
8651 }
8652 }
Romain Guy06882f82009-06-10 13:36:04 -07008653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008654 void showAllWindowsLocked() {
8655 final int NW = allAppWindows.size();
8656 for (int i=0; i<NW; i++) {
8657 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008658 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 "performing show on: " + w);
8660 w.performShowLocked();
8661 }
8662 }
Romain Guy06882f82009-06-10 13:36:04 -07008663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664 // This must be called while inside a transaction.
8665 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008666 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008667 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008669 if (animation == sDummyAnimation) {
8670 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008671 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008672 // when it is really time to animate, this will be set to
8673 // a real animation and the next call will execute normally.
8674 return false;
8675 }
Romain Guy06882f82009-06-10 13:36:04 -07008676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008677 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8678 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008679 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 TAG, "Starting animation in " + this +
8681 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8682 + " scale=" + mTransitionAnimationScale
8683 + " allDrawn=" + allDrawn + " animating=" + animating);
8684 animation.initialize(dw, dh, dw, dh);
8685 animation.setStartTime(currentTime);
8686 animating = true;
8687 }
8688 transformation.clear();
8689 final boolean more = animation.getTransformation(
8690 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008691 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008692 TAG, "Stepped animation in " + this +
8693 ": more=" + more + ", xform=" + transformation);
8694 if (more) {
8695 // we're done!
8696 hasTransformation = true;
8697 return true;
8698 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008699 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008700 TAG, "Finished animation in " + this +
8701 " @ " + currentTime);
8702 animation = null;
8703 }
8704 } else if (animation != null) {
8705 // If the display is frozen, and there is a pending animation,
8706 // clear it and make sure we run the cleanup code.
8707 animating = true;
8708 animation = null;
8709 }
8710
8711 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713 if (!animating) {
8714 return false;
8715 }
8716
8717 clearAnimation();
8718 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008719 if (animLayerAdjustment != 0) {
8720 animLayerAdjustment = 0;
8721 updateLayers();
8722 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008723 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8724 moveInputMethodWindowsIfNeededLocked(true);
8725 }
Romain Guy06882f82009-06-10 13:36:04 -07008726
Joe Onorato8a9b2202010-02-26 18:56:32 -08008727 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 TAG, "Animation done in " + this
8729 + ": reportedVisible=" + reportedVisible);
8730
8731 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008733 final int N = windows.size();
8734 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008735 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008736 }
8737 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008739 return false;
8740 }
8741
8742 void updateReportedVisibilityLocked() {
8743 if (appToken == null) {
8744 return;
8745 }
Romain Guy06882f82009-06-10 13:36:04 -07008746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008747 int numInteresting = 0;
8748 int numVisible = 0;
8749 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008750
Joe Onorato8a9b2202010-02-26 18:56:32 -08008751 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008752 final int N = allAppWindows.size();
8753 for (int i=0; i<N; i++) {
8754 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008755 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008756 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008757 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8758 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008759 continue;
8760 }
8761 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008762 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008763 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008764 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008765 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008766 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008767 + " pv=" + win.mPolicyVisibility
8768 + " dp=" + win.mDrawPending
8769 + " cdp=" + win.mCommitDrawPending
8770 + " ah=" + win.mAttachedHidden
8771 + " th="
8772 + (win.mAppToken != null
8773 ? win.mAppToken.hiddenRequested : false)
8774 + " a=" + win.mAnimating);
8775 }
8776 }
8777 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008778 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008779 if (!win.isAnimating()) {
8780 numVisible++;
8781 }
8782 nowGone = false;
8783 } else if (win.isAnimating()) {
8784 nowGone = false;
8785 }
8786 }
Romain Guy06882f82009-06-10 13:36:04 -07008787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008788 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008789 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008790 + numInteresting + " visible=" + numVisible);
8791 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008792 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 TAG, "Visibility changed in " + this
8794 + ": vis=" + nowVisible);
8795 reportedVisible = nowVisible;
8796 Message m = mH.obtainMessage(
8797 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8798 nowVisible ? 1 : 0,
8799 nowGone ? 1 : 0,
8800 this);
8801 mH.sendMessage(m);
8802 }
8803 }
Romain Guy06882f82009-06-10 13:36:04 -07008804
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008805 WindowState findMainWindow() {
8806 int j = windows.size();
8807 while (j > 0) {
8808 j--;
8809 WindowState win = windows.get(j);
8810 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8811 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8812 return win;
8813 }
8814 }
8815 return null;
8816 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008818 void dump(PrintWriter pw, String prefix) {
8819 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008820 if (appToken != null) {
8821 pw.print(prefix); pw.println("app=true");
8822 }
8823 if (allAppWindows.size() > 0) {
8824 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8825 }
8826 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008827 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008828 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8829 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8830 pw.print(" clientHidden="); pw.print(clientHidden);
8831 pw.print(" willBeHidden="); pw.print(willBeHidden);
8832 pw.print(" reportedVisible="); pw.println(reportedVisible);
8833 if (paused || freezingScreen) {
8834 pw.print(prefix); pw.print("paused="); pw.print(paused);
8835 pw.print(" freezingScreen="); pw.println(freezingScreen);
8836 }
8837 if (numInterestingWindows != 0 || numDrawnWindows != 0
8838 || inPendingTransaction || allDrawn) {
8839 pw.print(prefix); pw.print("numInterestingWindows=");
8840 pw.print(numInterestingWindows);
8841 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8842 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8843 pw.print(" allDrawn="); pw.println(allDrawn);
8844 }
8845 if (animating || animation != null) {
8846 pw.print(prefix); pw.print("animating="); pw.print(animating);
8847 pw.print(" animation="); pw.println(animation);
8848 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008849 if (hasTransformation) {
8850 pw.print(prefix); pw.print("XForm: ");
8851 transformation.printShortString(pw);
8852 pw.println();
8853 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008854 if (animLayerAdjustment != 0) {
8855 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8856 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008857 if (startingData != null || removed || firstWindowDrawn) {
8858 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8859 pw.print(" removed="); pw.print(removed);
8860 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8861 }
8862 if (startingWindow != null || startingView != null
8863 || startingDisplayed || startingMoved) {
8864 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8865 pw.print(" startingView="); pw.print(startingView);
8866 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8867 pw.print(" startingMoved"); pw.println(startingMoved);
8868 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008869 }
8870
8871 @Override
8872 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008873 if (stringName == null) {
8874 StringBuilder sb = new StringBuilder();
8875 sb.append("AppWindowToken{");
8876 sb.append(Integer.toHexString(System.identityHashCode(this)));
8877 sb.append(" token="); sb.append(token); sb.append('}');
8878 stringName = sb.toString();
8879 }
8880 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008881 }
8882 }
Romain Guy06882f82009-06-10 13:36:04 -07008883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008884 // -------------------------------------------------------------
8885 // DummyAnimation
8886 // -------------------------------------------------------------
8887
8888 // This is an animation that does nothing: it just immediately finishes
8889 // itself every time it is called. It is used as a stub animation in cases
8890 // where we want to synchronize multiple things that may be animating.
8891 static final class DummyAnimation extends Animation {
8892 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8893 return false;
8894 }
8895 }
8896 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 // -------------------------------------------------------------
8899 // Async Handler
8900 // -------------------------------------------------------------
8901
8902 static final class StartingData {
8903 final String pkg;
8904 final int theme;
8905 final CharSequence nonLocalizedLabel;
8906 final int labelRes;
8907 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008908 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008911 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008912 pkg = _pkg;
8913 theme = _theme;
8914 nonLocalizedLabel = _nonLocalizedLabel;
8915 labelRes = _labelRes;
8916 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008917 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008918 }
8919 }
8920
8921 private final class H extends Handler {
8922 public static final int REPORT_FOCUS_CHANGE = 2;
8923 public static final int REPORT_LOSING_FOCUS = 3;
8924 public static final int ANIMATE = 4;
8925 public static final int ADD_STARTING = 5;
8926 public static final int REMOVE_STARTING = 6;
8927 public static final int FINISHED_STARTING = 7;
8928 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008929 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8930 public static final int HOLD_SCREEN_CHANGED = 12;
8931 public static final int APP_TRANSITION_TIMEOUT = 13;
8932 public static final int PERSIST_ANIMATION_SCALE = 14;
8933 public static final int FORCE_GC = 15;
8934 public static final int ENABLE_SCREEN = 16;
8935 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008936 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008937 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008938 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008939 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08008940 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07008941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008942 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008944 public H() {
8945 }
Romain Guy06882f82009-06-10 13:36:04 -07008946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008947 @Override
8948 public void handleMessage(Message msg) {
8949 switch (msg.what) {
8950 case REPORT_FOCUS_CHANGE: {
8951 WindowState lastFocus;
8952 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 synchronized(mWindowMap) {
8955 lastFocus = mLastFocus;
8956 newFocus = mCurrentFocus;
8957 if (lastFocus == newFocus) {
8958 // Focus is not changing, so nothing to do.
8959 return;
8960 }
8961 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008962 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008963 // + " to " + newFocus);
8964 if (newFocus != null && lastFocus != null
8965 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008966 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 mLosingFocus.add(lastFocus);
8968 lastFocus = null;
8969 }
8970 }
8971
8972 if (lastFocus != newFocus) {
8973 //System.out.println("Changing focus from " + lastFocus
8974 // + " to " + newFocus);
8975 if (newFocus != null) {
8976 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008977 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008978 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8979 } catch (RemoteException e) {
8980 // Ignore if process has died.
8981 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008982 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008983 }
8984
8985 if (lastFocus != null) {
8986 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008987 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008988 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8989 } catch (RemoteException e) {
8990 // Ignore if process has died.
8991 }
8992 }
Joe Onorato664644d2011-01-23 17:53:23 -08008993
8994 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008995 }
8996 } break;
8997
8998 case REPORT_LOSING_FOCUS: {
8999 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07009000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009001 synchronized(mWindowMap) {
9002 losers = mLosingFocus;
9003 mLosingFocus = new ArrayList<WindowState>();
9004 }
9005
9006 final int N = losers.size();
9007 for (int i=0; i<N; i++) {
9008 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009009 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009010 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
9011 } catch (RemoteException e) {
9012 // Ignore if process has died.
9013 }
9014 }
9015 } break;
9016
9017 case ANIMATE: {
9018 synchronized(mWindowMap) {
9019 mAnimationPending = false;
9020 performLayoutAndPlaceSurfacesLocked();
9021 }
9022 } break;
9023
9024 case ADD_STARTING: {
9025 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9026 final StartingData sd = wtoken.startingData;
9027
9028 if (sd == null) {
9029 // Animation has been canceled... do nothing.
9030 return;
9031 }
Romain Guy06882f82009-06-10 13:36:04 -07009032
Joe Onorato8a9b2202010-02-26 18:56:32 -08009033 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009034 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07009035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009036 View view = null;
9037 try {
9038 view = mPolicy.addStartingWindow(
9039 wtoken.token, sd.pkg,
9040 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08009041 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009042 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009043 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009044 }
9045
9046 if (view != null) {
9047 boolean abort = false;
9048
9049 synchronized(mWindowMap) {
9050 if (wtoken.removed || wtoken.startingData == null) {
9051 // If the window was successfully added, then
9052 // we need to remove it.
9053 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009054 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009055 "Aborted starting " + wtoken
9056 + ": removed=" + wtoken.removed
9057 + " startingData=" + wtoken.startingData);
9058 wtoken.startingWindow = null;
9059 wtoken.startingData = null;
9060 abort = true;
9061 }
9062 } else {
9063 wtoken.startingView = view;
9064 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009065 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009066 "Added starting " + wtoken
9067 + ": startingWindow="
9068 + wtoken.startingWindow + " startingView="
9069 + wtoken.startingView);
9070 }
9071
9072 if (abort) {
9073 try {
9074 mPolicy.removeStartingWindow(wtoken.token, view);
9075 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009076 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009077 }
9078 }
9079 }
9080 } break;
9081
9082 case REMOVE_STARTING: {
9083 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9084 IBinder token = null;
9085 View view = null;
9086 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009087 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009088 + wtoken + ": startingWindow="
9089 + wtoken.startingWindow + " startingView="
9090 + wtoken.startingView);
9091 if (wtoken.startingWindow != null) {
9092 view = wtoken.startingView;
9093 token = wtoken.token;
9094 wtoken.startingData = null;
9095 wtoken.startingView = null;
9096 wtoken.startingWindow = null;
9097 }
9098 }
9099 if (view != null) {
9100 try {
9101 mPolicy.removeStartingWindow(token, view);
9102 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009103 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009104 }
9105 }
9106 } break;
9107
9108 case FINISHED_STARTING: {
9109 IBinder token = null;
9110 View view = null;
9111 while (true) {
9112 synchronized (mWindowMap) {
9113 final int N = mFinishedStarting.size();
9114 if (N <= 0) {
9115 break;
9116 }
9117 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9118
Joe Onorato8a9b2202010-02-26 18:56:32 -08009119 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009120 "Finished starting " + wtoken
9121 + ": startingWindow=" + wtoken.startingWindow
9122 + " startingView=" + wtoken.startingView);
9123
9124 if (wtoken.startingWindow == null) {
9125 continue;
9126 }
9127
9128 view = wtoken.startingView;
9129 token = wtoken.token;
9130 wtoken.startingData = null;
9131 wtoken.startingView = null;
9132 wtoken.startingWindow = null;
9133 }
9134
9135 try {
9136 mPolicy.removeStartingWindow(token, view);
9137 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009138 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009139 }
9140 }
9141 } break;
9142
9143 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9144 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9145
9146 boolean nowVisible = msg.arg1 != 0;
9147 boolean nowGone = msg.arg2 != 0;
9148
9149 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009150 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009151 TAG, "Reporting visible in " + wtoken
9152 + " visible=" + nowVisible
9153 + " gone=" + nowGone);
9154 if (nowVisible) {
9155 wtoken.appToken.windowsVisible();
9156 } else {
9157 wtoken.appToken.windowsGone();
9158 }
9159 } catch (RemoteException ex) {
9160 }
9161 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009163 case WINDOW_FREEZE_TIMEOUT: {
9164 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009165 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009166 int i = mWindows.size();
9167 while (i > 0) {
9168 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009169 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009170 if (w.mOrientationChanging) {
9171 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009172 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009173 }
9174 }
9175 performLayoutAndPlaceSurfacesLocked();
9176 }
9177 break;
9178 }
Romain Guy06882f82009-06-10 13:36:04 -07009179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009180 case HOLD_SCREEN_CHANGED: {
9181 Session oldHold;
9182 Session newHold;
9183 synchronized (mWindowMap) {
9184 oldHold = mLastReportedHold;
9185 newHold = (Session)msg.obj;
9186 mLastReportedHold = newHold;
9187 }
Romain Guy06882f82009-06-10 13:36:04 -07009188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009189 if (oldHold != newHold) {
9190 try {
9191 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009192 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009193 "window",
9194 BatteryStats.WAKE_TYPE_WINDOW);
9195 }
9196 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009197 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009198 "window",
9199 BatteryStats.WAKE_TYPE_WINDOW);
9200 }
9201 } catch (RemoteException e) {
9202 }
9203 }
9204 break;
9205 }
Romain Guy06882f82009-06-10 13:36:04 -07009206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009207 case APP_TRANSITION_TIMEOUT: {
9208 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009209 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009210 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 "*** APP TRANSITION TIMEOUT");
9212 mAppTransitionReady = true;
9213 mAppTransitionTimeout = true;
9214 performLayoutAndPlaceSurfacesLocked();
9215 }
9216 }
9217 break;
9218 }
Romain Guy06882f82009-06-10 13:36:04 -07009219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009220 case PERSIST_ANIMATION_SCALE: {
9221 Settings.System.putFloat(mContext.getContentResolver(),
9222 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9223 Settings.System.putFloat(mContext.getContentResolver(),
9224 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9225 break;
9226 }
Romain Guy06882f82009-06-10 13:36:04 -07009227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009228 case FORCE_GC: {
9229 synchronized(mWindowMap) {
9230 if (mAnimationPending) {
9231 // If we are animating, don't do the gc now but
9232 // delay a bit so we don't interrupt the animation.
9233 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9234 2000);
9235 return;
9236 }
9237 // If we are currently rotating the display, it will
9238 // schedule a new message when done.
9239 if (mDisplayFrozen) {
9240 return;
9241 }
9242 mFreezeGcPending = 0;
9243 }
9244 Runtime.getRuntime().gc();
9245 break;
9246 }
Romain Guy06882f82009-06-10 13:36:04 -07009247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248 case ENABLE_SCREEN: {
9249 performEnableScreen();
9250 break;
9251 }
Romain Guy06882f82009-06-10 13:36:04 -07009252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 case APP_FREEZE_TIMEOUT: {
9254 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009255 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009256 int i = mAppTokens.size();
9257 while (i > 0) {
9258 i--;
9259 AppWindowToken tok = mAppTokens.get(i);
9260 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009261 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 unsetAppFreezingScreenLocked(tok, true, true);
9263 }
9264 }
9265 }
9266 break;
9267 }
Romain Guy06882f82009-06-10 13:36:04 -07009268
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009269 case SEND_NEW_CONFIGURATION: {
9270 removeMessages(SEND_NEW_CONFIGURATION);
9271 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009272 break;
9273 }
Romain Guy06882f82009-06-10 13:36:04 -07009274
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009275 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009276 if (mWindowsChanged) {
9277 synchronized (mWindowMap) {
9278 mWindowsChanged = false;
9279 }
9280 notifyWindowsChanged();
9281 }
9282 break;
9283 }
9284
Christopher Tatea53146c2010-09-07 11:57:52 -07009285 case DRAG_START_TIMEOUT: {
9286 IBinder win = (IBinder)msg.obj;
9287 if (DEBUG_DRAG) {
9288 Slog.w(TAG, "Timeout starting drag by win " + win);
9289 }
9290 synchronized (mWindowMap) {
9291 // !!! TODO: ANR the app that has failed to start the drag in time
9292 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009293 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009294 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009295 mDragState.reset();
9296 mDragState = null;
9297 }
9298 }
Chris Tated4533f142010-10-19 15:15:08 -07009299 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009300 }
9301
Chris Tated4533f142010-10-19 15:15:08 -07009302 case DRAG_END_TIMEOUT: {
9303 IBinder win = (IBinder)msg.obj;
9304 if (DEBUG_DRAG) {
9305 Slog.w(TAG, "Timeout ending drag to win " + win);
9306 }
9307 synchronized (mWindowMap) {
9308 // !!! TODO: ANR the drag-receiving app
9309 mDragState.mDragResult = false;
9310 mDragState.endDragLw();
9311 }
9312 break;
9313 }
Jeff Brown2992ea72011-01-28 22:04:14 -08009314
9315 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
9316 notifyHardKeyboardStatusChange();
9317 break;
9318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009319 }
9320 }
9321 }
9322
9323 // -------------------------------------------------------------
9324 // IWindowManager API
9325 // -------------------------------------------------------------
9326
9327 public IWindowSession openSession(IInputMethodClient client,
9328 IInputContext inputContext) {
9329 if (client == null) throw new IllegalArgumentException("null client");
9330 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009331 Session session = new Session(client, inputContext);
9332 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 }
9334
9335 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9336 synchronized (mWindowMap) {
9337 // The focus for the client is the window immediately below
9338 // where we would place the input method window.
9339 int idx = findDesiredInputMethodWindowIndexLocked(false);
9340 WindowState imFocus;
9341 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009342 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009343 //Log.i(TAG, "Desired input method target: " + imFocus);
9344 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9345 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009346 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009347 // This may be a starting window, in which case we still want
9348 // to count it as okay.
9349 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9350 && imFocus.mAppToken != null) {
9351 // The client has definitely started, so it really should
9352 // have a window in this app token. Let's look for it.
9353 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9354 WindowState w = imFocus.mAppToken.windows.get(i);
9355 if (w != imFocus) {
9356 //Log.i(TAG, "Switching to real app window: " + w);
9357 imFocus = w;
9358 break;
9359 }
9360 }
9361 }
9362 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9363 //if (imFocus.mSession.mClient != null) {
9364 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9365 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9366 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009367 if (imFocus.mSession.mClient != null &&
9368 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9369 return true;
9370 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009371
9372 // Okay, how about this... what is the current focus?
9373 // It seems in some cases we may not have moved the IM
9374 // target window, such as when it was in a pop-up window,
9375 // so let's also look at the current focus. (An example:
9376 // go to Gmail, start searching so the keyboard goes up,
9377 // press home. Sometimes the IME won't go down.)
9378 // Would be nice to fix this more correctly, but it's
9379 // way at the end of a release, and this should be good enough.
9380 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9381 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9382 return true;
9383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 }
9385 }
9386 }
9387 return false;
9388 }
Romain Guy06882f82009-06-10 13:36:04 -07009389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009390 // -------------------------------------------------------------
9391 // Internals
9392 // -------------------------------------------------------------
9393
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009394 final WindowState windowForClientLocked(Session session, IWindow client,
9395 boolean throwOnError) {
9396 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009397 }
Romain Guy06882f82009-06-10 13:36:04 -07009398
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009399 final WindowState windowForClientLocked(Session session, IBinder client,
9400 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009401 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009402 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 TAG, "Looking up client " + client + ": " + win);
9404 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009405 RuntimeException ex = new IllegalArgumentException(
9406 "Requested window " + client + " does not exist");
9407 if (throwOnError) {
9408 throw ex;
9409 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009410 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 return null;
9412 }
9413 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009414 RuntimeException ex = new IllegalArgumentException(
9415 "Requested window " + client + " is in session " +
9416 win.mSession + ", not " + session);
9417 if (throwOnError) {
9418 throw ex;
9419 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009420 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009421 return null;
9422 }
9423
9424 return win;
9425 }
9426
Dianne Hackborna8f60182009-09-01 19:01:50 -07009427 final void rebuildAppWindowListLocked() {
9428 int NW = mWindows.size();
9429 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009430 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009431 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009432
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009433 if (mRebuildTmp.length < NW) {
9434 mRebuildTmp = new WindowState[NW+10];
9435 }
9436
Dianne Hackborna8f60182009-09-01 19:01:50 -07009437 // First remove all existing app windows.
9438 i=0;
9439 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009440 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009441 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009442 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009443 win.mRebuilding = true;
9444 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009445 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009446 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009447 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009448 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009449 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009450 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009451 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9452 && lastWallpaper == i-1) {
9453 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009454 }
9455 i++;
9456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009457
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009458 // The wallpaper window(s) typically live at the bottom of the stack,
9459 // so skip them before adding app tokens.
9460 lastWallpaper++;
9461 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009462
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009463 // First add all of the exiting app tokens... these are no longer
9464 // in the main app list, but still have windows shown. We put them
9465 // in the back because now that the animation is over we no longer
9466 // will care about them.
9467 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009468 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009469 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009471
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009472 // And add in the still active app tokens in Z order.
9473 NT = mAppTokens.size();
9474 for (int j=0; j<NT; j++) {
9475 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009476 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009477
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009478 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009479 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009480 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009481 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009482 for (i=0; i<numRemoved; i++) {
9483 WindowState ws = mRebuildTmp[i];
9484 if (ws.mRebuilding) {
9485 StringWriter sw = new StringWriter();
9486 PrintWriter pw = new PrintWriter(sw);
9487 ws.dump(pw, "");
9488 pw.flush();
9489 Slog.w(TAG, "This window was lost: " + ws);
9490 Slog.w(TAG, sw.toString());
9491 }
9492 }
9493 Slog.w(TAG, "Current app token list:");
9494 dumpAppTokensLocked();
9495 Slog.w(TAG, "Final window list:");
9496 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009497 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009498 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009500 private final void assignLayersLocked() {
9501 int N = mWindows.size();
9502 int curBaseLayer = 0;
9503 int curLayer = 0;
9504 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009505
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009506 if (DEBUG_LAYERS) {
9507 RuntimeException here = new RuntimeException("here");
9508 here.fillInStackTrace();
9509 Log.v(TAG, "Assigning layers", here);
9510 }
9511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009512 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009513 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009514 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9515 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 curLayer += WINDOW_LAYER_MULTIPLIER;
9517 w.mLayer = curLayer;
9518 } else {
9519 curBaseLayer = curLayer = w.mBaseLayer;
9520 w.mLayer = curLayer;
9521 }
9522 if (w.mTargetAppToken != null) {
9523 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9524 } else if (w.mAppToken != null) {
9525 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9526 } else {
9527 w.mAnimLayer = w.mLayer;
9528 }
9529 if (w.mIsImWindow) {
9530 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009531 } else if (w.mIsWallpaper) {
9532 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009533 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009534 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009535 + w.mAnimLayer);
9536 //System.out.println(
9537 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9538 }
9539 }
9540
9541 private boolean mInLayout = false;
9542 private final void performLayoutAndPlaceSurfacesLocked() {
9543 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009544 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 throw new RuntimeException("Recursive call!");
9546 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009547 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 return;
9549 }
9550
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009551 if (mWaitingForConfig) {
9552 // Our configuration has changed (most likely rotation), but we
9553 // don't yet have the complete configuration to report to
9554 // applications. Don't do any window layout until we have it.
9555 return;
9556 }
9557
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009558 if (mDisplay == null) {
9559 // Not yet initialized, nothing to do.
9560 return;
9561 }
9562
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009563 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009564 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009565
9566 try {
9567 if (mForceRemoves != null) {
9568 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009569 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009570 for (int i=0; i<mForceRemoves.size(); i++) {
9571 WindowState ws = mForceRemoves.get(i);
9572 Slog.i(TAG, "Force removing: " + ws);
9573 removeWindowInnerLocked(ws.mSession, ws);
9574 }
9575 mForceRemoves = null;
9576 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9577 Object tmp = new Object();
9578 synchronized (tmp) {
9579 try {
9580 tmp.wait(250);
9581 } catch (InterruptedException e) {
9582 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009583 }
9584 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009585 } catch (RuntimeException e) {
9586 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009587 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 try {
9590 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009591
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009592 int N = mPendingRemove.size();
9593 if (N > 0) {
9594 if (mPendingRemoveTmp.length < N) {
9595 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009597 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009598 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009599 for (int i=0; i<N; i++) {
9600 WindowState w = mPendingRemoveTmp[i];
9601 removeWindowInnerLocked(w.mSession, w);
9602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603
9604 mInLayout = false;
9605 assignLayersLocked();
9606 mLayoutNeeded = true;
9607 performLayoutAndPlaceSurfacesLocked();
9608
9609 } else {
9610 mInLayout = false;
9611 if (mLayoutNeeded) {
9612 requestAnimationLocked(0);
9613 }
9614 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009615 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009616 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9617 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009618 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009619 } catch (RuntimeException e) {
9620 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009621 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009622 }
9623 }
9624
Jeff Brown3a22cd92011-01-21 13:59:04 -08009625 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009626 if (!mLayoutNeeded) {
9627 return 0;
9628 }
9629
9630 mLayoutNeeded = false;
9631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009632 final int dw = mDisplay.getWidth();
9633 final int dh = mDisplay.getHeight();
9634
9635 final int N = mWindows.size();
9636 int i;
9637
Joe Onorato8a9b2202010-02-26 18:56:32 -08009638 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009639 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9640
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009641 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009642
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009643 int seq = mLayoutSeq+1;
9644 if (seq < 0) seq = 0;
9645 mLayoutSeq = seq;
9646
9647 // First perform layout of any root windows (not attached
9648 // to another window).
9649 int topAttached = -1;
9650 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009651 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009652
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009653 // Don't do layout of a window if it is not visible, or
9654 // soon won't be visible, to avoid wasting time and funky
9655 // changes while a window is animating away.
9656 final AppWindowToken atoken = win.mAppToken;
9657 final boolean gone = win.mViewVisibility == View.GONE
9658 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009659 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009660 || (atoken != null && atoken.hiddenRequested)
9661 || win.mAttachedHidden
9662 || win.mExiting || win.mDestroying;
9663
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009664 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9665 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009666 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9667 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009668 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009669 + win.mViewVisibility + " mRelayoutCalled="
9670 + win.mRelayoutCalled + " hidden="
9671 + win.mRootToken.hidden + " hiddenRequested="
9672 + (atoken != null && atoken.hiddenRequested)
9673 + " mAttachedHidden=" + win.mAttachedHidden);
9674 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009675
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009676 // If this view is GONE, then skip it -- keep the current
9677 // frame, and let the caller know so they can ignore it
9678 // if they want. (We do the normal layout for INVISIBLE
9679 // windows, since that means "perform layout as normal,
9680 // just don't display").
9681 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009682 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009683 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009684 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009685 win.mContentChanged = false;
9686 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009687 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9688 win.mLayoutSeq = seq;
9689 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9690 + win.mFrame + " mContainingFrame="
9691 + win.mContainingFrame + " mDisplayFrame="
9692 + win.mDisplayFrame);
9693 } else {
9694 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009695 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009696 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009697 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009698
9699 // Now perform layout of attached windows, which usually
9700 // depend on the position of the window they are attached to.
9701 // XXX does not deal with windows that are attached to windows
9702 // that are themselves attached.
9703 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009704 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009705
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009706 if (win.mLayoutAttached) {
9707 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9708 + " mHaveFrame=" + win.mHaveFrame
9709 + " mViewVisibility=" + win.mViewVisibility
9710 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009711 // If this view is GONE, then skip it -- keep the current
9712 // frame, and let the caller know so they can ignore it
9713 // if they want. (We do the normal layout for INVISIBLE
9714 // windows, since that means "perform layout as normal,
9715 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009716 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9717 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009718 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009719 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009720 win.mContentChanged = false;
9721 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009722 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9723 win.mLayoutSeq = seq;
9724 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9725 + win.mFrame + " mContainingFrame="
9726 + win.mContainingFrame + " mDisplayFrame="
9727 + win.mDisplayFrame);
9728 }
9729 }
9730 }
Jeff Brown349703e2010-06-22 01:27:15 -07009731
9732 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009733 mInputMonitor.setUpdateInputWindowsNeededLw();
9734 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009735 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009736 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009737
9738 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739 }
Romain Guy06882f82009-06-10 13:36:04 -07009740
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009741 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742 private final void performLayoutAndPlaceSurfacesLockedInner(
9743 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009744 if (mDisplay == null) {
9745 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9746 return;
9747 }
9748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009749 final long currentTime = SystemClock.uptimeMillis();
9750 final int dw = mDisplay.getWidth();
9751 final int dh = mDisplay.getHeight();
9752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 int i;
9754
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009755 if (mFocusMayChange) {
9756 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009757 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9758 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009759 }
9760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009761 // Initialize state of exiting tokens.
9762 for (i=mExitingTokens.size()-1; i>=0; i--) {
9763 mExitingTokens.get(i).hasVisible = false;
9764 }
9765
9766 // Initialize state of exiting applications.
9767 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9768 mExitingAppTokens.get(i).hasVisible = false;
9769 }
9770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009771 boolean orientationChangeComplete = true;
9772 Session holdScreen = null;
9773 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009774 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 boolean focusDisplayed = false;
9776 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009777 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009778 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009779
9780 if (mFxSession == null) {
9781 mFxSession = new SurfaceSession();
9782 createWatermark = true;
9783 }
9784
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009785 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009786
9787 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009788
9789 if (createWatermark) {
9790 createWatermark();
9791 }
9792 if (mWatermark != null) {
9793 mWatermark.positionSurface(dw, dh);
9794 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009795 if (mStrictModeFlash != null) {
9796 mStrictModeFlash.positionSurface(dw, dh);
9797 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009799 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009800 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009801 int repeats = 0;
9802 int changes = 0;
9803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009805 repeats++;
9806 if (repeats > 6) {
9807 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9808 mLayoutNeeded = false;
9809 break;
9810 }
9811
9812 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9813 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9814 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9815 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9816 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9817 assignLayersLocked();
9818 mLayoutNeeded = true;
9819 }
9820 }
9821 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9822 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009823 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009824 mLayoutNeeded = true;
9825 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9826 }
9827 }
9828 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9829 mLayoutNeeded = true;
9830 }
9831 }
9832
9833 // FIRST LOOP: Perform a layout, if needed.
9834 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009835 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009836 if (changes != 0) {
9837 continue;
9838 }
9839 } else {
9840 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9841 changes = 0;
9842 }
9843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009844 final int transactionSequence = ++mTransactionSequence;
9845
9846 // Update animations of all applications, including those
9847 // associated with exiting/removed apps
9848 boolean tokensAnimating = false;
9849 final int NAT = mAppTokens.size();
9850 for (i=0; i<NAT; i++) {
9851 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9852 tokensAnimating = true;
9853 }
9854 }
9855 final int NEAT = mExitingAppTokens.size();
9856 for (i=0; i<NEAT; i++) {
9857 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9858 tokensAnimating = true;
9859 }
9860 }
9861
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009862 // SECOND LOOP: Execute animations and update visibility of windows.
9863
Joe Onorato8a9b2202010-02-26 18:56:32 -08009864 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009865 + transactionSequence + " tokensAnimating="
9866 + tokensAnimating);
9867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009869
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009870 if (mScreenRotationAnimation != null) {
9871 if (mScreenRotationAnimation.isAnimating()) {
9872 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9873 animating = true;
9874 } else {
9875 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009876 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009877 }
9878 }
9879 }
9880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009881 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009882 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009883 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009884 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885
9886 mPolicy.beginAnimationLw(dw, dh);
9887
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009888 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009890 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009891 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892
9893 final WindowManager.LayoutParams attrs = w.mAttrs;
9894
9895 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009896 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009897 if (w.commitFinishDrawingLocked(currentTime)) {
9898 if ((w.mAttrs.flags
9899 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009900 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009901 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009902 wallpaperMayChange = true;
9903 }
9904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009905
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009906 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009907
9908 int animDw = dw;
9909 int animDh = dh;
9910
9911 // If the window has moved due to its containing
9912 // content frame changing, then we'd like to animate
9913 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009914 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009915 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009916 // Frame has moved, containing content frame
9917 // has also moved, and we're not currently animating...
9918 // let's do something.
9919 Animation a = AnimationUtils.loadAnimation(mContext,
9920 com.android.internal.R.anim.window_move_from_decor);
9921 w.setAnimation(a);
9922 animDw = w.mLastFrame.left - w.mFrame.left;
9923 animDh = w.mLastFrame.top - w.mFrame.top;
9924 }
9925
9926 // Execute animation.
9927 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9928 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009929
9930 // If this window is animating, make a note that we have
9931 // an animating window and take care of a request to run
9932 // a detached wallpaper animation.
9933 if (nowAnimating) {
9934 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9935 windowDetachedWallpaper = w;
9936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009938 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009939
9940 // If this window's app token is running a detached wallpaper
9941 // animation, make a note so we can ensure the wallpaper is
9942 // displayed behind it.
9943 if (w.mAppToken != null && w.mAppToken.animation != null
9944 && w.mAppToken.animation.getDetachWallpaper()) {
9945 windowDetachedWallpaper = w;
9946 }
9947
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009948 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9949 wallpaperMayChange = true;
9950 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009951
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009952 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009953 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009954 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009955 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009956 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009957 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009958 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009959 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9960 forceHiding = true;
9961 }
9962 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9963 boolean changed;
9964 if (forceHiding) {
9965 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009966 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9967 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009968 } else {
9969 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009970 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9971 "Now policy shown: " + w);
9972 if (changed) {
9973 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009974 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009975 // Assume we will need to animate. If
9976 // we don't (because the wallpaper will
9977 // stay with the lock screen), then we will
9978 // clean up later.
9979 Animation a = mPolicy.createForceHideEnterAnimation();
9980 if (a != null) {
9981 w.setAnimation(a);
9982 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009983 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009984 if (mCurrentFocus == null ||
9985 mCurrentFocus.mLayer < w.mLayer) {
9986 // We are showing on to of the current
9987 // focus, so re-evaluate focus to make
9988 // sure it is correct.
9989 mFocusMayChange = true;
9990 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009991 }
9992 }
9993 if (changed && (attrs.flags
9994 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9995 wallpaperMayChange = true;
9996 }
9997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009999 mPolicy.animatingWindowLw(w, attrs);
10000 }
10001
10002 final AppWindowToken atoken = w.mAppToken;
10003 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
10004 if (atoken.lastTransactionSequence != transactionSequence) {
10005 atoken.lastTransactionSequence = transactionSequence;
10006 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
10007 atoken.startingDisplayed = false;
10008 }
10009 if ((w.isOnScreen() || w.mAttrs.type
10010 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
10011 && !w.mExiting && !w.mDestroying) {
10012 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010013 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010014 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010015 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010016 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010017 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 + " pv=" + w.mPolicyVisibility
10019 + " dp=" + w.mDrawPending
10020 + " cdp=" + w.mCommitDrawPending
10021 + " ah=" + w.mAttachedHidden
10022 + " th=" + atoken.hiddenRequested
10023 + " a=" + w.mAnimating);
10024 }
10025 }
10026 if (w != atoken.startingWindow) {
10027 if (!atoken.freezingScreen || !w.mAppFreezing) {
10028 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010029 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010031 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010032 "tokenMayBeDrawn: " + atoken
10033 + " freezingScreen=" + atoken.freezingScreen
10034 + " mAppFreezing=" + w.mAppFreezing);
10035 tokenMayBeDrawn = true;
10036 }
10037 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010038 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010039 atoken.startingDisplayed = true;
10040 }
10041 }
10042 } else if (w.mReadyToShow) {
10043 w.performShowLocked();
10044 }
10045 }
10046
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010047 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010048
10049 if (tokenMayBeDrawn) {
10050 // See if any windows have been drawn, so they (and others
10051 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010052 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010053 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010054 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010055 if (wtoken.freezingScreen) {
10056 int numInteresting = wtoken.numInterestingWindows;
10057 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010058 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010059 "allDrawn: " + wtoken
10060 + " interesting=" + numInteresting
10061 + " drawn=" + wtoken.numDrawnWindows);
10062 wtoken.showAllWindowsLocked();
10063 unsetAppFreezingScreenLocked(wtoken, false, true);
10064 orientationChangeComplete = true;
10065 }
10066 } else if (!wtoken.allDrawn) {
10067 int numInteresting = wtoken.numInterestingWindows;
10068 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010069 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010070 "allDrawn: " + wtoken
10071 + " interesting=" + numInteresting
10072 + " drawn=" + wtoken.numDrawnWindows);
10073 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010074 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075
10076 // We can now show all of the drawn windows!
10077 if (!mOpeningApps.contains(wtoken)) {
10078 wtoken.showAllWindowsLocked();
10079 }
10080 }
10081 }
10082 }
10083 }
10084
10085 // If we are ready to perform an app transition, check through
10086 // all of the app tokens to be shown and see if they are ready
10087 // to go.
10088 if (mAppTransitionReady) {
10089 int NN = mOpeningApps.size();
10090 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010091 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010092 "Checking " + NN + " opening apps (frozen="
10093 + mDisplayFrozen + " timeout="
10094 + mAppTransitionTimeout + ")...");
10095 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10096 // If the display isn't frozen, wait to do anything until
10097 // all of the apps are ready. Otherwise just go because
10098 // we'll unfreeze the display when everyone is ready.
10099 for (i=0; i<NN && goodToGo; i++) {
10100 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010101 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010102 "Check opening app" + wtoken + ": allDrawn="
10103 + wtoken.allDrawn + " startingDisplayed="
10104 + wtoken.startingDisplayed);
10105 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10106 && !wtoken.startingMoved) {
10107 goodToGo = false;
10108 }
10109 }
10110 }
10111 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010112 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010113 int transit = mNextAppTransition;
10114 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010115 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010116 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010117 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010119 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010120 mAppTransitionTimeout = false;
10121 mStartingIconInTransition = false;
10122 mSkipAppTransitionAnimation = false;
10123
10124 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10125
Dianne Hackborna8f60182009-09-01 19:01:50 -070010126 // If there are applications waiting to come to the
10127 // top of the stack, now is the time to move their windows.
10128 // (Note that we don't do apps going to the bottom
10129 // here -- we want to keep their windows in the old
10130 // Z-order until the animation completes.)
10131 if (mToTopApps.size() > 0) {
10132 NN = mAppTokens.size();
10133 for (i=0; i<NN; i++) {
10134 AppWindowToken wtoken = mAppTokens.get(i);
10135 if (wtoken.sendingToTop) {
10136 wtoken.sendingToTop = false;
10137 moveAppWindowsLocked(wtoken, NN, false);
10138 }
10139 }
10140 mToTopApps.clear();
10141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010142
Dianne Hackborn25994b42009-09-04 14:21:19 -070010143 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010144
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010145 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010146 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010147
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010148 // The top-most window will supply the layout params,
10149 // and we will determine it below.
10150 LayoutParams animLp = null;
10151 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010152 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010153
Joe Onorato8a9b2202010-02-26 18:56:32 -080010154 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010155 "New wallpaper target=" + mWallpaperTarget
10156 + ", lower target=" + mLowerWallpaperTarget
10157 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010158 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010159 // Do a first pass through the tokens for two
10160 // things:
10161 // (1) Determine if both the closing and opening
10162 // app token sets are wallpaper targets, in which
10163 // case special animations are needed
10164 // (since the wallpaper needs to stay static
10165 // behind them).
10166 // (2) Find the layout params of the top-most
10167 // application window in the tokens, which is
10168 // what will control the animation theme.
10169 final int NC = mClosingApps.size();
10170 NN = NC + mOpeningApps.size();
10171 for (i=0; i<NN; i++) {
10172 AppWindowToken wtoken;
10173 int mode;
10174 if (i < NC) {
10175 wtoken = mClosingApps.get(i);
10176 mode = 1;
10177 } else {
10178 wtoken = mOpeningApps.get(i-NC);
10179 mode = 2;
10180 }
10181 if (mLowerWallpaperTarget != null) {
10182 if (mLowerWallpaperTarget.mAppToken == wtoken
10183 || mUpperWallpaperTarget.mAppToken == wtoken) {
10184 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010185 }
10186 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010187 if (wtoken.appFullscreen) {
10188 WindowState ws = wtoken.findMainWindow();
10189 if (ws != null) {
10190 // If this is a compatibility mode
10191 // window, we will always use its anim.
10192 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10193 animLp = ws.mAttrs;
10194 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010195 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010196 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010197 bestAnimLayer = ws.mLayer;
10198 }
10199 fullscreenAnim = true;
10200 }
10201 } else if (!fullscreenAnim) {
10202 WindowState ws = wtoken.findMainWindow();
10203 if (ws != null) {
10204 if (ws.mLayer > bestAnimLayer) {
10205 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010206 bestAnimLayer = ws.mLayer;
10207 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010208 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010209 }
10210 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010211
Dianne Hackborn25994b42009-09-04 14:21:19 -070010212 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010213 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010214 "Wallpaper animation!");
10215 switch (transit) {
10216 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10217 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10218 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10219 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10220 break;
10221 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10222 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10223 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10224 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10225 break;
10226 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010227 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010228 "New transit: " + transit);
10229 } else if (oldWallpaper != null) {
10230 // We are transitioning from an activity with
10231 // a wallpaper to one without.
10232 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010233 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010234 "New transit away from wallpaper: " + transit);
10235 } else if (mWallpaperTarget != null) {
10236 // We are transitioning from an activity without
10237 // a wallpaper to now showing the wallpaper
10238 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010239 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010240 "New transit into wallpaper: " + transit);
10241 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010242
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010243 // If all closing windows are obscured, then there is
10244 // no need to do an animation. This is the case, for
10245 // example, when this transition is being done behind
10246 // the lock screen.
10247 if (!mPolicy.allowAppAnimationsLw()) {
10248 animLp = null;
10249 }
10250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010251 NN = mOpeningApps.size();
10252 for (i=0; i<NN; i++) {
10253 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010254 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010255 "Now opening app" + wtoken);
10256 wtoken.reportedVisible = false;
10257 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010258 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010259 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010260 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010261 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010262 wtoken.showAllWindowsLocked();
10263 }
10264 NN = mClosingApps.size();
10265 for (i=0; i<NN; i++) {
10266 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010267 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 "Now closing app" + wtoken);
10269 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010270 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010271 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010273 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010274 // Force the allDrawn flag, because we want to start
10275 // this guy's animations regardless of whether it's
10276 // gotten drawn.
10277 wtoken.allDrawn = true;
10278 }
10279
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010280 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010282 mOpeningApps.clear();
10283 mClosingApps.clear();
10284
10285 // This has changed the visibility of windows, so perform
10286 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010287 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10288 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010290 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10291 assignLayersLocked();
10292 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010293 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10294 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010295 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010296 }
10297 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010298
Dianne Hackborn16064f92010-03-25 00:47:24 -070010299 int adjResult = 0;
10300
Dianne Hackborna8f60182009-09-01 19:01:50 -070010301 if (!animating && mAppTransitionRunning) {
10302 // We have finished the animation of an app transition. To do
10303 // this, we have delayed a lot of operations like showing and
10304 // hiding apps, moving apps in Z-order, etc. The app token list
10305 // reflects the correct Z-order, but the window list may now
10306 // be out of sync with it. So here we will just rebuild the
10307 // entire app window list. Fun!
10308 mAppTransitionRunning = false;
10309 // Clear information about apps that were moving.
10310 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010311
Dianne Hackborna8f60182009-09-01 19:01:50 -070010312 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010313 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010314 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010315 moveInputMethodWindowsIfNeededLocked(false);
10316 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010317 // Since the window list has been rebuilt, focus might
10318 // have to be recomputed since the actual order of windows
10319 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010320 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010321 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010322
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010323 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010324 // At this point, there was a window with a wallpaper that
10325 // was force hiding other windows behind it, but now it
10326 // is going away. This may be simple -- just animate
10327 // away the wallpaper and its window -- or it may be
10328 // hard -- the wallpaper now needs to be shown behind
10329 // something that was hidden.
10330 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010331 if (mLowerWallpaperTarget != null
10332 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010333 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010334 "wallpaperForceHiding changed with lower="
10335 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010336 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010337 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10338 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10339 if (mLowerWallpaperTarget.mAppToken.hidden) {
10340 // The lower target has become hidden before we
10341 // actually started the animation... let's completely
10342 // re-evaluate everything.
10343 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010344 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010345 }
10346 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010347 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010348 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010349 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010350 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010351 + " NEW: " + mWallpaperTarget
10352 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010353 if (mLowerWallpaperTarget == null) {
10354 // Whoops, we don't need a special wallpaper animation.
10355 // Clear them out.
10356 forceHiding = false;
10357 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010358 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010359 if (w.mSurface != null) {
10360 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010361 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010362 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010363 forceHiding = true;
10364 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10365 if (!w.mAnimating) {
10366 // We set the animation above so it
10367 // is not yet running.
10368 w.clearAnimation();
10369 }
10370 }
10371 }
10372 }
10373 }
10374 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010375
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010376 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10377 if (DEBUG_WALLPAPER) Slog.v(TAG,
10378 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10379 + windowDetachedWallpaper);
10380 mWindowDetachedWallpaper = windowDetachedWallpaper;
10381 wallpaperMayChange = true;
10382 }
10383
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010384 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010385 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010386 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010387 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010388 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010389
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010390 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010391 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010392 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010393 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010394 assignLayersLocked();
10395 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010396 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010397 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010398 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010399 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010400
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010401 if (mFocusMayChange) {
10402 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010403 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10404 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010405 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010406 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010407 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010408 }
10409
10410 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010411 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010412 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010413
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010414 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10415 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010416 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417
10418 // THIRD LOOP: Update the surfaces of all windows.
10419
10420 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10421
10422 boolean obscured = false;
10423 boolean blurring = false;
10424 boolean dimming = false;
10425 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010426 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010427 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010428
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010429 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010431 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010432 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433
10434 boolean displayed = false;
10435 final WindowManager.LayoutParams attrs = w.mAttrs;
10436 final int attrFlags = attrs.flags;
10437
10438 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010439 // XXX NOTE: The logic here could be improved. We have
10440 // the decision about whether to resize a window separated
10441 // from whether to hide the surface. This can cause us to
10442 // resize a surface even if we are going to hide it. You
10443 // can see this by (1) holding device in landscape mode on
10444 // home screen; (2) tapping browser icon (device will rotate
10445 // to landscape; (3) tap home. The wallpaper will be resized
10446 // in step 2 but then immediately hidden, causing us to
10447 // have to resize and then redraw it again in step 3. It
10448 // would be nice to figure out how to avoid this, but it is
10449 // difficult because we do need to resize surfaces in some
10450 // cases while they are hidden such as when first showing a
10451 // window.
10452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010453 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010454 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 TAG, "Placing surface #" + i + " " + w.mSurface
10456 + ": new=" + w.mShownFrame + ", old="
10457 + w.mLastShownFrame);
10458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010459 int width, height;
10460 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 // for a scaled surface, we just want to use
10462 // the requested size.
10463 width = w.mRequestedWidth;
10464 height = w.mRequestedHeight;
10465 w.mLastRequestedWidth = width;
10466 w.mLastRequestedHeight = height;
10467 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010468 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010469 width = w.mShownFrame.width();
10470 height = w.mShownFrame.height();
10471 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010472 }
10473
Jeff Brownfbae7222011-01-23 13:07:25 -080010474 if (w.mSurface != null) {
10475 if (w.mSurfaceX != w.mShownFrame.left
10476 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010478 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010479 "POS " + w.mShownFrame.left
10480 + ", " + w.mShownFrame.top, null);
10481 w.mSurfaceX = w.mShownFrame.left;
10482 w.mSurfaceY = w.mShownFrame.top;
10483 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10484 } catch (RuntimeException e) {
10485 Slog.w(TAG, "Error positioning surface of " + w
10486 + " pos=(" + w.mShownFrame.left
10487 + "," + w.mShownFrame.top + ")", e);
10488 if (!recoveringMemory) {
10489 reclaimSomeSurfaceMemoryLocked(w, "position");
10490 }
10491 }
10492 }
10493
10494 if (width < 1) {
10495 width = 1;
10496 }
10497 if (height < 1) {
10498 height = 1;
10499 }
10500
10501 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10502 try {
10503 if (SHOW_TRANSACTIONS) logSurface(w,
10504 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010505 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010506 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010507 w.mSurfaceW = width;
10508 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010510 } catch (RuntimeException e) {
10511 // If something goes wrong with the surface (such
10512 // as running out of memory), don't take down the
10513 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010514 Slog.e(TAG, "Error resizing surface of " + w
10515 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 if (!recoveringMemory) {
10517 reclaimSomeSurfaceMemoryLocked(w, "size");
10518 }
10519 }
10520 }
10521 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010522
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010523 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524 w.mContentInsetsChanged =
10525 !w.mLastContentInsets.equals(w.mContentInsets);
10526 w.mVisibleInsetsChanged =
10527 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010528 boolean configChanged =
10529 w.mConfiguration != mCurConfiguration
10530 && (w.mConfiguration == null
10531 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010532 if (DEBUG_CONFIGURATION && configChanged) {
10533 Slog.v(TAG, "Win " + w + " config changed: "
10534 + mCurConfiguration);
10535 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010536 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010537 + ": configChanged=" + configChanged
10538 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010539 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10540 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010541 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010542 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010543 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010544 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010545 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10546 Slog.v(TAG, "Resize reasons: "
10547 + "frameChanged=" + frameChanged
10548 + " contentInsetsChanged=" + w.mContentInsetsChanged
10549 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10550 + " surfaceResized=" + w.mSurfaceResized
10551 + " configChanged=" + configChanged);
10552 }
10553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010554 w.mLastFrame.set(w.mFrame);
10555 w.mLastContentInsets.set(w.mContentInsets);
10556 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010557 // If the screen is currently frozen, then keep
10558 // it frozen until this window draws at its new
10559 // orientation.
10560 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010561 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010562 "Resizing while display frozen: " + w);
10563 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010564 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010565 mWindowsFreezingScreen = true;
10566 // XXX should probably keep timeout from
10567 // when we first froze the display.
10568 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10569 mH.sendMessageDelayed(mH.obtainMessage(
10570 H.WINDOW_FREEZE_TIMEOUT), 2000);
10571 }
10572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 // If the orientation is changing, then we need to
10574 // hold off on unfreezing the display until this
10575 // window has been redrawn; to do that, we need
10576 // to go through the process of getting informed
10577 // by the application when it has finished drawing.
10578 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010579 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010580 "Orientation start waiting for draw in "
10581 + w + ", surface " + w.mSurface);
10582 w.mDrawPending = true;
10583 w.mCommitDrawPending = false;
10584 w.mReadyToShow = false;
10585 if (w.mAppToken != null) {
10586 w.mAppToken.allDrawn = false;
10587 }
10588 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010589 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590 "Resizing window " + w + " to " + w.mFrame);
10591 mResizingWindows.add(w);
10592 } else if (w.mOrientationChanging) {
10593 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010594 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010595 "Orientation not waiting for draw in "
10596 + w + ", surface " + w.mSurface);
10597 w.mOrientationChanging = false;
10598 }
10599 }
10600 }
10601
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010602 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010603 if (!w.mLastHidden) {
10604 //dump();
10605 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010606 if (SHOW_TRANSACTIONS) logSurface(w,
10607 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010608 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010609 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010610 try {
10611 w.mSurface.hide();
10612 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010613 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010614 }
10615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010616 }
10617 // If we are waiting for this window to handle an
10618 // orientation change, well, it is hidden, so
10619 // doesn't really matter. Note that this does
10620 // introduce a potential glitch if the window
10621 // becomes unhidden before it has drawn for the
10622 // new orientation.
10623 if (w.mOrientationChanging) {
10624 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010625 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010626 "Orientation change skips hidden " + w);
10627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010628 } else if (w.mLastLayer != w.mAnimLayer
10629 || w.mLastAlpha != w.mShownAlpha
10630 || w.mLastDsDx != w.mDsDx
10631 || w.mLastDtDx != w.mDtDx
10632 || w.mLastDsDy != w.mDsDy
10633 || w.mLastDtDy != w.mDtDy
10634 || w.mLastHScale != w.mHScale
10635 || w.mLastVScale != w.mVScale
10636 || w.mLastHidden) {
10637 displayed = true;
10638 w.mLastAlpha = w.mShownAlpha;
10639 w.mLastLayer = w.mAnimLayer;
10640 w.mLastDsDx = w.mDsDx;
10641 w.mLastDtDx = w.mDtDx;
10642 w.mLastDsDy = w.mDsDy;
10643 w.mLastDtDy = w.mDtDy;
10644 w.mLastHScale = w.mHScale;
10645 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010646 if (SHOW_TRANSACTIONS) logSurface(w,
10647 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010648 + " matrix=[" + (w.mDsDx*w.mHScale)
10649 + "," + (w.mDtDx*w.mVScale)
10650 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010651 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010652 if (w.mSurface != null) {
10653 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010654 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010656 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010657 w.mSurface.setLayer(w.mAnimLayer);
10658 w.mSurface.setMatrix(
10659 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10660 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10661 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010662 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010663 if (!recoveringMemory) {
10664 reclaimSomeSurfaceMemoryLocked(w, "update");
10665 }
10666 }
10667 }
10668
10669 if (w.mLastHidden && !w.mDrawPending
10670 && !w.mCommitDrawPending
10671 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010672 if (SHOW_TRANSACTIONS) logSurface(w,
10673 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010674 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675 + " during relayout");
10676 if (showSurfaceRobustlyLocked(w)) {
10677 w.mHasDrawn = true;
10678 w.mLastHidden = false;
10679 } else {
10680 w.mOrientationChanging = false;
10681 }
10682 }
10683 if (w.mSurface != null) {
10684 w.mToken.hasVisible = true;
10685 }
10686 } else {
10687 displayed = true;
10688 }
10689
10690 if (displayed) {
10691 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010692 if (attrs.width == LayoutParams.MATCH_PARENT
10693 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010694 covered = true;
10695 }
10696 }
10697 if (w.mOrientationChanging) {
10698 if (w.mDrawPending || w.mCommitDrawPending) {
10699 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010700 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010701 "Orientation continue waiting for draw in " + w);
10702 } else {
10703 w.mOrientationChanging = 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 change complete in " + w);
10706 }
10707 }
10708 w.mToken.hasVisible = true;
10709 }
10710 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010711 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010712 "Orientation change skips hidden " + w);
10713 w.mOrientationChanging = false;
10714 }
10715
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010716 if (w.mContentChanged) {
10717 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10718 w.mContentChanged = false;
10719 }
10720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010721 final boolean canBeSeen = w.isDisplayedLw();
10722
10723 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10724 focusDisplayed = true;
10725 }
10726
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010727 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010729 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010730 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010731 if (w.mSurface != null) {
10732 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10733 holdScreen = w.mSession;
10734 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010735 if (!syswin && w.mAttrs.screenBrightness >= 0
10736 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010737 screenBrightness = w.mAttrs.screenBrightness;
10738 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010739 if (!syswin && w.mAttrs.buttonBrightness >= 0
10740 && buttonBrightness < 0) {
10741 buttonBrightness = w.mAttrs.buttonBrightness;
10742 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010743 if (canBeSeen
10744 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10745 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10746 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010747 syswin = true;
10748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010750
Dianne Hackborn25994b42009-09-04 14:21:19 -070010751 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10752 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010753 // This window completely covers everything behind it,
10754 // so we want to leave all of them as unblurred (for
10755 // performance reasons).
10756 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010757 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010758 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010759 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010760 obscured = true;
10761 if (mBackgroundFillerSurface == null) {
10762 try {
10763 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010764 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010765 0, dw, dh,
10766 PixelFormat.OPAQUE,
10767 Surface.FX_SURFACE_NORMAL);
10768 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010769 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010770 }
10771 }
10772 try {
10773 mBackgroundFillerSurface.setPosition(0, 0);
10774 mBackgroundFillerSurface.setSize(dw, dh);
10775 // Using the same layer as Dim because they will never be shown at the
10776 // same time.
10777 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10778 mBackgroundFillerSurface.show();
10779 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010780 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010781 }
10782 backgroundFillerShown = true;
10783 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010784 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010786 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010787 + ": blurring=" + blurring
10788 + " obscured=" + obscured
10789 + " displayed=" + displayed);
10790 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10791 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010792 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010794 if (mDimAnimator == null) {
10795 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010796 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010797 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010798 mDimAnimator.updateParameters(mContext.getResources(),
10799 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010801 }
10802 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10803 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010804 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010805 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010807 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010808 + mBlurSurface + ": CREATE");
10809 try {
Romain Guy06882f82009-06-10 13:36:04 -070010810 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010811 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010812 -1, 16, 16,
10813 PixelFormat.OPAQUE,
10814 Surface.FX_SURFACE_BLUR);
10815 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010816 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010817 }
10818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010819 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010820 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10821 + mBlurSurface + ": pos=(0,0) (" +
10822 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010823 mBlurSurface.setPosition(0, 0);
10824 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010825 mBlurSurface.setLayer(w.mAnimLayer-2);
10826 if (!mBlurShown) {
10827 try {
10828 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10829 + mBlurSurface + ": SHOW");
10830 mBlurSurface.show();
10831 } catch (RuntimeException e) {
10832 Slog.w(TAG, "Failure showing blur surface", e);
10833 }
10834 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010835 }
10836 }
10837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010838 }
10839 }
10840 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010841
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010842 if (obscuredChanged && mWallpaperTarget == w) {
10843 // This is the wallpaper target and its obscured state
10844 // changed... make sure the current wallaper's visibility
10845 // has been updated accordingly.
10846 updateWallpaperVisibilityLocked();
10847 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010848 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010849
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010850 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10851 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010852 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010853 try {
10854 mBackgroundFillerSurface.hide();
10855 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010856 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010857 }
10858 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010859
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010860 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010861 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10862 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010863 }
Romain Guy06882f82009-06-10 13:36:04 -070010864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010865 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010866 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010867 + ": HIDE");
10868 try {
10869 mBlurSurface.hide();
10870 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010871 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010872 }
10873 mBlurShown = false;
10874 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010876 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010877 }
10878
10879 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010880
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010881 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10882
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010883 if (mWatermark != null) {
10884 mWatermark.drawIfNeeded();
10885 }
10886
Joe Onorato8a9b2202010-02-26 18:56:32 -080010887 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010888 "With display frozen, orientationChangeComplete="
10889 + orientationChangeComplete);
10890 if (orientationChangeComplete) {
10891 if (mWindowsFreezingScreen) {
10892 mWindowsFreezingScreen = false;
10893 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10894 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010895 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 }
Romain Guy06882f82009-06-10 13:36:04 -070010897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010898 i = mResizingWindows.size();
10899 if (i > 0) {
10900 do {
10901 i--;
10902 WindowState win = mResizingWindows.get(i);
10903 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010904 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10905 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010906 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010907 boolean configChanged =
10908 win.mConfiguration != mCurConfiguration
10909 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010910 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10911 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10912 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010913 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010914 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010915 + " / " + mCurConfiguration + " / 0x"
10916 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010917 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010918 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010919 win.mClient.resized(win.mFrame.width(),
10920 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010921 win.mLastVisibleInsets, win.mDrawPending,
10922 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010923 win.mContentInsetsChanged = false;
10924 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010925 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 } catch (RemoteException e) {
10927 win.mOrientationChanging = false;
10928 }
10929 } while (i > 0);
10930 mResizingWindows.clear();
10931 }
Romain Guy06882f82009-06-10 13:36:04 -070010932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010933 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010934 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010935 i = mDestroySurface.size();
10936 if (i > 0) {
10937 do {
10938 i--;
10939 WindowState win = mDestroySurface.get(i);
10940 win.mDestroying = false;
10941 if (mInputMethodWindow == win) {
10942 mInputMethodWindow = null;
10943 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010944 if (win == mWallpaperTarget) {
10945 wallpaperDestroyed = true;
10946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 win.destroySurfaceLocked();
10948 } while (i > 0);
10949 mDestroySurface.clear();
10950 }
10951
10952 // Time to remove any exiting tokens?
10953 for (i=mExitingTokens.size()-1; i>=0; i--) {
10954 WindowToken token = mExitingTokens.get(i);
10955 if (!token.hasVisible) {
10956 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010957 if (token.windowType == TYPE_WALLPAPER) {
10958 mWallpaperTokens.remove(token);
10959 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010960 }
10961 }
10962
10963 // Time to remove any exiting applications?
10964 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10965 AppWindowToken token = mExitingAppTokens.get(i);
10966 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010967 // Make sure there is no animation running on this token,
10968 // so any windows associated with it will be removed as
10969 // soon as their animations are complete
10970 token.animation = null;
10971 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010972 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10973 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 mAppTokens.remove(token);
10975 mExitingAppTokens.remove(i);
10976 }
10977 }
10978
Dianne Hackborna8f60182009-09-01 19:01:50 -070010979 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010980
Dianne Hackborna8f60182009-09-01 19:01:50 -070010981 if (!animating && mAppTransitionRunning) {
10982 // We have finished the animation of an app transition. To do
10983 // this, we have delayed a lot of operations like showing and
10984 // hiding apps, moving apps in Z-order, etc. The app token list
10985 // reflects the correct Z-order, but the window list may now
10986 // be out of sync with it. So here we will just rebuild the
10987 // entire app window list. Fun!
10988 mAppTransitionRunning = false;
10989 needRelayout = true;
10990 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010991 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010992 // Clear information about apps that were moving.
10993 mToBottomApps.clear();
10994 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010996 if (focusDisplayed) {
10997 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10998 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010999 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011000 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011001 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011002 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011003 requestAnimationLocked(0);
11004 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011005 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
11006 }
Jeff Browneb857f12010-07-16 10:06:33 -070011007
Jeff Brown3a22cd92011-01-21 13:59:04 -080011008 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080011009 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070011010
Jeff Brown8e03b752010-06-13 19:16:55 -070011011 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080011012 if (!mDisplayFrozen) {
11013 if (screenBrightness < 0 || screenBrightness > 1.0f) {
11014 mPowerManager.setScreenBrightnessOverride(-1);
11015 } else {
11016 mPowerManager.setScreenBrightnessOverride((int)
11017 (screenBrightness * Power.BRIGHTNESS_ON));
11018 }
11019 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
11020 mPowerManager.setButtonBrightnessOverride(-1);
11021 } else {
11022 mPowerManager.setButtonBrightnessOverride((int)
11023 (buttonBrightness * Power.BRIGHTNESS_ON));
11024 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050011025 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 if (holdScreen != mHoldingScreenOn) {
11027 mHoldingScreenOn = holdScreen;
11028 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
11029 mH.sendMessage(m);
11030 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011031
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011032 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011033 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011034 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
11035 LocalPowerManager.BUTTON_EVENT, true);
11036 mTurnOnScreen = false;
11037 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011038
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011039 if (updateRotation) {
11040 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11041 boolean changed = setRotationUncheckedLocked(
11042 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11043 if (changed) {
11044 sendNewConfiguration();
11045 }
11046 }
11047
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011048 // Check to see if we are now in a state where the screen should
11049 // be enabled, because the window obscured flags have changed.
11050 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011051 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070011052
11053 /**
11054 * Must be called with the main window manager lock held.
11055 */
11056 void setHoldScreenLocked(boolean holding) {
11057 boolean state = mHoldingScreenWakeLock.isHeld();
11058 if (holding != state) {
11059 if (holding) {
11060 mHoldingScreenWakeLock.acquire();
11061 } else {
11062 mPolicy.screenOnStoppedLw();
11063 mHoldingScreenWakeLock.release();
11064 }
11065 }
11066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011067
11068 void requestAnimationLocked(long delay) {
11069 if (!mAnimationPending) {
11070 mAnimationPending = true;
11071 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
11072 }
11073 }
Romain Guy06882f82009-06-10 13:36:04 -070011074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011075 /**
11076 * Have the surface flinger show a surface, robustly dealing with
11077 * error conditions. In particular, if there is not enough memory
11078 * to show the surface, then we will try to get rid of other surfaces
11079 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011080 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011081 * @return Returns true if the surface was successfully shown.
11082 */
11083 boolean showSurfaceRobustlyLocked(WindowState win) {
11084 try {
11085 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011086 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011087 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011088 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011089 if (DEBUG_VISIBILITY) Slog.v(TAG,
11090 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011091 win.mTurnOnScreen = false;
11092 mTurnOnScreen = true;
11093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011094 }
11095 return true;
11096 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011097 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011098 }
Romain Guy06882f82009-06-10 13:36:04 -070011099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011100 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011102 return false;
11103 }
Romain Guy06882f82009-06-10 13:36:04 -070011104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011105 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11106 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011107
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011108 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011109 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011111 if (mForceRemoves == null) {
11112 mForceRemoves = new ArrayList<WindowState>();
11113 }
Romain Guy06882f82009-06-10 13:36:04 -070011114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011115 long callingIdentity = Binder.clearCallingIdentity();
11116 try {
11117 // There was some problem... first, do a sanity check of the
11118 // window list to make sure we haven't left any dangling surfaces
11119 // around.
11120 int N = mWindows.size();
11121 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011122 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011123 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011124 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011125 if (ws.mSurface != null) {
11126 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011127 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011128 + ws + " surface=" + ws.mSurface
11129 + " token=" + win.mToken
11130 + " pid=" + ws.mSession.mPid
11131 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011132 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011133 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011134 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011135 ws.mSurface = null;
11136 mForceRemoves.add(ws);
11137 i--;
11138 N--;
11139 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011140 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011141 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011142 + ws + " surface=" + ws.mSurface
11143 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011144 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011145 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011146 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011147 ws.mSurface = null;
11148 leakedSurface = true;
11149 }
11150 }
11151 }
Romain Guy06882f82009-06-10 13:36:04 -070011152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011153 boolean killedApps = false;
11154 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011155 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011156 SparseIntArray pidCandidates = new SparseIntArray();
11157 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011158 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011159 if (ws.mSurface != null) {
11160 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11161 }
11162 }
11163 if (pidCandidates.size() > 0) {
11164 int[] pids = new int[pidCandidates.size()];
11165 for (int i=0; i<pids.length; i++) {
11166 pids[i] = pidCandidates.keyAt(i);
11167 }
11168 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011169 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011170 killedApps = true;
11171 }
11172 } catch (RemoteException e) {
11173 }
11174 }
11175 }
Romain Guy06882f82009-06-10 13:36:04 -070011176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011177 if (leakedSurface || killedApps) {
11178 // We managed to reclaim some memory, so get rid of the trouble
11179 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011180 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011181 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011182 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011183 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011184 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011185 win.mSurface = null;
11186 }
Romain Guy06882f82009-06-10 13:36:04 -070011187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011188 try {
11189 win.mClient.dispatchGetNewSurface();
11190 } catch (RemoteException e) {
11191 }
11192 }
11193 } finally {
11194 Binder.restoreCallingIdentity(callingIdentity);
11195 }
11196 }
Romain Guy06882f82009-06-10 13:36:04 -070011197
Jeff Brown3a22cd92011-01-21 13:59:04 -080011198 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011199 WindowState newFocus = computeFocusedWindowLocked();
11200 if (mCurrentFocus != newFocus) {
11201 // This check makes sure that we don't already have the focus
11202 // change message pending.
11203 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11204 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011205 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011206 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11207 final WindowState oldFocus = mCurrentFocus;
11208 mCurrentFocus = newFocus;
11209 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011211 final WindowState imWindow = mInputMethodWindow;
11212 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011213 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011214 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011215 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11216 mLayoutNeeded = true;
11217 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011218 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011219 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011220 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11221 // Client will do the layout, but we need to assign layers
11222 // for handleNewWindowLocked() below.
11223 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011224 }
11225 }
Jeff Brown349703e2010-06-22 01:27:15 -070011226
11227 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11228 // If we defer assigning layers, then the caller is responsible for
11229 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011230 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011232 return true;
11233 }
11234 return false;
11235 }
Jeff Brown349703e2010-06-22 01:27:15 -070011236
Jeff Brown3a22cd92011-01-21 13:59:04 -080011237 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11238 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011239 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011240
11241 private WindowState computeFocusedWindowLocked() {
11242 WindowState result = null;
11243 WindowState win;
11244
11245 int i = mWindows.size() - 1;
11246 int nextAppIndex = mAppTokens.size()-1;
11247 WindowToken nextApp = nextAppIndex >= 0
11248 ? mAppTokens.get(nextAppIndex) : null;
11249
11250 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011251 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011252
Joe Onorato8a9b2202010-02-26 18:56:32 -080011253 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011254 TAG, "Looking for focus: " + i
11255 + " = " + win
11256 + ", flags=" + win.mAttrs.flags
11257 + ", canReceive=" + win.canReceiveKeys());
11258
11259 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011261 // If this window's application has been removed, just skip it.
11262 if (thisApp != null && thisApp.removed) {
11263 i--;
11264 continue;
11265 }
Romain Guy06882f82009-06-10 13:36:04 -070011266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011267 // If there is a focused app, don't allow focus to go to any
11268 // windows below it. If this is an application window, step
11269 // through the app tokens until we find its app.
11270 if (thisApp != null && nextApp != null && thisApp != nextApp
11271 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11272 int origAppIndex = nextAppIndex;
11273 while (nextAppIndex > 0) {
11274 if (nextApp == mFocusedApp) {
11275 // Whoops, we are below the focused app... no focus
11276 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011277 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011278 TAG, "Reached focused app: " + mFocusedApp);
11279 return null;
11280 }
11281 nextAppIndex--;
11282 nextApp = mAppTokens.get(nextAppIndex);
11283 if (nextApp == thisApp) {
11284 break;
11285 }
11286 }
11287 if (thisApp != nextApp) {
11288 // Uh oh, the app token doesn't exist! This shouldn't
11289 // happen, but if it does we can get totally hosed...
11290 // so restart at the original app.
11291 nextAppIndex = origAppIndex;
11292 nextApp = mAppTokens.get(nextAppIndex);
11293 }
11294 }
11295
11296 // Dispatch to this window if it is wants key events.
11297 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011298 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011299 TAG, "Found focus @ " + i + " = " + win);
11300 result = win;
11301 break;
11302 }
11303
11304 i--;
11305 }
11306
11307 return result;
11308 }
11309
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011310 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011311 if (mDisplayFrozen) {
11312 return;
11313 }
Romain Guy06882f82009-06-10 13:36:04 -070011314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011315 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011317 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011318 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011319 if (mFreezeGcPending != 0) {
11320 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011321 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011322 mH.removeMessages(H.FORCE_GC);
11323 Runtime.getRuntime().gc();
11324 mFreezeGcPending = now;
11325 }
11326 } else {
11327 mFreezeGcPending = now;
11328 }
Romain Guy06882f82009-06-10 13:36:04 -070011329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011330 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011331
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011332 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011333
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011334 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11335 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011336 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011337 mAppTransitionReady = true;
11338 }
Romain Guy06882f82009-06-10 13:36:04 -070011339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011340 if (PROFILE_ORIENTATION) {
11341 File file = new File("/data/system/frozen");
11342 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11343 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011344
11345 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011346 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11347 mScreenRotationAnimation.kill();
11348 mScreenRotationAnimation = null;
11349 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011350 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011351 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011352 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011353 }
11354 } else {
11355 Surface.freezeDisplay(0);
11356 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011357 }
Romain Guy06882f82009-06-10 13:36:04 -070011358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011359 private void stopFreezingDisplayLocked() {
11360 if (!mDisplayFrozen) {
11361 return;
11362 }
Romain Guy06882f82009-06-10 13:36:04 -070011363
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011364 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11365 return;
11366 }
11367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011368 mDisplayFrozen = false;
11369 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11370 if (PROFILE_ORIENTATION) {
11371 Debug.stopMethodTracing();
11372 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011373
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011374 boolean updateRotation = false;
11375
Dianne Hackborna1111872010-11-23 20:55:11 -080011376 if (CUSTOM_SCREEN_ROTATION) {
11377 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011378 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11379 mTransitionAnimationScale)) {
11380 requestAnimationLocked(0);
11381 } else {
11382 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011383 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011384 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011385 }
11386 } else {
11387 Surface.unfreezeDisplay(0);
11388 }
Romain Guy06882f82009-06-10 13:36:04 -070011389
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011390 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011391
Dianne Hackborn420829e2011-01-28 11:30:35 -080011392 boolean configChanged;
11393
Christopher Tateb696aee2010-04-02 19:08:30 -070011394 // While the display is frozen we don't re-compute the orientation
11395 // to avoid inconsistent states. However, something interesting
11396 // could have actually changed during that time so re-evaluate it
11397 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -080011398 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -070011399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011400 // A little kludge: a lot could have happened while the
11401 // display was frozen, so now that we are coming back we
11402 // do a gc so that any remote references the system
11403 // processes holds on others can be released if they are
11404 // no longer needed.
11405 mH.removeMessages(H.FORCE_GC);
11406 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11407 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011409 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011410
11411 if (updateRotation) {
11412 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -080011413 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011414 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -080011415 }
11416
11417 if (configChanged) {
11418 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011420 }
Romain Guy06882f82009-06-10 13:36:04 -070011421
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011422 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11423 DisplayMetrics dm) {
11424 if (index < tokens.length) {
11425 String str = tokens[index];
11426 if (str != null && str.length() > 0) {
11427 try {
11428 int val = Integer.parseInt(str);
11429 return val;
11430 } catch (Exception e) {
11431 }
11432 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011433 }
11434 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11435 return defDps;
11436 }
11437 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11438 return val;
11439 }
11440
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011441 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011442 final String[] mTokens;
11443 final String mText;
11444 final Paint mTextPaint;
11445 final int mTextWidth;
11446 final int mTextHeight;
11447 final int mTextAscent;
11448 final int mTextDescent;
11449 final int mDeltaX;
11450 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011451
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011452 Surface mSurface;
11453 int mLastDW;
11454 int mLastDH;
11455 boolean mDrawNeeded;
11456
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011457 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011458 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011459 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011460
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011461 if (false) {
11462 Log.i(TAG, "*********************** WATERMARK");
11463 for (int i=0; i<tokens.length; i++) {
11464 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11465 }
11466 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011467
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011468 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011469
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011470 StringBuilder builder = new StringBuilder(32);
11471 int len = mTokens[0].length();
11472 len = len & ~1;
11473 for (int i=0; i<len; i+=2) {
11474 int c1 = mTokens[0].charAt(i);
11475 int c2 = mTokens[0].charAt(i+1);
11476 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11477 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11478 else c1 -= '0';
11479 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11480 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11481 else c2 -= '0';
11482 builder.append((char)(255-((c1*16)+c2)));
11483 }
11484 mText = builder.toString();
11485 if (false) {
11486 Log.i(TAG, "Final text: " + mText);
11487 }
11488
11489 int fontSize = getPropertyInt(tokens, 1,
11490 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11491
11492 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11493 mTextPaint.setTextSize(fontSize);
11494 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11495
11496 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11497 mTextWidth = (int)mTextPaint.measureText(mText);
11498 mTextAscent = fm.ascent;
11499 mTextDescent = fm.descent;
11500 mTextHeight = fm.descent - fm.ascent;
11501
11502 mDeltaX = getPropertyInt(tokens, 2,
11503 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11504 mDeltaY = getPropertyInt(tokens, 3,
11505 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11506 int shadowColor = getPropertyInt(tokens, 4,
11507 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11508 int color = getPropertyInt(tokens, 5,
11509 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11510 int shadowRadius = getPropertyInt(tokens, 6,
11511 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11512 int shadowDx = getPropertyInt(tokens, 8,
11513 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11514 int shadowDy = getPropertyInt(tokens, 9,
11515 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11516
11517 mTextPaint.setColor(color);
11518 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011519
11520 try {
11521 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011522 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011523 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011524 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011525 mSurface.show();
11526 } catch (OutOfResourcesException e) {
11527 }
11528 }
11529
11530 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011531 if (mLastDW != dw || mLastDH != dh) {
11532 mLastDW = dw;
11533 mLastDH = dh;
11534 mSurface.setSize(dw, dh);
11535 mDrawNeeded = true;
11536 }
11537 }
11538
11539 void drawIfNeeded() {
11540 if (mDrawNeeded) {
11541 final int dw = mLastDW;
11542 final int dh = mLastDH;
11543
11544 mDrawNeeded = false;
11545 Rect dirty = new Rect(0, 0, dw, dh);
11546 Canvas c = null;
11547 try {
11548 c = mSurface.lockCanvas(dirty);
11549 } catch (IllegalArgumentException e) {
11550 } catch (OutOfResourcesException e) {
11551 }
11552 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011553 c.drawColor(0, PorterDuff.Mode.CLEAR);
11554
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011555 int deltaX = mDeltaX;
11556 int deltaY = mDeltaY;
11557
11558 // deltaX shouldn't be close to a round fraction of our
11559 // x step, or else things will line up too much.
11560 int div = (dw+mTextWidth)/deltaX;
11561 int rem = (dw+mTextWidth) - (div*deltaX);
11562 int qdelta = deltaX/4;
11563 if (rem < qdelta || rem > (deltaX-qdelta)) {
11564 deltaX += deltaX/3;
11565 }
11566
11567 int y = -mTextHeight;
11568 int x = -mTextWidth;
11569 while (y < (dh+mTextHeight)) {
11570 c.drawText(mText, x, y, mTextPaint);
11571 x += deltaX;
11572 if (x >= dw) {
11573 x -= (dw+mTextWidth);
11574 y += deltaY;
11575 }
11576 }
11577 mSurface.unlockCanvasAndPost(c);
11578 }
11579 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011580 }
11581 }
11582
11583 void createWatermark() {
11584 if (mWatermark != null) {
11585 return;
11586 }
11587
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011588 File file = new File("/system/etc/setup.conf");
11589 FileInputStream in = null;
11590 try {
11591 in = new FileInputStream(file);
11592 DataInputStream ind = new DataInputStream(in);
11593 String line = ind.readLine();
11594 if (line != null) {
11595 String[] toks = line.split("%");
11596 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011597 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011598 }
11599 }
11600 } catch (FileNotFoundException e) {
11601 } catch (IOException e) {
11602 } finally {
11603 if (in != null) {
11604 try {
11605 in.close();
11606 } catch (IOException e) {
11607 }
11608 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011609 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011610 }
11611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011612 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011613 public void statusBarVisibilityChanged(int visibility) {
11614 synchronized (mWindowMap) {
11615 final int N = mWindows.size();
11616 for (int i = 0; i < N; i++) {
11617 WindowState ws = mWindows.get(i);
11618 try {
11619 if (ws.getAttrs().hasSystemUiListeners) {
11620 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11621 }
11622 } catch (RemoteException e) {
11623 // so sorry
11624 }
11625 }
11626 }
11627 }
11628
11629 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011630 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11631 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11632 != PackageManager.PERMISSION_GRANTED) {
11633 pw.println("Permission Denial: can't dump WindowManager from from pid="
11634 + Binder.getCallingPid()
11635 + ", uid=" + Binder.getCallingUid());
11636 return;
11637 }
Romain Guy06882f82009-06-10 13:36:04 -070011638
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011639 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011640 pw.println(" ");
11641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011642 synchronized(mWindowMap) {
11643 pw.println("Current Window Manager state:");
11644 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011645 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011646 pw.print(" Window #"); pw.print(i); pw.print(' ');
11647 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011648 w.dump(pw, " ");
11649 }
11650 if (mInputMethodDialogs.size() > 0) {
11651 pw.println(" ");
11652 pw.println(" Input method dialogs:");
11653 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11654 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011655 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011656 }
11657 }
11658 if (mPendingRemove.size() > 0) {
11659 pw.println(" ");
11660 pw.println(" Remove pending for:");
11661 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11662 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011663 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11664 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011665 w.dump(pw, " ");
11666 }
11667 }
11668 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11669 pw.println(" ");
11670 pw.println(" Windows force removing:");
11671 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11672 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011673 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11674 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011675 w.dump(pw, " ");
11676 }
11677 }
11678 if (mDestroySurface.size() > 0) {
11679 pw.println(" ");
11680 pw.println(" Windows waiting to destroy their surface:");
11681 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11682 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011683 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11684 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011685 w.dump(pw, " ");
11686 }
11687 }
11688 if (mLosingFocus.size() > 0) {
11689 pw.println(" ");
11690 pw.println(" Windows losing focus:");
11691 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11692 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011693 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11694 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011695 w.dump(pw, " ");
11696 }
11697 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011698 if (mResizingWindows.size() > 0) {
11699 pw.println(" ");
11700 pw.println(" Windows waiting to resize:");
11701 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11702 WindowState w = mResizingWindows.get(i);
11703 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11704 pw.print(w); pw.println(":");
11705 w.dump(pw, " ");
11706 }
11707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011708 if (mSessions.size() > 0) {
11709 pw.println(" ");
11710 pw.println(" All active sessions:");
11711 Iterator<Session> it = mSessions.iterator();
11712 while (it.hasNext()) {
11713 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011714 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011715 s.dump(pw, " ");
11716 }
11717 }
11718 if (mTokenMap.size() > 0) {
11719 pw.println(" ");
11720 pw.println(" All tokens:");
11721 Iterator<WindowToken> it = mTokenMap.values().iterator();
11722 while (it.hasNext()) {
11723 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011724 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011725 token.dump(pw, " ");
11726 }
11727 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011728 if (mWallpaperTokens.size() > 0) {
11729 pw.println(" ");
11730 pw.println(" Wallpaper tokens:");
11731 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11732 WindowToken token = mWallpaperTokens.get(i);
11733 pw.print(" Wallpaper #"); pw.print(i);
11734 pw.print(' '); pw.print(token); pw.println(':');
11735 token.dump(pw, " ");
11736 }
11737 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011738 if (mAppTokens.size() > 0) {
11739 pw.println(" ");
11740 pw.println(" Application tokens in Z order:");
11741 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011742 pw.print(" App #"); pw.print(i); pw.print(": ");
11743 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011744 }
11745 }
11746 if (mFinishedStarting.size() > 0) {
11747 pw.println(" ");
11748 pw.println(" Finishing start of application tokens:");
11749 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11750 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011751 pw.print(" Finished Starting #"); pw.print(i);
11752 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011753 token.dump(pw, " ");
11754 }
11755 }
11756 if (mExitingTokens.size() > 0) {
11757 pw.println(" ");
11758 pw.println(" Exiting tokens:");
11759 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11760 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011761 pw.print(" Exiting #"); pw.print(i);
11762 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011763 token.dump(pw, " ");
11764 }
11765 }
11766 if (mExitingAppTokens.size() > 0) {
11767 pw.println(" ");
11768 pw.println(" Exiting application tokens:");
11769 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11770 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011771 pw.print(" Exiting App #"); pw.print(i);
11772 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011773 token.dump(pw, " ");
11774 }
11775 }
11776 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011777 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11778 pw.print(" mLastFocus="); pw.println(mLastFocus);
11779 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11780 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11781 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011782 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011783 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11784 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11785 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11786 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011787 if (mWindowDetachedWallpaper != null) {
11788 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11789 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011790 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11791 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11792 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011793 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11794 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11795 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11796 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011797 if (mDimAnimator != null) {
11798 mDimAnimator.printTo(pw);
11799 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011800 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011801 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011802 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011803 pw.print(mInputMethodAnimLayerAdjustment);
11804 pw.print(" mWallpaperAnimLayerAdjustment=");
11805 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011806 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11807 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011808 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11809 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011810 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11811 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011812 pw.print(" mRotation="); pw.print(mRotation);
11813 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11814 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011815 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11816 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011817 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11818 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11819 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11820 pw.print(" mNextAppTransition=0x");
11821 pw.print(Integer.toHexString(mNextAppTransition));
11822 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011823 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011824 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011825 if (mNextAppTransitionPackage != null) {
11826 pw.print(" mNextAppTransitionPackage=");
11827 pw.print(mNextAppTransitionPackage);
11828 pw.print(", mNextAppTransitionEnter=0x");
11829 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11830 pw.print(", mNextAppTransitionExit=0x");
11831 pw.print(Integer.toHexString(mNextAppTransitionExit));
11832 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011833 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11834 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11835 if (mOpeningApps.size() > 0) {
11836 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11837 }
11838 if (mClosingApps.size() > 0) {
11839 pw.print(" mClosingApps="); pw.println(mClosingApps);
11840 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011841 if (mToTopApps.size() > 0) {
11842 pw.print(" mToTopApps="); pw.println(mToTopApps);
11843 }
11844 if (mToBottomApps.size() > 0) {
11845 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11846 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011847 if (mDisplay != null) {
11848 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11849 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11850 } else {
11851 pw.println(" NO DISPLAY");
11852 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011853 pw.println(" Policy:");
11854 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011855 }
11856 }
11857
Jeff Brown349703e2010-06-22 01:27:15 -070011858 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011859 public void monitor() {
11860 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011861 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011862 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011863
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011864 /**
11865 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011866 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011867 */
11868 private static class DimAnimator {
11869 Surface mDimSurface;
11870 boolean mDimShown = false;
11871 float mDimCurrentAlpha;
11872 float mDimTargetAlpha;
11873 float mDimDeltaPerMs;
11874 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011875
11876 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011877
11878 DimAnimator (SurfaceSession session) {
11879 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011880 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011881 + mDimSurface + ": CREATE");
11882 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011883 mDimSurface = new Surface(session, 0,
11884 "DimSurface",
11885 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011886 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011887 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011888 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011889 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011890 }
11891 }
11892 }
11893
11894 /**
11895 * Show the dim surface.
11896 */
11897 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011898 if (!mDimShown) {
11899 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11900 dw + "x" + dh + ")");
11901 mDimShown = true;
11902 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011903 mLastDimWidth = dw;
11904 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011905 mDimSurface.setPosition(0, 0);
11906 mDimSurface.setSize(dw, dh);
11907 mDimSurface.show();
11908 } catch (RuntimeException e) {
11909 Slog.w(TAG, "Failure showing dim surface", e);
11910 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011911 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11912 mLastDimWidth = dw;
11913 mLastDimHeight = dh;
11914 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011915 }
11916 }
11917
11918 /**
11919 * Set's the dim surface's layer and update dim parameters that will be used in
11920 * {@link updateSurface} after all windows are examined.
11921 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011922 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011923 mDimSurface.setLayer(w.mAnimLayer-1);
11924
11925 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011926 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011927 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011928 if (mDimTargetAlpha != target) {
11929 // If the desired dim level has changed, then
11930 // start an animation to it.
11931 mLastDimAnimTime = currentTime;
11932 long duration = (w.mAnimating && w.mAnimation != null)
11933 ? w.mAnimation.computeDurationHint()
11934 : DEFAULT_DIM_DURATION;
11935 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011936 TypedValue tv = new TypedValue();
11937 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11938 tv, true);
11939 if (tv.type == TypedValue.TYPE_FRACTION) {
11940 duration = (long)tv.getFraction((float)duration, (float)duration);
11941 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11942 && tv.type <= TypedValue.TYPE_LAST_INT) {
11943 duration = tv.data;
11944 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011945 }
11946 if (duration < 1) {
11947 // Don't divide by zero
11948 duration = 1;
11949 }
11950 mDimTargetAlpha = target;
11951 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11952 }
11953 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011954
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011955 /**
11956 * Updating the surface's alpha. Returns true if the animation continues, or returns
11957 * false when the animation is finished and the dim surface is hidden.
11958 */
11959 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11960 if (!dimming) {
11961 if (mDimTargetAlpha != 0) {
11962 mLastDimAnimTime = currentTime;
11963 mDimTargetAlpha = 0;
11964 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11965 }
11966 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011967
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011968 boolean animating = false;
11969 if (mLastDimAnimTime != 0) {
11970 mDimCurrentAlpha += mDimDeltaPerMs
11971 * (currentTime-mLastDimAnimTime);
11972 boolean more = true;
11973 if (displayFrozen) {
11974 // If the display is frozen, there is no reason to animate.
11975 more = false;
11976 } else if (mDimDeltaPerMs > 0) {
11977 if (mDimCurrentAlpha > mDimTargetAlpha) {
11978 more = false;
11979 }
11980 } else if (mDimDeltaPerMs < 0) {
11981 if (mDimCurrentAlpha < mDimTargetAlpha) {
11982 more = false;
11983 }
11984 } else {
11985 more = false;
11986 }
11987
11988 // Do we need to continue animating?
11989 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011990 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011991 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11992 mLastDimAnimTime = currentTime;
11993 mDimSurface.setAlpha(mDimCurrentAlpha);
11994 animating = true;
11995 } else {
11996 mDimCurrentAlpha = mDimTargetAlpha;
11997 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011998 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011999 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
12000 mDimSurface.setAlpha(mDimCurrentAlpha);
12001 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012002 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012003 + ": HIDE");
12004 try {
12005 mDimSurface.hide();
12006 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012007 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012008 }
12009 mDimShown = false;
12010 }
12011 }
12012 }
12013 return animating;
12014 }
12015
12016 public void printTo(PrintWriter pw) {
12017 pw.print(" mDimShown="); pw.print(mDimShown);
12018 pw.print(" current="); pw.print(mDimCurrentAlpha);
12019 pw.print(" target="); pw.print(mDimTargetAlpha);
12020 pw.print(" delta="); pw.print(mDimDeltaPerMs);
12021 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
12022 }
12023 }
12024
12025 /**
12026 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
12027 * This is used for opening/closing transition for apps in compatible mode.
12028 */
12029 private static class FadeInOutAnimation extends Animation {
12030 int mWidth;
12031 boolean mFadeIn;
12032
12033 public FadeInOutAnimation(boolean fadeIn) {
12034 setInterpolator(new AccelerateInterpolator());
12035 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
12036 mFadeIn = fadeIn;
12037 }
12038
12039 @Override
12040 protected void applyTransformation(float interpolatedTime, Transformation t) {
12041 float x = interpolatedTime;
12042 if (!mFadeIn) {
12043 x = 1.0f - x; // reverse the interpolation for fade out
12044 }
12045 if (x < 0.5) {
12046 // move the window out of the screen.
12047 t.getMatrix().setTranslate(mWidth, 0);
12048 } else {
12049 t.getMatrix().setTranslate(0, 0);// show
12050 t.setAlpha((x - 0.5f) * 2);
12051 }
12052 }
12053
12054 @Override
12055 public void initialize(int width, int height, int parentWidth, int parentHeight) {
12056 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
12057 mWidth = width;
12058 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012059
12060 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070012061 public int getZAdjustment() {
12062 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012063 }
12064 }
Jeff Brown2992ea72011-01-28 22:04:14 -080012065
12066 public interface OnHardKeyboardStatusChangeListener {
12067 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
12068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012069}