blob: fcc8e69376038e0d1c04987b0edb8b1486eedecc [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
27import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
30import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
32import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
33import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
34import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070035import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37import com.android.internal.app.IBatteryStats;
38import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080039import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070040import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import com.android.internal.view.IInputContext;
42import com.android.internal.view.IInputMethodClient;
43import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080044import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import com.android.server.am.BatteryStatsService;
46
47import android.Manifest;
48import android.app.ActivityManagerNative;
49import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070050import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070051import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070052import android.content.ClipData;
53import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070055import android.content.Intent;
56import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.pm.ActivityInfo;
58import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.res.Configuration;
Dianne Hackborn1c24e952010-11-23 00:34:30 -080061import android.content.res.Resources;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -080062import android.graphics.Bitmap;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070063import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.PixelFormat;
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070067import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
Brad Fitzpatrickec062f62010-11-03 09:56:54 -070088import android.os.StrictMode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.os.SystemClock;
90import android.os.SystemProperties;
91import android.os.TokenWatcher;
92import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070093import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070095import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080096import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070098import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -0700100import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101import android.view.Gravity;
102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
129import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.File;
132import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700133import java.io.FileInputStream;
134import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135import java.io.IOException;
136import java.io.OutputStream;
137import java.io.OutputStreamWriter;
138import java.io.PrintWriter;
139import java.io.StringWriter;
140import java.net.Socket;
141import java.util.ArrayList;
142import java.util.HashMap;
143import java.util.HashSet;
144import java.util.Iterator;
145import java.util.List;
146
147/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700148public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700149 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final String TAG = "WindowManager";
151 static final boolean DEBUG = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800152 static final boolean DEBUG_ADD_REMOVE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800162 static final boolean DEBUG_TOKEN_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700164 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean DEBUG_APP_TRANSITIONS = false;
166 static final boolean DEBUG_STARTING_WINDOW = false;
167 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700168 static final boolean DEBUG_WALLPAPER = false;
Christopher Tate994ef922011-01-12 20:06:07 -0800169 static final boolean DEBUG_DRAG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700171 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 static final boolean PROFILE_ORIENTATION = false;
174 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700175 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to multiply the policy's type layer, to reserve room
178 * for multiple windows of the same type and Z-ordering adjustment
179 * with TYPE_LAYER_OFFSET. */
180 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
183 * or below others in the same layer. */
184 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 /** How much to increment the layer for each window, to reserve room
187 * for effect surfaces between them.
188 */
189 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 /** The maximum length we will accept for a loaded animation duration:
192 * this is 10 seconds.
193 */
194 static final int MAX_ANIMATION_DURATION = 10*1000;
195
196 /** Amount of time (in milliseconds) to animate the dim surface from one
197 * value to another, when no window animation is driving it.
198 */
199 static final int DEFAULT_DIM_DURATION = 200;
200
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700201 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
202 * compatible windows.
203 */
204 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
205
Dianne Hackborna1111872010-11-23 20:55:11 -0800206 /**
207 * If true, the window manager will do its own custom freezing and general
208 * management of the screen during rotation.
209 */
210 static final boolean CUSTOM_SCREEN_ROTATION = true;
211
Jeff Brown7fbdc842010-06-17 20:52:56 -0700212 // Maximum number of milliseconds to wait for input event injection.
213 // FIXME is this value reasonable?
214 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brownb09abc12011-01-13 21:08:27 -0800215
216 // Maximum number of milliseconds to wait for input devices to be enumerated before
217 // proceding with safe mode detection.
218 private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700219
220 // Default input dispatching timeout in nanoseconds.
221 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 static final int UPDATE_FOCUS_NORMAL = 0;
224 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
225 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
226 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700229 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
231 /**
232 * Condition waited on by {@link #reenableKeyguard} to know the call to
233 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500234 * This is set to true only if mKeyguardTokenWatcher.acquired() has
235 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
Jim Miller284b62e2010-06-08 14:27:42 -0700239 private static final int ALLOW_DISABLE_YES = 1;
240 private static final int ALLOW_DISABLE_NO = 0;
241 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
242 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
243
Mike Lockwood983ee092009-11-22 01:42:24 -0500244 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
245 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700247 if (shouldAllowDisableKeyguard()) {
248 mPolicy.enableKeyguard(false);
249 mKeyguardDisabled = true;
250 } else {
251 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700255 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500256 synchronized (mKeyguardTokenWatcher) {
257 mKeyguardDisabled = false;
258 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260 }
261 };
262
Jim Miller284b62e2010-06-08 14:27:42 -0700263 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
264 @Override
265 public void onReceive(Context context, Intent intent) {
266 mPolicy.enableKeyguard(true);
267 synchronized(mKeyguardTokenWatcher) {
268 // lazily evaluate this next time we're asked to disable keyguard
269 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
270 mKeyguardDisabled = false;
271 }
272 }
273 };
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final Context mContext;
276
277 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
282
283 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 /**
288 * All currently active sessions with clients.
289 */
290 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 /**
293 * Mapping from an IWindow IBinder to the server's Window object.
294 * This is also used as the lock for all of our state.
295 */
296 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
297
298 /**
299 * Mapping from a token IBinder to a WindowToken object.
300 */
301 final HashMap<IBinder, WindowToken> mTokenMap =
302 new HashMap<IBinder, WindowToken>();
303
304 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 * Window tokens that are in the process of exiting, but still
306 * on screen for animations.
307 */
308 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
309
310 /**
311 * Z-ordered (bottom-most first) list of all application tokens, for
312 * controlling the ordering of windows in different applications. This
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800313 * contains AppWindowToken objects.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 */
315 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
316
317 /**
318 * Application tokens that are in the process of exiting, but still
319 * on screen for animations.
320 */
321 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
322
323 /**
324 * List of window tokens that have finished starting their application,
325 * and now need to have the policy remove their windows.
326 */
327 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
328
329 /**
330 * Z-ordered (bottom-most first) list of all Window objects.
331 */
Jeff Browne33348b2010-07-15 23:54:05 -0700332 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
334 /**
335 * Windows that are being resized. Used so we can tell the client about
336 * the resize after closing the transaction in which we resized the
337 * underlying surface.
338 */
339 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
340
341 /**
342 * Windows whose animations have ended and now must be removed.
343 */
344 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
345
346 /**
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800347 * Used when processing mPendingRemove to avoid working on the original array.
348 */
349 WindowState[] mPendingRemoveTmp = new WindowState[20];
350
351 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 * Windows whose surface should be destroyed.
353 */
354 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
355
356 /**
357 * Windows that have lost input focus and are waiting for the new
358 * focus window to be displayed before they are told about this.
359 */
360 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
361
362 /**
363 * This is set when we have run out of memory, and will either be an empty
364 * list or contain windows that need to be force removed.
365 */
366 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700367
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800368 /**
369 * Used when rebuilding window list to keep track of windows that have
370 * been removed.
371 */
372 WindowState[] mRebuildTmp = new WindowState[20];
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Brad Fitzpatrick68044332010-11-22 18:19:48 -0800381 StrictModeFlash mStrictModeFlash;
Dianne Hackborna1111872010-11-23 20:55:11 -0800382 ScreenRotationAnimation mScreenRotationAnimation;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 final float[] mTmpFloats = new float[9];
387
388 boolean mSafeMode;
389 boolean mDisplayEnabled = false;
390 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700391 int mInitialDisplayWidth = 0;
392 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 int mRotation = 0;
394 int mRequestedRotation = 0;
395 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700396 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 ArrayList<IRotationWatcher> mRotationWatchers
398 = new ArrayList<IRotationWatcher>();
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800399 int mDeferredRotation;
400 int mDeferredRotationAnimFlags;
Romain Guy06882f82009-06-10 13:36:04 -0700401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mLayoutNeeded = true;
403 boolean mAnimationPending = false;
404 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800405 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean mWindowsFreezingScreen = false;
407 long mFreezeGcPending = 0;
408 int mAppsFreezingScreen = 0;
409
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 int mLayoutSeq = 0;
411
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800412 // State while inside of layoutAndPlaceSurfacesLocked().
413 boolean mFocusMayChange;
414
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800415 Configuration mCurConfiguration = new Configuration();
416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 // This is held as long as we have the screen frozen, to give us time to
418 // perform a rotation animation when turning off shows the lock screen which
419 // changes the orientation.
420 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // State management of app transitions. When we are preparing for a
423 // transition, mNextAppTransition will be the kind of transition to
424 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
425 // mOpeningApps and mClosingApps are the lists of tokens that will be
426 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700427 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700428 String mNextAppTransitionPackage;
429 int mNextAppTransitionEnter;
430 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 boolean mAppTransitionTimeout = false;
434 boolean mStartingIconInTransition = false;
435 boolean mSkipAppTransitionAnimation = false;
436 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
437 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700438 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
439 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 H mH = new H();
444
445 WindowState mCurrentFocus = null;
446 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 // This just indicates the window the input method is on top of, not
449 // necessarily the window its input is going to.
450 WindowState mInputMethodTarget = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 boolean mInputMethodTargetWaitingAnim;
452 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 WindowState mInputMethodWindow = null;
455 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
456
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700457 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800458
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700459 // If non-null, this is the currently visible window that is associated
460 // with the wallpaper.
461 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the lower one in Z-order.
464 WindowState mLowerWallpaperTarget = null;
465 // If non-null, we are in the middle of animating from one wallpaper target
466 // to another, and this is the higher one in Z-order.
467 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -0800468 // Window currently running an animation that has requested it be detached
469 // from the wallpaper. This means we need to ensure the wallpaper is
470 // visible behind it in case it animates in a way that would allow it to be
471 // seen.
472 WindowState mWindowDetachedWallpaper = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700473 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700474 float mLastWallpaperX = -1;
475 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800476 float mLastWallpaperXStep = -1;
477 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700478 // This is set when we are waiting for a wallpaper to tell us it is done
479 // changing its scroll position.
480 WindowState mWaitingOnWallpaper;
481 // The last time we had a timeout when waiting for a wallpaper.
482 long mLastWallpaperTimeoutTime;
483 // We give a wallpaper up to 150ms to finish scrolling.
484 static final long WALLPAPER_TIMEOUT = 150;
485 // Time we wait after a timeout before trying to wait again.
486 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 AppWindowToken mFocusedApp = null;
489
490 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 float mWindowAnimationScale = 1.0f;
493 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700494
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700495 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496
497 // Who is holding the screen on.
498 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700499 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700500
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700501 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700504 * Drag/drop state
505 */
506 class DragState {
507 IBinder mToken;
508 Surface mSurface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800509 int mFlags;
Chris Tate7b362e42010-11-04 16:02:52 -0700510 IBinder mLocalWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700511 ClipData mData;
512 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700513 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700514 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700515 float mThumbOffsetX, mThumbOffsetY;
516 InputChannel mServerChannel, mClientChannel;
517 WindowState mTargetWindow;
518 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700519 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700520
Jeff Brownfbf09772011-01-16 14:06:57 -0800521 private final Region mTmpRegion = new Region();
Christopher Tatea53146c2010-09-07 11:57:52 -0700522
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800523 DragState(IBinder token, Surface surface, int flags, IBinder localWin) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700524 mToken = token;
525 mSurface = surface;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800526 mFlags = flags;
Chris Tate7b362e42010-11-04 16:02:52 -0700527 mLocalWin = localWin;
Christopher Tatea53146c2010-09-07 11:57:52 -0700528 mNotifiedWindows = new ArrayList<WindowState>();
529 }
530
531 void reset() {
532 if (mSurface != null) {
533 mSurface.destroy();
534 }
535 mSurface = null;
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800536 mFlags = 0;
Chris Tate7b362e42010-11-04 16:02:52 -0700537 mLocalWin = null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700538 mToken = null;
539 mData = null;
540 mThumbOffsetX = mThumbOffsetY = 0;
541 mNotifiedWindows = null;
542 }
543
544 void register() {
545 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
546 if (mClientChannel != null) {
547 Slog.e(TAG, "Duplicate register of drag input channel");
548 } else {
549 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
550 mServerChannel = channels[0];
551 mClientChannel = channels[1];
Jeff Brown928e0542011-01-10 11:17:36 -0800552 mInputManager.registerInputChannel(mServerChannel, null);
Christopher Tatea53146c2010-09-07 11:57:52 -0700553 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
554 mH.getLooper().getQueue());
555 }
556 }
557
558 void unregister() {
559 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
560 if (mClientChannel == null) {
561 Slog.e(TAG, "Unregister of nonexistent drag input channel");
562 } else {
563 mInputManager.unregisterInputChannel(mServerChannel);
564 InputQueue.unregisterInputChannel(mClientChannel);
565 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700566 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 mClientChannel = null;
568 mServerChannel = null;
569 }
570 }
571
Chris Tatea32dcf72010-10-14 12:13:50 -0700572 int getDragLayerLw() {
573 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
574 * TYPE_LAYER_MULTIPLIER
575 + TYPE_LAYER_OFFSET;
576 }
577
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 /* call out to each visible window/session informing it about the drag
579 */
Chris Tateb8203e92010-10-12 14:23:21 -0700580 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700581 // Cache a base-class instance of the clip metadata so that parceling
582 // works correctly in calling out to the apps.
Christopher Tate1fc014f2011-01-19 12:56:26 -0800583 mDataDescription = (mData != null) ? mData.getDescription() : null;
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700585 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700586
587 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700588 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700589 }
590
Christopher Tate2c095f32010-10-04 14:13:40 -0700591 final int N = mWindows.size();
592 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700593 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700595 }
596
597 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
598 * designated window is potentially a drop recipient. There are race situations
599 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
600 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700601 *
602 * This method clones the 'event' parameter if it's being delivered to the same
603 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700604 */
Chris Tateb478f462010-10-15 16:02:26 -0700605 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
606 ClipDescription desc) {
Chris Tate7b362e42010-11-04 16:02:52 -0700607 // Don't actually send the event if the drag is supposed to be pinned
608 // to the originating window but 'newWin' is not that window.
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800609 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700610 final IBinder winBinder = newWin.mClient.asBinder();
611 if (winBinder != mLocalWin) {
612 if (DEBUG_DRAG) {
613 Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin);
614 }
615 return;
616 }
617 }
618
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700619 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700620 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
621 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800622 null, desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700623 try {
624 newWin.mClient.dispatchDragEvent(event);
625 // track each window that we've notified that the drag is starting
626 mNotifiedWindows.add(newWin);
627 } catch (RemoteException e) {
628 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700629 } finally {
630 // if the callee was local, the dispatch has already recycled the event
631 if (Process.myPid() != newWin.mSession.mPid) {
632 event.recycle();
633 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700634 }
635 }
636 }
637
638 /* helper - construct and send a DRAG_STARTED event only if the window has not
639 * previously been notified, i.e. it became visible after the drag operation
640 * was begun. This is a rare case.
641 */
642 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700643 if (mDragInProgress) {
644 // If we have sent the drag-started, we needn't do so again
645 for (WindowState ws : mNotifiedWindows) {
646 if (ws == newWin) {
647 return;
648 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700650 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700651 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700652 }
Chris Tateb478f462010-10-15 16:02:26 -0700653 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700654 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700655 }
656
Chris Tated4533f142010-10-19 15:15:08 -0700657 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700658 if (DEBUG_DRAG) {
659 Slog.d(TAG, "broadcasting DRAG_ENDED");
660 }
Chris Tated4533f142010-10-19 15:15:08 -0700661 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
Christopher Tate407b4e92010-11-30 17:14:08 -0800662 0, 0, null, null, null, mDragResult);
Chris Tated4533f142010-10-19 15:15:08 -0700663 for (WindowState ws: mNotifiedWindows) {
664 try {
665 ws.mClient.dispatchDragEvent(evt);
666 } catch (RemoteException e) {
667 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700668 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700669 }
Chris Tated4533f142010-10-19 15:15:08 -0700670 mNotifiedWindows.clear();
671 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 evt.recycle();
673 }
674
Chris Tated4533f142010-10-19 15:15:08 -0700675 void endDragLw() {
676 mDragState.broadcastDragEndedLw();
677
678 // stop intercepting input
679 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -0800680 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tated4533f142010-10-19 15:15:08 -0700681
682 // free our resources and drop all the object references
683 mDragState.reset();
684 mDragState = null;
Christopher Tateccd24de2011-01-12 15:02:55 -0800685
Dianne Hackborn89ba6752011-01-23 16:51:16 -0800686 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation");
687 boolean changed = setRotationUncheckedLocked(
688 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
689 if (changed) {
690 sendNewConfiguration();
Christopher Tateccd24de2011-01-12 15:02:55 -0800691 }
Chris Tated4533f142010-10-19 15:15:08 -0700692 }
693
Christopher Tatea53146c2010-09-07 11:57:52 -0700694 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700695 final int myPid = Process.myPid();
696
697 // Move the surface to the given touch
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800698 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw");
Christopher Tatef01af752011-01-19 16:22:07 -0800699 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800700 try {
701 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
702 } finally {
Christopher Tatef01af752011-01-19 16:22:07 -0800703 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800704 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw");
705 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700706
707 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700708 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Christopher Tatef01af752011-01-19 16:22:07 -0800709 if (touchedWin == null) {
710 if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y);
711 return;
712 }
Christopher Tate02d2b3b2011-01-10 20:43:53 -0800713 if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
Chris Tate7b362e42010-11-04 16:02:52 -0700714 final IBinder touchedBinder = touchedWin.mClient.asBinder();
715 if (touchedBinder != mLocalWin) {
716 // This drag is pinned only to the originating window, but the drag
717 // point is outside that window. Pretend it's over empty space.
718 touchedWin = null;
719 }
720 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700721 try {
722 // have we dragged over a new window?
723 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
724 if (DEBUG_DRAG) {
725 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
726 }
727 // force DRAG_EXITED_EVENT if appropriate
728 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700729 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800730 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700731 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700732 if (myPid != mTargetWindow.mSession.mPid) {
733 evt.recycle();
734 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700735 }
736 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700737 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700738 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
739 }
740 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700741 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800742 null, null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700743 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700744 if (myPid != touchedWin.mSession.mPid) {
745 evt.recycle();
746 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700747 }
748 } catch (RemoteException e) {
749 Slog.w(TAG, "can't send drag notification to windows");
750 }
751 mTargetWindow = touchedWin;
752 }
753
Chris Tated4533f142010-10-19 15:15:08 -0700754 // Tell the drop target about the data. Returns 'true' if we can immediately
755 // dispatch the global drag-ended message, 'false' if we need to wait for a
756 // result from the recipient.
757 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700758 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700759 if (touchedWin == null) {
760 // "drop" outside a valid window -- no recipient to apply a
761 // timeout to, and we can send the drag-ended message immediately.
762 mDragResult = false;
763 return true;
764 }
765
766 if (DEBUG_DRAG) {
767 Slog.d(TAG, "sending DROP to " + touchedWin);
768 }
769 final int myPid = Process.myPid();
770 final IBinder token = touchedWin.mClient.asBinder();
771 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
772 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Christopher Tate407b4e92010-11-30 17:14:08 -0800773 null, null, mData, false);
Chris Tated4533f142010-10-19 15:15:08 -0700774 try {
775 touchedWin.mClient.dispatchDragEvent(evt);
776
777 // 5 second timeout for this window to respond to the drop
778 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
779 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
780 mH.sendMessageDelayed(msg, 5000);
781 } catch (RemoteException e) {
782 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
783 return true;
784 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700785 if (myPid != touchedWin.mSession.mPid) {
786 evt.recycle();
787 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700788 }
Chris Tated4533f142010-10-19 15:15:08 -0700789 mToken = token;
790 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700791 }
792
793 // Find the visible, touch-deliverable window under the given point
794 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
795 WindowState touchedWin = null;
796 final int x = (int) xf;
797 final int y = (int) yf;
798 final ArrayList<WindowState> windows = mWindows;
799 final int N = windows.size();
800 for (int i = N - 1; i >= 0; i--) {
801 WindowState child = windows.get(i);
802 final int flags = child.mAttrs.flags;
803 if (!child.isVisibleLw()) {
804 // not visible == don't tell about drags
805 continue;
806 }
807 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
808 // not touchable == don't tell about drags
809 continue;
810 }
Jeff Brownfbf09772011-01-16 14:06:57 -0800811
812 child.getTouchableRegion(mTmpRegion);
813
Christopher Tatea53146c2010-09-07 11:57:52 -0700814 final int touchFlags = flags &
Jeff Brownfbf09772011-01-16 14:06:57 -0800815 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
816 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
817 if (mTmpRegion.contains(x, y) || touchFlags == 0) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700818 // Found it
819 touchedWin = child;
820 break;
821 }
822 }
823
824 return touchedWin;
825 }
826 }
827
828 DragState mDragState = null;
829 private final InputHandler mDragInputHandler = new BaseInputHandler() {
830 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700831 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
832 boolean handled = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700833 try {
Jeff Brown3915bb82010-11-05 15:02:16 -0700834 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
835 && mDragState != null) {
836 boolean endDrag = false;
837 final float newX = event.getRawX();
838 final float newY = event.getRawY();
839
Christopher Tatea53146c2010-09-07 11:57:52 -0700840 switch (event.getAction()) {
841 case MotionEvent.ACTION_DOWN: {
842 if (DEBUG_DRAG) {
843 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
844 }
845 } break;
846
847 case MotionEvent.ACTION_MOVE: {
848 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700849 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700850 mDragState.notifyMoveLw(newX, newY);
851 }
852 } break;
853
854 case MotionEvent.ACTION_UP: {
855 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
856 + newX + "," + newY);
857 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700858 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700859 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700860 } break;
861
862 case MotionEvent.ACTION_CANCEL: {
863 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
864 endDrag = true;
865 } break;
866 }
867
868 if (endDrag) {
869 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
870 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700871 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700872 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700873 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700874 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700875
876 handled = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700877 }
878 } catch (Exception e) {
879 Slog.e(TAG, "Exception caught by drag handleMotion", e);
880 } finally {
Jeff Brown3915bb82010-11-05 15:02:16 -0700881 finishedCallback.finished(handled);
Christopher Tatea53146c2010-09-07 11:57:52 -0700882 }
883 }
884 };
885
886 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 * Whether the UI is currently running in touch mode (not showing
888 * navigational focus because the user is directly pressing the screen).
889 */
890 boolean mInTouchMode = false;
891
892 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700893 private ArrayList<WindowChangeListener> mWindowChangeListeners =
894 new ArrayList<WindowChangeListener>();
895 private boolean mWindowsChanged = false;
896
897 public interface WindowChangeListener {
898 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700899 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901
Dianne Hackbornc485a602009-03-24 22:39:49 -0700902 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700903 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700904
905 // The frame use to limit the size of the app running in compatibility mode.
906 Rect mCompatibleScreenFrame = new Rect();
907 // The surface used to fill the outer rim of the app running in compatibility mode.
908 Surface mBackgroundFillerSurface = null;
909 boolean mBackgroundFillerShown = false;
910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 public static WindowManagerService main(Context context,
912 PowerManagerService pm, boolean haveInputMethods) {
913 WMThread thr = new WMThread(context, pm, haveInputMethods);
914 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 synchronized (thr) {
917 while (thr.mService == null) {
918 try {
919 thr.wait();
920 } catch (InterruptedException e) {
921 }
922 }
923 }
Romain Guy06882f82009-06-10 13:36:04 -0700924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 return thr.mService;
926 }
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 static class WMThread extends Thread {
929 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 private final Context mContext;
932 private final PowerManagerService mPM;
933 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 public WMThread(Context context, PowerManagerService pm,
936 boolean haveInputMethods) {
937 super("WindowManager");
938 mContext = context;
939 mPM = pm;
940 mHaveInputMethods = haveInputMethods;
941 }
Romain Guy06882f82009-06-10 13:36:04 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 public void run() {
944 Looper.prepare();
945 WindowManagerService s = new WindowManagerService(mContext, mPM,
946 mHaveInputMethods);
947 android.os.Process.setThreadPriority(
948 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700949 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 synchronized (this) {
952 mService = s;
953 notifyAll();
954 }
Romain Guy06882f82009-06-10 13:36:04 -0700955
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700956 // For debug builds, log event loop stalls to dropbox for analysis.
957 if (StrictMode.conditionallyEnableDebugLogging()) {
958 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
959 }
960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 Looper.loop();
962 }
963 }
964
965 static class PolicyThread extends Thread {
966 private final WindowManagerPolicy mPolicy;
967 private final WindowManagerService mService;
968 private final Context mContext;
969 private final PowerManagerService mPM;
970 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 public PolicyThread(WindowManagerPolicy policy,
973 WindowManagerService service, Context context,
974 PowerManagerService pm) {
975 super("WindowManagerPolicy");
976 mPolicy = policy;
977 mService = service;
978 mContext = context;
979 mPM = pm;
980 }
Romain Guy06882f82009-06-10 13:36:04 -0700981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 public void run() {
983 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800984 WindowManagerPolicyThread.set(this, Looper.myLooper());
985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800987 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 android.os.Process.setThreadPriority(
989 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700990 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 synchronized (this) {
994 mRunning = true;
995 notifyAll();
996 }
Romain Guy06882f82009-06-10 13:36:04 -0700997
Brad Fitzpatrickec062f62010-11-03 09:56:54 -0700998 // For debug builds, log event loop stalls to dropbox for analysis.
999 if (StrictMode.conditionallyEnableDebugLogging()) {
1000 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
1001 }
1002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 Looper.loop();
1004 }
1005 }
1006
1007 private WindowManagerService(Context context, PowerManagerService pm,
1008 boolean haveInputMethods) {
1009 mContext = context;
1010 mHaveInputMethods = haveInputMethods;
1011 mLimitedAlphaCompositing = context.getResources().getBoolean(
1012 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -07001013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 mPowerManager = pm;
1015 mPowerManager.setPolicy(mPolicy);
1016 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1017 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1018 "SCREEN_FROZEN");
1019 mScreenFrozenLock.setReferenceCounted(false);
1020
1021 mActivityManager = ActivityManagerNative.getDefault();
1022 mBatteryStats = BatteryStatsService.getService();
1023
1024 // Get persisted window scale setting
1025 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1026 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
1027 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
1028 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -07001029
Jim Miller284b62e2010-06-08 14:27:42 -07001030 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
1031 IntentFilter filter = new IntentFilter();
1032 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1033 mContext.registerReceiver(mBroadcastReceiver, filter);
1034
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001035 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1036 "KEEP_SCREEN_ON_FLAG");
1037 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038
Jeff Browne33348b2010-07-15 23:54:05 -07001039 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1042 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 synchronized (thr) {
1045 while (!thr.mRunning) {
1046 try {
1047 thr.wait();
1048 } catch (InterruptedException e) {
1049 }
1050 }
1051 }
Romain Guy06882f82009-06-10 13:36:04 -07001052
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001053 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 // Add ourself to the Watchdog monitors.
1056 Watchdog.getInstance().addMonitor(this);
1057 }
1058
1059 @Override
1060 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1061 throws RemoteException {
1062 try {
1063 return super.onTransact(code, data, reply, flags);
1064 } catch (RuntimeException e) {
1065 // The window manager only throws security exceptions, so let's
1066 // log all others.
1067 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 }
1070 throw e;
1071 }
1072 }
1073
Jeff Browne33348b2010-07-15 23:54:05 -07001074 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001076 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 TAG, "Adding window " + window + " at "
1078 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1079 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001080 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 }
1082
Jeff Browne33348b2010-07-15 23:54:05 -07001083 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 final int i = mWindows.indexOf(pos);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001085 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 TAG, "Adding window " + window + " at "
1087 + i + " of " + mWindows.size() + " (before " + pos + ")");
1088 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001089 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 }
1091
1092 //This method finds out the index of a window that has the same app token as
1093 //win. used for z ordering the windows in mWindows
1094 private int findIdxBasedOnAppTokens(WindowState win) {
1095 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001096 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 int jmax = localmWindows.size();
1098 if(jmax == 0) {
1099 return -1;
1100 }
1101 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001102 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 if(wentry.mAppToken == win.mAppToken) {
1104 return j;
1105 }
1106 }
1107 return -1;
1108 }
Romain Guy06882f82009-06-10 13:36:04 -07001109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1111 final IWindow client = win.mClient;
1112 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001113 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 final int N = localmWindows.size();
1116 final WindowState attached = win.mAttachedWindow;
1117 int i;
1118 if (attached == null) {
1119 int tokenWindowsPos = token.windows.size();
1120 if (token.appWindowToken != null) {
1121 int index = tokenWindowsPos-1;
1122 if (index >= 0) {
1123 // If this application has existing windows, we
1124 // simply place the new window on top of them... but
1125 // keep the starting window on top.
1126 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1127 // Base windows go behind everything else.
1128 placeWindowBefore(token.windows.get(0), win);
1129 tokenWindowsPos = 0;
1130 } else {
1131 AppWindowToken atoken = win.mAppToken;
1132 if (atoken != null &&
1133 token.windows.get(index) == atoken.startingWindow) {
1134 placeWindowBefore(token.windows.get(index), win);
1135 tokenWindowsPos--;
1136 } else {
1137 int newIdx = findIdxBasedOnAppTokens(win);
1138 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001139 //there is a window above this one associated with the same
1140 //apptoken note that the window could be a floating window
1141 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 //windows associated with this token.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001143 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1144 Slog.v(TAG, "Adding window " + win + " at "
1145 + (newIdx+1) + " of " + N);
1146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001148 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 }
1151 }
1152 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001153 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 TAG, "Figuring out where to add app window "
1155 + client.asBinder() + " (token=" + token + ")");
1156 // Figure out where the window should go, based on the
1157 // order of applications.
1158 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001159 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 for (i=NA-1; i>=0; i--) {
1161 AppWindowToken t = mAppTokens.get(i);
1162 if (t == token) {
1163 i--;
1164 break;
1165 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001166
Dianne Hackborna8f60182009-09-01 19:01:50 -07001167 // We haven't reached the token yet; if this token
1168 // is not going to the bottom and has windows, we can
1169 // use it as an anchor for when we do reach the token.
1170 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 pos = t.windows.get(0);
1172 }
1173 }
1174 // We now know the index into the apps. If we found
1175 // an app window above, that gives us the position; else
1176 // we need to look some more.
1177 if (pos != null) {
1178 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001179 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 if (atoken != null) {
1181 final int NC = atoken.windows.size();
1182 if (NC > 0) {
1183 WindowState bottom = atoken.windows.get(0);
1184 if (bottom.mSubLayer < 0) {
1185 pos = bottom;
1186 }
1187 }
1188 }
1189 placeWindowBefore(pos, win);
1190 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001191 // Continue looking down until we find the first
1192 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 while (i >= 0) {
1194 AppWindowToken t = mAppTokens.get(i);
1195 final int NW = t.windows.size();
1196 if (NW > 0) {
1197 pos = t.windows.get(NW-1);
1198 break;
1199 }
1200 i--;
1201 }
1202 if (pos != null) {
1203 // Move in front of any windows attached to this
1204 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001205 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 if (atoken != null) {
1207 final int NC = atoken.windows.size();
1208 if (NC > 0) {
1209 WindowState top = atoken.windows.get(NC-1);
1210 if (top.mSubLayer >= 0) {
1211 pos = top;
1212 }
1213 }
1214 }
1215 placeWindowAfter(pos, win);
1216 } else {
1217 // Just search for the start of this layer.
1218 final int myLayer = win.mBaseLayer;
1219 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001220 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 if (w.mBaseLayer > myLayer) {
1222 break;
1223 }
1224 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001225 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
1226 Slog.v(TAG, "Adding window " + win + " at "
1227 + i + " of " + N);
1228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001230 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 }
1232 }
1233 }
1234 } else {
1235 // Figure out where window should go, based on layer.
1236 final int myLayer = win.mBaseLayer;
1237 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001238 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 i++;
1240 break;
1241 }
1242 }
1243 if (i < 0) i = 0;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001244 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001245 TAG, "Adding window " + win + " at "
1246 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001248 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 }
1250 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001251 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 token.windows.add(tokenWindowsPos, win);
1253 }
1254
1255 } else {
1256 // Figure out this window's ordering relative to the window
1257 // it is attached to.
1258 final int NA = token.windows.size();
1259 final int sublayer = win.mSubLayer;
1260 int largestSublayer = Integer.MIN_VALUE;
1261 WindowState windowWithLargestSublayer = null;
1262 for (i=0; i<NA; i++) {
1263 WindowState w = token.windows.get(i);
1264 final int wSublayer = w.mSubLayer;
1265 if (wSublayer >= largestSublayer) {
1266 largestSublayer = wSublayer;
1267 windowWithLargestSublayer = w;
1268 }
1269 if (sublayer < 0) {
1270 // For negative sublayers, we go below all windows
1271 // in the same sublayer.
1272 if (wSublayer >= sublayer) {
1273 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001274 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 token.windows.add(i, win);
1276 }
1277 placeWindowBefore(
1278 wSublayer >= 0 ? attached : w, win);
1279 break;
1280 }
1281 } else {
1282 // For positive sublayers, we go above all windows
1283 // in the same sublayer.
1284 if (wSublayer > sublayer) {
1285 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001286 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 token.windows.add(i, win);
1288 }
1289 placeWindowBefore(w, win);
1290 break;
1291 }
1292 }
1293 }
1294 if (i >= NA) {
1295 if (addToToken) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001296 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 token.windows.add(win);
1298 }
1299 if (sublayer < 0) {
1300 placeWindowBefore(attached, win);
1301 } else {
1302 placeWindowAfter(largestSublayer >= 0
1303 ? windowWithLargestSublayer
1304 : attached,
1305 win);
1306 }
1307 }
1308 }
Romain Guy06882f82009-06-10 13:36:04 -07001309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 if (win.mAppToken != null && addToToken) {
1311 win.mAppToken.allAppWindows.add(win);
1312 }
1313 }
Romain Guy06882f82009-06-10 13:36:04 -07001314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 static boolean canBeImeTarget(WindowState w) {
1316 final int fl = w.mAttrs.flags
1317 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001318 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
1319 || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
1320 if (DEBUG_INPUT_METHOD) {
1321 Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
1322 if (!w.isVisibleOrAdding()) {
1323 Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface
1324 + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
1325 + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
1326 + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
1327 if (w.mAppToken != null) {
1328 Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
1329 }
1330 }
1331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 return w.isVisibleOrAdding();
1333 }
1334 return false;
1335 }
Romain Guy06882f82009-06-10 13:36:04 -07001336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001338 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 final int N = localmWindows.size();
1340 WindowState w = null;
1341 int i = N;
1342 while (i > 0) {
1343 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001344 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001345
Dianne Hackborne75d8722011-01-27 19:37:40 -08001346 if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
1347 + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001349 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 // Yet more tricksyness! If this window is a "starting"
1352 // window, we do actually want to be on top of it, but
1353 // it is not -really- where input will go. So if the caller
1354 // is not actually looking to move the IME, look down below
1355 // for a real window to target...
1356 if (!willMove
1357 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1358 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001359 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1361 i--;
1362 w = wb;
1363 }
1364 }
1365 break;
1366 }
1367 }
Romain Guy06882f82009-06-10 13:36:04 -07001368
Dianne Hackborne75d8722011-01-27 19:37:40 -08001369 if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
1370
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001371 // Now, a special case -- if the last target's window is in the
1372 // process of exiting, and is above the new target, keep on the
1373 // last target to avoid flicker. Consider for example a Dialog with
1374 // the IME shown: when the Dialog is dismissed, we want to keep
1375 // the IME above it until it is completely gone so it doesn't drop
1376 // behind the dialog or its full-screen scrim.
1377 if (mInputMethodTarget != null && w != null
1378 && mInputMethodTarget.isDisplayedLw()
1379 && mInputMethodTarget.mExiting) {
1380 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1381 w = mInputMethodTarget;
1382 i = localmWindows.indexOf(w);
Dianne Hackborne75d8722011-01-27 19:37:40 -08001383 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w);
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001384 }
1385 }
Romain Guy06882f82009-06-10 13:36:04 -07001386
Joe Onorato8a9b2202010-02-26 18:56:32 -08001387 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 if (willMove && w != null) {
1391 final WindowState curTarget = mInputMethodTarget;
1392 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 // Now some fun for dealing with window animations that
1395 // modify the Z order. We need to look at all windows below
1396 // the current target that are in this app, finding the highest
1397 // visible one in layering.
1398 AppWindowToken token = curTarget.mAppToken;
1399 WindowState highestTarget = null;
1400 int highestPos = 0;
1401 if (token.animating || token.animation != null) {
1402 int pos = 0;
1403 pos = localmWindows.indexOf(curTarget);
1404 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001405 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 if (win.mAppToken != token) {
1407 break;
1408 }
1409 if (!win.mRemoved) {
1410 if (highestTarget == null || win.mAnimLayer >
1411 highestTarget.mAnimLayer) {
1412 highestTarget = win;
1413 highestPos = pos;
1414 }
1415 }
1416 pos--;
1417 }
1418 }
Romain Guy06882f82009-06-10 13:36:04 -07001419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001421 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 + mNextAppTransition + " " + highestTarget
1423 + " animating=" + highestTarget.isAnimating()
1424 + " layer=" + highestTarget.mAnimLayer
1425 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001426
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001427 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 // If we are currently setting up for an animation,
1429 // hold everything until we can find out what will happen.
1430 mInputMethodTargetWaitingAnim = true;
1431 mInputMethodTarget = highestTarget;
1432 return highestPos + 1;
1433 } else if (highestTarget.isAnimating() &&
1434 highestTarget.mAnimLayer > w.mAnimLayer) {
1435 // If the window we are currently targeting is involved
1436 // with an animation, and it is on top of the next target
1437 // we will be over, then hold off on moving until
1438 // that is done.
Dianne Hackborne75d8722011-01-27 19:37:40 -08001439 mInputMethodTargetWaitingAnim = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 mInputMethodTarget = highestTarget;
1441 return highestPos + 1;
1442 }
1443 }
1444 }
1445 }
Romain Guy06882f82009-06-10 13:36:04 -07001446
Joe Onorato8a9b2202010-02-26 18:56:32 -08001447 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 if (w != null) {
1449 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001450 if (DEBUG_INPUT_METHOD) {
1451 RuntimeException e = null;
1452 if (!HIDE_STACK_CRAWLS) {
1453 e = new RuntimeException();
1454 e.fillInStackTrace();
1455 }
1456 Slog.w(TAG, "Moving IM target from "
1457 + mInputMethodTarget + " to " + w, e);
1458 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 mInputMethodTarget = w;
Dianne Hackborne75d8722011-01-27 19:37:40 -08001460 mInputMethodTargetWaitingAnim = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 if (w.mAppToken != null) {
1462 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1463 } else {
1464 setInputMethodAnimLayerAdjustment(0);
1465 }
1466 }
1467 return i+1;
1468 }
1469 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001470 if (DEBUG_INPUT_METHOD) {
1471 RuntimeException e = null;
1472 if (!HIDE_STACK_CRAWLS) {
1473 e = new RuntimeException();
1474 e.fillInStackTrace();
1475 }
1476 Slog.w(TAG, "Moving IM target from "
1477 + mInputMethodTarget + " to null", e);
1478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 mInputMethodTarget = null;
1480 setInputMethodAnimLayerAdjustment(0);
1481 }
1482 return -1;
1483 }
Romain Guy06882f82009-06-10 13:36:04 -07001484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 void addInputMethodWindowToListLocked(WindowState win) {
1486 int pos = findDesiredInputMethodWindowIndexLocked(true);
1487 if (pos >= 0) {
1488 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001489 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001490 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001492 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 moveInputMethodDialogsLocked(pos+1);
1494 return;
1495 }
1496 win.mTargetAppToken = null;
1497 addWindowToListInOrderLocked(win, true);
1498 moveInputMethodDialogsLocked(pos);
1499 }
Romain Guy06882f82009-06-10 13:36:04 -07001500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001502 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 mInputMethodAnimLayerAdjustment = adj;
1504 WindowState imw = mInputMethodWindow;
1505 if (imw != null) {
1506 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 + " anim layer: " + imw.mAnimLayer);
1509 int wi = imw.mChildWindows.size();
1510 while (wi > 0) {
1511 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001512 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001514 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 + " anim layer: " + cw.mAnimLayer);
1516 }
1517 }
1518 int di = mInputMethodDialogs.size();
1519 while (di > 0) {
1520 di --;
1521 imw = mInputMethodDialogs.get(di);
1522 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001523 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 + " anim layer: " + imw.mAnimLayer);
1525 }
1526 }
Romain Guy06882f82009-06-10 13:36:04 -07001527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1529 int wpos = mWindows.indexOf(win);
1530 if (wpos >= 0) {
1531 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001532 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001534 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 int NC = win.mChildWindows.size();
1536 while (NC > 0) {
1537 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001538 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 int cpos = mWindows.indexOf(cw);
1540 if (cpos >= 0) {
1541 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001542 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001543 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 mWindows.remove(cpos);
1545 }
1546 }
1547 }
1548 return interestingPos;
1549 }
Romain Guy06882f82009-06-10 13:36:04 -07001550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001551 private void reAddWindowToListInOrderLocked(WindowState win) {
1552 addWindowToListInOrderLocked(win, false);
1553 // This is a hack to get all of the child windows added as well
1554 // at the right position. Child windows should be rare and
1555 // this case should be rare, so it shouldn't be that big a deal.
1556 int wpos = mWindows.indexOf(win);
1557 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001558 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001559 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001561 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 reAddWindowLocked(wpos, win);
1563 }
1564 }
Romain Guy06882f82009-06-10 13:36:04 -07001565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 void logWindowList(String prefix) {
1567 int N = mWindows.size();
1568 while (N > 0) {
1569 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001570 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 }
1572 }
Romain Guy06882f82009-06-10 13:36:04 -07001573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 void moveInputMethodDialogsLocked(int pos) {
1575 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001578 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 for (int i=0; i<N; i++) {
1580 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1581 }
1582 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 logWindowList(" ");
1585 }
Romain Guy06882f82009-06-10 13:36:04 -07001586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 if (pos >= 0) {
1588 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1589 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001590 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 if (wp == mInputMethodWindow) {
1592 pos++;
1593 }
1594 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001595 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 for (int i=0; i<N; i++) {
1597 WindowState win = dialogs.get(i);
1598 win.mTargetAppToken = targetAppToken;
1599 pos = reAddWindowLocked(pos, win);
1600 }
1601 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 logWindowList(" ");
1604 }
1605 return;
1606 }
1607 for (int i=0; i<N; i++) {
1608 WindowState win = dialogs.get(i);
1609 win.mTargetAppToken = null;
1610 reAddWindowToListInOrderLocked(win);
1611 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001612 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 logWindowList(" ");
1614 }
1615 }
1616 }
Romain Guy06882f82009-06-10 13:36:04 -07001617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1619 final WindowState imWin = mInputMethodWindow;
1620 final int DN = mInputMethodDialogs.size();
1621 if (imWin == null && DN == 0) {
1622 return false;
1623 }
Romain Guy06882f82009-06-10 13:36:04 -07001624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1626 if (imPos >= 0) {
1627 // In this case, the input method windows are to be placed
1628 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 // First check to see if the input method windows are already
1631 // located here, and contiguous.
1632 final int N = mWindows.size();
1633 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001634 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 // Figure out the actual input method window that should be
1637 // at the bottom of their stack.
1638 WindowState baseImWin = imWin != null
1639 ? imWin : mInputMethodDialogs.get(0);
1640 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001641 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001642 if (cw.mSubLayer < 0) baseImWin = cw;
1643 }
Romain Guy06882f82009-06-10 13:36:04 -07001644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 if (firstImWin == baseImWin) {
1646 // The windows haven't moved... but are they still contiguous?
1647 // First find the top IM window.
1648 int pos = imPos+1;
1649 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001650 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 break;
1652 }
1653 pos++;
1654 }
1655 pos++;
1656 // Now there should be no more input method windows above.
1657 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001658 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 break;
1660 }
1661 pos++;
1662 }
1663 if (pos >= N) {
1664 // All is good!
1665 return false;
1666 }
1667 }
Romain Guy06882f82009-06-10 13:36:04 -07001668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 if (imWin != null) {
1670 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001671 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 logWindowList(" ");
1673 }
1674 imPos = tmpRemoveWindowLocked(imPos, imWin);
1675 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001676 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 logWindowList(" ");
1678 }
1679 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1680 reAddWindowLocked(imPos, imWin);
1681 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 logWindowList(" ");
1684 }
1685 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1686 } else {
1687 moveInputMethodDialogsLocked(imPos);
1688 }
Romain Guy06882f82009-06-10 13:36:04 -07001689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 } else {
1691 // In this case, the input method windows go in a fixed layer,
1692 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001695 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696 tmpRemoveWindowLocked(0, imWin);
1697 imWin.mTargetAppToken = null;
1698 reAddWindowToListInOrderLocked(imWin);
1699 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 logWindowList(" ");
1702 }
1703 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1704 } else {
1705 moveInputMethodDialogsLocked(-1);;
1706 }
Romain Guy06882f82009-06-10 13:36:04 -07001707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 }
Romain Guy06882f82009-06-10 13:36:04 -07001709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 if (needAssignLayers) {
1711 assignLayersLocked();
1712 }
Romain Guy06882f82009-06-10 13:36:04 -07001713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 return true;
1715 }
Romain Guy06882f82009-06-10 13:36:04 -07001716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 void adjustInputMethodDialogsLocked() {
1718 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1719 }
Romain Guy06882f82009-06-10 13:36:04 -07001720
Dianne Hackborn25994b42009-09-04 14:21:19 -07001721 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001722 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001723 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1724 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1725 ? wallpaperTarget.mAppToken.animation : null)
1726 + " upper=" + mUpperWallpaperTarget
1727 + " lower=" + mLowerWallpaperTarget);
1728 return (wallpaperTarget != null
1729 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1730 && wallpaperTarget.mAppToken.animation != null)))
1731 || mUpperWallpaperTarget != null
1732 || mLowerWallpaperTarget != null;
1733 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001734
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001735 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1736 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001737
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001738 int adjustWallpaperWindowsLocked() {
1739 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001740
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 final int dw = mDisplay.getWidth();
1742 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001743
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001744 // First find top-most window that has asked to be on top of the
1745 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001746 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001747 int N = localmWindows.size();
1748 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001749 WindowState foundW = null;
1750 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001751 WindowState topCurW = null;
1752 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001753 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001754 int i = N;
1755 while (i > 0) {
1756 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001757 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001758 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1759 if (topCurW == null) {
1760 topCurW = w;
1761 topCurI = i;
1762 }
1763 continue;
1764 }
1765 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001766 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001767 // If this window's app token is hidden and not animating,
1768 // it is of no interest to us.
1769 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001770 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001771 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001772 continue;
1773 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001774 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001775 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001776 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1777 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001778 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001779 && (mWallpaperTarget == w
1780 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001781 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001782 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001783 foundW = w;
1784 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001785 if (w == mWallpaperTarget && ((w.mAppToken != null
1786 && w.mAppToken.animation != null)
1787 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001788 // The current wallpaper target is animating, so we'll
1789 // look behind it for another possible target and figure
1790 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001791 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001792 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001793 continue;
1794 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001795 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001796 } else if (w == mWindowDetachedWallpaper) {
1797 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001798 }
1799 }
1800
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001801 if (foundW == null && windowDetachedI >= 0) {
1802 if (DEBUG_WALLPAPER) Slog.v(TAG,
1803 "Found animating detached wallpaper activity: #" + i + "=" + w);
1804 foundW = w;
1805 foundI = windowDetachedI;
1806 }
1807
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001808 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001809 // If we are currently waiting for an app transition, and either
1810 // the current target or the next target are involved with it,
1811 // then hold off on doing anything with the wallpaper.
1812 // Note that we are checking here for just whether the target
1813 // is part of an app token... which is potentially overly aggressive
1814 // (the app token may not be involved in the transition), but good
1815 // enough (we'll just wait until whatever transition is pending
1816 // executes).
1817 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001818 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001819 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001820 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001821 }
1822 if (foundW != null && foundW.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 found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001825 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001826 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001827 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001828
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001829 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001830 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001831 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001832 + " oldTarget: " + mWallpaperTarget);
1833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001834
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001835 mLowerWallpaperTarget = null;
1836 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001837
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 WindowState oldW = mWallpaperTarget;
1839 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001840
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001841 // Now what is happening... if the current and new targets are
1842 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001843 if (foundW != null && oldW != null) {
1844 boolean oldAnim = oldW.mAnimation != null
1845 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1846 boolean foundAnim = foundW.mAnimation != null
1847 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001848 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001849 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001850 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001851 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001852 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001853 int oldI = localmWindows.indexOf(oldW);
1854 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001856 }
1857 if (oldI >= 0) {
1858 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001859 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001860 + "=" + oldW + "; new#" + foundI
1861 + "=" + foundW);
1862 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001863
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001864 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001865 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001866 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001867 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001868 }
1869 mWallpaperTarget = oldW;
1870 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001871
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001872 // Now set the upper and lower wallpaper targets
1873 // correctly, and make sure that we are positioning
1874 // the wallpaper below the lower.
1875 if (foundI > oldI) {
1876 // The new target is on top of the old one.
1877 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001879 }
1880 mUpperWallpaperTarget = foundW;
1881 mLowerWallpaperTarget = oldW;
1882 foundW = oldW;
1883 foundI = oldI;
1884 } else {
1885 // The new target is below the old one.
1886 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001887 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001888 }
1889 mUpperWallpaperTarget = oldW;
1890 mLowerWallpaperTarget = foundW;
1891 }
1892 }
1893 }
1894 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001895
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001896 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001897 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001898 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1899 || (mLowerWallpaperTarget.mAppToken != null
1900 && mLowerWallpaperTarget.mAppToken.animation != null);
1901 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1902 || (mUpperWallpaperTarget.mAppToken != null
1903 && mUpperWallpaperTarget.mAppToken.animation != null);
1904 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001905 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001906 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001907 }
1908 mLowerWallpaperTarget = null;
1909 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001910 }
1911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001912
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001913 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001914 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001915 // The window is visible to the compositor... but is it visible
1916 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001917 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001918 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001919
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001920 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001921 // its layer adjustment. Only do this if we are not transfering
1922 // between two wallpaper targets.
1923 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001924 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001925 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001926
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001927 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1928 * TYPE_LAYER_MULTIPLIER
1929 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001930
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001931 // Now w is the window we are supposed to be behind... but we
1932 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001933 // AND any starting window associated with it, AND below the
1934 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001935 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001936 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001937 if (wb.mBaseLayer < maxLayer &&
1938 wb.mAttachedWindow != foundW &&
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001939 (foundW.mAttachedWindow == null ||
1940 wb.mAttachedWindow != foundW.mAttachedWindow) &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001941 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackborn428ecb62011-01-26 14:53:23 -08001942 foundW.mToken == null || wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001943 // This window is not related to the previous one in any
1944 // interesting way, so stop here.
1945 break;
1946 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001947 foundW = wb;
1948 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001949 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001950 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001951 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001952 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001954 if (foundW == null && topCurW != null) {
1955 // There is no wallpaper target, so it goes at the bottom.
1956 // We will assume it is the same place as last time, if known.
1957 foundW = topCurW;
1958 foundI = topCurI+1;
1959 } else {
1960 // Okay i is the position immediately above the wallpaper. Look at
1961 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001962 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001963 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001964
Dianne Hackborn284ac932009-08-28 10:34:25 -07001965 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001966 if (mWallpaperTarget.mWallpaperX >= 0) {
1967 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001968 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001969 }
1970 if (mWallpaperTarget.mWallpaperY >= 0) {
1971 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001972 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001973 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001974 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001975
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001976 // Start stepping backwards from here, ensuring that our wallpaper windows
1977 // are correctly placed.
1978 int curTokenIndex = mWallpaperTokens.size();
1979 while (curTokenIndex > 0) {
1980 curTokenIndex--;
1981 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001982 if (token.hidden == visible) {
1983 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1984 token.hidden = !visible;
1985 // Need to do a layout to ensure the wallpaper now has the
1986 // correct size.
1987 mLayoutNeeded = true;
1988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001989
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001990 int curWallpaperIndex = token.windows.size();
1991 while (curWallpaperIndex > 0) {
1992 curWallpaperIndex--;
1993 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001994
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001995 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001996 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001997 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001998
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001999 // First, make sure the client has the current visibility
2000 // state.
2001 if (wallpaper.mWallpaperVisible != visible) {
2002 wallpaper.mWallpaperVisible = visible;
2003 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002004 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002005 "Setting visibility of wallpaper " + wallpaper
2006 + ": " + visible);
2007 wallpaper.mClient.dispatchAppVisibility(visible);
2008 } catch (RemoteException e) {
2009 }
2010 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002011
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002012 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002014 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002015
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002016 // First, if this window is at the current index, then all
2017 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002018 if (wallpaper == foundW) {
2019 foundI--;
2020 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002021 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002022 continue;
2023 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002024
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002025 // The window didn't match... the current wallpaper window,
2026 // wherever it is, is in the wrong place, so make sure it is
2027 // not in the list.
2028 int oldIndex = localmWindows.indexOf(wallpaper);
2029 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002030 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002031 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002032 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002033 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002034 if (oldIndex < foundI) {
2035 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002036 }
2037 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002038
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002039 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002040 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2041 Slog.v(TAG, "Moving wallpaper " + wallpaper
2042 + " from " + oldIndex + " to " + foundI);
2043 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002044
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002045 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002046 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002047 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002048 }
2049 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002050
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002051 return changed;
2052 }
2053
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002054 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002055 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002056 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002057 mWallpaperAnimLayerAdjustment = adj;
2058 int curTokenIndex = mWallpaperTokens.size();
2059 while (curTokenIndex > 0) {
2060 curTokenIndex--;
2061 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2062 int curWallpaperIndex = token.windows.size();
2063 while (curWallpaperIndex > 0) {
2064 curWallpaperIndex--;
2065 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2066 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002067 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002068 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002069 }
2070 }
2071 }
2072
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002073 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2074 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002075 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002076 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002077 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002078 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002079 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2080 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2081 changed = wallpaperWin.mXOffset != offset;
2082 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002083 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002084 + wallpaperWin + " x: " + offset);
2085 wallpaperWin.mXOffset = offset;
2086 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002087 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002089 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002090 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002092
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002093 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002094 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002095 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2096 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2097 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002098 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002099 + wallpaperWin + " y: " + offset);
2100 changed = true;
2101 wallpaperWin.mYOffset = offset;
2102 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002103 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002104 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002105 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002106 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002108
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002109 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002110 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002111 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002112 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2113 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002114 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002115 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002116 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002117 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002118 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2119 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002120 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002121 if (mWaitingOnWallpaper != null) {
2122 long start = SystemClock.uptimeMillis();
2123 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2124 < start) {
2125 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002126 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002127 "Waiting for offset complete...");
2128 mWindowMap.wait(WALLPAPER_TIMEOUT);
2129 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002130 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002131 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002132 if ((start+WALLPAPER_TIMEOUT)
2133 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002134 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002135 + wallpaperWin);
2136 mLastWallpaperTimeoutTime = start;
2137 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002138 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002139 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002140 }
2141 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002142 } catch (RemoteException e) {
2143 }
2144 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002145
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002146 return changed;
2147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002148
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002149 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002150 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002151 if (mWaitingOnWallpaper != null &&
2152 mWaitingOnWallpaper.mClient.asBinder() == window) {
2153 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002154 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002155 }
2156 }
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002159 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002160 final int dw = mDisplay.getWidth();
2161 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002162
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002163 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002164
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002165 WindowState target = mWallpaperTarget;
2166 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002167 if (target.mWallpaperX >= 0) {
2168 mLastWallpaperX = target.mWallpaperX;
2169 } else if (changingTarget.mWallpaperX >= 0) {
2170 mLastWallpaperX = changingTarget.mWallpaperX;
2171 }
2172 if (target.mWallpaperY >= 0) {
2173 mLastWallpaperY = target.mWallpaperY;
2174 } else if (changingTarget.mWallpaperY >= 0) {
2175 mLastWallpaperY = changingTarget.mWallpaperY;
2176 }
2177 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002178
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002179 int curTokenIndex = mWallpaperTokens.size();
2180 while (curTokenIndex > 0) {
2181 curTokenIndex--;
2182 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2183 int curWallpaperIndex = token.windows.size();
2184 while (curWallpaperIndex > 0) {
2185 curWallpaperIndex--;
2186 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2187 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2188 wallpaper.computeShownFrameLocked();
2189 changed = true;
2190 // We only want to be synchronous with one wallpaper.
2191 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002192 }
2193 }
2194 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002195
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002196 return changed;
2197 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002198
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002199 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002200 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002201 final int dw = mDisplay.getWidth();
2202 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002203
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002204 int curTokenIndex = mWallpaperTokens.size();
2205 while (curTokenIndex > 0) {
2206 curTokenIndex--;
2207 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002208 if (token.hidden == visible) {
2209 token.hidden = !visible;
2210 // Need to do a layout to ensure the wallpaper now has the
2211 // correct size.
2212 mLayoutNeeded = true;
2213 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002214
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002215 int curWallpaperIndex = token.windows.size();
2216 while (curWallpaperIndex > 0) {
2217 curWallpaperIndex--;
2218 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2219 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002220 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002222
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002223 if (wallpaper.mWallpaperVisible != visible) {
2224 wallpaper.mWallpaperVisible = visible;
2225 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002226 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002227 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002228 + ": " + visible);
2229 wallpaper.mClient.dispatchAppVisibility(visible);
2230 } catch (RemoteException e) {
2231 }
2232 }
2233 }
2234 }
2235 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 public int addWindow(Session session, IWindow client,
2238 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002239 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240 int res = mPolicy.checkAddPermission(attrs);
2241 if (res != WindowManagerImpl.ADD_OKAY) {
2242 return res;
2243 }
Romain Guy06882f82009-06-10 13:36:04 -07002244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 boolean reportNewConfig = false;
2246 WindowState attachedWindow = null;
2247 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002248 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002252 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 }
Romain Guy06882f82009-06-10 13:36:04 -07002254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002256 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2258 }
2259
2260 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002261 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002263 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 + attrs.token + ". Aborting.");
2265 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2266 }
2267 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2268 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002269 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 + attrs.token + ". Aborting.");
2271 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2272 }
2273 }
2274
2275 boolean addToken = false;
2276 WindowToken token = mTokenMap.get(attrs.token);
2277 if (token == null) {
2278 if (attrs.type >= FIRST_APPLICATION_WINDOW
2279 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002280 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 + attrs.token + ". Aborting.");
2282 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2283 }
2284 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 + attrs.token + ". Aborting.");
2287 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2288 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002289 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002290 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002291 + attrs.token + ". Aborting.");
2292 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 token = new WindowToken(attrs.token, -1, false);
2295 addToken = true;
2296 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2297 && attrs.type <= LAST_APPLICATION_WINDOW) {
2298 AppWindowToken atoken = token.appWindowToken;
2299 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002300 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 + token + ". Aborting.");
2302 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2303 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002304 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 + token + ". Aborting.");
2306 return WindowManagerImpl.ADD_APP_EXITING;
2307 }
2308 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2309 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002310 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2312 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2313 }
2314 } else if (attrs.type == TYPE_INPUT_METHOD) {
2315 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002316 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 + attrs.token + ". Aborting.");
2318 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2319 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002320 } else if (attrs.type == TYPE_WALLPAPER) {
2321 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002322 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002323 + attrs.token + ". Aborting.");
2324 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 }
2327
2328 win = new WindowState(session, client, token,
2329 attachedWindow, attrs, viewVisibility);
2330 if (win.mDeathRecipient == null) {
2331 // Client has apparently died, so there is no reason to
2332 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002333 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 + " that is dead, aborting.");
2335 return WindowManagerImpl.ADD_APP_EXITING;
2336 }
2337
2338 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 res = mPolicy.prepareAddWindowLw(win, attrs);
2341 if (res != WindowManagerImpl.ADD_OKAY) {
2342 return res;
2343 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002344
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002345 if (outInputChannel != null) {
2346 String name = win.makeInputChannelName();
2347 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2348 win.mInputChannel = inputChannels[0];
2349 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2350
Jeff Brown928e0542011-01-10 11:17:36 -08002351 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353
2354 // From now on, no exceptions or errors allowed!
2355
2356 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002357
Dianne Hackborn5132b372010-07-29 12:51:35 -07002358 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 if (addToken) {
2361 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 }
2363 win.attach();
2364 mWindowMap.put(client.asBinder(), win);
2365
2366 if (attrs.type == TYPE_APPLICATION_STARTING &&
2367 token.appWindowToken != null) {
2368 token.appWindowToken.startingWindow = win;
2369 }
2370
2371 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 if (attrs.type == TYPE_INPUT_METHOD) {
2374 mInputMethodWindow = win;
2375 addInputMethodWindowToListLocked(win);
2376 imMayMove = false;
2377 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2378 mInputMethodDialogs.add(win);
2379 addWindowToListInOrderLocked(win, true);
2380 adjustInputMethodDialogsLocked();
2381 imMayMove = false;
2382 } else {
2383 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002384 if (attrs.type == TYPE_WALLPAPER) {
2385 mLastWallpaperTimeoutTime = 0;
2386 adjustWallpaperWindowsLocked();
2387 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002388 adjustWallpaperWindowsLocked();
2389 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 }
Romain Guy06882f82009-06-10 13:36:04 -07002391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 if (mInTouchMode) {
2397 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2398 }
2399 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2400 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2401 }
Romain Guy06882f82009-06-10 13:36:04 -07002402
Jeff Brown2e44b072011-01-24 15:21:56 -08002403 mInputMonitor.setUpdateInputWindowsNeededLw();
2404
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002405 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002407 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2408 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002409 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 imMayMove = false;
2411 }
2412 }
Romain Guy06882f82009-06-10 13:36:04 -07002413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002415 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 }
Romain Guy06882f82009-06-10 13:36:04 -07002417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 assignLayersLocked();
2419 // Don't do layout here, the window must call
2420 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 //dump();
2423
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002424 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002425 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002426 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002427 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002428
Joe Onorato8a9b2202010-02-26 18:56:32 -08002429 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 TAG, "New client " + client.asBinder()
2431 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002432
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002433 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002434 reportNewConfig = true;
2435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 }
2437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 if (reportNewConfig) {
2439 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 return res;
2445 }
Romain Guy06882f82009-06-10 13:36:04 -07002446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 public void removeWindow(Session session, IWindow client) {
2448 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002449 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 if (win == null) {
2451 return;
2452 }
2453 removeWindowLocked(session, win);
2454 }
2455 }
Romain Guy06882f82009-06-10 13:36:04 -07002456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 public void removeWindowLocked(Session session, WindowState win) {
2458
Joe Onorato8a9b2202010-02-26 18:56:32 -08002459 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 TAG, "Remove " + win + " client="
2461 + Integer.toHexString(System.identityHashCode(
2462 win.mClient.asBinder()))
2463 + ", surface=" + win.mSurface);
2464
2465 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002466
2467 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002468
Joe Onorato8a9b2202010-02-26 18:56:32 -08002469 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2471 + " mExiting=" + win.mExiting
2472 + " isAnimating=" + win.isAnimating()
2473 + " app-animation="
2474 + (win.mAppToken != null ? win.mAppToken.animation : null)
2475 + " inPendingTransaction="
2476 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2477 + " mDisplayFrozen=" + mDisplayFrozen);
2478 // Visibility of the removed window. Will be used later to update orientation later on.
2479 boolean wasVisible = false;
2480 // First, see if we need to run an animation. If we do, we have
2481 // to hold off on removing the window until the animation is done.
2482 // If the display is frozen, just remove immediately, since the
2483 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002484 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 // If we are not currently running the exit animation, we
2486 // need to see about starting one.
2487 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2490 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2491 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2492 }
2493 // Try starting an animation.
2494 if (applyAnimationLocked(win, transit, false)) {
2495 win.mExiting = true;
2496 }
2497 }
2498 if (win.mExiting || win.isAnimating()) {
2499 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002500 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 win.mExiting = true;
2502 win.mRemoveOnExit = true;
2503 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002504 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2505 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002507 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 if (win.mAppToken != null) {
2509 win.mAppToken.updateReportedVisibilityLocked();
2510 }
2511 //dump();
2512 Binder.restoreCallingIdentity(origId);
2513 return;
2514 }
2515 }
2516
2517 removeWindowInnerLocked(session, win);
2518 // Removing a visible window will effect the computed orientation
2519 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002520 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002521 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002522 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002523 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002525 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 Binder.restoreCallingIdentity(origId);
2527 }
Romain Guy06882f82009-06-10 13:36:04 -07002528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002530 if (win.mRemoved) {
2531 // Nothing to do.
2532 return;
2533 }
2534
2535 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2536 WindowState cwin = win.mChildWindows.get(i);
2537 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2538 + win);
2539 removeWindowInnerLocked(cwin.mSession, cwin);
2540 }
2541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 if (mInputMethodTarget == win) {
2545 moveInputMethodWindowsIfNeededLocked(false);
2546 }
Romain Guy06882f82009-06-10 13:36:04 -07002547
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002548 if (false) {
2549 RuntimeException e = new RuntimeException("here");
2550 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002551 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002552 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 mPolicy.removeWindowLw(win);
2555 win.removeLocked();
2556
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002557 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 mWindowMap.remove(win.mClient.asBinder());
2559 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002560 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002561 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002562 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563
2564 if (mInputMethodWindow == win) {
2565 mInputMethodWindow = null;
2566 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2567 mInputMethodDialogs.remove(win);
2568 }
Romain Guy06882f82009-06-10 13:36:04 -07002569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 final WindowToken token = win.mToken;
2571 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002572 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 token.windows.remove(win);
2574 if (atoken != null) {
2575 atoken.allAppWindows.remove(win);
2576 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002577 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 TAG, "**** Removing window " + win + ": count="
2579 + token.windows.size());
2580 if (token.windows.size() == 0) {
2581 if (!token.explicit) {
2582 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 } else if (atoken != null) {
2584 atoken.firstWindowDrawn = false;
2585 }
2586 }
2587
2588 if (atoken != null) {
2589 if (atoken.startingWindow == win) {
2590 atoken.startingWindow = null;
2591 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2592 // If this is the last window and we had requested a starting
2593 // transition window, well there is no point now.
2594 atoken.startingData = null;
2595 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2596 // If this is the last window except for a starting transition
2597 // window, we need to get rid of the starting transition.
2598 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002599 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 + ": no more real windows");
2601 }
2602 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2603 mH.sendMessage(m);
2604 }
2605 }
Romain Guy06882f82009-06-10 13:36:04 -07002606
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002607 if (win.mAttrs.type == TYPE_WALLPAPER) {
2608 mLastWallpaperTimeoutTime = 0;
2609 adjustWallpaperWindowsLocked();
2610 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002611 adjustWallpaperWindowsLocked();
2612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 if (!mInLayout) {
2615 assignLayersLocked();
2616 mLayoutNeeded = true;
2617 performLayoutAndPlaceSurfacesLocked();
2618 if (win.mAppToken != null) {
2619 win.mAppToken.updateReportedVisibilityLocked();
2620 }
2621 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002622
Jeff Brown2e44b072011-01-24 15:21:56 -08002623 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 }
2625
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002626 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2627 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2628 + ": " + msg + " / " + w.mAttrs.getTitle();
2629 if (where != null) {
2630 Slog.i(TAG, str, where);
2631 } else {
2632 Slog.i(TAG, str);
2633 }
2634 }
2635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2637 long origId = Binder.clearCallingIdentity();
2638 try {
2639 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002640 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002642 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2643 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 Surface.openTransaction();
2645 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002646 if (SHOW_TRANSACTIONS) logSurface(w,
2647 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 w.mSurface.setTransparentRegionHint(region);
2649 } finally {
2650 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002651 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2652 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 }
2654 }
2655 }
2656 } finally {
2657 Binder.restoreCallingIdentity(origId);
2658 }
2659 }
2660
2661 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002662 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002663 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 long origId = Binder.clearCallingIdentity();
2665 try {
2666 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002667 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 if (w != null) {
2669 w.mGivenInsetsPending = false;
2670 w.mGivenContentInsets.set(contentInsets);
2671 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002672 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002673 w.mTouchableInsets = touchableInsets;
2674 mLayoutNeeded = true;
2675 performLayoutAndPlaceSurfacesLocked();
2676 }
2677 }
2678 } finally {
2679 Binder.restoreCallingIdentity(origId);
2680 }
2681 }
Romain Guy06882f82009-06-10 13:36:04 -07002682
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 public void getWindowDisplayFrame(Session session, IWindow client,
2684 Rect outDisplayFrame) {
2685 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002686 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 if (win == null) {
2688 outDisplayFrame.setEmpty();
2689 return;
2690 }
2691 outDisplayFrame.set(win.mDisplayFrame);
2692 }
2693 }
2694
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002695 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2696 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002697 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2698 window.mWallpaperX = x;
2699 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002700 window.mWallpaperXStep = xStep;
2701 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002702 if (updateWallpaperOffsetLocked(window, true)) {
2703 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002704 }
2705 }
2706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002707
Dianne Hackborn75804932009-10-20 20:15:20 -07002708 void wallpaperCommandComplete(IBinder window, Bundle result) {
2709 synchronized (mWindowMap) {
2710 if (mWaitingOnWallpaper != null &&
2711 mWaitingOnWallpaper.mClient.asBinder() == window) {
2712 mWaitingOnWallpaper = null;
2713 mWindowMap.notifyAll();
2714 }
2715 }
2716 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002717
Dianne Hackborn75804932009-10-20 20:15:20 -07002718 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2719 String action, int x, int y, int z, Bundle extras, boolean sync) {
2720 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2721 || window == mUpperWallpaperTarget) {
2722 boolean doWait = sync;
2723 int curTokenIndex = mWallpaperTokens.size();
2724 while (curTokenIndex > 0) {
2725 curTokenIndex--;
2726 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2727 int curWallpaperIndex = token.windows.size();
2728 while (curWallpaperIndex > 0) {
2729 curWallpaperIndex--;
2730 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2731 try {
2732 wallpaper.mClient.dispatchWallpaperCommand(action,
2733 x, y, z, extras, sync);
2734 // We only want to be synchronous with one wallpaper.
2735 sync = false;
2736 } catch (RemoteException e) {
2737 }
2738 }
2739 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002740
Dianne Hackborn75804932009-10-20 20:15:20 -07002741 if (doWait) {
2742 // XXX Need to wait for result.
2743 }
2744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002745
Dianne Hackborn75804932009-10-20 20:15:20 -07002746 return null;
2747 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 public int relayoutWindow(Session session, IWindow client,
2750 WindowManager.LayoutParams attrs, int requestedWidth,
2751 int requestedHeight, int viewVisibility, boolean insetsPending,
2752 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002753 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 boolean displayed = false;
2755 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002756 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002760 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 if (win == null) {
2762 return 0;
2763 }
2764 win.mRequestedWidth = requestedWidth;
2765 win.mRequestedHeight = requestedHeight;
2766
2767 if (attrs != null) {
2768 mPolicy.adjustWindowParamsLw(attrs);
2769 }
Romain Guy06882f82009-06-10 13:36:04 -07002770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 int attrChanges = 0;
2772 int flagChanges = 0;
2773 if (attrs != null) {
2774 flagChanges = win.mAttrs.flags ^= attrs.flags;
2775 attrChanges = win.mAttrs.copyFrom(attrs);
2776 }
2777
Joe Onorato8a9b2202010-02-26 18:56:32 -08002778 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779
2780 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2781 win.mAlpha = attrs.alpha;
2782 }
2783
2784 final boolean scaledWindow =
2785 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2786
2787 if (scaledWindow) {
2788 // requested{Width|Height} Surface's physical size
2789 // attrs.{width|height} Size on screen
2790 win.mHScale = (attrs.width != requestedWidth) ?
2791 (attrs.width / (float)requestedWidth) : 1.0f;
2792 win.mVScale = (attrs.height != requestedHeight) ?
2793 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002794 } else {
2795 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 }
2797
2798 boolean imMayMove = (flagChanges&(
2799 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2800 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 boolean focusMayChange = win.mViewVisibility != viewVisibility
2803 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2804 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002805
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002806 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2807 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 win.mRelayoutCalled = true;
2810 final int oldVisibility = win.mViewVisibility;
2811 win.mViewVisibility = viewVisibility;
2812 if (viewVisibility == View.VISIBLE &&
2813 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2814 displayed = !win.isVisibleLw();
2815 if (win.mExiting) {
2816 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002817 if (win.mAnimation != null) {
2818 win.mAnimation.cancel();
2819 win.mAnimation = null;
2820 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 }
2822 if (win.mDestroying) {
2823 win.mDestroying = false;
2824 mDestroySurface.remove(win);
2825 }
2826 if (oldVisibility == View.GONE) {
2827 win.mEnterAnimationPending = true;
2828 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002829 if (displayed) {
2830 if (win.mSurface != null && !win.mDrawPending
2831 && !win.mCommitDrawPending && !mDisplayFrozen
2832 && mPolicy.isScreenOn()) {
2833 applyEnterAnimationLocked(win);
2834 }
2835 if ((win.mAttrs.flags
2836 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2837 if (DEBUG_VISIBILITY) Slog.v(TAG,
2838 "Relayout window turning screen on: " + win);
2839 win.mTurnOnScreen = true;
2840 }
2841 int diff = 0;
2842 if (win.mConfiguration != mCurConfiguration
2843 && (win.mConfiguration == null
2844 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2845 win.mConfiguration = mCurConfiguration;
2846 if (DEBUG_CONFIGURATION) {
2847 Slog.i(TAG, "Window " + win + " visible with new config: "
2848 + win.mConfiguration + " / 0x"
2849 + Integer.toHexString(diff));
2850 }
2851 outConfig.setTo(mCurConfiguration);
2852 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2855 // To change the format, we need to re-build the surface.
2856 win.destroySurfaceLocked();
2857 displayed = true;
2858 }
2859 try {
2860 Surface surface = win.createSurfaceLocked();
2861 if (surface != null) {
2862 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002863 win.mReportDestroySurface = false;
2864 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002865 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002866 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002868 // For some reason there isn't a surface. Clear the
2869 // caller's object so they see the same state.
2870 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 }
2872 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002873 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002874
Joe Onorato8a9b2202010-02-26 18:56:32 -08002875 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002876 + client + " (" + win.mAttrs.getTitle() + ")",
2877 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 Binder.restoreCallingIdentity(origId);
2879 return 0;
2880 }
2881 if (displayed) {
2882 focusMayChange = true;
2883 }
2884 if (win.mAttrs.type == TYPE_INPUT_METHOD
2885 && mInputMethodWindow == null) {
2886 mInputMethodWindow = win;
2887 imMayMove = true;
2888 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002889 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2890 && win.mAppToken != null
2891 && win.mAppToken.startingWindow != null) {
2892 // Special handling of starting window over the base
2893 // window of the app: propagate lock screen flags to it,
2894 // to provide the correct semantics while starting.
2895 final int mask =
2896 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002897 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2898 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002899 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2900 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2901 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 } else {
2903 win.mEnterAnimationPending = false;
2904 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002905 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002906 + ": mExiting=" + win.mExiting
2907 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 // If we are not currently running the exit animation, we
2909 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002910 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 // Try starting an animation; if there isn't one, we
2912 // can destroy the surface right away.
2913 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2914 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2915 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2916 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002917 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002919 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 } else if (win.isAnimating()) {
2922 // Currently in a hide animation... turn this into
2923 // an exit.
2924 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002925 } else if (win == mWallpaperTarget) {
2926 // If the wallpaper is currently behind this
2927 // window, we need to change both of them inside
2928 // of a transaction to avoid artifacts.
2929 win.mExiting = true;
2930 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 } else {
2932 if (mInputMethodWindow == win) {
2933 mInputMethodWindow = null;
2934 }
2935 win.destroySurfaceLocked();
2936 }
2937 }
2938 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002939
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002940 if (win.mSurface == null || (win.getAttrs().flags
2941 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2942 || win.mSurfacePendingDestroy) {
2943 // We are being called from a local process, which
2944 // means outSurface holds its current surface. Ensure the
2945 // surface object is cleared, but we don't want it actually
2946 // destroyed at this point.
2947 win.mSurfacePendingDestroy = false;
2948 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002949 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002950 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002951 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002952 "Keeping surface, will report destroy: " + win);
2953 win.mReportDestroySurface = true;
2954 outSurface.copyFrom(win.mSurface);
2955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 }
2957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 if (focusMayChange) {
2959 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002960 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2961 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 imMayMove = false;
2963 }
2964 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2965 }
Romain Guy06882f82009-06-10 13:36:04 -07002966
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002967 // updateFocusedWindowLocked() already assigned layers so we only need to
2968 // reassign them at this point if the IM window state gets shuffled
2969 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002972 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2973 // Little hack here -- we -should- be able to rely on the
2974 // function to return true if the IME has moved and needs
2975 // its layer recomputed. However, if the IME was hidden
2976 // and isn't actually moved in the list, its layer may be
2977 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 assignLayers = true;
2979 }
2980 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002981 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002982 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002983 assignLayers = true;
2984 }
2985 }
Romain Guy06882f82009-06-10 13:36:04 -07002986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 mLayoutNeeded = true;
2988 win.mGivenInsetsPending = insetsPending;
2989 if (assignLayers) {
2990 assignLayersLocked();
2991 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002992 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002994 if (displayed && win.mIsWallpaper) {
2995 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002996 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 if (win.mAppToken != null) {
2999 win.mAppToken.updateReportedVisibilityLocked();
3000 }
3001 outFrame.set(win.mFrame);
3002 outContentInsets.set(win.mContentInsets);
3003 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003004 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07003006 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 + ", requestedHeight=" + requestedHeight
3008 + ", viewVisibility=" + viewVisibility
3009 + "\nRelayout returning frame=" + outFrame
3010 + ", surface=" + outSurface);
3011
Joe Onorato8a9b2202010-02-26 18:56:32 -08003012 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
3014
3015 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07003016
Jeff Brown2e44b072011-01-24 15:21:56 -08003017 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 }
3019
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003020 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003021 sendNewConfiguration();
3022 }
Romain Guy06882f82009-06-10 13:36:04 -07003023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003026 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3027 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3028 }
3029
3030 public void finishDrawingWindow(Session session, IWindow client) {
3031 final long origId = Binder.clearCallingIdentity();
3032 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003033 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003035 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3036 adjustWallpaperWindowsLocked();
3037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 mLayoutNeeded = true;
3039 performLayoutAndPlaceSurfacesLocked();
3040 }
3041 }
3042 Binder.restoreCallingIdentity(origId);
3043 }
3044
3045 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003046 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 + (lp != null ? lp.packageName : null)
3048 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3049 if (lp != null && lp.windowAnimations != 0) {
3050 // If this is a system resource, don't try to load it from the
3051 // application resources. It is nice to avoid loading application
3052 // resources if we can.
3053 String packageName = lp.packageName != null ? lp.packageName : "android";
3054 int resId = lp.windowAnimations;
3055 if ((resId&0xFF000000) == 0x01000000) {
3056 packageName = "android";
3057 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003058 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003059 + packageName);
3060 return AttributeCache.instance().get(packageName, resId,
3061 com.android.internal.R.styleable.WindowAnimation);
3062 }
3063 return null;
3064 }
Romain Guy06882f82009-06-10 13:36:04 -07003065
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003066 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003067 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003068 + packageName + " resId=0x" + Integer.toHexString(resId));
3069 if (packageName != null) {
3070 if ((resId&0xFF000000) == 0x01000000) {
3071 packageName = "android";
3072 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003073 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003074 + packageName);
3075 return AttributeCache.instance().get(packageName, resId,
3076 com.android.internal.R.styleable.WindowAnimation);
3077 }
3078 return null;
3079 }
3080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 private void applyEnterAnimationLocked(WindowState win) {
3082 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3083 if (win.mEnterAnimationPending) {
3084 win.mEnterAnimationPending = false;
3085 transit = WindowManagerPolicy.TRANSIT_ENTER;
3086 }
3087
3088 applyAnimationLocked(win, transit, true);
3089 }
3090
3091 private boolean applyAnimationLocked(WindowState win,
3092 int transit, boolean isEntrance) {
3093 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3094 // If we are trying to apply an animation, but already running
3095 // an animation of the same type, then just leave that one alone.
3096 return true;
3097 }
Romain Guy06882f82009-06-10 13:36:04 -07003098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 // Only apply an animation if the display isn't frozen. If it is
3100 // frozen, there is no reason to animate and it can cause strange
3101 // artifacts when we unfreeze the display if some different animation
3102 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003103 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 int anim = mPolicy.selectAnimationLw(win, transit);
3105 int attr = -1;
3106 Animation a = null;
3107 if (anim != 0) {
3108 a = AnimationUtils.loadAnimation(mContext, anim);
3109 } else {
3110 switch (transit) {
3111 case WindowManagerPolicy.TRANSIT_ENTER:
3112 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3113 break;
3114 case WindowManagerPolicy.TRANSIT_EXIT:
3115 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3116 break;
3117 case WindowManagerPolicy.TRANSIT_SHOW:
3118 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3119 break;
3120 case WindowManagerPolicy.TRANSIT_HIDE:
3121 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3122 break;
3123 }
3124 if (attr >= 0) {
3125 a = loadAnimation(win.mAttrs, attr);
3126 }
3127 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003128 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003129 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3130 + " mAnimation=" + win.mAnimation
3131 + " isEntrance=" + isEntrance);
3132 if (a != null) {
3133 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003134 RuntimeException e = null;
3135 if (!HIDE_STACK_CRAWLS) {
3136 e = new RuntimeException();
3137 e.fillInStackTrace();
3138 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003139 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 }
3141 win.setAnimation(a);
3142 win.mAnimationIsEntrance = isEntrance;
3143 }
3144 } else {
3145 win.clearAnimation();
3146 }
3147
3148 return win.mAnimation != null;
3149 }
3150
3151 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3152 int anim = 0;
3153 Context context = mContext;
3154 if (animAttr >= 0) {
3155 AttributeCache.Entry ent = getCachedAnimations(lp);
3156 if (ent != null) {
3157 context = ent.context;
3158 anim = ent.array.getResourceId(animAttr, 0);
3159 }
3160 }
3161 if (anim != 0) {
3162 return AnimationUtils.loadAnimation(context, anim);
3163 }
3164 return null;
3165 }
Romain Guy06882f82009-06-10 13:36:04 -07003166
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003167 private Animation loadAnimation(String packageName, int resId) {
3168 int anim = 0;
3169 Context context = mContext;
3170 if (resId >= 0) {
3171 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3172 if (ent != null) {
3173 context = ent.context;
3174 anim = resId;
3175 }
3176 }
3177 if (anim != 0) {
3178 return AnimationUtils.loadAnimation(context, anim);
3179 }
3180 return null;
3181 }
3182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 private boolean applyAnimationLocked(AppWindowToken wtoken,
3184 WindowManager.LayoutParams lp, int transit, boolean enter) {
3185 // Only apply an animation if the display isn't frozen. If it is
3186 // frozen, there is no reason to animate and it can cause strange
3187 // artifacts when we unfreeze the display if some different animation
3188 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003189 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003190 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003191 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003192 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003193 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003194 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003195 } else if (mNextAppTransitionPackage != null) {
3196 a = loadAnimation(mNextAppTransitionPackage, enter ?
3197 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003198 } else {
3199 int animAttr = 0;
3200 switch (transit) {
3201 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3202 animAttr = enter
3203 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3204 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3205 break;
3206 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3207 animAttr = enter
3208 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3209 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3210 break;
3211 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3212 animAttr = enter
3213 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3214 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3215 break;
3216 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3217 animAttr = enter
3218 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3219 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3220 break;
3221 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3222 animAttr = enter
3223 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3224 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3225 break;
3226 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3227 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003228 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003229 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3230 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003231 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003232 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003233 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3234 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003235 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003236 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003237 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003238 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3239 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3240 break;
3241 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3242 animAttr = enter
3243 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3244 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3245 break;
3246 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3247 animAttr = enter
3248 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3249 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003250 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003251 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003252 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003253 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003254 + " anim=" + a
3255 + " animAttr=0x" + Integer.toHexString(animAttr)
3256 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 if (a != null) {
3259 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003260 RuntimeException e = null;
3261 if (!HIDE_STACK_CRAWLS) {
3262 e = new RuntimeException();
3263 e.fillInStackTrace();
3264 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003265 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 }
3267 wtoken.setAnimation(a);
3268 }
3269 } else {
3270 wtoken.clearAnimation();
3271 }
3272
3273 return wtoken.animation != null;
3274 }
3275
3276 // -------------------------------------------------------------
3277 // Application Window Tokens
3278 // -------------------------------------------------------------
3279
3280 public void validateAppTokens(List tokens) {
3281 int v = tokens.size()-1;
3282 int m = mAppTokens.size()-1;
3283 while (v >= 0 && m >= 0) {
3284 AppWindowToken wtoken = mAppTokens.get(m);
3285 if (wtoken.removed) {
3286 m--;
3287 continue;
3288 }
3289 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003290 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3292 }
3293 v--;
3294 m--;
3295 }
3296 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003297 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 v--;
3299 }
3300 while (m >= 0) {
3301 AppWindowToken wtoken = mAppTokens.get(m);
3302 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003303 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 }
3305 m--;
3306 }
3307 }
3308
3309 boolean checkCallingPermission(String permission, String func) {
3310 // Quick check: if the calling permission is me, it's all okay.
3311 if (Binder.getCallingPid() == Process.myPid()) {
3312 return true;
3313 }
Romain Guy06882f82009-06-10 13:36:04 -07003314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 if (mContext.checkCallingPermission(permission)
3316 == PackageManager.PERMISSION_GRANTED) {
3317 return true;
3318 }
3319 String msg = "Permission Denial: " + func + " from pid="
3320 + Binder.getCallingPid()
3321 + ", uid=" + Binder.getCallingUid()
3322 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003323 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 return false;
3325 }
Romain Guy06882f82009-06-10 13:36:04 -07003326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 AppWindowToken findAppWindowToken(IBinder token) {
3328 WindowToken wtoken = mTokenMap.get(token);
3329 if (wtoken == null) {
3330 return null;
3331 }
3332 return wtoken.appWindowToken;
3333 }
Romain Guy06882f82009-06-10 13:36:04 -07003334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 public void addWindowToken(IBinder token, int type) {
3336 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3337 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003338 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 synchronized(mWindowMap) {
3342 WindowToken wtoken = mTokenMap.get(token);
3343 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003344 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 return;
3346 }
3347 wtoken = new WindowToken(token, type, true);
3348 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003349 if (type == TYPE_WALLPAPER) {
3350 mWallpaperTokens.add(wtoken);
3351 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 }
3353 }
Romain Guy06882f82009-06-10 13:36:04 -07003354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 public void removeWindowToken(IBinder token) {
3356 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3357 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003358 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 }
3360
3361 final long origId = Binder.clearCallingIdentity();
3362 synchronized(mWindowMap) {
3363 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 if (wtoken != null) {
3365 boolean delayed = false;
3366 if (!wtoken.hidden) {
3367 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 final int N = wtoken.windows.size();
3370 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 for (int i=0; i<N; i++) {
3373 WindowState win = wtoken.windows.get(i);
3374
3375 if (win.isAnimating()) {
3376 delayed = true;
3377 }
Romain Guy06882f82009-06-10 13:36:04 -07003378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 if (win.isVisibleNow()) {
3380 applyAnimationLocked(win,
3381 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 changed = true;
3383 }
3384 }
3385
3386 if (changed) {
3387 mLayoutNeeded = true;
3388 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003389 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3390 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003391 }
Romain Guy06882f82009-06-10 13:36:04 -07003392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 if (delayed) {
3394 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003395 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3396 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 }
3398 }
Romain Guy06882f82009-06-10 13:36:04 -07003399
Jeff Brown2e44b072011-01-24 15:21:56 -08003400 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003401 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003402 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 }
3404 }
3405 Binder.restoreCallingIdentity(origId);
3406 }
3407
3408 public void addAppToken(int addPos, IApplicationToken token,
3409 int groupId, int requestedOrientation, boolean fullscreen) {
3410 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3411 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003412 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 }
Jeff Brown349703e2010-06-22 01:27:15 -07003414
3415 // Get the dispatching timeout here while we are not holding any locks so that it
3416 // can be cached by the AppWindowToken. The timeout value is used later by the
3417 // input dispatcher in code that does hold locks. If we did not cache the value
3418 // here we would run the chance of introducing a deadlock between the window manager
3419 // (which holds locks while updating the input dispatcher state) and the activity manager
3420 // (which holds locks while querying the application token).
3421 long inputDispatchingTimeoutNanos;
3422 try {
3423 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3424 } catch (RemoteException ex) {
3425 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3426 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3427 }
Romain Guy06882f82009-06-10 13:36:04 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 synchronized(mWindowMap) {
3430 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3431 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003432 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 return;
3434 }
3435 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003436 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 wtoken.groupId = groupId;
3438 wtoken.appFullscreen = fullscreen;
3439 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003440 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003442 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 // Application tokens start out hidden.
3445 wtoken.hidden = true;
3446 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 //dump();
3449 }
3450 }
Romain Guy06882f82009-06-10 13:36:04 -07003451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452 public void setAppGroupId(IBinder token, int groupId) {
3453 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3454 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003455 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 }
3457
3458 synchronized(mWindowMap) {
3459 AppWindowToken wtoken = findAppWindowToken(token);
3460 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003461 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003462 return;
3463 }
3464 wtoken.groupId = groupId;
3465 }
3466 }
Romain Guy06882f82009-06-10 13:36:04 -07003467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 public int getOrientationFromWindowsLocked() {
3469 int pos = mWindows.size() - 1;
3470 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003471 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 pos--;
3473 if (wtoken.mAppToken != null) {
3474 // We hit an application window. so the orientation will be determined by the
3475 // app window. No point in continuing further.
3476 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3477 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003478 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003479 continue;
3480 }
3481 int req = wtoken.mAttrs.screenOrientation;
3482 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3483 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3484 continue;
3485 } else {
3486 return req;
3487 }
3488 }
3489 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3490 }
Romain Guy06882f82009-06-10 13:36:04 -07003491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003493 int pos = mAppTokens.size() - 1;
3494 int curGroup = 0;
3495 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3496 boolean findingBehind = false;
3497 boolean haveGroup = false;
3498 boolean lastFullscreen = false;
3499 while (pos >= 0) {
3500 AppWindowToken wtoken = mAppTokens.get(pos);
3501 pos--;
3502 // if we're about to tear down this window and not seek for
3503 // the behind activity, don't use it for orientation
3504 if (!findingBehind
3505 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3506 continue;
3507 }
3508
3509 if (!haveGroup) {
3510 // We ignore any hidden applications on the top.
3511 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003512 continue;
3513 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003514 haveGroup = true;
3515 curGroup = wtoken.groupId;
3516 lastOrientation = wtoken.requestedOrientation;
3517 } else if (curGroup != wtoken.groupId) {
3518 // If we have hit a new application group, and the bottom
3519 // of the previous group didn't explicitly say to use
3520 // the orientation behind it, and the last app was
3521 // full screen, then we'll stick with the
3522 // user's orientation.
3523 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3524 && lastFullscreen) {
3525 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003528 int or = wtoken.requestedOrientation;
3529 // If this application is fullscreen, and didn't explicitly say
3530 // to use the orientation behind it, then just take whatever
3531 // orientation it has and ignores whatever is under it.
3532 lastFullscreen = wtoken.appFullscreen;
3533 if (lastFullscreen
3534 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3535 return or;
3536 }
3537 // If this application has requested an explicit orientation,
3538 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003539 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3540 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003541 return or;
3542 }
3543 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3544 }
3545 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 }
Romain Guy06882f82009-06-10 13:36:04 -07003547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003549 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003550 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3551 "updateOrientationFromAppTokens()")) {
3552 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3553 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003554
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003555 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003557
3558 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003559 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003560 if (freezeThisOneIfNeeded != null) {
3561 AppWindowToken wtoken = findAppWindowToken(
3562 freezeThisOneIfNeeded);
3563 if (wtoken != null) {
3564 startAppFreezingScreenLocked(wtoken,
3565 ActivityInfo.CONFIG_ORIENTATION);
3566 }
3567 }
3568 config = computeNewConfigurationLocked();
3569
3570 } else if (currentConfig != null) {
3571 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003572 // state mismatches the activity manager's, update it,
3573 // disregarding font scale, which should remain set to
3574 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003575 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003576 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003577 if (computeNewConfigurationLocked(mTempConfiguration)) {
3578 if (currentConfig.diff(mTempConfiguration) != 0) {
3579 mWaitingForConfig = true;
3580 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003581 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003582 config = new Configuration(mTempConfiguration);
3583 }
3584 }
3585 }
3586 }
3587
Dianne Hackborncfaef692009-06-15 14:24:44 -07003588 Binder.restoreCallingIdentity(ident);
3589 return config;
3590 }
3591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003593 * Determine the new desired orientation of the display, returning
3594 * a non-null new Configuration if it has changed from the current
3595 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3596 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3597 * SCREEN. This will typically be done for you if you call
3598 * sendNewConfiguration().
3599 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 * The orientation is computed from non-application windows first. If none of
3601 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003602 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3604 * android.os.IBinder)
3605 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003606 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3607 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003608 // If the display is frozen, some activities may be in the middle
3609 // of restarting, and thus have removed their old window. If the
3610 // window has the flag to hide the lock screen, then the lock screen
3611 // can re-appear and inflict its own orientation on us. Keep the
3612 // orientation stable until this all settles down.
3613 return false;
3614 }
3615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 long ident = Binder.clearCallingIdentity();
3618 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003619 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 mForcedAppOrientation = req;
3623 //send a message to Policy indicating orientation change to take
3624 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003625 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003626 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003627 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3628 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003629 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 }
3631 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003632
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003633 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 } finally {
3635 Binder.restoreCallingIdentity(ident);
3636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 }
Romain Guy06882f82009-06-10 13:36:04 -07003638
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003639 int computeForcedAppOrientationLocked() {
3640 int req = getOrientationFromWindowsLocked();
3641 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3642 req = getOrientationFromAppTokensLocked();
3643 }
3644 return req;
3645 }
Romain Guy06882f82009-06-10 13:36:04 -07003646
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003647 public void setNewConfiguration(Configuration config) {
3648 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3649 "setNewConfiguration()")) {
3650 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3651 }
3652
3653 synchronized(mWindowMap) {
3654 mCurConfiguration = new Configuration(config);
3655 mWaitingForConfig = false;
3656 performLayoutAndPlaceSurfacesLocked();
3657 }
3658 }
3659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3661 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3662 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003663 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 }
Romain Guy06882f82009-06-10 13:36:04 -07003665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003666 synchronized(mWindowMap) {
3667 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3668 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003669 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 return;
3671 }
Romain Guy06882f82009-06-10 13:36:04 -07003672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 wtoken.requestedOrientation = requestedOrientation;
3674 }
3675 }
Romain Guy06882f82009-06-10 13:36:04 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 public int getAppOrientation(IApplicationToken token) {
3678 synchronized(mWindowMap) {
3679 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3680 if (wtoken == null) {
3681 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3682 }
Romain Guy06882f82009-06-10 13:36:04 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 return wtoken.requestedOrientation;
3685 }
3686 }
Romain Guy06882f82009-06-10 13:36:04 -07003687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3689 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3690 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003691 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 }
3693
3694 synchronized(mWindowMap) {
3695 boolean changed = false;
3696 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003697 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 changed = mFocusedApp != null;
3699 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003700 if (changed) {
3701 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 } else {
3704 AppWindowToken newFocus = findAppWindowToken(token);
3705 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003706 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 return;
3708 }
3709 changed = mFocusedApp != newFocus;
3710 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003711 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003712 if (changed) {
3713 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 }
3716
3717 if (moveFocusNow && changed) {
3718 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003719 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 Binder.restoreCallingIdentity(origId);
3721 }
3722 }
3723 }
3724
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003725 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3727 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003728 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 }
Romain Guy06882f82009-06-10 13:36:04 -07003730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003732 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 TAG, "Prepare app transition: transit=" + transit
3734 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003735 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003736 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3737 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003739 } else if (!alwaysKeepCurrent) {
3740 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3741 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3742 // Opening a new task always supersedes a close for the anim.
3743 mNextAppTransition = transit;
3744 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3745 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3746 // Opening a new activity always supersedes a close for the anim.
3747 mNextAppTransition = transit;
3748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 }
3750 mAppTransitionReady = false;
3751 mAppTransitionTimeout = false;
3752 mStartingIconInTransition = false;
3753 mSkipAppTransitionAnimation = false;
3754 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3755 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3756 5000);
3757 }
3758 }
3759 }
3760
3761 public int getPendingAppTransition() {
3762 return mNextAppTransition;
3763 }
Romain Guy06882f82009-06-10 13:36:04 -07003764
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003765 public void overridePendingAppTransition(String packageName,
3766 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003767 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003768 mNextAppTransitionPackage = packageName;
3769 mNextAppTransitionEnter = enterAnim;
3770 mNextAppTransitionExit = exitAnim;
3771 }
3772 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 public void executeAppTransition() {
3775 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3776 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003777 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 }
Romain Guy06882f82009-06-10 13:36:04 -07003779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003781 if (DEBUG_APP_TRANSITIONS) {
3782 RuntimeException e = new RuntimeException("here");
3783 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003784 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003785 + mNextAppTransition, e);
3786 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003787 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 mAppTransitionReady = true;
3789 final long origId = Binder.clearCallingIdentity();
3790 performLayoutAndPlaceSurfacesLocked();
3791 Binder.restoreCallingIdentity(origId);
3792 }
3793 }
3794 }
3795
3796 public void setAppStartingWindow(IBinder token, String pkg,
3797 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003798 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3800 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003801 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003802 }
3803
3804 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003805 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3807 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 AppWindowToken wtoken = findAppWindowToken(token);
3810 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003811 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 return;
3813 }
3814
3815 // If the display is frozen, we won't do anything until the
3816 // actual window is displayed so there is no reason to put in
3817 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003818 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 return;
3820 }
Romain Guy06882f82009-06-10 13:36:04 -07003821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 if (wtoken.startingData != null) {
3823 return;
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 if (transferFrom != null) {
3827 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3828 if (ttoken != null) {
3829 WindowState startingWindow = ttoken.startingWindow;
3830 if (startingWindow != null) {
3831 if (mStartingIconInTransition) {
3832 // In this case, the starting icon has already
3833 // been displayed, so start letting windows get
3834 // shown immediately without any more transitions.
3835 mSkipAppTransitionAnimation = true;
3836 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003837 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 "Moving existing starting from " + ttoken
3839 + " to " + wtoken);
3840 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 // Transfer the starting window over to the new
3843 // token.
3844 wtoken.startingData = ttoken.startingData;
3845 wtoken.startingView = ttoken.startingView;
3846 wtoken.startingWindow = startingWindow;
3847 ttoken.startingData = null;
3848 ttoken.startingView = null;
3849 ttoken.startingWindow = null;
3850 ttoken.startingMoved = true;
3851 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003852 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003854 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003855 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003857 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003858 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3859 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 ttoken.windows.remove(startingWindow);
3861 ttoken.allAppWindows.remove(startingWindow);
3862 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 // Propagate other interesting state between the
3865 // tokens. If the old token is displayed, we should
3866 // immediately force the new one to be displayed. If
3867 // it is animating, we need to move that animation to
3868 // the new one.
3869 if (ttoken.allDrawn) {
3870 wtoken.allDrawn = true;
3871 }
3872 if (ttoken.firstWindowDrawn) {
3873 wtoken.firstWindowDrawn = true;
3874 }
3875 if (!ttoken.hidden) {
3876 wtoken.hidden = false;
3877 wtoken.hiddenRequested = false;
3878 wtoken.willBeHidden = false;
3879 }
3880 if (wtoken.clientHidden != ttoken.clientHidden) {
3881 wtoken.clientHidden = ttoken.clientHidden;
3882 wtoken.sendAppVisibilityToClients();
3883 }
3884 if (ttoken.animation != null) {
3885 wtoken.animation = ttoken.animation;
3886 wtoken.animating = ttoken.animating;
3887 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3888 ttoken.animation = null;
3889 ttoken.animLayerAdjustment = 0;
3890 wtoken.updateLayers();
3891 ttoken.updateLayers();
3892 }
Romain Guy06882f82009-06-10 13:36:04 -07003893
Jeff Brown3a22cd92011-01-21 13:59:04 -08003894 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3895 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 mLayoutNeeded = true;
3897 performLayoutAndPlaceSurfacesLocked();
3898 Binder.restoreCallingIdentity(origId);
3899 return;
3900 } else if (ttoken.startingData != null) {
3901 // The previous app was getting ready to show a
3902 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003903 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 "Moving pending starting from " + ttoken
3905 + " to " + wtoken);
3906 wtoken.startingData = ttoken.startingData;
3907 ttoken.startingData = null;
3908 ttoken.startingMoved = true;
3909 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3910 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3911 // want to process the message ASAP, before any other queued
3912 // messages.
3913 mH.sendMessageAtFrontOfQueue(m);
3914 return;
3915 }
3916 }
3917 }
3918
3919 // There is no existing starting window, and the caller doesn't
3920 // want us to create one, so that's it!
3921 if (!createIfNeeded) {
3922 return;
3923 }
Romain Guy06882f82009-06-10 13:36:04 -07003924
Dianne Hackborn284ac932009-08-28 10:34:25 -07003925 // If this is a translucent or wallpaper window, then don't
3926 // show a starting window -- the current effect (a full-screen
3927 // opaque starting window that fades away to the real contents
3928 // when it is ready) does not work for this.
3929 if (theme != 0) {
3930 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3931 com.android.internal.R.styleable.Window);
3932 if (ent.array.getBoolean(
3933 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3934 return;
3935 }
3936 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003937 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3938 return;
3939 }
3940 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003941 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3942 return;
3943 }
3944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 mStartingIconInTransition = true;
3947 wtoken.startingData = new StartingData(
3948 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003949 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003950 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3951 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3952 // want to process the message ASAP, before any other queued
3953 // messages.
3954 mH.sendMessageAtFrontOfQueue(m);
3955 }
3956 }
3957
3958 public void setAppWillBeHidden(IBinder token) {
3959 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3960 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003961 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 }
3963
3964 AppWindowToken wtoken;
3965
3966 synchronized(mWindowMap) {
3967 wtoken = findAppWindowToken(token);
3968 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003969 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 -08003970 return;
3971 }
3972 wtoken.willBeHidden = true;
3973 }
3974 }
Romain Guy06882f82009-06-10 13:36:04 -07003975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3977 boolean visible, int transit, boolean performLayout) {
3978 boolean delayed = false;
3979
3980 if (wtoken.clientHidden == visible) {
3981 wtoken.clientHidden = !visible;
3982 wtoken.sendAppVisibilityToClients();
3983 }
Romain Guy06882f82009-06-10 13:36:04 -07003984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 wtoken.willBeHidden = false;
3986 if (wtoken.hidden == visible) {
3987 final int N = wtoken.allAppWindows.size();
3988 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003989 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3991 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003994
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003995 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 if (wtoken.animation == sDummyAnimation) {
3997 wtoken.animation = null;
3998 }
3999 applyAnimationLocked(wtoken, lp, transit, visible);
4000 changed = true;
4001 if (wtoken.animation != null) {
4002 delayed = runningAppAnimation = true;
4003 }
4004 }
Romain Guy06882f82009-06-10 13:36:04 -07004005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 for (int i=0; i<N; i++) {
4007 WindowState win = wtoken.allAppWindows.get(i);
4008 if (win == wtoken.startingWindow) {
4009 continue;
4010 }
4011
4012 if (win.isAnimating()) {
4013 delayed = true;
4014 }
Romain Guy06882f82009-06-10 13:36:04 -07004015
Joe Onorato8a9b2202010-02-26 18:56:32 -08004016 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004017 //win.dump(" ");
4018 if (visible) {
4019 if (!win.isVisibleNow()) {
4020 if (!runningAppAnimation) {
4021 applyAnimationLocked(win,
4022 WindowManagerPolicy.TRANSIT_ENTER, true);
4023 }
4024 changed = true;
4025 }
4026 } else if (win.isVisibleNow()) {
4027 if (!runningAppAnimation) {
4028 applyAnimationLocked(win,
4029 WindowManagerPolicy.TRANSIT_EXIT, false);
4030 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 changed = true;
4032 }
4033 }
4034
4035 wtoken.hidden = wtoken.hiddenRequested = !visible;
4036 if (!visible) {
4037 unsetAppFreezingScreenLocked(wtoken, true, true);
4038 } else {
4039 // If we are being set visible, and the starting window is
4040 // not yet displayed, then make sure it doesn't get displayed.
4041 WindowState swin = wtoken.startingWindow;
4042 if (swin != null && (swin.mDrawPending
4043 || swin.mCommitDrawPending)) {
4044 swin.mPolicyVisibility = false;
4045 swin.mPolicyVisibilityAfterAnim = false;
4046 }
4047 }
Romain Guy06882f82009-06-10 13:36:04 -07004048
Joe Onorato8a9b2202010-02-26 18:56:32 -08004049 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4051 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004052
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004053 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004055 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004056 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004057 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4058 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004059 performLayoutAndPlaceSurfacesLocked();
4060 }
Jeff Brown2e44b072011-01-24 15:21:56 -08004061 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004062 }
4063 }
4064
4065 if (wtoken.animation != null) {
4066 delayed = true;
4067 }
Romain Guy06882f82009-06-10 13:36:04 -07004068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004069 return delayed;
4070 }
4071
4072 public void setAppVisibility(IBinder token, boolean visible) {
4073 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4074 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004075 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 }
4077
4078 AppWindowToken wtoken;
4079
4080 synchronized(mWindowMap) {
4081 wtoken = findAppWindowToken(token);
4082 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004083 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 return;
4085 }
4086
4087 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004088 RuntimeException e = null;
4089 if (!HIDE_STACK_CRAWLS) {
4090 e = new RuntimeException();
4091 e.fillInStackTrace();
4092 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004093 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094 + "): mNextAppTransition=" + mNextAppTransition
4095 + " hidden=" + wtoken.hidden
4096 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4097 }
Romain Guy06882f82009-06-10 13:36:04 -07004098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 // If we are preparing an app transition, then delay changing
4100 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004101 if (!mDisplayFrozen && mPolicy.isScreenOn()
4102 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 // Already in requested state, don't do anything more.
4104 if (wtoken.hiddenRequested != visible) {
4105 return;
4106 }
4107 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004108
Joe Onorato8a9b2202010-02-26 18:56:32 -08004109 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 TAG, "Setting dummy animation on: " + wtoken);
4111 wtoken.setDummyAnimation();
4112 mOpeningApps.remove(wtoken);
4113 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004114 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 wtoken.inPendingTransaction = true;
4116 if (visible) {
4117 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004118 wtoken.startingDisplayed = false;
4119 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004120
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004121 // If the token is currently hidden (should be the
4122 // common case), then we need to set up to wait for
4123 // its windows to be ready.
4124 if (wtoken.hidden) {
4125 wtoken.allDrawn = false;
4126 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004127
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004128 if (wtoken.clientHidden) {
4129 // In the case where we are making an app visible
4130 // but holding off for a transition, we still need
4131 // to tell the client to make its windows visible so
4132 // they get drawn. Otherwise, we will wait on
4133 // performing the transition until all windows have
4134 // been drawn, they never will be, and we are sad.
4135 wtoken.clientHidden = false;
4136 wtoken.sendAppVisibilityToClients();
4137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004138 }
4139 } else {
4140 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004141
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004142 // If the token is currently visible (should be the
4143 // common case), then set up to wait for it to be hidden.
4144 if (!wtoken.hidden) {
4145 wtoken.waitingToHide = true;
4146 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147 }
4148 return;
4149 }
Romain Guy06882f82009-06-10 13:36:04 -07004150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004152 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 wtoken.updateReportedVisibilityLocked();
4154 Binder.restoreCallingIdentity(origId);
4155 }
4156 }
4157
4158 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4159 boolean unfreezeSurfaceNow, boolean force) {
4160 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004161 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 + " force=" + force);
4163 final int N = wtoken.allAppWindows.size();
4164 boolean unfrozeWindows = false;
4165 for (int i=0; i<N; i++) {
4166 WindowState w = wtoken.allAppWindows.get(i);
4167 if (w.mAppFreezing) {
4168 w.mAppFreezing = false;
4169 if (w.mSurface != null && !w.mOrientationChanging) {
4170 w.mOrientationChanging = true;
4171 }
4172 unfrozeWindows = true;
4173 }
4174 }
4175 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004176 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 wtoken.freezingScreen = false;
4178 mAppsFreezingScreen--;
4179 }
4180 if (unfreezeSurfaceNow) {
4181 if (unfrozeWindows) {
4182 mLayoutNeeded = true;
4183 performLayoutAndPlaceSurfacesLocked();
4184 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004185 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 }
4187 }
4188 }
Romain Guy06882f82009-06-10 13:36:04 -07004189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4191 int configChanges) {
4192 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004193 RuntimeException e = null;
4194 if (!HIDE_STACK_CRAWLS) {
4195 e = new RuntimeException();
4196 e.fillInStackTrace();
4197 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 + ": hidden=" + wtoken.hidden + " freezing="
4200 + wtoken.freezingScreen, e);
4201 }
4202 if (!wtoken.hiddenRequested) {
4203 if (!wtoken.freezingScreen) {
4204 wtoken.freezingScreen = true;
4205 mAppsFreezingScreen++;
4206 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004207 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4209 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4210 5000);
4211 }
4212 }
4213 final int N = wtoken.allAppWindows.size();
4214 for (int i=0; i<N; i++) {
4215 WindowState w = wtoken.allAppWindows.get(i);
4216 w.mAppFreezing = true;
4217 }
4218 }
4219 }
Romain Guy06882f82009-06-10 13:36:04 -07004220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 public void startAppFreezingScreen(IBinder token, int configChanges) {
4222 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4223 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004224 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 }
4226
4227 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004228 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004229 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004230 return;
4231 }
Romain Guy06882f82009-06-10 13:36:04 -07004232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004233 AppWindowToken wtoken = findAppWindowToken(token);
4234 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004235 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004236 return;
4237 }
4238 final long origId = Binder.clearCallingIdentity();
4239 startAppFreezingScreenLocked(wtoken, configChanges);
4240 Binder.restoreCallingIdentity(origId);
4241 }
4242 }
Romain Guy06882f82009-06-10 13:36:04 -07004243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 public void stopAppFreezingScreen(IBinder token, boolean force) {
4245 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4246 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004247 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 }
4249
4250 synchronized(mWindowMap) {
4251 AppWindowToken wtoken = findAppWindowToken(token);
4252 if (wtoken == null || wtoken.appToken == null) {
4253 return;
4254 }
4255 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004256 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4258 unsetAppFreezingScreenLocked(wtoken, true, force);
4259 Binder.restoreCallingIdentity(origId);
4260 }
4261 }
Romain Guy06882f82009-06-10 13:36:04 -07004262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004263 public void removeAppToken(IBinder token) {
4264 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4265 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004266 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 }
4268
4269 AppWindowToken wtoken = null;
4270 AppWindowToken startingToken = null;
4271 boolean delayed = false;
4272
4273 final long origId = Binder.clearCallingIdentity();
4274 synchronized(mWindowMap) {
4275 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004277 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004278 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 wtoken.inPendingTransaction = false;
4280 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004281 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 if (mClosingApps.contains(wtoken)) {
4283 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004284 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004286 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 delayed = true;
4288 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004289 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 TAG, "Removing app " + wtoken + " delayed=" + delayed
4291 + " animation=" + wtoken.animation
4292 + " animating=" + wtoken.animating);
4293 if (delayed) {
4294 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004295 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4296 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004298 } else {
4299 // Make sure there is no animation running on this token,
4300 // so any windows associated with it will be removed as
4301 // soon as their animations are complete
4302 wtoken.animation = null;
4303 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004305 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4306 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 mAppTokens.remove(wtoken);
4308 wtoken.removed = true;
4309 if (wtoken.startingData != null) {
4310 startingToken = wtoken;
4311 }
4312 unsetAppFreezingScreenLocked(wtoken, true, true);
4313 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004314 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004316 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004317 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
4319 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004320 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 }
Romain Guy06882f82009-06-10 13:36:04 -07004322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 if (!delayed && wtoken != null) {
4324 wtoken.updateReportedVisibilityLocked();
4325 }
4326 }
4327 Binder.restoreCallingIdentity(origId);
4328
4329 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004330 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 + startingToken + ": app token removed");
4332 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4333 mH.sendMessage(m);
4334 }
4335 }
4336
4337 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4338 final int NW = token.windows.size();
4339 for (int i=0; i<NW; i++) {
4340 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004341 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004343 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004344 int j = win.mChildWindows.size();
4345 while (j > 0) {
4346 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004347 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004348 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004349 "Tmp removing child window " + cwin);
4350 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 }
4352 }
4353 return NW > 0;
4354 }
4355
4356 void dumpAppTokensLocked() {
4357 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004358 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 }
4360 }
Romain Guy06882f82009-06-10 13:36:04 -07004361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 void dumpWindowsLocked() {
4363 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004364 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
4366 }
Romain Guy06882f82009-06-10 13:36:04 -07004367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 private int findWindowOffsetLocked(int tokenPos) {
4369 final int NW = mWindows.size();
4370
4371 if (tokenPos >= mAppTokens.size()) {
4372 int i = NW;
4373 while (i > 0) {
4374 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004375 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004376 if (win.getAppToken() != null) {
4377 return i+1;
4378 }
4379 }
4380 }
4381
4382 while (tokenPos > 0) {
4383 // Find the first app token below the new position that has
4384 // a window displayed.
4385 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004386 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004388 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004389 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004390 "Skipping token -- currently sending to bottom");
4391 tokenPos--;
4392 continue;
4393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 int i = wtoken.windows.size();
4395 while (i > 0) {
4396 i--;
4397 WindowState win = wtoken.windows.get(i);
4398 int j = win.mChildWindows.size();
4399 while (j > 0) {
4400 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004401 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004402 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 for (int pos=NW-1; pos>=0; pos--) {
4404 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004405 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 "Found child win @" + (pos+1));
4407 return pos+1;
4408 }
4409 }
4410 }
4411 }
4412 for (int pos=NW-1; pos>=0; pos--) {
4413 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004414 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 return pos+1;
4416 }
4417 }
4418 }
4419 tokenPos--;
4420 }
4421
4422 return 0;
4423 }
4424
4425 private final int reAddWindowLocked(int index, WindowState win) {
4426 final int NCW = win.mChildWindows.size();
4427 boolean added = false;
4428 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004429 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004430 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004431 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004432 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004433 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004434 mWindows.add(index, win);
4435 index++;
4436 added = true;
4437 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004438 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004439 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004440 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 mWindows.add(index, cwin);
4442 index++;
4443 }
4444 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004445 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004446 + index + ": " + win);
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 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004451 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 return index;
4453 }
Romain Guy06882f82009-06-10 13:36:04 -07004454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4456 final int NW = token.windows.size();
4457 for (int i=0; i<NW; i++) {
4458 index = reAddWindowLocked(index, token.windows.get(i));
4459 }
4460 return index;
4461 }
4462
4463 public void moveAppToken(int index, IBinder token) {
4464 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4465 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004466 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 }
4468
4469 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004470 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 if (DEBUG_REORDER) dumpAppTokensLocked();
4472 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004473 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4474 "Start moving token " + wtoken + " initially at "
4475 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004477 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 + token + " (" + wtoken + ")");
4479 return;
4480 }
4481 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004482 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004483 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004487 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488 if (DEBUG_REORDER) dumpWindowsLocked();
4489 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004490 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004491 if (DEBUG_REORDER) dumpWindowsLocked();
4492 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004493 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004495 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4496 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004498 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004500 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 }
4502 Binder.restoreCallingIdentity(origId);
4503 }
4504 }
4505
4506 private void removeAppTokensLocked(List<IBinder> tokens) {
4507 // XXX This should be done more efficiently!
4508 // (take advantage of the fact that both lists should be
4509 // ordered in the same way.)
4510 int N = tokens.size();
4511 for (int i=0; i<N; i++) {
4512 IBinder token = tokens.get(i);
4513 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004514 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4515 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004517 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004518 + token + " (" + wtoken + ")");
4519 i--;
4520 N--;
4521 }
4522 }
4523 }
4524
Dianne Hackborna8f60182009-09-01 19:01:50 -07004525 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4526 boolean updateFocusAndLayout) {
4527 // First remove all of the windows from the list.
4528 tmpRemoveAppWindowsLocked(wtoken);
4529
4530 // Where to start adding?
4531 int pos = findWindowOffsetLocked(tokenPos);
4532
4533 // And now add them back at the correct place.
4534 pos = reAddAppWindowsLocked(pos, wtoken);
4535
4536 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004537 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004538 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4539 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004540 assignLayersLocked();
4541 }
4542 mLayoutNeeded = true;
4543 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004544 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004545 }
4546 }
4547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4549 // First remove all of the windows from the list.
4550 final int N = tokens.size();
4551 int i;
4552 for (i=0; i<N; i++) {
4553 WindowToken token = mTokenMap.get(tokens.get(i));
4554 if (token != null) {
4555 tmpRemoveAppWindowsLocked(token);
4556 }
4557 }
4558
4559 // Where to start adding?
4560 int pos = findWindowOffsetLocked(tokenPos);
4561
4562 // And now add them back at the correct place.
4563 for (i=0; i<N; i++) {
4564 WindowToken token = mTokenMap.get(tokens.get(i));
4565 if (token != null) {
4566 pos = reAddAppWindowsLocked(pos, token);
4567 }
4568 }
4569
Jeff Brown2e44b072011-01-24 15:21:56 -08004570 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004571 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4572 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004573 assignLayersLocked();
4574 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 mLayoutNeeded = true;
4576 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004577 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578
4579 //dump();
4580 }
4581
4582 public void moveAppTokensToTop(List<IBinder> tokens) {
4583 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4584 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004585 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 }
4587
4588 final long origId = Binder.clearCallingIdentity();
4589 synchronized(mWindowMap) {
4590 removeAppTokensLocked(tokens);
4591 final int N = tokens.size();
4592 for (int i=0; i<N; i++) {
4593 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4594 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004595 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4596 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004597 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004598 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004599 mToTopApps.remove(wt);
4600 mToBottomApps.remove(wt);
4601 mToTopApps.add(wt);
4602 wt.sendingToBottom = false;
4603 wt.sendingToTop = true;
4604 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004605 }
4606 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004607
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004608 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004609 moveAppWindowsLocked(tokens, mAppTokens.size());
4610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 }
4612 Binder.restoreCallingIdentity(origId);
4613 }
4614
4615 public void moveAppTokensToBottom(List<IBinder> tokens) {
4616 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4617 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004618 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004619 }
4620
4621 final long origId = Binder.clearCallingIdentity();
4622 synchronized(mWindowMap) {
4623 removeAppTokensLocked(tokens);
4624 final int N = tokens.size();
4625 int pos = 0;
4626 for (int i=0; i<N; i++) {
4627 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4628 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004629 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4630 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004632 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004633 mToTopApps.remove(wt);
4634 mToBottomApps.remove(wt);
4635 mToBottomApps.add(i, wt);
4636 wt.sendingToTop = false;
4637 wt.sendingToBottom = true;
4638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 pos++;
4640 }
4641 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004642
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004643 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004644 moveAppWindowsLocked(tokens, 0);
4645 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 }
4647 Binder.restoreCallingIdentity(origId);
4648 }
4649
4650 // -------------------------------------------------------------
4651 // Misc IWindowSession methods
4652 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004653
Jim Miller284b62e2010-06-08 14:27:42 -07004654 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004655 {
Jim Miller284b62e2010-06-08 14:27:42 -07004656 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4657 // called before DevicePolicyManagerService has started.
4658 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4659 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4660 Context.DEVICE_POLICY_SERVICE);
4661 if (dpm != null) {
4662 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4663 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4664 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4665 }
Jim Millerd6b57052010-06-07 17:52:42 -07004666 }
Jim Miller284b62e2010-06-08 14:27:42 -07004667 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004668 }
4669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004671 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 != PackageManager.PERMISSION_GRANTED) {
4673 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4674 }
Jim Millerd6b57052010-06-07 17:52:42 -07004675
Jim Miller284b62e2010-06-08 14:27:42 -07004676 synchronized (mKeyguardTokenWatcher) {
4677 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004678 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004679 }
4680
4681 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004682 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 != PackageManager.PERMISSION_GRANTED) {
4684 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686
Jim Miller284b62e2010-06-08 14:27:42 -07004687 synchronized (mKeyguardTokenWatcher) {
4688 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004689
Jim Miller284b62e2010-06-08 14:27:42 -07004690 if (!mKeyguardTokenWatcher.isAcquired()) {
4691 // If we are the last one to reenable the keyguard wait until
4692 // we have actually finished reenabling until returning.
4693 // It is possible that reenableKeyguard() can be called before
4694 // the previous disableKeyguard() is handled, in which case
4695 // neither mKeyguardTokenWatcher.acquired() or released() would
4696 // be called. In that case mKeyguardDisabled will be false here
4697 // and we have nothing to wait for.
4698 while (mKeyguardDisabled) {
4699 try {
4700 mKeyguardTokenWatcher.wait();
4701 } catch (InterruptedException e) {
4702 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004703 }
4704 }
4705 }
4706 }
4707 }
4708
4709 /**
4710 * @see android.app.KeyguardManager#exitKeyguardSecurely
4711 */
4712 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004713 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 != PackageManager.PERMISSION_GRANTED) {
4715 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4716 }
4717 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4718 public void onKeyguardExitResult(boolean success) {
4719 try {
4720 callback.onKeyguardExitResult(success);
4721 } catch (RemoteException e) {
4722 // Client has died, we don't care.
4723 }
4724 }
4725 });
4726 }
4727
4728 public boolean inKeyguardRestrictedInputMode() {
4729 return mPolicy.inKeyguardRestrictedKeyInputMode();
4730 }
Romain Guy06882f82009-06-10 13:36:04 -07004731
Dianne Hackbornffa42482009-09-23 22:20:11 -07004732 public void closeSystemDialogs(String reason) {
4733 synchronized(mWindowMap) {
4734 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004735 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004736 if (w.mSurface != null) {
4737 try {
4738 w.mClient.closeSystemDialogs(reason);
4739 } catch (RemoteException e) {
4740 }
4741 }
4742 }
4743 }
4744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004746 static float fixScale(float scale) {
4747 if (scale < 0) scale = 0;
4748 else if (scale > 20) scale = 20;
4749 return Math.abs(scale);
4750 }
Romain Guy06882f82009-06-10 13:36:04 -07004751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 public void setAnimationScale(int which, float scale) {
4753 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4754 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004755 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 }
4757
4758 if (scale < 0) scale = 0;
4759 else if (scale > 20) scale = 20;
4760 scale = Math.abs(scale);
4761 switch (which) {
4762 case 0: mWindowAnimationScale = fixScale(scale); break;
4763 case 1: mTransitionAnimationScale = fixScale(scale); break;
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 // Persist setting
4767 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4768 }
Romain Guy06882f82009-06-10 13:36:04 -07004769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770 public void setAnimationScales(float[] scales) {
4771 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4772 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004773 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004774 }
4775
4776 if (scales != null) {
4777 if (scales.length >= 1) {
4778 mWindowAnimationScale = fixScale(scales[0]);
4779 }
4780 if (scales.length >= 2) {
4781 mTransitionAnimationScale = fixScale(scales[1]);
4782 }
4783 }
Romain Guy06882f82009-06-10 13:36:04 -07004784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004785 // Persist setting
4786 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4787 }
Romain Guy06882f82009-06-10 13:36:04 -07004788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 public float getAnimationScale(int which) {
4790 switch (which) {
4791 case 0: return mWindowAnimationScale;
4792 case 1: return mTransitionAnimationScale;
4793 }
4794 return 0;
4795 }
Romain Guy06882f82009-06-10 13:36:04 -07004796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 public float[] getAnimationScales() {
4798 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4799 }
Romain Guy06882f82009-06-10 13:36:04 -07004800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 public int getSwitchState(int sw) {
4802 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4803 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004804 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004806 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 }
Romain Guy06882f82009-06-10 13:36:04 -07004808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004809 public int getSwitchStateForDevice(int devid, int sw) {
4810 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4811 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004812 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004814 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004815 }
Romain Guy06882f82009-06-10 13:36:04 -07004816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004817 public int getScancodeState(int sw) {
4818 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4819 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004820 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004822 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 }
Romain Guy06882f82009-06-10 13:36:04 -07004824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004825 public int getScancodeStateForDevice(int devid, int sw) {
4826 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4827 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004828 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004830 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 }
Romain Guy06882f82009-06-10 13:36:04 -07004832
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004833 public int getTrackballScancodeState(int sw) {
4834 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4835 "getTrackballScancodeState()")) {
4836 throw new SecurityException("Requires READ_INPUT_STATE permission");
4837 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004838 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004839 }
4840
4841 public int getDPadScancodeState(int sw) {
4842 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4843 "getDPadScancodeState()")) {
4844 throw new SecurityException("Requires READ_INPUT_STATE permission");
4845 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004846 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004847 }
4848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849 public int getKeycodeState(int sw) {
4850 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4851 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004852 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004854 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 }
Romain Guy06882f82009-06-10 13:36:04 -07004856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 public int getKeycodeStateForDevice(int devid, int sw) {
4858 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4859 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004860 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004862 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 }
Romain Guy06882f82009-06-10 13:36:04 -07004864
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004865 public int getTrackballKeycodeState(int sw) {
4866 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4867 "getTrackballKeycodeState()")) {
4868 throw new SecurityException("Requires READ_INPUT_STATE permission");
4869 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004870 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004871 }
4872
4873 public int getDPadKeycodeState(int sw) {
4874 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4875 "getDPadKeycodeState()")) {
4876 throw new SecurityException("Requires READ_INPUT_STATE permission");
4877 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004878 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004879 }
Jeff Browna41ca772010-08-11 14:46:32 -07004880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004882 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883 }
Romain Guy06882f82009-06-10 13:36:04 -07004884
Jeff Browna41ca772010-08-11 14:46:32 -07004885 public InputChannel monitorInput(String inputChannelName) {
4886 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4887 "monitorInput()")) {
4888 throw new SecurityException("Requires READ_INPUT_STATE permission");
4889 }
4890 return mInputManager.monitorInput(inputChannelName);
4891 }
4892
Jeff Brown8d608662010-08-30 03:02:23 -07004893 public InputDevice getInputDevice(int deviceId) {
4894 return mInputManager.getInputDevice(deviceId);
4895 }
4896
4897 public int[] getInputDeviceIds() {
4898 return mInputManager.getInputDeviceIds();
4899 }
4900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004901 public void enableScreenAfterBoot() {
4902 synchronized(mWindowMap) {
4903 if (mSystemBooted) {
4904 return;
4905 }
4906 mSystemBooted = true;
4907 }
Romain Guy06882f82009-06-10 13:36:04 -07004908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004909 performEnableScreen();
4910 }
Romain Guy06882f82009-06-10 13:36:04 -07004911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004912 public void enableScreenIfNeededLocked() {
4913 if (mDisplayEnabled) {
4914 return;
4915 }
4916 if (!mSystemBooted) {
4917 return;
4918 }
4919 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4920 }
Romain Guy06882f82009-06-10 13:36:04 -07004921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004922 public void performEnableScreen() {
4923 synchronized(mWindowMap) {
4924 if (mDisplayEnabled) {
4925 return;
4926 }
4927 if (!mSystemBooted) {
4928 return;
4929 }
Romain Guy06882f82009-06-10 13:36:04 -07004930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 // Don't enable the screen until all existing windows
4932 // have been drawn.
4933 final int N = mWindows.size();
4934 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004935 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004936 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 return;
4938 }
4939 }
Romain Guy06882f82009-06-10 13:36:04 -07004940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004941 mDisplayEnabled = true;
4942 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004943 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004944 StringWriter sw = new StringWriter();
4945 PrintWriter pw = new PrintWriter(sw);
4946 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004947 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004948 }
4949 try {
4950 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4951 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004952 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 Parcel data = Parcel.obtain();
4954 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4955 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4956 data, null, 0);
4957 data.recycle();
4958 }
4959 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004960 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961 }
4962 }
Romain Guy06882f82009-06-10 13:36:04 -07004963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004966 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004967 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4968 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004969 }
Romain Guy06882f82009-06-10 13:36:04 -07004970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004971 public void setInTouchMode(boolean mode) {
4972 synchronized(mWindowMap) {
4973 mInTouchMode = mode;
4974 }
4975 }
4976
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004977 // TODO: more accounting of which pid(s) turned it on, keep count,
4978 // only allow disables from pids which have count on, etc.
4979 public void showStrictModeViolation(boolean on) {
4980 int pid = Binder.getCallingPid();
4981 synchronized(mWindowMap) {
4982 // Ignoring requests to enable the red border from clients
4983 // which aren't on screen. (e.g. Broadcast Receivers in
4984 // the background..)
4985 if (on) {
4986 boolean isVisible = false;
4987 for (WindowState ws : mWindows) {
4988 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4989 isVisible = true;
4990 break;
4991 }
4992 }
4993 if (!isVisible) {
4994 return;
4995 }
4996 }
4997
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004998 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004999 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005000 try {
5001 if (mStrictModeFlash == null) {
5002 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
5003 }
5004 mStrictModeFlash.setVisibility(on);
5005 } finally {
5006 Surface.closeTransaction();
5007 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005008 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08005009 }
5010 }
5011
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08005012 public void setStrictModeVisualIndicatorPreference(String value) {
5013 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
5014 }
5015
Dianne Hackbornd2835932010-12-13 16:28:46 -08005016 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005017 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
5018 "screenshotApplications()")) {
5019 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5020 }
5021
5022 Bitmap rawss;
5023
Dianne Hackbornd2835932010-12-13 16:28:46 -08005024 int maxLayer = 0;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005025 final Rect frame = new Rect();
5026
5027 float scale;
5028 int sw, sh, dw, dh;
5029 int rot;
5030
5031 synchronized(mWindowMap) {
5032 long ident = Binder.clearCallingIdentity();
5033
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005034 dw = mDisplay.getWidth();
5035 dh = mDisplay.getHeight();
5036
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005037 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5038 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5039 + TYPE_LAYER_OFFSET;
5040 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5041
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005042 boolean isImeTarget = mInputMethodTarget != null
5043 && mInputMethodTarget.mAppToken != null
5044 && mInputMethodTarget.mAppToken.appToken != null
5045 && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
5046
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005047 // Figure out the part of the screen that is actually the app.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005048 boolean including = false;
5049 for (int i=mWindows.size()-1; i>=0; i--) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005050 WindowState ws = mWindows.get(i);
5051 if (ws.mSurface == null) {
5052 continue;
5053 }
5054 if (ws.mLayer >= aboveAppLayer) {
Dianne Hackbornd2835932010-12-13 16:28:46 -08005055 continue;
5056 }
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005057 // When we will skip windows: when we are not including
5058 // ones behind a window we didn't skip, and we are actually
5059 // taking a screenshot of a specific app.
5060 if (!including && appToken != null) {
5061 // Also, we can possibly skip this window if it is not
5062 // an IME target or the application for the screenshot
5063 // is not the current IME target.
5064 if (!ws.mIsImWindow || !isImeTarget) {
5065 // And finally, this window is of no interest if it
5066 // is not associated with the screenshot app.
5067 if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
5068 continue;
5069 }
5070 }
5071 }
5072
5073 // We keep on including windows until we go past a full-screen
5074 // window.
5075 including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
5076
Dianne Hackbornd2835932010-12-13 16:28:46 -08005077 if (maxLayer < ws.mAnimLayer) {
5078 maxLayer = ws.mAnimLayer;
5079 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005080 final Rect wf = ws.mFrame;
5081 final Rect cr = ws.mContentInsets;
5082 int left = wf.left + cr.left;
5083 int top = wf.top + cr.top;
5084 int right = wf.right - cr.right;
5085 int bottom = wf.bottom - cr.bottom;
5086 frame.union(left, top, right, bottom);
5087 }
5088 Binder.restoreCallingIdentity(ident);
5089
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005090 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005091 return null;
5092 }
5093
5094 // The screenshot API does not apply the current screen rotation.
5095 rot = mDisplay.getRotation();
5096 int fw = frame.width();
5097 int fh = frame.height();
5098
5099 // First try reducing to fit in x dimension.
5100 scale = maxWidth/(float)fw;
5101 sw = maxWidth;
5102 sh = (int)(fh*scale);
5103 if (sh > maxHeight) {
5104 // y dimension became too long; constrain by that.
5105 scale = maxHeight/(float)fh;
5106 sw = (int)(fw*scale);
5107 sh = maxHeight;
5108 }
5109
5110 // The screen shot will contain the entire screen.
Dianne Hackborn428ecb62011-01-26 14:53:23 -08005111 dw = (int)(dw*scale);
5112 dh = (int)(dh*scale);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005113 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5114 int tmp = dw;
5115 dw = dh;
5116 dh = tmp;
5117 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5118 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005119 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005120 }
5121
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005122 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005123 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5124 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005125 return null;
5126 }
5127
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005128 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5129 Matrix matrix = new Matrix();
5130 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5131 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5132 Canvas canvas = new Canvas(bm);
5133 canvas.drawBitmap(rawss, matrix, null);
5134
5135 rawss.recycle();
5136 return bm;
5137 }
5138
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005139 public void freezeRotation() {
5140 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5141 "setRotation()")) {
5142 throw new SecurityException("Requires SET_ORIENTATION permission");
5143 }
5144
5145 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5146 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5147 }
5148
5149 public void thawRotation() {
5150 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5151 "setRotation()")) {
5152 throw new SecurityException("Requires SET_ORIENTATION permission");
5153 }
5154
5155 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5156 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5157 }
5158
Romain Guy06882f82009-06-10 13:36:04 -07005159 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005160 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005161 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005162 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005163 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005164 }
5165
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005166 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005167 }
Romain Guy06882f82009-06-10 13:36:04 -07005168
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005169 public void setRotationUnchecked(int rotation,
5170 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005171 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005172 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005174 long origId = Binder.clearCallingIdentity();
5175 boolean changed;
5176 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005177 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178 }
Romain Guy06882f82009-06-10 13:36:04 -07005179
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005180 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005181 sendNewConfiguration();
5182 }
Romain Guy06882f82009-06-10 13:36:04 -07005183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 Binder.restoreCallingIdentity(origId);
5185 }
Romain Guy06882f82009-06-10 13:36:04 -07005186
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005187 /**
5188 * Apply a new rotation to the screen, respecting the requests of
5189 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5190 * re-evaluate the desired rotation.
5191 *
5192 * Returns null if the rotation has been changed. In this case YOU
5193 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5194 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005195 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005196 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005197 // Potential rotation during a drag. Don't do the rotation now, but make
5198 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005199 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5200 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5201 mDeferredRotation = rotation;
5202 mDeferredRotationAnimFlags = animFlags;
5203 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005204 return false;
5205 }
5206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005207 boolean changed;
5208 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005209 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5210 rotation = mDeferredRotation;
5211 mRequestedRotation = rotation;
5212 mLastRotationFlags = mDeferredRotationAnimFlags;
5213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005214 rotation = mRequestedRotation;
5215 } else {
5216 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005217 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005218 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005219 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005220 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005221 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005223 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005226 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005227 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005228 "Rotation changed to " + rotation
5229 + " from " + mRotation
5230 + " (forceApp=" + mForcedAppOrientation
5231 + ", req=" + mRequestedRotation + ")");
5232 mRotation = rotation;
5233 mWindowsFreezingScreen = true;
5234 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5235 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5236 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005237 mWaitingForConfig = true;
5238 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005239 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005240 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005241 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005242 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005243 if (CUSTOM_SCREEN_ROTATION) {
5244 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005245 if (!inTransaction) {
5246 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5247 ">>> OPEN TRANSACTION setRotationUnchecked");
5248 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005249 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005250 try {
5251 if (mScreenRotationAnimation != null) {
5252 mScreenRotationAnimation.setRotation(rotation);
5253 }
5254 } finally {
5255 if (!inTransaction) {
5256 Surface.closeTransaction();
5257 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5258 "<<< CLOSE TRANSACTION setRotationUnchecked");
5259 }
5260 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005261 Surface.setOrientation(0, rotation, animFlags);
5262 Surface.unfreezeDisplay(0);
5263 } else {
5264 Surface.setOrientation(0, rotation, animFlags);
5265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 }
5267 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005268 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005269 if (w.mSurface != null) {
5270 w.mOrientationChanging = true;
5271 }
5272 }
5273 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5274 try {
5275 mRotationWatchers.get(i).onRotationChanged(rotation);
5276 } catch (RemoteException e) {
5277 }
5278 }
5279 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005281 return changed;
5282 }
Romain Guy06882f82009-06-10 13:36:04 -07005283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284 public int getRotation() {
5285 return mRotation;
5286 }
5287
5288 public int watchRotation(IRotationWatcher watcher) {
5289 final IBinder watcherBinder = watcher.asBinder();
5290 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5291 public void binderDied() {
5292 synchronized (mWindowMap) {
5293 for (int i=0; i<mRotationWatchers.size(); i++) {
5294 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005295 IRotationWatcher removed = mRotationWatchers.remove(i);
5296 if (removed != null) {
5297 removed.asBinder().unlinkToDeath(this, 0);
5298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005299 i--;
5300 }
5301 }
5302 }
5303 }
5304 };
Romain Guy06882f82009-06-10 13:36:04 -07005305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005306 synchronized (mWindowMap) {
5307 try {
5308 watcher.asBinder().linkToDeath(dr, 0);
5309 mRotationWatchers.add(watcher);
5310 } catch (RemoteException e) {
5311 // Client died, no cleanup needed.
5312 }
Romain Guy06882f82009-06-10 13:36:04 -07005313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005314 return mRotation;
5315 }
5316 }
5317
5318 /**
5319 * Starts the view server on the specified port.
5320 *
5321 * @param port The port to listener to.
5322 *
5323 * @return True if the server was successfully started, false otherwise.
5324 *
5325 * @see com.android.server.ViewServer
5326 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5327 */
5328 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005329 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005330 return false;
5331 }
5332
5333 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5334 return false;
5335 }
5336
5337 if (port < 1024) {
5338 return false;
5339 }
5340
5341 if (mViewServer != null) {
5342 if (!mViewServer.isRunning()) {
5343 try {
5344 return mViewServer.start();
5345 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005346 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 }
5348 }
5349 return false;
5350 }
5351
5352 try {
5353 mViewServer = new ViewServer(this, port);
5354 return mViewServer.start();
5355 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005356 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005357 }
5358 return false;
5359 }
5360
Romain Guy06882f82009-06-10 13:36:04 -07005361 private boolean isSystemSecure() {
5362 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5363 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5364 }
5365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005366 /**
5367 * Stops the view server if it exists.
5368 *
5369 * @return True if the server stopped, false if it wasn't started or
5370 * couldn't be stopped.
5371 *
5372 * @see com.android.server.ViewServer
5373 */
5374 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005375 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005376 return false;
5377 }
5378
5379 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5380 return false;
5381 }
5382
5383 if (mViewServer != null) {
5384 return mViewServer.stop();
5385 }
5386 return false;
5387 }
5388
5389 /**
5390 * Indicates whether the view server is running.
5391 *
5392 * @return True if the server is running, false otherwise.
5393 *
5394 * @see com.android.server.ViewServer
5395 */
5396 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005397 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005398 return false;
5399 }
5400
5401 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5402 return false;
5403 }
5404
5405 return mViewServer != null && mViewServer.isRunning();
5406 }
5407
5408 /**
5409 * Lists all availble windows in the system. The listing is written in the
5410 * specified Socket's output stream with the following syntax:
5411 * windowHashCodeInHexadecimal windowName
5412 * Each line of the ouput represents a different window.
5413 *
5414 * @param client The remote client to send the listing to.
5415 * @return False if an error occured, true otherwise.
5416 */
5417 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005418 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005419 return false;
5420 }
5421
5422 boolean result = true;
5423
Jeff Browne33348b2010-07-15 23:54:05 -07005424 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005425 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005426 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005427 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005428 }
5429
5430 BufferedWriter out = null;
5431
5432 // Any uncaught exception will crash the system process
5433 try {
5434 OutputStream clientStream = client.getOutputStream();
5435 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5436
5437 final int count = windows.length;
5438 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005439 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005440 out.write(Integer.toHexString(System.identityHashCode(w)));
5441 out.write(' ');
5442 out.append(w.mAttrs.getTitle());
5443 out.write('\n');
5444 }
5445
5446 out.write("DONE.\n");
5447 out.flush();
5448 } catch (Exception e) {
5449 result = false;
5450 } finally {
5451 if (out != null) {
5452 try {
5453 out.close();
5454 } catch (IOException e) {
5455 result = false;
5456 }
5457 }
5458 }
5459
5460 return result;
5461 }
5462
5463 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005464 * Returns the focused window in the following format:
5465 * windowHashCodeInHexadecimal windowName
5466 *
5467 * @param client The remote client to send the listing to.
5468 * @return False if an error occurred, true otherwise.
5469 */
5470 boolean viewServerGetFocusedWindow(Socket client) {
5471 if (isSystemSecure()) {
5472 return false;
5473 }
5474
5475 boolean result = true;
5476
5477 WindowState focusedWindow = getFocusedWindow();
5478
5479 BufferedWriter out = null;
5480
5481 // Any uncaught exception will crash the system process
5482 try {
5483 OutputStream clientStream = client.getOutputStream();
5484 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5485
5486 if(focusedWindow != null) {
5487 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5488 out.write(' ');
5489 out.append(focusedWindow.mAttrs.getTitle());
5490 }
5491 out.write('\n');
5492 out.flush();
5493 } catch (Exception e) {
5494 result = false;
5495 } finally {
5496 if (out != null) {
5497 try {
5498 out.close();
5499 } catch (IOException e) {
5500 result = false;
5501 }
5502 }
5503 }
5504
5505 return result;
5506 }
5507
5508 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005509 * Sends a command to a target window. The result of the command, if any, will be
5510 * written in the output stream of the specified socket.
5511 *
5512 * The parameters must follow this syntax:
5513 * windowHashcode extra
5514 *
5515 * Where XX is the length in characeters of the windowTitle.
5516 *
5517 * The first parameter is the target window. The window with the specified hashcode
5518 * will be the target. If no target can be found, nothing happens. The extra parameters
5519 * will be delivered to the target window and as parameters to the command itself.
5520 *
5521 * @param client The remote client to sent the result, if any, to.
5522 * @param command The command to execute.
5523 * @param parameters The command parameters.
5524 *
5525 * @return True if the command was successfully delivered, false otherwise. This does
5526 * not indicate whether the command itself was successful.
5527 */
5528 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005529 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530 return false;
5531 }
5532
5533 boolean success = true;
5534 Parcel data = null;
5535 Parcel reply = null;
5536
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005537 BufferedWriter out = null;
5538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 // Any uncaught exception will crash the system process
5540 try {
5541 // Find the hashcode of the window
5542 int index = parameters.indexOf(' ');
5543 if (index == -1) {
5544 index = parameters.length();
5545 }
5546 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005547 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005548
5549 // Extract the command's parameter after the window description
5550 if (index < parameters.length()) {
5551 parameters = parameters.substring(index + 1);
5552 } else {
5553 parameters = "";
5554 }
5555
5556 final WindowManagerService.WindowState window = findWindow(hashCode);
5557 if (window == null) {
5558 return false;
5559 }
5560
5561 data = Parcel.obtain();
5562 data.writeInterfaceToken("android.view.IWindow");
5563 data.writeString(command);
5564 data.writeString(parameters);
5565 data.writeInt(1);
5566 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5567
5568 reply = Parcel.obtain();
5569
5570 final IBinder binder = window.mClient.asBinder();
5571 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5572 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5573
5574 reply.readException();
5575
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005576 if (!client.isOutputShutdown()) {
5577 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5578 out.write("DONE\n");
5579 out.flush();
5580 }
5581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005582 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005583 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005584 success = false;
5585 } finally {
5586 if (data != null) {
5587 data.recycle();
5588 }
5589 if (reply != null) {
5590 reply.recycle();
5591 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005592 if (out != null) {
5593 try {
5594 out.close();
5595 } catch (IOException e) {
5596
5597 }
5598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005599 }
5600
5601 return success;
5602 }
5603
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005604 public void addWindowChangeListener(WindowChangeListener listener) {
5605 synchronized(mWindowMap) {
5606 mWindowChangeListeners.add(listener);
5607 }
5608 }
5609
5610 public void removeWindowChangeListener(WindowChangeListener listener) {
5611 synchronized(mWindowMap) {
5612 mWindowChangeListeners.remove(listener);
5613 }
5614 }
5615
5616 private void notifyWindowsChanged() {
5617 WindowChangeListener[] windowChangeListeners;
5618 synchronized(mWindowMap) {
5619 if(mWindowChangeListeners.isEmpty()) {
5620 return;
5621 }
5622 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5623 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5624 }
5625 int N = windowChangeListeners.length;
5626 for(int i = 0; i < N; i++) {
5627 windowChangeListeners[i].windowsChanged();
5628 }
5629 }
5630
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005631 private void notifyFocusChanged() {
5632 WindowChangeListener[] windowChangeListeners;
5633 synchronized(mWindowMap) {
5634 if(mWindowChangeListeners.isEmpty()) {
5635 return;
5636 }
5637 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5638 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5639 }
5640 int N = windowChangeListeners.length;
5641 for(int i = 0; i < N; i++) {
5642 windowChangeListeners[i].focusChanged();
5643 }
5644 }
5645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005646 private WindowState findWindow(int hashCode) {
5647 if (hashCode == -1) {
5648 return getFocusedWindow();
5649 }
5650
5651 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005652 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005653 final int count = windows.size();
5654
5655 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005656 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 if (System.identityHashCode(w) == hashCode) {
5658 return w;
5659 }
5660 }
5661 }
5662
5663 return null;
5664 }
5665
5666 /*
5667 * Instruct the Activity Manager to fetch the current configuration and broadcast
5668 * that to config-changed listeners if appropriate.
5669 */
5670 void sendNewConfiguration() {
5671 try {
5672 mActivityManager.updateConfiguration(null);
5673 } catch (RemoteException e) {
5674 }
5675 }
Romain Guy06882f82009-06-10 13:36:04 -07005676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005677 public Configuration computeNewConfiguration() {
5678 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005679 Configuration config = computeNewConfigurationLocked();
5680 if (config == null && mWaitingForConfig) {
5681 // Nothing changed but we are waiting for something... stop that!
5682 mWaitingForConfig = false;
5683 performLayoutAndPlaceSurfacesLocked();
5684 }
5685 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005686 }
5687 }
Romain Guy06882f82009-06-10 13:36:04 -07005688
Dianne Hackbornc485a602009-03-24 22:39:49 -07005689 Configuration computeNewConfigurationLocked() {
5690 Configuration config = new Configuration();
5691 if (!computeNewConfigurationLocked(config)) {
5692 return null;
5693 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005694 return config;
5695 }
Romain Guy06882f82009-06-10 13:36:04 -07005696
Dianne Hackbornc485a602009-03-24 22:39:49 -07005697 boolean computeNewConfigurationLocked(Configuration config) {
5698 if (mDisplay == null) {
5699 return false;
5700 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005701
5702 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005703
5704 // Use the effective "visual" dimensions based on current rotation
5705 final boolean rotated = (mRotation == Surface.ROTATION_90
5706 || mRotation == Surface.ROTATION_270);
5707 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5708 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5709
Dianne Hackbornc485a602009-03-24 22:39:49 -07005710 int orientation = Configuration.ORIENTATION_SQUARE;
5711 if (dw < dh) {
5712 orientation = Configuration.ORIENTATION_PORTRAIT;
5713 } else if (dw > dh) {
5714 orientation = Configuration.ORIENTATION_LANDSCAPE;
5715 }
5716 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005717
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005718 DisplayMetrics dm = new DisplayMetrics();
5719 mDisplay.getMetrics(dm);
5720 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5721
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005722 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005723 // Note we only do this once because at this point we don't
5724 // expect the screen to change in this way at runtime, and want
5725 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005726 int longSize = dw;
5727 int shortSize = dh;
5728 if (longSize < shortSize) {
5729 int tmp = longSize;
5730 longSize = shortSize;
5731 shortSize = tmp;
5732 }
5733 longSize = (int)(longSize/dm.density);
5734 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005735
Dianne Hackborn723738c2009-06-25 19:48:04 -07005736 // These semi-magic numbers define our compatibility modes for
5737 // applications with different screens. Don't change unless you
5738 // make sure to test lots and lots of apps!
5739 if (longSize < 470) {
5740 // This is shorter than an HVGA normal density screen (which
5741 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005742 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5743 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005744 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005745 // What size is this screen screen?
5746 if (longSize >= 800 && shortSize >= 600) {
5747 // SVGA or larger screens at medium density are the point
5748 // at which we consider it to be an extra large screen.
5749 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005750 } else if (longSize >= 530 && shortSize >= 400) {
5751 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005752 // at which we consider it to be a large screen.
5753 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5754 } else {
5755 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005756
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005757 // If this screen is wider than normal HVGA, or taller
5758 // than FWVGA, then for old apps we want to run in size
5759 // compatibility mode.
5760 if (shortSize > 321 || longSize > 570) {
5761 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5762 }
5763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005764
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005765 // Is this a long screen?
5766 if (((longSize*3)/5) >= (shortSize-1)) {
5767 // Anything wider than WVGA (5:3) is considering to be long.
5768 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5769 } else {
5770 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5771 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005772 }
5773 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005774 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005775
Dianne Hackbornc485a602009-03-24 22:39:49 -07005776 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5777 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5778 mPolicy.adjustConfigurationLw(config);
5779 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005780 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005781
5782 // -------------------------------------------------------------
5783 // Drag and drop
5784 // -------------------------------------------------------------
5785
5786 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005787 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005788 if (DEBUG_DRAG) {
5789 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005790 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005791 + " asbinder=" + window.asBinder());
5792 }
5793
5794 final int callerPid = Binder.getCallingPid();
5795 final long origId = Binder.clearCallingIdentity();
5796 IBinder token = null;
5797
5798 try {
5799 synchronized (mWindowMap) {
5800 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005801 if (mDragState == null) {
5802 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5803 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5804 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005805 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005806 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005807 // TODO: preserve flags param in DragState
5808 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005809 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005810 token = mDragState.mToken = new Binder();
5811
5812 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005813 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5814 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005815 mH.sendMessageDelayed(msg, 5000);
5816 } else {
5817 Slog.w(TAG, "Drag already in progress");
5818 }
5819 } catch (Surface.OutOfResourcesException e) {
5820 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5821 if (mDragState != null) {
5822 mDragState.reset();
5823 mDragState = null;
5824 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005825 }
5826 }
5827 } finally {
5828 Binder.restoreCallingIdentity(origId);
5829 }
5830
5831 return token;
5832 }
5833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 // -------------------------------------------------------------
5835 // Input Events and Focus Management
5836 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005837
Jeff Brown349703e2010-06-22 01:27:15 -07005838 InputMonitor mInputMonitor = new InputMonitor();
5839
5840 /* Tracks the progress of input dispatch and ensures that input dispatch state
5841 * is kept in sync with changes in window focus, visibility, registration, and
5842 * other relevant Window Manager state transitions. */
5843 final class InputMonitor {
5844 // Current window with input focus for keys and other non-touch events. May be null.
5845 private WindowState mInputFocus;
5846
5847 // When true, prevents input dispatch from proceeding until set to false again.
5848 private boolean mInputDispatchFrozen;
5849
5850 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5851 private boolean mInputDispatchEnabled = true;
5852
Jeff Brown3a22cd92011-01-21 13:59:04 -08005853 // When true, need to call updateInputWindowsLw().
5854 private boolean mUpdateInputWindowsNeeded = true;
5855
Jeff Brown349703e2010-06-22 01:27:15 -07005856 // Temporary list of windows information to provide to the input dispatcher.
5857 private InputWindowList mTempInputWindows = new InputWindowList();
5858
5859 // Temporary input application object to provide to the input dispatcher.
5860 private InputApplication mTempInputApplication = new InputApplication();
5861
Jeff Brownb09abc12011-01-13 21:08:27 -08005862 // Set to true when the first input device configuration change notification
5863 // is received to indicate that the input devices are ready.
5864 private final Object mInputDevicesReadyMonitor = new Object();
5865 private boolean mInputDevicesReady;
5866
Jeff Brown349703e2010-06-22 01:27:15 -07005867 /* Notifies the window manager about a broken input channel.
5868 *
5869 * Called by the InputManager.
5870 */
Jeff Brown928e0542011-01-10 11:17:36 -08005871 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5872 if (inputWindowHandle == null) {
5873 return;
5874 }
5875
Jeff Brown349703e2010-06-22 01:27:15 -07005876 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005877 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005878 Slog.i(TAG, "WINDOW DIED " + windowState);
5879 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005880 }
5881 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005882
Jeff Brown519e0242010-09-15 15:18:56 -07005883 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005884 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005885 *
5886 * Called by the InputManager.
5887 */
Jeff Brown928e0542011-01-10 11:17:36 -08005888 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5889 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005890 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005891 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005892 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005893 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005894 if (windowState != null) {
5895 Slog.i(TAG, "Input event dispatching timed out sending to "
5896 + windowState.mAttrs.getTitle());
5897 appWindowToken = windowState.mAppToken;
5898 }
Jeff Brown349703e2010-06-22 01:27:15 -07005899 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005900 }
5901
Jeff Brown928e0542011-01-10 11:17:36 -08005902 if (appWindowToken == null && inputApplicationHandle != null) {
5903 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005904 Slog.i(TAG, "Input event dispatching timed out sending to application "
5905 + appWindowToken.stringName);
5906 }
Jeff Brown349703e2010-06-22 01:27:15 -07005907
Jeff Brown519e0242010-09-15 15:18:56 -07005908 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005909 try {
5910 // Notify the activity manager about the timeout and let it decide whether
5911 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005912 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005913 if (! abort) {
5914 // The activity manager declined to abort dispatching.
5915 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005916 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005917 }
Jeff Brown349703e2010-06-22 01:27:15 -07005918 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005919 }
5920 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005921 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005922 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005923
Chris Tatea32dcf72010-10-14 12:13:50 -07005924 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005925 final InputWindow inputWindow = windowList.add();
5926 inputWindow.inputChannel = mDragState.mServerChannel;
5927 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08005928 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07005929 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5930 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5931 inputWindow.visible = true;
5932 inputWindow.canReceiveKeys = false;
5933 inputWindow.hasFocus = true;
5934 inputWindow.hasWallpaper = false;
5935 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005936 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005937 inputWindow.ownerPid = Process.myPid();
5938 inputWindow.ownerUid = Process.myUid();
5939
5940 // The drag window covers the entire display
5941 inputWindow.frameLeft = 0;
5942 inputWindow.frameTop = 0;
5943 inputWindow.frameRight = mDisplay.getWidth();
5944 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005945
Jeff Brownfbf09772011-01-16 14:06:57 -08005946 // The drag window cannot receive new touches.
5947 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07005948 }
5949
Jeff Brown3a22cd92011-01-21 13:59:04 -08005950 public void setUpdateInputWindowsNeededLw() {
5951 mUpdateInputWindowsNeeded = true;
5952 }
5953
Jeff Brown349703e2010-06-22 01:27:15 -07005954 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08005955 public void updateInputWindowsLw(boolean force) {
5956 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08005957 return;
5958 }
5959 mUpdateInputWindowsNeeded = false;
5960
Jeff Brown349703e2010-06-22 01:27:15 -07005961 // Populate the input window list with information about all of the windows that
5962 // could potentially receive input.
5963 // As an optimization, we could try to prune the list of windows but this turns
5964 // out to be difficult because only the native code knows for sure which window
5965 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005966 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005967
5968 // If there's a drag in flight, provide a pseudowindow to catch drag input
5969 final boolean inDrag = (mDragState != null);
5970 if (inDrag) {
5971 if (DEBUG_DRAG) {
5972 Log.d(TAG, "Inserting drag window");
5973 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005974 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005975 }
5976
Jeff Brown7fbdc842010-06-17 20:52:56 -07005977 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005978 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005979 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005980 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005981 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005982 continue;
5983 }
5984
Jeff Brown349703e2010-06-22 01:27:15 -07005985 final int flags = child.mAttrs.flags;
5986 final int type = child.mAttrs.type;
5987
5988 final boolean hasFocus = (child == mInputFocus);
5989 final boolean isVisible = child.isVisibleLw();
5990 final boolean hasWallpaper = (child == mWallpaperTarget)
5991 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005992
5993 // If there's a drag in progress and 'child' is a potential drop target,
5994 // make sure it's been told about the drag
5995 if (inDrag && isVisible) {
5996 mDragState.sendDragStartedIfNeededLw(child);
5997 }
5998
Jeff Brown349703e2010-06-22 01:27:15 -07005999 // Add a window to our list of input windows.
6000 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08006001 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006002 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07006003 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07006004 inputWindow.layoutParamsFlags = flags;
6005 inputWindow.layoutParamsType = type;
6006 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
6007 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07006008 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07006009 inputWindow.hasFocus = hasFocus;
6010 inputWindow.hasWallpaper = hasWallpaper;
6011 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07006012 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07006013 inputWindow.ownerPid = child.mSession.mPid;
6014 inputWindow.ownerUid = child.mSession.mUid;
6015
6016 final Rect frame = child.mFrame;
6017 inputWindow.frameLeft = frame.left;
6018 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07006019 inputWindow.frameRight = frame.right;
6020 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08006021
6022 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006023 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07006024
Jeff Brown349703e2010-06-22 01:27:15 -07006025 // Send windows to native code.
6026 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006027
Jeff Brown349703e2010-06-22 01:27:15 -07006028 // Clear the list in preparation for the next round.
6029 // Also avoids keeping InputChannel objects referenced unnecessarily.
6030 mTempInputWindows.clear();
6031 }
Jeff Brownb09abc12011-01-13 21:08:27 -08006032
6033 /* Notifies that the input device configuration has changed. */
6034 public void notifyConfigurationChanged() {
6035 sendNewConfiguration();
6036
6037 synchronized (mInputDevicesReadyMonitor) {
6038 if (!mInputDevicesReady) {
6039 mInputDevicesReady = true;
6040 mInputDevicesReadyMonitor.notifyAll();
6041 }
6042 }
6043 }
6044
6045 /* Waits until the built-in input devices have been configured. */
6046 public boolean waitForInputDevicesReady(long timeoutMillis) {
6047 synchronized (mInputDevicesReadyMonitor) {
6048 if (!mInputDevicesReady) {
6049 try {
6050 mInputDevicesReadyMonitor.wait(timeoutMillis);
6051 } catch (InterruptedException ex) {
6052 }
6053 }
6054 return mInputDevicesReady;
6055 }
6056 }
6057
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006058 /* Notifies that the lid switch changed state. */
6059 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6060 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6061 }
6062
Jeff Brown349703e2010-06-22 01:27:15 -07006063 /* Provides an opportunity for the window manager policy to intercept early key
6064 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006065 public int interceptKeyBeforeQueueing(
6066 KeyEvent event, int policyFlags, boolean isScreenOn) {
6067 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006068 }
6069
6070 /* Provides an opportunity for the window manager policy to process a key before
6071 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006072 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006073 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006074 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006075 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006076 }
6077
Jeff Brown3915bb82010-11-05 15:02:16 -07006078 /* Provides an opportunity for the window manager policy to process a key that
6079 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006080 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006081 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006082 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006083 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006084 }
6085
Jeff Brown349703e2010-06-22 01:27:15 -07006086 /* Called when the current input focus changes.
6087 * Layer assignment is assumed to be complete by the time this is called.
6088 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006089 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006090 if (DEBUG_INPUT) {
6091 Slog.d(TAG, "Input focus has changed to " + newWindow);
6092 }
6093
6094 if (newWindow != mInputFocus) {
6095 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006096 // Displaying a window implicitly causes dispatching to be unpaused.
6097 // This is to protect against bugs if someone pauses dispatching but
6098 // forgets to resume.
6099 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006100 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006101
Jeff Brown349703e2010-06-22 01:27:15 -07006102 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006103 setUpdateInputWindowsNeededLw();
6104
6105 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006106 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006107 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006108 }
6109 }
6110
Jeff Brown349703e2010-06-22 01:27:15 -07006111 public void setFocusedAppLw(AppWindowToken newApp) {
6112 // Focused app has changed.
6113 if (newApp == null) {
6114 mInputManager.setFocusedApplication(null);
6115 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006116 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006117 mTempInputApplication.name = newApp.toString();
6118 mTempInputApplication.dispatchingTimeoutNanos =
6119 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006120
Jeff Brown349703e2010-06-22 01:27:15 -07006121 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006122
6123 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006124 }
6125 }
6126
Jeff Brown349703e2010-06-22 01:27:15 -07006127 public void pauseDispatchingLw(WindowToken window) {
6128 if (! window.paused) {
6129 if (DEBUG_INPUT) {
6130 Slog.v(TAG, "Pausing WindowToken " + window);
6131 }
6132
6133 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006134 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006135 }
6136 }
6137
6138 public void resumeDispatchingLw(WindowToken window) {
6139 if (window.paused) {
6140 if (DEBUG_INPUT) {
6141 Slog.v(TAG, "Resuming WindowToken " + window);
6142 }
6143
6144 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006145 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006146 }
6147 }
6148
6149 public void freezeInputDispatchingLw() {
6150 if (! mInputDispatchFrozen) {
6151 if (DEBUG_INPUT) {
6152 Slog.v(TAG, "Freezing input dispatching");
6153 }
6154
6155 mInputDispatchFrozen = true;
6156 updateInputDispatchModeLw();
6157 }
6158 }
6159
6160 public void thawInputDispatchingLw() {
6161 if (mInputDispatchFrozen) {
6162 if (DEBUG_INPUT) {
6163 Slog.v(TAG, "Thawing input dispatching");
6164 }
6165
6166 mInputDispatchFrozen = false;
6167 updateInputDispatchModeLw();
6168 }
6169 }
6170
6171 public void setEventDispatchingLw(boolean enabled) {
6172 if (mInputDispatchEnabled != enabled) {
6173 if (DEBUG_INPUT) {
6174 Slog.v(TAG, "Setting event dispatching to " + enabled);
6175 }
6176
6177 mInputDispatchEnabled = enabled;
6178 updateInputDispatchModeLw();
6179 }
6180 }
6181
6182 private void updateInputDispatchModeLw() {
6183 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6184 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006185 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 public void pauseKeyDispatching(IBinder _token) {
6188 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6189 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006190 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 }
6192
6193 synchronized (mWindowMap) {
6194 WindowToken token = mTokenMap.get(_token);
6195 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006196 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006197 }
6198 }
6199 }
6200
6201 public void resumeKeyDispatching(IBinder _token) {
6202 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6203 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006204 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006205 }
6206
6207 synchronized (mWindowMap) {
6208 WindowToken token = mTokenMap.get(_token);
6209 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006210 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006211 }
6212 }
6213 }
6214
6215 public void setEventDispatching(boolean enabled) {
6216 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6217 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006218 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006219 }
6220
6221 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006222 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006223 }
6224 }
Romain Guy06882f82009-06-10 13:36:04 -07006225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006226 /**
6227 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006228 * Even when sync is false, this method may block while waiting for current
6229 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006230 *
6231 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006232 * {@link SystemClock#uptimeMillis()} as the timebase.)
6233 * @param sync If true, wait for the event to be completed before returning to the caller.
6234 * @return Returns true if event was dispatched, false if it was dropped for any reason
6235 */
6236 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6237 long downTime = ev.getDownTime();
6238 long eventTime = ev.getEventTime();
6239
6240 int action = ev.getAction();
6241 int code = ev.getKeyCode();
6242 int repeatCount = ev.getRepeatCount();
6243 int metaState = ev.getMetaState();
6244 int deviceId = ev.getDeviceId();
6245 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006246 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006247 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006248
6249 if (source == InputDevice.SOURCE_UNKNOWN) {
6250 source = InputDevice.SOURCE_KEYBOARD;
6251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006252
6253 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6254 if (downTime == 0) downTime = eventTime;
6255
6256 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006257 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006259 final int pid = Binder.getCallingPid();
6260 final int uid = Binder.getCallingUid();
6261 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006262
Jeff Brownbbda99d2010-07-28 15:48:59 -07006263 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6264 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6265 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6266 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006267
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006268 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006269 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006270 }
6271
6272 /**
6273 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006274 * Even when sync is false, this method may block while waiting for current
6275 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006276 *
6277 * @param ev A motion event describing the pointer (touch) action. (As noted in
6278 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006279 * {@link SystemClock#uptimeMillis()} as the timebase.)
6280 * @param sync If true, wait for the event to be completed before returning to the caller.
6281 * @return Returns true if event was dispatched, false if it was dropped for any reason
6282 */
6283 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006284 final int pid = Binder.getCallingPid();
6285 final int uid = Binder.getCallingUid();
6286 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006287
Jeff Brownc5ed5912010-07-14 18:48:53 -07006288 MotionEvent newEvent = MotionEvent.obtain(ev);
6289 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6290 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6291 }
6292
Jeff Brownbbda99d2010-07-28 15:48:59 -07006293 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6294 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6295 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6296 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006297
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006298 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006299 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006300 }
Romain Guy06882f82009-06-10 13:36:04 -07006301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006302 /**
6303 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006304 * Even when sync is false, this method may block while waiting for current
6305 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006306 *
6307 * @param ev A motion event describing the trackball action. (As noted in
6308 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006309 * {@link SystemClock#uptimeMillis()} as the timebase.)
6310 * @param sync If true, wait for the event to be completed before returning to the caller.
6311 * @return Returns true if event was dispatched, false if it was dropped for any reason
6312 */
6313 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006314 final int pid = Binder.getCallingPid();
6315 final int uid = Binder.getCallingUid();
6316 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006317
Jeff Brownc5ed5912010-07-14 18:48:53 -07006318 MotionEvent newEvent = MotionEvent.obtain(ev);
6319 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6320 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6321 }
6322
Jeff Brownbbda99d2010-07-28 15:48:59 -07006323 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6324 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6325 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6326 INJECTION_TIMEOUT_MILLIS);
6327
6328 Binder.restoreCallingIdentity(ident);
6329 return reportInjectionResult(result);
6330 }
6331
6332 /**
6333 * Inject an input event into the UI without waiting for dispatch to commence.
6334 * This variant is useful for fire-and-forget input event injection. It does not
6335 * block any longer than it takes to enqueue the input event.
6336 *
6337 * @param ev An input event. (Be sure to set the input source correctly.)
6338 * @return Returns true if event was dispatched, false if it was dropped for any reason
6339 */
6340 public boolean injectInputEventNoWait(InputEvent ev) {
6341 final int pid = Binder.getCallingPid();
6342 final int uid = Binder.getCallingUid();
6343 final long ident = Binder.clearCallingIdentity();
6344
6345 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6346 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6347 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006348
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006349 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006350 return reportInjectionResult(result);
6351 }
6352
6353 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006354 switch (result) {
6355 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6356 Slog.w(TAG, "Input event injection permission denied.");
6357 throw new SecurityException(
6358 "Injecting to another application requires INJECT_EVENTS permission");
6359 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006360 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006361 return true;
6362 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6363 Slog.w(TAG, "Input event injection timed out.");
6364 return false;
6365 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6366 default:
6367 Slog.w(TAG, "Input event injection failed.");
6368 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 }
Romain Guy06882f82009-06-10 13:36:04 -07006371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 private WindowState getFocusedWindow() {
6373 synchronized (mWindowMap) {
6374 return getFocusedWindowLocked();
6375 }
6376 }
6377
6378 private WindowState getFocusedWindowLocked() {
6379 return mCurrentFocus;
6380 }
Romain Guy06882f82009-06-10 13:36:04 -07006381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006383 if (!mInputMonitor.waitForInputDevicesReady(
6384 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6385 Slog.w(TAG, "Devices still not ready after waiting "
6386 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6387 + " milliseconds before attempting to detect safe mode.");
6388 }
6389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006390 mSafeMode = mPolicy.detectSafeMode();
6391 return mSafeMode;
6392 }
Romain Guy06882f82009-06-10 13:36:04 -07006393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006395 synchronized(mWindowMap) {
6396 if (mDisplay != null) {
6397 throw new IllegalStateException("Display already initialized");
6398 }
6399 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6400 mDisplay = wm.getDefaultDisplay();
6401 mInitialDisplayWidth = mDisplay.getWidth();
6402 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006403 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6404 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006405 }
6406
6407 try {
6408 mActivityManager.updateConfiguration(null);
6409 } catch (RemoteException e) {
6410 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006411
6412 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006413 }
6414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 // -------------------------------------------------------------
6416 // Client Session State
6417 // -------------------------------------------------------------
6418
6419 private final class Session extends IWindowSession.Stub
6420 implements IBinder.DeathRecipient {
6421 final IInputMethodClient mClient;
6422 final IInputContext mInputContext;
6423 final int mUid;
6424 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006425 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 SurfaceSession mSurfaceSession;
6427 int mNumWindow = 0;
6428 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006430 public Session(IInputMethodClient client, IInputContext inputContext) {
6431 mClient = client;
6432 mInputContext = inputContext;
6433 mUid = Binder.getCallingUid();
6434 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006435 StringBuilder sb = new StringBuilder();
6436 sb.append("Session{");
6437 sb.append(Integer.toHexString(System.identityHashCode(this)));
6438 sb.append(" uid ");
6439 sb.append(mUid);
6440 sb.append("}");
6441 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 synchronized (mWindowMap) {
6444 if (mInputMethodManager == null && mHaveInputMethods) {
6445 IBinder b = ServiceManager.getService(
6446 Context.INPUT_METHOD_SERVICE);
6447 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6448 }
6449 }
6450 long ident = Binder.clearCallingIdentity();
6451 try {
6452 // Note: it is safe to call in to the input method manager
6453 // here because we are not holding our lock.
6454 if (mInputMethodManager != null) {
6455 mInputMethodManager.addClient(client, inputContext,
6456 mUid, mPid);
6457 } else {
6458 client.setUsingInputMethod(false);
6459 }
6460 client.asBinder().linkToDeath(this, 0);
6461 } catch (RemoteException e) {
6462 // The caller has died, so we can just forget about this.
6463 try {
6464 if (mInputMethodManager != null) {
6465 mInputMethodManager.removeClient(client);
6466 }
6467 } catch (RemoteException ee) {
6468 }
6469 } finally {
6470 Binder.restoreCallingIdentity(ident);
6471 }
6472 }
Romain Guy06882f82009-06-10 13:36:04 -07006473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 @Override
6475 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6476 throws RemoteException {
6477 try {
6478 return super.onTransact(code, data, reply, flags);
6479 } catch (RuntimeException e) {
6480 // Log all 'real' exceptions thrown to the caller
6481 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006482 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 }
6484 throw e;
6485 }
6486 }
6487
6488 public void binderDied() {
6489 // Note: it is safe to call in to the input method manager
6490 // here because we are not holding our lock.
6491 try {
6492 if (mInputMethodManager != null) {
6493 mInputMethodManager.removeClient(mClient);
6494 }
6495 } catch (RemoteException e) {
6496 }
6497 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006498 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 mClientDead = true;
6500 killSessionLocked();
6501 }
6502 }
6503
6504 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006505 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6506 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6507 outInputChannel);
6508 }
6509
6510 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006512 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 }
Romain Guy06882f82009-06-10 13:36:04 -07006514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 public void remove(IWindow window) {
6516 removeWindow(this, window);
6517 }
Romain Guy06882f82009-06-10 13:36:04 -07006518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6520 int requestedWidth, int requestedHeight, int viewFlags,
6521 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006522 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006523 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6524 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006526 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006527 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6528 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006529 }
Romain Guy06882f82009-06-10 13:36:04 -07006530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 public void setTransparentRegion(IWindow window, Region region) {
6532 setTransparentRegionWindow(this, window, region);
6533 }
Romain Guy06882f82009-06-10 13:36:04 -07006534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006535 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006536 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006537 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006538 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006539 }
Romain Guy06882f82009-06-10 13:36:04 -07006540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006541 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6542 getWindowDisplayFrame(this, window, outDisplayFrame);
6543 }
Romain Guy06882f82009-06-10 13:36:04 -07006544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006545 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006546 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006547 TAG, "IWindow finishDrawing called for " + window);
6548 finishDrawingWindow(this, window);
6549 }
6550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 public void setInTouchMode(boolean mode) {
6552 synchronized(mWindowMap) {
6553 mInTouchMode = mode;
6554 }
6555 }
6556
6557 public boolean getInTouchMode() {
6558 synchronized(mWindowMap) {
6559 return mInTouchMode;
6560 }
6561 }
6562
6563 public boolean performHapticFeedback(IWindow window, int effectId,
6564 boolean always) {
6565 synchronized(mWindowMap) {
6566 long ident = Binder.clearCallingIdentity();
6567 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006568 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006569 windowForClientLocked(this, window, true),
6570 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 } finally {
6572 Binder.restoreCallingIdentity(ident);
6573 }
6574 }
6575 }
Romain Guy06882f82009-06-10 13:36:04 -07006576
Christopher Tatea53146c2010-09-07 11:57:52 -07006577 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006578 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006579 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006580 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006581 width, height, outSurface);
6582 }
6583
6584 public boolean performDrag(IWindow window, IBinder dragToken,
6585 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6586 ClipData data) {
6587 if (DEBUG_DRAG) {
6588 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6589 }
6590
6591 synchronized (mWindowMap) {
6592 if (mDragState == null) {
6593 Slog.w(TAG, "No drag prepared");
6594 throw new IllegalStateException("performDrag() without prepareDrag()");
6595 }
6596
6597 if (dragToken != mDragState.mToken) {
6598 Slog.w(TAG, "Performing mismatched drag");
6599 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6600 }
6601
6602 WindowState callingWin = windowForClientLocked(null, window, false);
6603 if (callingWin == null) {
6604 Slog.w(TAG, "Bad requesting window " + window);
6605 return false; // !!! TODO: throw here?
6606 }
6607
6608 // !!! TODO: if input is not still focused on the initiating window, fail
6609 // the drag initiation (e.g. an alarm window popped up just as the application
6610 // called performDrag()
6611
6612 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6613
Christopher Tate2c095f32010-10-04 14:13:40 -07006614 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6615 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006616
Chris Tateb478f462010-10-15 16:02:26 -07006617 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6618 // the actual drag event dispatch stuff in the dragstate
6619
Christopher Tatea53146c2010-09-07 11:57:52 -07006620 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006621 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006622 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6623 mDragState.mServerChannel)) {
6624 Slog.e(TAG, "Unable to transfer touch focus");
6625 mDragState.unregister();
6626 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006627 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006628 return false;
6629 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006630
6631 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006632 mDragState.mCurrentX = touchX;
6633 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006634 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006635
6636 // remember the thumb offsets for later
6637 mDragState.mThumbOffsetX = thumbCenterX;
6638 mDragState.mThumbOffsetY = thumbCenterY;
6639
6640 // Make the surface visible at the proper location
6641 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006642 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006643 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006644 try {
6645 surface.setPosition((int)(touchX - thumbCenterX),
6646 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006647 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006648 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006649 surface.show();
6650 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006651 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006652 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006653 }
6654 }
6655
6656 return true; // success!
6657 }
6658
Chris Tated4533f142010-10-19 15:15:08 -07006659 public void reportDropResult(IWindow window, boolean consumed) {
6660 IBinder token = window.asBinder();
6661 if (DEBUG_DRAG) {
6662 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6663 }
6664
6665 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006666 long ident = Binder.clearCallingIdentity();
6667 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006668 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006669 Slog.w(TAG, "Invalid drop-result claim by " + window);
6670 throw new IllegalStateException("reportDropResult() by non-recipient");
6671 }
6672
6673 // The right window has responded, even if it's no longer around,
6674 // so be sure to halt the timeout even if the later WindowState
6675 // lookup fails.
6676 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6677 WindowState callingWin = windowForClientLocked(null, window, false);
6678 if (callingWin == null) {
6679 Slog.w(TAG, "Bad result-reporting window " + window);
6680 return; // !!! TODO: throw here?
6681 }
6682
6683 mDragState.mDragResult = consumed;
6684 mDragState.endDragLw();
6685 } finally {
6686 Binder.restoreCallingIdentity(ident);
Chris Tated4533f142010-10-19 15:15:08 -07006687 }
Chris Tated4533f142010-10-19 15:15:08 -07006688 }
6689 }
6690
Christopher Tatea53146c2010-09-07 11:57:52 -07006691 public void dragRecipientEntered(IWindow window) {
6692 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006693 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006694 }
6695 }
6696
6697 public void dragRecipientExited(IWindow window) {
6698 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006699 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006700 }
6701 }
6702
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006703 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006704 synchronized(mWindowMap) {
6705 long ident = Binder.clearCallingIdentity();
6706 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006707 setWindowWallpaperPositionLocked(
6708 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006709 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006710 } finally {
6711 Binder.restoreCallingIdentity(ident);
6712 }
6713 }
6714 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006715
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006716 public void wallpaperOffsetsComplete(IBinder window) {
6717 WindowManagerService.this.wallpaperOffsetsComplete(window);
6718 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006719
Dianne Hackborn75804932009-10-20 20:15:20 -07006720 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6721 int z, Bundle extras, boolean sync) {
6722 synchronized(mWindowMap) {
6723 long ident = Binder.clearCallingIdentity();
6724 try {
6725 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006726 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006727 action, x, y, z, extras, sync);
6728 } finally {
6729 Binder.restoreCallingIdentity(ident);
6730 }
6731 }
6732 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006733
Dianne Hackborn75804932009-10-20 20:15:20 -07006734 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6735 WindowManagerService.this.wallpaperCommandComplete(window, result);
6736 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 void windowAddedLocked() {
6739 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006740 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006741 TAG, "First window added to " + this + ", creating SurfaceSession");
6742 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006743 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006744 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 mSessions.add(this);
6746 }
6747 mNumWindow++;
6748 }
6749
6750 void windowRemovedLocked() {
6751 mNumWindow--;
6752 killSessionLocked();
6753 }
Romain Guy06882f82009-06-10 13:36:04 -07006754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 void killSessionLocked() {
6756 if (mNumWindow <= 0 && mClientDead) {
6757 mSessions.remove(this);
6758 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006759 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 TAG, "Last window removed from " + this
6761 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006762 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006763 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764 try {
6765 mSurfaceSession.kill();
6766 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006767 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006768 + mSurfaceSession + " in session " + this
6769 + ": " + e.toString());
6770 }
6771 mSurfaceSession = null;
6772 }
6773 }
6774 }
Romain Guy06882f82009-06-10 13:36:04 -07006775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006777 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6778 pw.print(" mClientDead="); pw.print(mClientDead);
6779 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 }
6781
6782 @Override
6783 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006784 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006785 }
6786 }
6787
6788 // -------------------------------------------------------------
6789 // Client Window State
6790 // -------------------------------------------------------------
6791
6792 private final class WindowState implements WindowManagerPolicy.WindowState {
6793 final Session mSession;
6794 final IWindow mClient;
6795 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006796 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 AppWindowToken mAppToken;
6798 AppWindowToken mTargetAppToken;
6799 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6800 final DeathRecipient mDeathRecipient;
6801 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006802 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 final int mBaseLayer;
6804 final int mSubLayer;
6805 final boolean mLayoutAttached;
6806 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006807 final boolean mIsWallpaper;
6808 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006809 int mViewVisibility;
6810 boolean mPolicyVisibility = true;
6811 boolean mPolicyVisibilityAfterAnim = true;
6812 boolean mAppFreezing;
6813 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006814 boolean mReportDestroySurface;
6815 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006816 boolean mAttachedHidden; // is our parent window hidden?
6817 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006818 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006819 int mRequestedWidth;
6820 int mRequestedHeight;
6821 int mLastRequestedWidth;
6822 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006823 int mLayer;
6824 int mAnimLayer;
6825 int mLastLayer;
6826 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006827 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006828 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006829
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006830 int mLayoutSeq = -1;
6831
6832 Configuration mConfiguration = null;
6833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 // Actual frame shown on-screen (may be modified by animation)
6835 final Rect mShownFrame = new Rect();
6836 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006839 * Set when we have changed the size of the surface, to know that
6840 * we must tell them application to resize (and thus redraw itself).
6841 */
6842 boolean mSurfaceResized;
6843
6844 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845 * Insets that determine the actually visible area
6846 */
6847 final Rect mVisibleInsets = new Rect();
6848 final Rect mLastVisibleInsets = new Rect();
6849 boolean mVisibleInsetsChanged;
6850
6851 /**
6852 * Insets that are covered by system windows
6853 */
6854 final Rect mContentInsets = new Rect();
6855 final Rect mLastContentInsets = new Rect();
6856 boolean mContentInsetsChanged;
6857
6858 /**
6859 * Set to true if we are waiting for this window to receive its
6860 * given internal insets before laying out other windows based on it.
6861 */
6862 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 /**
6865 * These are the content insets that were given during layout for
6866 * this window, to be applied to windows behind it.
6867 */
6868 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006870 /**
6871 * These are the visible insets that were given during layout for
6872 * this window, to be applied to windows behind it.
6873 */
6874 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006876 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006877 * This is the given touchable area relative to the window frame, or null if none.
6878 */
6879 final Region mGivenTouchableRegion = new Region();
6880
6881 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006882 * Flag indicating whether the touchable region should be adjusted by
6883 * the visible insets; if false the area outside the visible insets is
6884 * NOT touchable, so we must use those to adjust the frame during hit
6885 * tests.
6886 */
6887 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006890 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6892 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6893 float mHScale=1, mVScale=1;
6894 float mLastHScale=1, mLastVScale=1;
6895 final Matrix mTmpMatrix = new Matrix();
6896
6897 // "Real" frame that the application sees.
6898 final Rect mFrame = new Rect();
6899 final Rect mLastFrame = new Rect();
6900
6901 final Rect mContainingFrame = new Rect();
6902 final Rect mDisplayFrame = new Rect();
6903 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006904 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 final Rect mVisibleFrame = new Rect();
6906
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006907 boolean mContentChanged;
6908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006909 float mShownAlpha = 1;
6910 float mAlpha = 1;
6911 float mLastAlpha = 1;
6912
6913 // Set to true if, when the window gets displayed, it should perform
6914 // an enter animation.
6915 boolean mEnterAnimationPending;
6916
6917 // Currently running animation.
6918 boolean mAnimating;
6919 boolean mLocalAnimating;
6920 Animation mAnimation;
6921 boolean mAnimationIsEntrance;
6922 boolean mHasTransformation;
6923 boolean mHasLocalTransformation;
6924 final Transformation mTransformation = new Transformation();
6925
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006926 // If a window showing a wallpaper: the requested offset for the
6927 // wallpaper; if a wallpaper window: the currently applied offset.
6928 float mWallpaperX = -1;
6929 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006930
6931 // If a window showing a wallpaper: what fraction of the offset
6932 // range corresponds to a full virtual screen.
6933 float mWallpaperXStep = -1;
6934 float mWallpaperYStep = -1;
6935
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006936 // Wallpaper windows: pixels offset based on above variables.
6937 int mXOffset;
6938 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006940 // This is set after IWindowSession.relayout() has been called at
6941 // least once for the window. It allows us to detect the situation
6942 // where we don't yet have a surface, but should have one soon, so
6943 // we can give the window focus before waiting for the relayout.
6944 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 // This is set after the Surface has been created but before the
6947 // window has been drawn. During this time the surface is hidden.
6948 boolean mDrawPending;
6949
6950 // This is set after the window has finished drawing for the first
6951 // time but before its surface is shown. The surface will be
6952 // displayed when the next layout is run.
6953 boolean mCommitDrawPending;
6954
6955 // This is set during the time after the window's drawing has been
6956 // committed, and before its surface is actually shown. It is used
6957 // to delay showing the surface until all windows in a token are ready
6958 // to be shown.
6959 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006961 // Set when the window has been shown in the screen the first time.
6962 boolean mHasDrawn;
6963
6964 // Currently running an exit animation?
6965 boolean mExiting;
6966
6967 // Currently on the mDestroySurface list?
6968 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006970 // Completely remove from window manager after exit animation?
6971 boolean mRemoveOnExit;
6972
6973 // Set when the orientation is changing and this window has not yet
6974 // been updated for the new orientation.
6975 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 // Is this window now (or just being) removed?
6978 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006979
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006980 // Temp for keeping track of windows that have been removed when
6981 // rebuilding window list.
6982 boolean mRebuilding;
6983
Dianne Hackborn16064f92010-03-25 00:47:24 -07006984 // For debugging, this is the last information given to the surface flinger.
6985 boolean mSurfaceShown;
6986 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6987 int mSurfaceLayer;
6988 float mSurfaceAlpha;
6989
Jeff Brown928e0542011-01-10 11:17:36 -08006990 // Input channel and input window handle used by the input dispatcher.
6991 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006992 InputChannel mInputChannel;
6993
Mattias Petersson1622eee2010-12-21 10:15:11 +01006994 // Used to improve performance of toString()
6995 String mStringNameCache;
6996 CharSequence mLastTitle;
6997 boolean mWasPaused;
6998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006999 WindowState(Session s, IWindow c, WindowToken token,
7000 WindowState attachedWindow, WindowManager.LayoutParams a,
7001 int viewVisibility) {
7002 mSession = s;
7003 mClient = c;
7004 mToken = token;
7005 mAttrs.copyFrom(a);
7006 mViewVisibility = viewVisibility;
7007 DeathRecipient deathRecipient = new DeathRecipient();
7008 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007009 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007010 TAG, "Window " + this + " client=" + c.asBinder()
7011 + " token=" + token + " (" + mAttrs.token + ")");
7012 try {
7013 c.asBinder().linkToDeath(deathRecipient, 0);
7014 } catch (RemoteException e) {
7015 mDeathRecipient = null;
7016 mAttachedWindow = null;
7017 mLayoutAttached = false;
7018 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007019 mIsWallpaper = false;
7020 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007021 mBaseLayer = 0;
7022 mSubLayer = 0;
7023 return;
7024 }
7025 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07007026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007027 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
7028 mAttrs.type <= LAST_SUB_WINDOW)) {
7029 // The multiplier here is to reserve space for multiple
7030 // windows in the same type layer.
7031 mBaseLayer = mPolicy.windowTypeToLayerLw(
7032 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
7033 + TYPE_LAYER_OFFSET;
7034 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
7035 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007036 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007037 mAttachedWindow.mChildWindows.add(this);
7038 mLayoutAttached = mAttrs.type !=
7039 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
7040 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
7041 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007042 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7043 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 } else {
7045 // The multiplier here is to reserve space for multiple
7046 // windows in the same type layer.
7047 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7048 * TYPE_LAYER_MULTIPLIER
7049 + TYPE_LAYER_OFFSET;
7050 mSubLayer = 0;
7051 mAttachedWindow = null;
7052 mLayoutAttached = false;
7053 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7054 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007055 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7056 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 }
7058
7059 WindowState appWin = this;
7060 while (appWin.mAttachedWindow != null) {
7061 appWin = mAttachedWindow;
7062 }
7063 WindowToken appToken = appWin.mToken;
7064 while (appToken.appWindowToken == null) {
7065 WindowToken parent = mTokenMap.get(appToken.token);
7066 if (parent == null || appToken == parent) {
7067 break;
7068 }
7069 appToken = parent;
7070 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007071 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 mAppToken = appToken.appWindowToken;
7073
7074 mSurface = null;
7075 mRequestedWidth = 0;
7076 mRequestedHeight = 0;
7077 mLastRequestedWidth = 0;
7078 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007079 mXOffset = 0;
7080 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 mLayer = 0;
7082 mAnimLayer = 0;
7083 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007084 mInputWindowHandle = new InputWindowHandle(
7085 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 }
7087
7088 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007089 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 TAG, "Attaching " + this + " token=" + mToken
7091 + ", list=" + mToken.windows);
7092 mSession.windowAddedLocked();
7093 }
7094
7095 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7096 mHaveFrame = true;
7097
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007098 final Rect container = mContainingFrame;
7099 container.set(pf);
7100
7101 final Rect display = mDisplayFrame;
7102 display.set(df);
7103
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007104 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007105 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007106 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7107 display.intersect(mCompatibleScreenFrame);
7108 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007109 }
7110
7111 final int pw = container.right - container.left;
7112 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007113
7114 int w,h;
7115 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7116 w = mAttrs.width < 0 ? pw : mAttrs.width;
7117 h = mAttrs.height< 0 ? ph : mAttrs.height;
7118 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007119 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7120 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 }
Romain Guy06882f82009-06-10 13:36:04 -07007122
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007123 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007124 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7125 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007126 mParentFrame.set(pf);
7127 mContentChanged = true;
7128 }
7129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 final Rect content = mContentFrame;
7131 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007133 final Rect visible = mVisibleFrame;
7134 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007137 final int fw = frame.width();
7138 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007140 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7141 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7142
7143 Gravity.apply(mAttrs.gravity, w, h, container,
7144 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7145 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7146
7147 //System.out.println("Out: " + mFrame);
7148
7149 // Now make sure the window fits in the overall display.
7150 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 // Make sure the content and visible frames are inside of the
7153 // final window frame.
7154 if (content.left < frame.left) content.left = frame.left;
7155 if (content.top < frame.top) content.top = frame.top;
7156 if (content.right > frame.right) content.right = frame.right;
7157 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7158 if (visible.left < frame.left) visible.left = frame.left;
7159 if (visible.top < frame.top) visible.top = frame.top;
7160 if (visible.right > frame.right) visible.right = frame.right;
7161 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007163 final Rect contentInsets = mContentInsets;
7164 contentInsets.left = content.left-frame.left;
7165 contentInsets.top = content.top-frame.top;
7166 contentInsets.right = frame.right-content.right;
7167 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007169 final Rect visibleInsets = mVisibleInsets;
7170 visibleInsets.left = visible.left-frame.left;
7171 visibleInsets.top = visible.top-frame.top;
7172 visibleInsets.right = frame.right-visible.right;
7173 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007174
Dianne Hackborn284ac932009-08-28 10:34:25 -07007175 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7176 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007177 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007178 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007180 if (localLOGV) {
7181 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7182 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007183 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007184 + mRequestedWidth + ", mRequestedheight="
7185 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7186 + "): frame=" + mFrame.toShortString()
7187 + " ci=" + contentInsets.toShortString()
7188 + " vi=" + visibleInsets.toShortString());
7189 //}
7190 }
7191 }
Romain Guy06882f82009-06-10 13:36:04 -07007192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007193 public Rect getFrameLw() {
7194 return mFrame;
7195 }
7196
7197 public Rect getShownFrameLw() {
7198 return mShownFrame;
7199 }
7200
7201 public Rect getDisplayFrameLw() {
7202 return mDisplayFrame;
7203 }
7204
7205 public Rect getContentFrameLw() {
7206 return mContentFrame;
7207 }
7208
7209 public Rect getVisibleFrameLw() {
7210 return mVisibleFrame;
7211 }
7212
7213 public boolean getGivenInsetsPendingLw() {
7214 return mGivenInsetsPending;
7215 }
7216
7217 public Rect getGivenContentInsetsLw() {
7218 return mGivenContentInsets;
7219 }
Romain Guy06882f82009-06-10 13:36:04 -07007220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007221 public Rect getGivenVisibleInsetsLw() {
7222 return mGivenVisibleInsets;
7223 }
Romain Guy06882f82009-06-10 13:36:04 -07007224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007225 public WindowManager.LayoutParams getAttrs() {
7226 return mAttrs;
7227 }
7228
7229 public int getSurfaceLayer() {
7230 return mLayer;
7231 }
Romain Guy06882f82009-06-10 13:36:04 -07007232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007233 public IApplicationToken getAppToken() {
7234 return mAppToken != null ? mAppToken.appToken : null;
7235 }
Jeff Brown349703e2010-06-22 01:27:15 -07007236
7237 public long getInputDispatchingTimeoutNanos() {
7238 return mAppToken != null
7239 ? mAppToken.inputDispatchingTimeoutNanos
7240 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007242
7243 public boolean hasAppShownWindows() {
7244 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7245 }
7246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007247 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007248 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007249 TAG, "Setting animation in " + this + ": " + anim);
7250 mAnimating = false;
7251 mLocalAnimating = false;
7252 mAnimation = anim;
7253 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7254 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7255 }
7256
7257 public void clearAnimation() {
7258 if (mAnimation != null) {
7259 mAnimating = true;
7260 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007261 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007262 mAnimation = null;
7263 }
7264 }
Romain Guy06882f82009-06-10 13:36:04 -07007265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266 Surface createSurfaceLocked() {
7267 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007268 mReportDestroySurface = false;
7269 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007270 mDrawPending = true;
7271 mCommitDrawPending = false;
7272 mReadyToShow = false;
7273 if (mAppToken != null) {
7274 mAppToken.allDrawn = false;
7275 }
7276
7277 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278
7279 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7280 flags |= Surface.SECURE;
7281 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007282 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 TAG, "Creating surface in session "
7284 + mSession.mSurfaceSession + " window " + this
7285 + " w=" + mFrame.width()
7286 + " h=" + mFrame.height() + " format="
7287 + mAttrs.format + " flags=" + flags);
7288
7289 int w = mFrame.width();
7290 int h = mFrame.height();
7291 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7292 // for a scaled surface, we always want the requested
7293 // size.
7294 w = mRequestedWidth;
7295 h = mRequestedHeight;
7296 }
7297
Romain Guy9825ec62009-10-01 00:58:09 -07007298 // Something is wrong and SurfaceFlinger will not like this,
7299 // try to revert to sane values
7300 if (w <= 0) w = 1;
7301 if (h <= 0) h = 1;
7302
Dianne Hackborn16064f92010-03-25 00:47:24 -07007303 mSurfaceShown = false;
7304 mSurfaceLayer = 0;
7305 mSurfaceAlpha = 1;
7306 mSurfaceX = 0;
7307 mSurfaceY = 0;
7308 mSurfaceW = w;
7309 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007311 final boolean isHwAccelerated = (mAttrs.flags &
7312 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7313 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7314 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7315 flags |= Surface.OPAQUE;
7316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007318 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007319 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007320 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007321 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007322 + mSurface + " IN SESSION "
7323 + mSession.mSurfaceSession
7324 + ": pid=" + mSession.mPid + " format="
7325 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007326 + Integer.toHexString(flags)
7327 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007328 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007329 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 reclaimSomeSurfaceMemoryLocked(this, "create");
7331 return null;
7332 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007333 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 return null;
7335 }
Romain Guy06882f82009-06-10 13:36:04 -07007336
Joe Onorato8a9b2202010-02-26 18:56:32 -08007337 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 TAG, "Got surface: " + mSurface
7339 + ", set left=" + mFrame.left + " top=" + mFrame.top
7340 + ", animLayer=" + mAnimLayer);
7341 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007342 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7343 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007344 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7345 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007346 }
7347 Surface.openTransaction();
7348 try {
7349 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007350 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007351 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007352 mSurface.setPosition(mSurfaceX, mSurfaceY);
7353 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007355 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007356 mSurface.hide();
7357 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007358 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 mSurface.setFlags(Surface.SURFACE_DITHER,
7360 Surface.SURFACE_DITHER);
7361 }
7362 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007363 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007364 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7365 }
7366 mLastHidden = true;
7367 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007369 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007370 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007371 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 TAG, "Created surface " + this);
7373 }
7374 return mSurface;
7375 }
Romain Guy06882f82009-06-10 13:36:04 -07007376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007377 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 if (mAppToken != null && this == mAppToken.startingWindow) {
7379 mAppToken.startingDisplayed = false;
7380 }
Romain Guy06882f82009-06-10 13:36:04 -07007381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007383 mDrawPending = false;
7384 mCommitDrawPending = false;
7385 mReadyToShow = false;
7386
7387 int i = mChildWindows.size();
7388 while (i > 0) {
7389 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007390 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007391 c.mAttachedHidden = true;
7392 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007393
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007394 if (mReportDestroySurface) {
7395 mReportDestroySurface = false;
7396 mSurfacePendingDestroy = true;
7397 try {
7398 mClient.dispatchGetNewSurface();
7399 // We'll really destroy on the next time around.
7400 return;
7401 } catch (RemoteException e) {
7402 }
7403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007406 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007407 RuntimeException e = null;
7408 if (!HIDE_STACK_CRAWLS) {
7409 e = new RuntimeException();
7410 e.fillInStackTrace();
7411 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007412 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007413 + mSurface + ", session " + mSession, e);
7414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007416 RuntimeException e = null;
7417 if (!HIDE_STACK_CRAWLS) {
7418 e = new RuntimeException();
7419 e.fillInStackTrace();
7420 }
7421 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007423 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007424 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007425 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 + " surface " + mSurface + " session " + mSession
7427 + ": " + e.toString());
7428 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007429
Dianne Hackborn16064f92010-03-25 00:47:24 -07007430 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 }
7433 }
7434
7435 boolean finishDrawingLocked() {
7436 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007437 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 TAG, "finishDrawingLocked: " + mSurface);
7439 mCommitDrawPending = true;
7440 mDrawPending = false;
7441 return true;
7442 }
7443 return false;
7444 }
7445
7446 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007447 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007448 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007450 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 }
7452 mCommitDrawPending = false;
7453 mReadyToShow = true;
7454 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7455 final AppWindowToken atoken = mAppToken;
7456 if (atoken == null || atoken.allDrawn || starting) {
7457 performShowLocked();
7458 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007459 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 }
7461
7462 // This must be called while inside a transaction.
7463 boolean performShowLocked() {
7464 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007465 RuntimeException e = null;
7466 if (!HIDE_STACK_CRAWLS) {
7467 e = new RuntimeException();
7468 e.fillInStackTrace();
7469 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007470 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007471 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7472 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7473 }
7474 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007475 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7476 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007477 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 + " during animation: policyVis=" + mPolicyVisibility
7479 + " attHidden=" + mAttachedHidden
7480 + " tok.hiddenRequested="
7481 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007482 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007483 + (mAppToken != null ? mAppToken.hidden : false)
7484 + " animating=" + mAnimating
7485 + " tok animating="
7486 + (mAppToken != null ? mAppToken.animating : false));
7487 if (!showSurfaceRobustlyLocked(this)) {
7488 return false;
7489 }
7490 mLastAlpha = -1;
7491 mHasDrawn = true;
7492 mLastHidden = false;
7493 mReadyToShow = false;
7494 enableScreenIfNeededLocked();
7495
7496 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 int i = mChildWindows.size();
7499 while (i > 0) {
7500 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007501 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007502 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007504 if (c.mSurface != null) {
7505 c.performShowLocked();
7506 // It hadn't been shown, which means layout not
7507 // performed on it, so now we want to make sure to
7508 // do a layout. If called from within the transaction
7509 // loop, this will cause it to restart with a new
7510 // layout.
7511 mLayoutNeeded = true;
7512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 }
7514 }
Romain Guy06882f82009-06-10 13:36:04 -07007515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 if (mAttrs.type != TYPE_APPLICATION_STARTING
7517 && mAppToken != null) {
7518 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007519
Dianne Hackborn248b1882009-09-16 16:46:44 -07007520 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007521 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007522 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007524 // If this initial window is animating, stop it -- we
7525 // will do an animation to reveal it from behind the
7526 // starting window, so there is no need for it to also
7527 // be doing its own stuff.
7528 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007529 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007530 mAnimation = null;
7531 // Make sure we clean up the animation.
7532 mAnimating = true;
7533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007534 mFinishedStarting.add(mAppToken);
7535 mH.sendEmptyMessage(H.FINISHED_STARTING);
7536 }
7537 mAppToken.updateReportedVisibilityLocked();
7538 }
7539 }
7540 return true;
7541 }
Romain Guy06882f82009-06-10 13:36:04 -07007542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007543 // This must be called while inside a transaction. Returns true if
7544 // there is more animation to run.
7545 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007546 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7550 mHasTransformation = true;
7551 mHasLocalTransformation = true;
7552 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007553 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 TAG, "Starting animation in " + this +
7555 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7556 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7557 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7558 mAnimation.setStartTime(currentTime);
7559 mLocalAnimating = true;
7560 mAnimating = true;
7561 }
7562 mTransformation.clear();
7563 final boolean more = mAnimation.getTransformation(
7564 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007565 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007566 TAG, "Stepped animation in " + this +
7567 ": more=" + more + ", xform=" + mTransformation);
7568 if (more) {
7569 // we're not done!
7570 return true;
7571 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007572 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 TAG, "Finished animation in " + this +
7574 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007575
7576 if (mAnimation != null) {
7577 mAnimation.cancel();
7578 mAnimation = null;
7579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 //WindowManagerService.this.dump();
7581 }
7582 mHasLocalTransformation = false;
7583 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007584 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 // When our app token is animating, we kind-of pretend like
7586 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7587 // part of this check means that we will only do this if
7588 // our window is not currently exiting, or it is not
7589 // locally animating itself. The idea being that one that
7590 // is exiting and doing a local animation should be removed
7591 // once that animation is done.
7592 mAnimating = true;
7593 mHasTransformation = true;
7594 mTransformation.clear();
7595 return false;
7596 } else if (mHasTransformation) {
7597 // Little trick to get through the path below to act like
7598 // we have finished an animation.
7599 mAnimating = true;
7600 } else if (isAnimating()) {
7601 mAnimating = true;
7602 }
7603 } else if (mAnimation != null) {
7604 // If the display is frozen, and there is a pending animation,
7605 // clear it and make sure we run the cleanup code.
7606 mAnimating = true;
7607 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007608 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 mAnimation = null;
7610 }
Romain Guy06882f82009-06-10 13:36:04 -07007611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007612 if (!mAnimating && !mLocalAnimating) {
7613 return false;
7614 }
7615
Joe Onorato8a9b2202010-02-26 18:56:32 -08007616 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 TAG, "Animation done in " + this + ": exiting=" + mExiting
7618 + ", reportedVisible="
7619 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 mAnimating = false;
7622 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007623 if (mAnimation != null) {
7624 mAnimation.cancel();
7625 mAnimation = null;
7626 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 mAnimLayer = mLayer;
7628 if (mIsImWindow) {
7629 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007630 } else if (mIsWallpaper) {
7631 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007633 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007634 + " anim layer: " + mAnimLayer);
7635 mHasTransformation = false;
7636 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007637 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7638 if (DEBUG_VISIBILITY) {
7639 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7640 + mPolicyVisibilityAfterAnim);
7641 }
7642 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7643 if (!mPolicyVisibility) {
7644 if (mCurrentFocus == this) {
7645 mFocusMayChange = true;
7646 }
7647 // Window is no longer visible -- make sure if we were waiting
7648 // for it to be displayed before enabling the display, that
7649 // we allow the display to be enabled now.
7650 enableScreenIfNeededLocked();
7651 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007653 mTransformation.clear();
7654 if (mHasDrawn
7655 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7656 && mAppToken != null
7657 && mAppToken.firstWindowDrawn
7658 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007659 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007660 + mToken + ": first real window done animating");
7661 mFinishedStarting.add(mAppToken);
7662 mH.sendEmptyMessage(H.FINISHED_STARTING);
7663 }
Romain Guy06882f82009-06-10 13:36:04 -07007664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 finishExit();
7666
7667 if (mAppToken != null) {
7668 mAppToken.updateReportedVisibilityLocked();
7669 }
7670
7671 return false;
7672 }
7673
7674 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007675 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007676 TAG, "finishExit in " + this
7677 + ": exiting=" + mExiting
7678 + " remove=" + mRemoveOnExit
7679 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007681 final int N = mChildWindows.size();
7682 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007683 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 }
Romain Guy06882f82009-06-10 13:36:04 -07007685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 if (!mExiting) {
7687 return;
7688 }
Romain Guy06882f82009-06-10 13:36:04 -07007689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 if (isWindowAnimating()) {
7691 return;
7692 }
7693
Joe Onorato8a9b2202010-02-26 18:56:32 -08007694 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007695 TAG, "Exit animation finished in " + this
7696 + ": remove=" + mRemoveOnExit);
7697 if (mSurface != null) {
7698 mDestroySurface.add(this);
7699 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007700 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007701 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 try {
7703 mSurface.hide();
7704 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007705 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007706 }
7707 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 }
7709 mExiting = false;
7710 if (mRemoveOnExit) {
7711 mPendingRemove.add(this);
7712 mRemoveOnExit = false;
7713 }
7714 }
Romain Guy06882f82009-06-10 13:36:04 -07007715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007716 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7717 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7718 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7719 if (dtdx < -.000001f || dtdx > .000001f) return false;
7720 if (dsdy < -.000001f || dsdy > .000001f) return false;
7721 return true;
7722 }
Romain Guy06882f82009-06-10 13:36:04 -07007723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 void computeShownFrameLocked() {
7725 final boolean selfTransformation = mHasLocalTransformation;
7726 Transformation attachedTransformation =
7727 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7728 ? mAttachedWindow.mTransformation : null;
7729 Transformation appTransformation =
7730 (mAppToken != null && mAppToken.hasTransformation)
7731 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007732
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007733 // Wallpapers are animated based on the "real" window they
7734 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007735 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007736 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007737 if (mWallpaperTarget.mHasLocalTransformation &&
7738 mWallpaperTarget.mAnimation != null &&
7739 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007740 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007741 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007742 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007743 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007744 }
7745 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007746 mWallpaperTarget.mAppToken.hasTransformation &&
7747 mWallpaperTarget.mAppToken.animation != null &&
7748 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007749 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007750 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007751 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007752 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007753 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007754 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007755
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007756 final boolean screenAnimation = mScreenRotationAnimation != null
7757 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007759 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007760 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007761 final Rect frame = mFrame;
7762 final float tmpFloats[] = mTmpFloats;
7763 final Matrix tmpMatrix = mTmpMatrix;
7764
7765 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007766 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007767 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007768 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007769 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007770 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007771 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007772 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007773 }
7774 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007775 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007777 if (screenAnimation) {
7778 tmpMatrix.postConcat(
7779 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7780 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007781
7782 // "convert" it into SurfaceFlinger's format
7783 // (a 2x2 matrix + an offset)
7784 // Here we must not transform the position of the surface
7785 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007786 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007787
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007788 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007789 tmpMatrix.getValues(tmpFloats);
7790 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007791 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7792 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007793 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007794 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7795 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 int w = frame.width();
7797 int h = frame.height();
7798 mShownFrame.set(x, y, x+w, y+h);
7799
7800 // Now set the alpha... but because our current hardware
7801 // can't do alpha transformation on a non-opaque surface,
7802 // turn it off if we are running an animation that is also
7803 // transforming since it is more important to have that
7804 // animation be smooth.
7805 mShownAlpha = mAlpha;
7806 if (!mLimitedAlphaCompositing
7807 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7808 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7809 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007810 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007811 if (selfTransformation) {
7812 mShownAlpha *= mTransformation.getAlpha();
7813 }
7814 if (attachedTransformation != null) {
7815 mShownAlpha *= attachedTransformation.getAlpha();
7816 }
7817 if (appTransformation != null) {
7818 mShownAlpha *= appTransformation.getAlpha();
7819 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007820 if (screenAnimation) {
7821 mShownAlpha *=
7822 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007824 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007825 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 }
Romain Guy06882f82009-06-10 13:36:04 -07007827
Joe Onorato8a9b2202010-02-26 18:56:32 -08007828 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007829 TAG, "Continuing animation in " + this +
7830 ": " + mShownFrame +
7831 ", alpha=" + mTransformation.getAlpha());
7832 return;
7833 }
Romain Guy06882f82009-06-10 13:36:04 -07007834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007835 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007836 if (mXOffset != 0 || mYOffset != 0) {
7837 mShownFrame.offset(mXOffset, mYOffset);
7838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007839 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007840 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007841 mDsDx = 1;
7842 mDtDx = 0;
7843 mDsDy = 0;
7844 mDtDy = 1;
7845 }
Romain Guy06882f82009-06-10 13:36:04 -07007846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007847 /**
7848 * Is this window visible? It is not visible if there is no
7849 * surface, or we are in the process of running an exit animation
7850 * that will remove the surface, or its app token has been hidden.
7851 */
7852 public boolean isVisibleLw() {
7853 final AppWindowToken atoken = mAppToken;
7854 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7855 && (atoken == null || !atoken.hiddenRequested)
7856 && !mExiting && !mDestroying;
7857 }
7858
7859 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007860 * Like {@link #isVisibleLw}, but also counts a window that is currently
7861 * "hidden" behind the keyguard as visible. This allows us to apply
7862 * things like window flags that impact the keyguard.
7863 * XXX I am starting to think we need to have ANOTHER visibility flag
7864 * for this "hidden behind keyguard" state rather than overloading
7865 * mPolicyVisibility. Ungh.
7866 */
7867 public boolean isVisibleOrBehindKeyguardLw() {
7868 final AppWindowToken atoken = mAppToken;
7869 return mSurface != null && !mAttachedHidden
7870 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007871 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007872 && !mExiting && !mDestroying;
7873 }
7874
7875 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 * Is this window visible, ignoring its app token? It is not visible
7877 * if there is no surface, or we are in the process of running an exit animation
7878 * that will remove the surface.
7879 */
7880 public boolean isWinVisibleLw() {
7881 final AppWindowToken atoken = mAppToken;
7882 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7883 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7884 && !mExiting && !mDestroying;
7885 }
7886
7887 /**
7888 * The same as isVisible(), but follows the current hidden state of
7889 * the associated app token, not the pending requested hidden state.
7890 */
7891 boolean isVisibleNow() {
7892 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007893 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 }
7895
7896 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007897 * Can this window possibly be a drag/drop target? The test here is
7898 * a combination of the above "visible now" with the check that the
7899 * Input Manager uses when discarding windows from input consideration.
7900 */
7901 boolean isPotentialDragTarget() {
7902 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7903 }
7904
7905 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007906 * Same as isVisible(), but we also count it as visible between the
7907 * call to IWindowSession.add() and the first relayout().
7908 */
7909 boolean isVisibleOrAdding() {
7910 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007911 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7913 && mPolicyVisibility && !mAttachedHidden
7914 && (atoken == null || !atoken.hiddenRequested)
7915 && !mExiting && !mDestroying;
7916 }
7917
7918 /**
7919 * Is this window currently on-screen? It is on-screen either if it
7920 * is visible or it is currently running an animation before no longer
7921 * being visible.
7922 */
7923 boolean isOnScreen() {
7924 final AppWindowToken atoken = mAppToken;
7925 if (atoken != null) {
7926 return mSurface != null && mPolicyVisibility && !mDestroying
7927 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007928 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 } else {
7930 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007931 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 }
7933 }
Romain Guy06882f82009-06-10 13:36:04 -07007934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007935 /**
7936 * Like isOnScreen(), but we don't return true if the window is part
7937 * of a transition that has not yet been started.
7938 */
7939 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007940 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007941 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007942 return false;
7943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007944 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007945 final boolean animating = atoken != null
7946 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007947 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007948 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7949 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007950 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 }
7952
7953 /** Is the window or its container currently animating? */
7954 boolean isAnimating() {
7955 final WindowState attached = mAttachedWindow;
7956 final AppWindowToken atoken = mAppToken;
7957 return mAnimation != null
7958 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007959 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007960 (atoken.animation != null
7961 || atoken.inPendingTransaction));
7962 }
7963
7964 /** Is this window currently animating? */
7965 boolean isWindowAnimating() {
7966 return mAnimation != null;
7967 }
7968
7969 /**
7970 * Like isOnScreen, but returns false if the surface hasn't yet
7971 * been drawn.
7972 */
7973 public boolean isDisplayedLw() {
7974 final AppWindowToken atoken = mAppToken;
7975 return mSurface != null && mPolicyVisibility && !mDestroying
7976 && !mDrawPending && !mCommitDrawPending
7977 && ((!mAttachedHidden &&
7978 (atoken == null || !atoken.hiddenRequested))
7979 || mAnimating);
7980 }
7981
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007982 /**
7983 * Returns true if the window has a surface that it has drawn a
7984 * complete UI in to.
7985 */
7986 public boolean isDrawnLw() {
7987 final AppWindowToken atoken = mAppToken;
7988 return mSurface != null && !mDestroying
7989 && !mDrawPending && !mCommitDrawPending;
7990 }
7991
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007992 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007993 * Return true if the window is opaque and fully drawn. This indicates
7994 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007995 */
7996 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007997 return (mAttrs.format == PixelFormat.OPAQUE
7998 || mAttrs.type == TYPE_WALLPAPER)
7999 && mSurface != null && mAnimation == null
8000 && (mAppToken == null || mAppToken.animation == null)
8001 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008002 }
8003
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008004 /**
8005 * Return whether this window is wanting to have a translation
8006 * animation applied to it for an in-progress move. (Only makes
8007 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
8008 */
8009 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008010 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008011 && (mFrame.top != mLastFrame.top
8012 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08008013 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008014 && mPolicy.isScreenOn();
8015 }
8016
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008017 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
8018 return
8019 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008020 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
8021 // only if it's visible
8022 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008023 // and only if the application fills the compatible screen
8024 mFrame.left <= mCompatibleScreenFrame.left &&
8025 mFrame.top <= mCompatibleScreenFrame.top &&
8026 mFrame.right >= mCompatibleScreenFrame.right &&
8027 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07008028 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07008029 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07008030 }
8031
8032 boolean isFullscreen(int screenWidth, int screenHeight) {
8033 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008034 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 }
8036
8037 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07008038 disposeInputChannel();
8039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008040 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008041 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008042 mAttachedWindow.mChildWindows.remove(this);
8043 }
8044 destroySurfaceLocked();
8045 mSession.windowRemovedLocked();
8046 try {
8047 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8048 } catch (RuntimeException e) {
8049 // Ignore if it has already been removed (usually because
8050 // we are doing this as part of processing a death note.)
8051 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008052 }
8053
8054 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008055 if (mInputChannel != null) {
8056 mInputManager.unregisterInputChannel(mInputChannel);
8057
8058 mInputChannel.dispose();
8059 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008061 }
8062
8063 private class DeathRecipient implements IBinder.DeathRecipient {
8064 public void binderDied() {
8065 try {
8066 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008067 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008068 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 if (win != null) {
8070 removeWindowLocked(mSession, win);
8071 }
8072 }
8073 } catch (IllegalArgumentException ex) {
8074 // This will happen if the window has already been
8075 // removed.
8076 }
8077 }
8078 }
8079
8080 /** Returns true if this window desires key events. */
8081 public final boolean canReceiveKeys() {
8082 return isVisibleOrAdding()
8083 && (mViewVisibility == View.VISIBLE)
8084 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8085 }
8086
8087 public boolean hasDrawnLw() {
8088 return mHasDrawn;
8089 }
8090
8091 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008092 return showLw(doAnimation, true);
8093 }
8094
8095 boolean showLw(boolean doAnimation, boolean requestAnim) {
8096 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8097 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008099 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008100 if (doAnimation) {
8101 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8102 + mPolicyVisibility + " mAnimation=" + mAnimation);
8103 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8104 doAnimation = false;
8105 } else if (mPolicyVisibility && mAnimation == null) {
8106 // Check for the case where we are currently visible and
8107 // not animating; we do not want to do animation at such a
8108 // point to become visible when we already are.
8109 doAnimation = false;
8110 }
8111 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008112 mPolicyVisibility = true;
8113 mPolicyVisibilityAfterAnim = true;
8114 if (doAnimation) {
8115 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8116 }
8117 if (requestAnim) {
8118 requestAnimationLocked(0);
8119 }
8120 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 }
8122
8123 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008124 return hideLw(doAnimation, true);
8125 }
8126
8127 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008128 if (doAnimation) {
8129 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8130 doAnimation = false;
8131 }
8132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8134 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008135 if (!current) {
8136 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008138 if (doAnimation) {
8139 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8140 if (mAnimation == null) {
8141 doAnimation = false;
8142 }
8143 }
8144 if (doAnimation) {
8145 mPolicyVisibilityAfterAnim = false;
8146 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008147 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008148 mPolicyVisibilityAfterAnim = false;
8149 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008150 // Window is no longer visible -- make sure if we were waiting
8151 // for it to be displayed before enabling the display, that
8152 // we allow the display to be enabled now.
8153 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008154 if (mCurrentFocus == this) {
8155 mFocusMayChange = true;
8156 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008157 }
8158 if (requestAnim) {
8159 requestAnimationLocked(0);
8160 }
8161 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 }
8163
Jeff Brownfbf09772011-01-16 14:06:57 -08008164 public void getTouchableRegion(Region outRegion) {
8165 final Rect frame = mFrame;
8166 switch (mTouchableInsets) {
8167 default:
8168 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8169 outRegion.set(frame);
8170 break;
8171 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8172 final Rect inset = mGivenContentInsets;
8173 outRegion.set(
8174 frame.left + inset.left, frame.top + inset.top,
8175 frame.right - inset.right, frame.bottom - inset.bottom);
8176 break;
8177 }
8178 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8179 final Rect inset = mGivenVisibleInsets;
8180 outRegion.set(
8181 frame.left + inset.left, frame.top + inset.top,
8182 frame.right - inset.right, frame.bottom - inset.bottom);
8183 break;
8184 }
8185 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8186 final Region givenTouchableRegion = mGivenTouchableRegion;
8187 outRegion.set(givenTouchableRegion);
8188 outRegion.translate(frame.left, frame.top);
8189 break;
8190 }
8191 }
8192 }
8193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008194 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008195 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8196 pw.print(" mClient="); pw.println(mClient.asBinder());
8197 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8198 if (mAttachedWindow != null || mLayoutAttached) {
8199 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8200 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8201 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008202 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8203 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8204 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008205 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8206 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008207 }
8208 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8209 pw.print(" mSubLayer="); pw.print(mSubLayer);
8210 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8211 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8212 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8213 pw.print("="); pw.print(mAnimLayer);
8214 pw.print(" mLastLayer="); pw.println(mLastLayer);
8215 if (mSurface != null) {
8216 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008217 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8218 pw.print(" layer="); pw.print(mSurfaceLayer);
8219 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8220 pw.print(" rect=("); pw.print(mSurfaceX);
8221 pw.print(","); pw.print(mSurfaceY);
8222 pw.print(") "); pw.print(mSurfaceW);
8223 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008224 }
8225 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8226 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8227 if (mAppToken != null) {
8228 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8229 }
8230 if (mTargetAppToken != null) {
8231 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8232 }
8233 pw.print(prefix); pw.print("mViewVisibility=0x");
8234 pw.print(Integer.toHexString(mViewVisibility));
8235 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008236 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8237 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008238 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8239 pw.print(prefix); pw.print("mPolicyVisibility=");
8240 pw.print(mPolicyVisibility);
8241 pw.print(" mPolicyVisibilityAfterAnim=");
8242 pw.print(mPolicyVisibilityAfterAnim);
8243 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8244 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008245 if (!mRelayoutCalled) {
8246 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8247 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008248 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008249 pw.print(" h="); pw.print(mRequestedHeight);
8250 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008251 if (mXOffset != 0 || mYOffset != 0) {
8252 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8253 pw.print(" y="); pw.println(mYOffset);
8254 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008255 pw.print(prefix); pw.print("mGivenContentInsets=");
8256 mGivenContentInsets.printShortString(pw);
8257 pw.print(" mGivenVisibleInsets=");
8258 mGivenVisibleInsets.printShortString(pw);
8259 pw.println();
8260 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8261 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8262 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8263 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008264 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008265 pw.print(prefix); pw.print("mShownFrame=");
8266 mShownFrame.printShortString(pw);
8267 pw.print(" last="); mLastShownFrame.printShortString(pw);
8268 pw.println();
8269 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8270 pw.print(" last="); mLastFrame.printShortString(pw);
8271 pw.println();
8272 pw.print(prefix); pw.print("mContainingFrame=");
8273 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008274 pw.print(" mParentFrame=");
8275 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008276 pw.print(" mDisplayFrame=");
8277 mDisplayFrame.printShortString(pw);
8278 pw.println();
8279 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8280 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8281 pw.println();
8282 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8283 pw.print(" last="); mLastContentInsets.printShortString(pw);
8284 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8285 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8286 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008287 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8288 || mAnimation != null) {
8289 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8290 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8291 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8292 pw.print(" mAnimation="); pw.println(mAnimation);
8293 }
8294 if (mHasTransformation || mHasLocalTransformation) {
8295 pw.print(prefix); pw.print("XForm: has=");
8296 pw.print(mHasTransformation);
8297 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8298 pw.print(" "); mTransformation.printShortString(pw);
8299 pw.println();
8300 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008301 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8302 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8303 pw.print(" mAlpha="); pw.print(mAlpha);
8304 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8305 }
8306 if (mHaveMatrix) {
8307 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8308 pw.print(" mDtDx="); pw.print(mDtDx);
8309 pw.print(" mDsDy="); pw.print(mDsDy);
8310 pw.print(" mDtDy="); pw.println(mDtDy);
8311 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008312 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8313 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8314 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8315 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8316 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8317 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8318 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8319 pw.print(" mDestroying="); pw.print(mDestroying);
8320 pw.print(" mRemoved="); pw.println(mRemoved);
8321 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008322 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008323 pw.print(prefix); pw.print("mOrientationChanging=");
8324 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008325 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8326 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008327 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008328 if (mHScale != 1 || mVScale != 1) {
8329 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8330 pw.print(" mVScale="); pw.println(mVScale);
8331 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008332 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008333 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8334 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8335 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008336 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8337 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8338 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008341
8342 String makeInputChannelName() {
8343 return Integer.toHexString(System.identityHashCode(this))
8344 + " " + mAttrs.getTitle();
8345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346
8347 @Override
8348 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008349 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8350 || mWasPaused != mToken.paused) {
8351 mLastTitle = mAttrs.getTitle();
8352 mWasPaused = mToken.paused;
8353 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8354 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8355 }
8356 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 }
8358 }
Romain Guy06882f82009-06-10 13:36:04 -07008359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 // -------------------------------------------------------------
8361 // Window Token State
8362 // -------------------------------------------------------------
8363
8364 class WindowToken {
8365 // The actual token.
8366 final IBinder token;
8367
8368 // The type of window this token is for, as per WindowManager.LayoutParams.
8369 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008371 // Set if this token was explicitly added by a client, so should
8372 // not be removed when all windows are removed.
8373 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008374
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008375 // For printing.
8376 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008378 // If this is an AppWindowToken, this is non-null.
8379 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008381 // All of the windows associated with this token.
8382 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8383
8384 // Is key dispatching paused for this token?
8385 boolean paused = false;
8386
8387 // Should this token's windows be hidden?
8388 boolean hidden;
8389
8390 // Temporary for finding which tokens no longer have visible windows.
8391 boolean hasVisible;
8392
Dianne Hackborna8f60182009-09-01 19:01:50 -07008393 // Set to true when this token is in a pending transaction where it
8394 // will be shown.
8395 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008396
Dianne Hackborna8f60182009-09-01 19:01:50 -07008397 // Set to true when this token is in a pending transaction where it
8398 // will be hidden.
8399 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008400
Dianne Hackborna8f60182009-09-01 19:01:50 -07008401 // Set to true when this token is in a pending transaction where its
8402 // windows will be put to the bottom of the list.
8403 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008404
Dianne Hackborna8f60182009-09-01 19:01:50 -07008405 // Set to true when this token is in a pending transaction where its
8406 // windows will be put to the top of the list.
8407 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008409 WindowToken(IBinder _token, int type, boolean _explicit) {
8410 token = _token;
8411 windowType = type;
8412 explicit = _explicit;
8413 }
8414
8415 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008416 pw.print(prefix); pw.print("token="); pw.println(token);
8417 pw.print(prefix); pw.print("windows="); pw.println(windows);
8418 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8419 pw.print(" hidden="); pw.print(hidden);
8420 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008421 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8422 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8423 pw.print(" waitingToHide="); pw.print(waitingToHide);
8424 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8425 pw.print(" sendingToTop="); pw.println(sendingToTop);
8426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 }
8428
8429 @Override
8430 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008431 if (stringName == null) {
8432 StringBuilder sb = new StringBuilder();
8433 sb.append("WindowToken{");
8434 sb.append(Integer.toHexString(System.identityHashCode(this)));
8435 sb.append(" token="); sb.append(token); sb.append('}');
8436 stringName = sb.toString();
8437 }
8438 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008439 }
8440 };
8441
8442 class AppWindowToken extends WindowToken {
8443 // Non-null only for application tokens.
8444 final IApplicationToken appToken;
8445
8446 // All of the windows and child windows that are included in this
8447 // application token. Note this list is NOT sorted!
8448 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8449
8450 int groupId = -1;
8451 boolean appFullscreen;
8452 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008453
8454 // The input dispatching timeout for this application token in nanoseconds.
8455 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008457 // These are used for determining when all windows associated with
8458 // an activity have been drawn, so they can be made visible together
8459 // at the same time.
8460 int lastTransactionSequence = mTransactionSequence-1;
8461 int numInterestingWindows;
8462 int numDrawnWindows;
8463 boolean inPendingTransaction;
8464 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008466 // Is this token going to be hidden in a little while? If so, it
8467 // won't be taken into account for setting the screen orientation.
8468 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008470 // Is this window's surface needed? This is almost like hidden, except
8471 // it will sometimes be true a little earlier: when the token has
8472 // been shown, but is still waiting for its app transition to execute
8473 // before making its windows shown.
8474 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008476 // Have we told the window clients to hide themselves?
8477 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 // Last visibility state we reported to the app token.
8480 boolean reportedVisible;
8481
8482 // Set to true when the token has been removed from the window mgr.
8483 boolean removed;
8484
8485 // Have we been asked to have this token keep the screen frozen?
8486 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008488 boolean animating;
8489 Animation animation;
8490 boolean hasTransformation;
8491 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 // Offset to the window of all layers in the token, for use by
8494 // AppWindowToken animations.
8495 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008497 // Information about an application starting window if displayed.
8498 StartingData startingData;
8499 WindowState startingWindow;
8500 View startingView;
8501 boolean startingDisplayed;
8502 boolean startingMoved;
8503 boolean firstWindowDrawn;
8504
Jeff Brown928e0542011-01-10 11:17:36 -08008505 // Input application handle used by the input dispatcher.
8506 InputApplicationHandle mInputApplicationHandle;
8507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008508 AppWindowToken(IApplicationToken _token) {
8509 super(_token.asBinder(),
8510 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8511 appWindowToken = this;
8512 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008513 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 }
Romain Guy06882f82009-06-10 13:36:04 -07008515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008517 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 TAG, "Setting animation in " + this + ": " + anim);
8519 animation = anim;
8520 animating = false;
8521 anim.restrictDuration(MAX_ANIMATION_DURATION);
8522 anim.scaleCurrentDuration(mTransitionAnimationScale);
8523 int zorder = anim.getZAdjustment();
8524 int adj = 0;
8525 if (zorder == Animation.ZORDER_TOP) {
8526 adj = TYPE_LAYER_OFFSET;
8527 } else if (zorder == Animation.ZORDER_BOTTOM) {
8528 adj = -TYPE_LAYER_OFFSET;
8529 }
Romain Guy06882f82009-06-10 13:36:04 -07008530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008531 if (animLayerAdjustment != adj) {
8532 animLayerAdjustment = adj;
8533 updateLayers();
8534 }
8535 }
Romain Guy06882f82009-06-10 13:36:04 -07008536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008537 public void setDummyAnimation() {
8538 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008539 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 TAG, "Setting dummy animation in " + this);
8541 animation = sDummyAnimation;
8542 }
8543 }
8544
8545 public void clearAnimation() {
8546 if (animation != null) {
8547 animation = null;
8548 animating = true;
8549 }
8550 }
Romain Guy06882f82009-06-10 13:36:04 -07008551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 void updateLayers() {
8553 final int N = allAppWindows.size();
8554 final int adj = animLayerAdjustment;
8555 for (int i=0; i<N; i++) {
8556 WindowState w = allAppWindows.get(i);
8557 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008558 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 + w.mAnimLayer);
Dianne Hackborne75d8722011-01-27 19:37:40 -08008560 if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 setInputMethodAnimLayerAdjustment(adj);
8562 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008563 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008564 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 }
8567 }
Romain Guy06882f82009-06-10 13:36:04 -07008568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008569 void sendAppVisibilityToClients() {
8570 final int N = allAppWindows.size();
8571 for (int i=0; i<N; i++) {
8572 WindowState win = allAppWindows.get(i);
8573 if (win == startingWindow && clientHidden) {
8574 // Don't hide the starting window.
8575 continue;
8576 }
8577 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008578 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579 "Setting visibility of " + win + ": " + (!clientHidden));
8580 win.mClient.dispatchAppVisibility(!clientHidden);
8581 } catch (RemoteException e) {
8582 }
8583 }
8584 }
Romain Guy06882f82009-06-10 13:36:04 -07008585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008586 void showAllWindowsLocked() {
8587 final int NW = allAppWindows.size();
8588 for (int i=0; i<NW; i++) {
8589 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008590 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008591 "performing show on: " + w);
8592 w.performShowLocked();
8593 }
8594 }
Romain Guy06882f82009-06-10 13:36:04 -07008595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 // This must be called while inside a transaction.
8597 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008598 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008601 if (animation == sDummyAnimation) {
8602 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008603 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008604 // when it is really time to animate, this will be set to
8605 // a real animation and the next call will execute normally.
8606 return false;
8607 }
Romain Guy06882f82009-06-10 13:36:04 -07008608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008609 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8610 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008611 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008612 TAG, "Starting animation in " + this +
8613 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8614 + " scale=" + mTransitionAnimationScale
8615 + " allDrawn=" + allDrawn + " animating=" + animating);
8616 animation.initialize(dw, dh, dw, dh);
8617 animation.setStartTime(currentTime);
8618 animating = true;
8619 }
8620 transformation.clear();
8621 final boolean more = animation.getTransformation(
8622 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008623 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008624 TAG, "Stepped animation in " + this +
8625 ": more=" + more + ", xform=" + transformation);
8626 if (more) {
8627 // we're done!
8628 hasTransformation = true;
8629 return true;
8630 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008631 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008632 TAG, "Finished animation in " + this +
8633 " @ " + currentTime);
8634 animation = null;
8635 }
8636 } else if (animation != null) {
8637 // If the display is frozen, and there is a pending animation,
8638 // clear it and make sure we run the cleanup code.
8639 animating = true;
8640 animation = null;
8641 }
8642
8643 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008645 if (!animating) {
8646 return false;
8647 }
8648
8649 clearAnimation();
8650 animating = false;
Dianne Hackborne75d8722011-01-27 19:37:40 -08008651 if (animLayerAdjustment != 0) {
8652 animLayerAdjustment = 0;
8653 updateLayers();
8654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8656 moveInputMethodWindowsIfNeededLocked(true);
8657 }
Romain Guy06882f82009-06-10 13:36:04 -07008658
Joe Onorato8a9b2202010-02-26 18:56:32 -08008659 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008660 TAG, "Animation done in " + this
8661 + ": reportedVisible=" + reportedVisible);
8662
8663 transformation.clear();
Romain Guy06882f82009-06-10 13:36:04 -07008664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008665 final int N = windows.size();
8666 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008667 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 }
8669 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 return false;
8672 }
8673
8674 void updateReportedVisibilityLocked() {
8675 if (appToken == null) {
8676 return;
8677 }
Romain Guy06882f82009-06-10 13:36:04 -07008678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 int numInteresting = 0;
8680 int numVisible = 0;
8681 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008682
Joe Onorato8a9b2202010-02-26 18:56:32 -08008683 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008684 final int N = allAppWindows.size();
8685 for (int i=0; i<N; i++) {
8686 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008687 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008688 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008689 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8690 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008691 continue;
8692 }
8693 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008694 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008695 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008697 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008698 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008699 + " pv=" + win.mPolicyVisibility
8700 + " dp=" + win.mDrawPending
8701 + " cdp=" + win.mCommitDrawPending
8702 + " ah=" + win.mAttachedHidden
8703 + " th="
8704 + (win.mAppToken != null
8705 ? win.mAppToken.hiddenRequested : false)
8706 + " a=" + win.mAnimating);
8707 }
8708 }
8709 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008710 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008711 if (!win.isAnimating()) {
8712 numVisible++;
8713 }
8714 nowGone = false;
8715 } else if (win.isAnimating()) {
8716 nowGone = false;
8717 }
8718 }
Romain Guy06882f82009-06-10 13:36:04 -07008719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008720 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008721 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008722 + numInteresting + " visible=" + numVisible);
8723 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008724 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008725 TAG, "Visibility changed in " + this
8726 + ": vis=" + nowVisible);
8727 reportedVisible = nowVisible;
8728 Message m = mH.obtainMessage(
8729 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8730 nowVisible ? 1 : 0,
8731 nowGone ? 1 : 0,
8732 this);
8733 mH.sendMessage(m);
8734 }
8735 }
Romain Guy06882f82009-06-10 13:36:04 -07008736
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008737 WindowState findMainWindow() {
8738 int j = windows.size();
8739 while (j > 0) {
8740 j--;
8741 WindowState win = windows.get(j);
8742 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8743 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8744 return win;
8745 }
8746 }
8747 return null;
8748 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008750 void dump(PrintWriter pw, String prefix) {
8751 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008752 if (appToken != null) {
8753 pw.print(prefix); pw.println("app=true");
8754 }
8755 if (allAppWindows.size() > 0) {
8756 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8757 }
8758 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008759 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008760 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8761 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8762 pw.print(" clientHidden="); pw.print(clientHidden);
8763 pw.print(" willBeHidden="); pw.print(willBeHidden);
8764 pw.print(" reportedVisible="); pw.println(reportedVisible);
8765 if (paused || freezingScreen) {
8766 pw.print(prefix); pw.print("paused="); pw.print(paused);
8767 pw.print(" freezingScreen="); pw.println(freezingScreen);
8768 }
8769 if (numInterestingWindows != 0 || numDrawnWindows != 0
8770 || inPendingTransaction || allDrawn) {
8771 pw.print(prefix); pw.print("numInterestingWindows=");
8772 pw.print(numInterestingWindows);
8773 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8774 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8775 pw.print(" allDrawn="); pw.println(allDrawn);
8776 }
8777 if (animating || animation != null) {
8778 pw.print(prefix); pw.print("animating="); pw.print(animating);
8779 pw.print(" animation="); pw.println(animation);
8780 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008781 if (hasTransformation) {
8782 pw.print(prefix); pw.print("XForm: ");
8783 transformation.printShortString(pw);
8784 pw.println();
8785 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008786 if (animLayerAdjustment != 0) {
8787 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8788 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008789 if (startingData != null || removed || firstWindowDrawn) {
8790 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8791 pw.print(" removed="); pw.print(removed);
8792 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8793 }
8794 if (startingWindow != null || startingView != null
8795 || startingDisplayed || startingMoved) {
8796 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8797 pw.print(" startingView="); pw.print(startingView);
8798 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8799 pw.print(" startingMoved"); pw.println(startingMoved);
8800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008801 }
8802
8803 @Override
8804 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008805 if (stringName == null) {
8806 StringBuilder sb = new StringBuilder();
8807 sb.append("AppWindowToken{");
8808 sb.append(Integer.toHexString(System.identityHashCode(this)));
8809 sb.append(" token="); sb.append(token); sb.append('}');
8810 stringName = sb.toString();
8811 }
8812 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813 }
8814 }
Romain Guy06882f82009-06-10 13:36:04 -07008815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008816 // -------------------------------------------------------------
8817 // DummyAnimation
8818 // -------------------------------------------------------------
8819
8820 // This is an animation that does nothing: it just immediately finishes
8821 // itself every time it is called. It is used as a stub animation in cases
8822 // where we want to synchronize multiple things that may be animating.
8823 static final class DummyAnimation extends Animation {
8824 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8825 return false;
8826 }
8827 }
8828 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008830 // -------------------------------------------------------------
8831 // Async Handler
8832 // -------------------------------------------------------------
8833
8834 static final class StartingData {
8835 final String pkg;
8836 final int theme;
8837 final CharSequence nonLocalizedLabel;
8838 final int labelRes;
8839 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008840 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008842 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008843 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008844 pkg = _pkg;
8845 theme = _theme;
8846 nonLocalizedLabel = _nonLocalizedLabel;
8847 labelRes = _labelRes;
8848 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008849 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008850 }
8851 }
8852
8853 private final class H extends Handler {
8854 public static final int REPORT_FOCUS_CHANGE = 2;
8855 public static final int REPORT_LOSING_FOCUS = 3;
8856 public static final int ANIMATE = 4;
8857 public static final int ADD_STARTING = 5;
8858 public static final int REMOVE_STARTING = 6;
8859 public static final int FINISHED_STARTING = 7;
8860 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008861 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8862 public static final int HOLD_SCREEN_CHANGED = 12;
8863 public static final int APP_TRANSITION_TIMEOUT = 13;
8864 public static final int PERSIST_ANIMATION_SCALE = 14;
8865 public static final int FORCE_GC = 15;
8866 public static final int ENABLE_SCREEN = 16;
8867 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008868 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008869 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008870 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008871 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008873 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008875 public H() {
8876 }
Romain Guy06882f82009-06-10 13:36:04 -07008877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008878 @Override
8879 public void handleMessage(Message msg) {
8880 switch (msg.what) {
8881 case REPORT_FOCUS_CHANGE: {
8882 WindowState lastFocus;
8883 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008885 synchronized(mWindowMap) {
8886 lastFocus = mLastFocus;
8887 newFocus = mCurrentFocus;
8888 if (lastFocus == newFocus) {
8889 // Focus is not changing, so nothing to do.
8890 return;
8891 }
8892 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008893 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008894 // + " to " + newFocus);
8895 if (newFocus != null && lastFocus != null
8896 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008897 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 mLosingFocus.add(lastFocus);
8899 lastFocus = null;
8900 }
8901 }
8902
8903 if (lastFocus != newFocus) {
8904 //System.out.println("Changing focus from " + lastFocus
8905 // + " to " + newFocus);
8906 if (newFocus != null) {
8907 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008908 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008909 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8910 } catch (RemoteException e) {
8911 // Ignore if process has died.
8912 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008913 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008914 }
8915
8916 if (lastFocus != null) {
8917 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008918 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008919 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8920 } catch (RemoteException e) {
8921 // Ignore if process has died.
8922 }
8923 }
Joe Onorato664644d2011-01-23 17:53:23 -08008924
8925 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008926 }
8927 } break;
8928
8929 case REPORT_LOSING_FOCUS: {
8930 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 synchronized(mWindowMap) {
8933 losers = mLosingFocus;
8934 mLosingFocus = new ArrayList<WindowState>();
8935 }
8936
8937 final int N = losers.size();
8938 for (int i=0; i<N; i++) {
8939 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008940 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008941 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8942 } catch (RemoteException e) {
8943 // Ignore if process has died.
8944 }
8945 }
8946 } break;
8947
8948 case ANIMATE: {
8949 synchronized(mWindowMap) {
8950 mAnimationPending = false;
8951 performLayoutAndPlaceSurfacesLocked();
8952 }
8953 } break;
8954
8955 case ADD_STARTING: {
8956 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8957 final StartingData sd = wtoken.startingData;
8958
8959 if (sd == null) {
8960 // Animation has been canceled... do nothing.
8961 return;
8962 }
Romain Guy06882f82009-06-10 13:36:04 -07008963
Joe Onorato8a9b2202010-02-26 18:56:32 -08008964 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008965 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 View view = null;
8968 try {
8969 view = mPolicy.addStartingWindow(
8970 wtoken.token, sd.pkg,
8971 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008972 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008973 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008974 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008975 }
8976
8977 if (view != null) {
8978 boolean abort = false;
8979
8980 synchronized(mWindowMap) {
8981 if (wtoken.removed || wtoken.startingData == null) {
8982 // If the window was successfully added, then
8983 // we need to remove it.
8984 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008985 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008986 "Aborted starting " + wtoken
8987 + ": removed=" + wtoken.removed
8988 + " startingData=" + wtoken.startingData);
8989 wtoken.startingWindow = null;
8990 wtoken.startingData = null;
8991 abort = true;
8992 }
8993 } else {
8994 wtoken.startingView = view;
8995 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008996 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 "Added starting " + wtoken
8998 + ": startingWindow="
8999 + wtoken.startingWindow + " startingView="
9000 + wtoken.startingView);
9001 }
9002
9003 if (abort) {
9004 try {
9005 mPolicy.removeStartingWindow(wtoken.token, view);
9006 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009007 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 }
9009 }
9010 }
9011 } break;
9012
9013 case REMOVE_STARTING: {
9014 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9015 IBinder token = null;
9016 View view = null;
9017 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009018 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 + wtoken + ": startingWindow="
9020 + wtoken.startingWindow + " startingView="
9021 + wtoken.startingView);
9022 if (wtoken.startingWindow != null) {
9023 view = wtoken.startingView;
9024 token = wtoken.token;
9025 wtoken.startingData = null;
9026 wtoken.startingView = null;
9027 wtoken.startingWindow = null;
9028 }
9029 }
9030 if (view != null) {
9031 try {
9032 mPolicy.removeStartingWindow(token, view);
9033 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009034 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 }
9036 }
9037 } break;
9038
9039 case FINISHED_STARTING: {
9040 IBinder token = null;
9041 View view = null;
9042 while (true) {
9043 synchronized (mWindowMap) {
9044 final int N = mFinishedStarting.size();
9045 if (N <= 0) {
9046 break;
9047 }
9048 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9049
Joe Onorato8a9b2202010-02-26 18:56:32 -08009050 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009051 "Finished starting " + wtoken
9052 + ": startingWindow=" + wtoken.startingWindow
9053 + " startingView=" + wtoken.startingView);
9054
9055 if (wtoken.startingWindow == null) {
9056 continue;
9057 }
9058
9059 view = wtoken.startingView;
9060 token = wtoken.token;
9061 wtoken.startingData = null;
9062 wtoken.startingView = null;
9063 wtoken.startingWindow = null;
9064 }
9065
9066 try {
9067 mPolicy.removeStartingWindow(token, view);
9068 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009069 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009070 }
9071 }
9072 } break;
9073
9074 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9075 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9076
9077 boolean nowVisible = msg.arg1 != 0;
9078 boolean nowGone = msg.arg2 != 0;
9079
9080 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009081 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009082 TAG, "Reporting visible in " + wtoken
9083 + " visible=" + nowVisible
9084 + " gone=" + nowGone);
9085 if (nowVisible) {
9086 wtoken.appToken.windowsVisible();
9087 } else {
9088 wtoken.appToken.windowsGone();
9089 }
9090 } catch (RemoteException ex) {
9091 }
9092 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009094 case WINDOW_FREEZE_TIMEOUT: {
9095 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009096 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009097 int i = mWindows.size();
9098 while (i > 0) {
9099 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009100 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009101 if (w.mOrientationChanging) {
9102 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009103 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009104 }
9105 }
9106 performLayoutAndPlaceSurfacesLocked();
9107 }
9108 break;
9109 }
Romain Guy06882f82009-06-10 13:36:04 -07009110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 case HOLD_SCREEN_CHANGED: {
9112 Session oldHold;
9113 Session newHold;
9114 synchronized (mWindowMap) {
9115 oldHold = mLastReportedHold;
9116 newHold = (Session)msg.obj;
9117 mLastReportedHold = newHold;
9118 }
Romain Guy06882f82009-06-10 13:36:04 -07009119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009120 if (oldHold != newHold) {
9121 try {
9122 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009123 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124 "window",
9125 BatteryStats.WAKE_TYPE_WINDOW);
9126 }
9127 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009128 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009129 "window",
9130 BatteryStats.WAKE_TYPE_WINDOW);
9131 }
9132 } catch (RemoteException e) {
9133 }
9134 }
9135 break;
9136 }
Romain Guy06882f82009-06-10 13:36:04 -07009137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009138 case APP_TRANSITION_TIMEOUT: {
9139 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009140 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009141 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009142 "*** APP TRANSITION TIMEOUT");
9143 mAppTransitionReady = true;
9144 mAppTransitionTimeout = true;
9145 performLayoutAndPlaceSurfacesLocked();
9146 }
9147 }
9148 break;
9149 }
Romain Guy06882f82009-06-10 13:36:04 -07009150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009151 case PERSIST_ANIMATION_SCALE: {
9152 Settings.System.putFloat(mContext.getContentResolver(),
9153 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9154 Settings.System.putFloat(mContext.getContentResolver(),
9155 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9156 break;
9157 }
Romain Guy06882f82009-06-10 13:36:04 -07009158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009159 case FORCE_GC: {
9160 synchronized(mWindowMap) {
9161 if (mAnimationPending) {
9162 // If we are animating, don't do the gc now but
9163 // delay a bit so we don't interrupt the animation.
9164 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9165 2000);
9166 return;
9167 }
9168 // If we are currently rotating the display, it will
9169 // schedule a new message when done.
9170 if (mDisplayFrozen) {
9171 return;
9172 }
9173 mFreezeGcPending = 0;
9174 }
9175 Runtime.getRuntime().gc();
9176 break;
9177 }
Romain Guy06882f82009-06-10 13:36:04 -07009178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009179 case ENABLE_SCREEN: {
9180 performEnableScreen();
9181 break;
9182 }
Romain Guy06882f82009-06-10 13:36:04 -07009183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 case APP_FREEZE_TIMEOUT: {
9185 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009186 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009187 int i = mAppTokens.size();
9188 while (i > 0) {
9189 i--;
9190 AppWindowToken tok = mAppTokens.get(i);
9191 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009192 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009193 unsetAppFreezingScreenLocked(tok, true, true);
9194 }
9195 }
9196 }
9197 break;
9198 }
Romain Guy06882f82009-06-10 13:36:04 -07009199
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009200 case SEND_NEW_CONFIGURATION: {
9201 removeMessages(SEND_NEW_CONFIGURATION);
9202 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009203 break;
9204 }
Romain Guy06882f82009-06-10 13:36:04 -07009205
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009206 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009207 if (mWindowsChanged) {
9208 synchronized (mWindowMap) {
9209 mWindowsChanged = false;
9210 }
9211 notifyWindowsChanged();
9212 }
9213 break;
9214 }
9215
Christopher Tatea53146c2010-09-07 11:57:52 -07009216 case DRAG_START_TIMEOUT: {
9217 IBinder win = (IBinder)msg.obj;
9218 if (DEBUG_DRAG) {
9219 Slog.w(TAG, "Timeout starting drag by win " + win);
9220 }
9221 synchronized (mWindowMap) {
9222 // !!! TODO: ANR the app that has failed to start the drag in time
9223 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07009224 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009225 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009226 mDragState.reset();
9227 mDragState = null;
9228 }
9229 }
Chris Tated4533f142010-10-19 15:15:08 -07009230 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009231 }
9232
Chris Tated4533f142010-10-19 15:15:08 -07009233 case DRAG_END_TIMEOUT: {
9234 IBinder win = (IBinder)msg.obj;
9235 if (DEBUG_DRAG) {
9236 Slog.w(TAG, "Timeout ending drag to win " + win);
9237 }
9238 synchronized (mWindowMap) {
9239 // !!! TODO: ANR the drag-receiving app
9240 mDragState.mDragResult = false;
9241 mDragState.endDragLw();
9242 }
9243 break;
9244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009245 }
9246 }
9247 }
9248
9249 // -------------------------------------------------------------
9250 // IWindowManager API
9251 // -------------------------------------------------------------
9252
9253 public IWindowSession openSession(IInputMethodClient client,
9254 IInputContext inputContext) {
9255 if (client == null) throw new IllegalArgumentException("null client");
9256 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009257 Session session = new Session(client, inputContext);
9258 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009259 }
9260
9261 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9262 synchronized (mWindowMap) {
9263 // The focus for the client is the window immediately below
9264 // where we would place the input method window.
9265 int idx = findDesiredInputMethodWindowIndexLocked(false);
9266 WindowState imFocus;
9267 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009268 imFocus = mWindows.get(idx-1);
Dianne Hackborne75d8722011-01-27 19:37:40 -08009269 //Log.i(TAG, "Desired input method target: " + imFocus);
9270 //Log.i(TAG, "Current focus: " + this.mCurrentFocus);
9271 //Log.i(TAG, "Last focus: " + this.mLastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009272 if (imFocus != null) {
Dianne Hackborne75d8722011-01-27 19:37:40 -08009273 // This may be a starting window, in which case we still want
9274 // to count it as okay.
9275 if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
9276 && imFocus.mAppToken != null) {
9277 // The client has definitely started, so it really should
9278 // have a window in this app token. Let's look for it.
9279 for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
9280 WindowState w = imFocus.mAppToken.windows.get(i);
9281 if (w != imFocus) {
9282 //Log.i(TAG, "Switching to real app window: " + w);
9283 imFocus = w;
9284 break;
9285 }
9286 }
9287 }
9288 //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient);
9289 //if (imFocus.mSession.mClient != null) {
9290 // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder());
9291 // Log.i(TAG, "Requesting client binder: " + client.asBinder());
9292 //}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009293 if (imFocus.mSession.mClient != null &&
9294 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9295 return true;
9296 }
Dianne Hackborne75d8722011-01-27 19:37:40 -08009297
9298 // Okay, how about this... what is the current focus?
9299 // It seems in some cases we may not have moved the IM
9300 // target window, such as when it was in a pop-up window,
9301 // so let's also look at the current focus. (An example:
9302 // go to Gmail, start searching so the keyboard goes up,
9303 // press home. Sometimes the IME won't go down.)
9304 // Would be nice to fix this more correctly, but it's
9305 // way at the end of a release, and this should be good enough.
9306 if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null &&
9307 mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
9308 return true;
9309 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009310 }
9311 }
9312 }
9313 return false;
9314 }
Romain Guy06882f82009-06-10 13:36:04 -07009315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009316 // -------------------------------------------------------------
9317 // Internals
9318 // -------------------------------------------------------------
9319
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009320 final WindowState windowForClientLocked(Session session, IWindow client,
9321 boolean throwOnError) {
9322 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 }
Romain Guy06882f82009-06-10 13:36:04 -07009324
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009325 final WindowState windowForClientLocked(Session session, IBinder client,
9326 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009328 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 TAG, "Looking up client " + client + ": " + win);
9330 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009331 RuntimeException ex = new IllegalArgumentException(
9332 "Requested window " + client + " does not exist");
9333 if (throwOnError) {
9334 throw ex;
9335 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009336 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009337 return null;
9338 }
9339 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009340 RuntimeException ex = new IllegalArgumentException(
9341 "Requested window " + client + " is in session " +
9342 win.mSession + ", not " + session);
9343 if (throwOnError) {
9344 throw ex;
9345 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009346 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 return null;
9348 }
9349
9350 return win;
9351 }
9352
Dianne Hackborna8f60182009-09-01 19:01:50 -07009353 final void rebuildAppWindowListLocked() {
9354 int NW = mWindows.size();
9355 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009356 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009357 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009358
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009359 if (mRebuildTmp.length < NW) {
9360 mRebuildTmp = new WindowState[NW+10];
9361 }
9362
Dianne Hackborna8f60182009-09-01 19:01:50 -07009363 // First remove all existing app windows.
9364 i=0;
9365 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009366 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009367 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009368 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009369 win.mRebuilding = true;
9370 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009371 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009372 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009373 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009374 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009375 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009376 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009377 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9378 && lastWallpaper == i-1) {
9379 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009380 }
9381 i++;
9382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009383
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009384 // The wallpaper window(s) typically live at the bottom of the stack,
9385 // so skip them before adding app tokens.
9386 lastWallpaper++;
9387 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009388
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009389 // First add all of the exiting app tokens... these are no longer
9390 // in the main app list, but still have windows shown. We put them
9391 // in the back because now that the animation is over we no longer
9392 // will care about them.
9393 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009394 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009395 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9396 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009397
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009398 // And add in the still active app tokens in Z order.
9399 NT = mAppTokens.size();
9400 for (int j=0; j<NT; j++) {
9401 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009402 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009403
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009404 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009405 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009406 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009407 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009408 for (i=0; i<numRemoved; i++) {
9409 WindowState ws = mRebuildTmp[i];
9410 if (ws.mRebuilding) {
9411 StringWriter sw = new StringWriter();
9412 PrintWriter pw = new PrintWriter(sw);
9413 ws.dump(pw, "");
9414 pw.flush();
9415 Slog.w(TAG, "This window was lost: " + ws);
9416 Slog.w(TAG, sw.toString());
9417 }
9418 }
9419 Slog.w(TAG, "Current app token list:");
9420 dumpAppTokensLocked();
9421 Slog.w(TAG, "Final window list:");
9422 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009423 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009424 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 private final void assignLayersLocked() {
9427 int N = mWindows.size();
9428 int curBaseLayer = 0;
9429 int curLayer = 0;
9430 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009431
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009432 if (DEBUG_LAYERS) {
9433 RuntimeException here = new RuntimeException("here");
9434 here.fillInStackTrace();
9435 Log.v(TAG, "Assigning layers", here);
9436 }
9437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009438 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009439 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009440 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9441 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 curLayer += WINDOW_LAYER_MULTIPLIER;
9443 w.mLayer = curLayer;
9444 } else {
9445 curBaseLayer = curLayer = w.mBaseLayer;
9446 w.mLayer = curLayer;
9447 }
9448 if (w.mTargetAppToken != null) {
9449 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9450 } else if (w.mAppToken != null) {
9451 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9452 } else {
9453 w.mAnimLayer = w.mLayer;
9454 }
9455 if (w.mIsImWindow) {
9456 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009457 } else if (w.mIsWallpaper) {
9458 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009459 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009460 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009461 + w.mAnimLayer);
9462 //System.out.println(
9463 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9464 }
9465 }
9466
9467 private boolean mInLayout = false;
9468 private final void performLayoutAndPlaceSurfacesLocked() {
9469 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009470 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471 throw new RuntimeException("Recursive call!");
9472 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009473 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 return;
9475 }
9476
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009477 if (mWaitingForConfig) {
9478 // Our configuration has changed (most likely rotation), but we
9479 // don't yet have the complete configuration to report to
9480 // applications. Don't do any window layout until we have it.
9481 return;
9482 }
9483
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009484 if (mDisplay == null) {
9485 // Not yet initialized, nothing to do.
9486 return;
9487 }
9488
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009489 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009490 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009491
9492 try {
9493 if (mForceRemoves != null) {
9494 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009495 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009496 for (int i=0; i<mForceRemoves.size(); i++) {
9497 WindowState ws = mForceRemoves.get(i);
9498 Slog.i(TAG, "Force removing: " + ws);
9499 removeWindowInnerLocked(ws.mSession, ws);
9500 }
9501 mForceRemoves = null;
9502 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9503 Object tmp = new Object();
9504 synchronized (tmp) {
9505 try {
9506 tmp.wait(250);
9507 } catch (InterruptedException e) {
9508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 }
9510 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009511 } catch (RuntimeException e) {
9512 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009513 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009515 try {
9516 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009517
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009518 int N = mPendingRemove.size();
9519 if (N > 0) {
9520 if (mPendingRemoveTmp.length < N) {
9521 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009522 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009523 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009524 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009525 for (int i=0; i<N; i++) {
9526 WindowState w = mPendingRemoveTmp[i];
9527 removeWindowInnerLocked(w.mSession, w);
9528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009529
9530 mInLayout = false;
9531 assignLayersLocked();
9532 mLayoutNeeded = true;
9533 performLayoutAndPlaceSurfacesLocked();
9534
9535 } else {
9536 mInLayout = false;
9537 if (mLayoutNeeded) {
9538 requestAnimationLocked(0);
9539 }
9540 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009541 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009542 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9543 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 } catch (RuntimeException e) {
9546 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009547 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 }
9549 }
9550
Jeff Brown3a22cd92011-01-21 13:59:04 -08009551 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009552 if (!mLayoutNeeded) {
9553 return 0;
9554 }
9555
9556 mLayoutNeeded = false;
9557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 final int dw = mDisplay.getWidth();
9559 final int dh = mDisplay.getHeight();
9560
9561 final int N = mWindows.size();
9562 int i;
9563
Joe Onorato8a9b2202010-02-26 18:56:32 -08009564 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009565 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9566
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009567 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009568
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009569 int seq = mLayoutSeq+1;
9570 if (seq < 0) seq = 0;
9571 mLayoutSeq = seq;
9572
9573 // First perform layout of any root windows (not attached
9574 // to another window).
9575 int topAttached = -1;
9576 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009577 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009578
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009579 // Don't do layout of a window if it is not visible, or
9580 // soon won't be visible, to avoid wasting time and funky
9581 // changes while a window is animating away.
9582 final AppWindowToken atoken = win.mAppToken;
9583 final boolean gone = win.mViewVisibility == View.GONE
9584 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009585 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009586 || (atoken != null && atoken.hiddenRequested)
9587 || win.mAttachedHidden
9588 || win.mExiting || win.mDestroying;
9589
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009590 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9591 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009592 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9593 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009594 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009595 + win.mViewVisibility + " mRelayoutCalled="
9596 + win.mRelayoutCalled + " hidden="
9597 + win.mRootToken.hidden + " hiddenRequested="
9598 + (atoken != null && atoken.hiddenRequested)
9599 + " mAttachedHidden=" + win.mAttachedHidden);
9600 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009601
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009602 // If this view is GONE, then skip it -- keep the current
9603 // frame, and let the caller know so they can ignore it
9604 // if they want. (We do the normal layout for INVISIBLE
9605 // windows, since that means "perform layout as normal,
9606 // just don't display").
9607 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009608 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009609 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009610 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009611 win.mContentChanged = false;
9612 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009613 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9614 win.mLayoutSeq = seq;
9615 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9616 + win.mFrame + " mContainingFrame="
9617 + win.mContainingFrame + " mDisplayFrame="
9618 + win.mDisplayFrame);
9619 } else {
9620 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009621 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009623 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009624
9625 // Now perform layout of attached windows, which usually
9626 // depend on the position of the window they are attached to.
9627 // XXX does not deal with windows that are attached to windows
9628 // that are themselves attached.
9629 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009630 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009631
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009632 if (win.mLayoutAttached) {
9633 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9634 + " mHaveFrame=" + win.mHaveFrame
9635 + " mViewVisibility=" + win.mViewVisibility
9636 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009637 // If this view is GONE, then skip it -- keep the current
9638 // frame, and let the caller know so they can ignore it
9639 // if they want. (We do the normal layout for INVISIBLE
9640 // windows, since that means "perform layout as normal,
9641 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009642 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9643 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009644 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009645 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009646 win.mContentChanged = false;
9647 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009648 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9649 win.mLayoutSeq = seq;
9650 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9651 + win.mFrame + " mContainingFrame="
9652 + win.mContainingFrame + " mDisplayFrame="
9653 + win.mDisplayFrame);
9654 }
9655 }
9656 }
Jeff Brown349703e2010-06-22 01:27:15 -07009657
9658 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009659 mInputMonitor.setUpdateInputWindowsNeededLw();
9660 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009661 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009662 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009663
9664 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009665 }
Romain Guy06882f82009-06-10 13:36:04 -07009666
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009667 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009668 private final void performLayoutAndPlaceSurfacesLockedInner(
9669 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009670 if (mDisplay == null) {
9671 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9672 return;
9673 }
9674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009675 final long currentTime = SystemClock.uptimeMillis();
9676 final int dw = mDisplay.getWidth();
9677 final int dh = mDisplay.getHeight();
9678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009679 int i;
9680
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009681 if (mFocusMayChange) {
9682 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009683 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9684 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009685 }
9686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009687 // Initialize state of exiting tokens.
9688 for (i=mExitingTokens.size()-1; i>=0; i--) {
9689 mExitingTokens.get(i).hasVisible = false;
9690 }
9691
9692 // Initialize state of exiting applications.
9693 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9694 mExitingAppTokens.get(i).hasVisible = false;
9695 }
9696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009697 boolean orientationChangeComplete = true;
9698 Session holdScreen = null;
9699 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009700 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009701 boolean focusDisplayed = false;
9702 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009703 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009704 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009705
9706 if (mFxSession == null) {
9707 mFxSession = new SurfaceSession();
9708 createWatermark = true;
9709 }
9710
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009711 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009712
9713 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009714
9715 if (createWatermark) {
9716 createWatermark();
9717 }
9718 if (mWatermark != null) {
9719 mWatermark.positionSurface(dw, dh);
9720 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009721 if (mStrictModeFlash != null) {
9722 mStrictModeFlash.positionSurface(dw, dh);
9723 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009725 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009726 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009727 int repeats = 0;
9728 int changes = 0;
9729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009730 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009731 repeats++;
9732 if (repeats > 6) {
9733 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9734 mLayoutNeeded = false;
9735 break;
9736 }
9737
9738 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9739 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9740 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9741 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9742 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9743 assignLayersLocked();
9744 mLayoutNeeded = true;
9745 }
9746 }
9747 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9748 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009749 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009750 mLayoutNeeded = true;
9751 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9752 }
9753 }
9754 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9755 mLayoutNeeded = true;
9756 }
9757 }
9758
9759 // FIRST LOOP: Perform a layout, if needed.
9760 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009761 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009762 if (changes != 0) {
9763 continue;
9764 }
9765 } else {
9766 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9767 changes = 0;
9768 }
9769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009770 final int transactionSequence = ++mTransactionSequence;
9771
9772 // Update animations of all applications, including those
9773 // associated with exiting/removed apps
9774 boolean tokensAnimating = false;
9775 final int NAT = mAppTokens.size();
9776 for (i=0; i<NAT; i++) {
9777 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9778 tokensAnimating = true;
9779 }
9780 }
9781 final int NEAT = mExitingAppTokens.size();
9782 for (i=0; i<NEAT; i++) {
9783 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9784 tokensAnimating = true;
9785 }
9786 }
9787
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009788 // SECOND LOOP: Execute animations and update visibility of windows.
9789
Joe Onorato8a9b2202010-02-26 18:56:32 -08009790 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009791 + transactionSequence + " tokensAnimating="
9792 + tokensAnimating);
9793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009796 if (mScreenRotationAnimation != null) {
9797 if (mScreenRotationAnimation.isAnimating()) {
9798 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9799 animating = true;
9800 } else {
9801 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009802 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009803 }
9804 }
9805 }
9806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009807 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009808 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009809 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009810 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811
9812 mPolicy.beginAnimationLw(dw, dh);
9813
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009814 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009817 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818
9819 final WindowManager.LayoutParams attrs = w.mAttrs;
9820
9821 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009822 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009823 if (w.commitFinishDrawingLocked(currentTime)) {
9824 if ((w.mAttrs.flags
9825 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009826 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009827 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009828 wallpaperMayChange = true;
9829 }
9830 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009831
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009832 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009833
9834 int animDw = dw;
9835 int animDh = dh;
9836
9837 // If the window has moved due to its containing
9838 // content frame changing, then we'd like to animate
9839 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009840 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009841 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009842 // Frame has moved, containing content frame
9843 // has also moved, and we're not currently animating...
9844 // let's do something.
9845 Animation a = AnimationUtils.loadAnimation(mContext,
9846 com.android.internal.R.anim.window_move_from_decor);
9847 w.setAnimation(a);
9848 animDw = w.mLastFrame.left - w.mFrame.left;
9849 animDh = w.mLastFrame.top - w.mFrame.top;
9850 }
9851
9852 // Execute animation.
9853 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9854 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009855
9856 // If this window is animating, make a note that we have
9857 // an animating window and take care of a request to run
9858 // a detached wallpaper animation.
9859 if (nowAnimating) {
9860 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9861 windowDetachedWallpaper = w;
9862 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009863 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009865
9866 // If this window's app token is running a detached wallpaper
9867 // animation, make a note so we can ensure the wallpaper is
9868 // displayed behind it.
9869 if (w.mAppToken != null && w.mAppToken.animation != null
9870 && w.mAppToken.animation.getDetachWallpaper()) {
9871 windowDetachedWallpaper = w;
9872 }
9873
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009874 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9875 wallpaperMayChange = true;
9876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009877
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009878 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009879 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009880 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009881 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009882 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009883 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009884 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009885 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9886 forceHiding = true;
9887 }
9888 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9889 boolean changed;
9890 if (forceHiding) {
9891 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009892 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9893 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009894 } else {
9895 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009896 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9897 "Now policy shown: " + w);
9898 if (changed) {
9899 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009900 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009901 // Assume we will need to animate. If
9902 // we don't (because the wallpaper will
9903 // stay with the lock screen), then we will
9904 // clean up later.
9905 Animation a = mPolicy.createForceHideEnterAnimation();
9906 if (a != null) {
9907 w.setAnimation(a);
9908 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009909 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009910 if (mCurrentFocus == null ||
9911 mCurrentFocus.mLayer < w.mLayer) {
9912 // We are showing on to of the current
9913 // focus, so re-evaluate focus to make
9914 // sure it is correct.
9915 mFocusMayChange = true;
9916 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009917 }
9918 }
9919 if (changed && (attrs.flags
9920 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9921 wallpaperMayChange = true;
9922 }
9923 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925 mPolicy.animatingWindowLw(w, attrs);
9926 }
9927
9928 final AppWindowToken atoken = w.mAppToken;
9929 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9930 if (atoken.lastTransactionSequence != transactionSequence) {
9931 atoken.lastTransactionSequence = transactionSequence;
9932 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9933 atoken.startingDisplayed = false;
9934 }
9935 if ((w.isOnScreen() || w.mAttrs.type
9936 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9937 && !w.mExiting && !w.mDestroying) {
9938 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009939 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009940 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009941 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009942 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009943 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 + " pv=" + w.mPolicyVisibility
9945 + " dp=" + w.mDrawPending
9946 + " cdp=" + w.mCommitDrawPending
9947 + " ah=" + w.mAttachedHidden
9948 + " th=" + atoken.hiddenRequested
9949 + " a=" + w.mAnimating);
9950 }
9951 }
9952 if (w != atoken.startingWindow) {
9953 if (!atoken.freezingScreen || !w.mAppFreezing) {
9954 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009955 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009956 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009957 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009958 "tokenMayBeDrawn: " + atoken
9959 + " freezingScreen=" + atoken.freezingScreen
9960 + " mAppFreezing=" + w.mAppFreezing);
9961 tokenMayBeDrawn = true;
9962 }
9963 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009964 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 atoken.startingDisplayed = true;
9966 }
9967 }
9968 } else if (w.mReadyToShow) {
9969 w.performShowLocked();
9970 }
9971 }
9972
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009973 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009974
9975 if (tokenMayBeDrawn) {
9976 // See if any windows have been drawn, so they (and others
9977 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009978 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009979 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009980 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009981 if (wtoken.freezingScreen) {
9982 int numInteresting = wtoken.numInterestingWindows;
9983 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009984 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 "allDrawn: " + wtoken
9986 + " interesting=" + numInteresting
9987 + " drawn=" + wtoken.numDrawnWindows);
9988 wtoken.showAllWindowsLocked();
9989 unsetAppFreezingScreenLocked(wtoken, false, true);
9990 orientationChangeComplete = true;
9991 }
9992 } else if (!wtoken.allDrawn) {
9993 int numInteresting = wtoken.numInterestingWindows;
9994 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009995 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009996 "allDrawn: " + wtoken
9997 + " interesting=" + numInteresting
9998 + " drawn=" + wtoken.numDrawnWindows);
9999 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010000 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010001
10002 // We can now show all of the drawn windows!
10003 if (!mOpeningApps.contains(wtoken)) {
10004 wtoken.showAllWindowsLocked();
10005 }
10006 }
10007 }
10008 }
10009 }
10010
10011 // If we are ready to perform an app transition, check through
10012 // all of the app tokens to be shown and see if they are ready
10013 // to go.
10014 if (mAppTransitionReady) {
10015 int NN = mOpeningApps.size();
10016 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010017 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 "Checking " + NN + " opening apps (frozen="
10019 + mDisplayFrozen + " timeout="
10020 + mAppTransitionTimeout + ")...");
10021 if (!mDisplayFrozen && !mAppTransitionTimeout) {
10022 // If the display isn't frozen, wait to do anything until
10023 // all of the apps are ready. Otherwise just go because
10024 // we'll unfreeze the display when everyone is ready.
10025 for (i=0; i<NN && goodToGo; i++) {
10026 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010027 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010028 "Check opening app" + wtoken + ": allDrawn="
10029 + wtoken.allDrawn + " startingDisplayed="
10030 + wtoken.startingDisplayed);
10031 if (!wtoken.allDrawn && !wtoken.startingDisplayed
10032 && !wtoken.startingMoved) {
10033 goodToGo = false;
10034 }
10035 }
10036 }
10037 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010038 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010039 int transit = mNextAppTransition;
10040 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010041 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010042 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010043 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010044 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010045 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 mAppTransitionTimeout = false;
10047 mStartingIconInTransition = false;
10048 mSkipAppTransitionAnimation = false;
10049
10050 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
10051
Dianne Hackborna8f60182009-09-01 19:01:50 -070010052 // If there are applications waiting to come to the
10053 // top of the stack, now is the time to move their windows.
10054 // (Note that we don't do apps going to the bottom
10055 // here -- we want to keep their windows in the old
10056 // Z-order until the animation completes.)
10057 if (mToTopApps.size() > 0) {
10058 NN = mAppTokens.size();
10059 for (i=0; i<NN; i++) {
10060 AppWindowToken wtoken = mAppTokens.get(i);
10061 if (wtoken.sendingToTop) {
10062 wtoken.sendingToTop = false;
10063 moveAppWindowsLocked(wtoken, NN, false);
10064 }
10065 }
10066 mToTopApps.clear();
10067 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010068
Dianne Hackborn25994b42009-09-04 14:21:19 -070010069 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010070
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010071 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010072 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010073
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010074 // The top-most window will supply the layout params,
10075 // and we will determine it below.
10076 LayoutParams animLp = null;
10077 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010078 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010079
Joe Onorato8a9b2202010-02-26 18:56:32 -080010080 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010081 "New wallpaper target=" + mWallpaperTarget
10082 + ", lower target=" + mLowerWallpaperTarget
10083 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010084 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010085 // Do a first pass through the tokens for two
10086 // things:
10087 // (1) Determine if both the closing and opening
10088 // app token sets are wallpaper targets, in which
10089 // case special animations are needed
10090 // (since the wallpaper needs to stay static
10091 // behind them).
10092 // (2) Find the layout params of the top-most
10093 // application window in the tokens, which is
10094 // what will control the animation theme.
10095 final int NC = mClosingApps.size();
10096 NN = NC + mOpeningApps.size();
10097 for (i=0; i<NN; i++) {
10098 AppWindowToken wtoken;
10099 int mode;
10100 if (i < NC) {
10101 wtoken = mClosingApps.get(i);
10102 mode = 1;
10103 } else {
10104 wtoken = mOpeningApps.get(i-NC);
10105 mode = 2;
10106 }
10107 if (mLowerWallpaperTarget != null) {
10108 if (mLowerWallpaperTarget.mAppToken == wtoken
10109 || mUpperWallpaperTarget.mAppToken == wtoken) {
10110 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010111 }
10112 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010113 if (wtoken.appFullscreen) {
10114 WindowState ws = wtoken.findMainWindow();
10115 if (ws != null) {
10116 // If this is a compatibility mode
10117 // window, we will always use its anim.
10118 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10119 animLp = ws.mAttrs;
10120 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010121 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010122 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010123 bestAnimLayer = ws.mLayer;
10124 }
10125 fullscreenAnim = true;
10126 }
10127 } else if (!fullscreenAnim) {
10128 WindowState ws = wtoken.findMainWindow();
10129 if (ws != null) {
10130 if (ws.mLayer > bestAnimLayer) {
10131 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010132 bestAnimLayer = ws.mLayer;
10133 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010134 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010135 }
10136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010137
Dianne Hackborn25994b42009-09-04 14:21:19 -070010138 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010139 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010140 "Wallpaper animation!");
10141 switch (transit) {
10142 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10143 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10144 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10145 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10146 break;
10147 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10148 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10149 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10150 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10151 break;
10152 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010153 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010154 "New transit: " + transit);
10155 } else if (oldWallpaper != null) {
10156 // We are transitioning from an activity with
10157 // a wallpaper to one without.
10158 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010159 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010160 "New transit away from wallpaper: " + transit);
10161 } else if (mWallpaperTarget != null) {
10162 // We are transitioning from an activity without
10163 // a wallpaper to now showing the wallpaper
10164 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010165 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010166 "New transit into wallpaper: " + transit);
10167 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010168
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010169 // If all closing windows are obscured, then there is
10170 // no need to do an animation. This is the case, for
10171 // example, when this transition is being done behind
10172 // the lock screen.
10173 if (!mPolicy.allowAppAnimationsLw()) {
10174 animLp = null;
10175 }
10176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010177 NN = mOpeningApps.size();
10178 for (i=0; i<NN; i++) {
10179 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010180 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010181 "Now opening app" + wtoken);
10182 wtoken.reportedVisible = false;
10183 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010184 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010185 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010186 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010187 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010188 wtoken.showAllWindowsLocked();
10189 }
10190 NN = mClosingApps.size();
10191 for (i=0; i<NN; i++) {
10192 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010193 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010194 "Now closing app" + wtoken);
10195 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010196 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010197 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010198 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010199 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010200 // Force the allDrawn flag, because we want to start
10201 // this guy's animations regardless of whether it's
10202 // gotten drawn.
10203 wtoken.allDrawn = true;
10204 }
10205
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010206 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010208 mOpeningApps.clear();
10209 mClosingApps.clear();
10210
10211 // This has changed the visibility of windows, so perform
10212 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010213 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10214 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010215 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010216 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10217 assignLayersLocked();
10218 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010219 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10220 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010221 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010222 }
10223 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010224
Dianne Hackborn16064f92010-03-25 00:47:24 -070010225 int adjResult = 0;
10226
Dianne Hackborna8f60182009-09-01 19:01:50 -070010227 if (!animating && mAppTransitionRunning) {
10228 // We have finished the animation of an app transition. To do
10229 // this, we have delayed a lot of operations like showing and
10230 // hiding apps, moving apps in Z-order, etc. The app token list
10231 // reflects the correct Z-order, but the window list may now
10232 // be out of sync with it. So here we will just rebuild the
10233 // entire app window list. Fun!
10234 mAppTransitionRunning = false;
10235 // Clear information about apps that were moving.
10236 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010237
Dianne Hackborna8f60182009-09-01 19:01:50 -070010238 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010239 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010240 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010241 moveInputMethodWindowsIfNeededLocked(false);
10242 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010243 // Since the window list has been rebuilt, focus might
10244 // have to be recomputed since the actual order of windows
10245 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010246 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010248
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010249 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010250 // At this point, there was a window with a wallpaper that
10251 // was force hiding other windows behind it, but now it
10252 // is going away. This may be simple -- just animate
10253 // away the wallpaper and its window -- or it may be
10254 // hard -- the wallpaper now needs to be shown behind
10255 // something that was hidden.
10256 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010257 if (mLowerWallpaperTarget != null
10258 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010259 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010260 "wallpaperForceHiding changed with lower="
10261 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010262 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010263 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10264 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10265 if (mLowerWallpaperTarget.mAppToken.hidden) {
10266 // The lower target has become hidden before we
10267 // actually started the animation... let's completely
10268 // re-evaluate everything.
10269 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010270 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010271 }
10272 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010273 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010274 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010275 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010276 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010277 + " NEW: " + mWallpaperTarget
10278 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010279 if (mLowerWallpaperTarget == null) {
10280 // Whoops, we don't need a special wallpaper animation.
10281 // Clear them out.
10282 forceHiding = false;
10283 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010284 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010285 if (w.mSurface != null) {
10286 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010287 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010288 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010289 forceHiding = true;
10290 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10291 if (!w.mAnimating) {
10292 // We set the animation above so it
10293 // is not yet running.
10294 w.clearAnimation();
10295 }
10296 }
10297 }
10298 }
10299 }
10300 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010301
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010302 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10303 if (DEBUG_WALLPAPER) Slog.v(TAG,
10304 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10305 + windowDetachedWallpaper);
10306 mWindowDetachedWallpaper = windowDetachedWallpaper;
10307 wallpaperMayChange = true;
10308 }
10309
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010310 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010311 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010312 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010313 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010314 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010315
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010316 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010317 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010318 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010319 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010320 assignLayersLocked();
10321 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010322 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010323 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010324 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010325 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010326
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010327 if (mFocusMayChange) {
10328 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010329 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10330 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010331 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010332 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010333 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010334 }
10335
10336 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010337 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010338 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010339
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010340 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10341 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010342 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010343
10344 // THIRD LOOP: Update the surfaces of all windows.
10345
10346 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10347
10348 boolean obscured = false;
10349 boolean blurring = false;
10350 boolean dimming = false;
10351 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010352 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010353 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010355 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010358 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359
10360 boolean displayed = false;
10361 final WindowManager.LayoutParams attrs = w.mAttrs;
10362 final int attrFlags = attrs.flags;
10363
10364 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010365 // XXX NOTE: The logic here could be improved. We have
10366 // the decision about whether to resize a window separated
10367 // from whether to hide the surface. This can cause us to
10368 // resize a surface even if we are going to hide it. You
10369 // can see this by (1) holding device in landscape mode on
10370 // home screen; (2) tapping browser icon (device will rotate
10371 // to landscape; (3) tap home. The wallpaper will be resized
10372 // in step 2 but then immediately hidden, causing us to
10373 // have to resize and then redraw it again in step 3. It
10374 // would be nice to figure out how to avoid this, but it is
10375 // difficult because we do need to resize surfaces in some
10376 // cases while they are hidden such as when first showing a
10377 // window.
10378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010379 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010380 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010381 TAG, "Placing surface #" + i + " " + w.mSurface
10382 + ": new=" + w.mShownFrame + ", old="
10383 + w.mLastShownFrame);
10384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 int width, height;
10386 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 // for a scaled surface, we just want to use
10388 // the requested size.
10389 width = w.mRequestedWidth;
10390 height = w.mRequestedHeight;
10391 w.mLastRequestedWidth = width;
10392 w.mLastRequestedHeight = height;
10393 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010394 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010395 width = w.mShownFrame.width();
10396 height = w.mShownFrame.height();
10397 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 }
10399
Jeff Brownfbae7222011-01-23 13:07:25 -080010400 if (w.mSurface != null) {
10401 if (w.mSurfaceX != w.mShownFrame.left
10402 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010404 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010405 "POS " + w.mShownFrame.left
10406 + ", " + w.mShownFrame.top, null);
10407 w.mSurfaceX = w.mShownFrame.left;
10408 w.mSurfaceY = w.mShownFrame.top;
10409 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10410 } catch (RuntimeException e) {
10411 Slog.w(TAG, "Error positioning surface of " + w
10412 + " pos=(" + w.mShownFrame.left
10413 + "," + w.mShownFrame.top + ")", e);
10414 if (!recoveringMemory) {
10415 reclaimSomeSurfaceMemoryLocked(w, "position");
10416 }
10417 }
10418 }
10419
10420 if (width < 1) {
10421 width = 1;
10422 }
10423 if (height < 1) {
10424 height = 1;
10425 }
10426
10427 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10428 try {
10429 if (SHOW_TRANSACTIONS) logSurface(w,
10430 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010431 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010432 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010433 w.mSurfaceW = width;
10434 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010436 } catch (RuntimeException e) {
10437 // If something goes wrong with the surface (such
10438 // as running out of memory), don't take down the
10439 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010440 Slog.e(TAG, "Error resizing surface of " + w
10441 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 if (!recoveringMemory) {
10443 reclaimSomeSurfaceMemoryLocked(w, "size");
10444 }
10445 }
10446 }
10447 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010448
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010449 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 w.mContentInsetsChanged =
10451 !w.mLastContentInsets.equals(w.mContentInsets);
10452 w.mVisibleInsetsChanged =
10453 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010454 boolean configChanged =
10455 w.mConfiguration != mCurConfiguration
10456 && (w.mConfiguration == null
10457 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010458 if (DEBUG_CONFIGURATION && configChanged) {
10459 Slog.v(TAG, "Win " + w + " config changed: "
10460 + mCurConfiguration);
10461 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010462 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010463 + ": configChanged=" + configChanged
10464 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010465 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10466 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010467 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010468 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010469 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010470 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010471 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10472 Slog.v(TAG, "Resize reasons: "
10473 + "frameChanged=" + frameChanged
10474 + " contentInsetsChanged=" + w.mContentInsetsChanged
10475 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10476 + " surfaceResized=" + w.mSurfaceResized
10477 + " configChanged=" + configChanged);
10478 }
10479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 w.mLastFrame.set(w.mFrame);
10481 w.mLastContentInsets.set(w.mContentInsets);
10482 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010483 // If the screen is currently frozen, then keep
10484 // it frozen until this window draws at its new
10485 // orientation.
10486 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010487 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010488 "Resizing while display frozen: " + w);
10489 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010490 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010491 mWindowsFreezingScreen = true;
10492 // XXX should probably keep timeout from
10493 // when we first froze the display.
10494 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10495 mH.sendMessageDelayed(mH.obtainMessage(
10496 H.WINDOW_FREEZE_TIMEOUT), 2000);
10497 }
10498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 // If the orientation is changing, then we need to
10500 // hold off on unfreezing the display until this
10501 // window has been redrawn; to do that, we need
10502 // to go through the process of getting informed
10503 // by the application when it has finished drawing.
10504 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010505 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 "Orientation start waiting for draw in "
10507 + w + ", surface " + w.mSurface);
10508 w.mDrawPending = true;
10509 w.mCommitDrawPending = false;
10510 w.mReadyToShow = false;
10511 if (w.mAppToken != null) {
10512 w.mAppToken.allDrawn = false;
10513 }
10514 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010515 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 "Resizing window " + w + " to " + w.mFrame);
10517 mResizingWindows.add(w);
10518 } else if (w.mOrientationChanging) {
10519 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010520 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010521 "Orientation not waiting for draw in "
10522 + w + ", surface " + w.mSurface);
10523 w.mOrientationChanging = false;
10524 }
10525 }
10526 }
10527
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010528 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010529 if (!w.mLastHidden) {
10530 //dump();
10531 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010532 if (SHOW_TRANSACTIONS) logSurface(w,
10533 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010534 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010535 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 try {
10537 w.mSurface.hide();
10538 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010539 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010540 }
10541 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 }
10543 // If we are waiting for this window to handle an
10544 // orientation change, well, it is hidden, so
10545 // doesn't really matter. Note that this does
10546 // introduce a potential glitch if the window
10547 // becomes unhidden before it has drawn for the
10548 // new orientation.
10549 if (w.mOrientationChanging) {
10550 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010551 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010552 "Orientation change skips hidden " + w);
10553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010554 } else if (w.mLastLayer != w.mAnimLayer
10555 || w.mLastAlpha != w.mShownAlpha
10556 || w.mLastDsDx != w.mDsDx
10557 || w.mLastDtDx != w.mDtDx
10558 || w.mLastDsDy != w.mDsDy
10559 || w.mLastDtDy != w.mDtDy
10560 || w.mLastHScale != w.mHScale
10561 || w.mLastVScale != w.mVScale
10562 || w.mLastHidden) {
10563 displayed = true;
10564 w.mLastAlpha = w.mShownAlpha;
10565 w.mLastLayer = w.mAnimLayer;
10566 w.mLastDsDx = w.mDsDx;
10567 w.mLastDtDx = w.mDtDx;
10568 w.mLastDsDy = w.mDsDy;
10569 w.mLastDtDy = w.mDtDy;
10570 w.mLastHScale = w.mHScale;
10571 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010572 if (SHOW_TRANSACTIONS) logSurface(w,
10573 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010574 + " matrix=[" + (w.mDsDx*w.mHScale)
10575 + "," + (w.mDtDx*w.mVScale)
10576 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010577 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 if (w.mSurface != null) {
10579 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010580 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010581 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010582 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010583 w.mSurface.setLayer(w.mAnimLayer);
10584 w.mSurface.setMatrix(
10585 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10586 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10587 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010588 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010589 if (!recoveringMemory) {
10590 reclaimSomeSurfaceMemoryLocked(w, "update");
10591 }
10592 }
10593 }
10594
10595 if (w.mLastHidden && !w.mDrawPending
10596 && !w.mCommitDrawPending
10597 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010598 if (SHOW_TRANSACTIONS) logSurface(w,
10599 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010600 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 + " during relayout");
10602 if (showSurfaceRobustlyLocked(w)) {
10603 w.mHasDrawn = true;
10604 w.mLastHidden = false;
10605 } else {
10606 w.mOrientationChanging = false;
10607 }
10608 }
10609 if (w.mSurface != null) {
10610 w.mToken.hasVisible = true;
10611 }
10612 } else {
10613 displayed = true;
10614 }
10615
10616 if (displayed) {
10617 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010618 if (attrs.width == LayoutParams.MATCH_PARENT
10619 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010620 covered = true;
10621 }
10622 }
10623 if (w.mOrientationChanging) {
10624 if (w.mDrawPending || w.mCommitDrawPending) {
10625 orientationChangeComplete = 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 continue waiting for draw in " + w);
10628 } else {
10629 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010630 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010631 "Orientation change complete in " + w);
10632 }
10633 }
10634 w.mToken.hasVisible = true;
10635 }
10636 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010637 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010638 "Orientation change skips hidden " + w);
10639 w.mOrientationChanging = false;
10640 }
10641
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010642 if (w.mContentChanged) {
10643 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10644 w.mContentChanged = false;
10645 }
10646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 final boolean canBeSeen = w.isDisplayedLw();
10648
10649 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10650 focusDisplayed = true;
10651 }
10652
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010653 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010656 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010657 if (w.mSurface != null) {
10658 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10659 holdScreen = w.mSession;
10660 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010661 if (!syswin && w.mAttrs.screenBrightness >= 0
10662 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010663 screenBrightness = w.mAttrs.screenBrightness;
10664 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010665 if (!syswin && w.mAttrs.buttonBrightness >= 0
10666 && buttonBrightness < 0) {
10667 buttonBrightness = w.mAttrs.buttonBrightness;
10668 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010669 if (canBeSeen
10670 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10671 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10672 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010673 syswin = true;
10674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010675 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010676
Dianne Hackborn25994b42009-09-04 14:21:19 -070010677 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10678 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010679 // This window completely covers everything behind it,
10680 // so we want to leave all of them as unblurred (for
10681 // performance reasons).
10682 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010683 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010684 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010685 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010686 obscured = true;
10687 if (mBackgroundFillerSurface == null) {
10688 try {
10689 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010690 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010691 0, dw, dh,
10692 PixelFormat.OPAQUE,
10693 Surface.FX_SURFACE_NORMAL);
10694 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010695 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010696 }
10697 }
10698 try {
10699 mBackgroundFillerSurface.setPosition(0, 0);
10700 mBackgroundFillerSurface.setSize(dw, dh);
10701 // Using the same layer as Dim because they will never be shown at the
10702 // same time.
10703 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10704 mBackgroundFillerSurface.show();
10705 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010706 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010707 }
10708 backgroundFillerShown = true;
10709 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010710 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010711 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010712 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010713 + ": blurring=" + blurring
10714 + " obscured=" + obscured
10715 + " displayed=" + displayed);
10716 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10717 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010718 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010719 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010720 if (mDimAnimator == null) {
10721 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010723 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010724 mDimAnimator.updateParameters(mContext.getResources(),
10725 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010726 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010727 }
10728 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10729 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010730 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010731 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010732 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010733 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010734 + mBlurSurface + ": CREATE");
10735 try {
Romain Guy06882f82009-06-10 13:36:04 -070010736 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010737 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010738 -1, 16, 16,
10739 PixelFormat.OPAQUE,
10740 Surface.FX_SURFACE_BLUR);
10741 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010742 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010743 }
10744 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010745 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010746 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10747 + mBlurSurface + ": pos=(0,0) (" +
10748 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010749 mBlurSurface.setPosition(0, 0);
10750 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010751 mBlurSurface.setLayer(w.mAnimLayer-2);
10752 if (!mBlurShown) {
10753 try {
10754 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10755 + mBlurSurface + ": SHOW");
10756 mBlurSurface.show();
10757 } catch (RuntimeException e) {
10758 Slog.w(TAG, "Failure showing blur surface", e);
10759 }
10760 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010761 }
10762 }
10763 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010764 }
10765 }
10766 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010767
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010768 if (obscuredChanged && mWallpaperTarget == w) {
10769 // This is the wallpaper target and its obscured state
10770 // changed... make sure the current wallaper's visibility
10771 // has been updated accordingly.
10772 updateWallpaperVisibilityLocked();
10773 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010774 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010775
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010776 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10777 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010778 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010779 try {
10780 mBackgroundFillerSurface.hide();
10781 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010782 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010783 }
10784 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010785
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010786 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010787 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10788 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010789 }
Romain Guy06882f82009-06-10 13:36:04 -070010790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010791 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010792 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010793 + ": HIDE");
10794 try {
10795 mBlurSurface.hide();
10796 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010797 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010798 }
10799 mBlurShown = false;
10800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010801 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010802 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010803 }
10804
10805 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010806
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010807 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10808
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010809 if (mWatermark != null) {
10810 mWatermark.drawIfNeeded();
10811 }
10812
Joe Onorato8a9b2202010-02-26 18:56:32 -080010813 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010814 "With display frozen, orientationChangeComplete="
10815 + orientationChangeComplete);
10816 if (orientationChangeComplete) {
10817 if (mWindowsFreezingScreen) {
10818 mWindowsFreezingScreen = false;
10819 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10820 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010821 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010822 }
Romain Guy06882f82009-06-10 13:36:04 -070010823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010824 i = mResizingWindows.size();
10825 if (i > 0) {
10826 do {
10827 i--;
10828 WindowState win = mResizingWindows.get(i);
10829 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010830 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10831 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010832 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010833 boolean configChanged =
10834 win.mConfiguration != mCurConfiguration
10835 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010836 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10837 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10838 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010839 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010840 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010841 + " / " + mCurConfiguration + " / 0x"
10842 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010843 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010844 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010845 win.mClient.resized(win.mFrame.width(),
10846 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010847 win.mLastVisibleInsets, win.mDrawPending,
10848 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010849 win.mContentInsetsChanged = false;
10850 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010851 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010852 } catch (RemoteException e) {
10853 win.mOrientationChanging = false;
10854 }
10855 } while (i > 0);
10856 mResizingWindows.clear();
10857 }
Romain Guy06882f82009-06-10 13:36:04 -070010858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010859 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010860 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010861 i = mDestroySurface.size();
10862 if (i > 0) {
10863 do {
10864 i--;
10865 WindowState win = mDestroySurface.get(i);
10866 win.mDestroying = false;
10867 if (mInputMethodWindow == win) {
10868 mInputMethodWindow = null;
10869 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010870 if (win == mWallpaperTarget) {
10871 wallpaperDestroyed = true;
10872 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010873 win.destroySurfaceLocked();
10874 } while (i > 0);
10875 mDestroySurface.clear();
10876 }
10877
10878 // Time to remove any exiting tokens?
10879 for (i=mExitingTokens.size()-1; i>=0; i--) {
10880 WindowToken token = mExitingTokens.get(i);
10881 if (!token.hasVisible) {
10882 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010883 if (token.windowType == TYPE_WALLPAPER) {
10884 mWallpaperTokens.remove(token);
10885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010886 }
10887 }
10888
10889 // Time to remove any exiting applications?
10890 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10891 AppWindowToken token = mExitingAppTokens.get(i);
10892 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010893 // Make sure there is no animation running on this token,
10894 // so any windows associated with it will be removed as
10895 // soon as their animations are complete
10896 token.animation = null;
10897 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010898 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10899 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010900 mAppTokens.remove(token);
10901 mExitingAppTokens.remove(i);
10902 }
10903 }
10904
Dianne Hackborna8f60182009-09-01 19:01:50 -070010905 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010906
Dianne Hackborna8f60182009-09-01 19:01:50 -070010907 if (!animating && mAppTransitionRunning) {
10908 // We have finished the animation of an app transition. To do
10909 // this, we have delayed a lot of operations like showing and
10910 // hiding apps, moving apps in Z-order, etc. The app token list
10911 // reflects the correct Z-order, but the window list may now
10912 // be out of sync with it. So here we will just rebuild the
10913 // entire app window list. Fun!
10914 mAppTransitionRunning = false;
10915 needRelayout = true;
10916 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010917 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010918 // Clear information about apps that were moving.
10919 mToBottomApps.clear();
10920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010922 if (focusDisplayed) {
10923 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10924 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010925 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010926 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010927 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010928 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010929 requestAnimationLocked(0);
10930 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010931 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10932 }
Jeff Browneb857f12010-07-16 10:06:33 -070010933
Jeff Brown3a22cd92011-01-21 13:59:04 -080010934 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080010935 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070010936
Jeff Brown8e03b752010-06-13 19:16:55 -070010937 setHoldScreenLocked(holdScreen != null);
Dianne Hackborn428ecb62011-01-26 14:53:23 -080010938 if (!mDisplayFrozen) {
10939 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10940 mPowerManager.setScreenBrightnessOverride(-1);
10941 } else {
10942 mPowerManager.setScreenBrightnessOverride((int)
10943 (screenBrightness * Power.BRIGHTNESS_ON));
10944 }
10945 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10946 mPowerManager.setButtonBrightnessOverride(-1);
10947 } else {
10948 mPowerManager.setButtonBrightnessOverride((int)
10949 (buttonBrightness * Power.BRIGHTNESS_ON));
10950 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010952 if (holdScreen != mHoldingScreenOn) {
10953 mHoldingScreenOn = holdScreen;
10954 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10955 mH.sendMessage(m);
10956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010957
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010958 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010959 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010960 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10961 LocalPowerManager.BUTTON_EVENT, true);
10962 mTurnOnScreen = false;
10963 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010964
Dianne Hackborn89ba6752011-01-23 16:51:16 -080010965 if (updateRotation) {
10966 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
10967 boolean changed = setRotationUncheckedLocked(
10968 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
10969 if (changed) {
10970 sendNewConfiguration();
10971 }
10972 }
10973
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010974 // Check to see if we are now in a state where the screen should
10975 // be enabled, because the window obscured flags have changed.
10976 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010977 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010978
10979 /**
10980 * Must be called with the main window manager lock held.
10981 */
10982 void setHoldScreenLocked(boolean holding) {
10983 boolean state = mHoldingScreenWakeLock.isHeld();
10984 if (holding != state) {
10985 if (holding) {
10986 mHoldingScreenWakeLock.acquire();
10987 } else {
10988 mPolicy.screenOnStoppedLw();
10989 mHoldingScreenWakeLock.release();
10990 }
10991 }
10992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010993
10994 void requestAnimationLocked(long delay) {
10995 if (!mAnimationPending) {
10996 mAnimationPending = true;
10997 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10998 }
10999 }
Romain Guy06882f82009-06-10 13:36:04 -070011000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011001 /**
11002 * Have the surface flinger show a surface, robustly dealing with
11003 * error conditions. In particular, if there is not enough memory
11004 * to show the surface, then we will try to get rid of other surfaces
11005 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070011006 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011007 * @return Returns true if the surface was successfully shown.
11008 */
11009 boolean showSurfaceRobustlyLocked(WindowState win) {
11010 try {
11011 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011012 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011013 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011014 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080011015 if (DEBUG_VISIBILITY) Slog.v(TAG,
11016 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070011017 win.mTurnOnScreen = false;
11018 mTurnOnScreen = true;
11019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011020 }
11021 return true;
11022 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011023 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011024 }
Romain Guy06882f82009-06-10 13:36:04 -070011025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070011027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011028 return false;
11029 }
Romain Guy06882f82009-06-10 13:36:04 -070011030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011031 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
11032 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070011033
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011034 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011035 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070011036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011037 if (mForceRemoves == null) {
11038 mForceRemoves = new ArrayList<WindowState>();
11039 }
Romain Guy06882f82009-06-10 13:36:04 -070011040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011041 long callingIdentity = Binder.clearCallingIdentity();
11042 try {
11043 // There was some problem... first, do a sanity check of the
11044 // window list to make sure we haven't left any dangling surfaces
11045 // around.
11046 int N = mWindows.size();
11047 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011048 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011049 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011050 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011051 if (ws.mSurface != null) {
11052 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011053 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011054 + ws + " surface=" + ws.mSurface
11055 + " token=" + win.mToken
11056 + " pid=" + ws.mSession.mPid
11057 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011058 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011059 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011060 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011061 ws.mSurface = null;
11062 mForceRemoves.add(ws);
11063 i--;
11064 N--;
11065 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011066 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011067 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011068 + ws + " surface=" + ws.mSurface
11069 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011070 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011071 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011072 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011073 ws.mSurface = null;
11074 leakedSurface = true;
11075 }
11076 }
11077 }
Romain Guy06882f82009-06-10 13:36:04 -070011078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011079 boolean killedApps = false;
11080 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011081 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011082 SparseIntArray pidCandidates = new SparseIntArray();
11083 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011084 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011085 if (ws.mSurface != null) {
11086 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11087 }
11088 }
11089 if (pidCandidates.size() > 0) {
11090 int[] pids = new int[pidCandidates.size()];
11091 for (int i=0; i<pids.length; i++) {
11092 pids[i] = pidCandidates.keyAt(i);
11093 }
11094 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011095 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011096 killedApps = true;
11097 }
11098 } catch (RemoteException e) {
11099 }
11100 }
11101 }
Romain Guy06882f82009-06-10 13:36:04 -070011102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011103 if (leakedSurface || killedApps) {
11104 // We managed to reclaim some memory, so get rid of the trouble
11105 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011106 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011107 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011108 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011109 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011110 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011111 win.mSurface = null;
11112 }
Romain Guy06882f82009-06-10 13:36:04 -070011113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011114 try {
11115 win.mClient.dispatchGetNewSurface();
11116 } catch (RemoteException e) {
11117 }
11118 }
11119 } finally {
11120 Binder.restoreCallingIdentity(callingIdentity);
11121 }
11122 }
Romain Guy06882f82009-06-10 13:36:04 -070011123
Jeff Brown3a22cd92011-01-21 13:59:04 -080011124 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011125 WindowState newFocus = computeFocusedWindowLocked();
11126 if (mCurrentFocus != newFocus) {
11127 // This check makes sure that we don't already have the focus
11128 // change message pending.
11129 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11130 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011131 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011132 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11133 final WindowState oldFocus = mCurrentFocus;
11134 mCurrentFocus = newFocus;
11135 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011137 final WindowState imWindow = mInputMethodWindow;
11138 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011139 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011140 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011141 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11142 mLayoutNeeded = true;
11143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011144 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011145 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011146 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11147 // Client will do the layout, but we need to assign layers
11148 // for handleNewWindowLocked() below.
11149 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011150 }
11151 }
Jeff Brown349703e2010-06-22 01:27:15 -070011152
11153 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11154 // If we defer assigning layers, then the caller is responsible for
11155 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011156 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011158 return true;
11159 }
11160 return false;
11161 }
Jeff Brown349703e2010-06-22 01:27:15 -070011162
Jeff Brown3a22cd92011-01-21 13:59:04 -080011163 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11164 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011166
11167 private WindowState computeFocusedWindowLocked() {
11168 WindowState result = null;
11169 WindowState win;
11170
11171 int i = mWindows.size() - 1;
11172 int nextAppIndex = mAppTokens.size()-1;
11173 WindowToken nextApp = nextAppIndex >= 0
11174 ? mAppTokens.get(nextAppIndex) : null;
11175
11176 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011177 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011178
Joe Onorato8a9b2202010-02-26 18:56:32 -080011179 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011180 TAG, "Looking for focus: " + i
11181 + " = " + win
11182 + ", flags=" + win.mAttrs.flags
11183 + ", canReceive=" + win.canReceiveKeys());
11184
11185 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011187 // If this window's application has been removed, just skip it.
11188 if (thisApp != null && thisApp.removed) {
11189 i--;
11190 continue;
11191 }
Romain Guy06882f82009-06-10 13:36:04 -070011192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011193 // If there is a focused app, don't allow focus to go to any
11194 // windows below it. If this is an application window, step
11195 // through the app tokens until we find its app.
11196 if (thisApp != null && nextApp != null && thisApp != nextApp
11197 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11198 int origAppIndex = nextAppIndex;
11199 while (nextAppIndex > 0) {
11200 if (nextApp == mFocusedApp) {
11201 // Whoops, we are below the focused app... no focus
11202 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011203 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011204 TAG, "Reached focused app: " + mFocusedApp);
11205 return null;
11206 }
11207 nextAppIndex--;
11208 nextApp = mAppTokens.get(nextAppIndex);
11209 if (nextApp == thisApp) {
11210 break;
11211 }
11212 }
11213 if (thisApp != nextApp) {
11214 // Uh oh, the app token doesn't exist! This shouldn't
11215 // happen, but if it does we can get totally hosed...
11216 // so restart at the original app.
11217 nextAppIndex = origAppIndex;
11218 nextApp = mAppTokens.get(nextAppIndex);
11219 }
11220 }
11221
11222 // Dispatch to this window if it is wants key events.
11223 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011224 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011225 TAG, "Found focus @ " + i + " = " + win);
11226 result = win;
11227 break;
11228 }
11229
11230 i--;
11231 }
11232
11233 return result;
11234 }
11235
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011236 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011237 if (mDisplayFrozen) {
11238 return;
11239 }
Romain Guy06882f82009-06-10 13:36:04 -070011240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011241 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011243 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011244 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011245 if (mFreezeGcPending != 0) {
11246 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011247 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011248 mH.removeMessages(H.FORCE_GC);
11249 Runtime.getRuntime().gc();
11250 mFreezeGcPending = now;
11251 }
11252 } else {
11253 mFreezeGcPending = now;
11254 }
Romain Guy06882f82009-06-10 13:36:04 -070011255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011256 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011257
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011258 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011259
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011260 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11261 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011262 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011263 mAppTransitionReady = true;
11264 }
Romain Guy06882f82009-06-10 13:36:04 -070011265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011266 if (PROFILE_ORIENTATION) {
11267 File file = new File("/data/system/frozen");
11268 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11269 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011270
11271 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011272 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11273 mScreenRotationAnimation.kill();
11274 mScreenRotationAnimation = null;
11275 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011276 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011277 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011278 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011279 }
11280 } else {
11281 Surface.freezeDisplay(0);
11282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011283 }
Romain Guy06882f82009-06-10 13:36:04 -070011284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011285 private void stopFreezingDisplayLocked() {
11286 if (!mDisplayFrozen) {
11287 return;
11288 }
Romain Guy06882f82009-06-10 13:36:04 -070011289
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011290 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11291 return;
11292 }
11293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011294 mDisplayFrozen = false;
11295 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11296 if (PROFILE_ORIENTATION) {
11297 Debug.stopMethodTracing();
11298 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011299
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011300 boolean updateRotation = false;
11301
Dianne Hackborna1111872010-11-23 20:55:11 -080011302 if (CUSTOM_SCREEN_ROTATION) {
11303 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011304 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11305 mTransitionAnimationScale)) {
11306 requestAnimationLocked(0);
11307 } else {
11308 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011309 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011310 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011311 }
11312 } else {
11313 Surface.unfreezeDisplay(0);
11314 }
Romain Guy06882f82009-06-10 13:36:04 -070011315
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011316 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011317
Christopher Tateb696aee2010-04-02 19:08:30 -070011318 // While the display is frozen we don't re-compute the orientation
11319 // to avoid inconsistent states. However, something interesting
11320 // could have actually changed during that time so re-evaluate it
11321 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011322 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011323 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11324 }
11325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011326 // A little kludge: a lot could have happened while the
11327 // display was frozen, so now that we are coming back we
11328 // do a gc so that any remote references the system
11329 // processes holds on others can be released if they are
11330 // no longer needed.
11331 mH.removeMessages(H.FORCE_GC);
11332 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11333 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011335 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011336
11337 if (updateRotation) {
11338 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11339 boolean changed = setRotationUncheckedLocked(
11340 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11341 if (changed) {
11342 sendNewConfiguration();
11343 }
11344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011345 }
Romain Guy06882f82009-06-10 13:36:04 -070011346
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011347 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11348 DisplayMetrics dm) {
11349 if (index < tokens.length) {
11350 String str = tokens[index];
11351 if (str != null && str.length() > 0) {
11352 try {
11353 int val = Integer.parseInt(str);
11354 return val;
11355 } catch (Exception e) {
11356 }
11357 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011358 }
11359 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11360 return defDps;
11361 }
11362 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11363 return val;
11364 }
11365
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011366 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011367 final String[] mTokens;
11368 final String mText;
11369 final Paint mTextPaint;
11370 final int mTextWidth;
11371 final int mTextHeight;
11372 final int mTextAscent;
11373 final int mTextDescent;
11374 final int mDeltaX;
11375 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011376
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011377 Surface mSurface;
11378 int mLastDW;
11379 int mLastDH;
11380 boolean mDrawNeeded;
11381
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011382 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011383 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011384 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011385
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011386 if (false) {
11387 Log.i(TAG, "*********************** WATERMARK");
11388 for (int i=0; i<tokens.length; i++) {
11389 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11390 }
11391 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011392
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011393 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011394
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011395 StringBuilder builder = new StringBuilder(32);
11396 int len = mTokens[0].length();
11397 len = len & ~1;
11398 for (int i=0; i<len; i+=2) {
11399 int c1 = mTokens[0].charAt(i);
11400 int c2 = mTokens[0].charAt(i+1);
11401 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11402 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11403 else c1 -= '0';
11404 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11405 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11406 else c2 -= '0';
11407 builder.append((char)(255-((c1*16)+c2)));
11408 }
11409 mText = builder.toString();
11410 if (false) {
11411 Log.i(TAG, "Final text: " + mText);
11412 }
11413
11414 int fontSize = getPropertyInt(tokens, 1,
11415 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11416
11417 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11418 mTextPaint.setTextSize(fontSize);
11419 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11420
11421 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11422 mTextWidth = (int)mTextPaint.measureText(mText);
11423 mTextAscent = fm.ascent;
11424 mTextDescent = fm.descent;
11425 mTextHeight = fm.descent - fm.ascent;
11426
11427 mDeltaX = getPropertyInt(tokens, 2,
11428 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11429 mDeltaY = getPropertyInt(tokens, 3,
11430 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11431 int shadowColor = getPropertyInt(tokens, 4,
11432 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11433 int color = getPropertyInt(tokens, 5,
11434 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11435 int shadowRadius = getPropertyInt(tokens, 6,
11436 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11437 int shadowDx = getPropertyInt(tokens, 8,
11438 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11439 int shadowDy = getPropertyInt(tokens, 9,
11440 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11441
11442 mTextPaint.setColor(color);
11443 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011444
11445 try {
11446 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011447 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011448 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011449 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011450 mSurface.show();
11451 } catch (OutOfResourcesException e) {
11452 }
11453 }
11454
11455 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011456 if (mLastDW != dw || mLastDH != dh) {
11457 mLastDW = dw;
11458 mLastDH = dh;
11459 mSurface.setSize(dw, dh);
11460 mDrawNeeded = true;
11461 }
11462 }
11463
11464 void drawIfNeeded() {
11465 if (mDrawNeeded) {
11466 final int dw = mLastDW;
11467 final int dh = mLastDH;
11468
11469 mDrawNeeded = false;
11470 Rect dirty = new Rect(0, 0, dw, dh);
11471 Canvas c = null;
11472 try {
11473 c = mSurface.lockCanvas(dirty);
11474 } catch (IllegalArgumentException e) {
11475 } catch (OutOfResourcesException e) {
11476 }
11477 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011478 c.drawColor(0, PorterDuff.Mode.CLEAR);
11479
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011480 int deltaX = mDeltaX;
11481 int deltaY = mDeltaY;
11482
11483 // deltaX shouldn't be close to a round fraction of our
11484 // x step, or else things will line up too much.
11485 int div = (dw+mTextWidth)/deltaX;
11486 int rem = (dw+mTextWidth) - (div*deltaX);
11487 int qdelta = deltaX/4;
11488 if (rem < qdelta || rem > (deltaX-qdelta)) {
11489 deltaX += deltaX/3;
11490 }
11491
11492 int y = -mTextHeight;
11493 int x = -mTextWidth;
11494 while (y < (dh+mTextHeight)) {
11495 c.drawText(mText, x, y, mTextPaint);
11496 x += deltaX;
11497 if (x >= dw) {
11498 x -= (dw+mTextWidth);
11499 y += deltaY;
11500 }
11501 }
11502 mSurface.unlockCanvasAndPost(c);
11503 }
11504 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011505 }
11506 }
11507
11508 void createWatermark() {
11509 if (mWatermark != null) {
11510 return;
11511 }
11512
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011513 File file = new File("/system/etc/setup.conf");
11514 FileInputStream in = null;
11515 try {
11516 in = new FileInputStream(file);
11517 DataInputStream ind = new DataInputStream(in);
11518 String line = ind.readLine();
11519 if (line != null) {
11520 String[] toks = line.split("%");
11521 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011522 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011523 }
11524 }
11525 } catch (FileNotFoundException e) {
11526 } catch (IOException e) {
11527 } finally {
11528 if (in != null) {
11529 try {
11530 in.close();
11531 } catch (IOException e) {
11532 }
11533 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011534 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011535 }
11536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011537 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011538 public void statusBarVisibilityChanged(int visibility) {
11539 synchronized (mWindowMap) {
11540 final int N = mWindows.size();
11541 for (int i = 0; i < N; i++) {
11542 WindowState ws = mWindows.get(i);
11543 try {
11544 if (ws.getAttrs().hasSystemUiListeners) {
11545 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11546 }
11547 } catch (RemoteException e) {
11548 // so sorry
11549 }
11550 }
11551 }
11552 }
11553
11554 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011555 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11556 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11557 != PackageManager.PERMISSION_GRANTED) {
11558 pw.println("Permission Denial: can't dump WindowManager from from pid="
11559 + Binder.getCallingPid()
11560 + ", uid=" + Binder.getCallingUid());
11561 return;
11562 }
Romain Guy06882f82009-06-10 13:36:04 -070011563
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011564 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011565 pw.println(" ");
11566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011567 synchronized(mWindowMap) {
11568 pw.println("Current Window Manager state:");
11569 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011570 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011571 pw.print(" Window #"); pw.print(i); pw.print(' ');
11572 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011573 w.dump(pw, " ");
11574 }
11575 if (mInputMethodDialogs.size() > 0) {
11576 pw.println(" ");
11577 pw.println(" Input method dialogs:");
11578 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11579 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011580 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011581 }
11582 }
11583 if (mPendingRemove.size() > 0) {
11584 pw.println(" ");
11585 pw.println(" Remove pending for:");
11586 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11587 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011588 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11589 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011590 w.dump(pw, " ");
11591 }
11592 }
11593 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11594 pw.println(" ");
11595 pw.println(" Windows force removing:");
11596 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11597 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011598 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11599 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011600 w.dump(pw, " ");
11601 }
11602 }
11603 if (mDestroySurface.size() > 0) {
11604 pw.println(" ");
11605 pw.println(" Windows waiting to destroy their surface:");
11606 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11607 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011608 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11609 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011610 w.dump(pw, " ");
11611 }
11612 }
11613 if (mLosingFocus.size() > 0) {
11614 pw.println(" ");
11615 pw.println(" Windows losing focus:");
11616 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11617 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011618 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11619 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011620 w.dump(pw, " ");
11621 }
11622 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011623 if (mResizingWindows.size() > 0) {
11624 pw.println(" ");
11625 pw.println(" Windows waiting to resize:");
11626 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11627 WindowState w = mResizingWindows.get(i);
11628 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11629 pw.print(w); pw.println(":");
11630 w.dump(pw, " ");
11631 }
11632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011633 if (mSessions.size() > 0) {
11634 pw.println(" ");
11635 pw.println(" All active sessions:");
11636 Iterator<Session> it = mSessions.iterator();
11637 while (it.hasNext()) {
11638 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011639 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011640 s.dump(pw, " ");
11641 }
11642 }
11643 if (mTokenMap.size() > 0) {
11644 pw.println(" ");
11645 pw.println(" All tokens:");
11646 Iterator<WindowToken> it = mTokenMap.values().iterator();
11647 while (it.hasNext()) {
11648 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011649 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011650 token.dump(pw, " ");
11651 }
11652 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011653 if (mWallpaperTokens.size() > 0) {
11654 pw.println(" ");
11655 pw.println(" Wallpaper tokens:");
11656 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11657 WindowToken token = mWallpaperTokens.get(i);
11658 pw.print(" Wallpaper #"); pw.print(i);
11659 pw.print(' '); pw.print(token); pw.println(':');
11660 token.dump(pw, " ");
11661 }
11662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011663 if (mAppTokens.size() > 0) {
11664 pw.println(" ");
11665 pw.println(" Application tokens in Z order:");
11666 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011667 pw.print(" App #"); pw.print(i); pw.print(": ");
11668 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011669 }
11670 }
11671 if (mFinishedStarting.size() > 0) {
11672 pw.println(" ");
11673 pw.println(" Finishing start of application tokens:");
11674 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11675 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011676 pw.print(" Finished Starting #"); pw.print(i);
11677 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011678 token.dump(pw, " ");
11679 }
11680 }
11681 if (mExitingTokens.size() > 0) {
11682 pw.println(" ");
11683 pw.println(" Exiting tokens:");
11684 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11685 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011686 pw.print(" Exiting #"); pw.print(i);
11687 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011688 token.dump(pw, " ");
11689 }
11690 }
11691 if (mExitingAppTokens.size() > 0) {
11692 pw.println(" ");
11693 pw.println(" Exiting application tokens:");
11694 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11695 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011696 pw.print(" Exiting App #"); pw.print(i);
11697 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011698 token.dump(pw, " ");
11699 }
11700 }
11701 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011702 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11703 pw.print(" mLastFocus="); pw.println(mLastFocus);
11704 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11705 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11706 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011707 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011708 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11709 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11710 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11711 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011712 if (mWindowDetachedWallpaper != null) {
11713 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11714 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011715 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11716 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11717 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011718 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11719 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11720 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11721 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011722 if (mDimAnimator != null) {
11723 mDimAnimator.printTo(pw);
11724 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011725 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011726 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011727 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011728 pw.print(mInputMethodAnimLayerAdjustment);
11729 pw.print(" mWallpaperAnimLayerAdjustment=");
11730 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011731 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11732 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011733 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11734 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011735 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11736 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011737 pw.print(" mRotation="); pw.print(mRotation);
11738 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11739 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011740 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11741 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011742 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11743 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11744 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11745 pw.print(" mNextAppTransition=0x");
11746 pw.print(Integer.toHexString(mNextAppTransition));
11747 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011748 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011749 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011750 if (mNextAppTransitionPackage != null) {
11751 pw.print(" mNextAppTransitionPackage=");
11752 pw.print(mNextAppTransitionPackage);
11753 pw.print(", mNextAppTransitionEnter=0x");
11754 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11755 pw.print(", mNextAppTransitionExit=0x");
11756 pw.print(Integer.toHexString(mNextAppTransitionExit));
11757 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011758 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11759 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11760 if (mOpeningApps.size() > 0) {
11761 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11762 }
11763 if (mClosingApps.size() > 0) {
11764 pw.print(" mClosingApps="); pw.println(mClosingApps);
11765 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011766 if (mToTopApps.size() > 0) {
11767 pw.print(" mToTopApps="); pw.println(mToTopApps);
11768 }
11769 if (mToBottomApps.size() > 0) {
11770 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11771 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011772 if (mDisplay != null) {
11773 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11774 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11775 } else {
11776 pw.println(" NO DISPLAY");
11777 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011778 pw.println(" Policy:");
11779 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011780 }
11781 }
11782
Jeff Brown349703e2010-06-22 01:27:15 -070011783 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011784 public void monitor() {
11785 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011786 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011787 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011788
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011789 /**
11790 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011791 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011792 */
11793 private static class DimAnimator {
11794 Surface mDimSurface;
11795 boolean mDimShown = false;
11796 float mDimCurrentAlpha;
11797 float mDimTargetAlpha;
11798 float mDimDeltaPerMs;
11799 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011800
11801 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011802
11803 DimAnimator (SurfaceSession session) {
11804 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011805 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011806 + mDimSurface + ": CREATE");
11807 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011808 mDimSurface = new Surface(session, 0,
11809 "DimSurface",
11810 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011811 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011812 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011813 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011814 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011815 }
11816 }
11817 }
11818
11819 /**
11820 * Show the dim surface.
11821 */
11822 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011823 if (!mDimShown) {
11824 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11825 dw + "x" + dh + ")");
11826 mDimShown = true;
11827 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011828 mLastDimWidth = dw;
11829 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011830 mDimSurface.setPosition(0, 0);
11831 mDimSurface.setSize(dw, dh);
11832 mDimSurface.show();
11833 } catch (RuntimeException e) {
11834 Slog.w(TAG, "Failure showing dim surface", e);
11835 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011836 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11837 mLastDimWidth = dw;
11838 mLastDimHeight = dh;
11839 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011840 }
11841 }
11842
11843 /**
11844 * Set's the dim surface's layer and update dim parameters that will be used in
11845 * {@link updateSurface} after all windows are examined.
11846 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011847 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011848 mDimSurface.setLayer(w.mAnimLayer-1);
11849
11850 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011851 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011852 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011853 if (mDimTargetAlpha != target) {
11854 // If the desired dim level has changed, then
11855 // start an animation to it.
11856 mLastDimAnimTime = currentTime;
11857 long duration = (w.mAnimating && w.mAnimation != null)
11858 ? w.mAnimation.computeDurationHint()
11859 : DEFAULT_DIM_DURATION;
11860 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011861 TypedValue tv = new TypedValue();
11862 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11863 tv, true);
11864 if (tv.type == TypedValue.TYPE_FRACTION) {
11865 duration = (long)tv.getFraction((float)duration, (float)duration);
11866 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11867 && tv.type <= TypedValue.TYPE_LAST_INT) {
11868 duration = tv.data;
11869 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011870 }
11871 if (duration < 1) {
11872 // Don't divide by zero
11873 duration = 1;
11874 }
11875 mDimTargetAlpha = target;
11876 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11877 }
11878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011879
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011880 /**
11881 * Updating the surface's alpha. Returns true if the animation continues, or returns
11882 * false when the animation is finished and the dim surface is hidden.
11883 */
11884 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11885 if (!dimming) {
11886 if (mDimTargetAlpha != 0) {
11887 mLastDimAnimTime = currentTime;
11888 mDimTargetAlpha = 0;
11889 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11890 }
11891 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011892
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011893 boolean animating = false;
11894 if (mLastDimAnimTime != 0) {
11895 mDimCurrentAlpha += mDimDeltaPerMs
11896 * (currentTime-mLastDimAnimTime);
11897 boolean more = true;
11898 if (displayFrozen) {
11899 // If the display is frozen, there is no reason to animate.
11900 more = false;
11901 } else if (mDimDeltaPerMs > 0) {
11902 if (mDimCurrentAlpha > mDimTargetAlpha) {
11903 more = false;
11904 }
11905 } else if (mDimDeltaPerMs < 0) {
11906 if (mDimCurrentAlpha < mDimTargetAlpha) {
11907 more = false;
11908 }
11909 } else {
11910 more = false;
11911 }
11912
11913 // Do we need to continue animating?
11914 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011915 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011916 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11917 mLastDimAnimTime = currentTime;
11918 mDimSurface.setAlpha(mDimCurrentAlpha);
11919 animating = true;
11920 } else {
11921 mDimCurrentAlpha = mDimTargetAlpha;
11922 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011923 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011924 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11925 mDimSurface.setAlpha(mDimCurrentAlpha);
11926 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011927 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011928 + ": HIDE");
11929 try {
11930 mDimSurface.hide();
11931 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011932 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011933 }
11934 mDimShown = false;
11935 }
11936 }
11937 }
11938 return animating;
11939 }
11940
11941 public void printTo(PrintWriter pw) {
11942 pw.print(" mDimShown="); pw.print(mDimShown);
11943 pw.print(" current="); pw.print(mDimCurrentAlpha);
11944 pw.print(" target="); pw.print(mDimTargetAlpha);
11945 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11946 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11947 }
11948 }
11949
11950 /**
11951 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11952 * This is used for opening/closing transition for apps in compatible mode.
11953 */
11954 private static class FadeInOutAnimation extends Animation {
11955 int mWidth;
11956 boolean mFadeIn;
11957
11958 public FadeInOutAnimation(boolean fadeIn) {
11959 setInterpolator(new AccelerateInterpolator());
11960 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11961 mFadeIn = fadeIn;
11962 }
11963
11964 @Override
11965 protected void applyTransformation(float interpolatedTime, Transformation t) {
11966 float x = interpolatedTime;
11967 if (!mFadeIn) {
11968 x = 1.0f - x; // reverse the interpolation for fade out
11969 }
11970 if (x < 0.5) {
11971 // move the window out of the screen.
11972 t.getMatrix().setTranslate(mWidth, 0);
11973 } else {
11974 t.getMatrix().setTranslate(0, 0);// show
11975 t.setAlpha((x - 0.5f) * 2);
11976 }
11977 }
11978
11979 @Override
11980 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11981 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11982 mWidth = width;
11983 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011984
11985 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011986 public int getZAdjustment() {
11987 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011988 }
11989 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011990}