blob: 7c79b8a05453de08a951d696319f91d6cbaf8e73 [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 Tate02d2b3b2011-01-10 20:43:53 -08005876 // TODO: preserve flags param in DragState
5877 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005878 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005879 token = mDragState.mToken = new Binder();
5880
5881 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005882 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5883 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005884 mH.sendMessageDelayed(msg, 5000);
5885 } else {
5886 Slog.w(TAG, "Drag already in progress");
5887 }
5888 } catch (Surface.OutOfResourcesException e) {
5889 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5890 if (mDragState != null) {
5891 mDragState.reset();
5892 mDragState = null;
5893 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005894 }
5895 }
5896 } finally {
5897 Binder.restoreCallingIdentity(origId);
5898 }
5899
5900 return token;
5901 }
5902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005903 // -------------------------------------------------------------
5904 // Input Events and Focus Management
5905 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005906
Jeff Brown349703e2010-06-22 01:27:15 -07005907 InputMonitor mInputMonitor = new InputMonitor();
5908
5909 /* Tracks the progress of input dispatch and ensures that input dispatch state
5910 * is kept in sync with changes in window focus, visibility, registration, and
5911 * other relevant Window Manager state transitions. */
5912 final class InputMonitor {
5913 // Current window with input focus for keys and other non-touch events. May be null.
5914 private WindowState mInputFocus;
5915
5916 // When true, prevents input dispatch from proceeding until set to false again.
5917 private boolean mInputDispatchFrozen;
5918
5919 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5920 private boolean mInputDispatchEnabled = true;
5921
Jeff Brown3a22cd92011-01-21 13:59:04 -08005922 // When true, need to call updateInputWindowsLw().
5923 private boolean mUpdateInputWindowsNeeded = true;
5924
Jeff Brown349703e2010-06-22 01:27:15 -07005925 // Temporary list of windows information to provide to the input dispatcher.
5926 private InputWindowList mTempInputWindows = new InputWindowList();
5927
5928 // Temporary input application object to provide to the input dispatcher.
5929 private InputApplication mTempInputApplication = new InputApplication();
5930
Jeff Brownb09abc12011-01-13 21:08:27 -08005931 // Set to true when the first input device configuration change notification
5932 // is received to indicate that the input devices are ready.
5933 private final Object mInputDevicesReadyMonitor = new Object();
5934 private boolean mInputDevicesReady;
5935
Jeff Brown349703e2010-06-22 01:27:15 -07005936 /* Notifies the window manager about a broken input channel.
5937 *
5938 * Called by the InputManager.
5939 */
Jeff Brown928e0542011-01-10 11:17:36 -08005940 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5941 if (inputWindowHandle == null) {
5942 return;
5943 }
5944
Jeff Brown349703e2010-06-22 01:27:15 -07005945 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005946 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005947 Slog.i(TAG, "WINDOW DIED " + windowState);
5948 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005949 }
5950 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005951
Jeff Brown519e0242010-09-15 15:18:56 -07005952 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005953 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005954 *
5955 * Called by the InputManager.
5956 */
Jeff Brown928e0542011-01-10 11:17:36 -08005957 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5958 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005959 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005960 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005961 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005962 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005963 if (windowState != null) {
5964 Slog.i(TAG, "Input event dispatching timed out sending to "
5965 + windowState.mAttrs.getTitle());
5966 appWindowToken = windowState.mAppToken;
5967 }
Jeff Brown349703e2010-06-22 01:27:15 -07005968 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005969 }
5970
Jeff Brown928e0542011-01-10 11:17:36 -08005971 if (appWindowToken == null && inputApplicationHandle != null) {
5972 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005973 Slog.i(TAG, "Input event dispatching timed out sending to application "
5974 + appWindowToken.stringName);
5975 }
Jeff Brown349703e2010-06-22 01:27:15 -07005976
Jeff Brown519e0242010-09-15 15:18:56 -07005977 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005978 try {
5979 // Notify the activity manager about the timeout and let it decide whether
5980 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005981 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005982 if (! abort) {
5983 // The activity manager declined to abort dispatching.
5984 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005985 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005986 }
Jeff Brown349703e2010-06-22 01:27:15 -07005987 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005988 }
5989 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005990 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005991 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005992
Chris Tatea32dcf72010-10-14 12:13:50 -07005993 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005994 final InputWindow inputWindow = windowList.add();
5995 inputWindow.inputChannel = mDragState.mServerChannel;
5996 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08005997 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07005998 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5999 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6000 inputWindow.visible = true;
6001 inputWindow.canReceiveKeys = false;
6002 inputWindow.hasFocus = true;
6003 inputWindow.hasWallpaper = false;
6004 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07006005 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07006006 inputWindow.ownerPid = Process.myPid();
6007 inputWindow.ownerUid = Process.myUid();
6008
6009 // The drag window covers the entire display
6010 inputWindow.frameLeft = 0;
6011 inputWindow.frameTop = 0;
6012 inputWindow.frameRight = mDisplay.getWidth();
6013 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07006014
Jeff Brownfbf09772011-01-16 14:06:57 -08006015 // The drag window cannot receive new touches.
6016 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07006017 }
6018
Jeff Brown3a22cd92011-01-21 13:59:04 -08006019 public void setUpdateInputWindowsNeededLw() {
6020 mUpdateInputWindowsNeeded = true;
6021 }
6022
Jeff Brown349703e2010-06-22 01:27:15 -07006023 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08006024 public void updateInputWindowsLw(boolean force) {
6025 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08006026 return;
6027 }
6028 mUpdateInputWindowsNeeded = false;
6029
Jeff Brown349703e2010-06-22 01:27:15 -07006030 // Populate the input window list with information about all of the windows that
6031 // could potentially receive input.
6032 // As an optimization, we could try to prune the list of windows but this turns
6033 // out to be difficult because only the native code knows for sure which window
6034 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07006035 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07006036
6037 // If there's a drag in flight, provide a pseudowindow to catch drag input
6038 final boolean inDrag = (mDragState != null);
6039 if (inDrag) {
6040 if (DEBUG_DRAG) {
6041 Log.d(TAG, "Inserting drag window");
6042 }
Chris Tatea32dcf72010-10-14 12:13:50 -07006043 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07006044 }
6045
Jeff Brown7fbdc842010-06-17 20:52:56 -07006046 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07006047 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07006048 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07006049 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07006050 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07006051 continue;
6052 }
6053
Jeff Brown349703e2010-06-22 01:27:15 -07006054 final int flags = child.mAttrs.flags;
6055 final int type = child.mAttrs.type;
6056
6057 final boolean hasFocus = (child == mInputFocus);
6058 final boolean isVisible = child.isVisibleLw();
6059 final boolean hasWallpaper = (child == mWallpaperTarget)
6060 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07006061
6062 // If there's a drag in progress and 'child' is a potential drop target,
6063 // make sure it's been told about the drag
6064 if (inDrag && isVisible) {
6065 mDragState.sendDragStartedIfNeededLw(child);
6066 }
6067
Jeff Brown349703e2010-06-22 01:27:15 -07006068 // Add a window to our list of input windows.
6069 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006070 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006071 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006072 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006073 inputWindow.layoutParamsFlags = flags;
6074 inputWindow.layoutParamsType = type;
6075 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6076 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006077 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006078 inputWindow.hasFocus = hasFocus;
6079 inputWindow.hasWallpaper = hasWallpaper;
6080 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006081 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006082 inputWindow.ownerPid = child.mSession.mPid;
6083 inputWindow.ownerUid = child.mSession.mUid;
6084
6085 final Rect frame = child.mFrame;
6086 inputWindow.frameLeft = frame.left;
6087 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006088 inputWindow.frameRight = frame.right;
6089 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006090
6091 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006092 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006093
Jeff Brown349703e2010-06-22 01:27:15 -07006094 // Send windows to native code.
6095 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006096
Jeff Brown349703e2010-06-22 01:27:15 -07006097 // Clear the list in preparation for the next round.
6098 // Also avoids keeping InputChannel objects referenced unnecessarily.
6099 mTempInputWindows.clear();
6100 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006101
6102 /* Notifies that the input device configuration has changed. */
6103 public void notifyConfigurationChanged() {
6104 sendNewConfiguration();
6105
6106 synchronized (mInputDevicesReadyMonitor) {
6107 if (!mInputDevicesReady) {
6108 mInputDevicesReady = true;
6109 mInputDevicesReadyMonitor.notifyAll();
6110 }
6111 }
6112 }
6113
6114 /* Waits until the built-in input devices have been configured. */
6115 public boolean waitForInputDevicesReady(long timeoutMillis) {
6116 synchronized (mInputDevicesReadyMonitor) {
6117 if (!mInputDevicesReady) {
6118 try {
6119 mInputDevicesReadyMonitor.wait(timeoutMillis);
6120 } catch (InterruptedException ex) {
6121 }
6122 }
6123 return mInputDevicesReady;
6124 }
6125 }
6126
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006127 /* Notifies that the lid switch changed state. */
6128 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6129 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6130 }
6131
Jeff Brown349703e2010-06-22 01:27:15 -07006132 /* Provides an opportunity for the window manager policy to intercept early key
6133 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006134 public int interceptKeyBeforeQueueing(
6135 KeyEvent event, int policyFlags, boolean isScreenOn) {
6136 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006137 }
6138
6139 /* Provides an opportunity for the window manager policy to process a key before
6140 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006141 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006142 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006143 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006144 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006145 }
6146
Jeff Brown3915bb82010-11-05 15:02:16 -07006147 /* Provides an opportunity for the window manager policy to process a key that
6148 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006149 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006150 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006151 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006152 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006153 }
6154
Jeff Brown349703e2010-06-22 01:27:15 -07006155 /* Called when the current input focus changes.
6156 * Layer assignment is assumed to be complete by the time this is called.
6157 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006158 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006159 if (DEBUG_INPUT) {
6160 Slog.d(TAG, "Input focus has changed to " + newWindow);
6161 }
6162
6163 if (newWindow != mInputFocus) {
6164 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006165 // Displaying a window implicitly causes dispatching to be unpaused.
6166 // This is to protect against bugs if someone pauses dispatching but
6167 // forgets to resume.
6168 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006169 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006170
Jeff Brown349703e2010-06-22 01:27:15 -07006171 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006172 setUpdateInputWindowsNeededLw();
6173
6174 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006175 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006176 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006177 }
6178 }
6179
Jeff Brown349703e2010-06-22 01:27:15 -07006180 public void setFocusedAppLw(AppWindowToken newApp) {
6181 // Focused app has changed.
6182 if (newApp == null) {
6183 mInputManager.setFocusedApplication(null);
6184 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006185 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006186 mTempInputApplication.name = newApp.toString();
6187 mTempInputApplication.dispatchingTimeoutNanos =
6188 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006189
Jeff Brown349703e2010-06-22 01:27:15 -07006190 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006191
6192 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006193 }
6194 }
6195
Jeff Brown349703e2010-06-22 01:27:15 -07006196 public void pauseDispatchingLw(WindowToken window) {
6197 if (! window.paused) {
6198 if (DEBUG_INPUT) {
6199 Slog.v(TAG, "Pausing WindowToken " + window);
6200 }
6201
6202 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006203 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006204 }
6205 }
6206
6207 public void resumeDispatchingLw(WindowToken window) {
6208 if (window.paused) {
6209 if (DEBUG_INPUT) {
6210 Slog.v(TAG, "Resuming WindowToken " + window);
6211 }
6212
6213 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006214 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006215 }
6216 }
6217
6218 public void freezeInputDispatchingLw() {
6219 if (! mInputDispatchFrozen) {
6220 if (DEBUG_INPUT) {
6221 Slog.v(TAG, "Freezing input dispatching");
6222 }
6223
6224 mInputDispatchFrozen = true;
6225 updateInputDispatchModeLw();
6226 }
6227 }
6228
6229 public void thawInputDispatchingLw() {
6230 if (mInputDispatchFrozen) {
6231 if (DEBUG_INPUT) {
6232 Slog.v(TAG, "Thawing input dispatching");
6233 }
6234
6235 mInputDispatchFrozen = false;
6236 updateInputDispatchModeLw();
6237 }
6238 }
6239
6240 public void setEventDispatchingLw(boolean enabled) {
6241 if (mInputDispatchEnabled != enabled) {
6242 if (DEBUG_INPUT) {
6243 Slog.v(TAG, "Setting event dispatching to " + enabled);
6244 }
6245
6246 mInputDispatchEnabled = enabled;
6247 updateInputDispatchModeLw();
6248 }
6249 }
6250
6251 private void updateInputDispatchModeLw() {
6252 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6253 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 public void pauseKeyDispatching(IBinder _token) {
6257 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6258 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006259 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006260 }
6261
6262 synchronized (mWindowMap) {
6263 WindowToken token = mTokenMap.get(_token);
6264 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006265 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 }
6267 }
6268 }
6269
6270 public void resumeKeyDispatching(IBinder _token) {
6271 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6272 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006273 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006274 }
6275
6276 synchronized (mWindowMap) {
6277 WindowToken token = mTokenMap.get(_token);
6278 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006279 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006280 }
6281 }
6282 }
6283
6284 public void setEventDispatching(boolean enabled) {
6285 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6286 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006287 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006288 }
6289
6290 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006291 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 }
6293 }
Romain Guy06882f82009-06-10 13:36:04 -07006294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006295 /**
6296 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006297 * Even when sync is false, this method may block while waiting for current
6298 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006299 *
6300 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006301 * {@link SystemClock#uptimeMillis()} as the timebase.)
6302 * @param sync If true, wait for the event to be completed before returning to the caller.
6303 * @return Returns true if event was dispatched, false if it was dropped for any reason
6304 */
6305 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6306 long downTime = ev.getDownTime();
6307 long eventTime = ev.getEventTime();
6308
6309 int action = ev.getAction();
6310 int code = ev.getKeyCode();
6311 int repeatCount = ev.getRepeatCount();
6312 int metaState = ev.getMetaState();
6313 int deviceId = ev.getDeviceId();
6314 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006315 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006316 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006317
6318 if (source == InputDevice.SOURCE_UNKNOWN) {
6319 source = InputDevice.SOURCE_KEYBOARD;
6320 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006321
6322 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6323 if (downTime == 0) downTime = eventTime;
6324
6325 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006326 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006328 final int pid = Binder.getCallingPid();
6329 final int uid = Binder.getCallingUid();
6330 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006331
Jeff Brownbbda99d2010-07-28 15:48:59 -07006332 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6333 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6334 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6335 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006336
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006337 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006338 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006339 }
6340
6341 /**
6342 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006343 * Even when sync is false, this method may block while waiting for current
6344 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006345 *
6346 * @param ev A motion event describing the pointer (touch) action. (As noted in
6347 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 * {@link SystemClock#uptimeMillis()} as the timebase.)
6349 * @param sync If true, wait for the event to be completed before returning to the caller.
6350 * @return Returns true if event was dispatched, false if it was dropped for any reason
6351 */
6352 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006353 final int pid = Binder.getCallingPid();
6354 final int uid = Binder.getCallingUid();
6355 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006356
Jeff Brownc5ed5912010-07-14 18:48:53 -07006357 MotionEvent newEvent = MotionEvent.obtain(ev);
6358 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6359 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6360 }
6361
Jeff Brownbbda99d2010-07-28 15:48:59 -07006362 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6363 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6364 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6365 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006366
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006367 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006368 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 }
Romain Guy06882f82009-06-10 13:36:04 -07006370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 /**
6372 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006373 * Even when sync is false, this method may block while waiting for current
6374 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006375 *
6376 * @param ev A motion event describing the trackball action. (As noted in
6377 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 * {@link SystemClock#uptimeMillis()} as the timebase.)
6379 * @param sync If true, wait for the event to be completed before returning to the caller.
6380 * @return Returns true if event was dispatched, false if it was dropped for any reason
6381 */
6382 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006383 final int pid = Binder.getCallingPid();
6384 final int uid = Binder.getCallingUid();
6385 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006386
Jeff Brownc5ed5912010-07-14 18:48:53 -07006387 MotionEvent newEvent = MotionEvent.obtain(ev);
6388 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6389 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6390 }
6391
Jeff Brownbbda99d2010-07-28 15:48:59 -07006392 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6393 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6394 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6395 INJECTION_TIMEOUT_MILLIS);
6396
6397 Binder.restoreCallingIdentity(ident);
6398 return reportInjectionResult(result);
6399 }
6400
6401 /**
6402 * Inject an input event into the UI without waiting for dispatch to commence.
6403 * This variant is useful for fire-and-forget input event injection. It does not
6404 * block any longer than it takes to enqueue the input event.
6405 *
6406 * @param ev An input event. (Be sure to set the input source correctly.)
6407 * @return Returns true if event was dispatched, false if it was dropped for any reason
6408 */
6409 public boolean injectInputEventNoWait(InputEvent ev) {
6410 final int pid = Binder.getCallingPid();
6411 final int uid = Binder.getCallingUid();
6412 final long ident = Binder.clearCallingIdentity();
6413
6414 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6415 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6416 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006417
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006418 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006419 return reportInjectionResult(result);
6420 }
6421
6422 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006423 switch (result) {
6424 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6425 Slog.w(TAG, "Input event injection permission denied.");
6426 throw new SecurityException(
6427 "Injecting to another application requires INJECT_EVENTS permission");
6428 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006429 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006430 return true;
6431 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6432 Slog.w(TAG, "Input event injection timed out.");
6433 return false;
6434 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6435 default:
6436 Slog.w(TAG, "Input event injection failed.");
6437 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006438 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006439 }
Romain Guy06882f82009-06-10 13:36:04 -07006440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 private WindowState getFocusedWindow() {
6442 synchronized (mWindowMap) {
6443 return getFocusedWindowLocked();
6444 }
6445 }
6446
6447 private WindowState getFocusedWindowLocked() {
6448 return mCurrentFocus;
6449 }
Romain Guy06882f82009-06-10 13:36:04 -07006450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006451 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006452 if (!mInputMonitor.waitForInputDevicesReady(
6453 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6454 Slog.w(TAG, "Devices still not ready after waiting "
6455 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6456 + " milliseconds before attempting to detect safe mode.");
6457 }
6458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006459 mSafeMode = mPolicy.detectSafeMode();
6460 return mSafeMode;
6461 }
Romain Guy06882f82009-06-10 13:36:04 -07006462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006463 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006464 synchronized(mWindowMap) {
6465 if (mDisplay != null) {
6466 throw new IllegalStateException("Display already initialized");
6467 }
6468 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6469 mDisplay = wm.getDefaultDisplay();
6470 mInitialDisplayWidth = mDisplay.getWidth();
6471 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006472 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6473 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006474 }
6475
6476 try {
6477 mActivityManager.updateConfiguration(null);
6478 } catch (RemoteException e) {
6479 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006480
6481 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006482 }
6483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006484 // -------------------------------------------------------------
6485 // Client Session State
6486 // -------------------------------------------------------------
6487
6488 private final class Session extends IWindowSession.Stub
6489 implements IBinder.DeathRecipient {
6490 final IInputMethodClient mClient;
6491 final IInputContext mInputContext;
6492 final int mUid;
6493 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006494 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006495 SurfaceSession mSurfaceSession;
6496 int mNumWindow = 0;
6497 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 public Session(IInputMethodClient client, IInputContext inputContext) {
6500 mClient = client;
6501 mInputContext = inputContext;
6502 mUid = Binder.getCallingUid();
6503 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006504 StringBuilder sb = new StringBuilder();
6505 sb.append("Session{");
6506 sb.append(Integer.toHexString(System.identityHashCode(this)));
6507 sb.append(" uid ");
6508 sb.append(mUid);
6509 sb.append("}");
6510 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 synchronized (mWindowMap) {
6513 if (mInputMethodManager == null && mHaveInputMethods) {
6514 IBinder b = ServiceManager.getService(
6515 Context.INPUT_METHOD_SERVICE);
6516 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6517 }
6518 }
6519 long ident = Binder.clearCallingIdentity();
6520 try {
6521 // Note: it is safe to call in to the input method manager
6522 // here because we are not holding our lock.
6523 if (mInputMethodManager != null) {
6524 mInputMethodManager.addClient(client, inputContext,
6525 mUid, mPid);
6526 } else {
6527 client.setUsingInputMethod(false);
6528 }
6529 client.asBinder().linkToDeath(this, 0);
6530 } catch (RemoteException e) {
6531 // The caller has died, so we can just forget about this.
6532 try {
6533 if (mInputMethodManager != null) {
6534 mInputMethodManager.removeClient(client);
6535 }
6536 } catch (RemoteException ee) {
6537 }
6538 } finally {
6539 Binder.restoreCallingIdentity(ident);
6540 }
6541 }
Romain Guy06882f82009-06-10 13:36:04 -07006542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006543 @Override
6544 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6545 throws RemoteException {
6546 try {
6547 return super.onTransact(code, data, reply, flags);
6548 } catch (RuntimeException e) {
6549 // Log all 'real' exceptions thrown to the caller
6550 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006551 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006552 }
6553 throw e;
6554 }
6555 }
6556
6557 public void binderDied() {
6558 // Note: it is safe to call in to the input method manager
6559 // here because we are not holding our lock.
6560 try {
6561 if (mInputMethodManager != null) {
6562 mInputMethodManager.removeClient(mClient);
6563 }
6564 } catch (RemoteException e) {
6565 }
6566 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006567 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006568 mClientDead = true;
6569 killSessionLocked();
6570 }
6571 }
6572
6573 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006574 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6575 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6576 outInputChannel);
6577 }
6578
6579 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006581 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006582 }
Romain Guy06882f82009-06-10 13:36:04 -07006583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006584 public void remove(IWindow window) {
6585 removeWindow(this, window);
6586 }
Romain Guy06882f82009-06-10 13:36:04 -07006587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6589 int requestedWidth, int requestedHeight, int viewFlags,
6590 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006591 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006592 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6593 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006595 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006596 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6597 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006598 }
Romain Guy06882f82009-06-10 13:36:04 -07006599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006600 public void setTransparentRegion(IWindow window, Region region) {
6601 setTransparentRegionWindow(this, window, region);
6602 }
Romain Guy06882f82009-06-10 13:36:04 -07006603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006604 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006605 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006607 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608 }
Romain Guy06882f82009-06-10 13:36:04 -07006609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006610 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6611 getWindowDisplayFrame(this, window, outDisplayFrame);
6612 }
Romain Guy06882f82009-06-10 13:36:04 -07006613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006614 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006615 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006616 TAG, "IWindow finishDrawing called for " + window);
6617 finishDrawingWindow(this, window);
6618 }
6619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 public void setInTouchMode(boolean mode) {
6621 synchronized(mWindowMap) {
6622 mInTouchMode = mode;
6623 }
6624 }
6625
6626 public boolean getInTouchMode() {
6627 synchronized(mWindowMap) {
6628 return mInTouchMode;
6629 }
6630 }
6631
6632 public boolean performHapticFeedback(IWindow window, int effectId,
6633 boolean always) {
6634 synchronized(mWindowMap) {
6635 long ident = Binder.clearCallingIdentity();
6636 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006637 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006638 windowForClientLocked(this, window, true),
6639 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 } finally {
6641 Binder.restoreCallingIdentity(ident);
6642 }
6643 }
6644 }
Romain Guy06882f82009-06-10 13:36:04 -07006645
Christopher Tatea53146c2010-09-07 11:57:52 -07006646 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006647 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006648 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006649 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006650 width, height, outSurface);
6651 }
6652
6653 public boolean performDrag(IWindow window, IBinder dragToken,
6654 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6655 ClipData data) {
6656 if (DEBUG_DRAG) {
6657 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6658 }
6659
6660 synchronized (mWindowMap) {
6661 if (mDragState == null) {
6662 Slog.w(TAG, "No drag prepared");
6663 throw new IllegalStateException("performDrag() without prepareDrag()");
6664 }
6665
6666 if (dragToken != mDragState.mToken) {
6667 Slog.w(TAG, "Performing mismatched drag");
6668 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6669 }
6670
6671 WindowState callingWin = windowForClientLocked(null, window, false);
6672 if (callingWin == null) {
6673 Slog.w(TAG, "Bad requesting window " + window);
6674 return false; // !!! TODO: throw here?
6675 }
6676
6677 // !!! TODO: if input is not still focused on the initiating window, fail
6678 // the drag initiation (e.g. an alarm window popped up just as the application
6679 // called performDrag()
6680
6681 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6682
Christopher Tate2c095f32010-10-04 14:13:40 -07006683 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6684 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006685
Chris Tateb478f462010-10-15 16:02:26 -07006686 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6687 // the actual drag event dispatch stuff in the dragstate
6688
Christopher Tatea53146c2010-09-07 11:57:52 -07006689 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006690 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006691 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6692 mDragState.mServerChannel)) {
6693 Slog.e(TAG, "Unable to transfer touch focus");
6694 mDragState.unregister();
6695 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006696 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006697 return false;
6698 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006699
6700 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006701 mDragState.mCurrentX = touchX;
6702 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006703 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006704
6705 // remember the thumb offsets for later
6706 mDragState.mThumbOffsetX = thumbCenterX;
6707 mDragState.mThumbOffsetY = thumbCenterY;
6708
6709 // Make the surface visible at the proper location
6710 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006711 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006712 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006713 try {
6714 surface.setPosition((int)(touchX - thumbCenterX),
6715 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006716 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006717 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006718 surface.show();
6719 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006720 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006721 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006722 }
6723 }
6724
6725 return true; // success!
6726 }
6727
Chris Tated4533f142010-10-19 15:15:08 -07006728 public void reportDropResult(IWindow window, boolean consumed) {
6729 IBinder token = window.asBinder();
6730 if (DEBUG_DRAG) {
6731 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6732 }
6733
6734 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006735 long ident = Binder.clearCallingIdentity();
6736 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006737 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006738 Slog.w(TAG, "Invalid drop-result claim by " + window);
6739 throw new IllegalStateException("reportDropResult() by non-recipient");
6740 }
6741
6742 // The right window has responded, even if it's no longer around,
6743 // so be sure to halt the timeout even if the later WindowState
6744 // lookup fails.
6745 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6746 WindowState callingWin = windowForClientLocked(null, window, false);
6747 if (callingWin == null) {
6748 Slog.w(TAG, "Bad result-reporting window " + window);
6749 return; // !!! TODO: throw here?
6750 }
6751
6752 mDragState.mDragResult = consumed;
6753 mDragState.endDragLw();
6754 } finally {
6755 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006756 }
Chris Tated4533f142010-10-19 15:15:08 -07006757 }
6758 }
6759
Christopher Tatea53146c2010-09-07 11:57:52 -07006760 public void dragRecipientEntered(IWindow window) {
6761 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006762 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006763 }
6764 }
6765
6766 public void dragRecipientExited(IWindow window) {
6767 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006768 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006769 }
6770 }
6771
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006772 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006773 synchronized(mWindowMap) {
6774 long ident = Binder.clearCallingIdentity();
6775 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006776 setWindowWallpaperPositionLocked(
6777 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006778 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006779 } finally {
6780 Binder.restoreCallingIdentity(ident);
6781 }
6782 }
6783 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006784
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006785 public void wallpaperOffsetsComplete(IBinder window) {
6786 WindowManagerService.this.wallpaperOffsetsComplete(window);
6787 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006788
Dianne Hackborn75804932009-10-20 20:15:20 -07006789 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6790 int z, Bundle extras, boolean sync) {
6791 synchronized(mWindowMap) {
6792 long ident = Binder.clearCallingIdentity();
6793 try {
6794 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006795 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006796 action, x, y, z, extras, sync);
6797 } finally {
6798 Binder.restoreCallingIdentity(ident);
6799 }
6800 }
6801 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006802
Dianne Hackborn75804932009-10-20 20:15:20 -07006803 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6804 WindowManagerService.this.wallpaperCommandComplete(window, result);
6805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 void windowAddedLocked() {
6808 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006809 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 TAG, "First window added to " + this + ", creating SurfaceSession");
6811 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006812 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006813 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006814 mSessions.add(this);
6815 }
6816 mNumWindow++;
6817 }
6818
6819 void windowRemovedLocked() {
6820 mNumWindow--;
6821 killSessionLocked();
6822 }
Romain Guy06882f82009-06-10 13:36:04 -07006823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006824 void killSessionLocked() {
6825 if (mNumWindow <= 0 && mClientDead) {
6826 mSessions.remove(this);
6827 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006828 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006829 TAG, "Last window removed from " + this
6830 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006831 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006832 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006833 try {
6834 mSurfaceSession.kill();
6835 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006836 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006837 + mSurfaceSession + " in session " + this
6838 + ": " + e.toString());
6839 }
6840 mSurfaceSession = null;
6841 }
6842 }
6843 }
Romain Guy06882f82009-06-10 13:36:04 -07006844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006846 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6847 pw.print(" mClientDead="); pw.print(mClientDead);
6848 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006849 }
6850
6851 @Override
6852 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006853 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 }
6855 }
6856
6857 // -------------------------------------------------------------
6858 // Client Window State
6859 // -------------------------------------------------------------
6860
6861 private final class WindowState implements WindowManagerPolicy.WindowState {
6862 final Session mSession;
6863 final IWindow mClient;
6864 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006865 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 AppWindowToken mAppToken;
6867 AppWindowToken mTargetAppToken;
6868 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6869 final DeathRecipient mDeathRecipient;
6870 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006871 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006872 final int mBaseLayer;
6873 final int mSubLayer;
6874 final boolean mLayoutAttached;
6875 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006876 final boolean mIsWallpaper;
6877 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 int mViewVisibility;
6879 boolean mPolicyVisibility = true;
6880 boolean mPolicyVisibilityAfterAnim = true;
6881 boolean mAppFreezing;
6882 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006883 boolean mReportDestroySurface;
6884 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006885 boolean mAttachedHidden; // is our parent window hidden?
6886 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006887 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006888 int mRequestedWidth;
6889 int mRequestedHeight;
6890 int mLastRequestedWidth;
6891 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006892 int mLayer;
6893 int mAnimLayer;
6894 int mLastLayer;
6895 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006896 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006897 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006899 int mLayoutSeq = -1;
6900
6901 Configuration mConfiguration = null;
6902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 // Actual frame shown on-screen (may be modified by animation)
6904 final Rect mShownFrame = new Rect();
6905 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006907 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006908 * Set when we have changed the size of the surface, to know that
6909 * we must tell them application to resize (and thus redraw itself).
6910 */
6911 boolean mSurfaceResized;
6912
6913 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 * Insets that determine the actually visible area
6915 */
6916 final Rect mVisibleInsets = new Rect();
6917 final Rect mLastVisibleInsets = new Rect();
6918 boolean mVisibleInsetsChanged;
6919
6920 /**
6921 * Insets that are covered by system windows
6922 */
6923 final Rect mContentInsets = new Rect();
6924 final Rect mLastContentInsets = new Rect();
6925 boolean mContentInsetsChanged;
6926
6927 /**
6928 * Set to true if we are waiting for this window to receive its
6929 * given internal insets before laying out other windows based on it.
6930 */
6931 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006933 /**
6934 * These are the content insets that were given during layout for
6935 * this window, to be applied to windows behind it.
6936 */
6937 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 /**
6940 * These are the visible insets that were given during layout for
6941 * this window, to be applied to windows behind it.
6942 */
6943 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006946 * This is the given touchable area relative to the window frame, or null if none.
6947 */
6948 final Region mGivenTouchableRegion = new Region();
6949
6950 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 * Flag indicating whether the touchable region should be adjusted by
6952 * the visible insets; if false the area outside the visible insets is
6953 * NOT touchable, so we must use those to adjust the frame during hit
6954 * tests.
6955 */
6956 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006959 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006960 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6961 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6962 float mHScale=1, mVScale=1;
6963 float mLastHScale=1, mLastVScale=1;
6964 final Matrix mTmpMatrix = new Matrix();
6965
6966 // "Real" frame that the application sees.
6967 final Rect mFrame = new Rect();
6968 final Rect mLastFrame = new Rect();
6969
6970 final Rect mContainingFrame = new Rect();
6971 final Rect mDisplayFrame = new Rect();
6972 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006973 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 final Rect mVisibleFrame = new Rect();
6975
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006976 boolean mContentChanged;
6977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 float mShownAlpha = 1;
6979 float mAlpha = 1;
6980 float mLastAlpha = 1;
6981
6982 // Set to true if, when the window gets displayed, it should perform
6983 // an enter animation.
6984 boolean mEnterAnimationPending;
6985
6986 // Currently running animation.
6987 boolean mAnimating;
6988 boolean mLocalAnimating;
6989 Animation mAnimation;
6990 boolean mAnimationIsEntrance;
6991 boolean mHasTransformation;
6992 boolean mHasLocalTransformation;
6993 final Transformation mTransformation = new Transformation();
6994
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006995 // If a window showing a wallpaper: the requested offset for the
6996 // wallpaper; if a wallpaper window: the currently applied offset.
6997 float mWallpaperX = -1;
6998 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006999
7000 // If a window showing a wallpaper: what fraction of the offset
7001 // range corresponds to a full virtual screen.
7002 float mWallpaperXStep = -1;
7003 float mWallpaperYStep = -1;
7004
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007005 // Wallpaper windows: pixels offset based on above variables.
7006 int mXOffset;
7007 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007009 // This is set after IWindowSession.relayout() has been called at
7010 // least once for the window. It allows us to detect the situation
7011 // where we don't yet have a surface, but should have one soon, so
7012 // we can give the window focus before waiting for the relayout.
7013 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07007014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007015 // This is set after the Surface has been created but before the
7016 // window has been drawn. During this time the surface is hidden.
7017 boolean mDrawPending;
7018
7019 // This is set after the window has finished drawing for the first
7020 // time but before its surface is shown. The surface will be
7021 // displayed when the next layout is run.
7022 boolean mCommitDrawPending;
7023
7024 // This is set during the time after the window's drawing has been
7025 // committed, and before its surface is actually shown. It is used
7026 // to delay showing the surface until all windows in a token are ready
7027 // to be shown.
7028 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07007029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007030 // Set when the window has been shown in the screen the first time.
7031 boolean mHasDrawn;
7032
7033 // Currently running an exit animation?
7034 boolean mExiting;
7035
7036 // Currently on the mDestroySurface list?
7037 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07007038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007039 // Completely remove from window manager after exit animation?
7040 boolean mRemoveOnExit;
7041
7042 // Set when the orientation is changing and this window has not yet
7043 // been updated for the new orientation.
7044 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07007045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007046 // Is this window now (or just being) removed?
7047 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07007048
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007049 // Temp for keeping track of windows that have been removed when
7050 // rebuilding window list.
7051 boolean mRebuilding;
7052
Dianne Hackborn16064f92010-03-25 00:47:24 -07007053 // For debugging, this is the last information given to the surface flinger.
7054 boolean mSurfaceShown;
7055 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
7056 int mSurfaceLayer;
7057 float mSurfaceAlpha;
7058
Jeff Brown928e0542011-01-10 11:17:36 -08007059 // Input channel and input window handle used by the input dispatcher.
7060 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007061 InputChannel mInputChannel;
7062
Mattias Petersson1622eee2010-12-21 10:15:11 +01007063 // Used to improve performance of toString()
7064 String mStringNameCache;
7065 CharSequence mLastTitle;
7066 boolean mWasPaused;
7067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007068 WindowState(Session s, IWindow c, WindowToken token,
7069 WindowState attachedWindow, WindowManager.LayoutParams a,
7070 int viewVisibility) {
7071 mSession = s;
7072 mClient = c;
7073 mToken = token;
7074 mAttrs.copyFrom(a);
7075 mViewVisibility = viewVisibility;
7076 DeathRecipient deathRecipient = new DeathRecipient();
7077 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007078 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007079 TAG, "Window " + this + " client=" + c.asBinder()
7080 + " token=" + token + " (" + mAttrs.token + ")");
7081 try {
7082 c.asBinder().linkToDeath(deathRecipient, 0);
7083 } catch (RemoteException e) {
7084 mDeathRecipient = null;
7085 mAttachedWindow = null;
7086 mLayoutAttached = false;
7087 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007088 mIsWallpaper = false;
7089 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 mBaseLayer = 0;
7091 mSubLayer = 0;
7092 return;
7093 }
7094 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7097 mAttrs.type <= LAST_SUB_WINDOW)) {
7098 // The multiplier here is to reserve space for multiple
7099 // windows in the same type layer.
7100 mBaseLayer = mPolicy.windowTypeToLayerLw(
7101 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7102 + TYPE_LAYER_OFFSET;
7103 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7104 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007105 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 mAttachedWindow.mChildWindows.add(this);
7107 mLayoutAttached = mAttrs.type !=
7108 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7109 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7110 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007111 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7112 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007113 } else {
7114 // The multiplier here is to reserve space for multiple
7115 // windows in the same type layer.
7116 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7117 * TYPE_LAYER_MULTIPLIER
7118 + TYPE_LAYER_OFFSET;
7119 mSubLayer = 0;
7120 mAttachedWindow = null;
7121 mLayoutAttached = false;
7122 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7123 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007124 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7125 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 }
7127
7128 WindowState appWin = this;
7129 while (appWin.mAttachedWindow != null) {
7130 appWin = mAttachedWindow;
7131 }
7132 WindowToken appToken = appWin.mToken;
7133 while (appToken.appWindowToken == null) {
7134 WindowToken parent = mTokenMap.get(appToken.token);
7135 if (parent == null || appToken == parent) {
7136 break;
7137 }
7138 appToken = parent;
7139 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007140 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 mAppToken = appToken.appWindowToken;
7142
7143 mSurface = null;
7144 mRequestedWidth = 0;
7145 mRequestedHeight = 0;
7146 mLastRequestedWidth = 0;
7147 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007148 mXOffset = 0;
7149 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 mLayer = 0;
7151 mAnimLayer = 0;
7152 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007153 mInputWindowHandle = new InputWindowHandle(
7154 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007155 }
7156
7157 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007158 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007159 TAG, "Attaching " + this + " token=" + mToken
7160 + ", list=" + mToken.windows);
7161 mSession.windowAddedLocked();
7162 }
7163
7164 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7165 mHaveFrame = true;
7166
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007167 final Rect container = mContainingFrame;
7168 container.set(pf);
7169
7170 final Rect display = mDisplayFrame;
7171 display.set(df);
7172
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007173 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007174 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007175 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7176 display.intersect(mCompatibleScreenFrame);
7177 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007178 }
7179
7180 final int pw = container.right - container.left;
7181 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182
7183 int w,h;
7184 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7185 w = mAttrs.width < 0 ? pw : mAttrs.width;
7186 h = mAttrs.height< 0 ? ph : mAttrs.height;
7187 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007188 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7189 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007190 }
Romain Guy06882f82009-06-10 13:36:04 -07007191
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007192 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007193 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7194 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007195 mParentFrame.set(pf);
7196 mContentChanged = true;
7197 }
7198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199 final Rect content = mContentFrame;
7200 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007202 final Rect visible = mVisibleFrame;
7203 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007206 final int fw = frame.width();
7207 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007209 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7210 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7211
7212 Gravity.apply(mAttrs.gravity, w, h, container,
7213 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7214 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7215
7216 //System.out.println("Out: " + mFrame);
7217
7218 // Now make sure the window fits in the overall display.
7219 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007221 // Make sure the content and visible frames are inside of the
7222 // final window frame.
7223 if (content.left < frame.left) content.left = frame.left;
7224 if (content.top < frame.top) content.top = frame.top;
7225 if (content.right > frame.right) content.right = frame.right;
7226 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7227 if (visible.left < frame.left) visible.left = frame.left;
7228 if (visible.top < frame.top) visible.top = frame.top;
7229 if (visible.right > frame.right) visible.right = frame.right;
7230 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007232 final Rect contentInsets = mContentInsets;
7233 contentInsets.left = content.left-frame.left;
7234 contentInsets.top = content.top-frame.top;
7235 contentInsets.right = frame.right-content.right;
7236 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007238 final Rect visibleInsets = mVisibleInsets;
7239 visibleInsets.left = visible.left-frame.left;
7240 visibleInsets.top = visible.top-frame.top;
7241 visibleInsets.right = frame.right-visible.right;
7242 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007243
Dianne Hackborn284ac932009-08-28 10:34:25 -07007244 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7245 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007246 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007249 if (localLOGV) {
7250 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7251 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007252 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007253 + mRequestedWidth + ", mRequestedheight="
7254 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7255 + "): frame=" + mFrame.toShortString()
7256 + " ci=" + contentInsets.toShortString()
7257 + " vi=" + visibleInsets.toShortString());
7258 //}
7259 }
7260 }
Romain Guy06882f82009-06-10 13:36:04 -07007261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 public Rect getFrameLw() {
7263 return mFrame;
7264 }
7265
7266 public Rect getShownFrameLw() {
7267 return mShownFrame;
7268 }
7269
7270 public Rect getDisplayFrameLw() {
7271 return mDisplayFrame;
7272 }
7273
7274 public Rect getContentFrameLw() {
7275 return mContentFrame;
7276 }
7277
7278 public Rect getVisibleFrameLw() {
7279 return mVisibleFrame;
7280 }
7281
7282 public boolean getGivenInsetsPendingLw() {
7283 return mGivenInsetsPending;
7284 }
7285
7286 public Rect getGivenContentInsetsLw() {
7287 return mGivenContentInsets;
7288 }
Romain Guy06882f82009-06-10 13:36:04 -07007289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 public Rect getGivenVisibleInsetsLw() {
7291 return mGivenVisibleInsets;
7292 }
Romain Guy06882f82009-06-10 13:36:04 -07007293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007294 public WindowManager.LayoutParams getAttrs() {
7295 return mAttrs;
7296 }
7297
7298 public int getSurfaceLayer() {
7299 return mLayer;
7300 }
Romain Guy06882f82009-06-10 13:36:04 -07007301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007302 public IApplicationToken getAppToken() {
7303 return mAppToken != null ? mAppToken.appToken : null;
7304 }
Jeff Brown349703e2010-06-22 01:27:15 -07007305
7306 public long getInputDispatchingTimeoutNanos() {
7307 return mAppToken != null
7308 ? mAppToken.inputDispatchingTimeoutNanos
7309 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007311
7312 public boolean hasAppShownWindows() {
7313 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7314 }
7315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007317 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007318 TAG, "Setting animation in " + this + ": " + anim);
7319 mAnimating = false;
7320 mLocalAnimating = false;
7321 mAnimation = anim;
7322 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7323 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7324 }
7325
7326 public void clearAnimation() {
7327 if (mAnimation != null) {
7328 mAnimating = true;
7329 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007330 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007331 mAnimation = null;
7332 }
7333 }
Romain Guy06882f82009-06-10 13:36:04 -07007334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007335 Surface createSurfaceLocked() {
7336 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007337 mReportDestroySurface = false;
7338 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 mDrawPending = true;
7340 mCommitDrawPending = false;
7341 mReadyToShow = false;
7342 if (mAppToken != null) {
7343 mAppToken.allDrawn = false;
7344 }
7345
7346 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347
7348 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7349 flags |= Surface.SECURE;
7350 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007351 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007352 TAG, "Creating surface in session "
7353 + mSession.mSurfaceSession + " window " + this
7354 + " w=" + mFrame.width()
7355 + " h=" + mFrame.height() + " format="
7356 + mAttrs.format + " flags=" + flags);
7357
7358 int w = mFrame.width();
7359 int h = mFrame.height();
7360 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7361 // for a scaled surface, we always want the requested
7362 // size.
7363 w = mRequestedWidth;
7364 h = mRequestedHeight;
7365 }
7366
Romain Guy9825ec62009-10-01 00:58:09 -07007367 // Something is wrong and SurfaceFlinger will not like this,
7368 // try to revert to sane values
7369 if (w <= 0) w = 1;
7370 if (h <= 0) h = 1;
7371
Dianne Hackborn16064f92010-03-25 00:47:24 -07007372 mSurfaceShown = false;
7373 mSurfaceLayer = 0;
7374 mSurfaceAlpha = 1;
7375 mSurfaceX = 0;
7376 mSurfaceY = 0;
7377 mSurfaceW = w;
7378 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007379 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007380 final boolean isHwAccelerated = (mAttrs.flags &
7381 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7382 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7383 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7384 flags |= Surface.OPAQUE;
7385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007387 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007388 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007389 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007390 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007391 + mSurface + " IN SESSION "
7392 + mSession.mSurfaceSession
7393 + ": pid=" + mSession.mPid + " format="
7394 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007395 + Integer.toHexString(flags)
7396 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007397 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007398 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 reclaimSomeSurfaceMemoryLocked(this, "create");
7400 return null;
7401 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007402 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007403 return null;
7404 }
Romain Guy06882f82009-06-10 13:36:04 -07007405
Joe Onorato8a9b2202010-02-26 18:56:32 -08007406 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 TAG, "Got surface: " + mSurface
7408 + ", set left=" + mFrame.left + " top=" + mFrame.top
7409 + ", animLayer=" + mAnimLayer);
7410 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007411 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7412 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007413 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7414 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 }
7416 Surface.openTransaction();
7417 try {
7418 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007419 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007420 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007421 mSurface.setPosition(mSurfaceX, mSurfaceY);
7422 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007423 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007424 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 mSurface.hide();
7426 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007427 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 mSurface.setFlags(Surface.SURFACE_DITHER,
7429 Surface.SURFACE_DITHER);
7430 }
7431 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007432 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7434 }
7435 mLastHidden = true;
7436 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007437 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007438 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007440 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007441 TAG, "Created surface " + this);
7442 }
7443 return mSurface;
7444 }
Romain Guy06882f82009-06-10 13:36:04 -07007445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007447 if (mAppToken != null && this == mAppToken.startingWindow) {
7448 mAppToken.startingDisplayed = false;
7449 }
Romain Guy06882f82009-06-10 13:36:04 -07007450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007452 mDrawPending = false;
7453 mCommitDrawPending = false;
7454 mReadyToShow = false;
7455
7456 int i = mChildWindows.size();
7457 while (i > 0) {
7458 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007459 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007460 c.mAttachedHidden = true;
7461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007462
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007463 if (mReportDestroySurface) {
7464 mReportDestroySurface = false;
7465 mSurfacePendingDestroy = true;
7466 try {
7467 mClient.dispatchGetNewSurface();
7468 // We'll really destroy on the next time around.
7469 return;
7470 } catch (RemoteException e) {
7471 }
7472 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007475 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007476 RuntimeException e = null;
7477 if (!HIDE_STACK_CRAWLS) {
7478 e = new RuntimeException();
7479 e.fillInStackTrace();
7480 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007481 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007482 + mSurface + ", session " + mSession, e);
7483 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007485 RuntimeException e = null;
7486 if (!HIDE_STACK_CRAWLS) {
7487 e = new RuntimeException();
7488 e.fillInStackTrace();
7489 }
7490 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007492 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007493 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007494 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 + " surface " + mSurface + " session " + mSession
7496 + ": " + e.toString());
7497 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007498
Dianne Hackborn16064f92010-03-25 00:47:24 -07007499 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007501 }
7502 }
7503
7504 boolean finishDrawingLocked() {
7505 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007506 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 TAG, "finishDrawingLocked: " + mSurface);
7508 mCommitDrawPending = true;
7509 mDrawPending = false;
7510 return true;
7511 }
7512 return false;
7513 }
7514
7515 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007516 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007517 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007518 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007519 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 }
7521 mCommitDrawPending = false;
7522 mReadyToShow = true;
7523 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7524 final AppWindowToken atoken = mAppToken;
7525 if (atoken == null || atoken.allDrawn || starting) {
7526 performShowLocked();
7527 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007528 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 }
7530
7531 // This must be called while inside a transaction.
7532 boolean performShowLocked() {
7533 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007534 RuntimeException e = null;
7535 if (!HIDE_STACK_CRAWLS) {
7536 e = new RuntimeException();
7537 e.fillInStackTrace();
7538 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007539 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7541 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7542 }
7543 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007544 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7545 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007546 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 + " during animation: policyVis=" + mPolicyVisibility
7548 + " attHidden=" + mAttachedHidden
7549 + " tok.hiddenRequested="
7550 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007551 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007552 + (mAppToken != null ? mAppToken.hidden : false)
7553 + " animating=" + mAnimating
7554 + " tok animating="
7555 + (mAppToken != null ? mAppToken.animating : false));
7556 if (!showSurfaceRobustlyLocked(this)) {
7557 return false;
7558 }
7559 mLastAlpha = -1;
7560 mHasDrawn = true;
7561 mLastHidden = false;
7562 mReadyToShow = false;
7563 enableScreenIfNeededLocked();
7564
7565 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 int i = mChildWindows.size();
7568 while (i > 0) {
7569 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007570 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007571 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007573 if (c.mSurface != null) {
7574 c.performShowLocked();
7575 // It hadn't been shown, which means layout not
7576 // performed on it, so now we want to make sure to
7577 // do a layout. If called from within the transaction
7578 // loop, this will cause it to restart with a new
7579 // layout.
7580 mLayoutNeeded = true;
7581 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 }
7583 }
Romain Guy06882f82009-06-10 13:36:04 -07007584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 if (mAttrs.type != TYPE_APPLICATION_STARTING
7586 && mAppToken != null) {
7587 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007588
Dianne Hackborn248b1882009-09-16 16:46:44 -07007589 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007590 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007591 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007593 // If this initial window is animating, stop it -- we
7594 // will do an animation to reveal it from behind the
7595 // starting window, so there is no need for it to also
7596 // be doing its own stuff.
7597 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007598 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007599 mAnimation = null;
7600 // Make sure we clean up the animation.
7601 mAnimating = true;
7602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007603 mFinishedStarting.add(mAppToken);
7604 mH.sendEmptyMessage(H.FINISHED_STARTING);
7605 }
7606 mAppToken.updateReportedVisibilityLocked();
7607 }
7608 }
7609 return true;
7610 }
Romain Guy06882f82009-06-10 13:36:04 -07007611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 // This must be called while inside a transaction. Returns true if
7613 // there is more animation to run.
7614 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007615 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007616 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7619 mHasTransformation = true;
7620 mHasLocalTransformation = true;
7621 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007622 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007623 TAG, "Starting animation in " + this +
7624 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7625 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7626 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7627 mAnimation.setStartTime(currentTime);
7628 mLocalAnimating = true;
7629 mAnimating = true;
7630 }
7631 mTransformation.clear();
7632 final boolean more = mAnimation.getTransformation(
7633 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007634 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007635 TAG, "Stepped animation in " + this +
7636 ": more=" + more + ", xform=" + mTransformation);
7637 if (more) {
7638 // we're not done!
7639 return true;
7640 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007641 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007642 TAG, "Finished animation in " + this +
7643 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007644
7645 if (mAnimation != null) {
7646 mAnimation.cancel();
7647 mAnimation = null;
7648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007649 //WindowManagerService.this.dump();
7650 }
7651 mHasLocalTransformation = false;
7652 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007653 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007654 // When our app token is animating, we kind-of pretend like
7655 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7656 // part of this check means that we will only do this if
7657 // our window is not currently exiting, or it is not
7658 // locally animating itself. The idea being that one that
7659 // is exiting and doing a local animation should be removed
7660 // once that animation is done.
7661 mAnimating = true;
7662 mHasTransformation = true;
7663 mTransformation.clear();
7664 return false;
7665 } else if (mHasTransformation) {
7666 // Little trick to get through the path below to act like
7667 // we have finished an animation.
7668 mAnimating = true;
7669 } else if (isAnimating()) {
7670 mAnimating = true;
7671 }
7672 } else if (mAnimation != null) {
7673 // If the display is frozen, and there is a pending animation,
7674 // clear it and make sure we run the cleanup code.
7675 mAnimating = true;
7676 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007677 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 mAnimation = null;
7679 }
Romain Guy06882f82009-06-10 13:36:04 -07007680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007681 if (!mAnimating && !mLocalAnimating) {
7682 return false;
7683 }
7684
Joe Onorato8a9b2202010-02-26 18:56:32 -08007685 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 TAG, "Animation done in " + this + ": exiting=" + mExiting
7687 + ", reportedVisible="
7688 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 mAnimating = false;
7691 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007692 if (mAnimation != null) {
7693 mAnimation.cancel();
7694 mAnimation = null;
7695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 mAnimLayer = mLayer;
7697 if (mIsImWindow) {
7698 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007699 } else if (mIsWallpaper) {
7700 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007701 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007702 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007703 + " anim layer: " + mAnimLayer);
7704 mHasTransformation = false;
7705 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007706 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7707 if (DEBUG_VISIBILITY) {
7708 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7709 + mPolicyVisibilityAfterAnim);
7710 }
7711 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7712 if (!mPolicyVisibility) {
7713 if (mCurrentFocus == this) {
7714 mFocusMayChange = true;
7715 }
7716 // Window is no longer visible -- make sure if we were waiting
7717 // for it to be displayed before enabling the display, that
7718 // we allow the display to be enabled now.
7719 enableScreenIfNeededLocked();
7720 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007722 mTransformation.clear();
7723 if (mHasDrawn
7724 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7725 && mAppToken != null
7726 && mAppToken.firstWindowDrawn
7727 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007728 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007729 + mToken + ": first real window done animating");
7730 mFinishedStarting.add(mAppToken);
7731 mH.sendEmptyMessage(H.FINISHED_STARTING);
7732 }
Romain Guy06882f82009-06-10 13:36:04 -07007733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007734 finishExit();
7735
7736 if (mAppToken != null) {
7737 mAppToken.updateReportedVisibilityLocked();
7738 }
7739
7740 return false;
7741 }
7742
7743 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007744 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007745 TAG, "finishExit in " + this
7746 + ": exiting=" + mExiting
7747 + " remove=" + mRemoveOnExit
7748 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 final int N = mChildWindows.size();
7751 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007752 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 }
Romain Guy06882f82009-06-10 13:36:04 -07007754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007755 if (!mExiting) {
7756 return;
7757 }
Romain Guy06882f82009-06-10 13:36:04 -07007758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007759 if (isWindowAnimating()) {
7760 return;
7761 }
7762
Joe Onorato8a9b2202010-02-26 18:56:32 -08007763 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007764 TAG, "Exit animation finished in " + this
7765 + ": remove=" + mRemoveOnExit);
7766 if (mSurface != null) {
7767 mDestroySurface.add(this);
7768 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007769 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007770 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007771 try {
7772 mSurface.hide();
7773 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007774 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007775 }
7776 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007777 }
7778 mExiting = false;
7779 if (mRemoveOnExit) {
7780 mPendingRemove.add(this);
7781 mRemoveOnExit = false;
7782 }
7783 }
Romain Guy06882f82009-06-10 13:36:04 -07007784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007785 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7786 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7787 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7788 if (dtdx < -.000001f || dtdx > .000001f) return false;
7789 if (dsdy < -.000001f || dsdy > .000001f) return false;
7790 return true;
7791 }
Romain Guy06882f82009-06-10 13:36:04 -07007792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 void computeShownFrameLocked() {
7794 final boolean selfTransformation = mHasLocalTransformation;
7795 Transformation attachedTransformation =
7796 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7797 ? mAttachedWindow.mTransformation : null;
7798 Transformation appTransformation =
7799 (mAppToken != null && mAppToken.hasTransformation)
7800 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007801
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007802 // Wallpapers are animated based on the "real" window they
7803 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007804 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007805 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007806 if (mWallpaperTarget.mHasLocalTransformation &&
7807 mWallpaperTarget.mAnimation != null &&
7808 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007809 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007810 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007811 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007812 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007813 }
7814 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007815 mWallpaperTarget.mAppToken.hasTransformation &&
7816 mWallpaperTarget.mAppToken.animation != null &&
7817 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007818 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007819 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007820 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007821 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007822 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007824
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007825 final boolean screenAnimation = mScreenRotationAnimation != null
7826 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007827 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007828 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007829 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 final Rect frame = mFrame;
7831 final float tmpFloats[] = mTmpFloats;
7832 final Matrix tmpMatrix = mTmpMatrix;
7833
7834 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007835 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007836 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007837 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007839 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007841 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 }
7843 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007844 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007846 if (screenAnimation) {
7847 tmpMatrix.postConcat(
7848 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7849 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850
7851 // "convert" it into SurfaceFlinger's format
7852 // (a 2x2 matrix + an offset)
7853 // Here we must not transform the position of the surface
7854 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007855 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007856
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007857 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007858 tmpMatrix.getValues(tmpFloats);
7859 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007860 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7861 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007863 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7864 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007865 int w = frame.width();
7866 int h = frame.height();
7867 mShownFrame.set(x, y, x+w, y+h);
7868
7869 // Now set the alpha... but because our current hardware
7870 // can't do alpha transformation on a non-opaque surface,
7871 // turn it off if we are running an animation that is also
7872 // transforming since it is more important to have that
7873 // animation be smooth.
7874 mShownAlpha = mAlpha;
7875 if (!mLimitedAlphaCompositing
7876 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7877 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7878 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007879 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 if (selfTransformation) {
7881 mShownAlpha *= mTransformation.getAlpha();
7882 }
7883 if (attachedTransformation != null) {
7884 mShownAlpha *= attachedTransformation.getAlpha();
7885 }
7886 if (appTransformation != null) {
7887 mShownAlpha *= appTransformation.getAlpha();
7888 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007889 if (screenAnimation) {
7890 mShownAlpha *=
7891 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007893 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007894 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007895 }
Romain Guy06882f82009-06-10 13:36:04 -07007896
Joe Onorato8a9b2202010-02-26 18:56:32 -08007897 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 TAG, "Continuing animation in " + this +
7899 ": " + mShownFrame +
7900 ", alpha=" + mTransformation.getAlpha());
7901 return;
7902 }
Romain Guy06882f82009-06-10 13:36:04 -07007903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007904 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007905 if (mXOffset != 0 || mYOffset != 0) {
7906 mShownFrame.offset(mXOffset, mYOffset);
7907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007909 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007910 mDsDx = 1;
7911 mDtDx = 0;
7912 mDsDy = 0;
7913 mDtDy = 1;
7914 }
Romain Guy06882f82009-06-10 13:36:04 -07007915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 /**
7917 * Is this window visible? It is not visible if there is no
7918 * surface, or we are in the process of running an exit animation
7919 * that will remove the surface, or its app token has been hidden.
7920 */
7921 public boolean isVisibleLw() {
7922 final AppWindowToken atoken = mAppToken;
7923 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7924 && (atoken == null || !atoken.hiddenRequested)
7925 && !mExiting && !mDestroying;
7926 }
7927
7928 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007929 * Like {@link #isVisibleLw}, but also counts a window that is currently
7930 * "hidden" behind the keyguard as visible. This allows us to apply
7931 * things like window flags that impact the keyguard.
7932 * XXX I am starting to think we need to have ANOTHER visibility flag
7933 * for this "hidden behind keyguard" state rather than overloading
7934 * mPolicyVisibility. Ungh.
7935 */
7936 public boolean isVisibleOrBehindKeyguardLw() {
7937 final AppWindowToken atoken = mAppToken;
7938 return mSurface != null && !mAttachedHidden
7939 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007940 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007941 && !mExiting && !mDestroying;
7942 }
7943
7944 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007945 * Is this window visible, ignoring its app token? It is not visible
7946 * if there is no surface, or we are in the process of running an exit animation
7947 * that will remove the surface.
7948 */
7949 public boolean isWinVisibleLw() {
7950 final AppWindowToken atoken = mAppToken;
7951 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7952 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7953 && !mExiting && !mDestroying;
7954 }
7955
7956 /**
7957 * The same as isVisible(), but follows the current hidden state of
7958 * the associated app token, not the pending requested hidden state.
7959 */
7960 boolean isVisibleNow() {
7961 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007962 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007963 }
7964
7965 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007966 * Can this window possibly be a drag/drop target? The test here is
7967 * a combination of the above "visible now" with the check that the
7968 * Input Manager uses when discarding windows from input consideration.
7969 */
7970 boolean isPotentialDragTarget() {
7971 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7972 }
7973
7974 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007975 * Same as isVisible(), but we also count it as visible between the
7976 * call to IWindowSession.add() and the first relayout().
7977 */
7978 boolean isVisibleOrAdding() {
7979 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007980 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007981 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7982 && mPolicyVisibility && !mAttachedHidden
7983 && (atoken == null || !atoken.hiddenRequested)
7984 && !mExiting && !mDestroying;
7985 }
7986
7987 /**
7988 * Is this window currently on-screen? It is on-screen either if it
7989 * is visible or it is currently running an animation before no longer
7990 * being visible.
7991 */
7992 boolean isOnScreen() {
7993 final AppWindowToken atoken = mAppToken;
7994 if (atoken != null) {
7995 return mSurface != null && mPolicyVisibility && !mDestroying
7996 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007997 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007998 } else {
7999 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008000 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 }
8002 }
Romain Guy06882f82009-06-10 13:36:04 -07008003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 /**
8005 * Like isOnScreen(), but we don't return true if the window is part
8006 * of a transition that has not yet been started.
8007 */
8008 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008009 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008010 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07008011 return false;
8012 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008013 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008014 final boolean animating = atoken != null
8015 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008017 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
8018 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07008019 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008020 }
8021
8022 /** Is the window or its container currently animating? */
8023 boolean isAnimating() {
8024 final WindowState attached = mAttachedWindow;
8025 final AppWindowToken atoken = mAppToken;
8026 return mAnimation != null
8027 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07008028 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008029 (atoken.animation != null
8030 || atoken.inPendingTransaction));
8031 }
8032
8033 /** Is this window currently animating? */
8034 boolean isWindowAnimating() {
8035 return mAnimation != null;
8036 }
8037
8038 /**
8039 * Like isOnScreen, but returns false if the surface hasn't yet
8040 * been drawn.
8041 */
8042 public boolean isDisplayedLw() {
8043 final AppWindowToken atoken = mAppToken;
8044 return mSurface != null && mPolicyVisibility && !mDestroying
8045 && !mDrawPending && !mCommitDrawPending
8046 && ((!mAttachedHidden &&
8047 (atoken == null || !atoken.hiddenRequested))
8048 || mAnimating);
8049 }
8050
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008051 /**
8052 * Returns true if the window has a surface that it has drawn a
8053 * complete UI in to.
8054 */
8055 public boolean isDrawnLw() {
8056 final AppWindowToken atoken = mAppToken;
8057 return mSurface != null && !mDestroying
8058 && !mDrawPending && !mCommitDrawPending;
8059 }
8060
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008061 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07008062 * Return true if the window is opaque and fully drawn. This indicates
8063 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008064 */
8065 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07008066 return (mAttrs.format == PixelFormat.OPAQUE
8067 || mAttrs.type == TYPE_WALLPAPER)
8068 && mSurface != null && mAnimation == null
8069 && (mAppToken == null || mAppToken.animation == null)
8070 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008071 }
8072
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008073 /**
8074 * Return whether this window is wanting to have a translation
8075 * animation applied to it for an in-progress move. (Only makes
8076 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8077 */
8078 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008079 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008080 && (mFrame.top != mLastFrame.top
8081 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008082 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008083 && mPolicy.isScreenOn();
8084 }
8085
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008086 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8087 return
8088 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008089 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8090 // only if it's visible
8091 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008092 // and only if the application fills the compatible screen
8093 mFrame.left <= mCompatibleScreenFrame.left &&
8094 mFrame.top <= mCompatibleScreenFrame.top &&
8095 mFrame.right >= mCompatibleScreenFrame.right &&
8096 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008097 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008098 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008099 }
8100
8101 boolean isFullscreen(int screenWidth, int screenHeight) {
8102 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008103 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008104 }
8105
8106 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008107 disposeInputChannel();
8108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008109 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008110 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 mAttachedWindow.mChildWindows.remove(this);
8112 }
8113 destroySurfaceLocked();
8114 mSession.windowRemovedLocked();
8115 try {
8116 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8117 } catch (RuntimeException e) {
8118 // Ignore if it has already been removed (usually because
8119 // we are doing this as part of processing a death note.)
8120 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008121 }
8122
8123 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008124 if (mInputChannel != null) {
8125 mInputManager.unregisterInputChannel(mInputChannel);
8126
8127 mInputChannel.dispose();
8128 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 }
8131
8132 private class DeathRecipient implements IBinder.DeathRecipient {
8133 public void binderDied() {
8134 try {
8135 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008136 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008137 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008138 if (win != null) {
8139 removeWindowLocked(mSession, win);
8140 }
8141 }
8142 } catch (IllegalArgumentException ex) {
8143 // This will happen if the window has already been
8144 // removed.
8145 }
8146 }
8147 }
8148
8149 /** Returns true if this window desires key events. */
8150 public final boolean canReceiveKeys() {
8151 return isVisibleOrAdding()
8152 && (mViewVisibility == View.VISIBLE)
8153 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8154 }
8155
8156 public boolean hasDrawnLw() {
8157 return mHasDrawn;
8158 }
8159
8160 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008161 return showLw(doAnimation, true);
8162 }
8163
8164 boolean showLw(boolean doAnimation, boolean requestAnim) {
8165 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8166 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008168 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008169 if (doAnimation) {
8170 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8171 + mPolicyVisibility + " mAnimation=" + mAnimation);
8172 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8173 doAnimation = false;
8174 } else if (mPolicyVisibility && mAnimation == null) {
8175 // Check for the case where we are currently visible and
8176 // not animating; we do not want to do animation at such a
8177 // point to become visible when we already are.
8178 doAnimation = false;
8179 }
8180 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008181 mPolicyVisibility = true;
8182 mPolicyVisibilityAfterAnim = true;
8183 if (doAnimation) {
8184 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8185 }
8186 if (requestAnim) {
8187 requestAnimationLocked(0);
8188 }
8189 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008190 }
8191
8192 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008193 return hideLw(doAnimation, true);
8194 }
8195
8196 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008197 if (doAnimation) {
8198 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8199 doAnimation = false;
8200 }
8201 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008202 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8203 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008204 if (!current) {
8205 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008207 if (doAnimation) {
8208 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8209 if (mAnimation == null) {
8210 doAnimation = false;
8211 }
8212 }
8213 if (doAnimation) {
8214 mPolicyVisibilityAfterAnim = false;
8215 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008216 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008217 mPolicyVisibilityAfterAnim = false;
8218 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008219 // Window is no longer visible -- make sure if we were waiting
8220 // for it to be displayed before enabling the display, that
8221 // we allow the display to be enabled now.
8222 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008223 if (mCurrentFocus == this) {
8224 mFocusMayChange = true;
8225 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008226 }
8227 if (requestAnim) {
8228 requestAnimationLocked(0);
8229 }
8230 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008231 }
8232
Jeff Brownfbf09772011-01-16 14:06:57 -08008233 public void getTouchableRegion(Region outRegion) {
8234 final Rect frame = mFrame;
8235 switch (mTouchableInsets) {
8236 default:
8237 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8238 outRegion.set(frame);
8239 break;
8240 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8241 final Rect inset = mGivenContentInsets;
8242 outRegion.set(
8243 frame.left + inset.left, frame.top + inset.top,
8244 frame.right - inset.right, frame.bottom - inset.bottom);
8245 break;
8246 }
8247 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8248 final Rect inset = mGivenVisibleInsets;
8249 outRegion.set(
8250 frame.left + inset.left, frame.top + inset.top,
8251 frame.right - inset.right, frame.bottom - inset.bottom);
8252 break;
8253 }
8254 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8255 final Region givenTouchableRegion = mGivenTouchableRegion;
8256 outRegion.set(givenTouchableRegion);
8257 outRegion.translate(frame.left, frame.top);
8258 break;
8259 }
8260 }
8261 }
8262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008263 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008264 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8265 pw.print(" mClient="); pw.println(mClient.asBinder());
8266 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8267 if (mAttachedWindow != null || mLayoutAttached) {
8268 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8269 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8270 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008271 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8272 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8273 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008274 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8275 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008276 }
8277 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8278 pw.print(" mSubLayer="); pw.print(mSubLayer);
8279 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8280 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8281 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8282 pw.print("="); pw.print(mAnimLayer);
8283 pw.print(" mLastLayer="); pw.println(mLastLayer);
8284 if (mSurface != null) {
8285 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008286 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8287 pw.print(" layer="); pw.print(mSurfaceLayer);
8288 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8289 pw.print(" rect=("); pw.print(mSurfaceX);
8290 pw.print(","); pw.print(mSurfaceY);
8291 pw.print(") "); pw.print(mSurfaceW);
8292 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008293 }
8294 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8295 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8296 if (mAppToken != null) {
8297 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8298 }
8299 if (mTargetAppToken != null) {
8300 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8301 }
8302 pw.print(prefix); pw.print("mViewVisibility=0x");
8303 pw.print(Integer.toHexString(mViewVisibility));
8304 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008305 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8306 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008307 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8308 pw.print(prefix); pw.print("mPolicyVisibility=");
8309 pw.print(mPolicyVisibility);
8310 pw.print(" mPolicyVisibilityAfterAnim=");
8311 pw.print(mPolicyVisibilityAfterAnim);
8312 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8313 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008314 if (!mRelayoutCalled) {
8315 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8316 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008317 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008318 pw.print(" h="); pw.print(mRequestedHeight);
8319 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008320 if (mXOffset != 0 || mYOffset != 0) {
8321 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8322 pw.print(" y="); pw.println(mYOffset);
8323 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008324 pw.print(prefix); pw.print("mGivenContentInsets=");
8325 mGivenContentInsets.printShortString(pw);
8326 pw.print(" mGivenVisibleInsets=");
8327 mGivenVisibleInsets.printShortString(pw);
8328 pw.println();
8329 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8330 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8331 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8332 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008333 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008334 pw.print(prefix); pw.print("mShownFrame=");
8335 mShownFrame.printShortString(pw);
8336 pw.print(" last="); mLastShownFrame.printShortString(pw);
8337 pw.println();
8338 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8339 pw.print(" last="); mLastFrame.printShortString(pw);
8340 pw.println();
8341 pw.print(prefix); pw.print("mContainingFrame=");
8342 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008343 pw.print(" mParentFrame=");
8344 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008345 pw.print(" mDisplayFrame=");
8346 mDisplayFrame.printShortString(pw);
8347 pw.println();
8348 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8349 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8350 pw.println();
8351 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8352 pw.print(" last="); mLastContentInsets.printShortString(pw);
8353 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8354 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8355 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008356 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8357 || mAnimation != null) {
8358 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8359 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8360 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8361 pw.print(" mAnimation="); pw.println(mAnimation);
8362 }
8363 if (mHasTransformation || mHasLocalTransformation) {
8364 pw.print(prefix); pw.print("XForm: has=");
8365 pw.print(mHasTransformation);
8366 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8367 pw.print(" "); mTransformation.printShortString(pw);
8368 pw.println();
8369 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008370 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8371 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8372 pw.print(" mAlpha="); pw.print(mAlpha);
8373 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8374 }
8375 if (mHaveMatrix) {
8376 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8377 pw.print(" mDtDx="); pw.print(mDtDx);
8378 pw.print(" mDsDy="); pw.print(mDsDy);
8379 pw.print(" mDtDy="); pw.println(mDtDy);
8380 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008381 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8382 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8383 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8384 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8385 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8386 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8387 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8388 pw.print(" mDestroying="); pw.print(mDestroying);
8389 pw.print(" mRemoved="); pw.println(mRemoved);
8390 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008391 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008392 pw.print(prefix); pw.print("mOrientationChanging=");
8393 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008394 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8395 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008396 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008397 if (mHScale != 1 || mVScale != 1) {
8398 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8399 pw.print(" mVScale="); pw.println(mVScale);
8400 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008401 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008402 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8403 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8404 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008405 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8406 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8407 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008410
8411 String makeInputChannelName() {
8412 return Integer.toHexString(System.identityHashCode(this))
8413 + " " + mAttrs.getTitle();
8414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415
8416 @Override
8417 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008418 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8419 || mWasPaused != mToken.paused) {
8420 mLastTitle = mAttrs.getTitle();
8421 mWasPaused = mToken.paused;
8422 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8423 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8424 }
8425 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008426 }
8427 }
Romain Guy06882f82009-06-10 13:36:04 -07008428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008429 // -------------------------------------------------------------
8430 // Window Token State
8431 // -------------------------------------------------------------
8432
8433 class WindowToken {
8434 // The actual token.
8435 final IBinder token;
8436
8437 // The type of window this token is for, as per WindowManager.LayoutParams.
8438 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 // Set if this token was explicitly added by a client, so should
8441 // not be removed when all windows are removed.
8442 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008443
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008444 // For printing.
8445 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 // If this is an AppWindowToken, this is non-null.
8448 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 // All of the windows associated with this token.
8451 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8452
8453 // Is key dispatching paused for this token?
8454 boolean paused = false;
8455
8456 // Should this token's windows be hidden?
8457 boolean hidden;
8458
8459 // Temporary for finding which tokens no longer have visible windows.
8460 boolean hasVisible;
8461
Dianne Hackborna8f60182009-09-01 19:01:50 -07008462 // Set to true when this token is in a pending transaction where it
8463 // will be shown.
8464 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008465
Dianne Hackborna8f60182009-09-01 19:01:50 -07008466 // Set to true when this token is in a pending transaction where it
8467 // will be hidden.
8468 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008469
Dianne Hackborna8f60182009-09-01 19:01:50 -07008470 // Set to true when this token is in a pending transaction where its
8471 // windows will be put to the bottom of the list.
8472 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008473
Dianne Hackborna8f60182009-09-01 19:01:50 -07008474 // Set to true when this token is in a pending transaction where its
8475 // windows will be put to the top of the list.
8476 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008478 WindowToken(IBinder _token, int type, boolean _explicit) {
8479 token = _token;
8480 windowType = type;
8481 explicit = _explicit;
8482 }
8483
8484 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008485 pw.print(prefix); pw.print("token="); pw.println(token);
8486 pw.print(prefix); pw.print("windows="); pw.println(windows);
8487 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8488 pw.print(" hidden="); pw.print(hidden);
8489 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008490 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8491 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8492 pw.print(" waitingToHide="); pw.print(waitingToHide);
8493 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8494 pw.print(" sendingToTop="); pw.println(sendingToTop);
8495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008496 }
8497
8498 @Override
8499 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008500 if (stringName == null) {
8501 StringBuilder sb = new StringBuilder();
8502 sb.append("WindowToken{");
8503 sb.append(Integer.toHexString(System.identityHashCode(this)));
8504 sb.append(" token="); sb.append(token); sb.append('}');
8505 stringName = sb.toString();
8506 }
8507 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008508 }
8509 };
8510
8511 class AppWindowToken extends WindowToken {
8512 // Non-null only for application tokens.
8513 final IApplicationToken appToken;
8514
8515 // All of the windows and child windows that are included in this
8516 // application token. Note this list is NOT sorted!
8517 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8518
8519 int groupId = -1;
8520 boolean appFullscreen;
8521 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008522
8523 // The input dispatching timeout for this application token in nanoseconds.
8524 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 // These are used for determining when all windows associated with
8527 // an activity have been drawn, so they can be made visible together
8528 // at the same time.
8529 int lastTransactionSequence = mTransactionSequence-1;
8530 int numInterestingWindows;
8531 int numDrawnWindows;
8532 boolean inPendingTransaction;
8533 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 // Is this token going to be hidden in a little while? If so, it
8536 // won't be taken into account for setting the screen orientation.
8537 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 // Is this window's surface needed? This is almost like hidden, except
8540 // it will sometimes be true a little earlier: when the token has
8541 // been shown, but is still waiting for its app transition to execute
8542 // before making its windows shown.
8543 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 // Have we told the window clients to hide themselves?
8546 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 // Last visibility state we reported to the app token.
8549 boolean reportedVisible;
8550
8551 // Set to true when the token has been removed from the window mgr.
8552 boolean removed;
8553
8554 // Have we been asked to have this token keep the screen frozen?
8555 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008557 boolean animating;
8558 Animation animation;
8559 boolean hasTransformation;
8560 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008562 // Offset to the window of all layers in the token, for use by
8563 // AppWindowToken animations.
8564 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 // Information about an application starting window if displayed.
8567 StartingData startingData;
8568 WindowState startingWindow;
8569 View startingView;
8570 boolean startingDisplayed;
8571 boolean startingMoved;
8572 boolean firstWindowDrawn;
8573
Jeff Brown928e0542011-01-10 11:17:36 -08008574 // Input application handle used by the input dispatcher.
8575 InputApplicationHandle mInputApplicationHandle;
8576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 AppWindowToken(IApplicationToken _token) {
8578 super(_token.asBinder(),
8579 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8580 appWindowToken = this;
8581 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008582 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 }
Romain Guy06882f82009-06-10 13:36:04 -07008584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008585 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008586 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 TAG, "Setting animation in " + this + ": " + anim);
8588 animation = anim;
8589 animating = false;
8590 anim.restrictDuration(MAX_ANIMATION_DURATION);
8591 anim.scaleCurrentDuration(mTransitionAnimationScale);
8592 int zorder = anim.getZAdjustment();
8593 int adj = 0;
8594 if (zorder == Animation.ZORDER_TOP) {
8595 adj = TYPE_LAYER_OFFSET;
8596 } else if (zorder == Animation.ZORDER_BOTTOM) {
8597 adj = -TYPE_LAYER_OFFSET;
8598 }
Romain Guy06882f82009-06-10 13:36:04 -07008599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008600 if (animLayerAdjustment != adj) {
8601 animLayerAdjustment = adj;
8602 updateLayers();
8603 }
8604 }
Romain Guy06882f82009-06-10 13:36:04 -07008605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008606 public void setDummyAnimation() {
8607 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008608 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008609 TAG, "Setting dummy animation in " + this);
8610 animation = sDummyAnimation;
8611 }
8612 }
8613
8614 public void clearAnimation() {
8615 if (animation != null) {
8616 animation = null;
8617 animating = true;
8618 }
8619 }
Romain Guy06882f82009-06-10 13:36:04 -07008620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621 void updateLayers() {
8622 final int N = allAppWindows.size();
8623 final int adj = animLayerAdjustment;
8624 for (int i=0; i<N; i++) {
8625 WindowState w = allAppWindows.get(i);
8626 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008627 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008629 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 setInputMethodAnimLayerAdjustment(adj);
8631 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008632 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008633 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008635 }
8636 }
Romain Guy06882f82009-06-10 13:36:04 -07008637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 void sendAppVisibilityToClients() {
8639 final int N = allAppWindows.size();
8640 for (int i=0; i<N; i++) {
8641 WindowState win = allAppWindows.get(i);
8642 if (win == startingWindow && clientHidden) {
8643 // Don't hide the starting window.
8644 continue;
8645 }
8646 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008647 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 "Setting visibility of " + win + ": " + (!clientHidden));
8649 win.mClient.dispatchAppVisibility(!clientHidden);
8650 } catch (RemoteException e) {
8651 }
8652 }
8653 }
Romain Guy06882f82009-06-10 13:36:04 -07008654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 void showAllWindowsLocked() {
8656 final int NW = allAppWindows.size();
8657 for (int i=0; i<NW; i++) {
8658 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008659 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008660 "performing show on: " + w);
8661 w.performShowLocked();
8662 }
8663 }
Romain Guy06882f82009-06-10 13:36:04 -07008664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008665 // This must be called while inside a transaction.
8666 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008667 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008670 if (animation == sDummyAnimation) {
8671 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008672 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 // when it is really time to animate, this will be set to
8674 // a real animation and the next call will execute normally.
8675 return false;
8676 }
Romain Guy06882f82009-06-10 13:36:04 -07008677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008678 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8679 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008680 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008681 TAG, "Starting animation in " + this +
8682 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8683 + " scale=" + mTransitionAnimationScale
8684 + " allDrawn=" + allDrawn + " animating=" + animating);
8685 animation.initialize(dw, dh, dw, dh);
8686 animation.setStartTime(currentTime);
8687 animating = true;
8688 }
8689 transformation.clear();
8690 final boolean more = animation.getTransformation(
8691 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008692 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008693 TAG, "Stepped animation in " + this +
8694 ": more=" + more + ", xform=" + transformation);
8695 if (more) {
8696 // we're done!
8697 hasTransformation = true;
8698 return true;
8699 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008700 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008701 TAG, "Finished animation in " + this +
8702 " @ " + currentTime);
8703 animation = null;
8704 }
8705 } else if (animation != null) {
8706 // If the display is frozen, and there is a pending animation,
8707 // clear it and make sure we run the cleanup code.
8708 animating = true;
8709 animation = null;
8710 }
8711
8712 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 if (!animating) {
8715 return false;
8716 }
8717
8718 clearAnimation();
8719 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008720 if (animLayerAdjustment != 0) {
8721 animLayerAdjustment = 0;
8722 updateLayers();
8723 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8725 moveInputMethodWindowsIfNeededLocked(true);
8726 }
Romain Guy06882f82009-06-10 13:36:04 -07008727
Joe Onorato8a9b2202010-02-26 18:56:32 -08008728 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 TAG, "Animation done in " + this
8730 + ": reportedVisible=" + reportedVisible);
8731
8732 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008734 final int N = windows.size();
8735 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008736 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008737 }
8738 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008740 return false;
8741 }
8742
8743 void updateReportedVisibilityLocked() {
8744 if (appToken == null) {
8745 return;
8746 }
Romain Guy06882f82009-06-10 13:36:04 -07008747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008748 int numInteresting = 0;
8749 int numVisible = 0;
8750 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008751
Joe Onorato8a9b2202010-02-26 18:56:32 -08008752 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008753 final int N = allAppWindows.size();
8754 for (int i=0; i<N; i++) {
8755 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008756 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008757 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008758 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8759 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008760 continue;
8761 }
8762 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008763 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008764 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008765 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008766 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008767 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768 + " pv=" + win.mPolicyVisibility
8769 + " dp=" + win.mDrawPending
8770 + " cdp=" + win.mCommitDrawPending
8771 + " ah=" + win.mAttachedHidden
8772 + " th="
8773 + (win.mAppToken != null
8774 ? win.mAppToken.hiddenRequested : false)
8775 + " a=" + win.mAnimating);
8776 }
8777 }
8778 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008779 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008780 if (!win.isAnimating()) {
8781 numVisible++;
8782 }
8783 nowGone = false;
8784 } else if (win.isAnimating()) {
8785 nowGone = false;
8786 }
8787 }
Romain Guy06882f82009-06-10 13:36:04 -07008788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008789 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008790 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008791 + numInteresting + " visible=" + numVisible);
8792 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008793 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008794 TAG, "Visibility changed in " + this
8795 + ": vis=" + nowVisible);
8796 reportedVisible = nowVisible;
8797 Message m = mH.obtainMessage(
8798 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8799 nowVisible ? 1 : 0,
8800 nowGone ? 1 : 0,
8801 this);
8802 mH.sendMessage(m);
8803 }
8804 }
Romain Guy06882f82009-06-10 13:36:04 -07008805
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008806 WindowState findMainWindow() {
8807 int j = windows.size();
8808 while (j > 0) {
8809 j--;
8810 WindowState win = windows.get(j);
8811 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8812 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8813 return win;
8814 }
8815 }
8816 return null;
8817 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008819 void dump(PrintWriter pw, String prefix) {
8820 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008821 if (appToken != null) {
8822 pw.print(prefix); pw.println("app=true");
8823 }
8824 if (allAppWindows.size() > 0) {
8825 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8826 }
8827 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008828 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008829 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8830 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8831 pw.print(" clientHidden="); pw.print(clientHidden);
8832 pw.print(" willBeHidden="); pw.print(willBeHidden);
8833 pw.print(" reportedVisible="); pw.println(reportedVisible);
8834 if (paused || freezingScreen) {
8835 pw.print(prefix); pw.print("paused="); pw.print(paused);
8836 pw.print(" freezingScreen="); pw.println(freezingScreen);
8837 }
8838 if (numInterestingWindows != 0 || numDrawnWindows != 0
8839 || inPendingTransaction || allDrawn) {
8840 pw.print(prefix); pw.print("numInterestingWindows=");
8841 pw.print(numInterestingWindows);
8842 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8843 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8844 pw.print(" allDrawn="); pw.println(allDrawn);
8845 }
8846 if (animating || animation != null) {
8847 pw.print(prefix); pw.print("animating="); pw.print(animating);
8848 pw.print(" animation="); pw.println(animation);
8849 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008850 if (hasTransformation) {
8851 pw.print(prefix); pw.print("XForm: ");
8852 transformation.printShortString(pw);
8853 pw.println();
8854 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008855 if (animLayerAdjustment != 0) {
8856 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8857 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008858 if (startingData != null || removed || firstWindowDrawn) {
8859 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8860 pw.print(" removed="); pw.print(removed);
8861 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8862 }
8863 if (startingWindow != null || startingView != null
8864 || startingDisplayed || startingMoved) {
8865 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8866 pw.print(" startingView="); pw.print(startingView);
8867 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8868 pw.print(" startingMoved"); pw.println(startingMoved);
8869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008870 }
8871
8872 @Override
8873 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008874 if (stringName == null) {
8875 StringBuilder sb = new StringBuilder();
8876 sb.append("AppWindowToken{");
8877 sb.append(Integer.toHexString(System.identityHashCode(this)));
8878 sb.append(" token="); sb.append(token); sb.append('}');
8879 stringName = sb.toString();
8880 }
8881 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008882 }
8883 }
Romain Guy06882f82009-06-10 13:36:04 -07008884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 // -------------------------------------------------------------
8886 // DummyAnimation
8887 // -------------------------------------------------------------
8888
8889 // This is an animation that does nothing: it just immediately finishes
8890 // itself every time it is called. It is used as a stub animation in cases
8891 // where we want to synchronize multiple things that may be animating.
8892 static final class DummyAnimation extends Animation {
8893 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8894 return false;
8895 }
8896 }
8897 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008899 // -------------------------------------------------------------
8900 // Async Handler
8901 // -------------------------------------------------------------
8902
8903 static final class StartingData {
8904 final String pkg;
8905 final int theme;
8906 final CharSequence nonLocalizedLabel;
8907 final int labelRes;
8908 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008909 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008911 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008912 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008913 pkg = _pkg;
8914 theme = _theme;
8915 nonLocalizedLabel = _nonLocalizedLabel;
8916 labelRes = _labelRes;
8917 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008918 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008919 }
8920 }
8921
8922 private final class H extends Handler {
8923 public static final int REPORT_FOCUS_CHANGE = 2;
8924 public static final int REPORT_LOSING_FOCUS = 3;
8925 public static final int ANIMATE = 4;
8926 public static final int ADD_STARTING = 5;
8927 public static final int REMOVE_STARTING = 6;
8928 public static final int FINISHED_STARTING = 7;
8929 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008930 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8931 public static final int HOLD_SCREEN_CHANGED = 12;
8932 public static final int APP_TRANSITION_TIMEOUT = 13;
8933 public static final int PERSIST_ANIMATION_SCALE = 14;
8934 public static final int FORCE_GC = 15;
8935 public static final int ENABLE_SCREEN = 16;
8936 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008937 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008938 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008939 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008940 public static final int DRAG_END_TIMEOUT = 21;
Jeff Brown2992ea72011-01-28 22:04:14 -08008941 public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
Romain Guy06882f82009-06-10 13:36:04 -07008942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 public H() {
8946 }
Romain Guy06882f82009-06-10 13:36:04 -07008947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008948 @Override
8949 public void handleMessage(Message msg) {
8950 switch (msg.what) {
8951 case REPORT_FOCUS_CHANGE: {
8952 WindowState lastFocus;
8953 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008955 synchronized(mWindowMap) {
8956 lastFocus = mLastFocus;
8957 newFocus = mCurrentFocus;
8958 if (lastFocus == newFocus) {
8959 // Focus is not changing, so nothing to do.
8960 return;
8961 }
8962 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008963 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008964 // + " to " + newFocus);
8965 if (newFocus != null && lastFocus != null
8966 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008967 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008968 mLosingFocus.add(lastFocus);
8969 lastFocus = null;
8970 }
8971 }
8972
8973 if (lastFocus != newFocus) {
8974 //System.out.println("Changing focus from " + lastFocus
8975 // + " to " + newFocus);
8976 if (newFocus != null) {
8977 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008978 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008979 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8980 } catch (RemoteException e) {
8981 // Ignore if process has died.
8982 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008983 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 }
8985
8986 if (lastFocus != null) {
8987 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008988 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008989 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8990 } catch (RemoteException e) {
8991 // Ignore if process has died.
8992 }
8993 }
Joe Onorato664644d2011-01-23 17:53:23 -08008994
8995 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008996 }
8997 } break;
8998
8999 case REPORT_LOSING_FOCUS: {
9000 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07009001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 synchronized(mWindowMap) {
9003 losers = mLosingFocus;
9004 mLosingFocus = new ArrayList<WindowState>();
9005 }
9006
9007 final int N = losers.size();
9008 for (int i=0; i<N; i++) {
9009 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009010 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009011 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
9012 } catch (RemoteException e) {
9013 // Ignore if process has died.
9014 }
9015 }
9016 } break;
9017
9018 case ANIMATE: {
9019 synchronized(mWindowMap) {
9020 mAnimationPending = false;
9021 performLayoutAndPlaceSurfacesLocked();
9022 }
9023 } break;
9024
9025 case ADD_STARTING: {
9026 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9027 final StartingData sd = wtoken.startingData;
9028
9029 if (sd == null) {
9030 // Animation has been canceled... do nothing.
9031 return;
9032 }
Romain Guy06882f82009-06-10 13:36:04 -07009033
Joe Onorato8a9b2202010-02-26 18:56:32 -08009034 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07009036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009037 View view = null;
9038 try {
9039 view = mPolicy.addStartingWindow(
9040 wtoken.token, sd.pkg,
9041 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08009042 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009043 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009044 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009045 }
9046
9047 if (view != null) {
9048 boolean abort = false;
9049
9050 synchronized(mWindowMap) {
9051 if (wtoken.removed || wtoken.startingData == null) {
9052 // If the window was successfully added, then
9053 // we need to remove it.
9054 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009055 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009056 "Aborted starting " + wtoken
9057 + ": removed=" + wtoken.removed
9058 + " startingData=" + wtoken.startingData);
9059 wtoken.startingWindow = null;
9060 wtoken.startingData = null;
9061 abort = true;
9062 }
9063 } else {
9064 wtoken.startingView = view;
9065 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009066 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009067 "Added starting " + wtoken
9068 + ": startingWindow="
9069 + wtoken.startingWindow + " startingView="
9070 + wtoken.startingView);
9071 }
9072
9073 if (abort) {
9074 try {
9075 mPolicy.removeStartingWindow(wtoken.token, view);
9076 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009077 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009078 }
9079 }
9080 }
9081 } break;
9082
9083 case REMOVE_STARTING: {
9084 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9085 IBinder token = null;
9086 View view = null;
9087 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009088 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009089 + wtoken + ": startingWindow="
9090 + wtoken.startingWindow + " startingView="
9091 + wtoken.startingView);
9092 if (wtoken.startingWindow != null) {
9093 view = wtoken.startingView;
9094 token = wtoken.token;
9095 wtoken.startingData = null;
9096 wtoken.startingView = null;
9097 wtoken.startingWindow = null;
9098 }
9099 }
9100 if (view != null) {
9101 try {
9102 mPolicy.removeStartingWindow(token, view);
9103 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009104 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009105 }
9106 }
9107 } break;
9108
9109 case FINISHED_STARTING: {
9110 IBinder token = null;
9111 View view = null;
9112 while (true) {
9113 synchronized (mWindowMap) {
9114 final int N = mFinishedStarting.size();
9115 if (N <= 0) {
9116 break;
9117 }
9118 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9119
Joe Onorato8a9b2202010-02-26 18:56:32 -08009120 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009121 "Finished starting " + wtoken
9122 + ": startingWindow=" + wtoken.startingWindow
9123 + " startingView=" + wtoken.startingView);
9124
9125 if (wtoken.startingWindow == null) {
9126 continue;
9127 }
9128
9129 view = wtoken.startingView;
9130 token = wtoken.token;
9131 wtoken.startingData = null;
9132 wtoken.startingView = null;
9133 wtoken.startingWindow = null;
9134 }
9135
9136 try {
9137 mPolicy.removeStartingWindow(token, view);
9138 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009139 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009140 }
9141 }
9142 } break;
9143
9144 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9145 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9146
9147 boolean nowVisible = msg.arg1 != 0;
9148 boolean nowGone = msg.arg2 != 0;
9149
9150 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009151 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009152 TAG, "Reporting visible in " + wtoken
9153 + " visible=" + nowVisible
9154 + " gone=" + nowGone);
9155 if (nowVisible) {
9156 wtoken.appToken.windowsVisible();
9157 } else {
9158 wtoken.appToken.windowsGone();
9159 }
9160 } catch (RemoteException ex) {
9161 }
9162 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009164 case WINDOW_FREEZE_TIMEOUT: {
9165 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009166 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009167 int i = mWindows.size();
9168 while (i > 0) {
9169 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009170 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 if (w.mOrientationChanging) {
9172 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009173 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 }
9175 }
9176 performLayoutAndPlaceSurfacesLocked();
9177 }
9178 break;
9179 }
Romain Guy06882f82009-06-10 13:36:04 -07009180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 case HOLD_SCREEN_CHANGED: {
9182 Session oldHold;
9183 Session newHold;
9184 synchronized (mWindowMap) {
9185 oldHold = mLastReportedHold;
9186 newHold = (Session)msg.obj;
9187 mLastReportedHold = newHold;
9188 }
Romain Guy06882f82009-06-10 13:36:04 -07009189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009190 if (oldHold != newHold) {
9191 try {
9192 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009193 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009194 "window",
9195 BatteryStats.WAKE_TYPE_WINDOW);
9196 }
9197 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009198 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 "window",
9200 BatteryStats.WAKE_TYPE_WINDOW);
9201 }
9202 } catch (RemoteException e) {
9203 }
9204 }
9205 break;
9206 }
Romain Guy06882f82009-06-10 13:36:04 -07009207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009208 case APP_TRANSITION_TIMEOUT: {
9209 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009210 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009211 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009212 "*** APP TRANSITION TIMEOUT");
9213 mAppTransitionReady = true;
9214 mAppTransitionTimeout = true;
9215 performLayoutAndPlaceSurfacesLocked();
9216 }
9217 }
9218 break;
9219 }
Romain Guy06882f82009-06-10 13:36:04 -07009220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009221 case PERSIST_ANIMATION_SCALE: {
9222 Settings.System.putFloat(mContext.getContentResolver(),
9223 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9224 Settings.System.putFloat(mContext.getContentResolver(),
9225 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9226 break;
9227 }
Romain Guy06882f82009-06-10 13:36:04 -07009228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009229 case FORCE_GC: {
9230 synchronized(mWindowMap) {
9231 if (mAnimationPending) {
9232 // If we are animating, don't do the gc now but
9233 // delay a bit so we don't interrupt the animation.
9234 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9235 2000);
9236 return;
9237 }
9238 // If we are currently rotating the display, it will
9239 // schedule a new message when done.
9240 if (mDisplayFrozen) {
9241 return;
9242 }
9243 mFreezeGcPending = 0;
9244 }
9245 Runtime.getRuntime().gc();
9246 break;
9247 }
Romain Guy06882f82009-06-10 13:36:04 -07009248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 case ENABLE_SCREEN: {
9250 performEnableScreen();
9251 break;
9252 }
Romain Guy06882f82009-06-10 13:36:04 -07009253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254 case APP_FREEZE_TIMEOUT: {
9255 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009256 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009257 int i = mAppTokens.size();
9258 while (i > 0) {
9259 i--;
9260 AppWindowToken tok = mAppTokens.get(i);
9261 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009262 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009263 unsetAppFreezingScreenLocked(tok, true, true);
9264 }
9265 }
9266 }
9267 break;
9268 }
Romain Guy06882f82009-06-10 13:36:04 -07009269
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009270 case SEND_NEW_CONFIGURATION: {
9271 removeMessages(SEND_NEW_CONFIGURATION);
9272 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009273 break;
9274 }
Romain Guy06882f82009-06-10 13:36:04 -07009275
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009276 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009277 if (mWindowsChanged) {
9278 synchronized (mWindowMap) {
9279 mWindowsChanged = false;
9280 }
9281 notifyWindowsChanged();
9282 }
9283 break;
9284 }
9285
Christopher Tatea53146c2010-09-07 11:57:52 -07009286 case DRAG_START_TIMEOUT: {
9287 IBinder win = (IBinder)msg.obj;
9288 if (DEBUG_DRAG) {
9289 Slog.w(TAG, "Timeout starting drag by win " + win);
9290 }
9291 synchronized (mWindowMap) {
9292 // !!! TODO: ANR the app that has failed to start the drag in time
9293 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009294 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009295 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009296 mDragState.reset();
9297 mDragState = null;
9298 }
9299 }
Chris Tated4533f142010-10-19 15:15:08 -07009300 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009301 }
9302
Chris Tated4533f142010-10-19 15:15:08 -07009303 case DRAG_END_TIMEOUT: {
9304 IBinder win = (IBinder)msg.obj;
9305 if (DEBUG_DRAG) {
9306 Slog.w(TAG, "Timeout ending drag to win " + win);
9307 }
9308 synchronized (mWindowMap) {
9309 // !!! TODO: ANR the drag-receiving app
9310 mDragState.mDragResult = false;
9311 mDragState.endDragLw();
9312 }
9313 break;
9314 }
Jeff Brown2992ea72011-01-28 22:04:14 -08009315
9316 case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
9317 notifyHardKeyboardStatusChange();
9318 break;
9319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 }
9321 }
9322 }
9323
9324 // -------------------------------------------------------------
9325 // IWindowManager API
9326 // -------------------------------------------------------------
9327
9328 public IWindowSession openSession(IInputMethodClient client,
9329 IInputContext inputContext) {
9330 if (client == null) throw new IllegalArgumentException("null client");
9331 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009332 Session session = new Session(client, inputContext);
9333 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009334 }
9335
9336 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9337 synchronized (mWindowMap) {
9338 // The focus for the client is the window immediately below
9339 // where we would place the input method window.
9340 int idx = findDesiredInputMethodWindowIndexLocked(false);
9341 WindowState imFocus;
9342 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009343 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009344 //Log.i(TAG, "Desired input method target: " + imFocus);
9345 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9346 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009348 // This may be a starting window, in which case we still want
9349 // to count it as okay.
9350 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9351 && imFocus.mAppToken != null) {
9352 // The client has definitely started, so it really should
9353 // have a window in this app token. Let's look for it.
9354 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9355 WindowState w = imFocus.mAppToken.windows.get(i);
9356 if (w != imFocus) {
9357 //Log.i(TAG, "Switching to real app window: " + w);
9358 imFocus = w;
9359 break;
9360 }
9361 }
9362 }
9363 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9364 //if (imFocus.mSession.mClient != null) {
9365 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9366 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9367 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009368 if (imFocus.mSession.mClient != null &&
9369 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9370 return true;
9371 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009372
9373 // Okay, how about this... what is the current focus?
9374 // It seems in some cases we may not have moved the IM
9375 // target window, such as when it was in a pop-up window,
9376 // so let's also look at the current focus. (An example:
9377 // go to Gmail, start searching so the keyboard goes up,
9378 // press home. Sometimes the IME won't go down.)
9379 // Would be nice to fix this more correctly, but it's
9380 // way at the end of a release, and this should be good enough.
9381 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9382 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9383 return true;
9384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009385 }
9386 }
9387 }
9388 return false;
9389 }
Romain Guy06882f82009-06-10 13:36:04 -07009390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009391 // -------------------------------------------------------------
9392 // Internals
9393 // -------------------------------------------------------------
9394
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009395 final WindowState windowForClientLocked(Session session, IWindow client,
9396 boolean throwOnError) {
9397 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009398 }
Romain Guy06882f82009-06-10 13:36:04 -07009399
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009400 final WindowState windowForClientLocked(Session session, IBinder client,
9401 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009402 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009403 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 TAG, "Looking up client " + client + ": " + win);
9405 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009406 RuntimeException ex = new IllegalArgumentException(
9407 "Requested window " + client + " does not exist");
9408 if (throwOnError) {
9409 throw ex;
9410 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009411 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009412 return null;
9413 }
9414 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009415 RuntimeException ex = new IllegalArgumentException(
9416 "Requested window " + client + " is in session " +
9417 win.mSession + ", not " + session);
9418 if (throwOnError) {
9419 throw ex;
9420 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009421 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 return null;
9423 }
9424
9425 return win;
9426 }
9427
Dianne Hackborna8f60182009-09-01 19:01:50 -07009428 final void rebuildAppWindowListLocked() {
9429 int NW = mWindows.size();
9430 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009431 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009432 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009433
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009434 if (mRebuildTmp.length < NW) {
9435 mRebuildTmp = new WindowState[NW+10];
9436 }
9437
Dianne Hackborna8f60182009-09-01 19:01:50 -07009438 // First remove all existing app windows.
9439 i=0;
9440 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009441 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009442 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009443 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009444 win.mRebuilding = true;
9445 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009446 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009447 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009448 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009449 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009450 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009451 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009452 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9453 && lastWallpaper == i-1) {
9454 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009455 }
9456 i++;
9457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009458
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009459 // The wallpaper window(s) typically live at the bottom of the stack,
9460 // so skip them before adding app tokens.
9461 lastWallpaper++;
9462 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009463
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009464 // First add all of the exiting app tokens... these are no longer
9465 // in the main app list, but still have windows shown. We put them
9466 // in the back because now that the animation is over we no longer
9467 // will care about them.
9468 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009469 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009470 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9471 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009472
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009473 // And add in the still active app tokens in Z order.
9474 NT = mAppTokens.size();
9475 for (int j=0; j<NT; j++) {
9476 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009477 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009478
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009479 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009480 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009481 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009482 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009483 for (i=0; i<numRemoved; i++) {
9484 WindowState ws = mRebuildTmp[i];
9485 if (ws.mRebuilding) {
9486 StringWriter sw = new StringWriter();
9487 PrintWriter pw = new PrintWriter(sw);
9488 ws.dump(pw, "");
9489 pw.flush();
9490 Slog.w(TAG, "This window was lost: " + ws);
9491 Slog.w(TAG, sw.toString());
9492 }
9493 }
9494 Slog.w(TAG, "Current app token list:");
9495 dumpAppTokensLocked();
9496 Slog.w(TAG, "Final window list:");
9497 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009498 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009499 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009501 private final void assignLayersLocked() {
9502 int N = mWindows.size();
9503 int curBaseLayer = 0;
9504 int curLayer = 0;
9505 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009506
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009507 if (DEBUG_LAYERS) {
9508 RuntimeException here = new RuntimeException("here");
9509 here.fillInStackTrace();
9510 Log.v(TAG, "Assigning layers", here);
9511 }
9512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009513 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009514 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009515 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9516 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009517 curLayer += WINDOW_LAYER_MULTIPLIER;
9518 w.mLayer = curLayer;
9519 } else {
9520 curBaseLayer = curLayer = w.mBaseLayer;
9521 w.mLayer = curLayer;
9522 }
9523 if (w.mTargetAppToken != null) {
9524 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9525 } else if (w.mAppToken != null) {
9526 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9527 } else {
9528 w.mAnimLayer = w.mLayer;
9529 }
9530 if (w.mIsImWindow) {
9531 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009532 } else if (w.mIsWallpaper) {
9533 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009535 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009536 + w.mAnimLayer);
9537 //System.out.println(
9538 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9539 }
9540 }
9541
9542 private boolean mInLayout = false;
9543 private final void performLayoutAndPlaceSurfacesLocked() {
9544 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009545 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009546 throw new RuntimeException("Recursive call!");
9547 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009548 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009549 return;
9550 }
9551
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009552 if (mWaitingForConfig) {
9553 // Our configuration has changed (most likely rotation), but we
9554 // don't yet have the complete configuration to report to
9555 // applications. Don't do any window layout until we have it.
9556 return;
9557 }
9558
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009559 if (mDisplay == null) {
9560 // Not yet initialized, nothing to do.
9561 return;
9562 }
9563
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009564 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009566
9567 try {
9568 if (mForceRemoves != null) {
9569 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009570 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009571 for (int i=0; i<mForceRemoves.size(); i++) {
9572 WindowState ws = mForceRemoves.get(i);
9573 Slog.i(TAG, "Force removing: " + ws);
9574 removeWindowInnerLocked(ws.mSession, ws);
9575 }
9576 mForceRemoves = null;
9577 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9578 Object tmp = new Object();
9579 synchronized (tmp) {
9580 try {
9581 tmp.wait(250);
9582 } catch (InterruptedException e) {
9583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009584 }
9585 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009586 } catch (RuntimeException e) {
9587 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009590 try {
9591 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009592
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009593 int N = mPendingRemove.size();
9594 if (N > 0) {
9595 if (mPendingRemoveTmp.length < N) {
9596 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009597 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009598 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009599 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009600 for (int i=0; i<N; i++) {
9601 WindowState w = mPendingRemoveTmp[i];
9602 removeWindowInnerLocked(w.mSession, w);
9603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009604
9605 mInLayout = false;
9606 assignLayersLocked();
9607 mLayoutNeeded = true;
9608 performLayoutAndPlaceSurfacesLocked();
9609
9610 } else {
9611 mInLayout = false;
9612 if (mLayoutNeeded) {
9613 requestAnimationLocked(0);
9614 }
9615 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009616 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009617 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9618 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009620 } catch (RuntimeException e) {
9621 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009622 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009623 }
9624 }
9625
Jeff Brown3a22cd92011-01-21 13:59:04 -08009626 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009627 if (!mLayoutNeeded) {
9628 return 0;
9629 }
9630
9631 mLayoutNeeded = false;
9632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 final int dw = mDisplay.getWidth();
9634 final int dh = mDisplay.getHeight();
9635
9636 final int N = mWindows.size();
9637 int i;
9638
Joe Onorato8a9b2202010-02-26 18:56:32 -08009639 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009640 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9641
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009642 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009643
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009644 int seq = mLayoutSeq+1;
9645 if (seq < 0) seq = 0;
9646 mLayoutSeq = seq;
9647
9648 // First perform layout of any root windows (not attached
9649 // to another window).
9650 int topAttached = -1;
9651 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009652 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009653
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009654 // Don't do layout of a window if it is not visible, or
9655 // soon won't be visible, to avoid wasting time and funky
9656 // changes while a window is animating away.
9657 final AppWindowToken atoken = win.mAppToken;
9658 final boolean gone = win.mViewVisibility == View.GONE
9659 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009660 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009661 || (atoken != null && atoken.hiddenRequested)
9662 || win.mAttachedHidden
9663 || win.mExiting || win.mDestroying;
9664
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009665 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9666 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009667 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9668 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009669 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009670 + win.mViewVisibility + " mRelayoutCalled="
9671 + win.mRelayoutCalled + " hidden="
9672 + win.mRootToken.hidden + " hiddenRequested="
9673 + (atoken != null && atoken.hiddenRequested)
9674 + " mAttachedHidden=" + win.mAttachedHidden);
9675 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009676
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009677 // If this view is GONE, then skip it -- keep the current
9678 // frame, and let the caller know so they can ignore it
9679 // if they want. (We do the normal layout for INVISIBLE
9680 // windows, since that means "perform layout as normal,
9681 // just don't display").
9682 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009683 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009684 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009685 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009686 win.mContentChanged = false;
9687 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009688 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9689 win.mLayoutSeq = seq;
9690 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9691 + win.mFrame + " mContainingFrame="
9692 + win.mContainingFrame + " mDisplayFrame="
9693 + win.mDisplayFrame);
9694 } else {
9695 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009696 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009697 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009698 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009699
9700 // Now perform layout of attached windows, which usually
9701 // depend on the position of the window they are attached to.
9702 // XXX does not deal with windows that are attached to windows
9703 // that are themselves attached.
9704 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009705 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009706
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009707 if (win.mLayoutAttached) {
9708 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9709 + " mHaveFrame=" + win.mHaveFrame
9710 + " mViewVisibility=" + win.mViewVisibility
9711 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009712 // If this view is GONE, then skip it -- keep the current
9713 // frame, and let the caller know so they can ignore it
9714 // if they want. (We do the normal layout for INVISIBLE
9715 // windows, since that means "perform layout as normal,
9716 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009717 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9718 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009719 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009720 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009721 win.mContentChanged = false;
9722 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009723 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9724 win.mLayoutSeq = seq;
9725 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9726 + win.mFrame + " mContainingFrame="
9727 + win.mContainingFrame + " mDisplayFrame="
9728 + win.mDisplayFrame);
9729 }
9730 }
9731 }
Jeff Brown349703e2010-06-22 01:27:15 -07009732
9733 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009734 mInputMonitor.setUpdateInputWindowsNeededLw();
9735 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009736 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009737 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009738
9739 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009740 }
Romain Guy06882f82009-06-10 13:36:04 -07009741
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009742 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009743 private final void performLayoutAndPlaceSurfacesLockedInner(
9744 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009745 if (mDisplay == null) {
9746 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9747 return;
9748 }
9749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009750 final long currentTime = SystemClock.uptimeMillis();
9751 final int dw = mDisplay.getWidth();
9752 final int dh = mDisplay.getHeight();
9753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009754 int i;
9755
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009756 if (mFocusMayChange) {
9757 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009758 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9759 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009760 }
9761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009762 // Initialize state of exiting tokens.
9763 for (i=mExitingTokens.size()-1; i>=0; i--) {
9764 mExitingTokens.get(i).hasVisible = false;
9765 }
9766
9767 // Initialize state of exiting applications.
9768 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9769 mExitingAppTokens.get(i).hasVisible = false;
9770 }
9771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 boolean orientationChangeComplete = true;
9773 Session holdScreen = null;
9774 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009775 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009776 boolean focusDisplayed = false;
9777 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009778 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009779 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009780
9781 if (mFxSession == null) {
9782 mFxSession = new SurfaceSession();
9783 createWatermark = true;
9784 }
9785
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009786 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787
9788 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009789
9790 if (createWatermark) {
9791 createWatermark();
9792 }
9793 if (mWatermark != null) {
9794 mWatermark.positionSurface(dw, dh);
9795 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009796 if (mStrictModeFlash != null) {
9797 mStrictModeFlash.positionSurface(dw, dh);
9798 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009801 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009802 int repeats = 0;
9803 int changes = 0;
9804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009806 repeats++;
9807 if (repeats > 6) {
9808 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9809 mLayoutNeeded = false;
9810 break;
9811 }
9812
9813 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9814 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9815 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9816 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9817 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9818 assignLayersLocked();
9819 mLayoutNeeded = true;
9820 }
9821 }
9822 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9823 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009824 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009825 mLayoutNeeded = true;
9826 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9827 }
9828 }
9829 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9830 mLayoutNeeded = true;
9831 }
9832 }
9833
9834 // FIRST LOOP: Perform a layout, if needed.
9835 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009836 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009837 if (changes != 0) {
9838 continue;
9839 }
9840 } else {
9841 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9842 changes = 0;
9843 }
9844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009845 final int transactionSequence = ++mTransactionSequence;
9846
9847 // Update animations of all applications, including those
9848 // associated with exiting/removed apps
9849 boolean tokensAnimating = false;
9850 final int NAT = mAppTokens.size();
9851 for (i=0; i<NAT; i++) {
9852 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9853 tokensAnimating = true;
9854 }
9855 }
9856 final int NEAT = mExitingAppTokens.size();
9857 for (i=0; i<NEAT; i++) {
9858 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9859 tokensAnimating = true;
9860 }
9861 }
9862
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009863 // SECOND LOOP: Execute animations and update visibility of windows.
9864
Joe Onorato8a9b2202010-02-26 18:56:32 -08009865 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009866 + transactionSequence + " tokensAnimating="
9867 + tokensAnimating);
9868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009869 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009870
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009871 if (mScreenRotationAnimation != null) {
9872 if (mScreenRotationAnimation.isAnimating()) {
9873 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9874 animating = true;
9875 } else {
9876 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009877 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009878 }
9879 }
9880 }
9881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009883 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009884 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009885 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009886
9887 mPolicy.beginAnimationLw(dw, dh);
9888
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009889 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009892 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893
9894 final WindowManager.LayoutParams attrs = w.mAttrs;
9895
9896 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009897 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009898 if (w.commitFinishDrawingLocked(currentTime)) {
9899 if ((w.mAttrs.flags
9900 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009901 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009902 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009903 wallpaperMayChange = true;
9904 }
9905 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009906
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009907 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009908
9909 int animDw = dw;
9910 int animDh = dh;
9911
9912 // If the window has moved due to its containing
9913 // content frame changing, then we'd like to animate
9914 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009915 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009916 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009917 // Frame has moved, containing content frame
9918 // has also moved, and we're not currently animating...
9919 // let's do something.
9920 Animation a = AnimationUtils.loadAnimation(mContext,
9921 com.android.internal.R.anim.window_move_from_decor);
9922 w.setAnimation(a);
9923 animDw = w.mLastFrame.left - w.mFrame.left;
9924 animDh = w.mLastFrame.top - w.mFrame.top;
9925 }
9926
9927 // Execute animation.
9928 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9929 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009930
9931 // If this window is animating, make a note that we have
9932 // an animating window and take care of a request to run
9933 // a detached wallpaper animation.
9934 if (nowAnimating) {
9935 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9936 windowDetachedWallpaper = w;
9937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009938 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009940
9941 // If this window's app token is running a detached wallpaper
9942 // animation, make a note so we can ensure the wallpaper is
9943 // displayed behind it.
9944 if (w.mAppToken != null && w.mAppToken.animation != null
9945 && w.mAppToken.animation.getDetachWallpaper()) {
9946 windowDetachedWallpaper = w;
9947 }
9948
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009949 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9950 wallpaperMayChange = true;
9951 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009952
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009953 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009954 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009955 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009956 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009957 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009958 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009959 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009960 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9961 forceHiding = true;
9962 }
9963 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9964 boolean changed;
9965 if (forceHiding) {
9966 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009967 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9968 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009969 } else {
9970 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009971 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9972 "Now policy shown: " + w);
9973 if (changed) {
9974 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009975 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009976 // Assume we will need to animate. If
9977 // we don't (because the wallpaper will
9978 // stay with the lock screen), then we will
9979 // clean up later.
9980 Animation a = mPolicy.createForceHideEnterAnimation();
9981 if (a != null) {
9982 w.setAnimation(a);
9983 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009984 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009985 if (mCurrentFocus == null ||
9986 mCurrentFocus.mLayer < w.mLayer) {
9987 // We are showing on to of the current
9988 // focus, so re-evaluate focus to make
9989 // sure it is correct.
9990 mFocusMayChange = true;
9991 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009992 }
9993 }
9994 if (changed && (attrs.flags
9995 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9996 wallpaperMayChange = true;
9997 }
9998 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 mPolicy.animatingWindowLw(w, attrs);
10001 }
10002
10003 final AppWindowToken atoken = w.mAppToken;
10004 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
10005 if (atoken.lastTransactionSequence != transactionSequence) {
10006 atoken.lastTransactionSequence = transactionSequence;
10007 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
10008 atoken.startingDisplayed = false;
10009 }
10010 if ((w.isOnScreen() || w.mAttrs.type
10011 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
10012 && !w.mExiting && !w.mDestroying) {
10013 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010014 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010015 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010016 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010017 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010018 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010019 + " pv=" + w.mPolicyVisibility
10020 + " dp=" + w.mDrawPending
10021 + " cdp=" + w.mCommitDrawPending
10022 + " ah=" + w.mAttachedHidden
10023 + " th=" + atoken.hiddenRequested
10024 + " a=" + w.mAnimating);
10025 }
10026 }
10027 if (w != atoken.startingWindow) {
10028 if (!atoken.freezingScreen || !w.mAppFreezing) {
10029 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010030 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010031 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010032 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 "tokenMayBeDrawn: " + atoken
10034 + " freezingScreen=" + atoken.freezingScreen
10035 + " mAppFreezing=" + w.mAppFreezing);
10036 tokenMayBeDrawn = true;
10037 }
10038 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -070010039 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010040 atoken.startingDisplayed = true;
10041 }
10042 }
10043 } else if (w.mReadyToShow) {
10044 w.performShowLocked();
10045 }
10046 }
10047
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010048 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010049
10050 if (tokenMayBeDrawn) {
10051 // See if any windows have been drawn, so they (and others
10052 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010053 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010055 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010056 if (wtoken.freezingScreen) {
10057 int numInteresting = wtoken.numInterestingWindows;
10058 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010059 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010060 "allDrawn: " + wtoken
10061 + " interesting=" + numInteresting
10062 + " drawn=" + wtoken.numDrawnWindows);
10063 wtoken.showAllWindowsLocked();
10064 unsetAppFreezingScreenLocked(wtoken, false, true);
10065 orientationChangeComplete = true;
10066 }
10067 } else if (!wtoken.allDrawn) {
10068 int numInteresting = wtoken.numInterestingWindows;
10069 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010070 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 "allDrawn: " + wtoken
10072 + " interesting=" + numInteresting
10073 + " drawn=" + wtoken.numDrawnWindows);
10074 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010075 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076
10077 // We can now show all of the drawn windows!
10078 if (!mOpeningApps.contains(wtoken)) {
10079 wtoken.showAllWindowsLocked();
10080 }
10081 }
10082 }
10083 }
10084 }
10085
10086 // If we are ready to perform an app transition, check through
10087 // all of the app tokens to be shown and see if they are ready
10088 // to go.
10089 if (mAppTransitionReady) {
10090 int NN = mOpeningApps.size();
10091 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010092 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010093 "Checking " + NN + " opening apps (frozen="
10094 + mDisplayFrozen + " timeout="
10095 + mAppTransitionTimeout + ")...");
10096 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10097 // If the display isn't frozen, wait to do anything until
10098 // all of the apps are ready. Otherwise just go because
10099 // we'll unfreeze the display when everyone is ready.
10100 for (i=0; i<NN && goodToGo; i++) {
10101 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010102 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 "Check opening app" + wtoken + ": allDrawn="
10104 + wtoken.allDrawn + " startingDisplayed="
10105 + wtoken.startingDisplayed);
10106 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10107 && !wtoken.startingMoved) {
10108 goodToGo = false;
10109 }
10110 }
10111 }
10112 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010113 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010114 int transit = mNextAppTransition;
10115 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010116 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010118 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010119 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010120 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010121 mAppTransitionTimeout = false;
10122 mStartingIconInTransition = false;
10123 mSkipAppTransitionAnimation = false;
10124
10125 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10126
Dianne Hackborna8f60182009-09-01 19:01:50 -070010127 // If there are applications waiting to come to the
10128 // top of the stack, now is the time to move their windows.
10129 // (Note that we don't do apps going to the bottom
10130 // here -- we want to keep their windows in the old
10131 // Z-order until the animation completes.)
10132 if (mToTopApps.size() > 0) {
10133 NN = mAppTokens.size();
10134 for (i=0; i<NN; i++) {
10135 AppWindowToken wtoken = mAppTokens.get(i);
10136 if (wtoken.sendingToTop) {
10137 wtoken.sendingToTop = false;
10138 moveAppWindowsLocked(wtoken, NN, false);
10139 }
10140 }
10141 mToTopApps.clear();
10142 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010143
Dianne Hackborn25994b42009-09-04 14:21:19 -070010144 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010145
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010146 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010147 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010148
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010149 // The top-most window will supply the layout params,
10150 // and we will determine it below.
10151 LayoutParams animLp = null;
10152 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010153 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010154
Joe Onorato8a9b2202010-02-26 18:56:32 -080010155 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010156 "New wallpaper target=" + mWallpaperTarget
10157 + ", lower target=" + mLowerWallpaperTarget
10158 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010159 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010160 // Do a first pass through the tokens for two
10161 // things:
10162 // (1) Determine if both the closing and opening
10163 // app token sets are wallpaper targets, in which
10164 // case special animations are needed
10165 // (since the wallpaper needs to stay static
10166 // behind them).
10167 // (2) Find the layout params of the top-most
10168 // application window in the tokens, which is
10169 // what will control the animation theme.
10170 final int NC = mClosingApps.size();
10171 NN = NC + mOpeningApps.size();
10172 for (i=0; i<NN; i++) {
10173 AppWindowToken wtoken;
10174 int mode;
10175 if (i < NC) {
10176 wtoken = mClosingApps.get(i);
10177 mode = 1;
10178 } else {
10179 wtoken = mOpeningApps.get(i-NC);
10180 mode = 2;
10181 }
10182 if (mLowerWallpaperTarget != null) {
10183 if (mLowerWallpaperTarget.mAppToken == wtoken
10184 || mUpperWallpaperTarget.mAppToken == wtoken) {
10185 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010186 }
10187 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010188 if (wtoken.appFullscreen) {
10189 WindowState ws = wtoken.findMainWindow();
10190 if (ws != null) {
10191 // If this is a compatibility mode
10192 // window, we will always use its anim.
10193 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10194 animLp = ws.mAttrs;
10195 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010196 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010197 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010198 bestAnimLayer = ws.mLayer;
10199 }
10200 fullscreenAnim = true;
10201 }
10202 } else if (!fullscreenAnim) {
10203 WindowState ws = wtoken.findMainWindow();
10204 if (ws != null) {
10205 if (ws.mLayer > bestAnimLayer) {
10206 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010207 bestAnimLayer = ws.mLayer;
10208 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010209 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010210 }
10211 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010212
Dianne Hackborn25994b42009-09-04 14:21:19 -070010213 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010214 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010215 "Wallpaper animation!");
10216 switch (transit) {
10217 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10218 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10219 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10220 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10221 break;
10222 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10223 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10224 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10225 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10226 break;
10227 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010228 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010229 "New transit: " + transit);
10230 } else if (oldWallpaper != null) {
10231 // We are transitioning from an activity with
10232 // a wallpaper to one without.
10233 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010234 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010235 "New transit away from wallpaper: " + transit);
10236 } else if (mWallpaperTarget != null) {
10237 // We are transitioning from an activity without
10238 // a wallpaper to now showing the wallpaper
10239 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010240 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010241 "New transit into wallpaper: " + transit);
10242 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010243
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010244 // If all closing windows are obscured, then there is
10245 // no need to do an animation. This is the case, for
10246 // example, when this transition is being done behind
10247 // the lock screen.
10248 if (!mPolicy.allowAppAnimationsLw()) {
10249 animLp = null;
10250 }
10251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010252 NN = mOpeningApps.size();
10253 for (i=0; i<NN; i++) {
10254 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010255 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010256 "Now opening app" + wtoken);
10257 wtoken.reportedVisible = false;
10258 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010259 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010260 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010261 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010262 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010263 wtoken.showAllWindowsLocked();
10264 }
10265 NN = mClosingApps.size();
10266 for (i=0; i<NN; i++) {
10267 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010268 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 "Now closing app" + wtoken);
10270 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010271 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010272 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010273 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010274 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275 // Force the allDrawn flag, because we want to start
10276 // this guy's animations regardless of whether it's
10277 // gotten drawn.
10278 wtoken.allDrawn = true;
10279 }
10280
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010281 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 mOpeningApps.clear();
10284 mClosingApps.clear();
10285
10286 // This has changed the visibility of windows, so perform
10287 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010288 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10289 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010290 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010291 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10292 assignLayersLocked();
10293 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010294 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10295 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010296 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 }
10298 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010299
Dianne Hackborn16064f92010-03-25 00:47:24 -070010300 int adjResult = 0;
10301
Dianne Hackborna8f60182009-09-01 19:01:50 -070010302 if (!animating && mAppTransitionRunning) {
10303 // We have finished the animation of an app transition. To do
10304 // this, we have delayed a lot of operations like showing and
10305 // hiding apps, moving apps in Z-order, etc. The app token list
10306 // reflects the correct Z-order, but the window list may now
10307 // be out of sync with it. So here we will just rebuild the
10308 // entire app window list. Fun!
10309 mAppTransitionRunning = false;
10310 // Clear information about apps that were moving.
10311 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010312
Dianne Hackborna8f60182009-09-01 19:01:50 -070010313 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010314 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010315 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010316 moveInputMethodWindowsIfNeededLocked(false);
10317 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010318 // Since the window list has been rebuilt, focus might
10319 // have to be recomputed since the actual order of windows
10320 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010321 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010322 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010323
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010324 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010325 // At this point, there was a window with a wallpaper that
10326 // was force hiding other windows behind it, but now it
10327 // is going away. This may be simple -- just animate
10328 // away the wallpaper and its window -- or it may be
10329 // hard -- the wallpaper now needs to be shown behind
10330 // something that was hidden.
10331 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010332 if (mLowerWallpaperTarget != null
10333 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010334 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010335 "wallpaperForceHiding changed with lower="
10336 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010337 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010338 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10339 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10340 if (mLowerWallpaperTarget.mAppToken.hidden) {
10341 // The lower target has become hidden before we
10342 // actually started the animation... let's completely
10343 // re-evaluate everything.
10344 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010345 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010346 }
10347 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010348 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010349 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010350 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010351 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010352 + " NEW: " + mWallpaperTarget
10353 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010354 if (mLowerWallpaperTarget == null) {
10355 // Whoops, we don't need a special wallpaper animation.
10356 // Clear them out.
10357 forceHiding = false;
10358 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010359 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010360 if (w.mSurface != null) {
10361 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010362 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010363 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010364 forceHiding = true;
10365 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10366 if (!w.mAnimating) {
10367 // We set the animation above so it
10368 // is not yet running.
10369 w.clearAnimation();
10370 }
10371 }
10372 }
10373 }
10374 }
10375 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010376
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010377 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10378 if (DEBUG_WALLPAPER) Slog.v(TAG,
10379 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10380 + windowDetachedWallpaper);
10381 mWindowDetachedWallpaper = windowDetachedWallpaper;
10382 wallpaperMayChange = true;
10383 }
10384
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010385 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010386 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010387 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010388 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010389 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010390
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010391 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010392 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010393 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010394 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010395 assignLayersLocked();
10396 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010397 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010398 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010399 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010400 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010401
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010402 if (mFocusMayChange) {
10403 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010404 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10405 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010406 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010407 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010408 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010409 }
10410
10411 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010412 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010413 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010414
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010415 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10416 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010417 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010418
10419 // THIRD LOOP: Update the surfaces of all windows.
10420
10421 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10422
10423 boolean obscured = false;
10424 boolean blurring = false;
10425 boolean dimming = false;
10426 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010427 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010428 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010430 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010433 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010434
10435 boolean displayed = false;
10436 final WindowManager.LayoutParams attrs = w.mAttrs;
10437 final int attrFlags = attrs.flags;
10438
10439 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010440 // XXX NOTE: The logic here could be improved. We have
10441 // the decision about whether to resize a window separated
10442 // from whether to hide the surface. This can cause us to
10443 // resize a surface even if we are going to hide it. You
10444 // can see this by (1) holding device in landscape mode on
10445 // home screen; (2) tapping browser icon (device will rotate
10446 // to landscape; (3) tap home. The wallpaper will be resized
10447 // in step 2 but then immediately hidden, causing us to
10448 // have to resize and then redraw it again in step 3. It
10449 // would be nice to figure out how to avoid this, but it is
10450 // difficult because we do need to resize surfaces in some
10451 // cases while they are hidden such as when first showing a
10452 // window.
10453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010454 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010455 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010456 TAG, "Placing surface #" + i + " " + w.mSurface
10457 + ": new=" + w.mShownFrame + ", old="
10458 + w.mLastShownFrame);
10459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 int width, height;
10461 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010462 // for a scaled surface, we just want to use
10463 // the requested size.
10464 width = w.mRequestedWidth;
10465 height = w.mRequestedHeight;
10466 w.mLastRequestedWidth = width;
10467 w.mLastRequestedHeight = height;
10468 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010469 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010470 width = w.mShownFrame.width();
10471 height = w.mShownFrame.height();
10472 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 }
10474
Jeff Brownfbae7222011-01-23 13:07:25 -080010475 if (w.mSurface != null) {
10476 if (w.mSurfaceX != w.mShownFrame.left
10477 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010478 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010479 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010480 "POS " + w.mShownFrame.left
10481 + ", " + w.mShownFrame.top, null);
10482 w.mSurfaceX = w.mShownFrame.left;
10483 w.mSurfaceY = w.mShownFrame.top;
10484 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10485 } catch (RuntimeException e) {
10486 Slog.w(TAG, "Error positioning surface of " + w
10487 + " pos=(" + w.mShownFrame.left
10488 + "," + w.mShownFrame.top + ")", e);
10489 if (!recoveringMemory) {
10490 reclaimSomeSurfaceMemoryLocked(w, "position");
10491 }
10492 }
10493 }
10494
10495 if (width < 1) {
10496 width = 1;
10497 }
10498 if (height < 1) {
10499 height = 1;
10500 }
10501
10502 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10503 try {
10504 if (SHOW_TRANSACTIONS) logSurface(w,
10505 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010506 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010507 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010508 w.mSurfaceW = width;
10509 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010510 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 } catch (RuntimeException e) {
10512 // If something goes wrong with the surface (such
10513 // as running out of memory), don't take down the
10514 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010515 Slog.e(TAG, "Error resizing surface of " + w
10516 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010517 if (!recoveringMemory) {
10518 reclaimSomeSurfaceMemoryLocked(w, "size");
10519 }
10520 }
10521 }
10522 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010523
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010524 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010525 w.mContentInsetsChanged =
10526 !w.mLastContentInsets.equals(w.mContentInsets);
10527 w.mVisibleInsetsChanged =
10528 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010529 boolean configChanged =
10530 w.mConfiguration != mCurConfiguration
10531 && (w.mConfiguration == null
10532 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010533 if (DEBUG_CONFIGURATION && configChanged) {
10534 Slog.v(TAG, "Win " + w + " config changed: "
10535 + mCurConfiguration);
10536 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010537 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010538 + ": configChanged=" + configChanged
10539 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010540 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10541 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010543 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010544 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010545 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010546 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10547 Slog.v(TAG, "Resize reasons: "
10548 + "frameChanged=" + frameChanged
10549 + " contentInsetsChanged=" + w.mContentInsetsChanged
10550 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10551 + " surfaceResized=" + w.mSurfaceResized
10552 + " configChanged=" + configChanged);
10553 }
10554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010555 w.mLastFrame.set(w.mFrame);
10556 w.mLastContentInsets.set(w.mContentInsets);
10557 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010558 // If the screen is currently frozen, then keep
10559 // it frozen until this window draws at its new
10560 // orientation.
10561 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010562 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010563 "Resizing while display frozen: " + w);
10564 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010565 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010566 mWindowsFreezingScreen = true;
10567 // XXX should probably keep timeout from
10568 // when we first froze the display.
10569 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10570 mH.sendMessageDelayed(mH.obtainMessage(
10571 H.WINDOW_FREEZE_TIMEOUT), 2000);
10572 }
10573 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010574 // If the orientation is changing, then we need to
10575 // hold off on unfreezing the display until this
10576 // window has been redrawn; to do that, we need
10577 // to go through the process of getting informed
10578 // by the application when it has finished drawing.
10579 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010580 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 "Orientation start waiting for draw in "
10582 + w + ", surface " + w.mSurface);
10583 w.mDrawPending = true;
10584 w.mCommitDrawPending = false;
10585 w.mReadyToShow = false;
10586 if (w.mAppToken != null) {
10587 w.mAppToken.allDrawn = false;
10588 }
10589 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010590 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010591 "Resizing window " + w + " to " + w.mFrame);
10592 mResizingWindows.add(w);
10593 } else if (w.mOrientationChanging) {
10594 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010595 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 "Orientation not waiting for draw in "
10597 + w + ", surface " + w.mSurface);
10598 w.mOrientationChanging = false;
10599 }
10600 }
10601 }
10602
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010603 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010604 if (!w.mLastHidden) {
10605 //dump();
10606 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010607 if (SHOW_TRANSACTIONS) logSurface(w,
10608 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010609 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010610 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010611 try {
10612 w.mSurface.hide();
10613 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010614 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010615 }
10616 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010617 }
10618 // If we are waiting for this window to handle an
10619 // orientation change, well, it is hidden, so
10620 // doesn't really matter. Note that this does
10621 // introduce a potential glitch if the window
10622 // becomes unhidden before it has drawn for the
10623 // new orientation.
10624 if (w.mOrientationChanging) {
10625 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010626 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010627 "Orientation change skips hidden " + w);
10628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010629 } else if (w.mLastLayer != w.mAnimLayer
10630 || w.mLastAlpha != w.mShownAlpha
10631 || w.mLastDsDx != w.mDsDx
10632 || w.mLastDtDx != w.mDtDx
10633 || w.mLastDsDy != w.mDsDy
10634 || w.mLastDtDy != w.mDtDy
10635 || w.mLastHScale != w.mHScale
10636 || w.mLastVScale != w.mVScale
10637 || w.mLastHidden) {
10638 displayed = true;
10639 w.mLastAlpha = w.mShownAlpha;
10640 w.mLastLayer = w.mAnimLayer;
10641 w.mLastDsDx = w.mDsDx;
10642 w.mLastDtDx = w.mDtDx;
10643 w.mLastDsDy = w.mDsDy;
10644 w.mLastDtDy = w.mDtDy;
10645 w.mLastHScale = w.mHScale;
10646 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010647 if (SHOW_TRANSACTIONS) logSurface(w,
10648 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010649 + " matrix=[" + (w.mDsDx*w.mHScale)
10650 + "," + (w.mDtDx*w.mVScale)
10651 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010652 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010653 if (w.mSurface != null) {
10654 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010655 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010656 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010657 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010658 w.mSurface.setLayer(w.mAnimLayer);
10659 w.mSurface.setMatrix(
10660 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10661 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10662 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010663 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 if (!recoveringMemory) {
10665 reclaimSomeSurfaceMemoryLocked(w, "update");
10666 }
10667 }
10668 }
10669
10670 if (w.mLastHidden && !w.mDrawPending
10671 && !w.mCommitDrawPending
10672 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010673 if (SHOW_TRANSACTIONS) logSurface(w,
10674 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010675 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010676 + " during relayout");
10677 if (showSurfaceRobustlyLocked(w)) {
10678 w.mHasDrawn = true;
10679 w.mLastHidden = false;
10680 } else {
10681 w.mOrientationChanging = false;
10682 }
10683 }
10684 if (w.mSurface != null) {
10685 w.mToken.hasVisible = true;
10686 }
10687 } else {
10688 displayed = true;
10689 }
10690
10691 if (displayed) {
10692 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010693 if (attrs.width == LayoutParams.MATCH_PARENT
10694 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010695 covered = true;
10696 }
10697 }
10698 if (w.mOrientationChanging) {
10699 if (w.mDrawPending || w.mCommitDrawPending) {
10700 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010701 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010702 "Orientation continue waiting for draw in " + w);
10703 } else {
10704 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010705 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010706 "Orientation change complete in " + w);
10707 }
10708 }
10709 w.mToken.hasVisible = true;
10710 }
10711 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010712 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010713 "Orientation change skips hidden " + w);
10714 w.mOrientationChanging = false;
10715 }
10716
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010717 if (w.mContentChanged) {
10718 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10719 w.mContentChanged = false;
10720 }
10721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 final boolean canBeSeen = w.isDisplayedLw();
10723
10724 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10725 focusDisplayed = true;
10726 }
10727
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010728 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010730 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010731 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010732 if (w.mSurface != null) {
10733 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10734 holdScreen = w.mSession;
10735 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010736 if (!syswin && w.mAttrs.screenBrightness >= 0
10737 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 screenBrightness = w.mAttrs.screenBrightness;
10739 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010740 if (!syswin && w.mAttrs.buttonBrightness >= 0
10741 && buttonBrightness < 0) {
10742 buttonBrightness = w.mAttrs.buttonBrightness;
10743 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010744 if (canBeSeen
10745 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10746 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10747 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010748 syswin = true;
10749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010750 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010751
Dianne Hackborn25994b42009-09-04 14:21:19 -070010752 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10753 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010754 // This window completely covers everything behind it,
10755 // so we want to leave all of them as unblurred (for
10756 // performance reasons).
10757 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010758 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010759 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010760 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010761 obscured = true;
10762 if (mBackgroundFillerSurface == null) {
10763 try {
10764 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010765 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010766 0, dw, dh,
10767 PixelFormat.OPAQUE,
10768 Surface.FX_SURFACE_NORMAL);
10769 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010770 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010771 }
10772 }
10773 try {
10774 mBackgroundFillerSurface.setPosition(0, 0);
10775 mBackgroundFillerSurface.setSize(dw, dh);
10776 // Using the same layer as Dim because they will never be shown at the
10777 // same time.
10778 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10779 mBackgroundFillerSurface.show();
10780 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010781 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010782 }
10783 backgroundFillerShown = true;
10784 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010785 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010786 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010787 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010788 + ": blurring=" + blurring
10789 + " obscured=" + obscured
10790 + " displayed=" + displayed);
10791 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10792 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010793 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010794 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010795 if (mDimAnimator == null) {
10796 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010797 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010798 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010799 mDimAnimator.updateParameters(mContext.getResources(),
10800 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010801 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010802 }
10803 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10804 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010805 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010806 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010807 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010808 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010809 + mBlurSurface + ": CREATE");
10810 try {
Romain Guy06882f82009-06-10 13:36:04 -070010811 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010812 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010813 -1, 16, 16,
10814 PixelFormat.OPAQUE,
10815 Surface.FX_SURFACE_BLUR);
10816 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010817 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010818 }
10819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010820 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010821 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10822 + mBlurSurface + ": pos=(0,0) (" +
10823 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010824 mBlurSurface.setPosition(0, 0);
10825 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010826 mBlurSurface.setLayer(w.mAnimLayer-2);
10827 if (!mBlurShown) {
10828 try {
10829 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10830 + mBlurSurface + ": SHOW");
10831 mBlurSurface.show();
10832 } catch (RuntimeException e) {
10833 Slog.w(TAG, "Failure showing blur surface", e);
10834 }
10835 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010836 }
10837 }
10838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010839 }
10840 }
10841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010842
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010843 if (obscuredChanged && mWallpaperTarget == w) {
10844 // This is the wallpaper target and its obscured state
10845 // changed... make sure the current wallaper's visibility
10846 // has been updated accordingly.
10847 updateWallpaperVisibilityLocked();
10848 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010850
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010851 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10852 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010853 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010854 try {
10855 mBackgroundFillerSurface.hide();
10856 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010857 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010858 }
10859 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010860
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010861 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010862 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10863 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010864 }
Romain Guy06882f82009-06-10 13:36:04 -070010865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010866 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010867 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010868 + ": HIDE");
10869 try {
10870 mBlurSurface.hide();
10871 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010872 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873 }
10874 mBlurShown = false;
10875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010876 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010877 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010878 }
10879
10880 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010881
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010882 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10883
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010884 if (mWatermark != null) {
10885 mWatermark.drawIfNeeded();
10886 }
10887
Joe Onorato8a9b2202010-02-26 18:56:32 -080010888 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010889 "With display frozen, orientationChangeComplete="
10890 + orientationChangeComplete);
10891 if (orientationChangeComplete) {
10892 if (mWindowsFreezingScreen) {
10893 mWindowsFreezingScreen = false;
10894 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10895 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010896 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010897 }
Romain Guy06882f82009-06-10 13:36:04 -070010898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010899 i = mResizingWindows.size();
10900 if (i > 0) {
10901 do {
10902 i--;
10903 WindowState win = mResizingWindows.get(i);
10904 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010905 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10906 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010907 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010908 boolean configChanged =
10909 win.mConfiguration != mCurConfiguration
10910 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010911 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10912 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10913 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010914 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010915 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010916 + " / " + mCurConfiguration + " / 0x"
10917 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010918 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010919 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010920 win.mClient.resized(win.mFrame.width(),
10921 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010922 win.mLastVisibleInsets, win.mDrawPending,
10923 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 win.mContentInsetsChanged = false;
10925 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010926 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010927 } catch (RemoteException e) {
10928 win.mOrientationChanging = false;
10929 }
10930 } while (i > 0);
10931 mResizingWindows.clear();
10932 }
Romain Guy06882f82009-06-10 13:36:04 -070010933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010934 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010935 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010936 i = mDestroySurface.size();
10937 if (i > 0) {
10938 do {
10939 i--;
10940 WindowState win = mDestroySurface.get(i);
10941 win.mDestroying = false;
10942 if (mInputMethodWindow == win) {
10943 mInputMethodWindow = null;
10944 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010945 if (win == mWallpaperTarget) {
10946 wallpaperDestroyed = true;
10947 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010948 win.destroySurfaceLocked();
10949 } while (i > 0);
10950 mDestroySurface.clear();
10951 }
10952
10953 // Time to remove any exiting tokens?
10954 for (i=mExitingTokens.size()-1; i>=0; i--) {
10955 WindowToken token = mExitingTokens.get(i);
10956 if (!token.hasVisible) {
10957 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010958 if (token.windowType == TYPE_WALLPAPER) {
10959 mWallpaperTokens.remove(token);
10960 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010961 }
10962 }
10963
10964 // Time to remove any exiting applications?
10965 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10966 AppWindowToken token = mExitingAppTokens.get(i);
10967 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010968 // Make sure there is no animation running on this token,
10969 // so any windows associated with it will be removed as
10970 // soon as their animations are complete
10971 token.animation = null;
10972 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010973 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10974 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010975 mAppTokens.remove(token);
10976 mExitingAppTokens.remove(i);
10977 }
10978 }
10979
Dianne Hackborna8f60182009-09-01 19:01:50 -070010980 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010981
Dianne Hackborna8f60182009-09-01 19:01:50 -070010982 if (!animating && mAppTransitionRunning) {
10983 // We have finished the animation of an app transition. To do
10984 // this, we have delayed a lot of operations like showing and
10985 // hiding apps, moving apps in Z-order, etc. The app token list
10986 // reflects the correct Z-order, but the window list may now
10987 // be out of sync with it. So here we will just rebuild the
10988 // entire app window list. Fun!
10989 mAppTransitionRunning = false;
10990 needRelayout = true;
10991 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010992 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010993 // Clear information about apps that were moving.
10994 mToBottomApps.clear();
10995 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010997 if (focusDisplayed) {
10998 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10999 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011000 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011001 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011002 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011003 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070011004 requestAnimationLocked(0);
11005 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011006 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
11007 }
Jeff Browneb857f12010-07-16 10:06:33 -070011008
Jeff Brown3a22cd92011-01-21 13:59:04 -080011009 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080011010 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070011011
Jeff Brown8e03b752010-06-13 19:16:55 -070011012 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080011013 if (!mDisplayFrozen) {
11014 if (screenBrightness < 0 || screenBrightness > 1.0f) {
11015 mPowerManager.setScreenBrightnessOverride(-1);
11016 } else {
11017 mPowerManager.setScreenBrightnessOverride((int)
11018 (screenBrightness * Power.BRIGHTNESS_ON));
11019 }
11020 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
11021 mPowerManager.setButtonBrightnessOverride(-1);
11022 } else {
11023 mPowerManager.setButtonBrightnessOverride((int)
11024 (buttonBrightness * Power.BRIGHTNESS_ON));
11025 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050011026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011027 if (holdScreen != mHoldingScreenOn) {
11028 mHoldingScreenOn = holdScreen;
11029 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
11030 mH.sendMessage(m);
11031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011032
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011033 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011034 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011035 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
11036 LocalPowerManager.BUTTON_EVENT, true);
11037 mTurnOnScreen = false;
11038 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011039
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011040 if (updateRotation) {
11041 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11042 boolean changed = setRotationUncheckedLocked(
11043 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11044 if (changed) {
11045 sendNewConfiguration();
11046 }
11047 }
11048
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080011049 // Check to see if we are now in a state where the screen should
11050 // be enabled, because the window obscured flags have changed.
11051 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011052 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070011053
11054 /**
11055 * Must be called with the main window manager lock held.
11056 */
11057 void setHoldScreenLocked(boolean holding) {
11058 boolean state = mHoldingScreenWakeLock.isHeld();
11059 if (holding != state) {
11060 if (holding) {
11061 mHoldingScreenWakeLock.acquire();
11062 } else {
11063 mPolicy.screenOnStoppedLw();
11064 mHoldingScreenWakeLock.release();
11065 }
11066 }
11067 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011068
11069 void requestAnimationLocked(long delay) {
11070 if (!mAnimationPending) {
11071 mAnimationPending = true;
11072 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
11073 }
11074 }
Romain Guy06882f82009-06-10 13:36:04 -070011075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011076 /**
11077 * Have the surface flinger show a surface, robustly dealing with
11078 * error conditions. In particular, if there is not enough memory
11079 * to show the surface, then we will try to get rid of other surfaces
11080 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011081 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011082 * @return Returns true if the surface was successfully shown.
11083 */
11084 boolean showSurfaceRobustlyLocked(WindowState win) {
11085 try {
11086 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011087 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011088 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011089 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011090 if (DEBUG_VISIBILITY) Slog.v(TAG,
11091 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011092 win.mTurnOnScreen = false;
11093 mTurnOnScreen = true;
11094 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011095 }
11096 return true;
11097 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011098 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011099 }
Romain Guy06882f82009-06-10 13:36:04 -070011100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011101 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011103 return false;
11104 }
Romain Guy06882f82009-06-10 13:36:04 -070011105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011106 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11107 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011108
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011109 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011110 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011112 if (mForceRemoves == null) {
11113 mForceRemoves = new ArrayList<WindowState>();
11114 }
Romain Guy06882f82009-06-10 13:36:04 -070011115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011116 long callingIdentity = Binder.clearCallingIdentity();
11117 try {
11118 // There was some problem... first, do a sanity check of the
11119 // window list to make sure we haven't left any dangling surfaces
11120 // around.
11121 int N = mWindows.size();
11122 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011123 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011124 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011125 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011126 if (ws.mSurface != null) {
11127 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011128 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011129 + ws + " surface=" + ws.mSurface
11130 + " token=" + win.mToken
11131 + " pid=" + ws.mSession.mPid
11132 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011133 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011134 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011135 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011136 ws.mSurface = null;
11137 mForceRemoves.add(ws);
11138 i--;
11139 N--;
11140 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011141 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011142 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011143 + ws + " surface=" + ws.mSurface
11144 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011145 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011146 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011147 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011148 ws.mSurface = null;
11149 leakedSurface = true;
11150 }
11151 }
11152 }
Romain Guy06882f82009-06-10 13:36:04 -070011153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011154 boolean killedApps = false;
11155 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011156 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011157 SparseIntArray pidCandidates = new SparseIntArray();
11158 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011159 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011160 if (ws.mSurface != null) {
11161 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11162 }
11163 }
11164 if (pidCandidates.size() > 0) {
11165 int[] pids = new int[pidCandidates.size()];
11166 for (int i=0; i<pids.length; i++) {
11167 pids[i] = pidCandidates.keyAt(i);
11168 }
11169 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011170 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011171 killedApps = true;
11172 }
11173 } catch (RemoteException e) {
11174 }
11175 }
11176 }
Romain Guy06882f82009-06-10 13:36:04 -070011177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011178 if (leakedSurface || killedApps) {
11179 // We managed to reclaim some memory, so get rid of the trouble
11180 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011181 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011182 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011183 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011184 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011185 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011186 win.mSurface = null;
11187 }
Romain Guy06882f82009-06-10 13:36:04 -070011188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011189 try {
11190 win.mClient.dispatchGetNewSurface();
11191 } catch (RemoteException e) {
11192 }
11193 }
11194 } finally {
11195 Binder.restoreCallingIdentity(callingIdentity);
11196 }
11197 }
Romain Guy06882f82009-06-10 13:36:04 -070011198
Jeff Brown3a22cd92011-01-21 13:59:04 -080011199 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011200 WindowState newFocus = computeFocusedWindowLocked();
11201 if (mCurrentFocus != newFocus) {
11202 // This check makes sure that we don't already have the focus
11203 // change message pending.
11204 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11205 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011206 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011207 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11208 final WindowState oldFocus = mCurrentFocus;
11209 mCurrentFocus = newFocus;
11210 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011212 final WindowState imWindow = mInputMethodWindow;
11213 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011214 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011215 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011216 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11217 mLayoutNeeded = true;
11218 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011219 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011220 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011221 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11222 // Client will do the layout, but we need to assign layers
11223 // for handleNewWindowLocked() below.
11224 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011225 }
11226 }
Jeff Brown349703e2010-06-22 01:27:15 -070011227
11228 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11229 // If we defer assigning layers, then the caller is responsible for
11230 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011231 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011233 return true;
11234 }
11235 return false;
11236 }
Jeff Brown349703e2010-06-22 01:27:15 -070011237
Jeff Brown3a22cd92011-01-21 13:59:04 -080011238 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11239 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011240 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011241
11242 private WindowState computeFocusedWindowLocked() {
11243 WindowState result = null;
11244 WindowState win;
11245
11246 int i = mWindows.size() - 1;
11247 int nextAppIndex = mAppTokens.size()-1;
11248 WindowToken nextApp = nextAppIndex >= 0
11249 ? mAppTokens.get(nextAppIndex) : null;
11250
11251 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011252 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011253
Joe Onorato8a9b2202010-02-26 18:56:32 -080011254 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011255 TAG, "Looking for focus: " + i
11256 + " = " + win
11257 + ", flags=" + win.mAttrs.flags
11258 + ", canReceive=" + win.canReceiveKeys());
11259
11260 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011262 // If this window's application has been removed, just skip it.
11263 if (thisApp != null && thisApp.removed) {
11264 i--;
11265 continue;
11266 }
Romain Guy06882f82009-06-10 13:36:04 -070011267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011268 // If there is a focused app, don't allow focus to go to any
11269 // windows below it. If this is an application window, step
11270 // through the app tokens until we find its app.
11271 if (thisApp != null && nextApp != null && thisApp != nextApp
11272 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11273 int origAppIndex = nextAppIndex;
11274 while (nextAppIndex > 0) {
11275 if (nextApp == mFocusedApp) {
11276 // Whoops, we are below the focused app... no focus
11277 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011278 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011279 TAG, "Reached focused app: " + mFocusedApp);
11280 return null;
11281 }
11282 nextAppIndex--;
11283 nextApp = mAppTokens.get(nextAppIndex);
11284 if (nextApp == thisApp) {
11285 break;
11286 }
11287 }
11288 if (thisApp != nextApp) {
11289 // Uh oh, the app token doesn't exist! This shouldn't
11290 // happen, but if it does we can get totally hosed...
11291 // so restart at the original app.
11292 nextAppIndex = origAppIndex;
11293 nextApp = mAppTokens.get(nextAppIndex);
11294 }
11295 }
11296
11297 // Dispatch to this window if it is wants key events.
11298 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011299 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011300 TAG, "Found focus @ " + i + " = " + win);
11301 result = win;
11302 break;
11303 }
11304
11305 i--;
11306 }
11307
11308 return result;
11309 }
11310
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011311 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011312 if (mDisplayFrozen) {
11313 return;
11314 }
Romain Guy06882f82009-06-10 13:36:04 -070011315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011316 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011318 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011319 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011320 if (mFreezeGcPending != 0) {
11321 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011322 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011323 mH.removeMessages(H.FORCE_GC);
11324 Runtime.getRuntime().gc();
11325 mFreezeGcPending = now;
11326 }
11327 } else {
11328 mFreezeGcPending = now;
11329 }
Romain Guy06882f82009-06-10 13:36:04 -070011330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011331 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011332
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011333 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011334
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011335 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11336 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011337 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011338 mAppTransitionReady = true;
11339 }
Romain Guy06882f82009-06-10 13:36:04 -070011340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011341 if (PROFILE_ORIENTATION) {
11342 File file = new File("/data/system/frozen");
11343 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11344 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011345
11346 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011347 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11348 mScreenRotationAnimation.kill();
11349 mScreenRotationAnimation = null;
11350 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011351 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011352 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011353 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011354 }
11355 } else {
11356 Surface.freezeDisplay(0);
11357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011358 }
Romain Guy06882f82009-06-10 13:36:04 -070011359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011360 private void stopFreezingDisplayLocked() {
11361 if (!mDisplayFrozen) {
11362 return;
11363 }
Romain Guy06882f82009-06-10 13:36:04 -070011364
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011365 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11366 return;
11367 }
11368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011369 mDisplayFrozen = false;
11370 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11371 if (PROFILE_ORIENTATION) {
11372 Debug.stopMethodTracing();
11373 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011374
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011375 boolean updateRotation = false;
11376
Dianne Hackborna1111872010-11-23 20:55:11 -080011377 if (CUSTOM_SCREEN_ROTATION) {
11378 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011379 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11380 mTransitionAnimationScale)) {
11381 requestAnimationLocked(0);
11382 } else {
11383 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011384 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011385 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011386 }
11387 } else {
11388 Surface.unfreezeDisplay(0);
11389 }
Romain Guy06882f82009-06-10 13:36:04 -070011390
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011391 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011392
Dianne Hackborn420829e2011-01-28 11:30:35 -080011393 boolean configChanged;
11394
Christopher Tateb696aee2010-04-02 19:08:30 -070011395 // While the display is frozen we don't re-compute the orientation
11396 // to avoid inconsistent states. However, something interesting
11397 // could have actually changed during that time so re-evaluate it
11398 // now to catch that.
Dianne Hackborn420829e2011-01-28 11:30:35 -080011399 configChanged = updateOrientationFromAppTokensLocked(false);
Christopher Tateb696aee2010-04-02 19:08:30 -070011400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011401 // A little kludge: a lot could have happened while the
11402 // display was frozen, so now that we are coming back we
11403 // do a gc so that any remote references the system
11404 // processes holds on others can be released if they are
11405 // no longer needed.
11406 mH.removeMessages(H.FORCE_GC);
11407 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11408 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011410 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011411
11412 if (updateRotation) {
11413 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
Dianne Hackborn420829e2011-01-28 11:30:35 -080011414 configChanged |= setRotationUncheckedLocked(
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011415 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
Dianne Hackborn420829e2011-01-28 11:30:35 -080011416 }
11417
11418 if (configChanged) {
11419 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011420 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011421 }
Romain Guy06882f82009-06-10 13:36:04 -070011422
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011423 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11424 DisplayMetrics dm) {
11425 if (index < tokens.length) {
11426 String str = tokens[index];
11427 if (str != null && str.length() > 0) {
11428 try {
11429 int val = Integer.parseInt(str);
11430 return val;
11431 } catch (Exception e) {
11432 }
11433 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011434 }
11435 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11436 return defDps;
11437 }
11438 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11439 return val;
11440 }
11441
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011442 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011443 final String[] mTokens;
11444 final String mText;
11445 final Paint mTextPaint;
11446 final int mTextWidth;
11447 final int mTextHeight;
11448 final int mTextAscent;
11449 final int mTextDescent;
11450 final int mDeltaX;
11451 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011452
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011453 Surface mSurface;
11454 int mLastDW;
11455 int mLastDH;
11456 boolean mDrawNeeded;
11457
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011458 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011459 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011460 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011461
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011462 if (false) {
11463 Log.i(TAG, "*********************** WATERMARK");
11464 for (int i=0; i<tokens.length; i++) {
11465 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11466 }
11467 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011468
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011469 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011470
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011471 StringBuilder builder = new StringBuilder(32);
11472 int len = mTokens[0].length();
11473 len = len & ~1;
11474 for (int i=0; i<len; i+=2) {
11475 int c1 = mTokens[0].charAt(i);
11476 int c2 = mTokens[0].charAt(i+1);
11477 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11478 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11479 else c1 -= '0';
11480 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11481 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11482 else c2 -= '0';
11483 builder.append((char)(255-((c1*16)+c2)));
11484 }
11485 mText = builder.toString();
11486 if (false) {
11487 Log.i(TAG, "Final text: " + mText);
11488 }
11489
11490 int fontSize = getPropertyInt(tokens, 1,
11491 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11492
11493 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11494 mTextPaint.setTextSize(fontSize);
11495 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11496
11497 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11498 mTextWidth = (int)mTextPaint.measureText(mText);
11499 mTextAscent = fm.ascent;
11500 mTextDescent = fm.descent;
11501 mTextHeight = fm.descent - fm.ascent;
11502
11503 mDeltaX = getPropertyInt(tokens, 2,
11504 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11505 mDeltaY = getPropertyInt(tokens, 3,
11506 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11507 int shadowColor = getPropertyInt(tokens, 4,
11508 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11509 int color = getPropertyInt(tokens, 5,
11510 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11511 int shadowRadius = getPropertyInt(tokens, 6,
11512 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11513 int shadowDx = getPropertyInt(tokens, 8,
11514 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11515 int shadowDy = getPropertyInt(tokens, 9,
11516 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11517
11518 mTextPaint.setColor(color);
11519 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011520
11521 try {
11522 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011523 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011524 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011525 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011526 mSurface.show();
11527 } catch (OutOfResourcesException e) {
11528 }
11529 }
11530
11531 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011532 if (mLastDW != dw || mLastDH != dh) {
11533 mLastDW = dw;
11534 mLastDH = dh;
11535 mSurface.setSize(dw, dh);
11536 mDrawNeeded = true;
11537 }
11538 }
11539
11540 void drawIfNeeded() {
11541 if (mDrawNeeded) {
11542 final int dw = mLastDW;
11543 final int dh = mLastDH;
11544
11545 mDrawNeeded = false;
11546 Rect dirty = new Rect(0, 0, dw, dh);
11547 Canvas c = null;
11548 try {
11549 c = mSurface.lockCanvas(dirty);
11550 } catch (IllegalArgumentException e) {
11551 } catch (OutOfResourcesException e) {
11552 }
11553 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011554 c.drawColor(0, PorterDuff.Mode.CLEAR);
11555
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011556 int deltaX = mDeltaX;
11557 int deltaY = mDeltaY;
11558
11559 // deltaX shouldn't be close to a round fraction of our
11560 // x step, or else things will line up too much.
11561 int div = (dw+mTextWidth)/deltaX;
11562 int rem = (dw+mTextWidth) - (div*deltaX);
11563 int qdelta = deltaX/4;
11564 if (rem < qdelta || rem > (deltaX-qdelta)) {
11565 deltaX += deltaX/3;
11566 }
11567
11568 int y = -mTextHeight;
11569 int x = -mTextWidth;
11570 while (y < (dh+mTextHeight)) {
11571 c.drawText(mText, x, y, mTextPaint);
11572 x += deltaX;
11573 if (x >= dw) {
11574 x -= (dw+mTextWidth);
11575 y += deltaY;
11576 }
11577 }
11578 mSurface.unlockCanvasAndPost(c);
11579 }
11580 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011581 }
11582 }
11583
11584 void createWatermark() {
11585 if (mWatermark != null) {
11586 return;
11587 }
11588
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011589 File file = new File("/system/etc/setup.conf");
11590 FileInputStream in = null;
11591 try {
11592 in = new FileInputStream(file);
11593 DataInputStream ind = new DataInputStream(in);
11594 String line = ind.readLine();
11595 if (line != null) {
11596 String[] toks = line.split("%");
11597 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011598 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011599 }
11600 }
11601 } catch (FileNotFoundException e) {
11602 } catch (IOException e) {
11603 } finally {
11604 if (in != null) {
11605 try {
11606 in.close();
11607 } catch (IOException e) {
11608 }
11609 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011610 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011611 }
11612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011613 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011614 public void statusBarVisibilityChanged(int visibility) {
11615 synchronized (mWindowMap) {
11616 final int N = mWindows.size();
11617 for (int i = 0; i < N; i++) {
11618 WindowState ws = mWindows.get(i);
11619 try {
11620 if (ws.getAttrs().hasSystemUiListeners) {
11621 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11622 }
11623 } catch (RemoteException e) {
11624 // so sorry
11625 }
11626 }
11627 }
11628 }
11629
11630 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011631 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11632 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11633 != PackageManager.PERMISSION_GRANTED) {
11634 pw.println("Permission Denial: can't dump WindowManager from from pid="
11635 + Binder.getCallingPid()
11636 + ", uid=" + Binder.getCallingUid());
11637 return;
11638 }
Romain Guy06882f82009-06-10 13:36:04 -070011639
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011640 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011641 pw.println(" ");
11642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011643 synchronized(mWindowMap) {
11644 pw.println("Current Window Manager state:");
11645 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011646 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011647 pw.print(" Window #"); pw.print(i); pw.print(' ');
11648 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011649 w.dump(pw, " ");
11650 }
11651 if (mInputMethodDialogs.size() > 0) {
11652 pw.println(" ");
11653 pw.println(" Input method dialogs:");
11654 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11655 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011656 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011657 }
11658 }
11659 if (mPendingRemove.size() > 0) {
11660 pw.println(" ");
11661 pw.println(" Remove pending for:");
11662 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11663 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011664 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11665 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011666 w.dump(pw, " ");
11667 }
11668 }
11669 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11670 pw.println(" ");
11671 pw.println(" Windows force removing:");
11672 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11673 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011674 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11675 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011676 w.dump(pw, " ");
11677 }
11678 }
11679 if (mDestroySurface.size() > 0) {
11680 pw.println(" ");
11681 pw.println(" Windows waiting to destroy their surface:");
11682 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11683 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011684 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11685 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011686 w.dump(pw, " ");
11687 }
11688 }
11689 if (mLosingFocus.size() > 0) {
11690 pw.println(" ");
11691 pw.println(" Windows losing focus:");
11692 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11693 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011694 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11695 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011696 w.dump(pw, " ");
11697 }
11698 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011699 if (mResizingWindows.size() > 0) {
11700 pw.println(" ");
11701 pw.println(" Windows waiting to resize:");
11702 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11703 WindowState w = mResizingWindows.get(i);
11704 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11705 pw.print(w); pw.println(":");
11706 w.dump(pw, " ");
11707 }
11708 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011709 if (mSessions.size() > 0) {
11710 pw.println(" ");
11711 pw.println(" All active sessions:");
11712 Iterator<Session> it = mSessions.iterator();
11713 while (it.hasNext()) {
11714 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011715 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011716 s.dump(pw, " ");
11717 }
11718 }
11719 if (mTokenMap.size() > 0) {
11720 pw.println(" ");
11721 pw.println(" All tokens:");
11722 Iterator<WindowToken> it = mTokenMap.values().iterator();
11723 while (it.hasNext()) {
11724 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011725 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011726 token.dump(pw, " ");
11727 }
11728 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011729 if (mWallpaperTokens.size() > 0) {
11730 pw.println(" ");
11731 pw.println(" Wallpaper tokens:");
11732 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11733 WindowToken token = mWallpaperTokens.get(i);
11734 pw.print(" Wallpaper #"); pw.print(i);
11735 pw.print(' '); pw.print(token); pw.println(':');
11736 token.dump(pw, " ");
11737 }
11738 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011739 if (mAppTokens.size() > 0) {
11740 pw.println(" ");
11741 pw.println(" Application tokens in Z order:");
11742 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011743 pw.print(" App #"); pw.print(i); pw.print(": ");
11744 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011745 }
11746 }
11747 if (mFinishedStarting.size() > 0) {
11748 pw.println(" ");
11749 pw.println(" Finishing start of application tokens:");
11750 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11751 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011752 pw.print(" Finished Starting #"); pw.print(i);
11753 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011754 token.dump(pw, " ");
11755 }
11756 }
11757 if (mExitingTokens.size() > 0) {
11758 pw.println(" ");
11759 pw.println(" Exiting tokens:");
11760 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11761 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011762 pw.print(" Exiting #"); pw.print(i);
11763 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011764 token.dump(pw, " ");
11765 }
11766 }
11767 if (mExitingAppTokens.size() > 0) {
11768 pw.println(" ");
11769 pw.println(" Exiting application tokens:");
11770 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11771 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011772 pw.print(" Exiting App #"); pw.print(i);
11773 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011774 token.dump(pw, " ");
11775 }
11776 }
11777 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011778 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11779 pw.print(" mLastFocus="); pw.println(mLastFocus);
11780 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11781 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11782 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011783 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011784 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11785 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11786 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11787 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011788 if (mWindowDetachedWallpaper != null) {
11789 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11790 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011791 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11792 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11793 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011794 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11795 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11796 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11797 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011798 if (mDimAnimator != null) {
11799 mDimAnimator.printTo(pw);
11800 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011801 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011802 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011803 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011804 pw.print(mInputMethodAnimLayerAdjustment);
11805 pw.print(" mWallpaperAnimLayerAdjustment=");
11806 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011807 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11808 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011809 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11810 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011811 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11812 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011813 pw.print(" mRotation="); pw.print(mRotation);
11814 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11815 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011816 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11817 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011818 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11819 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11820 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11821 pw.print(" mNextAppTransition=0x");
11822 pw.print(Integer.toHexString(mNextAppTransition));
11823 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011824 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011825 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011826 if (mNextAppTransitionPackage != null) {
11827 pw.print(" mNextAppTransitionPackage=");
11828 pw.print(mNextAppTransitionPackage);
11829 pw.print(", mNextAppTransitionEnter=0x");
11830 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11831 pw.print(", mNextAppTransitionExit=0x");
11832 pw.print(Integer.toHexString(mNextAppTransitionExit));
11833 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011834 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11835 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11836 if (mOpeningApps.size() > 0) {
11837 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11838 }
11839 if (mClosingApps.size() > 0) {
11840 pw.print(" mClosingApps="); pw.println(mClosingApps);
11841 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011842 if (mToTopApps.size() > 0) {
11843 pw.print(" mToTopApps="); pw.println(mToTopApps);
11844 }
11845 if (mToBottomApps.size() > 0) {
11846 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11847 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011848 if (mDisplay != null) {
11849 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11850 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11851 } else {
11852 pw.println(" NO DISPLAY");
11853 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011854 pw.println(" Policy:");
11855 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011856 }
11857 }
11858
Jeff Brown349703e2010-06-22 01:27:15 -070011859 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011860 public void monitor() {
11861 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011862 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011863 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011864
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011865 /**
11866 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011867 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011868 */
11869 private static class DimAnimator {
11870 Surface mDimSurface;
11871 boolean mDimShown = false;
11872 float mDimCurrentAlpha;
11873 float mDimTargetAlpha;
11874 float mDimDeltaPerMs;
11875 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011876
11877 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011878
11879 DimAnimator (SurfaceSession session) {
11880 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011881 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011882 + mDimSurface + ": CREATE");
11883 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011884 mDimSurface = new Surface(session, 0,
11885 "DimSurface",
11886 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011887 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011888 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011889 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011890 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011891 }
11892 }
11893 }
11894
11895 /**
11896 * Show the dim surface.
11897 */
11898 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011899 if (!mDimShown) {
11900 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11901 dw + "x" + dh + ")");
11902 mDimShown = true;
11903 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011904 mLastDimWidth = dw;
11905 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011906 mDimSurface.setPosition(0, 0);
11907 mDimSurface.setSize(dw, dh);
11908 mDimSurface.show();
11909 } catch (RuntimeException e) {
11910 Slog.w(TAG, "Failure showing dim surface", e);
11911 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011912 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11913 mLastDimWidth = dw;
11914 mLastDimHeight = dh;
11915 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011916 }
11917 }
11918
11919 /**
11920 * Set's the dim surface's layer and update dim parameters that will be used in
11921 * {@link updateSurface} after all windows are examined.
11922 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011923 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011924 mDimSurface.setLayer(w.mAnimLayer-1);
11925
11926 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011927 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011928 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011929 if (mDimTargetAlpha != target) {
11930 // If the desired dim level has changed, then
11931 // start an animation to it.
11932 mLastDimAnimTime = currentTime;
11933 long duration = (w.mAnimating && w.mAnimation != null)
11934 ? w.mAnimation.computeDurationHint()
11935 : DEFAULT_DIM_DURATION;
11936 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011937 TypedValue tv = new TypedValue();
11938 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11939 tv, true);
11940 if (tv.type == TypedValue.TYPE_FRACTION) {
11941 duration = (long)tv.getFraction((float)duration, (float)duration);
11942 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11943 && tv.type <= TypedValue.TYPE_LAST_INT) {
11944 duration = tv.data;
11945 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011946 }
11947 if (duration < 1) {
11948 // Don't divide by zero
11949 duration = 1;
11950 }
11951 mDimTargetAlpha = target;
11952 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11953 }
11954 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011955
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011956 /**
11957 * Updating the surface's alpha. Returns true if the animation continues, or returns
11958 * false when the animation is finished and the dim surface is hidden.
11959 */
11960 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11961 if (!dimming) {
11962 if (mDimTargetAlpha != 0) {
11963 mLastDimAnimTime = currentTime;
11964 mDimTargetAlpha = 0;
11965 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11966 }
11967 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011968
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011969 boolean animating = false;
11970 if (mLastDimAnimTime != 0) {
11971 mDimCurrentAlpha += mDimDeltaPerMs
11972 * (currentTime-mLastDimAnimTime);
11973 boolean more = true;
11974 if (displayFrozen) {
11975 // If the display is frozen, there is no reason to animate.
11976 more = false;
11977 } else if (mDimDeltaPerMs > 0) {
11978 if (mDimCurrentAlpha > mDimTargetAlpha) {
11979 more = false;
11980 }
11981 } else if (mDimDeltaPerMs < 0) {
11982 if (mDimCurrentAlpha < mDimTargetAlpha) {
11983 more = false;
11984 }
11985 } else {
11986 more = false;
11987 }
11988
11989 // Do we need to continue animating?
11990 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011991 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011992 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11993 mLastDimAnimTime = currentTime;
11994 mDimSurface.setAlpha(mDimCurrentAlpha);
11995 animating = true;
11996 } else {
11997 mDimCurrentAlpha = mDimTargetAlpha;
11998 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011999 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012000 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
12001 mDimSurface.setAlpha(mDimCurrentAlpha);
12002 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012003 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012004 + ": HIDE");
12005 try {
12006 mDimSurface.hide();
12007 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080012008 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012009 }
12010 mDimShown = false;
12011 }
12012 }
12013 }
12014 return animating;
12015 }
12016
12017 public void printTo(PrintWriter pw) {
12018 pw.print(" mDimShown="); pw.print(mDimShown);
12019 pw.print(" current="); pw.print(mDimCurrentAlpha);
12020 pw.print(" target="); pw.print(mDimTargetAlpha);
12021 pw.print(" delta="); pw.print(mDimDeltaPerMs);
12022 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
12023 }
12024 }
12025
12026 /**
12027 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
12028 * This is used for opening/closing transition for apps in compatible mode.
12029 */
12030 private static class FadeInOutAnimation extends Animation {
12031 int mWidth;
12032 boolean mFadeIn;
12033
12034 public FadeInOutAnimation(boolean fadeIn) {
12035 setInterpolator(new AccelerateInterpolator());
12036 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
12037 mFadeIn = fadeIn;
12038 }
12039
12040 @Override
12041 protected void applyTransformation(float interpolatedTime, Transformation t) {
12042 float x = interpolatedTime;
12043 if (!mFadeIn) {
12044 x = 1.0f - x; // reverse the interpolation for fade out
12045 }
12046 if (x < 0.5) {
12047 // move the window out of the screen.
12048 t.getMatrix().setTranslate(mWidth, 0);
12049 } else {
12050 t.getMatrix().setTranslate(0, 0);// show
12051 t.setAlpha((x - 0.5f) * 2);
12052 }
12053 }
12054
12055 @Override
12056 public void initialize(int width, int height, int parentWidth, int parentHeight) {
12057 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
12058 mWidth = width;
12059 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012060
12061 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070012062 public int getZAdjustment() {
12063 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070012064 }
12065 }
Jeff Brown2992ea72011-01-28 22:04:14 -080012066
12067 public interface OnHardKeyboardStatusChangeListener {
12068 public void onHardKeyboardStatusChange(boolean available, boolean enabled);
12069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080012070}