blob: 2c8403c82751d68220040f5347d913b0cab2e1e3 [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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-10-19 15:15:08 -0700670 mNotifiedWindows.clear();
671 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700672 evt.recycle();
673 }
674
Chris Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Brown46b9ac02010-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);
1318 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1319 return w.isVisibleOrAdding();
1320 }
1321 return false;
1322 }
Romain Guy06882f82009-06-10 13:36:04 -07001323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001324 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001325 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 final int N = localmWindows.size();
1327 WindowState w = null;
1328 int i = N;
1329 while (i > 0) {
1330 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001331 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001332
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 // + Integer.toHexString(w.mAttrs.flags));
1335 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001336 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001338 // Yet more tricksyness! If this window is a "starting"
1339 // window, we do actually want to be on top of it, but
1340 // it is not -really- where input will go. So if the caller
1341 // is not actually looking to move the IME, look down below
1342 // for a real window to target...
1343 if (!willMove
1344 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1345 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001346 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1348 i--;
1349 w = wb;
1350 }
1351 }
1352 break;
1353 }
1354 }
Romain Guy06882f82009-06-10 13:36:04 -07001355
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001356 // Now, a special case -- if the last target's window is in the
1357 // process of exiting, and is above the new target, keep on the
1358 // last target to avoid flicker. Consider for example a Dialog with
1359 // the IME shown: when the Dialog is dismissed, we want to keep
1360 // the IME above it until it is completely gone so it doesn't drop
1361 // behind the dialog or its full-screen scrim.
1362 if (mInputMethodTarget != null && w != null
1363 && mInputMethodTarget.isDisplayedLw()
1364 && mInputMethodTarget.mExiting) {
1365 if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) {
1366 w = mInputMethodTarget;
1367 i = localmWindows.indexOf(w);
1368 }
1369 }
Romain Guy06882f82009-06-10 13:36:04 -07001370
Joe Onorato8a9b2202010-02-26 18:56:32 -08001371 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 if (willMove && w != null) {
1375 final WindowState curTarget = mInputMethodTarget;
1376 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 // Now some fun for dealing with window animations that
1379 // modify the Z order. We need to look at all windows below
1380 // the current target that are in this app, finding the highest
1381 // visible one in layering.
1382 AppWindowToken token = curTarget.mAppToken;
1383 WindowState highestTarget = null;
1384 int highestPos = 0;
1385 if (token.animating || token.animation != null) {
1386 int pos = 0;
1387 pos = localmWindows.indexOf(curTarget);
1388 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001389 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 if (win.mAppToken != token) {
1391 break;
1392 }
1393 if (!win.mRemoved) {
1394 if (highestTarget == null || win.mAnimLayer >
1395 highestTarget.mAnimLayer) {
1396 highestTarget = win;
1397 highestPos = pos;
1398 }
1399 }
1400 pos--;
1401 }
1402 }
Romain Guy06882f82009-06-10 13:36:04 -07001403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 + mNextAppTransition + " " + highestTarget
1407 + " animating=" + highestTarget.isAnimating()
1408 + " layer=" + highestTarget.mAnimLayer
1409 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001410
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001411 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 // If we are currently setting up for an animation,
1413 // hold everything until we can find out what will happen.
1414 mInputMethodTargetWaitingAnim = true;
1415 mInputMethodTarget = highestTarget;
1416 return highestPos + 1;
1417 } else if (highestTarget.isAnimating() &&
1418 highestTarget.mAnimLayer > w.mAnimLayer) {
1419 // If the window we are currently targeting is involved
1420 // with an animation, and it is on top of the next target
1421 // we will be over, then hold off on moving until
1422 // that is done.
1423 mInputMethodTarget = highestTarget;
1424 return highestPos + 1;
1425 }
1426 }
1427 }
1428 }
Romain Guy06882f82009-06-10 13:36:04 -07001429
Joe Onorato8a9b2202010-02-26 18:56:32 -08001430 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 if (w != null) {
1432 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001433 if (DEBUG_INPUT_METHOD) {
1434 RuntimeException e = null;
1435 if (!HIDE_STACK_CRAWLS) {
1436 e = new RuntimeException();
1437 e.fillInStackTrace();
1438 }
1439 Slog.w(TAG, "Moving IM target from "
1440 + mInputMethodTarget + " to " + w, e);
1441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 mInputMethodTarget = w;
1443 if (w.mAppToken != null) {
1444 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1445 } else {
1446 setInputMethodAnimLayerAdjustment(0);
1447 }
1448 }
1449 return i+1;
1450 }
1451 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001452 if (DEBUG_INPUT_METHOD) {
1453 RuntimeException e = null;
1454 if (!HIDE_STACK_CRAWLS) {
1455 e = new RuntimeException();
1456 e.fillInStackTrace();
1457 }
1458 Slog.w(TAG, "Moving IM target from "
1459 + mInputMethodTarget + " to null", e);
1460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 mInputMethodTarget = null;
1462 setInputMethodAnimLayerAdjustment(0);
1463 }
1464 return -1;
1465 }
Romain Guy06882f82009-06-10 13:36:04 -07001466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 void addInputMethodWindowToListLocked(WindowState win) {
1468 int pos = findDesiredInputMethodWindowIndexLocked(true);
1469 if (pos >= 0) {
1470 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08001471 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001472 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001474 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 moveInputMethodDialogsLocked(pos+1);
1476 return;
1477 }
1478 win.mTargetAppToken = null;
1479 addWindowToListInOrderLocked(win, true);
1480 moveInputMethodDialogsLocked(pos);
1481 }
Romain Guy06882f82009-06-10 13:36:04 -07001482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001484 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 mInputMethodAnimLayerAdjustment = adj;
1486 WindowState imw = mInputMethodWindow;
1487 if (imw != null) {
1488 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001489 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 + " anim layer: " + imw.mAnimLayer);
1491 int wi = imw.mChildWindows.size();
1492 while (wi > 0) {
1493 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001494 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001496 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 + " anim layer: " + cw.mAnimLayer);
1498 }
1499 }
1500 int di = mInputMethodDialogs.size();
1501 while (di > 0) {
1502 di --;
1503 imw = mInputMethodDialogs.get(di);
1504 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001505 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 + " anim layer: " + imw.mAnimLayer);
1507 }
1508 }
Romain Guy06882f82009-06-10 13:36:04 -07001509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1511 int wpos = mWindows.indexOf(win);
1512 if (wpos >= 0) {
1513 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001514 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001516 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 int NC = win.mChildWindows.size();
1518 while (NC > 0) {
1519 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001520 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 int cpos = mWindows.indexOf(cw);
1522 if (cpos >= 0) {
1523 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001524 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001525 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 mWindows.remove(cpos);
1527 }
1528 }
1529 }
1530 return interestingPos;
1531 }
Romain Guy06882f82009-06-10 13:36:04 -07001532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 private void reAddWindowToListInOrderLocked(WindowState win) {
1534 addWindowToListInOrderLocked(win, false);
1535 // This is a hack to get all of the child windows added as well
1536 // at the right position. Child windows should be rare and
1537 // this case should be rare, so it shouldn't be that big a deal.
1538 int wpos = mWindows.indexOf(win);
1539 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001540 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001541 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001543 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 reAddWindowLocked(wpos, win);
1545 }
1546 }
Romain Guy06882f82009-06-10 13:36:04 -07001547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 void logWindowList(String prefix) {
1549 int N = mWindows.size();
1550 while (N > 0) {
1551 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001552 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 }
1554 }
Romain Guy06882f82009-06-10 13:36:04 -07001555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 void moveInputMethodDialogsLocked(int pos) {
1557 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 for (int i=0; i<N; i++) {
1562 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1563 }
1564 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001565 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 logWindowList(" ");
1567 }
Romain Guy06882f82009-06-10 13:36:04 -07001568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 if (pos >= 0) {
1570 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1571 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001572 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 if (wp == mInputMethodWindow) {
1574 pos++;
1575 }
1576 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 for (int i=0; i<N; i++) {
1579 WindowState win = dialogs.get(i);
1580 win.mTargetAppToken = targetAppToken;
1581 pos = reAddWindowLocked(pos, win);
1582 }
1583 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 logWindowList(" ");
1586 }
1587 return;
1588 }
1589 for (int i=0; i<N; i++) {
1590 WindowState win = dialogs.get(i);
1591 win.mTargetAppToken = null;
1592 reAddWindowToListInOrderLocked(win);
1593 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001594 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 logWindowList(" ");
1596 }
1597 }
1598 }
Romain Guy06882f82009-06-10 13:36:04 -07001599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1601 final WindowState imWin = mInputMethodWindow;
1602 final int DN = mInputMethodDialogs.size();
1603 if (imWin == null && DN == 0) {
1604 return false;
1605 }
Romain Guy06882f82009-06-10 13:36:04 -07001606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1608 if (imPos >= 0) {
1609 // In this case, the input method windows are to be placed
1610 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 // First check to see if the input method windows are already
1613 // located here, and contiguous.
1614 final int N = mWindows.size();
1615 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001616 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 // Figure out the actual input method window that should be
1619 // at the bottom of their stack.
1620 WindowState baseImWin = imWin != null
1621 ? imWin : mInputMethodDialogs.get(0);
1622 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001623 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 if (cw.mSubLayer < 0) baseImWin = cw;
1625 }
Romain Guy06882f82009-06-10 13:36:04 -07001626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 if (firstImWin == baseImWin) {
1628 // The windows haven't moved... but are they still contiguous?
1629 // First find the top IM window.
1630 int pos = imPos+1;
1631 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001632 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 break;
1634 }
1635 pos++;
1636 }
1637 pos++;
1638 // Now there should be no more input method windows above.
1639 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001640 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 break;
1642 }
1643 pos++;
1644 }
1645 if (pos >= N) {
1646 // All is good!
1647 return false;
1648 }
1649 }
Romain Guy06882f82009-06-10 13:36:04 -07001650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 if (imWin != null) {
1652 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001653 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 logWindowList(" ");
1655 }
1656 imPos = tmpRemoveWindowLocked(imPos, imWin);
1657 if (DEBUG_INPUT_METHOD) {
Dianne Hackborn7eab0942011-01-01 13:21:50 -08001658 Slog.v(TAG, "List after removing with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 logWindowList(" ");
1660 }
1661 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1662 reAddWindowLocked(imPos, imWin);
1663 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001664 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 logWindowList(" ");
1666 }
1667 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1668 } else {
1669 moveInputMethodDialogsLocked(imPos);
1670 }
Romain Guy06882f82009-06-10 13:36:04 -07001671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 } else {
1673 // In this case, the input method windows go in a fixed layer,
1674 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 tmpRemoveWindowLocked(0, imWin);
1679 imWin.mTargetAppToken = null;
1680 reAddWindowToListInOrderLocked(imWin);
1681 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 logWindowList(" ");
1684 }
1685 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1686 } else {
1687 moveInputMethodDialogsLocked(-1);;
1688 }
Romain Guy06882f82009-06-10 13:36:04 -07001689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 }
Romain Guy06882f82009-06-10 13:36:04 -07001691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 if (needAssignLayers) {
1693 assignLayersLocked();
1694 }
Romain Guy06882f82009-06-10 13:36:04 -07001695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696 return true;
1697 }
Romain Guy06882f82009-06-10 13:36:04 -07001698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 void adjustInputMethodDialogsLocked() {
1700 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1701 }
Romain Guy06882f82009-06-10 13:36:04 -07001702
Dianne Hackborn25994b42009-09-04 14:21:19 -07001703 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001704 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001705 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1706 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1707 ? wallpaperTarget.mAppToken.animation : null)
1708 + " upper=" + mUpperWallpaperTarget
1709 + " lower=" + mLowerWallpaperTarget);
1710 return (wallpaperTarget != null
1711 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1712 && wallpaperTarget.mAppToken.animation != null)))
1713 || mUpperWallpaperTarget != null
1714 || mLowerWallpaperTarget != null;
1715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001716
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001717 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1718 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001719
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001720 int adjustWallpaperWindowsLocked() {
1721 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001723 final int dw = mDisplay.getWidth();
1724 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001725
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001726 // First find top-most window that has asked to be on top of the
1727 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001728 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001729 int N = localmWindows.size();
1730 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001731 WindowState foundW = null;
1732 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001733 WindowState topCurW = null;
1734 int topCurI = 0;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001735 int windowDetachedI = -1;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001736 int i = N;
1737 while (i > 0) {
1738 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001739 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001740 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1741 if (topCurW == null) {
1742 topCurW = w;
1743 topCurI = i;
1744 }
1745 continue;
1746 }
1747 topCurW = null;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001748 if (w != mWindowDetachedWallpaper && w.mAppToken != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001749 // If this window's app token is hidden and not animating,
1750 // it is of no interest to us.
1751 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001752 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001753 "Skipping not hidden or animating token: " + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001754 continue;
1755 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001756 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001757 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001758 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1759 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001760 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001761 && (mWallpaperTarget == w
1762 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001763 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001764 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001765 foundW = w;
1766 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001767 if (w == mWallpaperTarget && ((w.mAppToken != null
1768 && w.mAppToken.animation != null)
1769 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 // The current wallpaper target is animating, so we'll
1771 // look behind it for another possible target and figure
1772 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001773 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001774 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001775 continue;
1776 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001777 break;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001778 } else if (w == mWindowDetachedWallpaper) {
1779 windowDetachedI = i;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001780 }
1781 }
1782
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08001783 if (foundW == null && windowDetachedI >= 0) {
1784 if (DEBUG_WALLPAPER) Slog.v(TAG,
1785 "Found animating detached wallpaper activity: #" + i + "=" + w);
1786 foundW = w;
1787 foundI = windowDetachedI;
1788 }
1789
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001790 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001791 // If we are currently waiting for an app transition, and either
1792 // the current target or the next target are involved with it,
1793 // then hold off on doing anything with the wallpaper.
1794 // Note that we are checking here for just whether the target
1795 // is part of an app token... which is potentially overly aggressive
1796 // (the app token may not be involved in the transition), but good
1797 // enough (we'll just wait until whatever transition is pending
1798 // executes).
1799 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001802 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001803 }
1804 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001805 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001807 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001808 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001809 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001810
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001811 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001812 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001813 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001814 + " oldTarget: " + mWallpaperTarget);
1815 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001816
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001817 mLowerWallpaperTarget = null;
1818 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001819
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001820 WindowState oldW = mWallpaperTarget;
1821 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001822
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001823 // Now what is happening... if the current and new targets are
1824 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001825 if (foundW != null && oldW != null) {
1826 boolean oldAnim = oldW.mAnimation != null
1827 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1828 boolean foundAnim = foundW.mAnimation != null
1829 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001830 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001831 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001832 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001833 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001834 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001835 int oldI = localmWindows.indexOf(oldW);
1836 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001837 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001838 }
1839 if (oldI >= 0) {
1840 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001841 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001842 + "=" + oldW + "; new#" + foundI
1843 + "=" + foundW);
1844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001847 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001848 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001849 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001850 }
1851 mWallpaperTarget = oldW;
1852 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001853
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001854 // Now set the upper and lower wallpaper targets
1855 // correctly, and make sure that we are positioning
1856 // the wallpaper below the lower.
1857 if (foundI > oldI) {
1858 // The new target is on top of the old one.
1859 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001861 }
1862 mUpperWallpaperTarget = foundW;
1863 mLowerWallpaperTarget = oldW;
1864 foundW = oldW;
1865 foundI = oldI;
1866 } else {
1867 // The new target is below the old one.
1868 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001870 }
1871 mUpperWallpaperTarget = oldW;
1872 mLowerWallpaperTarget = foundW;
1873 }
1874 }
1875 }
1876 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001877
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001878 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001879 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001880 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1881 || (mLowerWallpaperTarget.mAppToken != null
1882 && mLowerWallpaperTarget.mAppToken.animation != null);
1883 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1884 || (mUpperWallpaperTarget.mAppToken != null
1885 && mUpperWallpaperTarget.mAppToken.animation != null);
1886 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001887 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001888 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001889 }
1890 mLowerWallpaperTarget = null;
1891 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001892 }
1893 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001894
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001895 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001896 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001897 // The window is visible to the compositor... but is it visible
1898 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001899 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001900 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001901
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001902 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001903 // its layer adjustment. Only do this if we are not transfering
1904 // between two wallpaper targets.
1905 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001906 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001907 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001908
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001909 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1910 * TYPE_LAYER_MULTIPLIER
1911 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001912
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 // Now w is the window we are supposed to be behind... but we
1914 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001915 // AND any starting window associated with it, AND below the
1916 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001917 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001918 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001919 if (wb.mBaseLayer < maxLayer &&
1920 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001921 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001922 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001923 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001924 // This window is not related to the previous one in any
1925 // interesting way, so stop here.
1926 break;
1927 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001928 foundW = wb;
1929 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001930 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001931 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001932 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001933 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001935 if (foundW == null && topCurW != null) {
1936 // There is no wallpaper target, so it goes at the bottom.
1937 // We will assume it is the same place as last time, if known.
1938 foundW = topCurW;
1939 foundI = topCurI+1;
1940 } else {
1941 // Okay i is the position immediately above the wallpaper. Look at
1942 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001943 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001945
Dianne Hackborn284ac932009-08-28 10:34:25 -07001946 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001947 if (mWallpaperTarget.mWallpaperX >= 0) {
1948 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001949 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001950 }
1951 if (mWallpaperTarget.mWallpaperY >= 0) {
1952 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001953 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001954 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001955 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001956
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001957 // Start stepping backwards from here, ensuring that our wallpaper windows
1958 // are correctly placed.
1959 int curTokenIndex = mWallpaperTokens.size();
1960 while (curTokenIndex > 0) {
1961 curTokenIndex--;
1962 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001963 if (token.hidden == visible) {
1964 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1965 token.hidden = !visible;
1966 // Need to do a layout to ensure the wallpaper now has the
1967 // correct size.
1968 mLayoutNeeded = true;
1969 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001970
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001971 int curWallpaperIndex = token.windows.size();
1972 while (curWallpaperIndex > 0) {
1973 curWallpaperIndex--;
1974 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001975
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001976 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001977 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001978 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001979
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001980 // First, make sure the client has the current visibility
1981 // state.
1982 if (wallpaper.mWallpaperVisible != visible) {
1983 wallpaper.mWallpaperVisible = visible;
1984 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001985 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001986 "Setting visibility of wallpaper " + wallpaper
1987 + ": " + visible);
1988 wallpaper.mClient.dispatchAppVisibility(visible);
1989 } catch (RemoteException e) {
1990 }
1991 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001992
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001993 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001994 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001995 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001996
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001997 // First, if this window is at the current index, then all
1998 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001999 if (wallpaper == foundW) {
2000 foundI--;
2001 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07002002 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002003 continue;
2004 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002005
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002006 // The window didn't match... the current wallpaper window,
2007 // wherever it is, is in the wrong place, so make sure it is
2008 // not in the list.
2009 int oldIndex = localmWindows.indexOf(wallpaper);
2010 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07002012 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002013 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002014 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002015 if (oldIndex < foundI) {
2016 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002017 }
2018 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002019
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002020 // Now stick it in.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002021 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
2022 Slog.v(TAG, "Moving wallpaper " + wallpaper
2023 + " from " + oldIndex + " to " + foundI);
2024 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002025
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002026 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002027 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002028 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002029 }
2030 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002031
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002032 return changed;
2033 }
2034
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002035 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002036 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002037 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002038 mWallpaperAnimLayerAdjustment = adj;
2039 int curTokenIndex = mWallpaperTokens.size();
2040 while (curTokenIndex > 0) {
2041 curTokenIndex--;
2042 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2043 int curWallpaperIndex = token.windows.size();
2044 while (curWallpaperIndex > 0) {
2045 curWallpaperIndex--;
2046 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2047 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002048 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002049 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002050 }
2051 }
2052 }
2053
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002054 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
2055 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002056 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002057 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002058 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002059 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002060 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2061 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2062 changed = wallpaperWin.mXOffset != offset;
2063 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002064 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002065 + wallpaperWin + " x: " + offset);
2066 wallpaperWin.mXOffset = offset;
2067 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002068 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002069 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002070 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002071 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002072 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002073
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002074 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002075 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002076 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2077 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2078 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002079 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002080 + wallpaperWin + " y: " + offset);
2081 changed = true;
2082 wallpaperWin.mYOffset = offset;
2083 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002084 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002085 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002086 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002087 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002089
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002090 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002091 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002092 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002093 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2094 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002095 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002096 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002097 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002098 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002099 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2100 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002101 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002102 if (mWaitingOnWallpaper != null) {
2103 long start = SystemClock.uptimeMillis();
2104 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2105 < start) {
2106 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002107 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002108 "Waiting for offset complete...");
2109 mWindowMap.wait(WALLPAPER_TIMEOUT);
2110 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002111 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002112 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002113 if ((start+WALLPAPER_TIMEOUT)
2114 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002115 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002116 + wallpaperWin);
2117 mLastWallpaperTimeoutTime = start;
2118 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002119 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002120 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002121 }
2122 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002123 } catch (RemoteException e) {
2124 }
2125 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002126
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002127 return changed;
2128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002129
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002130 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002131 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002132 if (mWaitingOnWallpaper != null &&
2133 mWaitingOnWallpaper.mClient.asBinder() == window) {
2134 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002135 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002136 }
2137 }
2138 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002139
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002140 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002141 final int dw = mDisplay.getWidth();
2142 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002143
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002144 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002145
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002146 WindowState target = mWallpaperTarget;
2147 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002148 if (target.mWallpaperX >= 0) {
2149 mLastWallpaperX = target.mWallpaperX;
2150 } else if (changingTarget.mWallpaperX >= 0) {
2151 mLastWallpaperX = changingTarget.mWallpaperX;
2152 }
2153 if (target.mWallpaperY >= 0) {
2154 mLastWallpaperY = target.mWallpaperY;
2155 } else if (changingTarget.mWallpaperY >= 0) {
2156 mLastWallpaperY = changingTarget.mWallpaperY;
2157 }
2158 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002159
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002160 int curTokenIndex = mWallpaperTokens.size();
2161 while (curTokenIndex > 0) {
2162 curTokenIndex--;
2163 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2164 int curWallpaperIndex = token.windows.size();
2165 while (curWallpaperIndex > 0) {
2166 curWallpaperIndex--;
2167 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2168 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2169 wallpaper.computeShownFrameLocked();
2170 changed = true;
2171 // We only want to be synchronous with one wallpaper.
2172 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002173 }
2174 }
2175 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002176
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002177 return changed;
2178 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002179
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002180 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002181 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002182 final int dw = mDisplay.getWidth();
2183 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002184
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002185 int curTokenIndex = mWallpaperTokens.size();
2186 while (curTokenIndex > 0) {
2187 curTokenIndex--;
2188 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002189 if (token.hidden == visible) {
2190 token.hidden = !visible;
2191 // Need to do a layout to ensure the wallpaper now has the
2192 // correct size.
2193 mLayoutNeeded = true;
2194 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002195
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002196 int curWallpaperIndex = token.windows.size();
2197 while (curWallpaperIndex > 0) {
2198 curWallpaperIndex--;
2199 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2200 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002201 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002202 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002203
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002204 if (wallpaper.mWallpaperVisible != visible) {
2205 wallpaper.mWallpaperVisible = visible;
2206 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002207 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002208 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002209 + ": " + visible);
2210 wallpaper.mClient.dispatchAppVisibility(visible);
2211 } catch (RemoteException e) {
2212 }
2213 }
2214 }
2215 }
2216 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 public int addWindow(Session session, IWindow client,
2219 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07002220 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 int res = mPolicy.checkAddPermission(attrs);
2222 if (res != WindowManagerImpl.ADD_OKAY) {
2223 return res;
2224 }
Romain Guy06882f82009-06-10 13:36:04 -07002225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 boolean reportNewConfig = false;
2227 WindowState attachedWindow = null;
2228 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002229 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002233 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 }
Romain Guy06882f82009-06-10 13:36:04 -07002235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002237 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2239 }
2240
2241 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002242 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002244 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002245 + attrs.token + ". Aborting.");
2246 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2247 }
2248 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2249 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002250 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 + attrs.token + ". Aborting.");
2252 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2253 }
2254 }
2255
2256 boolean addToken = false;
2257 WindowToken token = mTokenMap.get(attrs.token);
2258 if (token == null) {
2259 if (attrs.type >= FIRST_APPLICATION_WINDOW
2260 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002261 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 + attrs.token + ". Aborting.");
2263 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2264 }
2265 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002266 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 + attrs.token + ". Aborting.");
2268 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2269 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002270 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002271 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002272 + attrs.token + ". Aborting.");
2273 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 token = new WindowToken(attrs.token, -1, false);
2276 addToken = true;
2277 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2278 && attrs.type <= LAST_APPLICATION_WINDOW) {
2279 AppWindowToken atoken = token.appWindowToken;
2280 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002281 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 + token + ". Aborting.");
2283 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2284 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002285 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 + token + ". Aborting.");
2287 return WindowManagerImpl.ADD_APP_EXITING;
2288 }
2289 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2290 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002291 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2293 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2294 }
2295 } else if (attrs.type == TYPE_INPUT_METHOD) {
2296 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002297 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 + attrs.token + ". Aborting.");
2299 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2300 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002301 } else if (attrs.type == TYPE_WALLPAPER) {
2302 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002303 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002304 + attrs.token + ". Aborting.");
2305 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 }
2308
2309 win = new WindowState(session, client, token,
2310 attachedWindow, attrs, viewVisibility);
2311 if (win.mDeathRecipient == null) {
2312 // Client has apparently died, so there is no reason to
2313 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002314 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 + " that is dead, aborting.");
2316 return WindowManagerImpl.ADD_APP_EXITING;
2317 }
2318
2319 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 res = mPolicy.prepareAddWindowLw(win, attrs);
2322 if (res != WindowManagerImpl.ADD_OKAY) {
2323 return res;
2324 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07002325
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002326 if (outInputChannel != null) {
2327 String name = win.makeInputChannelName();
2328 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2329 win.mInputChannel = inputChannels[0];
2330 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2331
Jeff Brown928e0542011-01-10 11:17:36 -08002332 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334
2335 // From now on, no exceptions or errors allowed!
2336
2337 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002338
Dianne Hackborn5132b372010-07-29 12:51:35 -07002339 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 if (addToken) {
2342 mTokenMap.put(attrs.token, token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 }
2344 win.attach();
2345 mWindowMap.put(client.asBinder(), win);
2346
2347 if (attrs.type == TYPE_APPLICATION_STARTING &&
2348 token.appWindowToken != null) {
2349 token.appWindowToken.startingWindow = win;
2350 }
2351
2352 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 if (attrs.type == TYPE_INPUT_METHOD) {
2355 mInputMethodWindow = win;
2356 addInputMethodWindowToListLocked(win);
2357 imMayMove = false;
2358 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2359 mInputMethodDialogs.add(win);
2360 addWindowToListInOrderLocked(win, true);
2361 adjustInputMethodDialogsLocked();
2362 imMayMove = false;
2363 } else {
2364 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002365 if (attrs.type == TYPE_WALLPAPER) {
2366 mLastWallpaperTimeoutTime = 0;
2367 adjustWallpaperWindowsLocked();
2368 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002369 adjustWallpaperWindowsLocked();
2370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 }
Romain Guy06882f82009-06-10 13:36:04 -07002372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 if (mInTouchMode) {
2378 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2379 }
2380 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2381 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2382 }
Romain Guy06882f82009-06-10 13:36:04 -07002383
Jeff Brown2e44b072011-01-24 15:21:56 -08002384 mInputMonitor.setUpdateInputWindowsNeededLw();
2385
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002386 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 if (win.canReceiveKeys()) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002388 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
2389 false /*updateInputWindows*/);
Jeff Brown349703e2010-06-22 01:27:15 -07002390 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 imMayMove = false;
2392 }
2393 }
Romain Guy06882f82009-06-10 13:36:04 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002396 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 }
Romain Guy06882f82009-06-10 13:36:04 -07002398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 assignLayersLocked();
2400 // Don't do layout here, the window must call
2401 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 //dump();
2404
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002405 if (focusChanged) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08002406 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002407 }
Jeff Brown2e44b072011-01-24 15:21:56 -08002408 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08002409
Joe Onorato8a9b2202010-02-26 18:56:32 -08002410 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002411 TAG, "New client " + client.asBinder()
2412 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002413
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002414 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002415 reportNewConfig = true;
2416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 }
2418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 if (reportNewConfig) {
2420 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 return res;
2426 }
Romain Guy06882f82009-06-10 13:36:04 -07002427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 public void removeWindow(Session session, IWindow client) {
2429 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002430 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 if (win == null) {
2432 return;
2433 }
2434 removeWindowLocked(session, win);
2435 }
2436 }
Romain Guy06882f82009-06-10 13:36:04 -07002437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 public void removeWindowLocked(Session session, WindowState win) {
2439
Joe Onorato8a9b2202010-02-26 18:56:32 -08002440 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 TAG, "Remove " + win + " client="
2442 + Integer.toHexString(System.identityHashCode(
2443 win.mClient.asBinder()))
2444 + ", surface=" + win.mSurface);
2445
2446 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002447
2448 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002449
Joe Onorato8a9b2202010-02-26 18:56:32 -08002450 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2452 + " mExiting=" + win.mExiting
2453 + " isAnimating=" + win.isAnimating()
2454 + " app-animation="
2455 + (win.mAppToken != null ? win.mAppToken.animation : null)
2456 + " inPendingTransaction="
2457 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2458 + " mDisplayFrozen=" + mDisplayFrozen);
2459 // Visibility of the removed window. Will be used later to update orientation later on.
2460 boolean wasVisible = false;
2461 // First, see if we need to run an animation. If we do, we have
2462 // to hold off on removing the window until the animation is done.
2463 // If the display is frozen, just remove immediately, since the
2464 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002465 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 // If we are not currently running the exit animation, we
2467 // need to see about starting one.
2468 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2471 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2472 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2473 }
2474 // Try starting an animation.
2475 if (applyAnimationLocked(win, transit, false)) {
2476 win.mExiting = true;
2477 }
2478 }
2479 if (win.mExiting || win.isAnimating()) {
2480 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002481 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 win.mExiting = true;
2483 win.mRemoveOnExit = true;
2484 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08002485 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2486 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08002488 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 if (win.mAppToken != null) {
2490 win.mAppToken.updateReportedVisibilityLocked();
2491 }
2492 //dump();
2493 Binder.restoreCallingIdentity(origId);
2494 return;
2495 }
2496 }
2497
2498 removeWindowInnerLocked(session, win);
2499 // Removing a visible window will effect the computed orientation
2500 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002501 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002502 != mForcedAppOrientation
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002503 && updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002504 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08002506 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 Binder.restoreCallingIdentity(origId);
2508 }
Romain Guy06882f82009-06-10 13:36:04 -07002509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 private void removeWindowInnerLocked(Session session, WindowState win) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002511 if (win.mRemoved) {
2512 // Nothing to do.
2513 return;
2514 }
2515
2516 for (int i=win.mChildWindows.size()-1; i>=0; i--) {
2517 WindowState cwin = win.mChildWindows.get(i);
2518 Slog.w(TAG, "Force-removing child win " + cwin + " from container "
2519 + win);
2520 removeWindowInnerLocked(cwin.mSession, cwin);
2521 }
2522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 if (mInputMethodTarget == win) {
2526 moveInputMethodWindowsIfNeededLocked(false);
2527 }
Romain Guy06882f82009-06-10 13:36:04 -07002528
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002529 if (false) {
2530 RuntimeException e = new RuntimeException("here");
2531 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002532 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002533 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 mPolicy.removeWindowLw(win);
2536 win.removeLocked();
2537
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002538 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 mWindowMap.remove(win.mClient.asBinder());
2540 mWindows.remove(win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002541 mPendingRemove.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002542 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002543 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544
2545 if (mInputMethodWindow == win) {
2546 mInputMethodWindow = null;
2547 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2548 mInputMethodDialogs.remove(win);
2549 }
Romain Guy06882f82009-06-10 13:36:04 -07002550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 final WindowToken token = win.mToken;
2552 final AppWindowToken atoken = win.mAppToken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002553 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 token.windows.remove(win);
2555 if (atoken != null) {
2556 atoken.allAppWindows.remove(win);
2557 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002558 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 TAG, "**** Removing window " + win + ": count="
2560 + token.windows.size());
2561 if (token.windows.size() == 0) {
2562 if (!token.explicit) {
2563 mTokenMap.remove(token.token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 } else if (atoken != null) {
2565 atoken.firstWindowDrawn = false;
2566 }
2567 }
2568
2569 if (atoken != null) {
2570 if (atoken.startingWindow == win) {
2571 atoken.startingWindow = null;
2572 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2573 // If this is the last window and we had requested a starting
2574 // transition window, well there is no point now.
2575 atoken.startingData = null;
2576 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2577 // If this is the last window except for a starting transition
2578 // window, we need to get rid of the starting transition.
2579 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002580 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 + ": no more real windows");
2582 }
2583 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2584 mH.sendMessage(m);
2585 }
2586 }
Romain Guy06882f82009-06-10 13:36:04 -07002587
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002588 if (win.mAttrs.type == TYPE_WALLPAPER) {
2589 mLastWallpaperTimeoutTime = 0;
2590 adjustWallpaperWindowsLocked();
2591 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002592 adjustWallpaperWindowsLocked();
2593 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 if (!mInLayout) {
2596 assignLayersLocked();
2597 mLayoutNeeded = true;
2598 performLayoutAndPlaceSurfacesLocked();
2599 if (win.mAppToken != null) {
2600 win.mAppToken.updateReportedVisibilityLocked();
2601 }
2602 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002603
Jeff Brown2e44b072011-01-24 15:21:56 -08002604 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 }
2606
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002607 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2608 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2609 + ": " + msg + " / " + w.mAttrs.getTitle();
2610 if (where != null) {
2611 Slog.i(TAG, str, where);
2612 } else {
2613 Slog.i(TAG, str);
2614 }
2615 }
2616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2618 long origId = Binder.clearCallingIdentity();
2619 try {
2620 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002621 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 if ((w != null) && (w.mSurface != null)) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002623 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2624 ">>> OPEN TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 Surface.openTransaction();
2626 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002627 if (SHOW_TRANSACTIONS) logSurface(w,
2628 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 w.mSurface.setTransparentRegionHint(region);
2630 } finally {
2631 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002632 if (SHOW_TRANSACTIONS) Slog.i(TAG,
2633 "<<< CLOSE TRANSACTION setTransparentRegion");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 }
2635 }
2636 }
2637 } finally {
2638 Binder.restoreCallingIdentity(origId);
2639 }
2640 }
2641
2642 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002643 int touchableInsets, Rect contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08002644 Rect visibleInsets, Region touchableRegion) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 long origId = Binder.clearCallingIdentity();
2646 try {
2647 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002648 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 if (w != null) {
2650 w.mGivenInsetsPending = false;
2651 w.mGivenContentInsets.set(contentInsets);
2652 w.mGivenVisibleInsets.set(visibleInsets);
Jeff Brownfbf09772011-01-16 14:06:57 -08002653 w.mGivenTouchableRegion.set(touchableRegion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 w.mTouchableInsets = touchableInsets;
2655 mLayoutNeeded = true;
2656 performLayoutAndPlaceSurfacesLocked();
2657 }
2658 }
2659 } finally {
2660 Binder.restoreCallingIdentity(origId);
2661 }
2662 }
Romain Guy06882f82009-06-10 13:36:04 -07002663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 public void getWindowDisplayFrame(Session session, IWindow client,
2665 Rect outDisplayFrame) {
2666 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002667 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 if (win == null) {
2669 outDisplayFrame.setEmpty();
2670 return;
2671 }
2672 outDisplayFrame.set(win.mDisplayFrame);
2673 }
2674 }
2675
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002676 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2677 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002678 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2679 window.mWallpaperX = x;
2680 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002681 window.mWallpaperXStep = xStep;
2682 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002683 if (updateWallpaperOffsetLocked(window, true)) {
2684 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002685 }
2686 }
2687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002688
Dianne Hackborn75804932009-10-20 20:15:20 -07002689 void wallpaperCommandComplete(IBinder window, Bundle result) {
2690 synchronized (mWindowMap) {
2691 if (mWaitingOnWallpaper != null &&
2692 mWaitingOnWallpaper.mClient.asBinder() == window) {
2693 mWaitingOnWallpaper = null;
2694 mWindowMap.notifyAll();
2695 }
2696 }
2697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002698
Dianne Hackborn75804932009-10-20 20:15:20 -07002699 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2700 String action, int x, int y, int z, Bundle extras, boolean sync) {
2701 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2702 || window == mUpperWallpaperTarget) {
2703 boolean doWait = sync;
2704 int curTokenIndex = mWallpaperTokens.size();
2705 while (curTokenIndex > 0) {
2706 curTokenIndex--;
2707 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2708 int curWallpaperIndex = token.windows.size();
2709 while (curWallpaperIndex > 0) {
2710 curWallpaperIndex--;
2711 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2712 try {
2713 wallpaper.mClient.dispatchWallpaperCommand(action,
2714 x, y, z, extras, sync);
2715 // We only want to be synchronous with one wallpaper.
2716 sync = false;
2717 } catch (RemoteException e) {
2718 }
2719 }
2720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002721
Dianne Hackborn75804932009-10-20 20:15:20 -07002722 if (doWait) {
2723 // XXX Need to wait for result.
2724 }
2725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002726
Dianne Hackborn75804932009-10-20 20:15:20 -07002727 return null;
2728 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 public int relayoutWindow(Session session, IWindow client,
2731 WindowManager.LayoutParams attrs, int requestedWidth,
2732 int requestedHeight, int viewVisibility, boolean insetsPending,
2733 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002734 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 boolean displayed = false;
2736 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002737 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002741 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 if (win == null) {
2743 return 0;
2744 }
2745 win.mRequestedWidth = requestedWidth;
2746 win.mRequestedHeight = requestedHeight;
2747
2748 if (attrs != null) {
2749 mPolicy.adjustWindowParamsLw(attrs);
2750 }
Romain Guy06882f82009-06-10 13:36:04 -07002751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 int attrChanges = 0;
2753 int flagChanges = 0;
2754 if (attrs != null) {
2755 flagChanges = win.mAttrs.flags ^= attrs.flags;
2756 attrChanges = win.mAttrs.copyFrom(attrs);
2757 }
2758
Joe Onorato8a9b2202010-02-26 18:56:32 -08002759 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002760
2761 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2762 win.mAlpha = attrs.alpha;
2763 }
2764
2765 final boolean scaledWindow =
2766 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2767
2768 if (scaledWindow) {
2769 // requested{Width|Height} Surface's physical size
2770 // attrs.{width|height} Size on screen
2771 win.mHScale = (attrs.width != requestedWidth) ?
2772 (attrs.width / (float)requestedWidth) : 1.0f;
2773 win.mVScale = (attrs.height != requestedHeight) ?
2774 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002775 } else {
2776 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 }
2778
2779 boolean imMayMove = (flagChanges&(
2780 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2781 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 boolean focusMayChange = win.mViewVisibility != viewVisibility
2784 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2785 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002786
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002787 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2788 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002790 win.mRelayoutCalled = true;
2791 final int oldVisibility = win.mViewVisibility;
2792 win.mViewVisibility = viewVisibility;
2793 if (viewVisibility == View.VISIBLE &&
2794 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2795 displayed = !win.isVisibleLw();
2796 if (win.mExiting) {
2797 win.mExiting = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07002798 if (win.mAnimation != null) {
2799 win.mAnimation.cancel();
2800 win.mAnimation = null;
2801 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 }
2803 if (win.mDestroying) {
2804 win.mDestroying = false;
2805 mDestroySurface.remove(win);
2806 }
2807 if (oldVisibility == View.GONE) {
2808 win.mEnterAnimationPending = true;
2809 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002810 if (displayed) {
2811 if (win.mSurface != null && !win.mDrawPending
2812 && !win.mCommitDrawPending && !mDisplayFrozen
2813 && mPolicy.isScreenOn()) {
2814 applyEnterAnimationLocked(win);
2815 }
2816 if ((win.mAttrs.flags
2817 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2818 if (DEBUG_VISIBILITY) Slog.v(TAG,
2819 "Relayout window turning screen on: " + win);
2820 win.mTurnOnScreen = true;
2821 }
2822 int diff = 0;
2823 if (win.mConfiguration != mCurConfiguration
2824 && (win.mConfiguration == null
2825 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2826 win.mConfiguration = mCurConfiguration;
2827 if (DEBUG_CONFIGURATION) {
2828 Slog.i(TAG, "Window " + win + " visible with new config: "
2829 + win.mConfiguration + " / 0x"
2830 + Integer.toHexString(diff));
2831 }
2832 outConfig.setTo(mCurConfiguration);
2833 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2836 // To change the format, we need to re-build the surface.
2837 win.destroySurfaceLocked();
2838 displayed = true;
2839 }
2840 try {
2841 Surface surface = win.createSurfaceLocked();
2842 if (surface != null) {
2843 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002844 win.mReportDestroySurface = false;
2845 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002846 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002847 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002849 // For some reason there isn't a surface. Clear the
2850 // caller's object so they see the same state.
2851 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 }
2853 } catch (Exception e) {
Jeff Brown2e44b072011-01-24 15:21:56 -08002854 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browne33348b2010-07-15 23:54:05 -07002855
Joe Onorato8a9b2202010-02-26 18:56:32 -08002856 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002857 + client + " (" + win.mAttrs.getTitle() + ")",
2858 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 Binder.restoreCallingIdentity(origId);
2860 return 0;
2861 }
2862 if (displayed) {
2863 focusMayChange = true;
2864 }
2865 if (win.mAttrs.type == TYPE_INPUT_METHOD
2866 && mInputMethodWindow == null) {
2867 mInputMethodWindow = win;
2868 imMayMove = true;
2869 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002870 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2871 && win.mAppToken != null
2872 && win.mAppToken.startingWindow != null) {
2873 // Special handling of starting window over the base
2874 // window of the app: propagate lock screen flags to it,
2875 // to provide the correct semantics while starting.
2876 final int mask =
2877 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002878 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2879 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002880 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2881 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 } else {
2884 win.mEnterAnimationPending = false;
2885 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002886 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002887 + ": mExiting=" + win.mExiting
2888 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 // If we are not currently running the exit animation, we
2890 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002891 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 // Try starting an animation; if there isn't one, we
2893 // can destroy the surface right away.
2894 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2895 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2896 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2897 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002898 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002900 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 } else if (win.isAnimating()) {
2903 // Currently in a hide animation... turn this into
2904 // an exit.
2905 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002906 } else if (win == mWallpaperTarget) {
2907 // If the wallpaper is currently behind this
2908 // window, we need to change both of them inside
2909 // of a transaction to avoid artifacts.
2910 win.mExiting = true;
2911 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 } else {
2913 if (mInputMethodWindow == win) {
2914 mInputMethodWindow = null;
2915 }
2916 win.destroySurfaceLocked();
2917 }
2918 }
2919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002920
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002921 if (win.mSurface == null || (win.getAttrs().flags
2922 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2923 || win.mSurfacePendingDestroy) {
2924 // We are being called from a local process, which
2925 // means outSurface holds its current surface. Ensure the
2926 // surface object is cleared, but we don't want it actually
2927 // destroyed at this point.
2928 win.mSurfacePendingDestroy = false;
2929 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002930 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002931 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002932 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002933 "Keeping surface, will report destroy: " + win);
2934 win.mReportDestroySurface = true;
2935 outSurface.copyFrom(win.mSurface);
2936 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 }
2938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002939 if (focusMayChange) {
2940 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
Jeff Brown3a22cd92011-01-21 13:59:04 -08002941 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2942 false /*updateInputWindows*/)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 imMayMove = false;
2944 }
2945 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2946 }
Romain Guy06882f82009-06-10 13:36:04 -07002947
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002948 // updateFocusedWindowLocked() already assigned layers so we only need to
2949 // reassign them at this point if the IM window state gets shuffled
2950 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002953 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2954 // Little hack here -- we -should- be able to rely on the
2955 // function to return true if the IME has moved and needs
2956 // its layer recomputed. However, if the IME was hidden
2957 // and isn't actually moved in the list, its layer may be
2958 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 assignLayers = true;
2960 }
2961 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002962 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002963 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002964 assignLayers = true;
2965 }
2966 }
Romain Guy06882f82009-06-10 13:36:04 -07002967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 mLayoutNeeded = true;
2969 win.mGivenInsetsPending = insetsPending;
2970 if (assignLayers) {
2971 assignLayersLocked();
2972 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08002973 configChanged = updateOrientationFromAppTokensLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002975 if (displayed && win.mIsWallpaper) {
2976 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002977 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002978 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 if (win.mAppToken != null) {
2980 win.mAppToken.updateReportedVisibilityLocked();
2981 }
2982 outFrame.set(win.mFrame);
2983 outContentInsets.set(win.mContentInsets);
2984 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002985 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002987 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 + ", requestedHeight=" + requestedHeight
2989 + ", viewVisibility=" + viewVisibility
2990 + "\nRelayout returning frame=" + outFrame
2991 + ", surface=" + outSurface);
2992
Joe Onorato8a9b2202010-02-26 18:56:32 -08002993 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2995
2996 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002997
Jeff Brown2e44b072011-01-24 15:21:56 -08002998 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 }
3000
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003001 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 sendNewConfiguration();
3003 }
Romain Guy06882f82009-06-10 13:36:04 -07003004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07003006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
3008 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
3009 }
3010
3011 public void finishDrawingWindow(Session session, IWindow client) {
3012 final long origId = Binder.clearCallingIdentity();
3013 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003014 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07003016 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
3017 adjustWallpaperWindowsLocked();
3018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 mLayoutNeeded = true;
3020 performLayoutAndPlaceSurfacesLocked();
3021 }
3022 }
3023 Binder.restoreCallingIdentity(origId);
3024 }
3025
3026 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003027 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028 + (lp != null ? lp.packageName : null)
3029 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
3030 if (lp != null && lp.windowAnimations != 0) {
3031 // If this is a system resource, don't try to load it from the
3032 // application resources. It is nice to avoid loading application
3033 // resources if we can.
3034 String packageName = lp.packageName != null ? lp.packageName : "android";
3035 int resId = lp.windowAnimations;
3036 if ((resId&0xFF000000) == 0x01000000) {
3037 packageName = "android";
3038 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003039 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 + packageName);
3041 return AttributeCache.instance().get(packageName, resId,
3042 com.android.internal.R.styleable.WindowAnimation);
3043 }
3044 return null;
3045 }
Romain Guy06882f82009-06-10 13:36:04 -07003046
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003047 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Dianne Hackborn08121bc2011-01-17 17:54:31 -08003048 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003049 + packageName + " resId=0x" + Integer.toHexString(resId));
3050 if (packageName != null) {
3051 if ((resId&0xFF000000) == 0x01000000) {
3052 packageName = "android";
3053 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003054 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003055 + packageName);
3056 return AttributeCache.instance().get(packageName, resId,
3057 com.android.internal.R.styleable.WindowAnimation);
3058 }
3059 return null;
3060 }
3061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003062 private void applyEnterAnimationLocked(WindowState win) {
3063 int transit = WindowManagerPolicy.TRANSIT_SHOW;
3064 if (win.mEnterAnimationPending) {
3065 win.mEnterAnimationPending = false;
3066 transit = WindowManagerPolicy.TRANSIT_ENTER;
3067 }
3068
3069 applyAnimationLocked(win, transit, true);
3070 }
3071
3072 private boolean applyAnimationLocked(WindowState win,
3073 int transit, boolean isEntrance) {
3074 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
3075 // If we are trying to apply an animation, but already running
3076 // an animation of the same type, then just leave that one alone.
3077 return true;
3078 }
Romain Guy06882f82009-06-10 13:36:04 -07003079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 // Only apply an animation if the display isn't frozen. If it is
3081 // frozen, there is no reason to animate and it can cause strange
3082 // artifacts when we unfreeze the display if some different animation
3083 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003084 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003085 int anim = mPolicy.selectAnimationLw(win, transit);
3086 int attr = -1;
3087 Animation a = null;
3088 if (anim != 0) {
3089 a = AnimationUtils.loadAnimation(mContext, anim);
3090 } else {
3091 switch (transit) {
3092 case WindowManagerPolicy.TRANSIT_ENTER:
3093 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3094 break;
3095 case WindowManagerPolicy.TRANSIT_EXIT:
3096 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3097 break;
3098 case WindowManagerPolicy.TRANSIT_SHOW:
3099 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3100 break;
3101 case WindowManagerPolicy.TRANSIT_HIDE:
3102 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3103 break;
3104 }
3105 if (attr >= 0) {
3106 a = loadAnimation(win.mAttrs, attr);
3107 }
3108 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003109 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3111 + " mAnimation=" + win.mAnimation
3112 + " isEntrance=" + isEntrance);
3113 if (a != null) {
3114 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003115 RuntimeException e = null;
3116 if (!HIDE_STACK_CRAWLS) {
3117 e = new RuntimeException();
3118 e.fillInStackTrace();
3119 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003120 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003121 }
3122 win.setAnimation(a);
3123 win.mAnimationIsEntrance = isEntrance;
3124 }
3125 } else {
3126 win.clearAnimation();
3127 }
3128
3129 return win.mAnimation != null;
3130 }
3131
3132 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3133 int anim = 0;
3134 Context context = mContext;
3135 if (animAttr >= 0) {
3136 AttributeCache.Entry ent = getCachedAnimations(lp);
3137 if (ent != null) {
3138 context = ent.context;
3139 anim = ent.array.getResourceId(animAttr, 0);
3140 }
3141 }
3142 if (anim != 0) {
3143 return AnimationUtils.loadAnimation(context, anim);
3144 }
3145 return null;
3146 }
Romain Guy06882f82009-06-10 13:36:04 -07003147
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003148 private Animation loadAnimation(String packageName, int resId) {
3149 int anim = 0;
3150 Context context = mContext;
3151 if (resId >= 0) {
3152 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3153 if (ent != null) {
3154 context = ent.context;
3155 anim = resId;
3156 }
3157 }
3158 if (anim != 0) {
3159 return AnimationUtils.loadAnimation(context, anim);
3160 }
3161 return null;
3162 }
3163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 private boolean applyAnimationLocked(AppWindowToken wtoken,
3165 WindowManager.LayoutParams lp, int transit, boolean enter) {
3166 // Only apply an animation if the display isn't frozen. If it is
3167 // frozen, there is no reason to animate and it can cause strange
3168 // artifacts when we unfreeze the display if some different animation
3169 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003170 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003171 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003172 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003173 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003174 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003175 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003176 } else if (mNextAppTransitionPackage != null) {
3177 a = loadAnimation(mNextAppTransitionPackage, enter ?
3178 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003179 } else {
3180 int animAttr = 0;
3181 switch (transit) {
3182 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3183 animAttr = enter
3184 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3185 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3186 break;
3187 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3188 animAttr = enter
3189 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3190 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3191 break;
3192 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3193 animAttr = enter
3194 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3195 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3196 break;
3197 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3198 animAttr = enter
3199 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3200 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3201 break;
3202 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3203 animAttr = enter
3204 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3205 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3206 break;
3207 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3208 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003209 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003210 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3211 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003212 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003213 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003214 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3215 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003216 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003217 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003218 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003219 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3220 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3221 break;
3222 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3223 animAttr = enter
3224 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3225 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3226 break;
3227 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3228 animAttr = enter
3229 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3230 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003231 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003232 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003233 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003234 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003235 + " anim=" + a
3236 + " animAttr=0x" + Integer.toHexString(animAttr)
3237 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 if (a != null) {
3240 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003241 RuntimeException e = null;
3242 if (!HIDE_STACK_CRAWLS) {
3243 e = new RuntimeException();
3244 e.fillInStackTrace();
3245 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003246 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247 }
3248 wtoken.setAnimation(a);
3249 }
3250 } else {
3251 wtoken.clearAnimation();
3252 }
3253
3254 return wtoken.animation != null;
3255 }
3256
3257 // -------------------------------------------------------------
3258 // Application Window Tokens
3259 // -------------------------------------------------------------
3260
3261 public void validateAppTokens(List tokens) {
3262 int v = tokens.size()-1;
3263 int m = mAppTokens.size()-1;
3264 while (v >= 0 && m >= 0) {
3265 AppWindowToken wtoken = mAppTokens.get(m);
3266 if (wtoken.removed) {
3267 m--;
3268 continue;
3269 }
3270 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003271 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3273 }
3274 v--;
3275 m--;
3276 }
3277 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003278 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 v--;
3280 }
3281 while (m >= 0) {
3282 AppWindowToken wtoken = mAppTokens.get(m);
3283 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003284 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 }
3286 m--;
3287 }
3288 }
3289
3290 boolean checkCallingPermission(String permission, String func) {
3291 // Quick check: if the calling permission is me, it's all okay.
3292 if (Binder.getCallingPid() == Process.myPid()) {
3293 return true;
3294 }
Romain Guy06882f82009-06-10 13:36:04 -07003295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 if (mContext.checkCallingPermission(permission)
3297 == PackageManager.PERMISSION_GRANTED) {
3298 return true;
3299 }
3300 String msg = "Permission Denial: " + func + " from pid="
3301 + Binder.getCallingPid()
3302 + ", uid=" + Binder.getCallingUid()
3303 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003304 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 return false;
3306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 AppWindowToken findAppWindowToken(IBinder token) {
3309 WindowToken wtoken = mTokenMap.get(token);
3310 if (wtoken == null) {
3311 return null;
3312 }
3313 return wtoken.appWindowToken;
3314 }
Romain Guy06882f82009-06-10 13:36:04 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 public void addWindowToken(IBinder token, int type) {
3317 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3318 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003319 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 }
Romain Guy06882f82009-06-10 13:36:04 -07003321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 synchronized(mWindowMap) {
3323 WindowToken wtoken = mTokenMap.get(token);
3324 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003325 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 return;
3327 }
3328 wtoken = new WindowToken(token, type, true);
3329 mTokenMap.put(token, wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003330 if (type == TYPE_WALLPAPER) {
3331 mWallpaperTokens.add(wtoken);
3332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 }
3334 }
Romain Guy06882f82009-06-10 13:36:04 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 public void removeWindowToken(IBinder token) {
3337 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3338 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003339 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 }
3341
3342 final long origId = Binder.clearCallingIdentity();
3343 synchronized(mWindowMap) {
3344 WindowToken wtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 if (wtoken != null) {
3346 boolean delayed = false;
3347 if (!wtoken.hidden) {
3348 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 final int N = wtoken.windows.size();
3351 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 for (int i=0; i<N; i++) {
3354 WindowState win = wtoken.windows.get(i);
3355
3356 if (win.isAnimating()) {
3357 delayed = true;
3358 }
Romain Guy06882f82009-06-10 13:36:04 -07003359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 if (win.isVisibleNow()) {
3361 applyAnimationLocked(win,
3362 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 changed = true;
3364 }
3365 }
3366
3367 if (changed) {
3368 mLayoutNeeded = true;
3369 performLayoutAndPlaceSurfacesLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003370 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
3371 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 }
Romain Guy06882f82009-06-10 13:36:04 -07003373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 if (delayed) {
3375 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003376 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3377 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 }
3379 }
Romain Guy06882f82009-06-10 13:36:04 -07003380
Jeff Brown2e44b072011-01-24 15:21:56 -08003381 mInputMonitor.updateInputWindowsLw(true /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003383 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 }
3385 }
3386 Binder.restoreCallingIdentity(origId);
3387 }
3388
3389 public void addAppToken(int addPos, IApplicationToken token,
3390 int groupId, int requestedOrientation, boolean fullscreen) {
3391 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3392 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003393 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394 }
Jeff Brown349703e2010-06-22 01:27:15 -07003395
3396 // Get the dispatching timeout here while we are not holding any locks so that it
3397 // can be cached by the AppWindowToken. The timeout value is used later by the
3398 // input dispatcher in code that does hold locks. If we did not cache the value
3399 // here we would run the chance of introducing a deadlock between the window manager
3400 // (which holds locks while updating the input dispatcher state) and the activity manager
3401 // (which holds locks while querying the application token).
3402 long inputDispatchingTimeoutNanos;
3403 try {
3404 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3405 } catch (RemoteException ex) {
3406 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3407 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3408 }
Romain Guy06882f82009-06-10 13:36:04 -07003409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 synchronized(mWindowMap) {
3411 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3412 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003413 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 return;
3415 }
3416 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003417 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418 wtoken.groupId = groupId;
3419 wtoken.appFullscreen = fullscreen;
3420 wtoken.requestedOrientation = requestedOrientation;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003421 if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 mAppTokens.add(addPos, wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 mTokenMap.put(token.asBinder(), wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 // Application tokens start out hidden.
3426 wtoken.hidden = true;
3427 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 //dump();
3430 }
3431 }
Romain Guy06882f82009-06-10 13:36:04 -07003432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 public void setAppGroupId(IBinder token, int groupId) {
3434 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3435 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003436 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 }
3438
3439 synchronized(mWindowMap) {
3440 AppWindowToken wtoken = findAppWindowToken(token);
3441 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003442 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 return;
3444 }
3445 wtoken.groupId = groupId;
3446 }
3447 }
Romain Guy06882f82009-06-10 13:36:04 -07003448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003449 public int getOrientationFromWindowsLocked() {
3450 int pos = mWindows.size() - 1;
3451 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003452 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003453 pos--;
3454 if (wtoken.mAppToken != null) {
3455 // We hit an application window. so the orientation will be determined by the
3456 // app window. No point in continuing further.
3457 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3458 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003459 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 continue;
3461 }
3462 int req = wtoken.mAttrs.screenOrientation;
3463 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3464 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3465 continue;
3466 } else {
3467 return req;
3468 }
3469 }
3470 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3471 }
Romain Guy06882f82009-06-10 13:36:04 -07003472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003474 int pos = mAppTokens.size() - 1;
3475 int curGroup = 0;
3476 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3477 boolean findingBehind = false;
3478 boolean haveGroup = false;
3479 boolean lastFullscreen = false;
3480 while (pos >= 0) {
3481 AppWindowToken wtoken = mAppTokens.get(pos);
3482 pos--;
3483 // if we're about to tear down this window and not seek for
3484 // the behind activity, don't use it for orientation
3485 if (!findingBehind
3486 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3487 continue;
3488 }
3489
3490 if (!haveGroup) {
3491 // We ignore any hidden applications on the top.
3492 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003493 continue;
3494 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003495 haveGroup = true;
3496 curGroup = wtoken.groupId;
3497 lastOrientation = wtoken.requestedOrientation;
3498 } else if (curGroup != wtoken.groupId) {
3499 // If we have hit a new application group, and the bottom
3500 // of the previous group didn't explicitly say to use
3501 // the orientation behind it, and the last app was
3502 // full screen, then we'll stick with the
3503 // user's orientation.
3504 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3505 && lastFullscreen) {
3506 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003509 int or = wtoken.requestedOrientation;
3510 // If this application is fullscreen, and didn't explicitly say
3511 // to use the orientation behind it, then just take whatever
3512 // orientation it has and ignores whatever is under it.
3513 lastFullscreen = wtoken.appFullscreen;
3514 if (lastFullscreen
3515 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3516 return or;
3517 }
3518 // If this application has requested an explicit orientation,
3519 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003520 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3521 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003522 return or;
3523 }
3524 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3525 }
3526 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 }
Romain Guy06882f82009-06-10 13:36:04 -07003528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003530 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003531 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3532 "updateOrientationFromAppTokens()")) {
3533 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3534 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003535
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003536 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003538
3539 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003540 if (updateOrientationFromAppTokensLocked(false)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003541 if (freezeThisOneIfNeeded != null) {
3542 AppWindowToken wtoken = findAppWindowToken(
3543 freezeThisOneIfNeeded);
3544 if (wtoken != null) {
3545 startAppFreezingScreenLocked(wtoken,
3546 ActivityInfo.CONFIG_ORIENTATION);
3547 }
3548 }
3549 config = computeNewConfigurationLocked();
3550
3551 } else if (currentConfig != null) {
3552 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003553 // state mismatches the activity manager's, update it,
3554 // disregarding font scale, which should remain set to
3555 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003556 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003557 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003558 if (computeNewConfigurationLocked(mTempConfiguration)) {
3559 if (currentConfig.diff(mTempConfiguration) != 0) {
3560 mWaitingForConfig = true;
3561 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003562 startFreezingDisplayLocked(false);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003563 config = new Configuration(mTempConfiguration);
3564 }
3565 }
3566 }
3567 }
3568
Dianne Hackborncfaef692009-06-15 14:24:44 -07003569 Binder.restoreCallingIdentity(ident);
3570 return config;
3571 }
3572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003573 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003574 * Determine the new desired orientation of the display, returning
3575 * a non-null new Configuration if it has changed from the current
3576 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3577 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3578 * SCREEN. This will typically be done for you if you call
3579 * sendNewConfiguration().
3580 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 * The orientation is computed from non-application windows first. If none of
3582 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003583 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3585 * android.os.IBinder)
3586 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003587 boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
3588 if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
Christopher Tateb696aee2010-04-02 19:08:30 -07003589 // If the display is frozen, some activities may be in the middle
3590 // of restarting, and thus have removed their old window. If the
3591 // window has the flag to hide the lock screen, then the lock screen
3592 // can re-appear and inflict its own orientation on us. Keep the
3593 // orientation stable until this all settles down.
3594 return false;
3595 }
3596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 long ident = Binder.clearCallingIdentity();
3599 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003600 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 mForcedAppOrientation = req;
3604 //send a message to Policy indicating orientation change to take
3605 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003606 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003607 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08003608 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE,
3609 inTransaction)) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003610 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 }
3612 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003613
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003614 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 } finally {
3616 Binder.restoreCallingIdentity(ident);
3617 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 }
Romain Guy06882f82009-06-10 13:36:04 -07003619
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003620 int computeForcedAppOrientationLocked() {
3621 int req = getOrientationFromWindowsLocked();
3622 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3623 req = getOrientationFromAppTokensLocked();
3624 }
3625 return req;
3626 }
Romain Guy06882f82009-06-10 13:36:04 -07003627
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003628 public void setNewConfiguration(Configuration config) {
3629 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3630 "setNewConfiguration()")) {
3631 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3632 }
3633
3634 synchronized(mWindowMap) {
3635 mCurConfiguration = new Configuration(config);
3636 mWaitingForConfig = false;
3637 performLayoutAndPlaceSurfacesLocked();
3638 }
3639 }
3640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3642 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3643 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003644 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 }
Romain Guy06882f82009-06-10 13:36:04 -07003646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647 synchronized(mWindowMap) {
3648 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3649 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003650 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 return;
3652 }
Romain Guy06882f82009-06-10 13:36:04 -07003653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 wtoken.requestedOrientation = requestedOrientation;
3655 }
3656 }
Romain Guy06882f82009-06-10 13:36:04 -07003657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 public int getAppOrientation(IApplicationToken token) {
3659 synchronized(mWindowMap) {
3660 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3661 if (wtoken == null) {
3662 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3663 }
Romain Guy06882f82009-06-10 13:36:04 -07003664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 return wtoken.requestedOrientation;
3666 }
3667 }
Romain Guy06882f82009-06-10 13:36:04 -07003668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3670 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3671 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003672 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 }
3674
3675 synchronized(mWindowMap) {
3676 boolean changed = false;
3677 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003678 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 changed = mFocusedApp != null;
3680 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003681 if (changed) {
3682 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 } else {
3685 AppWindowToken newFocus = findAppWindowToken(token);
3686 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003687 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 return;
3689 }
3690 changed = mFocusedApp != newFocus;
3691 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003692 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003693 if (changed) {
3694 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003695 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 }
3697
3698 if (moveFocusNow && changed) {
3699 final long origId = Binder.clearCallingIdentity();
Jeff Brown3a22cd92011-01-21 13:59:04 -08003700 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 Binder.restoreCallingIdentity(origId);
3702 }
3703 }
3704 }
3705
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003706 public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3708 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003709 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 }
Romain Guy06882f82009-06-10 13:36:04 -07003711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003713 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 TAG, "Prepare app transition: transit=" + transit
3715 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003716 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003717 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3718 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 mNextAppTransition = transit;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08003720 } else if (!alwaysKeepCurrent) {
3721 if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3722 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3723 // Opening a new task always supersedes a close for the anim.
3724 mNextAppTransition = transit;
3725 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3726 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3727 // Opening a new activity always supersedes a close for the anim.
3728 mNextAppTransition = transit;
3729 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 }
3731 mAppTransitionReady = false;
3732 mAppTransitionTimeout = false;
3733 mStartingIconInTransition = false;
3734 mSkipAppTransitionAnimation = false;
3735 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3736 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3737 5000);
3738 }
3739 }
3740 }
3741
3742 public int getPendingAppTransition() {
3743 return mNextAppTransition;
3744 }
Romain Guy06882f82009-06-10 13:36:04 -07003745
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003746 public void overridePendingAppTransition(String packageName,
3747 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003748 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003749 mNextAppTransitionPackage = packageName;
3750 mNextAppTransitionEnter = enterAnim;
3751 mNextAppTransitionExit = exitAnim;
3752 }
3753 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 public void executeAppTransition() {
3756 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3757 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003758 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 }
Romain Guy06882f82009-06-10 13:36:04 -07003760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003762 if (DEBUG_APP_TRANSITIONS) {
3763 RuntimeException e = new RuntimeException("here");
3764 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003765 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003766 + mNextAppTransition, e);
3767 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003768 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003769 mAppTransitionReady = true;
3770 final long origId = Binder.clearCallingIdentity();
3771 performLayoutAndPlaceSurfacesLocked();
3772 Binder.restoreCallingIdentity(origId);
3773 }
3774 }
3775 }
3776
3777 public void setAppStartingWindow(IBinder token, String pkg,
3778 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003779 int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3781 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003782 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 }
3784
3785 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003786 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3788 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 AppWindowToken wtoken = findAppWindowToken(token);
3791 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003792 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 return;
3794 }
3795
3796 // If the display is frozen, we won't do anything until the
3797 // actual window is displayed so there is no reason to put in
3798 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003799 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 return;
3801 }
Romain Guy06882f82009-06-10 13:36:04 -07003802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 if (wtoken.startingData != null) {
3804 return;
3805 }
Romain Guy06882f82009-06-10 13:36:04 -07003806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 if (transferFrom != null) {
3808 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3809 if (ttoken != null) {
3810 WindowState startingWindow = ttoken.startingWindow;
3811 if (startingWindow != null) {
3812 if (mStartingIconInTransition) {
3813 // In this case, the starting icon has already
3814 // been displayed, so start letting windows get
3815 // shown immediately without any more transitions.
3816 mSkipAppTransitionAnimation = true;
3817 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003818 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 "Moving existing starting from " + ttoken
3820 + " to " + wtoken);
3821 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 // Transfer the starting window over to the new
3824 // token.
3825 wtoken.startingData = ttoken.startingData;
3826 wtoken.startingView = ttoken.startingView;
3827 wtoken.startingWindow = startingWindow;
3828 ttoken.startingData = null;
3829 ttoken.startingView = null;
3830 ttoken.startingWindow = null;
3831 ttoken.startingMoved = true;
3832 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003833 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 startingWindow.mAppToken = wtoken;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003835 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003836 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003838 mWindowsChanged = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08003839 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow
3840 + " from " + ttoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 ttoken.windows.remove(startingWindow);
3842 ttoken.allAppWindows.remove(startingWindow);
3843 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 // Propagate other interesting state between the
3846 // tokens. If the old token is displayed, we should
3847 // immediately force the new one to be displayed. If
3848 // it is animating, we need to move that animation to
3849 // the new one.
3850 if (ttoken.allDrawn) {
3851 wtoken.allDrawn = true;
3852 }
3853 if (ttoken.firstWindowDrawn) {
3854 wtoken.firstWindowDrawn = true;
3855 }
3856 if (!ttoken.hidden) {
3857 wtoken.hidden = false;
3858 wtoken.hiddenRequested = false;
3859 wtoken.willBeHidden = false;
3860 }
3861 if (wtoken.clientHidden != ttoken.clientHidden) {
3862 wtoken.clientHidden = ttoken.clientHidden;
3863 wtoken.sendAppVisibilityToClients();
3864 }
3865 if (ttoken.animation != null) {
3866 wtoken.animation = ttoken.animation;
3867 wtoken.animating = ttoken.animating;
3868 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3869 ttoken.animation = null;
3870 ttoken.animLayerAdjustment = 0;
3871 wtoken.updateLayers();
3872 ttoken.updateLayers();
3873 }
Romain Guy06882f82009-06-10 13:36:04 -07003874
Jeff Brown3a22cd92011-01-21 13:59:04 -08003875 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
3876 true /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003877 mLayoutNeeded = true;
3878 performLayoutAndPlaceSurfacesLocked();
3879 Binder.restoreCallingIdentity(origId);
3880 return;
3881 } else if (ttoken.startingData != null) {
3882 // The previous app was getting ready to show a
3883 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003884 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 "Moving pending starting from " + ttoken
3886 + " to " + wtoken);
3887 wtoken.startingData = ttoken.startingData;
3888 ttoken.startingData = null;
3889 ttoken.startingMoved = true;
3890 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3891 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3892 // want to process the message ASAP, before any other queued
3893 // messages.
3894 mH.sendMessageAtFrontOfQueue(m);
3895 return;
3896 }
3897 }
3898 }
3899
3900 // There is no existing starting window, and the caller doesn't
3901 // want us to create one, so that's it!
3902 if (!createIfNeeded) {
3903 return;
3904 }
Romain Guy06882f82009-06-10 13:36:04 -07003905
Dianne Hackborn284ac932009-08-28 10:34:25 -07003906 // If this is a translucent or wallpaper window, then don't
3907 // show a starting window -- the current effect (a full-screen
3908 // opaque starting window that fades away to the real contents
3909 // when it is ready) does not work for this.
3910 if (theme != 0) {
3911 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3912 com.android.internal.R.styleable.Window);
3913 if (ent.array.getBoolean(
3914 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3915 return;
3916 }
3917 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003918 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3919 return;
3920 }
3921 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003922 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3923 return;
3924 }
3925 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 mStartingIconInTransition = true;
3928 wtoken.startingData = new StartingData(
3929 pkg, theme, nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08003930 labelRes, icon, windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3932 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3933 // want to process the message ASAP, before any other queued
3934 // messages.
3935 mH.sendMessageAtFrontOfQueue(m);
3936 }
3937 }
3938
3939 public void setAppWillBeHidden(IBinder token) {
3940 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3941 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003942 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 }
3944
3945 AppWindowToken wtoken;
3946
3947 synchronized(mWindowMap) {
3948 wtoken = findAppWindowToken(token);
3949 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003950 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 -08003951 return;
3952 }
3953 wtoken.willBeHidden = true;
3954 }
3955 }
Romain Guy06882f82009-06-10 13:36:04 -07003956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3958 boolean visible, int transit, boolean performLayout) {
3959 boolean delayed = false;
3960
3961 if (wtoken.clientHidden == visible) {
3962 wtoken.clientHidden = !visible;
3963 wtoken.sendAppVisibilityToClients();
3964 }
Romain Guy06882f82009-06-10 13:36:04 -07003965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 wtoken.willBeHidden = false;
3967 if (wtoken.hidden == visible) {
3968 final int N = wtoken.allAppWindows.size();
3969 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003970 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3972 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003975
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003976 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 if (wtoken.animation == sDummyAnimation) {
3978 wtoken.animation = null;
3979 }
3980 applyAnimationLocked(wtoken, lp, transit, visible);
3981 changed = true;
3982 if (wtoken.animation != null) {
3983 delayed = runningAppAnimation = true;
3984 }
3985 }
Romain Guy06882f82009-06-10 13:36:04 -07003986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 for (int i=0; i<N; i++) {
3988 WindowState win = wtoken.allAppWindows.get(i);
3989 if (win == wtoken.startingWindow) {
3990 continue;
3991 }
3992
3993 if (win.isAnimating()) {
3994 delayed = true;
3995 }
Romain Guy06882f82009-06-10 13:36:04 -07003996
Joe Onorato8a9b2202010-02-26 18:56:32 -08003997 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 //win.dump(" ");
3999 if (visible) {
4000 if (!win.isVisibleNow()) {
4001 if (!runningAppAnimation) {
4002 applyAnimationLocked(win,
4003 WindowManagerPolicy.TRANSIT_ENTER, true);
4004 }
4005 changed = true;
4006 }
4007 } else if (win.isVisibleNow()) {
4008 if (!runningAppAnimation) {
4009 applyAnimationLocked(win,
4010 WindowManagerPolicy.TRANSIT_EXIT, false);
4011 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 changed = true;
4013 }
4014 }
4015
4016 wtoken.hidden = wtoken.hiddenRequested = !visible;
4017 if (!visible) {
4018 unsetAppFreezingScreenLocked(wtoken, true, true);
4019 } else {
4020 // If we are being set visible, and the starting window is
4021 // not yet displayed, then make sure it doesn't get displayed.
4022 WindowState swin = wtoken.startingWindow;
4023 if (swin != null && (swin.mDrawPending
4024 || swin.mCommitDrawPending)) {
4025 swin.mPolicyVisibility = false;
4026 swin.mPolicyVisibilityAfterAnim = false;
4027 }
4028 }
Romain Guy06882f82009-06-10 13:36:04 -07004029
Joe Onorato8a9b2202010-02-26 18:56:32 -08004030 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 + ": hidden=" + wtoken.hidden + " hiddenRequested="
4032 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07004033
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004034 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 mLayoutNeeded = true;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004036 mInputMonitor.setUpdateInputWindowsNeededLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004037 if (performLayout) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08004038 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4039 false /*updateInputWindows*/);
Dianne Hackborn9b52a212009-12-11 14:51:35 -08004040 performLayoutAndPlaceSurfacesLocked();
4041 }
Jeff Brown2e44b072011-01-24 15:21:56 -08004042 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004043 }
4044 }
4045
4046 if (wtoken.animation != null) {
4047 delayed = true;
4048 }
Romain Guy06882f82009-06-10 13:36:04 -07004049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 return delayed;
4051 }
4052
4053 public void setAppVisibility(IBinder token, boolean visible) {
4054 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4055 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004056 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 }
4058
4059 AppWindowToken wtoken;
4060
4061 synchronized(mWindowMap) {
4062 wtoken = findAppWindowToken(token);
4063 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004064 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004065 return;
4066 }
4067
4068 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004069 RuntimeException e = null;
4070 if (!HIDE_STACK_CRAWLS) {
4071 e = new RuntimeException();
4072 e.fillInStackTrace();
4073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004074 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 + "): mNextAppTransition=" + mNextAppTransition
4076 + " hidden=" + wtoken.hidden
4077 + " hiddenRequested=" + wtoken.hiddenRequested, e);
4078 }
Romain Guy06882f82009-06-10 13:36:04 -07004079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080 // If we are preparing an app transition, then delay changing
4081 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004082 if (!mDisplayFrozen && mPolicy.isScreenOn()
4083 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 // Already in requested state, don't do anything more.
4085 if (wtoken.hiddenRequested != visible) {
4086 return;
4087 }
4088 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07004089
Joe Onorato8a9b2202010-02-26 18:56:32 -08004090 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004091 TAG, "Setting dummy animation on: " + wtoken);
4092 wtoken.setDummyAnimation();
4093 mOpeningApps.remove(wtoken);
4094 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004095 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 wtoken.inPendingTransaction = true;
4097 if (visible) {
4098 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 wtoken.startingDisplayed = false;
4100 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004101
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004102 // If the token is currently hidden (should be the
4103 // common case), then we need to set up to wait for
4104 // its windows to be ready.
4105 if (wtoken.hidden) {
4106 wtoken.allDrawn = false;
4107 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004108
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004109 if (wtoken.clientHidden) {
4110 // In the case where we are making an app visible
4111 // but holding off for a transition, we still need
4112 // to tell the client to make its windows visible so
4113 // they get drawn. Otherwise, we will wait on
4114 // performing the transition until all windows have
4115 // been drawn, they never will be, and we are sad.
4116 wtoken.clientHidden = false;
4117 wtoken.sendAppVisibilityToClients();
4118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 }
4120 } else {
4121 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004122
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004123 // If the token is currently visible (should be the
4124 // common case), then set up to wait for it to be hidden.
4125 if (!wtoken.hidden) {
4126 wtoken.waitingToHide = true;
4127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004128 }
4129 return;
4130 }
Romain Guy06882f82009-06-10 13:36:04 -07004131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004133 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004134 wtoken.updateReportedVisibilityLocked();
4135 Binder.restoreCallingIdentity(origId);
4136 }
4137 }
4138
4139 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4140 boolean unfreezeSurfaceNow, boolean force) {
4141 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004142 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004143 + " force=" + force);
4144 final int N = wtoken.allAppWindows.size();
4145 boolean unfrozeWindows = false;
4146 for (int i=0; i<N; i++) {
4147 WindowState w = wtoken.allAppWindows.get(i);
4148 if (w.mAppFreezing) {
4149 w.mAppFreezing = false;
4150 if (w.mSurface != null && !w.mOrientationChanging) {
4151 w.mOrientationChanging = true;
4152 }
4153 unfrozeWindows = true;
4154 }
4155 }
4156 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004157 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 wtoken.freezingScreen = false;
4159 mAppsFreezingScreen--;
4160 }
4161 if (unfreezeSurfaceNow) {
4162 if (unfrozeWindows) {
4163 mLayoutNeeded = true;
4164 performLayoutAndPlaceSurfacesLocked();
4165 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004166 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004167 }
4168 }
4169 }
Romain Guy06882f82009-06-10 13:36:04 -07004170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4172 int configChanges) {
4173 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004174 RuntimeException e = null;
4175 if (!HIDE_STACK_CRAWLS) {
4176 e = new RuntimeException();
4177 e.fillInStackTrace();
4178 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004179 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 + ": hidden=" + wtoken.hidden + " freezing="
4181 + wtoken.freezingScreen, e);
4182 }
4183 if (!wtoken.hiddenRequested) {
4184 if (!wtoken.freezingScreen) {
4185 wtoken.freezingScreen = true;
4186 mAppsFreezingScreen++;
4187 if (mAppsFreezingScreen == 1) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004188 startFreezingDisplayLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4190 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4191 5000);
4192 }
4193 }
4194 final int N = wtoken.allAppWindows.size();
4195 for (int i=0; i<N; i++) {
4196 WindowState w = wtoken.allAppWindows.get(i);
4197 w.mAppFreezing = true;
4198 }
4199 }
4200 }
Romain Guy06882f82009-06-10 13:36:04 -07004201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 public void startAppFreezingScreen(IBinder token, int configChanges) {
4203 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4204 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004205 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004206 }
4207
4208 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004209 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004210 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 return;
4212 }
Romain Guy06882f82009-06-10 13:36:04 -07004213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004214 AppWindowToken wtoken = findAppWindowToken(token);
4215 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004216 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 return;
4218 }
4219 final long origId = Binder.clearCallingIdentity();
4220 startAppFreezingScreenLocked(wtoken, configChanges);
4221 Binder.restoreCallingIdentity(origId);
4222 }
4223 }
Romain Guy06882f82009-06-10 13:36:04 -07004224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225 public void stopAppFreezingScreen(IBinder token, boolean force) {
4226 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4227 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004228 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004229 }
4230
4231 synchronized(mWindowMap) {
4232 AppWindowToken wtoken = findAppWindowToken(token);
4233 if (wtoken == null || wtoken.appToken == null) {
4234 return;
4235 }
4236 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004237 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4239 unsetAppFreezingScreenLocked(wtoken, true, force);
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 removeAppToken(IBinder token) {
4245 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4246 "removeAppToken()")) {
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 AppWindowToken wtoken = null;
4251 AppWindowToken startingToken = null;
4252 boolean delayed = false;
4253
4254 final long origId = Binder.clearCallingIdentity();
4255 synchronized(mWindowMap) {
4256 WindowToken basewtoken = mTokenMap.remove(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004258 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004259 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 wtoken.inPendingTransaction = false;
4261 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004262 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004263 if (mClosingApps.contains(wtoken)) {
4264 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004265 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004267 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 delayed = true;
4269 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004270 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 TAG, "Removing app " + wtoken + " delayed=" + delayed
4272 + " animation=" + wtoken.animation
4273 + " animating=" + wtoken.animating);
4274 if (delayed) {
4275 // set the token aside because it has an active animation to be finished
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004276 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4277 "removeAppToken make exiting: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004279 } else {
4280 // Make sure there is no animation running on this token,
4281 // so any windows associated with it will be removed as
4282 // soon as their animations are complete
4283 wtoken.animation = null;
4284 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004286 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4287 "removeAppToken: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 mAppTokens.remove(wtoken);
4289 wtoken.removed = true;
4290 if (wtoken.startingData != null) {
4291 startingToken = wtoken;
4292 }
4293 unsetAppFreezingScreenLocked(wtoken, true, true);
4294 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004295 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 mFocusedApp = null;
Jeff Brown3a22cd92011-01-21 13:59:04 -08004297 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004298 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 }
4300 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004301 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 }
Romain Guy06882f82009-06-10 13:36:04 -07004303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 if (!delayed && wtoken != null) {
4305 wtoken.updateReportedVisibilityLocked();
4306 }
4307 }
4308 Binder.restoreCallingIdentity(origId);
4309
4310 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004311 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 + startingToken + ": app token removed");
4313 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4314 mH.sendMessage(m);
4315 }
4316 }
4317
4318 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4319 final int NW = token.windows.size();
4320 for (int i=0; i<NW; i++) {
4321 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004322 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004324 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 int j = win.mChildWindows.size();
4326 while (j > 0) {
4327 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004328 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004329 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004330 "Tmp removing child window " + cwin);
4331 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
4333 }
4334 return NW > 0;
4335 }
4336
4337 void dumpAppTokensLocked() {
4338 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004339 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004340 }
4341 }
Romain Guy06882f82009-06-10 13:36:04 -07004342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 void dumpWindowsLocked() {
4344 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004345 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 }
4347 }
Romain Guy06882f82009-06-10 13:36:04 -07004348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 private int findWindowOffsetLocked(int tokenPos) {
4350 final int NW = mWindows.size();
4351
4352 if (tokenPos >= mAppTokens.size()) {
4353 int i = NW;
4354 while (i > 0) {
4355 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004356 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 if (win.getAppToken() != null) {
4358 return i+1;
4359 }
4360 }
4361 }
4362
4363 while (tokenPos > 0) {
4364 // Find the first app token below the new position that has
4365 // a window displayed.
4366 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004367 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004369 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004370 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004371 "Skipping token -- currently sending to bottom");
4372 tokenPos--;
4373 continue;
4374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004375 int i = wtoken.windows.size();
4376 while (i > 0) {
4377 i--;
4378 WindowState win = wtoken.windows.get(i);
4379 int j = win.mChildWindows.size();
4380 while (j > 0) {
4381 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004382 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004383 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 for (int pos=NW-1; pos>=0; pos--) {
4385 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004386 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 "Found child win @" + (pos+1));
4388 return pos+1;
4389 }
4390 }
4391 }
4392 }
4393 for (int pos=NW-1; pos>=0; pos--) {
4394 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004395 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 return pos+1;
4397 }
4398 }
4399 }
4400 tokenPos--;
4401 }
4402
4403 return 0;
4404 }
4405
4406 private final int reAddWindowLocked(int index, WindowState win) {
4407 final int NCW = win.mChildWindows.size();
4408 boolean added = false;
4409 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004410 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004412 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004413 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004414 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 mWindows.add(index, win);
4416 index++;
4417 added = true;
4418 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004419 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004420 + index + ": " + cwin);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004421 cwin.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422 mWindows.add(index, cwin);
4423 index++;
4424 }
4425 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004426 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004427 + index + ": " + win);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004428 win.mRebuilding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004429 mWindows.add(index, win);
4430 index++;
4431 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004432 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 return index;
4434 }
Romain Guy06882f82009-06-10 13:36:04 -07004435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4437 final int NW = token.windows.size();
4438 for (int i=0; i<NW; i++) {
4439 index = reAddWindowLocked(index, token.windows.get(i));
4440 }
4441 return index;
4442 }
4443
4444 public void moveAppToken(int index, IBinder token) {
4445 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4446 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004447 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 }
4449
4450 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004451 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452 if (DEBUG_REORDER) dumpAppTokensLocked();
4453 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004454 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4455 "Start moving token " + wtoken + " initially at "
4456 + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004458 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 + token + " (" + wtoken + ")");
4460 return;
4461 }
4462 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004463 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004464 else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004465 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004468 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 if (DEBUG_REORDER) dumpWindowsLocked();
4470 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004471 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 if (DEBUG_REORDER) dumpWindowsLocked();
4473 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004474 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 if (DEBUG_REORDER) dumpWindowsLocked();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004476 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4477 false /*updateInputWindows*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 mLayoutNeeded = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08004479 mInputMonitor.setUpdateInputWindowsNeededLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004481 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 }
4483 Binder.restoreCallingIdentity(origId);
4484 }
4485 }
4486
4487 private void removeAppTokensLocked(List<IBinder> tokens) {
4488 // XXX This should be done more efficiently!
4489 // (take advantage of the fact that both lists should be
4490 // ordered in the same way.)
4491 int N = tokens.size();
4492 for (int i=0; i<N; i++) {
4493 IBinder token = tokens.get(i);
4494 final AppWindowToken wtoken = findAppWindowToken(token);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004495 if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4496 "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004498 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 + token + " (" + wtoken + ")");
4500 i--;
4501 N--;
4502 }
4503 }
4504 }
4505
Dianne Hackborna8f60182009-09-01 19:01:50 -07004506 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4507 boolean updateFocusAndLayout) {
4508 // First remove all of the windows from the list.
4509 tmpRemoveAppWindowsLocked(wtoken);
4510
4511 // Where to start adding?
4512 int pos = findWindowOffsetLocked(tokenPos);
4513
4514 // And now add them back at the correct place.
4515 pos = reAddAppWindowsLocked(pos, wtoken);
4516
4517 if (updateFocusAndLayout) {
Jeff Brown2e44b072011-01-24 15:21:56 -08004518 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004519 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4520 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004521 assignLayersLocked();
4522 }
4523 mLayoutNeeded = true;
4524 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004525 mInputMonitor.updateInputWindowsLw(false /*force*/);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004526 }
4527 }
4528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4530 // First remove all of the windows from the list.
4531 final int N = tokens.size();
4532 int i;
4533 for (i=0; i<N; i++) {
4534 WindowToken token = mTokenMap.get(tokens.get(i));
4535 if (token != null) {
4536 tmpRemoveAppWindowsLocked(token);
4537 }
4538 }
4539
4540 // Where to start adding?
4541 int pos = findWindowOffsetLocked(tokenPos);
4542
4543 // And now add them back at the correct place.
4544 for (i=0; i<N; i++) {
4545 WindowToken token = mTokenMap.get(tokens.get(i));
4546 if (token != null) {
4547 pos = reAddAppWindowsLocked(pos, token);
4548 }
4549 }
4550
Jeff Brown2e44b072011-01-24 15:21:56 -08004551 mInputMonitor.setUpdateInputWindowsNeededLw();
Jeff Brown3a22cd92011-01-21 13:59:04 -08004552 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
4553 false /*updateInputWindows*/)) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004554 assignLayersLocked();
4555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004556 mLayoutNeeded = true;
4557 performLayoutAndPlaceSurfacesLocked();
Jeff Brown2e44b072011-01-24 15:21:56 -08004558 mInputMonitor.updateInputWindowsLw(false /*force*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004559
4560 //dump();
4561 }
4562
4563 public void moveAppTokensToTop(List<IBinder> tokens) {
4564 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4565 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004566 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004567 }
4568
4569 final long origId = Binder.clearCallingIdentity();
4570 synchronized(mWindowMap) {
4571 removeAppTokensLocked(tokens);
4572 final int N = tokens.size();
4573 for (int i=0; i<N; i++) {
4574 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4575 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004576 if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG,
4577 "Adding next to top: " + wt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004578 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004579 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004580 mToTopApps.remove(wt);
4581 mToBottomApps.remove(wt);
4582 mToTopApps.add(wt);
4583 wt.sendingToBottom = false;
4584 wt.sendingToTop = true;
4585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 }
4587 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004588
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004589 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004590 moveAppWindowsLocked(tokens, mAppTokens.size());
4591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 }
4593 Binder.restoreCallingIdentity(origId);
4594 }
4595
4596 public void moveAppTokensToBottom(List<IBinder> tokens) {
4597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4598 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004600 }
4601
4602 final long origId = Binder.clearCallingIdentity();
4603 synchronized(mWindowMap) {
4604 removeAppTokensLocked(tokens);
4605 final int N = tokens.size();
4606 int pos = 0;
4607 for (int i=0; i<N; i++) {
4608 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4609 if (wt != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004610 if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4611 "Adding next to bottom: " + wt + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004612 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004613 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004614 mToTopApps.remove(wt);
4615 mToBottomApps.remove(wt);
4616 mToBottomApps.add(i, wt);
4617 wt.sendingToTop = false;
4618 wt.sendingToBottom = true;
4619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 pos++;
4621 }
4622 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004623
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004624 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004625 moveAppWindowsLocked(tokens, 0);
4626 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 }
4628 Binder.restoreCallingIdentity(origId);
4629 }
4630
4631 // -------------------------------------------------------------
4632 // Misc IWindowSession methods
4633 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004634
Jim Miller284b62e2010-06-08 14:27:42 -07004635 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004636 {
Jim Miller284b62e2010-06-08 14:27:42 -07004637 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4638 // called before DevicePolicyManagerService has started.
4639 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4640 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4641 Context.DEVICE_POLICY_SERVICE);
4642 if (dpm != null) {
4643 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4644 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4645 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4646 }
Jim Millerd6b57052010-06-07 17:52:42 -07004647 }
Jim Miller284b62e2010-06-08 14:27:42 -07004648 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004649 }
4650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004652 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 != PackageManager.PERMISSION_GRANTED) {
4654 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4655 }
Jim Millerd6b57052010-06-07 17:52:42 -07004656
Jim Miller284b62e2010-06-08 14:27:42 -07004657 synchronized (mKeyguardTokenWatcher) {
4658 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004659 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 }
4661
4662 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004663 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 != PackageManager.PERMISSION_GRANTED) {
4665 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004667
Jim Miller284b62e2010-06-08 14:27:42 -07004668 synchronized (mKeyguardTokenWatcher) {
4669 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004670
Jim Miller284b62e2010-06-08 14:27:42 -07004671 if (!mKeyguardTokenWatcher.isAcquired()) {
4672 // If we are the last one to reenable the keyguard wait until
4673 // we have actually finished reenabling until returning.
4674 // It is possible that reenableKeyguard() can be called before
4675 // the previous disableKeyguard() is handled, in which case
4676 // neither mKeyguardTokenWatcher.acquired() or released() would
4677 // be called. In that case mKeyguardDisabled will be false here
4678 // and we have nothing to wait for.
4679 while (mKeyguardDisabled) {
4680 try {
4681 mKeyguardTokenWatcher.wait();
4682 } catch (InterruptedException e) {
4683 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 }
4685 }
4686 }
4687 }
4688 }
4689
4690 /**
4691 * @see android.app.KeyguardManager#exitKeyguardSecurely
4692 */
4693 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004694 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004695 != PackageManager.PERMISSION_GRANTED) {
4696 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4697 }
4698 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4699 public void onKeyguardExitResult(boolean success) {
4700 try {
4701 callback.onKeyguardExitResult(success);
4702 } catch (RemoteException e) {
4703 // Client has died, we don't care.
4704 }
4705 }
4706 });
4707 }
4708
4709 public boolean inKeyguardRestrictedInputMode() {
4710 return mPolicy.inKeyguardRestrictedKeyInputMode();
4711 }
Romain Guy06882f82009-06-10 13:36:04 -07004712
Dianne Hackbornffa42482009-09-23 22:20:11 -07004713 public void closeSystemDialogs(String reason) {
4714 synchronized(mWindowMap) {
4715 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004716 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004717 if (w.mSurface != null) {
4718 try {
4719 w.mClient.closeSystemDialogs(reason);
4720 } catch (RemoteException e) {
4721 }
4722 }
4723 }
4724 }
4725 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004727 static float fixScale(float scale) {
4728 if (scale < 0) scale = 0;
4729 else if (scale > 20) scale = 20;
4730 return Math.abs(scale);
4731 }
Romain Guy06882f82009-06-10 13:36:04 -07004732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004733 public void setAnimationScale(int which, float scale) {
4734 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4735 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004736 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 }
4738
4739 if (scale < 0) scale = 0;
4740 else if (scale > 20) scale = 20;
4741 scale = Math.abs(scale);
4742 switch (which) {
4743 case 0: mWindowAnimationScale = fixScale(scale); break;
4744 case 1: mTransitionAnimationScale = fixScale(scale); break;
4745 }
Romain Guy06882f82009-06-10 13:36:04 -07004746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004747 // Persist setting
4748 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4749 }
Romain Guy06882f82009-06-10 13:36:04 -07004750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004751 public void setAnimationScales(float[] scales) {
4752 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4753 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004754 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004755 }
4756
4757 if (scales != null) {
4758 if (scales.length >= 1) {
4759 mWindowAnimationScale = fixScale(scales[0]);
4760 }
4761 if (scales.length >= 2) {
4762 mTransitionAnimationScale = fixScale(scales[1]);
4763 }
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 float getAnimationScale(int which) {
4771 switch (which) {
4772 case 0: return mWindowAnimationScale;
4773 case 1: return mTransitionAnimationScale;
4774 }
4775 return 0;
4776 }
Romain Guy06882f82009-06-10 13:36:04 -07004777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 public float[] getAnimationScales() {
4779 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4780 }
Romain Guy06882f82009-06-10 13:36:04 -07004781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004782 public int getSwitchState(int sw) {
4783 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4784 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004785 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004786 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004787 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 public int getSwitchStateForDevice(int devid, int sw) {
4791 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4792 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004793 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004795 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 }
Romain Guy06882f82009-06-10 13:36:04 -07004797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 public int getScancodeState(int sw) {
4799 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4800 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004801 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004802 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004803 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 }
Romain Guy06882f82009-06-10 13:36:04 -07004805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004806 public int getScancodeStateForDevice(int devid, int sw) {
4807 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4808 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004809 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004811 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 }
Romain Guy06882f82009-06-10 13:36:04 -07004813
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004814 public int getTrackballScancodeState(int sw) {
4815 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4816 "getTrackballScancodeState()")) {
4817 throw new SecurityException("Requires READ_INPUT_STATE permission");
4818 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004819 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004820 }
4821
4822 public int getDPadScancodeState(int sw) {
4823 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4824 "getDPadScancodeState()")) {
4825 throw new SecurityException("Requires READ_INPUT_STATE permission");
4826 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004827 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004828 }
4829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830 public int getKeycodeState(int sw) {
4831 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4832 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004833 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004835 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004836 }
Romain Guy06882f82009-06-10 13:36:04 -07004837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004838 public int getKeycodeStateForDevice(int devid, int sw) {
4839 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4840 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004841 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004843 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004844 }
Romain Guy06882f82009-06-10 13:36:04 -07004845
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004846 public int getTrackballKeycodeState(int sw) {
4847 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4848 "getTrackballKeycodeState()")) {
4849 throw new SecurityException("Requires READ_INPUT_STATE permission");
4850 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004851 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004852 }
4853
4854 public int getDPadKeycodeState(int sw) {
4855 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4856 "getDPadKeycodeState()")) {
4857 throw new SecurityException("Requires READ_INPUT_STATE permission");
4858 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004859 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004860 }
Jeff Browna41ca772010-08-11 14:46:32 -07004861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004863 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 }
Romain Guy06882f82009-06-10 13:36:04 -07004865
Jeff Browna41ca772010-08-11 14:46:32 -07004866 public InputChannel monitorInput(String inputChannelName) {
4867 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4868 "monitorInput()")) {
4869 throw new SecurityException("Requires READ_INPUT_STATE permission");
4870 }
4871 return mInputManager.monitorInput(inputChannelName);
4872 }
4873
Jeff Brown8d608662010-08-30 03:02:23 -07004874 public InputDevice getInputDevice(int deviceId) {
4875 return mInputManager.getInputDevice(deviceId);
4876 }
4877
4878 public int[] getInputDeviceIds() {
4879 return mInputManager.getInputDeviceIds();
4880 }
4881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004882 public void enableScreenAfterBoot() {
4883 synchronized(mWindowMap) {
4884 if (mSystemBooted) {
4885 return;
4886 }
4887 mSystemBooted = true;
4888 }
Romain Guy06882f82009-06-10 13:36:04 -07004889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004890 performEnableScreen();
4891 }
Romain Guy06882f82009-06-10 13:36:04 -07004892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004893 public void enableScreenIfNeededLocked() {
4894 if (mDisplayEnabled) {
4895 return;
4896 }
4897 if (!mSystemBooted) {
4898 return;
4899 }
4900 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4901 }
Romain Guy06882f82009-06-10 13:36:04 -07004902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004903 public void performEnableScreen() {
4904 synchronized(mWindowMap) {
4905 if (mDisplayEnabled) {
4906 return;
4907 }
4908 if (!mSystemBooted) {
4909 return;
4910 }
Romain Guy06882f82009-06-10 13:36:04 -07004911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004912 // Don't enable the screen until all existing windows
4913 // have been drawn.
4914 final int N = mWindows.size();
4915 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004916 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004917 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004918 return;
4919 }
4920 }
Romain Guy06882f82009-06-10 13:36:04 -07004921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004922 mDisplayEnabled = true;
4923 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004924 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 StringWriter sw = new StringWriter();
4926 PrintWriter pw = new PrintWriter(sw);
4927 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004928 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 }
4930 try {
4931 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4932 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004933 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004934 Parcel data = Parcel.obtain();
4935 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4936 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4937 data, null, 0);
4938 data.recycle();
4939 }
4940 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004941 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004942 }
4943 }
Romain Guy06882f82009-06-10 13:36:04 -07004944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004945 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004948 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4949 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 }
Romain Guy06882f82009-06-10 13:36:04 -07004951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004952 public void setInTouchMode(boolean mode) {
4953 synchronized(mWindowMap) {
4954 mInTouchMode = mode;
4955 }
4956 }
4957
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004958 // TODO: more accounting of which pid(s) turned it on, keep count,
4959 // only allow disables from pids which have count on, etc.
4960 public void showStrictModeViolation(boolean on) {
4961 int pid = Binder.getCallingPid();
4962 synchronized(mWindowMap) {
4963 // Ignoring requests to enable the red border from clients
4964 // which aren't on screen. (e.g. Broadcast Receivers in
4965 // the background..)
4966 if (on) {
4967 boolean isVisible = false;
4968 for (WindowState ws : mWindows) {
4969 if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
4970 isVisible = true;
4971 break;
4972 }
4973 }
4974 if (!isVisible) {
4975 return;
4976 }
4977 }
4978
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004979 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004980 Surface.openTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08004981 try {
4982 if (mStrictModeFlash == null) {
4983 mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession);
4984 }
4985 mStrictModeFlash.setVisibility(on);
4986 } finally {
4987 Surface.closeTransaction();
4988 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation");
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004989 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08004990 }
4991 }
4992
Brad Fitzpatrickc1a968a2010-11-24 08:56:40 -08004993 public void setStrictModeVisualIndicatorPreference(String value) {
4994 SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
4995 }
4996
Dianne Hackbornd2835932010-12-13 16:28:46 -08004997 public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08004998 if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
4999 "screenshotApplications()")) {
5000 throw new SecurityException("Requires READ_FRAME_BUFFER permission");
5001 }
5002
5003 Bitmap rawss;
5004
Dianne Hackbornd2835932010-12-13 16:28:46 -08005005 int maxLayer = 0;
5006 boolean foundApp;
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005007 final Rect frame = new Rect();
5008
5009 float scale;
5010 int sw, sh, dw, dh;
5011 int rot;
5012
5013 synchronized(mWindowMap) {
5014 long ident = Binder.clearCallingIdentity();
5015
5016 int aboveAppLayer = mPolicy.windowTypeToLayerLw(
5017 WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER
5018 + TYPE_LAYER_OFFSET;
5019 aboveAppLayer += TYPE_LAYER_MULTIPLIER;
5020
5021 // Figure out the part of the screen that is actually the app.
5022 for (int i=0; i<mWindows.size(); i++) {
5023 WindowState ws = mWindows.get(i);
5024 if (ws.mSurface == null) {
5025 continue;
5026 }
5027 if (ws.mLayer >= aboveAppLayer) {
5028 break;
5029 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005030 if (appToken != null && (ws.mAppToken == null
5031 || ws.mAppToken.token != appToken)) {
5032 continue;
5033 }
5034 if (maxLayer < ws.mAnimLayer) {
5035 maxLayer = ws.mAnimLayer;
5036 }
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005037 final Rect wf = ws.mFrame;
5038 final Rect cr = ws.mContentInsets;
5039 int left = wf.left + cr.left;
5040 int top = wf.top + cr.top;
5041 int right = wf.right - cr.right;
5042 int bottom = wf.bottom - cr.bottom;
5043 frame.union(left, top, right, bottom);
5044 }
5045 Binder.restoreCallingIdentity(ident);
5046
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005047 if (frame.isEmpty() || maxLayer == 0) {
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005048 return null;
5049 }
5050
5051 // The screenshot API does not apply the current screen rotation.
5052 rot = mDisplay.getRotation();
5053 int fw = frame.width();
5054 int fh = frame.height();
5055
5056 // First try reducing to fit in x dimension.
5057 scale = maxWidth/(float)fw;
5058 sw = maxWidth;
5059 sh = (int)(fh*scale);
5060 if (sh > maxHeight) {
5061 // y dimension became too long; constrain by that.
5062 scale = maxHeight/(float)fh;
5063 sw = (int)(fw*scale);
5064 sh = maxHeight;
5065 }
5066
5067 // The screen shot will contain the entire screen.
5068 dw = (int)(mDisplay.getWidth()*scale);
5069 dh = (int)(mDisplay.getHeight()*scale);
5070 if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
5071 int tmp = dw;
5072 dw = dh;
5073 dh = tmp;
5074 rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
5075 }
Dianne Hackbornd2835932010-12-13 16:28:46 -08005076 rawss = Surface.screenshot(dw, dh, 0, maxLayer);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005077 }
5078
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005079 if (rawss == null) {
Dianne Hackborn88b03bd2010-12-16 11:15:18 -08005080 Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh
5081 + ") to layer " + maxLayer);
Dianne Hackborncb8f0e02010-12-16 11:15:18 -08005082 return null;
5083 }
5084
Dianne Hackborn0aae2d42010-12-07 23:51:29 -08005085 Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig());
5086 Matrix matrix = new Matrix();
5087 ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
5088 matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale));
5089 Canvas canvas = new Canvas(bm);
5090 canvas.drawBitmap(rawss, matrix, null);
5091
5092 rawss.recycle();
5093 return bm;
5094 }
5095
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005096 public void freezeRotation() {
5097 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5098 "setRotation()")) {
5099 throw new SecurityException("Requires SET_ORIENTATION permission");
5100 }
5101
5102 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5103 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5104 }
5105
5106 public void thawRotation() {
5107 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
5108 "setRotation()")) {
5109 throw new SecurityException("Requires SET_ORIENTATION permission");
5110 }
5111
5112 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
5113 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
5114 }
5115
Romain Guy06882f82009-06-10 13:36:04 -07005116 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005117 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005118 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005119 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005120 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005121 }
5122
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005123 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 }
Romain Guy06882f82009-06-10 13:36:04 -07005125
Dianne Hackborn1e880db2009-03-27 16:04:08 -07005126 public void setRotationUnchecked(int rotation,
5127 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005128 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005129 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07005130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005131 long origId = Binder.clearCallingIdentity();
5132 boolean changed;
5133 synchronized(mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005134 changed = setRotationUncheckedLocked(rotation, animFlags, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005135 }
Romain Guy06882f82009-06-10 13:36:04 -07005136
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005137 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005138 sendNewConfiguration();
5139 }
Romain Guy06882f82009-06-10 13:36:04 -07005140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005141 Binder.restoreCallingIdentity(origId);
5142 }
Romain Guy06882f82009-06-10 13:36:04 -07005143
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005144 /**
5145 * Apply a new rotation to the screen, respecting the requests of
5146 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
5147 * re-evaluate the desired rotation.
5148 *
5149 * Returns null if the rotation has been changed. In this case YOU
5150 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
5151 */
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005152 public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005153 if (mDragState != null || mScreenRotationAnimation != null) {
Christopher Tateccd24de2011-01-12 15:02:55 -08005154 // Potential rotation during a drag. Don't do the rotation now, but make
5155 // a note to perform the rotation later.
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005156 if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation.");
5157 if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5158 mDeferredRotation = rotation;
5159 mDeferredRotationAnimFlags = animFlags;
5160 }
Christopher Tateccd24de2011-01-12 15:02:55 -08005161 return false;
5162 }
5163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005164 boolean changed;
5165 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005166 if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) {
5167 rotation = mDeferredRotation;
5168 mRequestedRotation = rotation;
5169 mLastRotationFlags = mDeferredRotationAnimFlags;
5170 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005171 rotation = mRequestedRotation;
5172 } else {
5173 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07005174 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005175 }
Dianne Hackborn89ba6752011-01-23 16:51:16 -08005176 mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005177 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005178 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005180 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005181 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07005182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005183 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005184 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005185 "Rotation changed to " + rotation
5186 + " from " + mRotation
5187 + " (forceApp=" + mForcedAppOrientation
5188 + ", req=" + mRequestedRotation + ")");
5189 mRotation = rotation;
5190 mWindowsFreezingScreen = true;
5191 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
5192 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
5193 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005194 mWaitingForConfig = true;
5195 mLayoutNeeded = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005196 startFreezingDisplayLocked(inTransaction);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005197 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005198 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005199 if (mDisplayEnabled) {
Dianne Hackborna1111872010-11-23 20:55:11 -08005200 if (CUSTOM_SCREEN_ROTATION) {
5201 Surface.freezeDisplay(0);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005202 if (!inTransaction) {
5203 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5204 ">>> OPEN TRANSACTION setRotationUnchecked");
5205 Surface.openTransaction();
Dianne Hackborna1111872010-11-23 20:55:11 -08005206 }
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005207 try {
5208 if (mScreenRotationAnimation != null) {
5209 mScreenRotationAnimation.setRotation(rotation);
5210 }
5211 } finally {
5212 if (!inTransaction) {
5213 Surface.closeTransaction();
5214 if (SHOW_TRANSACTIONS) Slog.i(TAG,
5215 "<<< CLOSE TRANSACTION setRotationUnchecked");
5216 }
5217 }
Dianne Hackborna1111872010-11-23 20:55:11 -08005218 Surface.setOrientation(0, rotation, animFlags);
5219 Surface.unfreezeDisplay(0);
5220 } else {
5221 Surface.setOrientation(0, rotation, animFlags);
5222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005223 }
5224 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005225 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005226 if (w.mSurface != null) {
5227 w.mOrientationChanging = true;
5228 }
5229 }
5230 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
5231 try {
5232 mRotationWatchers.get(i).onRotationChanged(rotation);
5233 } catch (RemoteException e) {
5234 }
5235 }
5236 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07005237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 return changed;
5239 }
Romain Guy06882f82009-06-10 13:36:04 -07005240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 public int getRotation() {
5242 return mRotation;
5243 }
5244
5245 public int watchRotation(IRotationWatcher watcher) {
5246 final IBinder watcherBinder = watcher.asBinder();
5247 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
5248 public void binderDied() {
5249 synchronized (mWindowMap) {
5250 for (int i=0; i<mRotationWatchers.size(); i++) {
5251 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005252 IRotationWatcher removed = mRotationWatchers.remove(i);
5253 if (removed != null) {
5254 removed.asBinder().unlinkToDeath(this, 0);
5255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 i--;
5257 }
5258 }
5259 }
5260 }
5261 };
Romain Guy06882f82009-06-10 13:36:04 -07005262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005263 synchronized (mWindowMap) {
5264 try {
5265 watcher.asBinder().linkToDeath(dr, 0);
5266 mRotationWatchers.add(watcher);
5267 } catch (RemoteException e) {
5268 // Client died, no cleanup needed.
5269 }
Romain Guy06882f82009-06-10 13:36:04 -07005270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005271 return mRotation;
5272 }
5273 }
5274
5275 /**
5276 * Starts the view server on the specified port.
5277 *
5278 * @param port The port to listener to.
5279 *
5280 * @return True if the server was successfully started, false otherwise.
5281 *
5282 * @see com.android.server.ViewServer
5283 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
5284 */
5285 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07005286 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005287 return false;
5288 }
5289
5290 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5291 return false;
5292 }
5293
5294 if (port < 1024) {
5295 return false;
5296 }
5297
5298 if (mViewServer != null) {
5299 if (!mViewServer.isRunning()) {
5300 try {
5301 return mViewServer.start();
5302 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005303 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005304 }
5305 }
5306 return false;
5307 }
5308
5309 try {
5310 mViewServer = new ViewServer(this, port);
5311 return mViewServer.start();
5312 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005313 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005314 }
5315 return false;
5316 }
5317
Romain Guy06882f82009-06-10 13:36:04 -07005318 private boolean isSystemSecure() {
5319 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5320 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5321 }
5322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005323 /**
5324 * Stops the view server if it exists.
5325 *
5326 * @return True if the server stopped, false if it wasn't started or
5327 * couldn't be stopped.
5328 *
5329 * @see com.android.server.ViewServer
5330 */
5331 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005332 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333 return false;
5334 }
5335
5336 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5337 return false;
5338 }
5339
5340 if (mViewServer != null) {
5341 return mViewServer.stop();
5342 }
5343 return false;
5344 }
5345
5346 /**
5347 * Indicates whether the view server is running.
5348 *
5349 * @return True if the server is running, false otherwise.
5350 *
5351 * @see com.android.server.ViewServer
5352 */
5353 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005354 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355 return false;
5356 }
5357
5358 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5359 return false;
5360 }
5361
5362 return mViewServer != null && mViewServer.isRunning();
5363 }
5364
5365 /**
5366 * Lists all availble windows in the system. The listing is written in the
5367 * specified Socket's output stream with the following syntax:
5368 * windowHashCodeInHexadecimal windowName
5369 * Each line of the ouput represents a different window.
5370 *
5371 * @param client The remote client to send the listing to.
5372 * @return False if an error occured, true otherwise.
5373 */
5374 boolean viewServerListWindows(Socket client) {
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 boolean result = true;
5380
Jeff Browne33348b2010-07-15 23:54:05 -07005381 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005382 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005383 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005384 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005385 }
5386
5387 BufferedWriter out = null;
5388
5389 // Any uncaught exception will crash the system process
5390 try {
5391 OutputStream clientStream = client.getOutputStream();
5392 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5393
5394 final int count = windows.length;
5395 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005396 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005397 out.write(Integer.toHexString(System.identityHashCode(w)));
5398 out.write(' ');
5399 out.append(w.mAttrs.getTitle());
5400 out.write('\n');
5401 }
5402
5403 out.write("DONE.\n");
5404 out.flush();
5405 } catch (Exception e) {
5406 result = false;
5407 } finally {
5408 if (out != null) {
5409 try {
5410 out.close();
5411 } catch (IOException e) {
5412 result = false;
5413 }
5414 }
5415 }
5416
5417 return result;
5418 }
5419
5420 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005421 * Returns the focused window in the following format:
5422 * windowHashCodeInHexadecimal windowName
5423 *
5424 * @param client The remote client to send the listing to.
5425 * @return False if an error occurred, true otherwise.
5426 */
5427 boolean viewServerGetFocusedWindow(Socket client) {
5428 if (isSystemSecure()) {
5429 return false;
5430 }
5431
5432 boolean result = true;
5433
5434 WindowState focusedWindow = getFocusedWindow();
5435
5436 BufferedWriter out = null;
5437
5438 // Any uncaught exception will crash the system process
5439 try {
5440 OutputStream clientStream = client.getOutputStream();
5441 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5442
5443 if(focusedWindow != null) {
5444 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5445 out.write(' ');
5446 out.append(focusedWindow.mAttrs.getTitle());
5447 }
5448 out.write('\n');
5449 out.flush();
5450 } catch (Exception e) {
5451 result = false;
5452 } finally {
5453 if (out != null) {
5454 try {
5455 out.close();
5456 } catch (IOException e) {
5457 result = false;
5458 }
5459 }
5460 }
5461
5462 return result;
5463 }
5464
5465 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005466 * Sends a command to a target window. The result of the command, if any, will be
5467 * written in the output stream of the specified socket.
5468 *
5469 * The parameters must follow this syntax:
5470 * windowHashcode extra
5471 *
5472 * Where XX is the length in characeters of the windowTitle.
5473 *
5474 * The first parameter is the target window. The window with the specified hashcode
5475 * will be the target. If no target can be found, nothing happens. The extra parameters
5476 * will be delivered to the target window and as parameters to the command itself.
5477 *
5478 * @param client The remote client to sent the result, if any, to.
5479 * @param command The command to execute.
5480 * @param parameters The command parameters.
5481 *
5482 * @return True if the command was successfully delivered, false otherwise. This does
5483 * not indicate whether the command itself was successful.
5484 */
5485 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005486 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005487 return false;
5488 }
5489
5490 boolean success = true;
5491 Parcel data = null;
5492 Parcel reply = null;
5493
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005494 BufferedWriter out = null;
5495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 // Any uncaught exception will crash the system process
5497 try {
5498 // Find the hashcode of the window
5499 int index = parameters.indexOf(' ');
5500 if (index == -1) {
5501 index = parameters.length();
5502 }
5503 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005504 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005505
5506 // Extract the command's parameter after the window description
5507 if (index < parameters.length()) {
5508 parameters = parameters.substring(index + 1);
5509 } else {
5510 parameters = "";
5511 }
5512
5513 final WindowManagerService.WindowState window = findWindow(hashCode);
5514 if (window == null) {
5515 return false;
5516 }
5517
5518 data = Parcel.obtain();
5519 data.writeInterfaceToken("android.view.IWindow");
5520 data.writeString(command);
5521 data.writeString(parameters);
5522 data.writeInt(1);
5523 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5524
5525 reply = Parcel.obtain();
5526
5527 final IBinder binder = window.mClient.asBinder();
5528 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5529 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5530
5531 reply.readException();
5532
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005533 if (!client.isOutputShutdown()) {
5534 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5535 out.write("DONE\n");
5536 out.flush();
5537 }
5538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005540 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005541 success = false;
5542 } finally {
5543 if (data != null) {
5544 data.recycle();
5545 }
5546 if (reply != null) {
5547 reply.recycle();
5548 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005549 if (out != null) {
5550 try {
5551 out.close();
5552 } catch (IOException e) {
5553
5554 }
5555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005556 }
5557
5558 return success;
5559 }
5560
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005561 public void addWindowChangeListener(WindowChangeListener listener) {
5562 synchronized(mWindowMap) {
5563 mWindowChangeListeners.add(listener);
5564 }
5565 }
5566
5567 public void removeWindowChangeListener(WindowChangeListener listener) {
5568 synchronized(mWindowMap) {
5569 mWindowChangeListeners.remove(listener);
5570 }
5571 }
5572
5573 private void notifyWindowsChanged() {
5574 WindowChangeListener[] windowChangeListeners;
5575 synchronized(mWindowMap) {
5576 if(mWindowChangeListeners.isEmpty()) {
5577 return;
5578 }
5579 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5580 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5581 }
5582 int N = windowChangeListeners.length;
5583 for(int i = 0; i < N; i++) {
5584 windowChangeListeners[i].windowsChanged();
5585 }
5586 }
5587
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005588 private void notifyFocusChanged() {
5589 WindowChangeListener[] windowChangeListeners;
5590 synchronized(mWindowMap) {
5591 if(mWindowChangeListeners.isEmpty()) {
5592 return;
5593 }
5594 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5595 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5596 }
5597 int N = windowChangeListeners.length;
5598 for(int i = 0; i < N; i++) {
5599 windowChangeListeners[i].focusChanged();
5600 }
5601 }
5602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005603 private WindowState findWindow(int hashCode) {
5604 if (hashCode == -1) {
5605 return getFocusedWindow();
5606 }
5607
5608 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005609 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005610 final int count = windows.size();
5611
5612 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005613 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005614 if (System.identityHashCode(w) == hashCode) {
5615 return w;
5616 }
5617 }
5618 }
5619
5620 return null;
5621 }
5622
5623 /*
5624 * Instruct the Activity Manager to fetch the current configuration and broadcast
5625 * that to config-changed listeners if appropriate.
5626 */
5627 void sendNewConfiguration() {
5628 try {
5629 mActivityManager.updateConfiguration(null);
5630 } catch (RemoteException e) {
5631 }
5632 }
Romain Guy06882f82009-06-10 13:36:04 -07005633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005634 public Configuration computeNewConfiguration() {
5635 synchronized (mWindowMap) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08005636 Configuration config = computeNewConfigurationLocked();
5637 if (config == null && mWaitingForConfig) {
5638 // Nothing changed but we are waiting for something... stop that!
5639 mWaitingForConfig = false;
5640 performLayoutAndPlaceSurfacesLocked();
5641 }
5642 return config;
Dianne Hackbornc485a602009-03-24 22:39:49 -07005643 }
5644 }
Romain Guy06882f82009-06-10 13:36:04 -07005645
Dianne Hackbornc485a602009-03-24 22:39:49 -07005646 Configuration computeNewConfigurationLocked() {
5647 Configuration config = new Configuration();
5648 if (!computeNewConfigurationLocked(config)) {
5649 return null;
5650 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005651 return config;
5652 }
Romain Guy06882f82009-06-10 13:36:04 -07005653
Dianne Hackbornc485a602009-03-24 22:39:49 -07005654 boolean computeNewConfigurationLocked(Configuration config) {
5655 if (mDisplay == null) {
5656 return false;
5657 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005658
5659 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005660
5661 // Use the effective "visual" dimensions based on current rotation
5662 final boolean rotated = (mRotation == Surface.ROTATION_90
5663 || mRotation == Surface.ROTATION_270);
5664 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5665 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5666
Dianne Hackbornc485a602009-03-24 22:39:49 -07005667 int orientation = Configuration.ORIENTATION_SQUARE;
5668 if (dw < dh) {
5669 orientation = Configuration.ORIENTATION_PORTRAIT;
5670 } else if (dw > dh) {
5671 orientation = Configuration.ORIENTATION_LANDSCAPE;
5672 }
5673 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005674
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005675 DisplayMetrics dm = new DisplayMetrics();
5676 mDisplay.getMetrics(dm);
5677 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5678
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005679 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005680 // Note we only do this once because at this point we don't
5681 // expect the screen to change in this way at runtime, and want
5682 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005683 int longSize = dw;
5684 int shortSize = dh;
5685 if (longSize < shortSize) {
5686 int tmp = longSize;
5687 longSize = shortSize;
5688 shortSize = tmp;
5689 }
5690 longSize = (int)(longSize/dm.density);
5691 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005692
Dianne Hackborn723738c2009-06-25 19:48:04 -07005693 // These semi-magic numbers define our compatibility modes for
5694 // applications with different screens. Don't change unless you
5695 // make sure to test lots and lots of apps!
5696 if (longSize < 470) {
5697 // This is shorter than an HVGA normal density screen (which
5698 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005699 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5700 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005701 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005702 // What size is this screen screen?
5703 if (longSize >= 800 && shortSize >= 600) {
5704 // SVGA or larger screens at medium density are the point
5705 // at which we consider it to be an extra large screen.
5706 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005707 } else if (longSize >= 530 && shortSize >= 400) {
5708 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005709 // at which we consider it to be a large screen.
5710 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5711 } else {
5712 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005713
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005714 // If this screen is wider than normal HVGA, or taller
5715 // than FWVGA, then for old apps we want to run in size
5716 // compatibility mode.
5717 if (shortSize > 321 || longSize > 570) {
5718 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5719 }
5720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005721
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005722 // Is this a long screen?
5723 if (((longSize*3)/5) >= (shortSize-1)) {
5724 // Anything wider than WVGA (5:3) is considering to be long.
5725 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5726 } else {
5727 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5728 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005729 }
5730 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005731 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005732
Dianne Hackbornc485a602009-03-24 22:39:49 -07005733 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5734 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5735 mPolicy.adjustConfigurationLw(config);
5736 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005738
5739 // -------------------------------------------------------------
5740 // Drag and drop
5741 // -------------------------------------------------------------
5742
5743 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005744 int flags, int width, int height, Surface outSurface) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005745 if (DEBUG_DRAG) {
5746 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005747 + " flags=" + Integer.toHexString(flags) + " win=" + window
Christopher Tatea53146c2010-09-07 11:57:52 -07005748 + " asbinder=" + window.asBinder());
5749 }
5750
5751 final int callerPid = Binder.getCallingPid();
5752 final long origId = Binder.clearCallingIdentity();
5753 IBinder token = null;
5754
5755 try {
5756 synchronized (mWindowMap) {
5757 try {
Christopher Tatea53146c2010-09-07 11:57:52 -07005758 if (mDragState == null) {
5759 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5760 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5761 outSurface.copyFrom(surface);
Chris Tate7b362e42010-11-04 16:02:52 -07005762 final IBinder winBinder = window.asBinder();
Christopher Tatea53146c2010-09-07 11:57:52 -07005763 token = new Binder();
Christopher Tate02d2b3b2011-01-10 20:43:53 -08005764 // TODO: preserve flags param in DragState
5765 mDragState = new DragState(token, surface, 0, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005766 mDragState.mSurface = surface;
Christopher Tatea53146c2010-09-07 11:57:52 -07005767 token = mDragState.mToken = new Binder();
5768
5769 // 5 second timeout for this window to actually begin the drag
Chris Tate7b362e42010-11-04 16:02:52 -07005770 mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
5771 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
Christopher Tatea53146c2010-09-07 11:57:52 -07005772 mH.sendMessageDelayed(msg, 5000);
5773 } else {
5774 Slog.w(TAG, "Drag already in progress");
5775 }
5776 } catch (Surface.OutOfResourcesException e) {
5777 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5778 if (mDragState != null) {
5779 mDragState.reset();
5780 mDragState = null;
5781 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005782 }
5783 }
5784 } finally {
5785 Binder.restoreCallingIdentity(origId);
5786 }
5787
5788 return token;
5789 }
5790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005791 // -------------------------------------------------------------
5792 // Input Events and Focus Management
5793 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005794
Jeff Brown349703e2010-06-22 01:27:15 -07005795 InputMonitor mInputMonitor = new InputMonitor();
5796
5797 /* Tracks the progress of input dispatch and ensures that input dispatch state
5798 * is kept in sync with changes in window focus, visibility, registration, and
5799 * other relevant Window Manager state transitions. */
5800 final class InputMonitor {
5801 // Current window with input focus for keys and other non-touch events. May be null.
5802 private WindowState mInputFocus;
5803
5804 // When true, prevents input dispatch from proceeding until set to false again.
5805 private boolean mInputDispatchFrozen;
5806
5807 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5808 private boolean mInputDispatchEnabled = true;
5809
Jeff Brown3a22cd92011-01-21 13:59:04 -08005810 // When true, need to call updateInputWindowsLw().
5811 private boolean mUpdateInputWindowsNeeded = true;
5812
Jeff Brown349703e2010-06-22 01:27:15 -07005813 // Temporary list of windows information to provide to the input dispatcher.
5814 private InputWindowList mTempInputWindows = new InputWindowList();
5815
5816 // Temporary input application object to provide to the input dispatcher.
5817 private InputApplication mTempInputApplication = new InputApplication();
5818
Jeff Brownb09abc12011-01-13 21:08:27 -08005819 // Set to true when the first input device configuration change notification
5820 // is received to indicate that the input devices are ready.
5821 private final Object mInputDevicesReadyMonitor = new Object();
5822 private boolean mInputDevicesReady;
5823
Jeff Brown349703e2010-06-22 01:27:15 -07005824 /* Notifies the window manager about a broken input channel.
5825 *
5826 * Called by the InputManager.
5827 */
Jeff Brown928e0542011-01-10 11:17:36 -08005828 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
5829 if (inputWindowHandle == null) {
5830 return;
5831 }
5832
Jeff Brown349703e2010-06-22 01:27:15 -07005833 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005834 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown349703e2010-06-22 01:27:15 -07005835 Slog.i(TAG, "WINDOW DIED " + windowState);
5836 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005837 }
5838 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005839
Jeff Brown519e0242010-09-15 15:18:56 -07005840 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005841 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005842 *
5843 * Called by the InputManager.
5844 */
Jeff Brown928e0542011-01-10 11:17:36 -08005845 public long notifyANR(InputApplicationHandle inputApplicationHandle,
5846 InputWindowHandle inputWindowHandle) {
Jeff Brown519e0242010-09-15 15:18:56 -07005847 AppWindowToken appWindowToken = null;
Jeff Brown928e0542011-01-10 11:17:36 -08005848 if (inputWindowHandle != null) {
Jeff Brown519e0242010-09-15 15:18:56 -07005849 synchronized (mWindowMap) {
Jeff Brown928e0542011-01-10 11:17:36 -08005850 WindowState windowState = (WindowState) inputWindowHandle.windowState;
Jeff Brown519e0242010-09-15 15:18:56 -07005851 if (windowState != null) {
5852 Slog.i(TAG, "Input event dispatching timed out sending to "
5853 + windowState.mAttrs.getTitle());
5854 appWindowToken = windowState.mAppToken;
5855 }
Jeff Brown349703e2010-06-22 01:27:15 -07005856 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005857 }
5858
Jeff Brown928e0542011-01-10 11:17:36 -08005859 if (appWindowToken == null && inputApplicationHandle != null) {
5860 appWindowToken = inputApplicationHandle.appWindowToken;
Jeff Brown519e0242010-09-15 15:18:56 -07005861 Slog.i(TAG, "Input event dispatching timed out sending to application "
5862 + appWindowToken.stringName);
5863 }
Jeff Brown349703e2010-06-22 01:27:15 -07005864
Jeff Brown519e0242010-09-15 15:18:56 -07005865 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005866 try {
5867 // Notify the activity manager about the timeout and let it decide whether
5868 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005869 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005870 if (! abort) {
5871 // The activity manager declined to abort dispatching.
5872 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005873 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005874 }
Jeff Brown349703e2010-06-22 01:27:15 -07005875 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005876 }
5877 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005878 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005879 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005880
Chris Tatea32dcf72010-10-14 12:13:50 -07005881 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005882 final InputWindow inputWindow = windowList.add();
5883 inputWindow.inputChannel = mDragState.mServerChannel;
5884 inputWindow.name = "drag";
Christopher Tatea1595792011-01-19 17:26:50 -08005885 inputWindow.layoutParamsFlags = 0;
Christopher Tatea53146c2010-09-07 11:57:52 -07005886 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5887 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5888 inputWindow.visible = true;
5889 inputWindow.canReceiveKeys = false;
5890 inputWindow.hasFocus = true;
5891 inputWindow.hasWallpaper = false;
5892 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005893 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005894 inputWindow.ownerPid = Process.myPid();
5895 inputWindow.ownerUid = Process.myUid();
5896
5897 // The drag window covers the entire display
5898 inputWindow.frameLeft = 0;
5899 inputWindow.frameTop = 0;
5900 inputWindow.frameRight = mDisplay.getWidth();
5901 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005902
Jeff Brownfbf09772011-01-16 14:06:57 -08005903 // The drag window cannot receive new touches.
5904 inputWindow.touchableRegion.setEmpty();
Christopher Tatea53146c2010-09-07 11:57:52 -07005905 }
5906
Jeff Brown3a22cd92011-01-21 13:59:04 -08005907 public void setUpdateInputWindowsNeededLw() {
5908 mUpdateInputWindowsNeeded = true;
5909 }
5910
Jeff Brown349703e2010-06-22 01:27:15 -07005911 /* Updates the cached window information provided to the input dispatcher. */
Jeff Brown2e44b072011-01-24 15:21:56 -08005912 public void updateInputWindowsLw(boolean force) {
5913 if (!force && !mUpdateInputWindowsNeeded) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08005914 return;
5915 }
5916 mUpdateInputWindowsNeeded = false;
5917
Jeff Brown349703e2010-06-22 01:27:15 -07005918 // Populate the input window list with information about all of the windows that
5919 // could potentially receive input.
5920 // As an optimization, we could try to prune the list of windows but this turns
5921 // out to be difficult because only the native code knows for sure which window
5922 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005923 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005924
5925 // If there's a drag in flight, provide a pseudowindow to catch drag input
5926 final boolean inDrag = (mDragState != null);
5927 if (inDrag) {
5928 if (DEBUG_DRAG) {
5929 Log.d(TAG, "Inserting drag window");
5930 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005931 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005932 }
5933
Jeff Brown7fbdc842010-06-17 20:52:56 -07005934 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005935 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005936 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005937 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005938 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005939 continue;
5940 }
5941
Jeff Brown349703e2010-06-22 01:27:15 -07005942 final int flags = child.mAttrs.flags;
5943 final int type = child.mAttrs.type;
5944
5945 final boolean hasFocus = (child == mInputFocus);
5946 final boolean isVisible = child.isVisibleLw();
5947 final boolean hasWallpaper = (child == mWallpaperTarget)
5948 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005949
5950 // If there's a drag in progress and 'child' is a potential drop target,
5951 // make sure it's been told about the drag
5952 if (inDrag && isVisible) {
5953 mDragState.sendDragStartedIfNeededLw(child);
5954 }
5955
Jeff Brown349703e2010-06-22 01:27:15 -07005956 // Add a window to our list of input windows.
5957 final InputWindow inputWindow = mTempInputWindows.add();
Jeff Brown928e0542011-01-10 11:17:36 -08005958 inputWindow.inputWindowHandle = child.mInputWindowHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07005959 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005960 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005961 inputWindow.layoutParamsFlags = flags;
5962 inputWindow.layoutParamsType = type;
5963 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5964 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005965 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005966 inputWindow.hasFocus = hasFocus;
5967 inputWindow.hasWallpaper = hasWallpaper;
5968 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005969 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005970 inputWindow.ownerPid = child.mSession.mPid;
5971 inputWindow.ownerUid = child.mSession.mUid;
5972
5973 final Rect frame = child.mFrame;
5974 inputWindow.frameLeft = frame.left;
5975 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005976 inputWindow.frameRight = frame.right;
5977 inputWindow.frameBottom = frame.bottom;
Jeff Brownfbf09772011-01-16 14:06:57 -08005978
5979 child.getTouchableRegion(inputWindow.touchableRegion);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005980 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005981
Jeff Brown349703e2010-06-22 01:27:15 -07005982 // Send windows to native code.
5983 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005984
Jeff Brown349703e2010-06-22 01:27:15 -07005985 // Clear the list in preparation for the next round.
5986 // Also avoids keeping InputChannel objects referenced unnecessarily.
5987 mTempInputWindows.clear();
5988 }
Jeff Brownb09abc12011-01-13 21:08:27 -08005989
5990 /* Notifies that the input device configuration has changed. */
5991 public void notifyConfigurationChanged() {
5992 sendNewConfiguration();
5993
5994 synchronized (mInputDevicesReadyMonitor) {
5995 if (!mInputDevicesReady) {
5996 mInputDevicesReady = true;
5997 mInputDevicesReadyMonitor.notifyAll();
5998 }
5999 }
6000 }
6001
6002 /* Waits until the built-in input devices have been configured. */
6003 public boolean waitForInputDevicesReady(long timeoutMillis) {
6004 synchronized (mInputDevicesReadyMonitor) {
6005 if (!mInputDevicesReady) {
6006 try {
6007 mInputDevicesReadyMonitor.wait(timeoutMillis);
6008 } catch (InterruptedException ex) {
6009 }
6010 }
6011 return mInputDevicesReady;
6012 }
6013 }
6014
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006015 /* Notifies that the lid switch changed state. */
6016 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
6017 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
6018 }
6019
Jeff Brown349703e2010-06-22 01:27:15 -07006020 /* Provides an opportunity for the window manager policy to intercept early key
6021 * processing as soon as the key has been read from the device. */
Jeff Brown1f245102010-11-18 20:53:46 -08006022 public int interceptKeyBeforeQueueing(
6023 KeyEvent event, int policyFlags, boolean isScreenOn) {
6024 return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07006025 }
6026
6027 /* Provides an opportunity for the window manager policy to process a key before
6028 * ordinary dispatch. */
Jeff Brown1f245102010-11-18 20:53:46 -08006029 public boolean interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -08006030 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006031 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006032 return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07006033 }
6034
Jeff Brown3915bb82010-11-05 15:02:16 -07006035 /* Provides an opportunity for the window manager policy to process a key that
6036 * the application did not handle. */
Jeff Brown49ed71d2010-12-06 17:13:33 -08006037 public KeyEvent dispatchUnhandledKey(
Jeff Brown928e0542011-01-10 11:17:36 -08006038 InputWindowHandle focus, KeyEvent event, int policyFlags) {
Jeff Brown00ae87d2011-01-13 19:58:24 -08006039 WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
Jeff Brown1f245102010-11-18 20:53:46 -08006040 return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07006041 }
6042
Jeff Brown349703e2010-06-22 01:27:15 -07006043 /* Called when the current input focus changes.
6044 * Layer assignment is assumed to be complete by the time this is called.
6045 */
Jeff Brown3a22cd92011-01-21 13:59:04 -08006046 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Jeff Brown349703e2010-06-22 01:27:15 -07006047 if (DEBUG_INPUT) {
6048 Slog.d(TAG, "Input focus has changed to " + newWindow);
6049 }
6050
6051 if (newWindow != mInputFocus) {
6052 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07006053 // Displaying a window implicitly causes dispatching to be unpaused.
6054 // This is to protect against bugs if someone pauses dispatching but
6055 // forgets to resume.
6056 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006057 }
Jeff Brown3a22cd92011-01-21 13:59:04 -08006058
Jeff Brown349703e2010-06-22 01:27:15 -07006059 mInputFocus = newWindow;
Jeff Brown3a22cd92011-01-21 13:59:04 -08006060 setUpdateInputWindowsNeededLw();
6061
6062 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08006063 updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08006064 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07006065 }
6066 }
6067
Jeff Brown349703e2010-06-22 01:27:15 -07006068 public void setFocusedAppLw(AppWindowToken newApp) {
6069 // Focused app has changed.
6070 if (newApp == null) {
6071 mInputManager.setFocusedApplication(null);
6072 } else {
Jeff Brown928e0542011-01-10 11:17:36 -08006073 mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle;
Jeff Brown349703e2010-06-22 01:27:15 -07006074 mTempInputApplication.name = newApp.toString();
6075 mTempInputApplication.dispatchingTimeoutNanos =
6076 newApp.inputDispatchingTimeoutNanos;
Jeff Brown928e0542011-01-10 11:17:36 -08006077
Jeff Brown349703e2010-06-22 01:27:15 -07006078 mInputManager.setFocusedApplication(mTempInputApplication);
Jeff Brown928e0542011-01-10 11:17:36 -08006079
6080 mTempInputApplication.recycle();
Jeff Brown349703e2010-06-22 01:27:15 -07006081 }
6082 }
6083
Jeff Brown349703e2010-06-22 01:27:15 -07006084 public void pauseDispatchingLw(WindowToken window) {
6085 if (! window.paused) {
6086 if (DEBUG_INPUT) {
6087 Slog.v(TAG, "Pausing WindowToken " + window);
6088 }
6089
6090 window.paused = true;
Jeff Brown2e44b072011-01-24 15:21:56 -08006091 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006092 }
6093 }
6094
6095 public void resumeDispatchingLw(WindowToken window) {
6096 if (window.paused) {
6097 if (DEBUG_INPUT) {
6098 Slog.v(TAG, "Resuming WindowToken " + window);
6099 }
6100
6101 window.paused = false;
Jeff Brown2e44b072011-01-24 15:21:56 -08006102 updateInputWindowsLw(true /*force*/);
Jeff Brown349703e2010-06-22 01:27:15 -07006103 }
6104 }
6105
6106 public void freezeInputDispatchingLw() {
6107 if (! mInputDispatchFrozen) {
6108 if (DEBUG_INPUT) {
6109 Slog.v(TAG, "Freezing input dispatching");
6110 }
6111
6112 mInputDispatchFrozen = true;
6113 updateInputDispatchModeLw();
6114 }
6115 }
6116
6117 public void thawInputDispatchingLw() {
6118 if (mInputDispatchFrozen) {
6119 if (DEBUG_INPUT) {
6120 Slog.v(TAG, "Thawing input dispatching");
6121 }
6122
6123 mInputDispatchFrozen = false;
6124 updateInputDispatchModeLw();
6125 }
6126 }
6127
6128 public void setEventDispatchingLw(boolean enabled) {
6129 if (mInputDispatchEnabled != enabled) {
6130 if (DEBUG_INPUT) {
6131 Slog.v(TAG, "Setting event dispatching to " + enabled);
6132 }
6133
6134 mInputDispatchEnabled = enabled;
6135 updateInputDispatchModeLw();
6136 }
6137 }
6138
6139 private void updateInputDispatchModeLw() {
6140 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
6141 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07006142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 public void pauseKeyDispatching(IBinder _token) {
6145 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6146 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006147 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 }
6149
6150 synchronized (mWindowMap) {
6151 WindowToken token = mTokenMap.get(_token);
6152 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006153 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 }
6155 }
6156 }
6157
6158 public void resumeKeyDispatching(IBinder _token) {
6159 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6160 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006161 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006162 }
6163
6164 synchronized (mWindowMap) {
6165 WindowToken token = mTokenMap.get(_token);
6166 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006167 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 }
6169 }
6170 }
6171
6172 public void setEventDispatching(boolean enabled) {
6173 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
6174 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07006175 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006176 }
6177
6178 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006179 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180 }
6181 }
Romain Guy06882f82009-06-10 13:36:04 -07006182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006183 /**
6184 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006185 * Even when sync is false, this method may block while waiting for current
6186 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006187 *
6188 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006189 * {@link SystemClock#uptimeMillis()} as the timebase.)
6190 * @param sync If true, wait for the event to be completed before returning to the caller.
6191 * @return Returns true if event was dispatched, false if it was dropped for any reason
6192 */
6193 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
6194 long downTime = ev.getDownTime();
6195 long eventTime = ev.getEventTime();
6196
6197 int action = ev.getAction();
6198 int code = ev.getKeyCode();
6199 int repeatCount = ev.getRepeatCount();
6200 int metaState = ev.getMetaState();
6201 int deviceId = ev.getDeviceId();
6202 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006203 int source = ev.getSource();
Mike Playlec6ded102010-11-29 16:01:03 +00006204 int flags = ev.getFlags();
Jeff Brownc5ed5912010-07-14 18:48:53 -07006205
6206 if (source == InputDevice.SOURCE_UNKNOWN) {
6207 source = InputDevice.SOURCE_KEYBOARD;
6208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006209
6210 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
6211 if (downTime == 0) downTime = eventTime;
6212
6213 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jean-Baptiste Queru4a880132010-12-02 15:16:53 -08006214 deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006216 final int pid = Binder.getCallingPid();
6217 final int uid = Binder.getCallingUid();
6218 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006219
Jeff Brownbbda99d2010-07-28 15:48:59 -07006220 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6221 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6222 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6223 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006224
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006225 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006226 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006227 }
6228
6229 /**
6230 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006231 * Even when sync is false, this method may block while waiting for current
6232 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006233 *
6234 * @param ev A motion event describing the pointer (touch) action. (As noted in
6235 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006236 * {@link SystemClock#uptimeMillis()} as the timebase.)
6237 * @param sync If true, wait for the event to be completed before returning to the caller.
6238 * @return Returns true if event was dispatched, false if it was dropped for any reason
6239 */
6240 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006241 final int pid = Binder.getCallingPid();
6242 final int uid = Binder.getCallingUid();
6243 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006244
Jeff Brownc5ed5912010-07-14 18:48:53 -07006245 MotionEvent newEvent = MotionEvent.obtain(ev);
6246 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
6247 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
6248 }
6249
Jeff Brownbbda99d2010-07-28 15:48:59 -07006250 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6251 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6252 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6253 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006254
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006255 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006256 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006257 }
Romain Guy06882f82009-06-10 13:36:04 -07006258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006259 /**
6260 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07006261 * Even when sync is false, this method may block while waiting for current
6262 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07006263 *
6264 * @param ev A motion event describing the trackball action. (As noted in
6265 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 * {@link SystemClock#uptimeMillis()} as the timebase.)
6267 * @param sync If true, wait for the event to be completed before returning to the caller.
6268 * @return Returns true if event was dispatched, false if it was dropped for any reason
6269 */
6270 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006271 final int pid = Binder.getCallingPid();
6272 final int uid = Binder.getCallingUid();
6273 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07006274
Jeff Brownc5ed5912010-07-14 18:48:53 -07006275 MotionEvent newEvent = MotionEvent.obtain(ev);
6276 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
6277 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
6278 }
6279
Jeff Brownbbda99d2010-07-28 15:48:59 -07006280 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
6281 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
6282 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
6283 INJECTION_TIMEOUT_MILLIS);
6284
6285 Binder.restoreCallingIdentity(ident);
6286 return reportInjectionResult(result);
6287 }
6288
6289 /**
6290 * Inject an input event into the UI without waiting for dispatch to commence.
6291 * This variant is useful for fire-and-forget input event injection. It does not
6292 * block any longer than it takes to enqueue the input event.
6293 *
6294 * @param ev An input event. (Be sure to set the input source correctly.)
6295 * @return Returns true if event was dispatched, false if it was dropped for any reason
6296 */
6297 public boolean injectInputEventNoWait(InputEvent ev) {
6298 final int pid = Binder.getCallingPid();
6299 final int uid = Binder.getCallingUid();
6300 final long ident = Binder.clearCallingIdentity();
6301
6302 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6303 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6304 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006305
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006306 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006307 return reportInjectionResult(result);
6308 }
6309
6310 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006311 switch (result) {
6312 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6313 Slog.w(TAG, "Input event injection permission denied.");
6314 throw new SecurityException(
6315 "Injecting to another application requires INJECT_EVENTS permission");
6316 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006317 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006318 return true;
6319 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6320 Slog.w(TAG, "Input event injection timed out.");
6321 return false;
6322 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6323 default:
6324 Slog.w(TAG, "Input event injection failed.");
6325 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327 }
Romain Guy06882f82009-06-10 13:36:04 -07006328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006329 private WindowState getFocusedWindow() {
6330 synchronized (mWindowMap) {
6331 return getFocusedWindowLocked();
6332 }
6333 }
6334
6335 private WindowState getFocusedWindowLocked() {
6336 return mCurrentFocus;
6337 }
Romain Guy06882f82009-06-10 13:36:04 -07006338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006339 public boolean detectSafeMode() {
Jeff Brownb09abc12011-01-13 21:08:27 -08006340 if (!mInputMonitor.waitForInputDevicesReady(
6341 INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
6342 Slog.w(TAG, "Devices still not ready after waiting "
6343 + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
6344 + " milliseconds before attempting to detect safe mode.");
6345 }
6346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006347 mSafeMode = mPolicy.detectSafeMode();
6348 return mSafeMode;
6349 }
Romain Guy06882f82009-06-10 13:36:04 -07006350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006352 synchronized(mWindowMap) {
6353 if (mDisplay != null) {
6354 throw new IllegalStateException("Display already initialized");
6355 }
6356 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6357 mDisplay = wm.getDefaultDisplay();
6358 mInitialDisplayWidth = mDisplay.getWidth();
6359 mInitialDisplayHeight = mDisplay.getHeight();
Dianne Hackborn4c7cc342010-12-16 16:37:39 -08006360 mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth),
6361 Display.unmapDisplaySize(mInitialDisplayHeight));
Dianne Hackborn5132b372010-07-29 12:51:35 -07006362 }
6363
6364 try {
6365 mActivityManager.updateConfiguration(null);
6366 } catch (RemoteException e) {
6367 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006368
6369 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006370 }
6371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 // -------------------------------------------------------------
6373 // Client Session State
6374 // -------------------------------------------------------------
6375
6376 private final class Session extends IWindowSession.Stub
6377 implements IBinder.DeathRecipient {
6378 final IInputMethodClient mClient;
6379 final IInputContext mInputContext;
6380 final int mUid;
6381 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006382 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 SurfaceSession mSurfaceSession;
6384 int mNumWindow = 0;
6385 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 public Session(IInputMethodClient client, IInputContext inputContext) {
6388 mClient = client;
6389 mInputContext = inputContext;
6390 mUid = Binder.getCallingUid();
6391 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006392 StringBuilder sb = new StringBuilder();
6393 sb.append("Session{");
6394 sb.append(Integer.toHexString(System.identityHashCode(this)));
6395 sb.append(" uid ");
6396 sb.append(mUid);
6397 sb.append("}");
6398 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006400 synchronized (mWindowMap) {
6401 if (mInputMethodManager == null && mHaveInputMethods) {
6402 IBinder b = ServiceManager.getService(
6403 Context.INPUT_METHOD_SERVICE);
6404 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6405 }
6406 }
6407 long ident = Binder.clearCallingIdentity();
6408 try {
6409 // Note: it is safe to call in to the input method manager
6410 // here because we are not holding our lock.
6411 if (mInputMethodManager != null) {
6412 mInputMethodManager.addClient(client, inputContext,
6413 mUid, mPid);
6414 } else {
6415 client.setUsingInputMethod(false);
6416 }
6417 client.asBinder().linkToDeath(this, 0);
6418 } catch (RemoteException e) {
6419 // The caller has died, so we can just forget about this.
6420 try {
6421 if (mInputMethodManager != null) {
6422 mInputMethodManager.removeClient(client);
6423 }
6424 } catch (RemoteException ee) {
6425 }
6426 } finally {
6427 Binder.restoreCallingIdentity(ident);
6428 }
6429 }
Romain Guy06882f82009-06-10 13:36:04 -07006430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006431 @Override
6432 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6433 throws RemoteException {
6434 try {
6435 return super.onTransact(code, data, reply, flags);
6436 } catch (RuntimeException e) {
6437 // Log all 'real' exceptions thrown to the caller
6438 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006439 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006440 }
6441 throw e;
6442 }
6443 }
6444
6445 public void binderDied() {
6446 // Note: it is safe to call in to the input method manager
6447 // here because we are not holding our lock.
6448 try {
6449 if (mInputMethodManager != null) {
6450 mInputMethodManager.removeClient(mClient);
6451 }
6452 } catch (RemoteException e) {
6453 }
6454 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006455 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 mClientDead = true;
6457 killSessionLocked();
6458 }
6459 }
6460
6461 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006462 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6463 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6464 outInputChannel);
6465 }
6466
6467 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006468 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006469 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 }
Romain Guy06882f82009-06-10 13:36:04 -07006471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 public void remove(IWindow window) {
6473 removeWindow(this, window);
6474 }
Romain Guy06882f82009-06-10 13:36:04 -07006475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6477 int requestedWidth, int requestedHeight, int viewFlags,
6478 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006479 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006480 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6481 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006483 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006484 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6485 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 }
Romain Guy06882f82009-06-10 13:36:04 -07006487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 public void setTransparentRegion(IWindow window, Region region) {
6489 setTransparentRegionWindow(this, window, region);
6490 }
Romain Guy06882f82009-06-10 13:36:04 -07006491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 public void setInsets(IWindow window, int touchableInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006493 Rect contentInsets, Rect visibleInsets, Region touchableArea) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 setInsetsWindow(this, window, touchableInsets, contentInsets,
Jeff Brownfbf09772011-01-16 14:06:57 -08006495 visibleInsets, touchableArea);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 }
Romain Guy06882f82009-06-10 13:36:04 -07006497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6499 getWindowDisplayFrame(this, window, outDisplayFrame);
6500 }
Romain Guy06882f82009-06-10 13:36:04 -07006501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006503 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006504 TAG, "IWindow finishDrawing called for " + window);
6505 finishDrawingWindow(this, window);
6506 }
6507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 public void setInTouchMode(boolean mode) {
6509 synchronized(mWindowMap) {
6510 mInTouchMode = mode;
6511 }
6512 }
6513
6514 public boolean getInTouchMode() {
6515 synchronized(mWindowMap) {
6516 return mInTouchMode;
6517 }
6518 }
6519
6520 public boolean performHapticFeedback(IWindow window, int effectId,
6521 boolean always) {
6522 synchronized(mWindowMap) {
6523 long ident = Binder.clearCallingIdentity();
6524 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006525 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006526 windowForClientLocked(this, window, true),
6527 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006528 } finally {
6529 Binder.restoreCallingIdentity(ident);
6530 }
6531 }
6532 }
Romain Guy06882f82009-06-10 13:36:04 -07006533
Christopher Tatea53146c2010-09-07 11:57:52 -07006534 /* Drag/drop */
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006535 public IBinder prepareDrag(IWindow window, int flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006536 int width, int height, Surface outSurface) {
Christopher Tate02d2b3b2011-01-10 20:43:53 -08006537 return prepareDragSurface(window, mSurfaceSession, flags,
Christopher Tatea53146c2010-09-07 11:57:52 -07006538 width, height, outSurface);
6539 }
6540
6541 public boolean performDrag(IWindow window, IBinder dragToken,
6542 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6543 ClipData data) {
6544 if (DEBUG_DRAG) {
6545 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6546 }
6547
6548 synchronized (mWindowMap) {
6549 if (mDragState == null) {
6550 Slog.w(TAG, "No drag prepared");
6551 throw new IllegalStateException("performDrag() without prepareDrag()");
6552 }
6553
6554 if (dragToken != mDragState.mToken) {
6555 Slog.w(TAG, "Performing mismatched drag");
6556 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6557 }
6558
6559 WindowState callingWin = windowForClientLocked(null, window, false);
6560 if (callingWin == null) {
6561 Slog.w(TAG, "Bad requesting window " + window);
6562 return false; // !!! TODO: throw here?
6563 }
6564
6565 // !!! TODO: if input is not still focused on the initiating window, fail
6566 // the drag initiation (e.g. an alarm window popped up just as the application
6567 // called performDrag()
6568
6569 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6570
Christopher Tate2c095f32010-10-04 14:13:40 -07006571 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6572 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006573
Chris Tateb478f462010-10-15 16:02:26 -07006574 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6575 // the actual drag event dispatch stuff in the dragstate
6576
Christopher Tatea53146c2010-09-07 11:57:52 -07006577 mDragState.register();
Jeff Brown2e44b072011-01-24 15:21:56 -08006578 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006579 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6580 mDragState.mServerChannel)) {
6581 Slog.e(TAG, "Unable to transfer touch focus");
6582 mDragState.unregister();
6583 mDragState = null;
Jeff Brown2e44b072011-01-24 15:21:56 -08006584 mInputMonitor.updateInputWindowsLw(true /*force*/);
Chris Tateef70a072010-10-22 19:10:34 -07006585 return false;
6586 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006587
6588 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006589 mDragState.mCurrentX = touchX;
6590 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006591 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006592
6593 // remember the thumb offsets for later
6594 mDragState.mThumbOffsetX = thumbCenterX;
6595 mDragState.mThumbOffsetY = thumbCenterY;
6596
6597 // Make the surface visible at the proper location
6598 final Surface surface = mDragState.mSurface;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006599 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag");
Chris Tateb478f462010-10-15 16:02:26 -07006600 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006601 try {
6602 surface.setPosition((int)(touchX - thumbCenterX),
6603 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006604 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006605 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006606 surface.show();
6607 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006608 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08006609 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag");
Christopher Tatea53146c2010-09-07 11:57:52 -07006610 }
6611 }
6612
6613 return true; // success!
6614 }
6615
Chris Tated4533f12010-10-19 15:15:08 -07006616 public void reportDropResult(IWindow window, boolean consumed) {
6617 IBinder token = window.asBinder();
6618 if (DEBUG_DRAG) {
6619 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6620 }
6621
6622 synchronized (mWindowMap) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006623 long ident = Binder.clearCallingIdentity();
6624 try {
Jeff Brownfbf09772011-01-16 14:06:57 -08006625 if (mDragState == null || mDragState.mToken != token) {
Christopher Tateccd24de2011-01-12 15:02:55 -08006626 Slog.w(TAG, "Invalid drop-result claim by " + window);
6627 throw new IllegalStateException("reportDropResult() by non-recipient");
6628 }
6629
6630 // The right window has responded, even if it's no longer around,
6631 // so be sure to halt the timeout even if the later WindowState
6632 // lookup fails.
6633 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6634 WindowState callingWin = windowForClientLocked(null, window, false);
6635 if (callingWin == null) {
6636 Slog.w(TAG, "Bad result-reporting window " + window);
6637 return; // !!! TODO: throw here?
6638 }
6639
6640 mDragState.mDragResult = consumed;
6641 mDragState.endDragLw();
6642 } finally {
6643 Binder.restoreCallingIdentity(ident);
Chris Tated4533f12010-10-19 15:15:08 -07006644 }
Chris Tated4533f12010-10-19 15:15:08 -07006645 }
6646 }
6647
Christopher Tatea53146c2010-09-07 11:57:52 -07006648 public void dragRecipientEntered(IWindow window) {
6649 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006650 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006651 }
6652 }
6653
6654 public void dragRecipientExited(IWindow window) {
6655 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006656 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006657 }
6658 }
6659
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006660 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006661 synchronized(mWindowMap) {
6662 long ident = Binder.clearCallingIdentity();
6663 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006664 setWindowWallpaperPositionLocked(
6665 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006666 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006667 } finally {
6668 Binder.restoreCallingIdentity(ident);
6669 }
6670 }
6671 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006672
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006673 public void wallpaperOffsetsComplete(IBinder window) {
6674 WindowManagerService.this.wallpaperOffsetsComplete(window);
6675 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006676
Dianne Hackborn75804932009-10-20 20:15:20 -07006677 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6678 int z, Bundle extras, boolean sync) {
6679 synchronized(mWindowMap) {
6680 long ident = Binder.clearCallingIdentity();
6681 try {
6682 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006683 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006684 action, x, y, z, extras, sync);
6685 } finally {
6686 Binder.restoreCallingIdentity(ident);
6687 }
6688 }
6689 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006690
Dianne Hackborn75804932009-10-20 20:15:20 -07006691 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6692 WindowManagerService.this.wallpaperCommandComplete(window, result);
6693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006695 void windowAddedLocked() {
6696 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006697 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006698 TAG, "First window added to " + this + ", creating SurfaceSession");
6699 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006700 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006701 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 mSessions.add(this);
6703 }
6704 mNumWindow++;
6705 }
6706
6707 void windowRemovedLocked() {
6708 mNumWindow--;
6709 killSessionLocked();
6710 }
Romain Guy06882f82009-06-10 13:36:04 -07006711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 void killSessionLocked() {
6713 if (mNumWindow <= 0 && mClientDead) {
6714 mSessions.remove(this);
6715 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006716 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 TAG, "Last window removed from " + this
6718 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006719 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006720 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006721 try {
6722 mSurfaceSession.kill();
6723 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006724 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 + mSurfaceSession + " in session " + this
6726 + ": " + e.toString());
6727 }
6728 mSurfaceSession = null;
6729 }
6730 }
6731 }
Romain Guy06882f82009-06-10 13:36:04 -07006732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006733 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006734 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6735 pw.print(" mClientDead="); pw.print(mClientDead);
6736 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 }
6738
6739 @Override
6740 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006741 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 }
6743 }
6744
6745 // -------------------------------------------------------------
6746 // Client Window State
6747 // -------------------------------------------------------------
6748
6749 private final class WindowState implements WindowManagerPolicy.WindowState {
6750 final Session mSession;
6751 final IWindow mClient;
6752 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006753 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006754 AppWindowToken mAppToken;
6755 AppWindowToken mTargetAppToken;
6756 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6757 final DeathRecipient mDeathRecipient;
6758 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006759 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 final int mBaseLayer;
6761 final int mSubLayer;
6762 final boolean mLayoutAttached;
6763 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006764 final boolean mIsWallpaper;
6765 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006766 int mViewVisibility;
6767 boolean mPolicyVisibility = true;
6768 boolean mPolicyVisibilityAfterAnim = true;
6769 boolean mAppFreezing;
6770 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006771 boolean mReportDestroySurface;
6772 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 boolean mAttachedHidden; // is our parent window hidden?
6774 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006775 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006776 int mRequestedWidth;
6777 int mRequestedHeight;
6778 int mLastRequestedWidth;
6779 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 int mLayer;
6781 int mAnimLayer;
6782 int mLastLayer;
6783 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006784 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006785 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006786
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006787 int mLayoutSeq = -1;
6788
6789 Configuration mConfiguration = null;
6790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 // Actual frame shown on-screen (may be modified by animation)
6792 final Rect mShownFrame = new Rect();
6793 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006795 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006796 * Set when we have changed the size of the surface, to know that
6797 * we must tell them application to resize (and thus redraw itself).
6798 */
6799 boolean mSurfaceResized;
6800
6801 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 * Insets that determine the actually visible area
6803 */
6804 final Rect mVisibleInsets = new Rect();
6805 final Rect mLastVisibleInsets = new Rect();
6806 boolean mVisibleInsetsChanged;
6807
6808 /**
6809 * Insets that are covered by system windows
6810 */
6811 final Rect mContentInsets = new Rect();
6812 final Rect mLastContentInsets = new Rect();
6813 boolean mContentInsetsChanged;
6814
6815 /**
6816 * Set to true if we are waiting for this window to receive its
6817 * given internal insets before laying out other windows based on it.
6818 */
6819 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006821 /**
6822 * These are the content insets that were given during layout for
6823 * this window, to be applied to windows behind it.
6824 */
6825 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 /**
6828 * These are the visible insets that were given during layout for
6829 * this window, to be applied to windows behind it.
6830 */
6831 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006833 /**
Jeff Brownfbf09772011-01-16 14:06:57 -08006834 * This is the given touchable area relative to the window frame, or null if none.
6835 */
6836 final Region mGivenTouchableRegion = new Region();
6837
6838 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006839 * Flag indicating whether the touchable region should be adjusted by
6840 * the visible insets; if false the area outside the visible insets is
6841 * NOT touchable, so we must use those to adjust the frame during hit
6842 * tests.
6843 */
6844 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 // Current transformation being applied.
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08006847 boolean mHaveMatrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6849 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6850 float mHScale=1, mVScale=1;
6851 float mLastHScale=1, mLastVScale=1;
6852 final Matrix mTmpMatrix = new Matrix();
6853
6854 // "Real" frame that the application sees.
6855 final Rect mFrame = new Rect();
6856 final Rect mLastFrame = new Rect();
6857
6858 final Rect mContainingFrame = new Rect();
6859 final Rect mDisplayFrame = new Rect();
6860 final Rect mContentFrame = new Rect();
Dianne Hackborn1c24e952010-11-23 00:34:30 -08006861 final Rect mParentFrame = new Rect();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862 final Rect mVisibleFrame = new Rect();
6863
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08006864 boolean mContentChanged;
6865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 float mShownAlpha = 1;
6867 float mAlpha = 1;
6868 float mLastAlpha = 1;
6869
6870 // Set to true if, when the window gets displayed, it should perform
6871 // an enter animation.
6872 boolean mEnterAnimationPending;
6873
6874 // Currently running animation.
6875 boolean mAnimating;
6876 boolean mLocalAnimating;
6877 Animation mAnimation;
6878 boolean mAnimationIsEntrance;
6879 boolean mHasTransformation;
6880 boolean mHasLocalTransformation;
6881 final Transformation mTransformation = new Transformation();
6882
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006883 // If a window showing a wallpaper: the requested offset for the
6884 // wallpaper; if a wallpaper window: the currently applied offset.
6885 float mWallpaperX = -1;
6886 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006887
6888 // If a window showing a wallpaper: what fraction of the offset
6889 // range corresponds to a full virtual screen.
6890 float mWallpaperXStep = -1;
6891 float mWallpaperYStep = -1;
6892
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006893 // Wallpaper windows: pixels offset based on above variables.
6894 int mXOffset;
6895 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 // This is set after IWindowSession.relayout() has been called at
6898 // least once for the window. It allows us to detect the situation
6899 // where we don't yet have a surface, but should have one soon, so
6900 // we can give the window focus before waiting for the relayout.
6901 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006903 // This is set after the Surface has been created but before the
6904 // window has been drawn. During this time the surface is hidden.
6905 boolean mDrawPending;
6906
6907 // This is set after the window has finished drawing for the first
6908 // time but before its surface is shown. The surface will be
6909 // displayed when the next layout is run.
6910 boolean mCommitDrawPending;
6911
6912 // This is set during the time after the window's drawing has been
6913 // committed, and before its surface is actually shown. It is used
6914 // to delay showing the surface until all windows in a token are ready
6915 // to be shown.
6916 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006918 // Set when the window has been shown in the screen the first time.
6919 boolean mHasDrawn;
6920
6921 // Currently running an exit animation?
6922 boolean mExiting;
6923
6924 // Currently on the mDestroySurface list?
6925 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006927 // Completely remove from window manager after exit animation?
6928 boolean mRemoveOnExit;
6929
6930 // Set when the orientation is changing and this window has not yet
6931 // been updated for the new orientation.
6932 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 // Is this window now (or just being) removed?
6935 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006936
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006937 // Temp for keeping track of windows that have been removed when
6938 // rebuilding window list.
6939 boolean mRebuilding;
6940
Dianne Hackborn16064f92010-03-25 00:47:24 -07006941 // For debugging, this is the last information given to the surface flinger.
6942 boolean mSurfaceShown;
6943 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6944 int mSurfaceLayer;
6945 float mSurfaceAlpha;
6946
Jeff Brown928e0542011-01-10 11:17:36 -08006947 // Input channel and input window handle used by the input dispatcher.
6948 InputWindowHandle mInputWindowHandle;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006949 InputChannel mInputChannel;
6950
Mattias Petersson1622eee2010-12-21 10:15:11 +01006951 // Used to improve performance of toString()
6952 String mStringNameCache;
6953 CharSequence mLastTitle;
6954 boolean mWasPaused;
6955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 WindowState(Session s, IWindow c, WindowToken token,
6957 WindowState attachedWindow, WindowManager.LayoutParams a,
6958 int viewVisibility) {
6959 mSession = s;
6960 mClient = c;
6961 mToken = token;
6962 mAttrs.copyFrom(a);
6963 mViewVisibility = viewVisibility;
6964 DeathRecipient deathRecipient = new DeathRecipient();
6965 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006966 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006967 TAG, "Window " + this + " client=" + c.asBinder()
6968 + " token=" + token + " (" + mAttrs.token + ")");
6969 try {
6970 c.asBinder().linkToDeath(deathRecipient, 0);
6971 } catch (RemoteException e) {
6972 mDeathRecipient = null;
6973 mAttachedWindow = null;
6974 mLayoutAttached = false;
6975 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006976 mIsWallpaper = false;
6977 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 mBaseLayer = 0;
6979 mSubLayer = 0;
6980 return;
6981 }
6982 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6985 mAttrs.type <= LAST_SUB_WINDOW)) {
6986 // The multiplier here is to reserve space for multiple
6987 // windows in the same type layer.
6988 mBaseLayer = mPolicy.windowTypeToLayerLw(
6989 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6990 + TYPE_LAYER_OFFSET;
6991 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6992 mAttachedWindow = attachedWindow;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006993 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006994 mAttachedWindow.mChildWindows.add(this);
6995 mLayoutAttached = mAttrs.type !=
6996 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6997 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6998 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006999 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
7000 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007001 } else {
7002 // The multiplier here is to reserve space for multiple
7003 // windows in the same type layer.
7004 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
7005 * TYPE_LAYER_MULTIPLIER
7006 + TYPE_LAYER_OFFSET;
7007 mSubLayer = 0;
7008 mAttachedWindow = null;
7009 mLayoutAttached = false;
7010 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
7011 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007012 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
7013 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007014 }
7015
7016 WindowState appWin = this;
7017 while (appWin.mAttachedWindow != null) {
7018 appWin = mAttachedWindow;
7019 }
7020 WindowToken appToken = appWin.mToken;
7021 while (appToken.appWindowToken == null) {
7022 WindowToken parent = mTokenMap.get(appToken.token);
7023 if (parent == null || appToken == parent) {
7024 break;
7025 }
7026 appToken = parent;
7027 }
The Android Open Source Project10592532009-03-18 17:39:46 -07007028 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 mAppToken = appToken.appWindowToken;
7030
7031 mSurface = null;
7032 mRequestedWidth = 0;
7033 mRequestedHeight = 0;
7034 mLastRequestedWidth = 0;
7035 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007036 mXOffset = 0;
7037 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 mLayer = 0;
7039 mAnimLayer = 0;
7040 mLastLayer = 0;
Jeff Brown928e0542011-01-10 11:17:36 -08007041 mInputWindowHandle = new InputWindowHandle(
7042 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 }
7044
7045 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007046 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007047 TAG, "Attaching " + this + " token=" + mToken
7048 + ", list=" + mToken.windows);
7049 mSession.windowAddedLocked();
7050 }
7051
7052 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
7053 mHaveFrame = true;
7054
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007055 final Rect container = mContainingFrame;
7056 container.set(pf);
7057
7058 final Rect display = mDisplayFrame;
7059 display.set(df);
7060
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007061 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007062 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007063 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
7064 display.intersect(mCompatibleScreenFrame);
7065 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007066 }
7067
7068 final int pw = container.right - container.left;
7069 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070
7071 int w,h;
7072 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
7073 w = mAttrs.width < 0 ? pw : mAttrs.width;
7074 h = mAttrs.height< 0 ? ph : mAttrs.height;
7075 } else {
Romain Guy980a9382010-01-08 15:06:28 -08007076 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
7077 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007078 }
Romain Guy06882f82009-06-10 13:36:04 -07007079
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007080 if (!mParentFrame.equals(pf)) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007081 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
7082 // + " to " + pf);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007083 mParentFrame.set(pf);
7084 mContentChanged = true;
7085 }
7086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007087 final Rect content = mContentFrame;
7088 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07007089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 final Rect visible = mVisibleFrame;
7091 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07007092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007093 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007094 final int fw = frame.width();
7095 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07007096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007097 //System.out.println("In: w=" + w + " h=" + h + " container=" +
7098 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
7099
7100 Gravity.apply(mAttrs.gravity, w, h, container,
7101 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
7102 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
7103
7104 //System.out.println("Out: " + mFrame);
7105
7106 // Now make sure the window fits in the overall display.
7107 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007109 // Make sure the content and visible frames are inside of the
7110 // final window frame.
7111 if (content.left < frame.left) content.left = frame.left;
7112 if (content.top < frame.top) content.top = frame.top;
7113 if (content.right > frame.right) content.right = frame.right;
7114 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
7115 if (visible.left < frame.left) visible.left = frame.left;
7116 if (visible.top < frame.top) visible.top = frame.top;
7117 if (visible.right > frame.right) visible.right = frame.right;
7118 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007120 final Rect contentInsets = mContentInsets;
7121 contentInsets.left = content.left-frame.left;
7122 contentInsets.top = content.top-frame.top;
7123 contentInsets.right = frame.right-content.right;
7124 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 final Rect visibleInsets = mVisibleInsets;
7127 visibleInsets.left = visible.left-frame.left;
7128 visibleInsets.top = visible.top-frame.top;
7129 visibleInsets.right = frame.right-visible.right;
7130 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07007131
Dianne Hackborn284ac932009-08-28 10:34:25 -07007132 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
7133 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07007134 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07007135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007137 if (localLOGV) {
7138 //if ("com.google.android.youtube".equals(mAttrs.packageName)
7139 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007140 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007141 + mRequestedWidth + ", mRequestedheight="
7142 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
7143 + "): frame=" + mFrame.toShortString()
7144 + " ci=" + contentInsets.toShortString()
7145 + " vi=" + visibleInsets.toShortString());
7146 //}
7147 }
7148 }
Romain Guy06882f82009-06-10 13:36:04 -07007149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007150 public Rect getFrameLw() {
7151 return mFrame;
7152 }
7153
7154 public Rect getShownFrameLw() {
7155 return mShownFrame;
7156 }
7157
7158 public Rect getDisplayFrameLw() {
7159 return mDisplayFrame;
7160 }
7161
7162 public Rect getContentFrameLw() {
7163 return mContentFrame;
7164 }
7165
7166 public Rect getVisibleFrameLw() {
7167 return mVisibleFrame;
7168 }
7169
7170 public boolean getGivenInsetsPendingLw() {
7171 return mGivenInsetsPending;
7172 }
7173
7174 public Rect getGivenContentInsetsLw() {
7175 return mGivenContentInsets;
7176 }
Romain Guy06882f82009-06-10 13:36:04 -07007177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007178 public Rect getGivenVisibleInsetsLw() {
7179 return mGivenVisibleInsets;
7180 }
Romain Guy06882f82009-06-10 13:36:04 -07007181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007182 public WindowManager.LayoutParams getAttrs() {
7183 return mAttrs;
7184 }
7185
7186 public int getSurfaceLayer() {
7187 return mLayer;
7188 }
Romain Guy06882f82009-06-10 13:36:04 -07007189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007190 public IApplicationToken getAppToken() {
7191 return mAppToken != null ? mAppToken.appToken : null;
7192 }
Jeff Brown349703e2010-06-22 01:27:15 -07007193
7194 public long getInputDispatchingTimeoutNanos() {
7195 return mAppToken != null
7196 ? mAppToken.inputDispatchingTimeoutNanos
7197 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
7198 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007199
7200 public boolean hasAppShownWindows() {
7201 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
7202 }
7203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007204 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007205 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007206 TAG, "Setting animation in " + this + ": " + anim);
7207 mAnimating = false;
7208 mLocalAnimating = false;
7209 mAnimation = anim;
7210 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
7211 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
7212 }
7213
7214 public void clearAnimation() {
7215 if (mAnimation != null) {
7216 mAnimating = true;
7217 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007218 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007219 mAnimation = null;
7220 }
7221 }
Romain Guy06882f82009-06-10 13:36:04 -07007222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 Surface createSurfaceLocked() {
7224 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007225 mReportDestroySurface = false;
7226 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007227 mDrawPending = true;
7228 mCommitDrawPending = false;
7229 mReadyToShow = false;
7230 if (mAppToken != null) {
7231 mAppToken.allDrawn = false;
7232 }
7233
7234 int flags = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235
7236 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
7237 flags |= Surface.SECURE;
7238 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007239 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007240 TAG, "Creating surface in session "
7241 + mSession.mSurfaceSession + " window " + this
7242 + " w=" + mFrame.width()
7243 + " h=" + mFrame.height() + " format="
7244 + mAttrs.format + " flags=" + flags);
7245
7246 int w = mFrame.width();
7247 int h = mFrame.height();
7248 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
7249 // for a scaled surface, we always want the requested
7250 // size.
7251 w = mRequestedWidth;
7252 h = mRequestedHeight;
7253 }
7254
Romain Guy9825ec62009-10-01 00:58:09 -07007255 // Something is wrong and SurfaceFlinger will not like this,
7256 // try to revert to sane values
7257 if (w <= 0) w = 1;
7258 if (h <= 0) h = 1;
7259
Dianne Hackborn16064f92010-03-25 00:47:24 -07007260 mSurfaceShown = false;
7261 mSurfaceLayer = 0;
7262 mSurfaceAlpha = 1;
7263 mSurfaceX = 0;
7264 mSurfaceY = 0;
7265 mSurfaceW = w;
7266 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007267 try {
Romain Guyd10cd572010-10-10 13:33:22 -07007268 final boolean isHwAccelerated = (mAttrs.flags &
7269 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
7270 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
7271 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
7272 flags |= Surface.OPAQUE;
7273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007274 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07007275 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08007276 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07007277 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007278 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007279 + mSurface + " IN SESSION "
7280 + mSession.mSurfaceSession
7281 + ": pid=" + mSession.mPid + " format="
7282 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007283 + Integer.toHexString(flags)
7284 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007285 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007286 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 reclaimSomeSurfaceMemoryLocked(this, "create");
7288 return null;
7289 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007290 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007291 return null;
7292 }
Romain Guy06882f82009-06-10 13:36:04 -07007293
Joe Onorato8a9b2202010-02-26 18:56:32 -08007294 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 TAG, "Got surface: " + mSurface
7296 + ", set left=" + mFrame.left + " top=" + mFrame.top
7297 + ", animLayer=" + mAnimLayer);
7298 if (SHOW_TRANSACTIONS) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007299 Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
7300 logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007301 mFrame.width() + "x" + mFrame.height() + "), layer=" +
7302 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007303 }
7304 Surface.openTransaction();
7305 try {
7306 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07007307 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07007308 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07007309 mSurface.setPosition(mSurfaceX, mSurfaceY);
7310 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007311 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007312 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007313 mSurface.hide();
7314 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007315 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 mSurface.setFlags(Surface.SURFACE_DITHER,
7317 Surface.SURFACE_DITHER);
7318 }
7319 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007320 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 reclaimSomeSurfaceMemoryLocked(this, "create-init");
7322 }
7323 mLastHidden = true;
7324 } finally {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 Surface.closeTransaction();
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08007326 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007327 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007328 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007329 TAG, "Created surface " + this);
7330 }
7331 return mSurface;
7332 }
Romain Guy06882f82009-06-10 13:36:04 -07007333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007335 if (mAppToken != null && this == mAppToken.startingWindow) {
7336 mAppToken.startingDisplayed = false;
7337 }
Romain Guy06882f82009-06-10 13:36:04 -07007338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007340 mDrawPending = false;
7341 mCommitDrawPending = false;
7342 mReadyToShow = false;
7343
7344 int i = mChildWindows.size();
7345 while (i > 0) {
7346 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007347 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007348 c.mAttachedHidden = true;
7349 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007350
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007351 if (mReportDestroySurface) {
7352 mReportDestroySurface = false;
7353 mSurfacePendingDestroy = true;
7354 try {
7355 mClient.dispatchGetNewSurface();
7356 // We'll really destroy on the next time around.
7357 return;
7358 } catch (RemoteException e) {
7359 }
7360 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007363 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007364 RuntimeException e = null;
7365 if (!HIDE_STACK_CRAWLS) {
7366 e = new RuntimeException();
7367 e.fillInStackTrace();
7368 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007369 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007370 + mSurface + ", session " + mSession, e);
7371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007373 RuntimeException e = null;
7374 if (!HIDE_STACK_CRAWLS) {
7375 e = new RuntimeException();
7376 e.fillInStackTrace();
7377 }
7378 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007379 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007380 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007381 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007382 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 + " surface " + mSurface + " session " + mSession
7384 + ": " + e.toString());
7385 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007386
Dianne Hackborn16064f92010-03-25 00:47:24 -07007387 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007389 }
7390 }
7391
7392 boolean finishDrawingLocked() {
7393 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007394 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007395 TAG, "finishDrawingLocked: " + mSurface);
7396 mCommitDrawPending = true;
7397 mDrawPending = false;
7398 return true;
7399 }
7400 return false;
7401 }
7402
7403 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007404 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007405 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007407 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 }
7409 mCommitDrawPending = false;
7410 mReadyToShow = true;
7411 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7412 final AppWindowToken atoken = mAppToken;
7413 if (atoken == null || atoken.allDrawn || starting) {
7414 performShowLocked();
7415 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007416 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007417 }
7418
7419 // This must be called while inside a transaction.
7420 boolean performShowLocked() {
7421 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007422 RuntimeException e = null;
7423 if (!HIDE_STACK_CRAWLS) {
7424 e = new RuntimeException();
7425 e.fillInStackTrace();
7426 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007427 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7429 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7430 }
7431 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007432 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7433 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007434 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007435 + " during animation: policyVis=" + mPolicyVisibility
7436 + " attHidden=" + mAttachedHidden
7437 + " tok.hiddenRequested="
7438 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007439 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007440 + (mAppToken != null ? mAppToken.hidden : false)
7441 + " animating=" + mAnimating
7442 + " tok animating="
7443 + (mAppToken != null ? mAppToken.animating : false));
7444 if (!showSurfaceRobustlyLocked(this)) {
7445 return false;
7446 }
7447 mLastAlpha = -1;
7448 mHasDrawn = true;
7449 mLastHidden = false;
7450 mReadyToShow = false;
7451 enableScreenIfNeededLocked();
7452
7453 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 int i = mChildWindows.size();
7456 while (i > 0) {
7457 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007458 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007459 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007461 if (c.mSurface != null) {
7462 c.performShowLocked();
7463 // It hadn't been shown, which means layout not
7464 // performed on it, so now we want to make sure to
7465 // do a layout. If called from within the transaction
7466 // loop, this will cause it to restart with a new
7467 // layout.
7468 mLayoutNeeded = true;
7469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007470 }
7471 }
Romain Guy06882f82009-06-10 13:36:04 -07007472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007473 if (mAttrs.type != TYPE_APPLICATION_STARTING
7474 && mAppToken != null) {
7475 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007476
Dianne Hackborn248b1882009-09-16 16:46:44 -07007477 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007478 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007479 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007480 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007481 // If this initial window is animating, stop it -- we
7482 // will do an animation to reveal it from behind the
7483 // starting window, so there is no need for it to also
7484 // be doing its own stuff.
7485 if (mAnimation != null) {
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007486 mAnimation.cancel();
Dianne Hackborn248b1882009-09-16 16:46:44 -07007487 mAnimation = null;
7488 // Make sure we clean up the animation.
7489 mAnimating = true;
7490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 mFinishedStarting.add(mAppToken);
7492 mH.sendEmptyMessage(H.FINISHED_STARTING);
7493 }
7494 mAppToken.updateReportedVisibilityLocked();
7495 }
7496 }
7497 return true;
7498 }
Romain Guy06882f82009-06-10 13:36:04 -07007499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007500 // This must be called while inside a transaction. Returns true if
7501 // there is more animation to run.
7502 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007503 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007506 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7507 mHasTransformation = true;
7508 mHasLocalTransformation = true;
7509 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007510 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 TAG, "Starting animation in " + this +
7512 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7513 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7514 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7515 mAnimation.setStartTime(currentTime);
7516 mLocalAnimating = true;
7517 mAnimating = true;
7518 }
7519 mTransformation.clear();
7520 final boolean more = mAnimation.getTransformation(
7521 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007522 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523 TAG, "Stepped animation in " + this +
7524 ": more=" + more + ", xform=" + mTransformation);
7525 if (more) {
7526 // we're not done!
7527 return true;
7528 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007529 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007530 TAG, "Finished animation in " + this +
7531 " @ " + currentTime);
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007532
7533 if (mAnimation != null) {
7534 mAnimation.cancel();
7535 mAnimation = null;
7536 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 //WindowManagerService.this.dump();
7538 }
7539 mHasLocalTransformation = false;
7540 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007541 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007542 // When our app token is animating, we kind-of pretend like
7543 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7544 // part of this check means that we will only do this if
7545 // our window is not currently exiting, or it is not
7546 // locally animating itself. The idea being that one that
7547 // is exiting and doing a local animation should be removed
7548 // once that animation is done.
7549 mAnimating = true;
7550 mHasTransformation = true;
7551 mTransformation.clear();
7552 return false;
7553 } else if (mHasTransformation) {
7554 // Little trick to get through the path below to act like
7555 // we have finished an animation.
7556 mAnimating = true;
7557 } else if (isAnimating()) {
7558 mAnimating = true;
7559 }
7560 } else if (mAnimation != null) {
7561 // If the display is frozen, and there is a pending animation,
7562 // clear it and make sure we run the cleanup code.
7563 mAnimating = true;
7564 mLocalAnimating = true;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007565 mAnimation.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007566 mAnimation = null;
7567 }
Romain Guy06882f82009-06-10 13:36:04 -07007568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 if (!mAnimating && !mLocalAnimating) {
7570 return false;
7571 }
7572
Joe Onorato8a9b2202010-02-26 18:56:32 -08007573 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007574 TAG, "Animation done in " + this + ": exiting=" + mExiting
7575 + ", reportedVisible="
7576 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007578 mAnimating = false;
7579 mLocalAnimating = false;
Brad Fitzpatrick3fe38512010-11-03 11:46:54 -07007580 if (mAnimation != null) {
7581 mAnimation.cancel();
7582 mAnimation = null;
7583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 mAnimLayer = mLayer;
7585 if (mIsImWindow) {
7586 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007587 } else if (mIsWallpaper) {
7588 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007589 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007590 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 + " anim layer: " + mAnimLayer);
7592 mHasTransformation = false;
7593 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007594 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7595 if (DEBUG_VISIBILITY) {
7596 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7597 + mPolicyVisibilityAfterAnim);
7598 }
7599 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7600 if (!mPolicyVisibility) {
7601 if (mCurrentFocus == this) {
7602 mFocusMayChange = true;
7603 }
7604 // Window is no longer visible -- make sure if we were waiting
7605 // for it to be displayed before enabling the display, that
7606 // we allow the display to be enabled now.
7607 enableScreenIfNeededLocked();
7608 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007610 mTransformation.clear();
7611 if (mHasDrawn
7612 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7613 && mAppToken != null
7614 && mAppToken.firstWindowDrawn
7615 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007616 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 + mToken + ": first real window done animating");
7618 mFinishedStarting.add(mAppToken);
7619 mH.sendEmptyMessage(H.FINISHED_STARTING);
7620 }
Romain Guy06882f82009-06-10 13:36:04 -07007621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 finishExit();
7623
7624 if (mAppToken != null) {
7625 mAppToken.updateReportedVisibilityLocked();
7626 }
7627
7628 return false;
7629 }
7630
7631 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007632 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 TAG, "finishExit in " + this
7634 + ": exiting=" + mExiting
7635 + " remove=" + mRemoveOnExit
7636 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 final int N = mChildWindows.size();
7639 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007640 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007641 }
Romain Guy06882f82009-06-10 13:36:04 -07007642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 if (!mExiting) {
7644 return;
7645 }
Romain Guy06882f82009-06-10 13:36:04 -07007646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 if (isWindowAnimating()) {
7648 return;
7649 }
7650
Joe Onorato8a9b2202010-02-26 18:56:32 -08007651 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007652 TAG, "Exit animation finished in " + this
7653 + ": remove=" + mRemoveOnExit);
7654 if (mSurface != null) {
7655 mDestroySurface.add(this);
7656 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007657 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007658 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 try {
7660 mSurface.hide();
7661 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007662 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 }
7664 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 }
7666 mExiting = false;
7667 if (mRemoveOnExit) {
7668 mPendingRemove.add(this);
7669 mRemoveOnExit = false;
7670 }
7671 }
Romain Guy06882f82009-06-10 13:36:04 -07007672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007673 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7674 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7675 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7676 if (dtdx < -.000001f || dtdx > .000001f) return false;
7677 if (dsdy < -.000001f || dsdy > .000001f) return false;
7678 return true;
7679 }
Romain Guy06882f82009-06-10 13:36:04 -07007680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007681 void computeShownFrameLocked() {
7682 final boolean selfTransformation = mHasLocalTransformation;
7683 Transformation attachedTransformation =
7684 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7685 ? mAttachedWindow.mTransformation : null;
7686 Transformation appTransformation =
7687 (mAppToken != null && mAppToken.hasTransformation)
7688 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007689
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007690 // Wallpapers are animated based on the "real" window they
7691 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007692 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007693 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007694 if (mWallpaperTarget.mHasLocalTransformation &&
7695 mWallpaperTarget.mAnimation != null &&
7696 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007697 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007698 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007699 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007700 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007701 }
7702 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007703 mWallpaperTarget.mAppToken.hasTransformation &&
7704 mWallpaperTarget.mAppToken.animation != null &&
7705 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007706 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007707 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007708 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007709 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007710 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007711 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007712
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007713 final boolean screenAnimation = mScreenRotationAnimation != null
7714 && mScreenRotationAnimation.isAnimating();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007715 if (selfTransformation || attachedTransformation != null
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007716 || appTransformation != null || screenAnimation) {
Romain Guy06882f82009-06-10 13:36:04 -07007717 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007718 final Rect frame = mFrame;
7719 final float tmpFloats[] = mTmpFloats;
7720 final Matrix tmpMatrix = mTmpMatrix;
7721
7722 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007723 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007725 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007726 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007727 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007728 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007729 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 }
7731 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007732 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007733 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007734 if (screenAnimation) {
7735 tmpMatrix.postConcat(
7736 mScreenRotationAnimation.getEnterTransformation().getMatrix());
7737 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007738
7739 // "convert" it into SurfaceFlinger's format
7740 // (a 2x2 matrix + an offset)
7741 // Here we must not transform the position of the surface
7742 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007743 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007744
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007745 mHaveMatrix = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007746 tmpMatrix.getValues(tmpFloats);
7747 mDsDx = tmpFloats[Matrix.MSCALE_X];
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007748 mDtDx = tmpFloats[Matrix.MSKEW_Y];
7749 mDsDy = tmpFloats[Matrix.MSKEW_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007751 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7752 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007753 int w = frame.width();
7754 int h = frame.height();
7755 mShownFrame.set(x, y, x+w, y+h);
7756
7757 // Now set the alpha... but because our current hardware
7758 // can't do alpha transformation on a non-opaque surface,
7759 // turn it off if we are running an animation that is also
7760 // transforming since it is more important to have that
7761 // animation be smooth.
7762 mShownAlpha = mAlpha;
7763 if (!mLimitedAlphaCompositing
7764 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7765 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7766 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007767 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 if (selfTransformation) {
7769 mShownAlpha *= mTransformation.getAlpha();
7770 }
7771 if (attachedTransformation != null) {
7772 mShownAlpha *= attachedTransformation.getAlpha();
7773 }
7774 if (appTransformation != null) {
7775 mShownAlpha *= appTransformation.getAlpha();
7776 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08007777 if (screenAnimation) {
7778 mShownAlpha *=
7779 mScreenRotationAnimation.getEnterTransformation().getAlpha();
7780 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007781 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007782 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 }
Romain Guy06882f82009-06-10 13:36:04 -07007784
Joe Onorato8a9b2202010-02-26 18:56:32 -08007785 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 TAG, "Continuing animation in " + this +
7787 ": " + mShownFrame +
7788 ", alpha=" + mTransformation.getAlpha());
7789 return;
7790 }
Romain Guy06882f82009-06-10 13:36:04 -07007791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007793 if (mXOffset != 0 || mYOffset != 0) {
7794 mShownFrame.offset(mXOffset, mYOffset);
7795 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007796 mShownAlpha = mAlpha;
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08007797 mHaveMatrix = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007798 mDsDx = 1;
7799 mDtDx = 0;
7800 mDsDy = 0;
7801 mDtDy = 1;
7802 }
Romain Guy06882f82009-06-10 13:36:04 -07007803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007804 /**
7805 * Is this window visible? It is not visible if there is no
7806 * surface, or we are in the process of running an exit animation
7807 * that will remove the surface, or its app token has been hidden.
7808 */
7809 public boolean isVisibleLw() {
7810 final AppWindowToken atoken = mAppToken;
7811 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7812 && (atoken == null || !atoken.hiddenRequested)
7813 && !mExiting && !mDestroying;
7814 }
7815
7816 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007817 * Like {@link #isVisibleLw}, but also counts a window that is currently
7818 * "hidden" behind the keyguard as visible. This allows us to apply
7819 * things like window flags that impact the keyguard.
7820 * XXX I am starting to think we need to have ANOTHER visibility flag
7821 * for this "hidden behind keyguard" state rather than overloading
7822 * mPolicyVisibility. Ungh.
7823 */
7824 public boolean isVisibleOrBehindKeyguardLw() {
7825 final AppWindowToken atoken = mAppToken;
7826 return mSurface != null && !mAttachedHidden
7827 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007828 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007829 && !mExiting && !mDestroying;
7830 }
7831
7832 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 * Is this window visible, ignoring its app token? It is not visible
7834 * if there is no surface, or we are in the process of running an exit animation
7835 * that will remove the surface.
7836 */
7837 public boolean isWinVisibleLw() {
7838 final AppWindowToken atoken = mAppToken;
7839 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7840 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7841 && !mExiting && !mDestroying;
7842 }
7843
7844 /**
7845 * The same as isVisible(), but follows the current hidden state of
7846 * the associated app token, not the pending requested hidden state.
7847 */
7848 boolean isVisibleNow() {
7849 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007850 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007851 }
7852
7853 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007854 * Can this window possibly be a drag/drop target? The test here is
7855 * a combination of the above "visible now" with the check that the
7856 * Input Manager uses when discarding windows from input consideration.
7857 */
7858 boolean isPotentialDragTarget() {
7859 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7860 }
7861
7862 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007863 * Same as isVisible(), but we also count it as visible between the
7864 * call to IWindowSession.add() and the first relayout().
7865 */
7866 boolean isVisibleOrAdding() {
7867 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007868 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007869 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7870 && mPolicyVisibility && !mAttachedHidden
7871 && (atoken == null || !atoken.hiddenRequested)
7872 && !mExiting && !mDestroying;
7873 }
7874
7875 /**
7876 * Is this window currently on-screen? It is on-screen either if it
7877 * is visible or it is currently running an animation before no longer
7878 * being visible.
7879 */
7880 boolean isOnScreen() {
7881 final AppWindowToken atoken = mAppToken;
7882 if (atoken != null) {
7883 return mSurface != null && mPolicyVisibility && !mDestroying
7884 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007885 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 } else {
7887 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007888 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007889 }
7890 }
Romain Guy06882f82009-06-10 13:36:04 -07007891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007892 /**
7893 * Like isOnScreen(), but we don't return true if the window is part
7894 * of a transition that has not yet been started.
7895 */
7896 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007897 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007898 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007899 return false;
7900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007901 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007902 final boolean animating = atoken != null
7903 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007904 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007905 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7906 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007907 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 }
7909
7910 /** Is the window or its container currently animating? */
7911 boolean isAnimating() {
7912 final WindowState attached = mAttachedWindow;
7913 final AppWindowToken atoken = mAppToken;
7914 return mAnimation != null
7915 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007916 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007917 (atoken.animation != null
7918 || atoken.inPendingTransaction));
7919 }
7920
7921 /** Is this window currently animating? */
7922 boolean isWindowAnimating() {
7923 return mAnimation != null;
7924 }
7925
7926 /**
7927 * Like isOnScreen, but returns false if the surface hasn't yet
7928 * been drawn.
7929 */
7930 public boolean isDisplayedLw() {
7931 final AppWindowToken atoken = mAppToken;
7932 return mSurface != null && mPolicyVisibility && !mDestroying
7933 && !mDrawPending && !mCommitDrawPending
7934 && ((!mAttachedHidden &&
7935 (atoken == null || !atoken.hiddenRequested))
7936 || mAnimating);
7937 }
7938
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007939 /**
7940 * Returns true if the window has a surface that it has drawn a
7941 * complete UI in to.
7942 */
7943 public boolean isDrawnLw() {
7944 final AppWindowToken atoken = mAppToken;
7945 return mSurface != null && !mDestroying
7946 && !mDrawPending && !mCommitDrawPending;
7947 }
7948
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007949 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007950 * Return true if the window is opaque and fully drawn. This indicates
7951 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007952 */
7953 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007954 return (mAttrs.format == PixelFormat.OPAQUE
7955 || mAttrs.type == TYPE_WALLPAPER)
7956 && mSurface != null && mAnimation == null
7957 && (mAppToken == null || mAppToken.animation == null)
7958 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007959 }
7960
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007961 /**
7962 * Return whether this window is wanting to have a translation
7963 * animation applied to it for an in-progress move. (Only makes
7964 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
7965 */
7966 boolean shouldAnimateMove() {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007967 return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007968 && (mFrame.top != mLastFrame.top
7969 || mFrame.left != mLastFrame.left)
Dianne Hackborn0f761d62010-11-30 22:06:10 -08007970 && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove())
Dianne Hackborn1c24e952010-11-23 00:34:30 -08007971 && mPolicy.isScreenOn();
7972 }
7973
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007974 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7975 return
7976 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007977 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7978 // only if it's visible
7979 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007980 // and only if the application fills the compatible screen
7981 mFrame.left <= mCompatibleScreenFrame.left &&
7982 mFrame.top <= mCompatibleScreenFrame.top &&
7983 mFrame.right >= mCompatibleScreenFrame.right &&
7984 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007985 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007986 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007987 }
7988
7989 boolean isFullscreen(int screenWidth, int screenHeight) {
7990 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007991 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007992 }
7993
7994 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007995 disposeInputChannel();
7996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007997 if (mAttachedWindow != null) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007998 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007999 mAttachedWindow.mChildWindows.remove(this);
8000 }
8001 destroySurfaceLocked();
8002 mSession.windowRemovedLocked();
8003 try {
8004 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
8005 } catch (RuntimeException e) {
8006 // Ignore if it has already been removed (usually because
8007 // we are doing this as part of processing a death note.)
8008 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07008009 }
8010
8011 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008012 if (mInputChannel != null) {
8013 mInputManager.unregisterInputChannel(mInputChannel);
8014
8015 mInputChannel.dispose();
8016 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07008017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008018 }
8019
8020 private class DeathRecipient implements IBinder.DeathRecipient {
8021 public void binderDied() {
8022 try {
8023 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008024 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008025 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008026 if (win != null) {
8027 removeWindowLocked(mSession, win);
8028 }
8029 }
8030 } catch (IllegalArgumentException ex) {
8031 // This will happen if the window has already been
8032 // removed.
8033 }
8034 }
8035 }
8036
8037 /** Returns true if this window desires key events. */
8038 public final boolean canReceiveKeys() {
8039 return isVisibleOrAdding()
8040 && (mViewVisibility == View.VISIBLE)
8041 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
8042 }
8043
8044 public boolean hasDrawnLw() {
8045 return mHasDrawn;
8046 }
8047
8048 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008049 return showLw(doAnimation, true);
8050 }
8051
8052 boolean showLw(boolean doAnimation, boolean requestAnim) {
8053 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
8054 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008055 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008056 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008057 if (doAnimation) {
8058 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
8059 + mPolicyVisibility + " mAnimation=" + mAnimation);
8060 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8061 doAnimation = false;
8062 } else if (mPolicyVisibility && mAnimation == null) {
8063 // Check for the case where we are currently visible and
8064 // not animating; we do not want to do animation at such a
8065 // point to become visible when we already are.
8066 doAnimation = false;
8067 }
8068 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008069 mPolicyVisibility = true;
8070 mPolicyVisibilityAfterAnim = true;
8071 if (doAnimation) {
8072 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
8073 }
8074 if (requestAnim) {
8075 requestAnimationLocked(0);
8076 }
8077 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008078 }
8079
8080 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008081 return hideLw(doAnimation, true);
8082 }
8083
8084 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008085 if (doAnimation) {
8086 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
8087 doAnimation = false;
8088 }
8089 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008090 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
8091 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008092 if (!current) {
8093 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008095 if (doAnimation) {
8096 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
8097 if (mAnimation == null) {
8098 doAnimation = false;
8099 }
8100 }
8101 if (doAnimation) {
8102 mPolicyVisibilityAfterAnim = false;
8103 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008104 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008105 mPolicyVisibilityAfterAnim = false;
8106 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08008107 // Window is no longer visible -- make sure if we were waiting
8108 // for it to be displayed before enabling the display, that
8109 // we allow the display to be enabled now.
8110 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008111 if (mCurrentFocus == this) {
8112 mFocusMayChange = true;
8113 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008114 }
8115 if (requestAnim) {
8116 requestAnimationLocked(0);
8117 }
8118 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008119 }
8120
Jeff Brownfbf09772011-01-16 14:06:57 -08008121 public void getTouchableRegion(Region outRegion) {
8122 final Rect frame = mFrame;
8123 switch (mTouchableInsets) {
8124 default:
8125 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
8126 outRegion.set(frame);
8127 break;
8128 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
8129 final Rect inset = mGivenContentInsets;
8130 outRegion.set(
8131 frame.left + inset.left, frame.top + inset.top,
8132 frame.right - inset.right, frame.bottom - inset.bottom);
8133 break;
8134 }
8135 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
8136 final Rect inset = mGivenVisibleInsets;
8137 outRegion.set(
8138 frame.left + inset.left, frame.top + inset.top,
8139 frame.right - inset.right, frame.bottom - inset.bottom);
8140 break;
8141 }
8142 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
8143 final Region givenTouchableRegion = mGivenTouchableRegion;
8144 outRegion.set(givenTouchableRegion);
8145 outRegion.translate(frame.left, frame.top);
8146 break;
8147 }
8148 }
8149 }
8150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008151 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008152 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
8153 pw.print(" mClient="); pw.println(mClient.asBinder());
8154 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
8155 if (mAttachedWindow != null || mLayoutAttached) {
8156 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
8157 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
8158 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07008159 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
8160 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
8161 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008162 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
8163 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008164 }
8165 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
8166 pw.print(" mSubLayer="); pw.print(mSubLayer);
8167 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
8168 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
8169 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
8170 pw.print("="); pw.print(mAnimLayer);
8171 pw.print(" mLastLayer="); pw.println(mLastLayer);
8172 if (mSurface != null) {
8173 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07008174 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
8175 pw.print(" layer="); pw.print(mSurfaceLayer);
8176 pw.print(" alpha="); pw.print(mSurfaceAlpha);
8177 pw.print(" rect=("); pw.print(mSurfaceX);
8178 pw.print(","); pw.print(mSurfaceY);
8179 pw.print(") "); pw.print(mSurfaceW);
8180 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008181 }
8182 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
8183 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
8184 if (mAppToken != null) {
8185 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
8186 }
8187 if (mTargetAppToken != null) {
8188 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
8189 }
8190 pw.print(prefix); pw.print("mViewVisibility=0x");
8191 pw.print(Integer.toHexString(mViewVisibility));
8192 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008193 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
8194 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008195 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
8196 pw.print(prefix); pw.print("mPolicyVisibility=");
8197 pw.print(mPolicyVisibility);
8198 pw.print(" mPolicyVisibilityAfterAnim=");
8199 pw.print(mPolicyVisibilityAfterAnim);
8200 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
8201 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008202 if (!mRelayoutCalled) {
8203 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
8204 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008205 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008206 pw.print(" h="); pw.print(mRequestedHeight);
8207 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008208 if (mXOffset != 0 || mYOffset != 0) {
8209 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
8210 pw.print(" y="); pw.println(mYOffset);
8211 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008212 pw.print(prefix); pw.print("mGivenContentInsets=");
8213 mGivenContentInsets.printShortString(pw);
8214 pw.print(" mGivenVisibleInsets=");
8215 mGivenVisibleInsets.printShortString(pw);
8216 pw.println();
8217 if (mTouchableInsets != 0 || mGivenInsetsPending) {
8218 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
8219 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
8220 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008221 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008222 pw.print(prefix); pw.print("mShownFrame=");
8223 mShownFrame.printShortString(pw);
8224 pw.print(" last="); mLastShownFrame.printShortString(pw);
8225 pw.println();
8226 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
8227 pw.print(" last="); mLastFrame.printShortString(pw);
8228 pw.println();
8229 pw.print(prefix); pw.print("mContainingFrame=");
8230 mContainingFrame.printShortString(pw);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08008231 pw.print(" mParentFrame=");
8232 mParentFrame.printShortString(pw);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008233 pw.print(" mDisplayFrame=");
8234 mDisplayFrame.printShortString(pw);
8235 pw.println();
8236 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
8237 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
8238 pw.println();
8239 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
8240 pw.print(" last="); mLastContentInsets.printShortString(pw);
8241 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
8242 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
8243 pw.println();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008244 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
8245 || mAnimation != null) {
8246 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
8247 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
8248 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
8249 pw.print(" mAnimation="); pw.println(mAnimation);
8250 }
8251 if (mHasTransformation || mHasLocalTransformation) {
8252 pw.print(prefix); pw.print("XForm: has=");
8253 pw.print(mHasTransformation);
8254 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
8255 pw.print(" "); mTransformation.printShortString(pw);
8256 pw.println();
8257 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008258 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
8259 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
8260 pw.print(" mAlpha="); pw.print(mAlpha);
8261 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
8262 }
8263 if (mHaveMatrix) {
8264 pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx);
8265 pw.print(" mDtDx="); pw.print(mDtDx);
8266 pw.print(" mDsDy="); pw.print(mDsDy);
8267 pw.print(" mDtDy="); pw.println(mDtDy);
8268 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008269 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
8270 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
8271 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
8272 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
8273 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
8274 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
8275 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
8276 pw.print(" mDestroying="); pw.print(mDestroying);
8277 pw.print(" mRemoved="); pw.println(mRemoved);
8278 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008279 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008280 pw.print(prefix); pw.print("mOrientationChanging=");
8281 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07008282 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
8283 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008284 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07008285 if (mHScale != 1 || mVScale != 1) {
8286 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
8287 pw.print(" mVScale="); pw.println(mVScale);
8288 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07008289 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008290 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
8291 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
8292 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08008293 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
8294 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
8295 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
8296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008297 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07008298
8299 String makeInputChannelName() {
8300 return Integer.toHexString(System.identityHashCode(this))
8301 + " " + mAttrs.getTitle();
8302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008303
8304 @Override
8305 public String toString() {
Mattias Petersson1622eee2010-12-21 10:15:11 +01008306 if (mStringNameCache == null || mLastTitle != mAttrs.getTitle()
8307 || mWasPaused != mToken.paused) {
8308 mLastTitle = mAttrs.getTitle();
8309 mWasPaused = mToken.paused;
8310 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
8311 + " " + mLastTitle + " paused=" + mWasPaused + "}";
8312 }
8313 return mStringNameCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008314 }
8315 }
Romain Guy06882f82009-06-10 13:36:04 -07008316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008317 // -------------------------------------------------------------
8318 // Window Token State
8319 // -------------------------------------------------------------
8320
8321 class WindowToken {
8322 // The actual token.
8323 final IBinder token;
8324
8325 // The type of window this token is for, as per WindowManager.LayoutParams.
8326 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07008327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 // Set if this token was explicitly added by a client, so should
8329 // not be removed when all windows are removed.
8330 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07008331
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008332 // For printing.
8333 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07008334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008335 // If this is an AppWindowToken, this is non-null.
8336 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07008337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008338 // All of the windows associated with this token.
8339 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
8340
8341 // Is key dispatching paused for this token?
8342 boolean paused = false;
8343
8344 // Should this token's windows be hidden?
8345 boolean hidden;
8346
8347 // Temporary for finding which tokens no longer have visible windows.
8348 boolean hasVisible;
8349
Dianne Hackborna8f60182009-09-01 19:01:50 -07008350 // Set to true when this token is in a pending transaction where it
8351 // will be shown.
8352 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008353
Dianne Hackborna8f60182009-09-01 19:01:50 -07008354 // Set to true when this token is in a pending transaction where it
8355 // will be hidden.
8356 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008357
Dianne Hackborna8f60182009-09-01 19:01:50 -07008358 // Set to true when this token is in a pending transaction where its
8359 // windows will be put to the bottom of the list.
8360 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008361
Dianne Hackborna8f60182009-09-01 19:01:50 -07008362 // Set to true when this token is in a pending transaction where its
8363 // windows will be put to the top of the list.
8364 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008366 WindowToken(IBinder _token, int type, boolean _explicit) {
8367 token = _token;
8368 windowType = type;
8369 explicit = _explicit;
8370 }
8371
8372 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008373 pw.print(prefix); pw.print("token="); pw.println(token);
8374 pw.print(prefix); pw.print("windows="); pw.println(windows);
8375 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
8376 pw.print(" hidden="); pw.print(hidden);
8377 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008378 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
8379 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
8380 pw.print(" waitingToHide="); pw.print(waitingToHide);
8381 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
8382 pw.print(" sendingToTop="); pw.println(sendingToTop);
8383 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008384 }
8385
8386 @Override
8387 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008388 if (stringName == null) {
8389 StringBuilder sb = new StringBuilder();
8390 sb.append("WindowToken{");
8391 sb.append(Integer.toHexString(System.identityHashCode(this)));
8392 sb.append(" token="); sb.append(token); sb.append('}');
8393 stringName = sb.toString();
8394 }
8395 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008396 }
8397 };
8398
8399 class AppWindowToken extends WindowToken {
8400 // Non-null only for application tokens.
8401 final IApplicationToken appToken;
8402
8403 // All of the windows and child windows that are included in this
8404 // application token. Note this list is NOT sorted!
8405 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
8406
8407 int groupId = -1;
8408 boolean appFullscreen;
8409 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07008410
8411 // The input dispatching timeout for this application token in nanoseconds.
8412 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 // These are used for determining when all windows associated with
8415 // an activity have been drawn, so they can be made visible together
8416 // at the same time.
8417 int lastTransactionSequence = mTransactionSequence-1;
8418 int numInterestingWindows;
8419 int numDrawnWindows;
8420 boolean inPendingTransaction;
8421 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008423 // Is this token going to be hidden in a little while? If so, it
8424 // won't be taken into account for setting the screen orientation.
8425 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 // Is this window's surface needed? This is almost like hidden, except
8428 // it will sometimes be true a little earlier: when the token has
8429 // been shown, but is still waiting for its app transition to execute
8430 // before making its windows shown.
8431 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 // Have we told the window clients to hide themselves?
8434 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008436 // Last visibility state we reported to the app token.
8437 boolean reportedVisible;
8438
8439 // Set to true when the token has been removed from the window mgr.
8440 boolean removed;
8441
8442 // Have we been asked to have this token keep the screen frozen?
8443 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008445 boolean animating;
8446 Animation animation;
8447 boolean hasTransformation;
8448 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 // Offset to the window of all layers in the token, for use by
8451 // AppWindowToken animations.
8452 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008454 // Information about an application starting window if displayed.
8455 StartingData startingData;
8456 WindowState startingWindow;
8457 View startingView;
8458 boolean startingDisplayed;
8459 boolean startingMoved;
8460 boolean firstWindowDrawn;
8461
Jeff Brown928e0542011-01-10 11:17:36 -08008462 // Input application handle used by the input dispatcher.
8463 InputApplicationHandle mInputApplicationHandle;
8464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008465 AppWindowToken(IApplicationToken _token) {
8466 super(_token.asBinder(),
8467 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8468 appWindowToken = this;
8469 appToken = _token;
Jeff Brown928e0542011-01-10 11:17:36 -08008470 mInputApplicationHandle = new InputApplicationHandle(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008471 }
Romain Guy06882f82009-06-10 13:36:04 -07008472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008473 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008474 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 TAG, "Setting animation in " + this + ": " + anim);
8476 animation = anim;
8477 animating = false;
8478 anim.restrictDuration(MAX_ANIMATION_DURATION);
8479 anim.scaleCurrentDuration(mTransitionAnimationScale);
8480 int zorder = anim.getZAdjustment();
8481 int adj = 0;
8482 if (zorder == Animation.ZORDER_TOP) {
8483 adj = TYPE_LAYER_OFFSET;
8484 } else if (zorder == Animation.ZORDER_BOTTOM) {
8485 adj = -TYPE_LAYER_OFFSET;
8486 }
Romain Guy06882f82009-06-10 13:36:04 -07008487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008488 if (animLayerAdjustment != adj) {
8489 animLayerAdjustment = adj;
8490 updateLayers();
8491 }
8492 }
Romain Guy06882f82009-06-10 13:36:04 -07008493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 public void setDummyAnimation() {
8495 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008496 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008497 TAG, "Setting dummy animation in " + this);
8498 animation = sDummyAnimation;
8499 }
8500 }
8501
8502 public void clearAnimation() {
8503 if (animation != null) {
8504 animation = null;
8505 animating = true;
8506 }
8507 }
Romain Guy06882f82009-06-10 13:36:04 -07008508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008509 void updateLayers() {
8510 final int N = allAppWindows.size();
8511 final int adj = animLayerAdjustment;
8512 for (int i=0; i<N; i++) {
8513 WindowState w = allAppWindows.get(i);
8514 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008515 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 + w.mAnimLayer);
8517 if (w == mInputMethodTarget) {
8518 setInputMethodAnimLayerAdjustment(adj);
8519 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008520 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008521 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 }
8524 }
Romain Guy06882f82009-06-10 13:36:04 -07008525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 void sendAppVisibilityToClients() {
8527 final int N = allAppWindows.size();
8528 for (int i=0; i<N; i++) {
8529 WindowState win = allAppWindows.get(i);
8530 if (win == startingWindow && clientHidden) {
8531 // Don't hide the starting window.
8532 continue;
8533 }
8534 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008535 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 "Setting visibility of " + win + ": " + (!clientHidden));
8537 win.mClient.dispatchAppVisibility(!clientHidden);
8538 } catch (RemoteException e) {
8539 }
8540 }
8541 }
Romain Guy06882f82009-06-10 13:36:04 -07008542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008543 void showAllWindowsLocked() {
8544 final int NW = allAppWindows.size();
8545 for (int i=0; i<NW; i++) {
8546 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008547 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 "performing show on: " + w);
8549 w.performShowLocked();
8550 }
8551 }
Romain Guy06882f82009-06-10 13:36:04 -07008552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008553 // This must be called while inside a transaction.
8554 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008555 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 if (animation == sDummyAnimation) {
8559 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008560 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 // when it is really time to animate, this will be set to
8562 // a real animation and the next call will execute normally.
8563 return false;
8564 }
Romain Guy06882f82009-06-10 13:36:04 -07008565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8567 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008568 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008569 TAG, "Starting animation in " + this +
8570 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8571 + " scale=" + mTransitionAnimationScale
8572 + " allDrawn=" + allDrawn + " animating=" + animating);
8573 animation.initialize(dw, dh, dw, dh);
8574 animation.setStartTime(currentTime);
8575 animating = true;
8576 }
8577 transformation.clear();
8578 final boolean more = animation.getTransformation(
8579 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008580 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008581 TAG, "Stepped animation in " + this +
8582 ": more=" + more + ", xform=" + transformation);
8583 if (more) {
8584 // we're done!
8585 hasTransformation = true;
8586 return true;
8587 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008588 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008589 TAG, "Finished animation in " + this +
8590 " @ " + currentTime);
8591 animation = null;
8592 }
8593 } else if (animation != null) {
8594 // If the display is frozen, and there is a pending animation,
8595 // clear it and make sure we run the cleanup code.
8596 animating = true;
8597 animation = null;
8598 }
8599
8600 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008602 if (!animating) {
8603 return false;
8604 }
8605
8606 clearAnimation();
8607 animating = false;
8608 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8609 moveInputMethodWindowsIfNeededLocked(true);
8610 }
Romain Guy06882f82009-06-10 13:36:04 -07008611
Joe Onorato8a9b2202010-02-26 18:56:32 -08008612 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008613 TAG, "Animation done in " + this
8614 + ": reportedVisible=" + reportedVisible);
8615
8616 transformation.clear();
8617 if (animLayerAdjustment != 0) {
8618 animLayerAdjustment = 0;
8619 updateLayers();
8620 }
Romain Guy06882f82009-06-10 13:36:04 -07008621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008622 final int N = windows.size();
8623 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008624 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008625 }
8626 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 return false;
8629 }
8630
8631 void updateReportedVisibilityLocked() {
8632 if (appToken == null) {
8633 return;
8634 }
Romain Guy06882f82009-06-10 13:36:04 -07008635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008636 int numInteresting = 0;
8637 int numVisible = 0;
8638 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008639
Joe Onorato8a9b2202010-02-26 18:56:32 -08008640 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 final int N = allAppWindows.size();
8642 for (int i=0; i<N; i++) {
8643 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008644 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008645 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008646 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8647 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 continue;
8649 }
8650 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008651 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008652 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008654 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008655 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008656 + " pv=" + win.mPolicyVisibility
8657 + " dp=" + win.mDrawPending
8658 + " cdp=" + win.mCommitDrawPending
8659 + " ah=" + win.mAttachedHidden
8660 + " th="
8661 + (win.mAppToken != null
8662 ? win.mAppToken.hiddenRequested : false)
8663 + " a=" + win.mAnimating);
8664 }
8665 }
8666 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008667 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 if (!win.isAnimating()) {
8669 numVisible++;
8670 }
8671 nowGone = false;
8672 } else if (win.isAnimating()) {
8673 nowGone = false;
8674 }
8675 }
Romain Guy06882f82009-06-10 13:36:04 -07008676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008677 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008678 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 + numInteresting + " visible=" + numVisible);
8680 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008681 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008682 TAG, "Visibility changed in " + this
8683 + ": vis=" + nowVisible);
8684 reportedVisible = nowVisible;
8685 Message m = mH.obtainMessage(
8686 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8687 nowVisible ? 1 : 0,
8688 nowGone ? 1 : 0,
8689 this);
8690 mH.sendMessage(m);
8691 }
8692 }
Romain Guy06882f82009-06-10 13:36:04 -07008693
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008694 WindowState findMainWindow() {
8695 int j = windows.size();
8696 while (j > 0) {
8697 j--;
8698 WindowState win = windows.get(j);
8699 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8700 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8701 return win;
8702 }
8703 }
8704 return null;
8705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008707 void dump(PrintWriter pw, String prefix) {
8708 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008709 if (appToken != null) {
8710 pw.print(prefix); pw.println("app=true");
8711 }
8712 if (allAppWindows.size() > 0) {
8713 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8714 }
8715 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008716 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008717 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8718 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8719 pw.print(" clientHidden="); pw.print(clientHidden);
8720 pw.print(" willBeHidden="); pw.print(willBeHidden);
8721 pw.print(" reportedVisible="); pw.println(reportedVisible);
8722 if (paused || freezingScreen) {
8723 pw.print(prefix); pw.print("paused="); pw.print(paused);
8724 pw.print(" freezingScreen="); pw.println(freezingScreen);
8725 }
8726 if (numInterestingWindows != 0 || numDrawnWindows != 0
8727 || inPendingTransaction || allDrawn) {
8728 pw.print(prefix); pw.print("numInterestingWindows=");
8729 pw.print(numInterestingWindows);
8730 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8731 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8732 pw.print(" allDrawn="); pw.println(allDrawn);
8733 }
8734 if (animating || animation != null) {
8735 pw.print(prefix); pw.print("animating="); pw.print(animating);
8736 pw.print(" animation="); pw.println(animation);
8737 }
Dianne Hackborn7da6ac32010-12-09 19:22:04 -08008738 if (hasTransformation) {
8739 pw.print(prefix); pw.print("XForm: ");
8740 transformation.printShortString(pw);
8741 pw.println();
8742 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008743 if (animLayerAdjustment != 0) {
8744 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8745 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008746 if (startingData != null || removed || firstWindowDrawn) {
8747 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8748 pw.print(" removed="); pw.print(removed);
8749 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8750 }
8751 if (startingWindow != null || startingView != null
8752 || startingDisplayed || startingMoved) {
8753 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8754 pw.print(" startingView="); pw.print(startingView);
8755 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8756 pw.print(" startingMoved"); pw.println(startingMoved);
8757 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008758 }
8759
8760 @Override
8761 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008762 if (stringName == null) {
8763 StringBuilder sb = new StringBuilder();
8764 sb.append("AppWindowToken{");
8765 sb.append(Integer.toHexString(System.identityHashCode(this)));
8766 sb.append(" token="); sb.append(token); sb.append('}');
8767 stringName = sb.toString();
8768 }
8769 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008770 }
8771 }
Romain Guy06882f82009-06-10 13:36:04 -07008772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008773 // -------------------------------------------------------------
8774 // DummyAnimation
8775 // -------------------------------------------------------------
8776
8777 // This is an animation that does nothing: it just immediately finishes
8778 // itself every time it is called. It is used as a stub animation in cases
8779 // where we want to synchronize multiple things that may be animating.
8780 static final class DummyAnimation extends Animation {
8781 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8782 return false;
8783 }
8784 }
8785 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008787 // -------------------------------------------------------------
8788 // Async Handler
8789 // -------------------------------------------------------------
8790
8791 static final class StartingData {
8792 final String pkg;
8793 final int theme;
8794 final CharSequence nonLocalizedLabel;
8795 final int labelRes;
8796 final int icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008797 final int windowFlags;
Romain Guy06882f82009-06-10 13:36:04 -07008798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008799 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008800 int _labelRes, int _icon, int _windowFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008801 pkg = _pkg;
8802 theme = _theme;
8803 nonLocalizedLabel = _nonLocalizedLabel;
8804 labelRes = _labelRes;
8805 icon = _icon;
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008806 windowFlags = _windowFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008807 }
8808 }
8809
8810 private final class H extends Handler {
8811 public static final int REPORT_FOCUS_CHANGE = 2;
8812 public static final int REPORT_LOSING_FOCUS = 3;
8813 public static final int ANIMATE = 4;
8814 public static final int ADD_STARTING = 5;
8815 public static final int REMOVE_STARTING = 6;
8816 public static final int FINISHED_STARTING = 7;
8817 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008818 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8819 public static final int HOLD_SCREEN_CHANGED = 12;
8820 public static final int APP_TRANSITION_TIMEOUT = 13;
8821 public static final int PERSIST_ANIMATION_SCALE = 14;
8822 public static final int FORCE_GC = 15;
8823 public static final int ENABLE_SCREEN = 16;
8824 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008825 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008826 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008827 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008828 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008830 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008832 public H() {
8833 }
Romain Guy06882f82009-06-10 13:36:04 -07008834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008835 @Override
8836 public void handleMessage(Message msg) {
8837 switch (msg.what) {
8838 case REPORT_FOCUS_CHANGE: {
8839 WindowState lastFocus;
8840 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008842 synchronized(mWindowMap) {
8843 lastFocus = mLastFocus;
8844 newFocus = mCurrentFocus;
8845 if (lastFocus == newFocus) {
8846 // Focus is not changing, so nothing to do.
8847 return;
8848 }
8849 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008850 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008851 // + " to " + newFocus);
8852 if (newFocus != null && lastFocus != null
8853 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008854 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008855 mLosingFocus.add(lastFocus);
8856 lastFocus = null;
8857 }
8858 }
8859
8860 if (lastFocus != newFocus) {
8861 //System.out.println("Changing focus from " + lastFocus
8862 // + " to " + newFocus);
8863 if (newFocus != null) {
8864 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008865 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008866 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8867 } catch (RemoteException e) {
8868 // Ignore if process has died.
8869 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008870 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008871 }
8872
8873 if (lastFocus != null) {
8874 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008875 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008876 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8877 } catch (RemoteException e) {
8878 // Ignore if process has died.
8879 }
8880 }
Joe Onorato664644d2011-01-23 17:53:23 -08008881
8882 mPolicy.focusChanged(lastFocus, newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008883 }
8884 } break;
8885
8886 case REPORT_LOSING_FOCUS: {
8887 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008889 synchronized(mWindowMap) {
8890 losers = mLosingFocus;
8891 mLosingFocus = new ArrayList<WindowState>();
8892 }
8893
8894 final int N = losers.size();
8895 for (int i=0; i<N; i++) {
8896 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008897 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008898 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8899 } catch (RemoteException e) {
8900 // Ignore if process has died.
8901 }
8902 }
8903 } break;
8904
8905 case ANIMATE: {
8906 synchronized(mWindowMap) {
8907 mAnimationPending = false;
8908 performLayoutAndPlaceSurfacesLocked();
8909 }
8910 } break;
8911
8912 case ADD_STARTING: {
8913 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8914 final StartingData sd = wtoken.startingData;
8915
8916 if (sd == null) {
8917 // Animation has been canceled... do nothing.
8918 return;
8919 }
Romain Guy06882f82009-06-10 13:36:04 -07008920
Joe Onorato8a9b2202010-02-26 18:56:32 -08008921 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008922 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924 View view = null;
8925 try {
8926 view = mPolicy.addStartingWindow(
8927 wtoken.token, sd.pkg,
8928 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08008929 sd.icon, sd.windowFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008930 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008931 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008932 }
8933
8934 if (view != null) {
8935 boolean abort = false;
8936
8937 synchronized(mWindowMap) {
8938 if (wtoken.removed || wtoken.startingData == null) {
8939 // If the window was successfully added, then
8940 // we need to remove it.
8941 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008942 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 "Aborted starting " + wtoken
8944 + ": removed=" + wtoken.removed
8945 + " startingData=" + wtoken.startingData);
8946 wtoken.startingWindow = null;
8947 wtoken.startingData = null;
8948 abort = true;
8949 }
8950 } else {
8951 wtoken.startingView = view;
8952 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 "Added starting " + wtoken
8955 + ": startingWindow="
8956 + wtoken.startingWindow + " startingView="
8957 + wtoken.startingView);
8958 }
8959
8960 if (abort) {
8961 try {
8962 mPolicy.removeStartingWindow(wtoken.token, view);
8963 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008964 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008965 }
8966 }
8967 }
8968 } break;
8969
8970 case REMOVE_STARTING: {
8971 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8972 IBinder token = null;
8973 View view = null;
8974 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008975 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 + wtoken + ": startingWindow="
8977 + wtoken.startingWindow + " startingView="
8978 + wtoken.startingView);
8979 if (wtoken.startingWindow != null) {
8980 view = wtoken.startingView;
8981 token = wtoken.token;
8982 wtoken.startingData = null;
8983 wtoken.startingView = null;
8984 wtoken.startingWindow = null;
8985 }
8986 }
8987 if (view != null) {
8988 try {
8989 mPolicy.removeStartingWindow(token, view);
8990 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008991 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008992 }
8993 }
8994 } break;
8995
8996 case FINISHED_STARTING: {
8997 IBinder token = null;
8998 View view = null;
8999 while (true) {
9000 synchronized (mWindowMap) {
9001 final int N = mFinishedStarting.size();
9002 if (N <= 0) {
9003 break;
9004 }
9005 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
9006
Joe Onorato8a9b2202010-02-26 18:56:32 -08009007 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 "Finished starting " + wtoken
9009 + ": startingWindow=" + wtoken.startingWindow
9010 + " startingView=" + wtoken.startingView);
9011
9012 if (wtoken.startingWindow == null) {
9013 continue;
9014 }
9015
9016 view = wtoken.startingView;
9017 token = wtoken.token;
9018 wtoken.startingData = null;
9019 wtoken.startingView = null;
9020 wtoken.startingWindow = null;
9021 }
9022
9023 try {
9024 mPolicy.removeStartingWindow(token, view);
9025 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009026 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009027 }
9028 }
9029 } break;
9030
9031 case REPORT_APPLICATION_TOKEN_WINDOWS: {
9032 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
9033
9034 boolean nowVisible = msg.arg1 != 0;
9035 boolean nowGone = msg.arg2 != 0;
9036
9037 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009038 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009039 TAG, "Reporting visible in " + wtoken
9040 + " visible=" + nowVisible
9041 + " gone=" + nowGone);
9042 if (nowVisible) {
9043 wtoken.appToken.windowsVisible();
9044 } else {
9045 wtoken.appToken.windowsGone();
9046 }
9047 } catch (RemoteException ex) {
9048 }
9049 } break;
Romain Guy06882f82009-06-10 13:36:04 -07009050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009051 case WINDOW_FREEZE_TIMEOUT: {
9052 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009053 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054 int i = mWindows.size();
9055 while (i > 0) {
9056 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07009057 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009058 if (w.mOrientationChanging) {
9059 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009060 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009061 }
9062 }
9063 performLayoutAndPlaceSurfacesLocked();
9064 }
9065 break;
9066 }
Romain Guy06882f82009-06-10 13:36:04 -07009067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009068 case HOLD_SCREEN_CHANGED: {
9069 Session oldHold;
9070 Session newHold;
9071 synchronized (mWindowMap) {
9072 oldHold = mLastReportedHold;
9073 newHold = (Session)msg.obj;
9074 mLastReportedHold = newHold;
9075 }
Romain Guy06882f82009-06-10 13:36:04 -07009076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009077 if (oldHold != newHold) {
9078 try {
9079 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009080 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009081 "window",
9082 BatteryStats.WAKE_TYPE_WINDOW);
9083 }
9084 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07009085 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009086 "window",
9087 BatteryStats.WAKE_TYPE_WINDOW);
9088 }
9089 } catch (RemoteException e) {
9090 }
9091 }
9092 break;
9093 }
Romain Guy06882f82009-06-10 13:36:04 -07009094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009095 case APP_TRANSITION_TIMEOUT: {
9096 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009097 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009098 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009099 "*** APP TRANSITION TIMEOUT");
9100 mAppTransitionReady = true;
9101 mAppTransitionTimeout = true;
9102 performLayoutAndPlaceSurfacesLocked();
9103 }
9104 }
9105 break;
9106 }
Romain Guy06882f82009-06-10 13:36:04 -07009107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009108 case PERSIST_ANIMATION_SCALE: {
9109 Settings.System.putFloat(mContext.getContentResolver(),
9110 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
9111 Settings.System.putFloat(mContext.getContentResolver(),
9112 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
9113 break;
9114 }
Romain Guy06882f82009-06-10 13:36:04 -07009115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009116 case FORCE_GC: {
9117 synchronized(mWindowMap) {
9118 if (mAnimationPending) {
9119 // If we are animating, don't do the gc now but
9120 // delay a bit so we don't interrupt the animation.
9121 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9122 2000);
9123 return;
9124 }
9125 // If we are currently rotating the display, it will
9126 // schedule a new message when done.
9127 if (mDisplayFrozen) {
9128 return;
9129 }
9130 mFreezeGcPending = 0;
9131 }
9132 Runtime.getRuntime().gc();
9133 break;
9134 }
Romain Guy06882f82009-06-10 13:36:04 -07009135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009136 case ENABLE_SCREEN: {
9137 performEnableScreen();
9138 break;
9139 }
Romain Guy06882f82009-06-10 13:36:04 -07009140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 case APP_FREEZE_TIMEOUT: {
9142 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009143 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009144 int i = mAppTokens.size();
9145 while (i > 0) {
9146 i--;
9147 AppWindowToken tok = mAppTokens.get(i);
9148 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009149 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 unsetAppFreezingScreenLocked(tok, true, true);
9151 }
9152 }
9153 }
9154 break;
9155 }
Romain Guy06882f82009-06-10 13:36:04 -07009156
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009157 case SEND_NEW_CONFIGURATION: {
9158 removeMessages(SEND_NEW_CONFIGURATION);
9159 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07009160 break;
9161 }
Romain Guy06882f82009-06-10 13:36:04 -07009162
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009163 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009164 if (mWindowsChanged) {
9165 synchronized (mWindowMap) {
9166 mWindowsChanged = false;
9167 }
9168 notifyWindowsChanged();
9169 }
9170 break;
9171 }
9172
Christopher Tatea53146c2010-09-07 11:57:52 -07009173 case DRAG_START_TIMEOUT: {
9174 IBinder win = (IBinder)msg.obj;
9175 if (DEBUG_DRAG) {
9176 Slog.w(TAG, "Timeout starting drag by win " + win);
9177 }
9178 synchronized (mWindowMap) {
9179 // !!! TODO: ANR the app that has failed to start the drag in time
9180 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07009181 mDragState.unregister();
Jeff Brown2e44b072011-01-24 15:21:56 -08009182 mInputMonitor.updateInputWindowsLw(true /*force*/);
Christopher Tatea53146c2010-09-07 11:57:52 -07009183 mDragState.reset();
9184 mDragState = null;
9185 }
9186 }
Chris Tated4533f12010-10-19 15:15:08 -07009187 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07009188 }
9189
Chris Tated4533f12010-10-19 15:15:08 -07009190 case DRAG_END_TIMEOUT: {
9191 IBinder win = (IBinder)msg.obj;
9192 if (DEBUG_DRAG) {
9193 Slog.w(TAG, "Timeout ending drag to win " + win);
9194 }
9195 synchronized (mWindowMap) {
9196 // !!! TODO: ANR the drag-receiving app
9197 mDragState.mDragResult = false;
9198 mDragState.endDragLw();
9199 }
9200 break;
9201 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009202 }
9203 }
9204 }
9205
9206 // -------------------------------------------------------------
9207 // IWindowManager API
9208 // -------------------------------------------------------------
9209
9210 public IWindowSession openSession(IInputMethodClient client,
9211 IInputContext inputContext) {
9212 if (client == null) throw new IllegalArgumentException("null client");
9213 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07009214 Session session = new Session(client, inputContext);
9215 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009216 }
9217
9218 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
9219 synchronized (mWindowMap) {
9220 // The focus for the client is the window immediately below
9221 // where we would place the input method window.
9222 int idx = findDesiredInputMethodWindowIndexLocked(false);
9223 WindowState imFocus;
9224 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009225 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 if (imFocus != null) {
9227 if (imFocus.mSession.mClient != null &&
9228 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
9229 return true;
9230 }
9231 }
9232 }
9233 }
9234 return false;
9235 }
Romain Guy06882f82009-06-10 13:36:04 -07009236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009237 // -------------------------------------------------------------
9238 // Internals
9239 // -------------------------------------------------------------
9240
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009241 final WindowState windowForClientLocked(Session session, IWindow client,
9242 boolean throwOnError) {
9243 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 }
Romain Guy06882f82009-06-10 13:36:04 -07009245
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009246 final WindowState windowForClientLocked(Session session, IBinder client,
9247 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009249 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009250 TAG, "Looking up client " + client + ": " + win);
9251 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009252 RuntimeException ex = new IllegalArgumentException(
9253 "Requested window " + client + " does not exist");
9254 if (throwOnError) {
9255 throw ex;
9256 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009257 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009258 return null;
9259 }
9260 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009261 RuntimeException ex = new IllegalArgumentException(
9262 "Requested window " + client + " is in session " +
9263 win.mSession + ", not " + session);
9264 if (throwOnError) {
9265 throw ex;
9266 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009267 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009268 return null;
9269 }
9270
9271 return win;
9272 }
9273
Dianne Hackborna8f60182009-09-01 19:01:50 -07009274 final void rebuildAppWindowListLocked() {
9275 int NW = mWindows.size();
9276 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009277 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009278 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009279
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009280 if (mRebuildTmp.length < NW) {
9281 mRebuildTmp = new WindowState[NW+10];
9282 }
9283
Dianne Hackborna8f60182009-09-01 19:01:50 -07009284 // First remove all existing app windows.
9285 i=0;
9286 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07009287 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009288 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07009289 WindowState win = mWindows.remove(i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009290 win.mRebuilding = true;
9291 mRebuildTmp[numRemoved] = win;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009292 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009293 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009294 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07009295 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009296 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009297 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009298 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
9299 && lastWallpaper == i-1) {
9300 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009301 }
9302 i++;
9303 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009304
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009305 // The wallpaper window(s) typically live at the bottom of the stack,
9306 // so skip them before adding app tokens.
9307 lastWallpaper++;
9308 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009309
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009310 // First add all of the exiting app tokens... these are no longer
9311 // in the main app list, but still have windows shown. We put them
9312 // in the back because now that the animation is over we no longer
9313 // will care about them.
9314 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009315 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009316 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
9317 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009318
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009319 // And add in the still active app tokens in Z order.
9320 NT = mAppTokens.size();
9321 for (int j=0; j<NT; j++) {
9322 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07009323 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009324
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009325 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009326 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009327 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009328 + " windows but added " + i);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009329 for (i=0; i<numRemoved; i++) {
9330 WindowState ws = mRebuildTmp[i];
9331 if (ws.mRebuilding) {
9332 StringWriter sw = new StringWriter();
9333 PrintWriter pw = new PrintWriter(sw);
9334 ws.dump(pw, "");
9335 pw.flush();
9336 Slog.w(TAG, "This window was lost: " + ws);
9337 Slog.w(TAG, sw.toString());
9338 }
9339 }
9340 Slog.w(TAG, "Current app token list:");
9341 dumpAppTokensLocked();
9342 Slog.w(TAG, "Final window list:");
9343 dumpWindowsLocked();
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009344 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009345 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 private final void assignLayersLocked() {
9348 int N = mWindows.size();
9349 int curBaseLayer = 0;
9350 int curLayer = 0;
9351 int i;
Romain Guy06882f82009-06-10 13:36:04 -07009352
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009353 if (DEBUG_LAYERS) {
9354 RuntimeException here = new RuntimeException("here");
9355 here.fillInStackTrace();
9356 Log.v(TAG, "Assigning layers", here);
9357 }
9358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009359 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009360 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009361 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
9362 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009363 curLayer += WINDOW_LAYER_MULTIPLIER;
9364 w.mLayer = curLayer;
9365 } else {
9366 curBaseLayer = curLayer = w.mBaseLayer;
9367 w.mLayer = curLayer;
9368 }
9369 if (w.mTargetAppToken != null) {
9370 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
9371 } else if (w.mAppToken != null) {
9372 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
9373 } else {
9374 w.mAnimLayer = w.mLayer;
9375 }
9376 if (w.mIsImWindow) {
9377 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07009378 } else if (w.mIsWallpaper) {
9379 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009380 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009381 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009382 + w.mAnimLayer);
9383 //System.out.println(
9384 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
9385 }
9386 }
9387
9388 private boolean mInLayout = false;
9389 private final void performLayoutAndPlaceSurfacesLocked() {
9390 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07009391 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009392 throw new RuntimeException("Recursive call!");
9393 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009394 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009395 return;
9396 }
9397
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009398 if (mWaitingForConfig) {
9399 // Our configuration has changed (most likely rotation), but we
9400 // don't yet have the complete configuration to report to
9401 // applications. Don't do any window layout until we have it.
9402 return;
9403 }
9404
Dianne Hackbornce2ef762010-09-20 11:39:14 -07009405 if (mDisplay == null) {
9406 // Not yet initialized, nothing to do.
9407 return;
9408 }
9409
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009410 mInLayout = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 boolean recoveringMemory = false;
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009412
9413 try {
9414 if (mForceRemoves != null) {
9415 recoveringMemory = true;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009416 // Wait a little bit for things to settle down, and off we go.
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009417 for (int i=0; i<mForceRemoves.size(); i++) {
9418 WindowState ws = mForceRemoves.get(i);
9419 Slog.i(TAG, "Force removing: " + ws);
9420 removeWindowInnerLocked(ws.mSession, ws);
9421 }
9422 mForceRemoves = null;
9423 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
9424 Object tmp = new Object();
9425 synchronized (tmp) {
9426 try {
9427 tmp.wait(250);
9428 } catch (InterruptedException e) {
9429 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009430 }
9431 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009432 } catch (RuntimeException e) {
9433 Slog.e(TAG, "Unhandled exception while force removing for memory", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 }
Dianne Hackborn2e7ffa52011-01-12 13:21:28 -08009435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009436 try {
9437 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07009438
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009439 int N = mPendingRemove.size();
9440 if (N > 0) {
9441 if (mPendingRemoveTmp.length < N) {
9442 mPendingRemoveTmp = new WindowState[N+10];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009443 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009444 mPendingRemove.toArray(mPendingRemoveTmp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 mPendingRemove.clear();
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009446 for (int i=0; i<N; i++) {
9447 WindowState w = mPendingRemoveTmp[i];
9448 removeWindowInnerLocked(w.mSession, w);
9449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009450
9451 mInLayout = false;
9452 assignLayersLocked();
9453 mLayoutNeeded = true;
9454 performLayoutAndPlaceSurfacesLocked();
9455
9456 } else {
9457 mInLayout = false;
9458 if (mLayoutNeeded) {
9459 requestAnimationLocked(0);
9460 }
9461 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009462 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009463 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9464 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009465 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009466 } catch (RuntimeException e) {
9467 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009468 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009469 }
9470 }
9471
Jeff Brown3a22cd92011-01-21 13:59:04 -08009472 private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009473 if (!mLayoutNeeded) {
9474 return 0;
9475 }
9476
9477 mLayoutNeeded = false;
9478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009479 final int dw = mDisplay.getWidth();
9480 final int dh = mDisplay.getHeight();
9481
9482 final int N = mWindows.size();
9483 int i;
9484
Joe Onorato8a9b2202010-02-26 18:56:32 -08009485 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009486 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9487
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009488 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009489
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009490 int seq = mLayoutSeq+1;
9491 if (seq < 0) seq = 0;
9492 mLayoutSeq = seq;
9493
9494 // First perform layout of any root windows (not attached
9495 // to another window).
9496 int topAttached = -1;
9497 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009498 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009500 // Don't do layout of a window if it is not visible, or
9501 // soon won't be visible, to avoid wasting time and funky
9502 // changes while a window is animating away.
9503 final AppWindowToken atoken = win.mAppToken;
9504 final boolean gone = win.mViewVisibility == View.GONE
9505 || !win.mRelayoutCalled
Dianne Hackbornff801ec2011-01-22 18:05:38 -08009506 || (atoken == null && win.mRootToken.hidden)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009507 || (atoken != null && atoken.hiddenRequested)
9508 || win.mAttachedHidden
9509 || win.mExiting || win.mDestroying;
9510
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009511 if (DEBUG_LAYOUT && !win.mLayoutAttached) {
9512 Slog.v(TAG, "First pass " + win
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009513 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9514 + " mLayoutAttached=" + win.mLayoutAttached);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009515 if (gone) Slog.v(TAG, " (mViewVisibility="
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009516 + win.mViewVisibility + " mRelayoutCalled="
9517 + win.mRelayoutCalled + " hidden="
9518 + win.mRootToken.hidden + " hiddenRequested="
9519 + (atoken != null && atoken.hiddenRequested)
9520 + " mAttachedHidden=" + win.mAttachedHidden);
9521 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009522
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009523 // If this view is GONE, then skip it -- keep the current
9524 // frame, and let the caller know so they can ignore it
9525 // if they want. (We do the normal layout for INVISIBLE
9526 // windows, since that means "perform layout as normal,
9527 // just don't display").
9528 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009529 if (!win.mLayoutAttached) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009530 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009531 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009532 win.mContentChanged = false;
9533 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009534 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9535 win.mLayoutSeq = seq;
9536 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9537 + win.mFrame + " mContainingFrame="
9538 + win.mContainingFrame + " mDisplayFrame="
9539 + win.mDisplayFrame);
9540 } else {
9541 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009542 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009544 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009545
9546 // Now perform layout of attached windows, which usually
9547 // depend on the position of the window they are attached to.
9548 // XXX does not deal with windows that are attached to windows
9549 // that are themselves attached.
9550 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009551 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009552
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009553 if (win.mLayoutAttached) {
9554 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9555 + " mHaveFrame=" + win.mHaveFrame
9556 + " mViewVisibility=" + win.mViewVisibility
9557 + " mRelayoutCalled=" + win.mRelayoutCalled);
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009558 // If this view is GONE, then skip it -- keep the current
9559 // frame, and let the caller know so they can ignore it
9560 // if they want. (We do the normal layout for INVISIBLE
9561 // windows, since that means "perform layout as normal,
9562 // just don't display").
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009563 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9564 || !win.mHaveFrame) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009565 if (initial) {
Dianne Hackborn0f761d62010-11-30 22:06:10 -08009566 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009567 win.mContentChanged = false;
9568 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009569 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9570 win.mLayoutSeq = seq;
9571 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9572 + win.mFrame + " mContainingFrame="
9573 + win.mContainingFrame + " mDisplayFrame="
9574 + win.mDisplayFrame);
9575 }
9576 }
9577 }
Jeff Brown349703e2010-06-22 01:27:15 -07009578
9579 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown3a22cd92011-01-21 13:59:04 -08009580 mInputMonitor.setUpdateInputWindowsNeededLw();
9581 if (updateInputWindows) {
Jeff Brown2e44b072011-01-24 15:21:56 -08009582 mInputMonitor.updateInputWindowsLw(false /*force*/);
Jeff Brown3a22cd92011-01-21 13:59:04 -08009583 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009584
9585 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 }
Romain Guy06882f82009-06-10 13:36:04 -07009587
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009588 // "Something has changed! Let's make it correct now."
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 private final void performLayoutAndPlaceSurfacesLockedInner(
9590 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009591 if (mDisplay == null) {
9592 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9593 return;
9594 }
9595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596 final long currentTime = SystemClock.uptimeMillis();
9597 final int dw = mDisplay.getWidth();
9598 final int dh = mDisplay.getHeight();
9599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 int i;
9601
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009602 if (mFocusMayChange) {
9603 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -08009604 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
9605 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009606 }
9607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009608 // Initialize state of exiting tokens.
9609 for (i=mExitingTokens.size()-1; i>=0; i--) {
9610 mExitingTokens.get(i).hasVisible = false;
9611 }
9612
9613 // Initialize state of exiting applications.
9614 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9615 mExitingAppTokens.get(i).hasVisible = false;
9616 }
9617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009618 boolean orientationChangeComplete = true;
9619 Session holdScreen = null;
9620 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009621 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009622 boolean focusDisplayed = false;
9623 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009624 boolean createWatermark = false;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009625 boolean updateRotation = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009626
9627 if (mFxSession == null) {
9628 mFxSession = new SurfaceSession();
9629 createWatermark = true;
9630 }
9631
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009632 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633
9634 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009635
9636 if (createWatermark) {
9637 createWatermark();
9638 }
9639 if (mWatermark != null) {
9640 mWatermark.positionSurface(dw, dh);
9641 }
Brad Fitzpatrick68044332010-11-22 18:19:48 -08009642 if (mStrictModeFlash != null) {
9643 mStrictModeFlash.positionSurface(dw, dh);
9644 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009646 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009647 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009648 int repeats = 0;
9649 int changes = 0;
9650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009651 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009652 repeats++;
9653 if (repeats > 6) {
9654 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9655 mLayoutNeeded = false;
9656 break;
9657 }
9658
9659 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9660 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9661 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9662 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9663 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9664 assignLayersLocked();
9665 mLayoutNeeded = true;
9666 }
9667 }
9668 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9669 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -08009670 if (updateOrientationFromAppTokensLocked(true)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009671 mLayoutNeeded = true;
9672 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9673 }
9674 }
9675 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9676 mLayoutNeeded = true;
9677 }
9678 }
9679
9680 // FIRST LOOP: Perform a layout, if needed.
9681 if (repeats < 4) {
Jeff Brown3a22cd92011-01-21 13:59:04 -08009682 changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009683 if (changes != 0) {
9684 continue;
9685 }
9686 } else {
9687 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9688 changes = 0;
9689 }
9690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 final int transactionSequence = ++mTransactionSequence;
9692
9693 // Update animations of all applications, including those
9694 // associated with exiting/removed apps
9695 boolean tokensAnimating = false;
9696 final int NAT = mAppTokens.size();
9697 for (i=0; i<NAT; i++) {
9698 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9699 tokensAnimating = true;
9700 }
9701 }
9702 final int NEAT = mExitingAppTokens.size();
9703 for (i=0; i<NEAT; i++) {
9704 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9705 tokensAnimating = true;
9706 }
9707 }
9708
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009709 // SECOND LOOP: Execute animations and update visibility of windows.
9710
Joe Onorato8a9b2202010-02-26 18:56:32 -08009711 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009712 + transactionSequence + " tokensAnimating="
9713 + tokensAnimating);
9714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009715 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009716
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009717 if (mScreenRotationAnimation != null) {
9718 if (mScreenRotationAnimation.isAnimating()) {
9719 if (mScreenRotationAnimation.stepAnimation(currentTime)) {
9720 animating = true;
9721 } else {
9722 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -08009723 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -08009724 }
9725 }
9726 }
9727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009729 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009730 boolean forceHiding = false;
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009731 WindowState windowDetachedWallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009732
9733 mPolicy.beginAnimationLw(dw, dh);
9734
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009735 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009737 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009738 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739
9740 final WindowManager.LayoutParams attrs = w.mAttrs;
9741
9742 if (w.mSurface != null) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009743 // Take care of the window being ready to display.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009744 if (w.commitFinishDrawingLocked(currentTime)) {
9745 if ((w.mAttrs.flags
9746 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009747 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009748 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009749 wallpaperMayChange = true;
9750 }
9751 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009752
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009753 final boolean wasAnimating = w.mAnimating;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009754
9755 int animDw = dw;
9756 int animDh = dh;
9757
9758 // If the window has moved due to its containing
9759 // content frame changing, then we'd like to animate
9760 // it. The checks here are ordered by what is least
Joe Onorato3fe7f2f2010-11-20 13:48:58 -08009761 // likely to be true first.
Dianne Hackborn1c24e952010-11-23 00:34:30 -08009762 if (w.shouldAnimateMove()) {
Dianne Hackborn8e11ef02010-11-18 19:47:42 -08009763 // Frame has moved, containing content frame
9764 // has also moved, and we're not currently animating...
9765 // let's do something.
9766 Animation a = AnimationUtils.loadAnimation(mContext,
9767 com.android.internal.R.anim.window_move_from_decor);
9768 w.setAnimation(a);
9769 animDw = w.mLastFrame.left - w.mFrame.left;
9770 animDh = w.mLastFrame.top - w.mFrame.top;
9771 }
9772
9773 // Execute animation.
9774 final boolean nowAnimating = w.stepAnimationLocked(currentTime,
9775 animDw, animDh);
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009776
9777 // If this window is animating, make a note that we have
9778 // an animating window and take care of a request to run
9779 // a detached wallpaper animation.
9780 if (nowAnimating) {
9781 if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) {
9782 windowDetachedWallpaper = w;
9783 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009784 animating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009785 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009786
9787 // If this window's app token is running a detached wallpaper
9788 // animation, make a note so we can ensure the wallpaper is
9789 // displayed behind it.
9790 if (w.mAppToken != null && w.mAppToken.animation != null
9791 && w.mAppToken.animation.getDetachWallpaper()) {
9792 windowDetachedWallpaper = w;
9793 }
9794
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009795 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9796 wallpaperMayChange = true;
9797 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009798
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009799 if (mPolicy.doesForceHide(w, attrs)) {
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009800 if (!wasAnimating && nowAnimating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009801 if (DEBUG_VISIBILITY) Slog.v(TAG,
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -08009802 "Animation started that could impact force hide: "
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009803 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009804 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009805 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009806 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9807 forceHiding = true;
9808 }
9809 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9810 boolean changed;
9811 if (forceHiding) {
9812 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009813 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9814 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009815 } else {
9816 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009817 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9818 "Now policy shown: " + w);
9819 if (changed) {
9820 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009821 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009822 // Assume we will need to animate. If
9823 // we don't (because the wallpaper will
9824 // stay with the lock screen), then we will
9825 // clean up later.
9826 Animation a = mPolicy.createForceHideEnterAnimation();
9827 if (a != null) {
9828 w.setAnimation(a);
9829 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009830 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009831 if (mCurrentFocus == null ||
9832 mCurrentFocus.mLayer < w.mLayer) {
9833 // We are showing on to of the current
9834 // focus, so re-evaluate focus to make
9835 // sure it is correct.
9836 mFocusMayChange = true;
9837 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009838 }
9839 }
9840 if (changed && (attrs.flags
9841 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9842 wallpaperMayChange = true;
9843 }
9844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 mPolicy.animatingWindowLw(w, attrs);
9847 }
9848
9849 final AppWindowToken atoken = w.mAppToken;
9850 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9851 if (atoken.lastTransactionSequence != transactionSequence) {
9852 atoken.lastTransactionSequence = transactionSequence;
9853 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9854 atoken.startingDisplayed = false;
9855 }
9856 if ((w.isOnScreen() || w.mAttrs.type
9857 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9858 && !w.mExiting && !w.mDestroying) {
9859 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009860 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009861 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009862 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009863 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009864 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009865 + " pv=" + w.mPolicyVisibility
9866 + " dp=" + w.mDrawPending
9867 + " cdp=" + w.mCommitDrawPending
9868 + " ah=" + w.mAttachedHidden
9869 + " th=" + atoken.hiddenRequested
9870 + " a=" + w.mAnimating);
9871 }
9872 }
9873 if (w != atoken.startingWindow) {
9874 if (!atoken.freezingScreen || !w.mAppFreezing) {
9875 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009876 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009877 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009878 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009879 "tokenMayBeDrawn: " + atoken
9880 + " freezingScreen=" + atoken.freezingScreen
9881 + " mAppFreezing=" + w.mAppFreezing);
9882 tokenMayBeDrawn = true;
9883 }
9884 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009885 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009886 atoken.startingDisplayed = true;
9887 }
9888 }
9889 } else if (w.mReadyToShow) {
9890 w.performShowLocked();
9891 }
9892 }
9893
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009894 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009895
9896 if (tokenMayBeDrawn) {
9897 // See if any windows have been drawn, so they (and others
9898 // associated with them) can now be shown.
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009899 final int NT = mAppTokens.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 for (i=0; i<NT; i++) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08009901 AppWindowToken wtoken = mAppTokens.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 if (wtoken.freezingScreen) {
9903 int numInteresting = wtoken.numInterestingWindows;
9904 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009906 "allDrawn: " + wtoken
9907 + " interesting=" + numInteresting
9908 + " drawn=" + wtoken.numDrawnWindows);
9909 wtoken.showAllWindowsLocked();
9910 unsetAppFreezingScreenLocked(wtoken, false, true);
9911 orientationChangeComplete = true;
9912 }
9913 } else if (!wtoken.allDrawn) {
9914 int numInteresting = wtoken.numInterestingWindows;
9915 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009916 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 "allDrawn: " + wtoken
9918 + " interesting=" + numInteresting
9919 + " drawn=" + wtoken.numDrawnWindows);
9920 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009921 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922
9923 // We can now show all of the drawn windows!
9924 if (!mOpeningApps.contains(wtoken)) {
9925 wtoken.showAllWindowsLocked();
9926 }
9927 }
9928 }
9929 }
9930 }
9931
9932 // If we are ready to perform an app transition, check through
9933 // all of the app tokens to be shown and see if they are ready
9934 // to go.
9935 if (mAppTransitionReady) {
9936 int NN = mOpeningApps.size();
9937 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009938 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 "Checking " + NN + " opening apps (frozen="
9940 + mDisplayFrozen + " timeout="
9941 + mAppTransitionTimeout + ")...");
9942 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9943 // If the display isn't frozen, wait to do anything until
9944 // all of the apps are ready. Otherwise just go because
9945 // we'll unfreeze the display when everyone is ready.
9946 for (i=0; i<NN && goodToGo; i++) {
9947 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009948 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009949 "Check opening app" + wtoken + ": allDrawn="
9950 + wtoken.allDrawn + " startingDisplayed="
9951 + wtoken.startingDisplayed);
9952 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9953 && !wtoken.startingMoved) {
9954 goodToGo = false;
9955 }
9956 }
9957 }
9958 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009959 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009960 int transit = mNextAppTransition;
9961 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009962 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009964 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009966 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009967 mAppTransitionTimeout = false;
9968 mStartingIconInTransition = false;
9969 mSkipAppTransitionAnimation = false;
9970
9971 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9972
Dianne Hackborna8f60182009-09-01 19:01:50 -07009973 // If there are applications waiting to come to the
9974 // top of the stack, now is the time to move their windows.
9975 // (Note that we don't do apps going to the bottom
9976 // here -- we want to keep their windows in the old
9977 // Z-order until the animation completes.)
9978 if (mToTopApps.size() > 0) {
9979 NN = mAppTokens.size();
9980 for (i=0; i<NN; i++) {
9981 AppWindowToken wtoken = mAppTokens.get(i);
9982 if (wtoken.sendingToTop) {
9983 wtoken.sendingToTop = false;
9984 moveAppWindowsLocked(wtoken, NN, false);
9985 }
9986 }
9987 mToTopApps.clear();
9988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009989
Dianne Hackborn25994b42009-09-04 14:21:19 -07009990 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009991
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009992 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009993 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009994
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009995 // The top-most window will supply the layout params,
9996 // and we will determine it below.
9997 LayoutParams animLp = null;
9998 int bestAnimLayer = -1;
Dianne Hackborn08121bc2011-01-17 17:54:31 -08009999 boolean fullscreenAnim = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010000
Joe Onorato8a9b2202010-02-26 18:56:32 -080010001 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -070010002 "New wallpaper target=" + mWallpaperTarget
10003 + ", lower target=" + mLowerWallpaperTarget
10004 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -070010005 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010006 // Do a first pass through the tokens for two
10007 // things:
10008 // (1) Determine if both the closing and opening
10009 // app token sets are wallpaper targets, in which
10010 // case special animations are needed
10011 // (since the wallpaper needs to stay static
10012 // behind them).
10013 // (2) Find the layout params of the top-most
10014 // application window in the tokens, which is
10015 // what will control the animation theme.
10016 final int NC = mClosingApps.size();
10017 NN = NC + mOpeningApps.size();
10018 for (i=0; i<NN; i++) {
10019 AppWindowToken wtoken;
10020 int mode;
10021 if (i < NC) {
10022 wtoken = mClosingApps.get(i);
10023 mode = 1;
10024 } else {
10025 wtoken = mOpeningApps.get(i-NC);
10026 mode = 2;
10027 }
10028 if (mLowerWallpaperTarget != null) {
10029 if (mLowerWallpaperTarget.mAppToken == wtoken
10030 || mUpperWallpaperTarget.mAppToken == wtoken) {
10031 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010032 }
10033 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010034 if (wtoken.appFullscreen) {
10035 WindowState ws = wtoken.findMainWindow();
10036 if (ws != null) {
10037 // If this is a compatibility mode
10038 // window, we will always use its anim.
10039 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
10040 animLp = ws.mAttrs;
10041 bestAnimLayer = Integer.MAX_VALUE;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010042 } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) {
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010043 animLp = ws.mAttrs;
Dianne Hackborn08121bc2011-01-17 17:54:31 -080010044 bestAnimLayer = ws.mLayer;
10045 }
10046 fullscreenAnim = true;
10047 }
10048 } else if (!fullscreenAnim) {
10049 WindowState ws = wtoken.findMainWindow();
10050 if (ws != null) {
10051 if (ws.mLayer > bestAnimLayer) {
10052 animLp = ws.mAttrs;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010053 bestAnimLayer = ws.mLayer;
10054 }
Dianne Hackborn25994b42009-09-04 14:21:19 -070010055 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -070010056 }
10057 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010058
Dianne Hackborn25994b42009-09-04 14:21:19 -070010059 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010060 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010061 "Wallpaper animation!");
10062 switch (transit) {
10063 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
10064 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
10065 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
10066 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
10067 break;
10068 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
10069 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
10070 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
10071 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
10072 break;
10073 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010074 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010075 "New transit: " + transit);
10076 } else if (oldWallpaper != null) {
10077 // We are transitioning from an activity with
10078 // a wallpaper to one without.
10079 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010080 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010081 "New transit away from wallpaper: " + transit);
10082 } else if (mWallpaperTarget != null) {
10083 // We are transitioning from an activity without
10084 // a wallpaper to now showing the wallpaper
10085 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010086 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -070010087 "New transit into wallpaper: " + transit);
10088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010089
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010090 // If all closing windows are obscured, then there is
10091 // no need to do an animation. This is the case, for
10092 // example, when this transition is being done behind
10093 // the lock screen.
10094 if (!mPolicy.allowAppAnimationsLw()) {
10095 animLp = null;
10096 }
10097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098 NN = mOpeningApps.size();
10099 for (i=0; i<NN; i++) {
10100 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010101 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010102 "Now opening app" + wtoken);
10103 wtoken.reportedVisible = false;
10104 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010105 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010106 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010108 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010109 wtoken.showAllWindowsLocked();
10110 }
10111 NN = mClosingApps.size();
10112 for (i=0; i<NN; i++) {
10113 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010114 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010115 "Now closing app" + wtoken);
10116 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -070010117 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -070010118 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010119 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010120 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010121 // Force the allDrawn flag, because we want to start
10122 // this guy's animations regardless of whether it's
10123 // gotten drawn.
10124 wtoken.allDrawn = true;
10125 }
10126
Dianne Hackborn8b571a82009-09-25 16:09:43 -070010127 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 mOpeningApps.clear();
10130 mClosingApps.clear();
10131
10132 // This has changed the visibility of windows, so perform
10133 // a new layout to get them all up-to-date.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010134 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT
10135 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -070010137 if (!moveInputMethodWindowsIfNeededLocked(true)) {
10138 assignLayersLocked();
10139 }
Jeff Brown3a22cd92011-01-21 13:59:04 -080010140 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10141 false /*updateInputWindows*/);
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010142 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010143 }
10144 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010145
Dianne Hackborn16064f92010-03-25 00:47:24 -070010146 int adjResult = 0;
10147
Dianne Hackborna8f60182009-09-01 19:01:50 -070010148 if (!animating && mAppTransitionRunning) {
10149 // We have finished the animation of an app transition. To do
10150 // this, we have delayed a lot of operations like showing and
10151 // hiding apps, moving apps in Z-order, etc. The app token list
10152 // reflects the correct Z-order, but the window list may now
10153 // be out of sync with it. So here we will just rebuild the
10154 // entire app window list. Fun!
10155 mAppTransitionRunning = false;
10156 // Clear information about apps that were moving.
10157 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010158
Dianne Hackborna8f60182009-09-01 19:01:50 -070010159 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010160 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010161 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010162 moveInputMethodWindowsIfNeededLocked(false);
10163 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -080010164 // Since the window list has been rebuilt, focus might
10165 // have to be recomputed since the actual order of windows
10166 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010167 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -070010168 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010169
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010170 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010171 // At this point, there was a window with a wallpaper that
10172 // was force hiding other windows behind it, but now it
10173 // is going away. This may be simple -- just animate
10174 // away the wallpaper and its window -- or it may be
10175 // hard -- the wallpaper now needs to be shown behind
10176 // something that was hidden.
10177 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010178 if (mLowerWallpaperTarget != null
10179 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010180 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010181 "wallpaperForceHiding changed with lower="
10182 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010183 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010184 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
10185 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
10186 if (mLowerWallpaperTarget.mAppToken.hidden) {
10187 // The lower target has become hidden before we
10188 // actually started the animation... let's completely
10189 // re-evaluate everything.
10190 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010191 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010192 }
10193 }
Dianne Hackborn16064f92010-03-25 00:47:24 -070010194 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010195 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010196 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010197 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010198 + " NEW: " + mWallpaperTarget
10199 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010200 if (mLowerWallpaperTarget == null) {
10201 // Whoops, we don't need a special wallpaper animation.
10202 // Clear them out.
10203 forceHiding = false;
10204 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010205 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010206 if (w.mSurface != null) {
10207 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -070010208 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010209 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010210 forceHiding = true;
10211 } else if (mPolicy.canBeForceHidden(w, attrs)) {
10212 if (!w.mAnimating) {
10213 // We set the animation above so it
10214 // is not yet running.
10215 w.clearAnimation();
10216 }
10217 }
10218 }
10219 }
10220 }
10221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010222
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080010223 if (mWindowDetachedWallpaper != windowDetachedWallpaper) {
10224 if (DEBUG_WALLPAPER) Slog.v(TAG,
10225 "Detached wallpaper changed from " + mWindowDetachedWallpaper
10226 + windowDetachedWallpaper);
10227 mWindowDetachedWallpaper = windowDetachedWallpaper;
10228 wallpaperMayChange = true;
10229 }
10230
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010231 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010232 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010233 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -070010234 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010235 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010236
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010237 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010238 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010239 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010240 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010241 assignLayersLocked();
10242 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010243 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010244 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010245 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010247
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010248 if (mFocusMayChange) {
10249 mFocusMayChange = false;
Jeff Brown3a22cd92011-01-21 13:59:04 -080010250 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
10251 false /*updateInputWindows*/)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010252 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010253 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010254 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010255 }
10256
10257 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010258 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -070010259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010260
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010261 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
10262 + Integer.toHexString(changes));
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010263 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010264
10265 // THIRD LOOP: Update the surfaces of all windows.
10266
10267 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
10268
10269 boolean obscured = false;
10270 boolean blurring = false;
10271 boolean dimming = false;
10272 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010273 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010274 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275
Dianne Hackbornbdd52b22009-09-02 21:46:19 -070010276 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010279 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280
10281 boolean displayed = false;
10282 final WindowManager.LayoutParams attrs = w.mAttrs;
10283 final int attrFlags = attrs.flags;
10284
10285 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010286 // XXX NOTE: The logic here could be improved. We have
10287 // the decision about whether to resize a window separated
10288 // from whether to hide the surface. This can cause us to
10289 // resize a surface even if we are going to hide it. You
10290 // can see this by (1) holding device in landscape mode on
10291 // home screen; (2) tapping browser icon (device will rotate
10292 // to landscape; (3) tap home. The wallpaper will be resized
10293 // in step 2 but then immediately hidden, causing us to
10294 // have to resize and then redraw it again in step 3. It
10295 // would be nice to figure out how to avoid this, but it is
10296 // difficult because we do need to resize surfaces in some
10297 // cases while they are hidden such as when first showing a
10298 // window.
10299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010300 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010301 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010302 TAG, "Placing surface #" + i + " " + w.mSurface
10303 + ": new=" + w.mShownFrame + ", old="
10304 + w.mLastShownFrame);
10305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 int width, height;
10307 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010308 // for a scaled surface, we just want to use
10309 // the requested size.
10310 width = w.mRequestedWidth;
10311 height = w.mRequestedHeight;
10312 w.mLastRequestedWidth = width;
10313 w.mLastRequestedHeight = height;
10314 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010315 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010316 width = w.mShownFrame.width();
10317 height = w.mShownFrame.height();
10318 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319 }
10320
Jeff Brownfbae7222011-01-23 13:07:25 -080010321 if (w.mSurface != null) {
10322 if (w.mSurfaceX != w.mShownFrame.left
10323 || w.mSurfaceY != w.mShownFrame.top) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010324 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010325 if (SHOW_TRANSACTIONS) logSurface(w,
Jeff Brownfbae7222011-01-23 13:07:25 -080010326 "POS " + w.mShownFrame.left
10327 + ", " + w.mShownFrame.top, null);
10328 w.mSurfaceX = w.mShownFrame.left;
10329 w.mSurfaceY = w.mShownFrame.top;
10330 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
10331 } catch (RuntimeException e) {
10332 Slog.w(TAG, "Error positioning surface of " + w
10333 + " pos=(" + w.mShownFrame.left
10334 + "," + w.mShownFrame.top + ")", e);
10335 if (!recoveringMemory) {
10336 reclaimSomeSurfaceMemoryLocked(w, "position");
10337 }
10338 }
10339 }
10340
10341 if (width < 1) {
10342 width = 1;
10343 }
10344 if (height < 1) {
10345 height = 1;
10346 }
10347
10348 if (w.mSurfaceW != width || w.mSurfaceH != height) {
10349 try {
10350 if (SHOW_TRANSACTIONS) logSurface(w,
10351 "SIZE " + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010352 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010353 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010354 w.mSurfaceW = width;
10355 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010356 w.mSurface.setSize(width, height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 } catch (RuntimeException e) {
10358 // If something goes wrong with the surface (such
10359 // as running out of memory), don't take down the
10360 // entire system.
Jeff Brownfbae7222011-01-23 13:07:25 -080010361 Slog.e(TAG, "Error resizing surface of " + w
10362 + " size=(" + width + "x" + height + ")", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 if (!recoveringMemory) {
10364 reclaimSomeSurfaceMemoryLocked(w, "size");
10365 }
10366 }
10367 }
10368 }
Jeff Brownfbae7222011-01-23 13:07:25 -080010369
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010370 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010371 w.mContentInsetsChanged =
10372 !w.mLastContentInsets.equals(w.mContentInsets);
10373 w.mVisibleInsetsChanged =
10374 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010375 boolean configChanged =
10376 w.mConfiguration != mCurConfiguration
10377 && (w.mConfiguration == null
10378 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010379 if (DEBUG_CONFIGURATION && configChanged) {
10380 Slog.v(TAG, "Win " + w + " config changed: "
10381 + mCurConfiguration);
10382 }
Joe Onorato8a9b2202010-02-26 18:56:32 -080010383 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010384 + ": configChanged=" + configChanged
10385 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Jeff Brownfbae7222011-01-23 13:07:25 -080010386 boolean frameChanged = !w.mLastFrame.equals(w.mFrame);
10387 if (frameChanged
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010389 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010390 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010391 || configChanged) {
Jeff Brownfbae7222011-01-23 13:07:25 -080010392 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
10393 Slog.v(TAG, "Resize reasons: "
10394 + "frameChanged=" + frameChanged
10395 + " contentInsetsChanged=" + w.mContentInsetsChanged
10396 + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
10397 + " surfaceResized=" + w.mSurfaceResized
10398 + " configChanged=" + configChanged);
10399 }
10400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 w.mLastFrame.set(w.mFrame);
10402 w.mLastContentInsets.set(w.mContentInsets);
10403 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010404 // If the screen is currently frozen, then keep
10405 // it frozen until this window draws at its new
10406 // orientation.
10407 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010408 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010409 "Resizing while display frozen: " + w);
10410 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010411 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010412 mWindowsFreezingScreen = true;
10413 // XXX should probably keep timeout from
10414 // when we first froze the display.
10415 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10416 mH.sendMessageDelayed(mH.obtainMessage(
10417 H.WINDOW_FREEZE_TIMEOUT), 2000);
10418 }
10419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010420 // If the orientation is changing, then we need to
10421 // hold off on unfreezing the display until this
10422 // window has been redrawn; to do that, we need
10423 // to go through the process of getting informed
10424 // by the application when it has finished drawing.
10425 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010426 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427 "Orientation start waiting for draw in "
10428 + w + ", surface " + w.mSurface);
10429 w.mDrawPending = true;
10430 w.mCommitDrawPending = false;
10431 w.mReadyToShow = false;
10432 if (w.mAppToken != null) {
10433 w.mAppToken.allDrawn = false;
10434 }
10435 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010436 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010437 "Resizing window " + w + " to " + w.mFrame);
10438 mResizingWindows.add(w);
10439 } else if (w.mOrientationChanging) {
10440 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010441 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 "Orientation not waiting for draw in "
10443 + w + ", surface " + w.mSurface);
10444 w.mOrientationChanging = false;
10445 }
10446 }
10447 }
10448
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010449 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010450 if (!w.mLastHidden) {
10451 //dump();
10452 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010453 if (SHOW_TRANSACTIONS) logSurface(w,
10454 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010456 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 try {
10458 w.mSurface.hide();
10459 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010460 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010461 }
10462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 }
10464 // If we are waiting for this window to handle an
10465 // orientation change, well, it is hidden, so
10466 // doesn't really matter. Note that this does
10467 // introduce a potential glitch if the window
10468 // becomes unhidden before it has drawn for the
10469 // new orientation.
10470 if (w.mOrientationChanging) {
10471 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010472 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 "Orientation change skips hidden " + w);
10474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010475 } else if (w.mLastLayer != w.mAnimLayer
10476 || w.mLastAlpha != w.mShownAlpha
10477 || w.mLastDsDx != w.mDsDx
10478 || w.mLastDtDx != w.mDtDx
10479 || w.mLastDsDy != w.mDsDy
10480 || w.mLastDtDy != w.mDtDy
10481 || w.mLastHScale != w.mHScale
10482 || w.mLastVScale != w.mVScale
10483 || w.mLastHidden) {
10484 displayed = true;
10485 w.mLastAlpha = w.mShownAlpha;
10486 w.mLastLayer = w.mAnimLayer;
10487 w.mLastDsDx = w.mDsDx;
10488 w.mLastDtDx = w.mDtDx;
10489 w.mLastDsDy = w.mDsDy;
10490 w.mLastDtDy = w.mDtDy;
10491 w.mLastHScale = w.mHScale;
10492 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010493 if (SHOW_TRANSACTIONS) logSurface(w,
10494 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010495 + " matrix=[" + (w.mDsDx*w.mHScale)
10496 + "," + (w.mDtDx*w.mVScale)
10497 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010498 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 if (w.mSurface != null) {
10500 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010501 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010503 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010504 w.mSurface.setLayer(w.mAnimLayer);
10505 w.mSurface.setMatrix(
10506 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
10507 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
10508 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010509 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010510 if (!recoveringMemory) {
10511 reclaimSomeSurfaceMemoryLocked(w, "update");
10512 }
10513 }
10514 }
10515
10516 if (w.mLastHidden && !w.mDrawPending
10517 && !w.mCommitDrawPending
10518 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080010519 if (SHOW_TRANSACTIONS) logSurface(w,
10520 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010521 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010522 + " during relayout");
10523 if (showSurfaceRobustlyLocked(w)) {
10524 w.mHasDrawn = true;
10525 w.mLastHidden = false;
10526 } else {
10527 w.mOrientationChanging = false;
10528 }
10529 }
10530 if (w.mSurface != null) {
10531 w.mToken.hasVisible = true;
10532 }
10533 } else {
10534 displayed = true;
10535 }
10536
10537 if (displayed) {
10538 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010539 if (attrs.width == LayoutParams.MATCH_PARENT
10540 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010541 covered = true;
10542 }
10543 }
10544 if (w.mOrientationChanging) {
10545 if (w.mDrawPending || w.mCommitDrawPending) {
10546 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010547 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 "Orientation continue waiting for draw in " + w);
10549 } else {
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 complete in " + w);
10553 }
10554 }
10555 w.mToken.hasVisible = true;
10556 }
10557 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010558 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010559 "Orientation change skips hidden " + w);
10560 w.mOrientationChanging = false;
10561 }
10562
Dianne Hackborn0f761d62010-11-30 22:06:10 -080010563 if (w.mContentChanged) {
10564 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
10565 w.mContentChanged = false;
10566 }
10567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010568 final boolean canBeSeen = w.isDisplayedLw();
10569
10570 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10571 focusDisplayed = true;
10572 }
10573
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010574 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010576 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010577 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010578 if (w.mSurface != null) {
10579 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10580 holdScreen = w.mSession;
10581 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010582 if (!syswin && w.mAttrs.screenBrightness >= 0
10583 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010584 screenBrightness = w.mAttrs.screenBrightness;
10585 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010586 if (!syswin && w.mAttrs.buttonBrightness >= 0
10587 && buttonBrightness < 0) {
10588 buttonBrightness = w.mAttrs.buttonBrightness;
10589 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010590 if (canBeSeen
10591 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10592 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10593 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010594 syswin = true;
10595 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010596 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010597
Dianne Hackborn25994b42009-09-04 14:21:19 -070010598 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10599 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010600 // This window completely covers everything behind it,
10601 // so we want to leave all of them as unblurred (for
10602 // performance reasons).
10603 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010604 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010605 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010606 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010607 obscured = true;
10608 if (mBackgroundFillerSurface == null) {
10609 try {
10610 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010611 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010612 0, dw, dh,
10613 PixelFormat.OPAQUE,
10614 Surface.FX_SURFACE_NORMAL);
10615 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010616 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010617 }
10618 }
10619 try {
10620 mBackgroundFillerSurface.setPosition(0, 0);
10621 mBackgroundFillerSurface.setSize(dw, dh);
10622 // Using the same layer as Dim because they will never be shown at the
10623 // same time.
10624 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10625 mBackgroundFillerSurface.show();
10626 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010627 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010628 }
10629 backgroundFillerShown = true;
10630 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010631 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010633 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010634 + ": blurring=" + blurring
10635 + " obscured=" + obscured
10636 + " displayed=" + displayed);
10637 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10638 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010639 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010640 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010641 if (mDimAnimator == null) {
10642 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010643 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010644 mDimAnimator.show(dw, dh);
Dianne Hackborn1c24e952010-11-23 00:34:30 -080010645 mDimAnimator.updateParameters(mContext.getResources(),
10646 w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010647 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010648 }
10649 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10650 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010651 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010652 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010653 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010654 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010655 + mBlurSurface + ": CREATE");
10656 try {
Romain Guy06882f82009-06-10 13:36:04 -070010657 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010658 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659 -1, 16, 16,
10660 PixelFormat.OPAQUE,
10661 Surface.FX_SURFACE_BLUR);
10662 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010663 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010664 }
10665 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010667 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10668 + mBlurSurface + ": pos=(0,0) (" +
10669 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010670 mBlurSurface.setPosition(0, 0);
10671 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010672 mBlurSurface.setLayer(w.mAnimLayer-2);
10673 if (!mBlurShown) {
10674 try {
10675 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10676 + mBlurSurface + ": SHOW");
10677 mBlurSurface.show();
10678 } catch (RuntimeException e) {
10679 Slog.w(TAG, "Failure showing blur surface", e);
10680 }
10681 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010682 }
10683 }
10684 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010685 }
10686 }
10687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010688
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010689 if (obscuredChanged && mWallpaperTarget == w) {
10690 // This is the wallpaper target and its obscured state
10691 // changed... make sure the current wallaper's visibility
10692 // has been updated accordingly.
10693 updateWallpaperVisibilityLocked();
10694 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010695 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010696
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010697 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10698 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010699 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010700 try {
10701 mBackgroundFillerSurface.hide();
10702 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010703 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010704 }
10705 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010706
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010707 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010708 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10709 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010710 }
Romain Guy06882f82009-06-10 13:36:04 -070010711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010712 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010713 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010714 + ": HIDE");
10715 try {
10716 mBlurSurface.hide();
10717 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010718 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010719 }
10720 mBlurShown = false;
10721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010722 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010723 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010724 }
10725
10726 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010727
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010728 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
10729
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010730 if (mWatermark != null) {
10731 mWatermark.drawIfNeeded();
10732 }
10733
Joe Onorato8a9b2202010-02-26 18:56:32 -080010734 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010735 "With display frozen, orientationChangeComplete="
10736 + orientationChangeComplete);
10737 if (orientationChangeComplete) {
10738 if (mWindowsFreezingScreen) {
10739 mWindowsFreezingScreen = false;
10740 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10741 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010742 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010743 }
Romain Guy06882f82009-06-10 13:36:04 -070010744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010745 i = mResizingWindows.size();
10746 if (i > 0) {
10747 do {
10748 i--;
10749 WindowState win = mResizingWindows.get(i);
10750 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010751 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10752 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010753 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010754 boolean configChanged =
10755 win.mConfiguration != mCurConfiguration
10756 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010757 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10758 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10759 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010760 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010761 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010762 + " / " + mCurConfiguration + " / 0x"
10763 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010764 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010765 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010766 win.mClient.resized(win.mFrame.width(),
10767 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010768 win.mLastVisibleInsets, win.mDrawPending,
10769 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010770 win.mContentInsetsChanged = false;
10771 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010772 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010773 } catch (RemoteException e) {
10774 win.mOrientationChanging = false;
10775 }
10776 } while (i > 0);
10777 mResizingWindows.clear();
10778 }
Romain Guy06882f82009-06-10 13:36:04 -070010779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010780 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010781 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010782 i = mDestroySurface.size();
10783 if (i > 0) {
10784 do {
10785 i--;
10786 WindowState win = mDestroySurface.get(i);
10787 win.mDestroying = false;
10788 if (mInputMethodWindow == win) {
10789 mInputMethodWindow = null;
10790 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010791 if (win == mWallpaperTarget) {
10792 wallpaperDestroyed = true;
10793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010794 win.destroySurfaceLocked();
10795 } while (i > 0);
10796 mDestroySurface.clear();
10797 }
10798
10799 // Time to remove any exiting tokens?
10800 for (i=mExitingTokens.size()-1; i>=0; i--) {
10801 WindowToken token = mExitingTokens.get(i);
10802 if (!token.hasVisible) {
10803 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010804 if (token.windowType == TYPE_WALLPAPER) {
10805 mWallpaperTokens.remove(token);
10806 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010807 }
10808 }
10809
10810 // Time to remove any exiting applications?
10811 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10812 AppWindowToken token = mExitingAppTokens.get(i);
10813 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010814 // Make sure there is no animation running on this token,
10815 // so any windows associated with it will be removed as
10816 // soon as their animations are complete
10817 token.animation = null;
10818 token.animating = false;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080010819 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
10820 "performLayout: App token exiting now removed" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010821 mAppTokens.remove(token);
10822 mExitingAppTokens.remove(i);
10823 }
10824 }
10825
Dianne Hackborna8f60182009-09-01 19:01:50 -070010826 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010827
Dianne Hackborna8f60182009-09-01 19:01:50 -070010828 if (!animating && mAppTransitionRunning) {
10829 // We have finished the animation of an app transition. To do
10830 // this, we have delayed a lot of operations like showing and
10831 // hiding apps, moving apps in Z-order, etc. The app token list
10832 // reflects the correct Z-order, but the window list may now
10833 // be out of sync with it. So here we will just rebuild the
10834 // entire app window list. Fun!
10835 mAppTransitionRunning = false;
10836 needRelayout = true;
10837 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010838 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010839 // Clear information about apps that were moving.
10840 mToBottomApps.clear();
10841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010843 if (focusDisplayed) {
10844 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10845 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010846 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010847 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010848 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010849 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010850 requestAnimationLocked(0);
10851 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010852 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10853 }
Jeff Browneb857f12010-07-16 10:06:33 -070010854
Jeff Brown3a22cd92011-01-21 13:59:04 -080010855 // Finally update all input windows now that the window changes have stabilized.
Jeff Brown2e44b072011-01-24 15:21:56 -080010856 mInputMonitor.updateInputWindowsLw(true /*force*/);
Jeff Browneb857f12010-07-16 10:06:33 -070010857
Jeff Brown8e03b752010-06-13 19:16:55 -070010858 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010859 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10860 mPowerManager.setScreenBrightnessOverride(-1);
10861 } else {
10862 mPowerManager.setScreenBrightnessOverride((int)
10863 (screenBrightness * Power.BRIGHTNESS_ON));
10864 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010865 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10866 mPowerManager.setButtonBrightnessOverride(-1);
10867 } else {
10868 mPowerManager.setButtonBrightnessOverride((int)
10869 (buttonBrightness * Power.BRIGHTNESS_ON));
10870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 if (holdScreen != mHoldingScreenOn) {
10872 mHoldingScreenOn = holdScreen;
10873 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10874 mH.sendMessage(m);
10875 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010876
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010877 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010878 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010879 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10880 LocalPowerManager.BUTTON_EVENT, true);
10881 mTurnOnScreen = false;
10882 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010883
Dianne Hackborn89ba6752011-01-23 16:51:16 -080010884 if (updateRotation) {
10885 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
10886 boolean changed = setRotationUncheckedLocked(
10887 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
10888 if (changed) {
10889 sendNewConfiguration();
10890 }
10891 }
10892
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010893 // Check to see if we are now in a state where the screen should
10894 // be enabled, because the window obscured flags have changed.
10895 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010896 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010897
10898 /**
10899 * Must be called with the main window manager lock held.
10900 */
10901 void setHoldScreenLocked(boolean holding) {
10902 boolean state = mHoldingScreenWakeLock.isHeld();
10903 if (holding != state) {
10904 if (holding) {
10905 mHoldingScreenWakeLock.acquire();
10906 } else {
10907 mPolicy.screenOnStoppedLw();
10908 mHoldingScreenWakeLock.release();
10909 }
10910 }
10911 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010912
10913 void requestAnimationLocked(long delay) {
10914 if (!mAnimationPending) {
10915 mAnimationPending = true;
10916 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10917 }
10918 }
Romain Guy06882f82009-06-10 13:36:04 -070010919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010920 /**
10921 * Have the surface flinger show a surface, robustly dealing with
10922 * error conditions. In particular, if there is not enough memory
10923 * to show the surface, then we will try to get rid of other surfaces
10924 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010925 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010926 * @return Returns true if the surface was successfully shown.
10927 */
10928 boolean showSurfaceRobustlyLocked(WindowState win) {
10929 try {
10930 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010931 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010932 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010933 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010934 if (DEBUG_VISIBILITY) Slog.v(TAG,
10935 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010936 win.mTurnOnScreen = false;
10937 mTurnOnScreen = true;
10938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010939 }
10940 return true;
10941 } catch (RuntimeException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010942 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010943 }
Romain Guy06882f82009-06-10 13:36:04 -070010944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010945 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 return false;
10948 }
Romain Guy06882f82009-06-10 13:36:04 -070010949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010950 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10951 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010952
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010953 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010954 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010956 if (mForceRemoves == null) {
10957 mForceRemoves = new ArrayList<WindowState>();
10958 }
Romain Guy06882f82009-06-10 13:36:04 -070010959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010960 long callingIdentity = Binder.clearCallingIdentity();
10961 try {
10962 // There was some problem... first, do a sanity check of the
10963 // window list to make sure we haven't left any dangling surfaces
10964 // around.
10965 int N = mWindows.size();
10966 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010967 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010968 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010969 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010970 if (ws.mSurface != null) {
10971 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010972 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010973 + ws + " surface=" + ws.mSurface
10974 + " token=" + win.mToken
10975 + " pid=" + ws.mSession.mPid
10976 + " uid=" + ws.mSession.mUid);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010977 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010978 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010979 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 ws.mSurface = null;
10981 mForceRemoves.add(ws);
10982 i--;
10983 N--;
10984 leakedSurface = true;
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010985 } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010986 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010987 + ws + " surface=" + ws.mSurface
10988 + " token=" + win.mAppToken);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080010989 if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010990 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010991 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010992 ws.mSurface = null;
10993 leakedSurface = true;
10994 }
10995 }
10996 }
Romain Guy06882f82009-06-10 13:36:04 -070010997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010998 boolean killedApps = false;
10999 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011000 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011001 SparseIntArray pidCandidates = new SparseIntArray();
11002 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070011003 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011004 if (ws.mSurface != null) {
11005 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
11006 }
11007 }
11008 if (pidCandidates.size() > 0) {
11009 int[] pids = new int[pidCandidates.size()];
11010 for (int i=0; i<pids.length; i++) {
11011 pids[i] = pidCandidates.keyAt(i);
11012 }
11013 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070011014 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011015 killedApps = true;
11016 }
11017 } catch (RemoteException e) {
11018 }
11019 }
11020 }
Romain Guy06882f82009-06-10 13:36:04 -070011021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011022 if (leakedSurface || killedApps) {
11023 // We managed to reclaim some memory, so get rid of the trouble
11024 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080011025 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011026 if (surface != null) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011027 if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011028 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070011029 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011030 win.mSurface = null;
11031 }
Romain Guy06882f82009-06-10 13:36:04 -070011032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011033 try {
11034 win.mClient.dispatchGetNewSurface();
11035 } catch (RemoteException e) {
11036 }
11037 }
11038 } finally {
11039 Binder.restoreCallingIdentity(callingIdentity);
11040 }
11041 }
Romain Guy06882f82009-06-10 13:36:04 -070011042
Jeff Brown3a22cd92011-01-21 13:59:04 -080011043 private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011044 WindowState newFocus = computeFocusedWindowLocked();
11045 if (mCurrentFocus != newFocus) {
11046 // This check makes sure that we don't already have the focus
11047 // change message pending.
11048 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
11049 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080011050 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011051 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
11052 final WindowState oldFocus = mCurrentFocus;
11053 mCurrentFocus = newFocus;
11054 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070011055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011056 final WindowState imWindow = mInputMethodWindow;
11057 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011058 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011059 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011060 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
11061 mLayoutNeeded = true;
11062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011063 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
Jeff Brown3a22cd92011-01-21 13:59:04 -080011064 performLayoutLockedInner(true /*initial*/, updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011065 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
11066 // Client will do the layout, but we need to assign layers
11067 // for handleNewWindowLocked() below.
11068 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011069 }
11070 }
Jeff Brown349703e2010-06-22 01:27:15 -070011071
11072 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
11073 // If we defer assigning layers, then the caller is responsible for
11074 // doing this part.
Jeff Brown3a22cd92011-01-21 13:59:04 -080011075 finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080011076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011077 return true;
11078 }
11079 return false;
11080 }
Jeff Brown349703e2010-06-22 01:27:15 -070011081
Jeff Brown3a22cd92011-01-21 13:59:04 -080011082 private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
11083 mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
Jeff Brown349703e2010-06-22 01:27:15 -070011084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011085
11086 private WindowState computeFocusedWindowLocked() {
11087 WindowState result = null;
11088 WindowState win;
11089
11090 int i = mWindows.size() - 1;
11091 int nextAppIndex = mAppTokens.size()-1;
11092 WindowToken nextApp = nextAppIndex >= 0
11093 ? mAppTokens.get(nextAppIndex) : null;
11094
11095 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070011096 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011097
Joe Onorato8a9b2202010-02-26 18:56:32 -080011098 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011099 TAG, "Looking for focus: " + i
11100 + " = " + win
11101 + ", flags=" + win.mAttrs.flags
11102 + ", canReceive=" + win.canReceiveKeys());
11103
11104 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070011105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011106 // If this window's application has been removed, just skip it.
11107 if (thisApp != null && thisApp.removed) {
11108 i--;
11109 continue;
11110 }
Romain Guy06882f82009-06-10 13:36:04 -070011111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011112 // If there is a focused app, don't allow focus to go to any
11113 // windows below it. If this is an application window, step
11114 // through the app tokens until we find its app.
11115 if (thisApp != null && nextApp != null && thisApp != nextApp
11116 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
11117 int origAppIndex = nextAppIndex;
11118 while (nextAppIndex > 0) {
11119 if (nextApp == mFocusedApp) {
11120 // Whoops, we are below the focused app... no focus
11121 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080011122 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011123 TAG, "Reached focused app: " + mFocusedApp);
11124 return null;
11125 }
11126 nextAppIndex--;
11127 nextApp = mAppTokens.get(nextAppIndex);
11128 if (nextApp == thisApp) {
11129 break;
11130 }
11131 }
11132 if (thisApp != nextApp) {
11133 // Uh oh, the app token doesn't exist! This shouldn't
11134 // happen, but if it does we can get totally hosed...
11135 // so restart at the original app.
11136 nextAppIndex = origAppIndex;
11137 nextApp = mAppTokens.get(nextAppIndex);
11138 }
11139 }
11140
11141 // Dispatch to this window if it is wants key events.
11142 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011143 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011144 TAG, "Found focus @ " + i + " = " + win);
11145 result = win;
11146 break;
11147 }
11148
11149 i--;
11150 }
11151
11152 return result;
11153 }
11154
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011155 private void startFreezingDisplayLocked(boolean inTransaction) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011156 if (mDisplayFrozen) {
11157 return;
11158 }
Romain Guy06882f82009-06-10 13:36:04 -070011159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011160 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070011161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011162 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080011163 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011164 if (mFreezeGcPending != 0) {
11165 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011166 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011167 mH.removeMessages(H.FORCE_GC);
11168 Runtime.getRuntime().gc();
11169 mFreezeGcPending = now;
11170 }
11171 } else {
11172 mFreezeGcPending = now;
11173 }
Romain Guy06882f82009-06-10 13:36:04 -070011174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011175 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070011176
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011177 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070011178
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070011179 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
11180 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011181 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011182 mAppTransitionReady = true;
11183 }
Romain Guy06882f82009-06-10 13:36:04 -070011184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011185 if (PROFILE_ORIENTATION) {
11186 File file = new File("/data/system/frozen");
11187 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
11188 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011189
11190 if (CUSTOM_SCREEN_ROTATION) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011191 if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) {
11192 mScreenRotationAnimation.kill();
11193 mScreenRotationAnimation = null;
11194 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011195 if (mScreenRotationAnimation == null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011196 mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011197 mDisplay, mFxSession, inTransaction);
Dianne Hackborna1111872010-11-23 20:55:11 -080011198 }
11199 } else {
11200 Surface.freezeDisplay(0);
11201 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011202 }
Romain Guy06882f82009-06-10 13:36:04 -070011203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011204 private void stopFreezingDisplayLocked() {
11205 if (!mDisplayFrozen) {
11206 return;
11207 }
Romain Guy06882f82009-06-10 13:36:04 -070011208
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011209 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
11210 return;
11211 }
11212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011213 mDisplayFrozen = false;
11214 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
11215 if (PROFILE_ORIENTATION) {
11216 Debug.stopMethodTracing();
11217 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011218
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011219 boolean updateRotation = false;
11220
Dianne Hackborna1111872010-11-23 20:55:11 -080011221 if (CUSTOM_SCREEN_ROTATION) {
11222 if (mScreenRotationAnimation != null) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011223 if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION,
11224 mTransitionAnimationScale)) {
11225 requestAnimationLocked(0);
11226 } else {
11227 mScreenRotationAnimation = null;
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011228 updateRotation = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080011229 }
Dianne Hackborna1111872010-11-23 20:55:11 -080011230 }
11231 } else {
11232 Surface.unfreezeDisplay(0);
11233 }
Romain Guy06882f82009-06-10 13:36:04 -070011234
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011235 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011236
Christopher Tateb696aee2010-04-02 19:08:30 -070011237 // While the display is frozen we don't re-compute the orientation
11238 // to avoid inconsistent states. However, something interesting
11239 // could have actually changed during that time so re-evaluate it
11240 // now to catch that.
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -080011241 if (updateOrientationFromAppTokensLocked(false)) {
Christopher Tateb696aee2010-04-02 19:08:30 -070011242 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
11243 }
11244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011245 // A little kludge: a lot could have happened while the
11246 // display was frozen, so now that we are coming back we
11247 // do a gc so that any remote references the system
11248 // processes holds on others can be released if they are
11249 // no longer needed.
11250 mH.removeMessages(H.FORCE_GC);
11251 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
11252 2000);
Romain Guy06882f82009-06-10 13:36:04 -070011253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011254 mScreenFrozenLock.release();
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011255
11256 if (updateRotation) {
11257 if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
11258 boolean changed = setRotationUncheckedLocked(
11259 WindowManagerPolicy.USE_LAST_ROTATION, 0, false);
11260 if (changed) {
11261 sendNewConfiguration();
11262 }
11263 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011264 }
Romain Guy06882f82009-06-10 13:36:04 -070011265
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011266 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
11267 DisplayMetrics dm) {
11268 if (index < tokens.length) {
11269 String str = tokens[index];
11270 if (str != null && str.length() > 0) {
11271 try {
11272 int val = Integer.parseInt(str);
11273 return val;
11274 } catch (Exception e) {
11275 }
11276 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011277 }
11278 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
11279 return defDps;
11280 }
11281 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
11282 return val;
11283 }
11284
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011285 static class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011286 final String[] mTokens;
11287 final String mText;
11288 final Paint mTextPaint;
11289 final int mTextWidth;
11290 final int mTextHeight;
11291 final int mTextAscent;
11292 final int mTextDescent;
11293 final int mDeltaX;
11294 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011295
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011296 Surface mSurface;
11297 int mLastDW;
11298 int mLastDH;
11299 boolean mDrawNeeded;
11300
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011301 Watermark(Display display, SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011302 final DisplayMetrics dm = new DisplayMetrics();
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011303 display.getMetrics(dm);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011304
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011305 if (false) {
11306 Log.i(TAG, "*********************** WATERMARK");
11307 for (int i=0; i<tokens.length; i++) {
11308 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
11309 }
11310 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011311
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011312 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011313
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011314 StringBuilder builder = new StringBuilder(32);
11315 int len = mTokens[0].length();
11316 len = len & ~1;
11317 for (int i=0; i<len; i+=2) {
11318 int c1 = mTokens[0].charAt(i);
11319 int c2 = mTokens[0].charAt(i+1);
11320 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
11321 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
11322 else c1 -= '0';
11323 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
11324 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
11325 else c2 -= '0';
11326 builder.append((char)(255-((c1*16)+c2)));
11327 }
11328 mText = builder.toString();
11329 if (false) {
11330 Log.i(TAG, "Final text: " + mText);
11331 }
11332
11333 int fontSize = getPropertyInt(tokens, 1,
11334 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
11335
11336 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
11337 mTextPaint.setTextSize(fontSize);
11338 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
11339
11340 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
11341 mTextWidth = (int)mTextPaint.measureText(mText);
11342 mTextAscent = fm.ascent;
11343 mTextDescent = fm.descent;
11344 mTextHeight = fm.descent - fm.ascent;
11345
11346 mDeltaX = getPropertyInt(tokens, 2,
11347 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
11348 mDeltaY = getPropertyInt(tokens, 3,
11349 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
11350 int shadowColor = getPropertyInt(tokens, 4,
11351 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
11352 int color = getPropertyInt(tokens, 5,
11353 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
11354 int shadowRadius = getPropertyInt(tokens, 6,
11355 TypedValue.COMPLEX_UNIT_PX, 7, dm);
11356 int shadowDx = getPropertyInt(tokens, 8,
11357 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11358 int shadowDy = getPropertyInt(tokens, 9,
11359 TypedValue.COMPLEX_UNIT_PX, 0, dm);
11360
11361 mTextPaint.setColor(color);
11362 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011363
11364 try {
11365 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011366 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011367 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011368 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011369 mSurface.show();
11370 } catch (OutOfResourcesException e) {
11371 }
11372 }
11373
11374 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011375 if (mLastDW != dw || mLastDH != dh) {
11376 mLastDW = dw;
11377 mLastDH = dh;
11378 mSurface.setSize(dw, dh);
11379 mDrawNeeded = true;
11380 }
11381 }
11382
11383 void drawIfNeeded() {
11384 if (mDrawNeeded) {
11385 final int dw = mLastDW;
11386 final int dh = mLastDH;
11387
11388 mDrawNeeded = false;
11389 Rect dirty = new Rect(0, 0, dw, dh);
11390 Canvas c = null;
11391 try {
11392 c = mSurface.lockCanvas(dirty);
11393 } catch (IllegalArgumentException e) {
11394 } catch (OutOfResourcesException e) {
11395 }
11396 if (c != null) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011397 c.drawColor(0, PorterDuff.Mode.CLEAR);
11398
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011399 int deltaX = mDeltaX;
11400 int deltaY = mDeltaY;
11401
11402 // deltaX shouldn't be close to a round fraction of our
11403 // x step, or else things will line up too much.
11404 int div = (dw+mTextWidth)/deltaX;
11405 int rem = (dw+mTextWidth) - (div*deltaX);
11406 int qdelta = deltaX/4;
11407 if (rem < qdelta || rem > (deltaX-qdelta)) {
11408 deltaX += deltaX/3;
11409 }
11410
11411 int y = -mTextHeight;
11412 int x = -mTextWidth;
11413 while (y < (dh+mTextHeight)) {
11414 c.drawText(mText, x, y, mTextPaint);
11415 x += deltaX;
11416 if (x >= dw) {
11417 x -= (dw+mTextWidth);
11418 y += deltaY;
11419 }
11420 }
11421 mSurface.unlockCanvasAndPost(c);
11422 }
11423 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011424 }
11425 }
11426
11427 void createWatermark() {
11428 if (mWatermark != null) {
11429 return;
11430 }
11431
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011432 File file = new File("/system/etc/setup.conf");
11433 FileInputStream in = null;
11434 try {
11435 in = new FileInputStream(file);
11436 DataInputStream ind = new DataInputStream(in);
11437 String line = ind.readLine();
11438 if (line != null) {
11439 String[] toks = line.split("%");
11440 if (toks != null && toks.length > 0) {
Dianne Hackborned7bfbf2010-11-05 13:08:35 -070011441 mWatermark = new Watermark(mDisplay, mFxSession, toks);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070011442 }
11443 }
11444 } catch (FileNotFoundException e) {
11445 } catch (IOException e) {
11446 } finally {
11447 if (in != null) {
11448 try {
11449 in.close();
11450 } catch (IOException e) {
11451 }
11452 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011453 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070011454 }
11455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011456 @Override
Joe Onorato664644d2011-01-23 17:53:23 -080011457 public void statusBarVisibilityChanged(int visibility) {
11458 synchronized (mWindowMap) {
11459 final int N = mWindows.size();
11460 for (int i = 0; i < N; i++) {
11461 WindowState ws = mWindows.get(i);
11462 try {
11463 if (ws.getAttrs().hasSystemUiListeners) {
11464 ws.mClient.dispatchSystemUiVisibilityChanged(visibility);
11465 }
11466 } catch (RemoteException e) {
11467 // so sorry
11468 }
11469 }
11470 }
11471 }
11472
11473 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011474 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
11475 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
11476 != PackageManager.PERMISSION_GRANTED) {
11477 pw.println("Permission Denial: can't dump WindowManager from from pid="
11478 + Binder.getCallingPid()
11479 + ", uid=" + Binder.getCallingUid());
11480 return;
11481 }
Romain Guy06882f82009-06-10 13:36:04 -070011482
Jeff Brown00fa7bd2010-07-02 15:37:36 -070011483 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080011484 pw.println(" ");
11485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011486 synchronized(mWindowMap) {
11487 pw.println("Current Window Manager state:");
11488 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070011489 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011490 pw.print(" Window #"); pw.print(i); pw.print(' ');
11491 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011492 w.dump(pw, " ");
11493 }
11494 if (mInputMethodDialogs.size() > 0) {
11495 pw.println(" ");
11496 pw.println(" Input method dialogs:");
11497 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
11498 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011499 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011500 }
11501 }
11502 if (mPendingRemove.size() > 0) {
11503 pw.println(" ");
11504 pw.println(" Remove pending for:");
11505 for (int i=mPendingRemove.size()-1; i>=0; i--) {
11506 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011507 pw.print(" Remove #"); pw.print(i); pw.print(' ');
11508 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011509 w.dump(pw, " ");
11510 }
11511 }
11512 if (mForceRemoves != null && mForceRemoves.size() > 0) {
11513 pw.println(" ");
11514 pw.println(" Windows force removing:");
11515 for (int i=mForceRemoves.size()-1; i>=0; i--) {
11516 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011517 pw.print(" Removing #"); pw.print(i); pw.print(' ');
11518 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011519 w.dump(pw, " ");
11520 }
11521 }
11522 if (mDestroySurface.size() > 0) {
11523 pw.println(" ");
11524 pw.println(" Windows waiting to destroy their surface:");
11525 for (int i=mDestroySurface.size()-1; i>=0; i--) {
11526 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011527 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
11528 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011529 w.dump(pw, " ");
11530 }
11531 }
11532 if (mLosingFocus.size() > 0) {
11533 pw.println(" ");
11534 pw.println(" Windows losing focus:");
11535 for (int i=mLosingFocus.size()-1; i>=0; i--) {
11536 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011537 pw.print(" Losing #"); pw.print(i); pw.print(' ');
11538 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011539 w.dump(pw, " ");
11540 }
11541 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011542 if (mResizingWindows.size() > 0) {
11543 pw.println(" ");
11544 pw.println(" Windows waiting to resize:");
11545 for (int i=mResizingWindows.size()-1; i>=0; i--) {
11546 WindowState w = mResizingWindows.get(i);
11547 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
11548 pw.print(w); pw.println(":");
11549 w.dump(pw, " ");
11550 }
11551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011552 if (mSessions.size() > 0) {
11553 pw.println(" ");
11554 pw.println(" All active sessions:");
11555 Iterator<Session> it = mSessions.iterator();
11556 while (it.hasNext()) {
11557 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011558 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011559 s.dump(pw, " ");
11560 }
11561 }
11562 if (mTokenMap.size() > 0) {
11563 pw.println(" ");
11564 pw.println(" All tokens:");
11565 Iterator<WindowToken> it = mTokenMap.values().iterator();
11566 while (it.hasNext()) {
11567 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011568 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011569 token.dump(pw, " ");
11570 }
11571 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070011572 if (mWallpaperTokens.size() > 0) {
11573 pw.println(" ");
11574 pw.println(" Wallpaper tokens:");
11575 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
11576 WindowToken token = mWallpaperTokens.get(i);
11577 pw.print(" Wallpaper #"); pw.print(i);
11578 pw.print(' '); pw.print(token); pw.println(':');
11579 token.dump(pw, " ");
11580 }
11581 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011582 if (mAppTokens.size() > 0) {
11583 pw.println(" ");
11584 pw.println(" Application tokens in Z order:");
11585 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011586 pw.print(" App #"); pw.print(i); pw.print(": ");
11587 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011588 }
11589 }
11590 if (mFinishedStarting.size() > 0) {
11591 pw.println(" ");
11592 pw.println(" Finishing start of application tokens:");
11593 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
11594 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011595 pw.print(" Finished Starting #"); pw.print(i);
11596 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011597 token.dump(pw, " ");
11598 }
11599 }
11600 if (mExitingTokens.size() > 0) {
11601 pw.println(" ");
11602 pw.println(" Exiting tokens:");
11603 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11604 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011605 pw.print(" Exiting #"); pw.print(i);
11606 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011607 token.dump(pw, " ");
11608 }
11609 }
11610 if (mExitingAppTokens.size() > 0) {
11611 pw.println(" ");
11612 pw.println(" Exiting application tokens:");
11613 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11614 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011615 pw.print(" Exiting App #"); pw.print(i);
11616 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011617 token.dump(pw, " ");
11618 }
11619 }
11620 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011621 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11622 pw.print(" mLastFocus="); pw.println(mLastFocus);
11623 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11624 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11625 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011626 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011627 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11628 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11629 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11630 }
Dianne Hackborn6c8e20f2010-11-09 18:59:09 -080011631 if (mWindowDetachedWallpaper != null) {
11632 pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper);
11633 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011634 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11635 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11636 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011637 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11638 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11639 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11640 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011641 if (mDimAnimator != null) {
11642 mDimAnimator.printTo(pw);
11643 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011644 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011645 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011646 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011647 pw.print(mInputMethodAnimLayerAdjustment);
11648 pw.print(" mWallpaperAnimLayerAdjustment=");
11649 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011650 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11651 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011652 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11653 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011654 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11655 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011656 pw.print(" mRotation="); pw.print(mRotation);
11657 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11658 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
Dianne Hackborn89ba6752011-01-23 16:51:16 -080011659 pw.print(" mDeferredRotation="); pw.print(mDeferredRotation);
11660 pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011661 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11662 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11663 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11664 pw.print(" mNextAppTransition=0x");
11665 pw.print(Integer.toHexString(mNextAppTransition));
11666 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011667 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011668 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011669 if (mNextAppTransitionPackage != null) {
11670 pw.print(" mNextAppTransitionPackage=");
11671 pw.print(mNextAppTransitionPackage);
11672 pw.print(", mNextAppTransitionEnter=0x");
11673 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11674 pw.print(", mNextAppTransitionExit=0x");
11675 pw.print(Integer.toHexString(mNextAppTransitionExit));
11676 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011677 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11678 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
11679 if (mOpeningApps.size() > 0) {
11680 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11681 }
11682 if (mClosingApps.size() > 0) {
11683 pw.print(" mClosingApps="); pw.println(mClosingApps);
11684 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011685 if (mToTopApps.size() > 0) {
11686 pw.print(" mToTopApps="); pw.println(mToTopApps);
11687 }
11688 if (mToBottomApps.size() > 0) {
11689 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11690 }
Dianne Hackborn87fc3082010-12-03 13:09:12 -080011691 if (mDisplay != null) {
11692 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11693 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
11694 } else {
11695 pw.println(" NO DISPLAY");
11696 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -080011697 pw.println(" Policy:");
11698 mPolicy.dump(" ", fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011699 }
11700 }
11701
Jeff Brown349703e2010-06-22 01:27:15 -070011702 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011703 public void monitor() {
11704 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011705 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011706 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011707
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011708 /**
11709 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011710 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011711 */
11712 private static class DimAnimator {
11713 Surface mDimSurface;
11714 boolean mDimShown = false;
11715 float mDimCurrentAlpha;
11716 float mDimTargetAlpha;
11717 float mDimDeltaPerMs;
11718 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011719
11720 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011721
11722 DimAnimator (SurfaceSession session) {
11723 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011724 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011725 + mDimSurface + ": CREATE");
11726 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011727 mDimSurface = new Surface(session, 0,
11728 "DimSurface",
11729 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011730 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011731 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011732 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011733 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011734 }
11735 }
11736 }
11737
11738 /**
11739 * Show the dim surface.
11740 */
11741 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011742 if (!mDimShown) {
11743 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11744 dw + "x" + dh + ")");
11745 mDimShown = true;
11746 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011747 mLastDimWidth = dw;
11748 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011749 mDimSurface.setPosition(0, 0);
11750 mDimSurface.setSize(dw, dh);
11751 mDimSurface.show();
11752 } catch (RuntimeException e) {
11753 Slog.w(TAG, "Failure showing dim surface", e);
11754 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011755 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11756 mLastDimWidth = dw;
11757 mLastDimHeight = dh;
11758 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011759 }
11760 }
11761
11762 /**
11763 * Set's the dim surface's layer and update dim parameters that will be used in
11764 * {@link updateSurface} after all windows are examined.
11765 */
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011766 void updateParameters(Resources res, WindowState w, long currentTime) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011767 mDimSurface.setLayer(w.mAnimLayer-1);
11768
11769 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011770 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011771 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011772 if (mDimTargetAlpha != target) {
11773 // If the desired dim level has changed, then
11774 // start an animation to it.
11775 mLastDimAnimTime = currentTime;
11776 long duration = (w.mAnimating && w.mAnimation != null)
11777 ? w.mAnimation.computeDurationHint()
11778 : DEFAULT_DIM_DURATION;
11779 if (target > mDimTargetAlpha) {
Dianne Hackborn1c24e952010-11-23 00:34:30 -080011780 TypedValue tv = new TypedValue();
11781 res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration,
11782 tv, true);
11783 if (tv.type == TypedValue.TYPE_FRACTION) {
11784 duration = (long)tv.getFraction((float)duration, (float)duration);
11785 } else if (tv.type >= TypedValue.TYPE_FIRST_INT
11786 && tv.type <= TypedValue.TYPE_LAST_INT) {
11787 duration = tv.data;
11788 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011789 }
11790 if (duration < 1) {
11791 // Don't divide by zero
11792 duration = 1;
11793 }
11794 mDimTargetAlpha = target;
11795 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11796 }
11797 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011798
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011799 /**
11800 * Updating the surface's alpha. Returns true if the animation continues, or returns
11801 * false when the animation is finished and the dim surface is hidden.
11802 */
11803 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11804 if (!dimming) {
11805 if (mDimTargetAlpha != 0) {
11806 mLastDimAnimTime = currentTime;
11807 mDimTargetAlpha = 0;
11808 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11809 }
11810 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011811
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011812 boolean animating = false;
11813 if (mLastDimAnimTime != 0) {
11814 mDimCurrentAlpha += mDimDeltaPerMs
11815 * (currentTime-mLastDimAnimTime);
11816 boolean more = true;
11817 if (displayFrozen) {
11818 // If the display is frozen, there is no reason to animate.
11819 more = false;
11820 } else if (mDimDeltaPerMs > 0) {
11821 if (mDimCurrentAlpha > mDimTargetAlpha) {
11822 more = false;
11823 }
11824 } else if (mDimDeltaPerMs < 0) {
11825 if (mDimCurrentAlpha < mDimTargetAlpha) {
11826 more = false;
11827 }
11828 } else {
11829 more = false;
11830 }
11831
11832 // Do we need to continue animating?
11833 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011834 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011835 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11836 mLastDimAnimTime = currentTime;
11837 mDimSurface.setAlpha(mDimCurrentAlpha);
11838 animating = true;
11839 } else {
11840 mDimCurrentAlpha = mDimTargetAlpha;
11841 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011842 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011843 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11844 mDimSurface.setAlpha(mDimCurrentAlpha);
11845 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011846 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011847 + ": HIDE");
11848 try {
11849 mDimSurface.hide();
11850 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011851 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011852 }
11853 mDimShown = false;
11854 }
11855 }
11856 }
11857 return animating;
11858 }
11859
11860 public void printTo(PrintWriter pw) {
11861 pw.print(" mDimShown="); pw.print(mDimShown);
11862 pw.print(" current="); pw.print(mDimCurrentAlpha);
11863 pw.print(" target="); pw.print(mDimTargetAlpha);
11864 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11865 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11866 }
11867 }
11868
11869 /**
11870 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11871 * This is used for opening/closing transition for apps in compatible mode.
11872 */
11873 private static class FadeInOutAnimation extends Animation {
11874 int mWidth;
11875 boolean mFadeIn;
11876
11877 public FadeInOutAnimation(boolean fadeIn) {
11878 setInterpolator(new AccelerateInterpolator());
11879 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11880 mFadeIn = fadeIn;
11881 }
11882
11883 @Override
11884 protected void applyTransformation(float interpolatedTime, Transformation t) {
11885 float x = interpolatedTime;
11886 if (!mFadeIn) {
11887 x = 1.0f - x; // reverse the interpolation for fade out
11888 }
11889 if (x < 0.5) {
11890 // move the window out of the screen.
11891 t.getMatrix().setTranslate(mWidth, 0);
11892 } else {
11893 t.getMatrix().setTranslate(0, 0);// show
11894 t.setAlpha((x - 0.5f) * 2);
11895 }
11896 }
11897
11898 @Override
11899 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11900 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11901 mWidth = width;
11902 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011903
11904 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011905 public int getZAdjustment() {
11906 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011907 }
11908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011909}