blob: dbc7f480ce49cf4dcb0617fe1898a2f229dfc566 [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;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
68import 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 Fitzpatrick07218612010-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;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700102import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103import android.view.IApplicationToken;
104import android.view.IOnKeyguardExitResult;
105import android.view.IRotationWatcher;
106import android.view.IWindow;
107import android.view.IWindowManager;
108import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700109import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700111import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700112import android.view.InputHandler;
113import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.KeyEvent;
115import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.Surface;
117import android.view.SurfaceSession;
118import android.view.View;
119import android.view.ViewTreeObserver;
120import android.view.WindowManager;
121import android.view.WindowManagerImpl;
122import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700123import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700125import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import android.view.animation.Animation;
127import android.view.animation.AnimationUtils;
128import android.view.animation.Transformation;
129
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700130import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700132import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133import java.io.File;
134import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700135import java.io.FileInputStream;
136import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137import java.io.IOException;
138import java.io.OutputStream;
139import java.io.OutputStreamWriter;
140import java.io.PrintWriter;
141import java.io.StringWriter;
142import java.net.Socket;
143import java.util.ArrayList;
144import java.util.HashMap;
145import java.util.HashSet;
146import java.util.Iterator;
147import java.util.List;
148
149/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700150public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700151 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final String TAG = "WindowManager";
153 static final boolean DEBUG = false;
154 static final boolean DEBUG_FOCUS = false;
155 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800156 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800157 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 static final boolean DEBUG_LAYERS = false;
159 static final boolean DEBUG_INPUT = false;
160 static final boolean DEBUG_INPUT_METHOD = false;
161 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700162 static final boolean DEBUG_WINDOW_MOVEMENT = false;
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 Tatea53146c2010-09-07 11:57:52 -0700169 static final boolean DEBUG_DRAG = true;
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 /** Adjustment to time to perform a dim, to make it more dramatic.
207 */
208 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700209
210 // Maximum number of milliseconds to wait for input event injection.
211 // FIXME is this value reasonable?
212 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700213
214 // Default input dispatching timeout in nanoseconds.
215 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 static final int UPDATE_FOCUS_NORMAL = 0;
218 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
219 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
220 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700223 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
225 /**
226 * Condition waited on by {@link #reenableKeyguard} to know the call to
227 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500228 * This is set to true only if mKeyguardTokenWatcher.acquired() has
229 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500231 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232
Jim Miller284b62e2010-06-08 14:27:42 -0700233 private static final int ALLOW_DISABLE_YES = 1;
234 private static final int ALLOW_DISABLE_NO = 0;
235 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
236 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
237
Mike Lockwood983ee092009-11-22 01:42:24 -0500238 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
239 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700241 if (shouldAllowDisableKeyguard()) {
242 mPolicy.enableKeyguard(false);
243 mKeyguardDisabled = true;
244 } else {
245 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700249 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500250 synchronized (mKeyguardTokenWatcher) {
251 mKeyguardDisabled = false;
252 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
254 }
255 };
256
Jim Miller284b62e2010-06-08 14:27:42 -0700257 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
258 @Override
259 public void onReceive(Context context, Intent intent) {
260 mPolicy.enableKeyguard(true);
261 synchronized(mKeyguardTokenWatcher) {
262 // lazily evaluate this next time we're asked to disable keyguard
263 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
264 mKeyguardDisabled = false;
265 }
266 }
267 };
268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 final Context mContext;
270
271 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
276
277 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 /**
282 * All currently active sessions with clients.
283 */
284 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /**
287 * Mapping from an IWindow IBinder to the server's Window object.
288 * This is also used as the lock for all of our state.
289 */
290 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
291
292 /**
293 * Mapping from a token IBinder to a WindowToken object.
294 */
295 final HashMap<IBinder, WindowToken> mTokenMap =
296 new HashMap<IBinder, WindowToken>();
297
298 /**
299 * The same tokens as mTokenMap, stored in a list for efficient iteration
300 * over them.
301 */
302 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 /**
305 * 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
313 * contains WindowToken objects.
314 */
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 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700330 * This was the app token that was used to retrieve the last enter
331 * animation. It will be used for the next exit animation.
332 */
333 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800334
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700335 /**
336 * These were the layout params used to retrieve the last enter animation.
337 * They will be used for the next exit animation.
338 */
339 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800340
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700341 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 * Z-ordered (bottom-most first) list of all Window objects.
343 */
Jeff Browne33348b2010-07-15 23:54:05 -0700344 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345
346 /**
347 * Windows that are being resized. Used so we can tell the client about
348 * the resize after closing the transaction in which we resized the
349 * underlying surface.
350 */
351 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
352
353 /**
354 * Windows whose animations have ended and now must be removed.
355 */
356 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
357
358 /**
359 * Windows whose surface should be destroyed.
360 */
361 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
362
363 /**
364 * Windows that have lost input focus and are waiting for the new
365 * focus window to be displayed before they are told about this.
366 */
367 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
368
369 /**
370 * This is set when we have run out of memory, and will either be an empty
371 * list or contain windows that need to be force removed.
372 */
373 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700378 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 Surface mBlurSurface;
380 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700381 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 final float[] mTmpFloats = new float[9];
386
387 boolean mSafeMode;
388 boolean mDisplayEnabled = false;
389 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700390 int mInitialDisplayWidth = 0;
391 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 int mRotation = 0;
393 int mRequestedRotation = 0;
394 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700395 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 ArrayList<IRotationWatcher> mRotationWatchers
397 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 boolean mLayoutNeeded = true;
400 boolean mAnimationPending = false;
401 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800402 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 boolean mWindowsFreezingScreen = false;
404 long mFreezeGcPending = 0;
405 int mAppsFreezingScreen = 0;
406
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800407 int mLayoutSeq = 0;
408
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800409 // State while inside of layoutAndPlaceSurfacesLocked().
410 boolean mFocusMayChange;
411
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800412 Configuration mCurConfiguration = new Configuration();
413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 // This is held as long as we have the screen frozen, to give us time to
415 // perform a rotation animation when turning off shows the lock screen which
416 // changes the orientation.
417 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 // State management of app transitions. When we are preparing for a
420 // transition, mNextAppTransition will be the kind of transition to
421 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
422 // mOpeningApps and mClosingApps are the lists of tokens that will be
423 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700424 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700425 String mNextAppTransitionPackage;
426 int mNextAppTransitionEnter;
427 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700429 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 boolean mAppTransitionTimeout = false;
431 boolean mStartingIconInTransition = false;
432 boolean mSkipAppTransitionAnimation = false;
433 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
434 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700435 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
436 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 H mH = new H();
441
442 WindowState mCurrentFocus = null;
443 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 // This just indicates the window the input method is on top of, not
446 // necessarily the window its input is going to.
447 WindowState mInputMethodTarget = null;
448 WindowState mUpcomingInputMethodTarget = null;
449 boolean mInputMethodTargetWaitingAnim;
450 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 WindowState mInputMethodWindow = null;
453 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
454
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700455 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800456
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 // If non-null, this is the currently visible window that is associated
458 // with the wallpaper.
459 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the lower one in Z-order.
462 WindowState mLowerWallpaperTarget = null;
463 // If non-null, we are in the middle of animating from one wallpaper target
464 // to another, and this is the higher one in Z-order.
465 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700466 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700467 float mLastWallpaperX = -1;
468 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800469 float mLastWallpaperXStep = -1;
470 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700471 // This is set when we are waiting for a wallpaper to tell us it is done
472 // changing its scroll position.
473 WindowState mWaitingOnWallpaper;
474 // The last time we had a timeout when waiting for a wallpaper.
475 long mLastWallpaperTimeoutTime;
476 // We give a wallpaper up to 150ms to finish scrolling.
477 static final long WALLPAPER_TIMEOUT = 150;
478 // Time we wait after a timeout before trying to wait again.
479 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 AppWindowToken mFocusedApp = null;
482
483 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 float mWindowAnimationScale = 1.0f;
486 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700487
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700488 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489
490 // Who is holding the screen on.
491 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700492 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700493
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700494 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700497 * Drag/drop state
498 */
499 class DragState {
500 IBinder mToken;
501 Surface mSurface;
502 boolean mLocalOnly;
503 ClipData mData;
504 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700505 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700506 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700507 float mThumbOffsetX, mThumbOffsetY;
508 InputChannel mServerChannel, mClientChannel;
509 WindowState mTargetWindow;
510 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700511 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700512
513 private final Rect tmpRect = new Rect();
514
515 DragState(IBinder token, Surface surface, boolean localOnly) {
516 mToken = token;
517 mSurface = surface;
518 mLocalOnly = localOnly;
519 mNotifiedWindows = new ArrayList<WindowState>();
520 }
521
522 void reset() {
523 if (mSurface != null) {
524 mSurface.destroy();
525 }
526 mSurface = null;
527 mLocalOnly = false;
528 mToken = null;
529 mData = null;
530 mThumbOffsetX = mThumbOffsetY = 0;
531 mNotifiedWindows = null;
532 }
533
534 void register() {
535 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
536 if (mClientChannel != null) {
537 Slog.e(TAG, "Duplicate register of drag input channel");
538 } else {
539 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
540 mServerChannel = channels[0];
541 mClientChannel = channels[1];
542 mInputManager.registerInputChannel(mServerChannel);
543 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
544 mH.getLooper().getQueue());
545 }
546 }
547
548 void unregister() {
549 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
550 if (mClientChannel == null) {
551 Slog.e(TAG, "Unregister of nonexistent drag input channel");
552 } else {
553 mInputManager.unregisterInputChannel(mServerChannel);
554 InputQueue.unregisterInputChannel(mClientChannel);
555 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700556 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700557 mClientChannel = null;
558 mServerChannel = null;
559 }
560 }
561
Chris Tatea32dcf72010-10-14 12:13:50 -0700562 int getDragLayerLw() {
563 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
564 * TYPE_LAYER_MULTIPLIER
565 + TYPE_LAYER_OFFSET;
566 }
567
Christopher Tatea53146c2010-09-07 11:57:52 -0700568 /* call out to each visible window/session informing it about the drag
569 */
Chris Tateb8203e92010-10-12 14:23:21 -0700570 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700571 // Cache a base-class instance of the clip metadata so that parceling
572 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700573 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700574 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700575 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700576
577 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700578 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700579 }
580
Christopher Tate2c095f32010-10-04 14:13:40 -0700581 final int N = mWindows.size();
582 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700583 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700585 }
586
587 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
588 * designated window is potentially a drop recipient. There are race situations
589 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
590 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700591 *
592 * This method clones the 'event' parameter if it's being delivered to the same
593 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700594 */
Chris Tateb478f462010-10-15 16:02:26 -0700595 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
596 ClipDescription desc) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700597 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700598 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
599 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700600 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700601 try {
602 newWin.mClient.dispatchDragEvent(event);
603 // track each window that we've notified that the drag is starting
604 mNotifiedWindows.add(newWin);
605 } catch (RemoteException e) {
606 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700607 } finally {
608 // if the callee was local, the dispatch has already recycled the event
609 if (Process.myPid() != newWin.mSession.mPid) {
610 event.recycle();
611 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700612 }
613 }
614 }
615
616 /* helper - construct and send a DRAG_STARTED event only if the window has not
617 * previously been notified, i.e. it became visible after the drag operation
618 * was begun. This is a rare case.
619 */
620 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700621 if (mDragInProgress) {
622 // If we have sent the drag-started, we needn't do so again
623 for (WindowState ws : mNotifiedWindows) {
624 if (ws == newWin) {
625 return;
626 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700627 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700628 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700629 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700630 }
Chris Tateb478f462010-10-15 16:02:26 -0700631 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700632 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700633 }
634
Chris Tated4533f142010-10-19 15:15:08 -0700635 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700636 if (DEBUG_DRAG) {
637 Slog.d(TAG, "broadcasting DRAG_ENDED");
638 }
Chris Tated4533f142010-10-19 15:15:08 -0700639 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
640 0, 0, null, null, mDragResult);
641 for (WindowState ws: mNotifiedWindows) {
642 try {
643 ws.mClient.dispatchDragEvent(evt);
644 } catch (RemoteException e) {
645 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700646 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700647 }
Chris Tated4533f142010-10-19 15:15:08 -0700648 mNotifiedWindows.clear();
649 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700650 evt.recycle();
651 }
652
Chris Tated4533f142010-10-19 15:15:08 -0700653 void endDragLw() {
654 mDragState.broadcastDragEndedLw();
655
656 // stop intercepting input
657 mDragState.unregister();
658 mInputMonitor.updateInputWindowsLw();
659
660 // free our resources and drop all the object references
661 mDragState.reset();
662 mDragState = null;
663 }
664
Christopher Tatea53146c2010-09-07 11:57:52 -0700665 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700666 final int myPid = Process.myPid();
667
668 // Move the surface to the given touch
669 mSurface.openTransaction();
670 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
671 mSurface.closeTransaction();
672
673 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700674 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
675 try {
676 // have we dragged over a new window?
677 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
678 if (DEBUG_DRAG) {
679 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
680 }
681 // force DRAG_EXITED_EVENT if appropriate
682 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700683 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700684 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700685 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700686 if (myPid != mTargetWindow.mSession.mPid) {
687 evt.recycle();
688 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700689 }
690 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700691 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700692 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
693 }
694 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700695 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700696 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700697 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700698 if (myPid != touchedWin.mSession.mPid) {
699 evt.recycle();
700 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700701 }
702 } catch (RemoteException e) {
703 Slog.w(TAG, "can't send drag notification to windows");
704 }
705 mTargetWindow = touchedWin;
706 }
707
Chris Tated4533f142010-10-19 15:15:08 -0700708 // Tell the drop target about the data. Returns 'true' if we can immediately
709 // dispatch the global drag-ended message, 'false' if we need to wait for a
710 // result from the recipient.
711 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700712 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700713 if (touchedWin == null) {
714 // "drop" outside a valid window -- no recipient to apply a
715 // timeout to, and we can send the drag-ended message immediately.
716 mDragResult = false;
717 return true;
718 }
719
720 if (DEBUG_DRAG) {
721 Slog.d(TAG, "sending DROP to " + touchedWin);
722 }
723 final int myPid = Process.myPid();
724 final IBinder token = touchedWin.mClient.asBinder();
725 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
726 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
727 null, mData, false);
728 try {
729 touchedWin.mClient.dispatchDragEvent(evt);
730
731 // 5 second timeout for this window to respond to the drop
732 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
733 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
734 mH.sendMessageDelayed(msg, 5000);
735 } catch (RemoteException e) {
736 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
737 return true;
738 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700739 if (myPid != touchedWin.mSession.mPid) {
740 evt.recycle();
741 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700742 }
Chris Tated4533f142010-10-19 15:15:08 -0700743 mToken = token;
744 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700745 }
746
747 // Find the visible, touch-deliverable window under the given point
748 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
749 WindowState touchedWin = null;
750 final int x = (int) xf;
751 final int y = (int) yf;
752 final ArrayList<WindowState> windows = mWindows;
753 final int N = windows.size();
754 for (int i = N - 1; i >= 0; i--) {
755 WindowState child = windows.get(i);
756 final int flags = child.mAttrs.flags;
757 if (!child.isVisibleLw()) {
758 // not visible == don't tell about drags
759 continue;
760 }
761 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
762 // not touchable == don't tell about drags
763 continue;
764 }
765 // account for the window's decor etc
766 tmpRect.set(child.mFrame);
767 if (child.mTouchableInsets == ViewTreeObserver
768 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
769 // The point is inside of the window if it is
770 // inside the frame, AND the content part of that
771 // frame that was given by the application.
772 tmpRect.left += child.mGivenContentInsets.left;
773 tmpRect.top += child.mGivenContentInsets.top;
774 tmpRect.right -= child.mGivenContentInsets.right;
775 tmpRect.bottom -= child.mGivenContentInsets.bottom;
776 } else if (child.mTouchableInsets == ViewTreeObserver
777 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
778 // The point is inside of the window if it is
779 // inside the frame, AND the visible part of that
780 // frame that was given by the application.
781 tmpRect.left += child.mGivenVisibleInsets.left;
782 tmpRect.top += child.mGivenVisibleInsets.top;
783 tmpRect.right -= child.mGivenVisibleInsets.right;
784 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
785 }
786 final int touchFlags = flags &
787 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
788 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
789 if (tmpRect.contains(x, y) || touchFlags == 0) {
790 // Found it
791 touchedWin = child;
792 break;
793 }
794 }
795
796 return touchedWin;
797 }
798 }
799
800 DragState mDragState = null;
801 private final InputHandler mDragInputHandler = new BaseInputHandler() {
802 @Override
803 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
804 boolean endDrag = false;
805 final float newX = event.getRawX();
806 final float newY = event.getRawY();
807
808 try {
809 if (mDragState != null) {
810 switch (event.getAction()) {
811 case MotionEvent.ACTION_DOWN: {
812 if (DEBUG_DRAG) {
813 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
814 }
815 } break;
816
817 case MotionEvent.ACTION_MOVE: {
818 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700819 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700820 mDragState.notifyMoveLw(newX, newY);
821 }
822 } break;
823
824 case MotionEvent.ACTION_UP: {
825 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
826 + newX + "," + newY);
827 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700828 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700829 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700830 } break;
831
832 case MotionEvent.ACTION_CANCEL: {
833 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
834 endDrag = true;
835 } break;
836 }
837
838 if (endDrag) {
839 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
840 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700841 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700842 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700843 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700844 }
845 }
846 } catch (Exception e) {
847 Slog.e(TAG, "Exception caught by drag handleMotion", e);
848 } finally {
849 finishedCallback.run();
850 }
851 }
852 };
853
854 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 * Whether the UI is currently running in touch mode (not showing
856 * navigational focus because the user is directly pressing the screen).
857 */
858 boolean mInTouchMode = false;
859
860 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700861 private ArrayList<WindowChangeListener> mWindowChangeListeners =
862 new ArrayList<WindowChangeListener>();
863 private boolean mWindowsChanged = false;
864
865 public interface WindowChangeListener {
866 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700867 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700868 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869
Dianne Hackbornc485a602009-03-24 22:39:49 -0700870 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700871 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700872
873 // The frame use to limit the size of the app running in compatibility mode.
874 Rect mCompatibleScreenFrame = new Rect();
875 // The surface used to fill the outer rim of the app running in compatibility mode.
876 Surface mBackgroundFillerSurface = null;
877 boolean mBackgroundFillerShown = false;
878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 public static WindowManagerService main(Context context,
880 PowerManagerService pm, boolean haveInputMethods) {
881 WMThread thr = new WMThread(context, pm, haveInputMethods);
882 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 synchronized (thr) {
885 while (thr.mService == null) {
886 try {
887 thr.wait();
888 } catch (InterruptedException e) {
889 }
890 }
891 }
Romain Guy06882f82009-06-10 13:36:04 -0700892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 return thr.mService;
894 }
Romain Guy06882f82009-06-10 13:36:04 -0700895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 static class WMThread extends Thread {
897 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 private final Context mContext;
900 private final PowerManagerService mPM;
901 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 public WMThread(Context context, PowerManagerService pm,
904 boolean haveInputMethods) {
905 super("WindowManager");
906 mContext = context;
907 mPM = pm;
908 mHaveInputMethods = haveInputMethods;
909 }
Romain Guy06882f82009-06-10 13:36:04 -0700910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 public void run() {
912 Looper.prepare();
913 WindowManagerService s = new WindowManagerService(mContext, mPM,
914 mHaveInputMethods);
915 android.os.Process.setThreadPriority(
916 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700917 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 synchronized (this) {
920 mService = s;
921 notifyAll();
922 }
Romain Guy06882f82009-06-10 13:36:04 -0700923
Brad Fitzpatrick07218612010-11-03 09:56:54 -0700924 // For debug builds, log event loop stalls to dropbox for analysis.
925 if (StrictMode.conditionallyEnableDebugLogging()) {
926 Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper");
927 }
928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 Looper.loop();
930 }
931 }
932
933 static class PolicyThread extends Thread {
934 private final WindowManagerPolicy mPolicy;
935 private final WindowManagerService mService;
936 private final Context mContext;
937 private final PowerManagerService mPM;
938 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 public PolicyThread(WindowManagerPolicy policy,
941 WindowManagerService service, Context context,
942 PowerManagerService pm) {
943 super("WindowManagerPolicy");
944 mPolicy = policy;
945 mService = service;
946 mContext = context;
947 mPM = pm;
948 }
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 public void run() {
951 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800952 WindowManagerPolicyThread.set(this, Looper.myLooper());
953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800955 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 android.os.Process.setThreadPriority(
957 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700958 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 synchronized (this) {
962 mRunning = true;
963 notifyAll();
964 }
Romain Guy06882f82009-06-10 13:36:04 -0700965
Brad Fitzpatrick07218612010-11-03 09:56:54 -0700966 // For debug builds, log event loop stalls to dropbox for analysis.
967 if (StrictMode.conditionallyEnableDebugLogging()) {
968 Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper");
969 }
970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 Looper.loop();
972 }
973 }
974
975 private WindowManagerService(Context context, PowerManagerService pm,
976 boolean haveInputMethods) {
977 mContext = context;
978 mHaveInputMethods = haveInputMethods;
979 mLimitedAlphaCompositing = context.getResources().getBoolean(
980 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 mPowerManager = pm;
983 mPowerManager.setPolicy(mPolicy);
984 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
985 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
986 "SCREEN_FROZEN");
987 mScreenFrozenLock.setReferenceCounted(false);
988
989 mActivityManager = ActivityManagerNative.getDefault();
990 mBatteryStats = BatteryStatsService.getService();
991
992 // Get persisted window scale setting
993 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
994 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
995 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
996 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700997
Jim Miller284b62e2010-06-08 14:27:42 -0700998 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
999 IntentFilter filter = new IntentFilter();
1000 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
1001 mContext.registerReceiver(mBroadcastReceiver, filter);
1002
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001003 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
1004 "KEEP_SCREEN_ON_FLAG");
1005 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006
Jeff Browne33348b2010-07-15 23:54:05 -07001007 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -07001008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
1010 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 synchronized (thr) {
1013 while (!thr.mRunning) {
1014 try {
1015 thr.wait();
1016 } catch (InterruptedException e) {
1017 }
1018 }
1019 }
Romain Guy06882f82009-06-10 13:36:04 -07001020
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001021 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 // Add ourself to the Watchdog monitors.
1024 Watchdog.getInstance().addMonitor(this);
1025 }
1026
1027 @Override
1028 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1029 throws RemoteException {
1030 try {
1031 return super.onTransact(code, data, reply, flags);
1032 } catch (RuntimeException e) {
1033 // The window manager only throws security exceptions, so let's
1034 // log all others.
1035 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001036 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 }
1038 throw e;
1039 }
1040 }
1041
Jeff Browne33348b2010-07-15 23:54:05 -07001042 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001044 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 TAG, "Adding window " + window + " at "
1046 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1047 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001048 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 }
1050
Jeff Browne33348b2010-07-15 23:54:05 -07001051 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001053 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 TAG, "Adding window " + window + " at "
1055 + i + " of " + mWindows.size() + " (before " + pos + ")");
1056 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001057 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 }
1059
1060 //This method finds out the index of a window that has the same app token as
1061 //win. used for z ordering the windows in mWindows
1062 private int findIdxBasedOnAppTokens(WindowState win) {
1063 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001064 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 int jmax = localmWindows.size();
1066 if(jmax == 0) {
1067 return -1;
1068 }
1069 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001070 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 if(wentry.mAppToken == win.mAppToken) {
1072 return j;
1073 }
1074 }
1075 return -1;
1076 }
Romain Guy06882f82009-06-10 13:36:04 -07001077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1079 final IWindow client = win.mClient;
1080 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001081 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 final int N = localmWindows.size();
1084 final WindowState attached = win.mAttachedWindow;
1085 int i;
1086 if (attached == null) {
1087 int tokenWindowsPos = token.windows.size();
1088 if (token.appWindowToken != null) {
1089 int index = tokenWindowsPos-1;
1090 if (index >= 0) {
1091 // If this application has existing windows, we
1092 // simply place the new window on top of them... but
1093 // keep the starting window on top.
1094 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1095 // Base windows go behind everything else.
1096 placeWindowBefore(token.windows.get(0), win);
1097 tokenWindowsPos = 0;
1098 } else {
1099 AppWindowToken atoken = win.mAppToken;
1100 if (atoken != null &&
1101 token.windows.get(index) == atoken.startingWindow) {
1102 placeWindowBefore(token.windows.get(index), win);
1103 tokenWindowsPos--;
1104 } else {
1105 int newIdx = findIdxBasedOnAppTokens(win);
1106 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001107 //there is a window above this one associated with the same
1108 //apptoken note that the window could be a floating window
1109 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001111 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001112 TAG, "Adding window " + win + " at "
1113 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001115 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 }
1118 }
1119 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001120 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 TAG, "Figuring out where to add app window "
1122 + client.asBinder() + " (token=" + token + ")");
1123 // Figure out where the window should go, based on the
1124 // order of applications.
1125 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001126 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 for (i=NA-1; i>=0; i--) {
1128 AppWindowToken t = mAppTokens.get(i);
1129 if (t == token) {
1130 i--;
1131 break;
1132 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001133
Dianne Hackborna8f60182009-09-01 19:01:50 -07001134 // We haven't reached the token yet; if this token
1135 // is not going to the bottom and has windows, we can
1136 // use it as an anchor for when we do reach the token.
1137 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 pos = t.windows.get(0);
1139 }
1140 }
1141 // We now know the index into the apps. If we found
1142 // an app window above, that gives us the position; else
1143 // we need to look some more.
1144 if (pos != null) {
1145 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001146 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 if (atoken != null) {
1148 final int NC = atoken.windows.size();
1149 if (NC > 0) {
1150 WindowState bottom = atoken.windows.get(0);
1151 if (bottom.mSubLayer < 0) {
1152 pos = bottom;
1153 }
1154 }
1155 }
1156 placeWindowBefore(pos, win);
1157 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001158 // Continue looking down until we find the first
1159 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 while (i >= 0) {
1161 AppWindowToken t = mAppTokens.get(i);
1162 final int NW = t.windows.size();
1163 if (NW > 0) {
1164 pos = t.windows.get(NW-1);
1165 break;
1166 }
1167 i--;
1168 }
1169 if (pos != null) {
1170 // Move in front of any windows attached to this
1171 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001172 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 if (atoken != null) {
1174 final int NC = atoken.windows.size();
1175 if (NC > 0) {
1176 WindowState top = atoken.windows.get(NC-1);
1177 if (top.mSubLayer >= 0) {
1178 pos = top;
1179 }
1180 }
1181 }
1182 placeWindowAfter(pos, win);
1183 } else {
1184 // Just search for the start of this layer.
1185 final int myLayer = win.mBaseLayer;
1186 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001187 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 if (w.mBaseLayer > myLayer) {
1189 break;
1190 }
1191 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001192 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001193 TAG, "Adding window " + win + " at "
1194 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001196 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 }
1198 }
1199 }
1200 } else {
1201 // Figure out where window should go, based on layer.
1202 final int myLayer = win.mBaseLayer;
1203 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001204 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 i++;
1206 break;
1207 }
1208 }
1209 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001210 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001211 TAG, "Adding window " + win + " at "
1212 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001214 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 }
1216 if (addToToken) {
1217 token.windows.add(tokenWindowsPos, win);
1218 }
1219
1220 } else {
1221 // Figure out this window's ordering relative to the window
1222 // it is attached to.
1223 final int NA = token.windows.size();
1224 final int sublayer = win.mSubLayer;
1225 int largestSublayer = Integer.MIN_VALUE;
1226 WindowState windowWithLargestSublayer = null;
1227 for (i=0; i<NA; i++) {
1228 WindowState w = token.windows.get(i);
1229 final int wSublayer = w.mSubLayer;
1230 if (wSublayer >= largestSublayer) {
1231 largestSublayer = wSublayer;
1232 windowWithLargestSublayer = w;
1233 }
1234 if (sublayer < 0) {
1235 // For negative sublayers, we go below all windows
1236 // in the same sublayer.
1237 if (wSublayer >= sublayer) {
1238 if (addToToken) {
1239 token.windows.add(i, win);
1240 }
1241 placeWindowBefore(
1242 wSublayer >= 0 ? attached : w, win);
1243 break;
1244 }
1245 } else {
1246 // For positive sublayers, we go above all windows
1247 // in the same sublayer.
1248 if (wSublayer > sublayer) {
1249 if (addToToken) {
1250 token.windows.add(i, win);
1251 }
1252 placeWindowBefore(w, win);
1253 break;
1254 }
1255 }
1256 }
1257 if (i >= NA) {
1258 if (addToToken) {
1259 token.windows.add(win);
1260 }
1261 if (sublayer < 0) {
1262 placeWindowBefore(attached, win);
1263 } else {
1264 placeWindowAfter(largestSublayer >= 0
1265 ? windowWithLargestSublayer
1266 : attached,
1267 win);
1268 }
1269 }
1270 }
Romain Guy06882f82009-06-10 13:36:04 -07001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 if (win.mAppToken != null && addToToken) {
1273 win.mAppToken.allAppWindows.add(win);
1274 }
1275 }
Romain Guy06882f82009-06-10 13:36:04 -07001276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 static boolean canBeImeTarget(WindowState w) {
1278 final int fl = w.mAttrs.flags
1279 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1280 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1281 return w.isVisibleOrAdding();
1282 }
1283 return false;
1284 }
Romain Guy06882f82009-06-10 13:36:04 -07001285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001287 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 final int N = localmWindows.size();
1289 WindowState w = null;
1290 int i = N;
1291 while (i > 0) {
1292 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001293 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001294
Joe Onorato8a9b2202010-02-26 18:56:32 -08001295 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 // + Integer.toHexString(w.mAttrs.flags));
1297 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001298 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 // Yet more tricksyness! If this window is a "starting"
1301 // window, we do actually want to be on top of it, but
1302 // it is not -really- where input will go. So if the caller
1303 // is not actually looking to move the IME, look down below
1304 // for a real window to target...
1305 if (!willMove
1306 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1307 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001308 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001309 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1310 i--;
1311 w = wb;
1312 }
1313 }
1314 break;
1315 }
1316 }
Romain Guy06882f82009-06-10 13:36:04 -07001317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001319
Joe Onorato8a9b2202010-02-26 18:56:32 -08001320 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001323 if (willMove && w != null) {
1324 final WindowState curTarget = mInputMethodTarget;
1325 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001327 // Now some fun for dealing with window animations that
1328 // modify the Z order. We need to look at all windows below
1329 // the current target that are in this app, finding the highest
1330 // visible one in layering.
1331 AppWindowToken token = curTarget.mAppToken;
1332 WindowState highestTarget = null;
1333 int highestPos = 0;
1334 if (token.animating || token.animation != null) {
1335 int pos = 0;
1336 pos = localmWindows.indexOf(curTarget);
1337 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001338 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 if (win.mAppToken != token) {
1340 break;
1341 }
1342 if (!win.mRemoved) {
1343 if (highestTarget == null || win.mAnimLayer >
1344 highestTarget.mAnimLayer) {
1345 highestTarget = win;
1346 highestPos = pos;
1347 }
1348 }
1349 pos--;
1350 }
1351 }
Romain Guy06882f82009-06-10 13:36:04 -07001352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001354 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001355 + mNextAppTransition + " " + highestTarget
1356 + " animating=" + highestTarget.isAnimating()
1357 + " layer=" + highestTarget.mAnimLayer
1358 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001359
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001360 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 // If we are currently setting up for an animation,
1362 // hold everything until we can find out what will happen.
1363 mInputMethodTargetWaitingAnim = true;
1364 mInputMethodTarget = highestTarget;
1365 return highestPos + 1;
1366 } else if (highestTarget.isAnimating() &&
1367 highestTarget.mAnimLayer > w.mAnimLayer) {
1368 // If the window we are currently targeting is involved
1369 // with an animation, and it is on top of the next target
1370 // we will be over, then hold off on moving until
1371 // that is done.
1372 mInputMethodTarget = highestTarget;
1373 return highestPos + 1;
1374 }
1375 }
1376 }
1377 }
Romain Guy06882f82009-06-10 13:36:04 -07001378
Joe Onorato8a9b2202010-02-26 18:56:32 -08001379 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 if (w != null) {
1381 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001382 if (DEBUG_INPUT_METHOD) {
1383 RuntimeException e = null;
1384 if (!HIDE_STACK_CRAWLS) {
1385 e = new RuntimeException();
1386 e.fillInStackTrace();
1387 }
1388 Slog.w(TAG, "Moving IM target from "
1389 + mInputMethodTarget + " to " + w, e);
1390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 mInputMethodTarget = w;
1392 if (w.mAppToken != null) {
1393 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1394 } else {
1395 setInputMethodAnimLayerAdjustment(0);
1396 }
1397 }
1398 return i+1;
1399 }
1400 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001401 if (DEBUG_INPUT_METHOD) {
1402 RuntimeException e = null;
1403 if (!HIDE_STACK_CRAWLS) {
1404 e = new RuntimeException();
1405 e.fillInStackTrace();
1406 }
1407 Slog.w(TAG, "Moving IM target from "
1408 + mInputMethodTarget + " to null", e);
1409 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001410 mInputMethodTarget = null;
1411 setInputMethodAnimLayerAdjustment(0);
1412 }
1413 return -1;
1414 }
Romain Guy06882f82009-06-10 13:36:04 -07001415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001416 void addInputMethodWindowToListLocked(WindowState win) {
1417 int pos = findDesiredInputMethodWindowIndexLocked(true);
1418 if (pos >= 0) {
1419 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001420 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001421 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001423 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 moveInputMethodDialogsLocked(pos+1);
1425 return;
1426 }
1427 win.mTargetAppToken = null;
1428 addWindowToListInOrderLocked(win, true);
1429 moveInputMethodDialogsLocked(pos);
1430 }
Romain Guy06882f82009-06-10 13:36:04 -07001431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 mInputMethodAnimLayerAdjustment = adj;
1435 WindowState imw = mInputMethodWindow;
1436 if (imw != null) {
1437 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001438 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 + " anim layer: " + imw.mAnimLayer);
1440 int wi = imw.mChildWindows.size();
1441 while (wi > 0) {
1442 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001443 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001445 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 + " anim layer: " + cw.mAnimLayer);
1447 }
1448 }
1449 int di = mInputMethodDialogs.size();
1450 while (di > 0) {
1451 di --;
1452 imw = mInputMethodDialogs.get(di);
1453 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001454 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 + " anim layer: " + imw.mAnimLayer);
1456 }
1457 }
Romain Guy06882f82009-06-10 13:36:04 -07001458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1460 int wpos = mWindows.indexOf(win);
1461 if (wpos >= 0) {
1462 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001463 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001465 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 int NC = win.mChildWindows.size();
1467 while (NC > 0) {
1468 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001469 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 int cpos = mWindows.indexOf(cw);
1471 if (cpos >= 0) {
1472 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001473 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001474 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 mWindows.remove(cpos);
1476 }
1477 }
1478 }
1479 return interestingPos;
1480 }
Romain Guy06882f82009-06-10 13:36:04 -07001481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 private void reAddWindowToListInOrderLocked(WindowState win) {
1483 addWindowToListInOrderLocked(win, false);
1484 // This is a hack to get all of the child windows added as well
1485 // at the right position. Child windows should be rare and
1486 // this case should be rare, so it shouldn't be that big a deal.
1487 int wpos = mWindows.indexOf(win);
1488 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001489 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001490 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001492 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 reAddWindowLocked(wpos, win);
1494 }
1495 }
Romain Guy06882f82009-06-10 13:36:04 -07001496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 void logWindowList(String prefix) {
1498 int N = mWindows.size();
1499 while (N > 0) {
1500 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001501 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 }
1503 }
Romain Guy06882f82009-06-10 13:36:04 -07001504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 void moveInputMethodDialogsLocked(int pos) {
1506 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001509 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 for (int i=0; i<N; i++) {
1511 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1512 }
1513 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001514 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 logWindowList(" ");
1516 }
Romain Guy06882f82009-06-10 13:36:04 -07001517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 if (pos >= 0) {
1519 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1520 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001521 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 if (wp == mInputMethodWindow) {
1523 pos++;
1524 }
1525 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001526 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 for (int i=0; i<N; i++) {
1528 WindowState win = dialogs.get(i);
1529 win.mTargetAppToken = targetAppToken;
1530 pos = reAddWindowLocked(pos, win);
1531 }
1532 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001533 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 logWindowList(" ");
1535 }
1536 return;
1537 }
1538 for (int i=0; i<N; i++) {
1539 WindowState win = dialogs.get(i);
1540 win.mTargetAppToken = null;
1541 reAddWindowToListInOrderLocked(win);
1542 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001543 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 logWindowList(" ");
1545 }
1546 }
1547 }
Romain Guy06882f82009-06-10 13:36:04 -07001548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1550 final WindowState imWin = mInputMethodWindow;
1551 final int DN = mInputMethodDialogs.size();
1552 if (imWin == null && DN == 0) {
1553 return false;
1554 }
Romain Guy06882f82009-06-10 13:36:04 -07001555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1557 if (imPos >= 0) {
1558 // In this case, the input method windows are to be placed
1559 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 // First check to see if the input method windows are already
1562 // located here, and contiguous.
1563 final int N = mWindows.size();
1564 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001565 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 // Figure out the actual input method window that should be
1568 // at the bottom of their stack.
1569 WindowState baseImWin = imWin != null
1570 ? imWin : mInputMethodDialogs.get(0);
1571 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001572 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 if (cw.mSubLayer < 0) baseImWin = cw;
1574 }
Romain Guy06882f82009-06-10 13:36:04 -07001575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 if (firstImWin == baseImWin) {
1577 // The windows haven't moved... but are they still contiguous?
1578 // First find the top IM window.
1579 int pos = imPos+1;
1580 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001581 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 break;
1583 }
1584 pos++;
1585 }
1586 pos++;
1587 // Now there should be no more input method windows above.
1588 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001589 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 break;
1591 }
1592 pos++;
1593 }
1594 if (pos >= N) {
1595 // All is good!
1596 return false;
1597 }
1598 }
Romain Guy06882f82009-06-10 13:36:04 -07001599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 if (imWin != null) {
1601 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 logWindowList(" ");
1604 }
1605 imPos = tmpRemoveWindowLocked(imPos, imWin);
1606 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001607 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 logWindowList(" ");
1609 }
1610 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1611 reAddWindowLocked(imPos, imWin);
1612 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 logWindowList(" ");
1615 }
1616 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1617 } else {
1618 moveInputMethodDialogsLocked(imPos);
1619 }
Romain Guy06882f82009-06-10 13:36:04 -07001620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 } else {
1622 // In this case, the input method windows go in a fixed layer,
1623 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 tmpRemoveWindowLocked(0, imWin);
1628 imWin.mTargetAppToken = null;
1629 reAddWindowToListInOrderLocked(imWin);
1630 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001631 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 logWindowList(" ");
1633 }
1634 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1635 } else {
1636 moveInputMethodDialogsLocked(-1);;
1637 }
Romain Guy06882f82009-06-10 13:36:04 -07001638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 }
Romain Guy06882f82009-06-10 13:36:04 -07001640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 if (needAssignLayers) {
1642 assignLayersLocked();
1643 }
Romain Guy06882f82009-06-10 13:36:04 -07001644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 return true;
1646 }
Romain Guy06882f82009-06-10 13:36:04 -07001647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 void adjustInputMethodDialogsLocked() {
1649 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1650 }
Romain Guy06882f82009-06-10 13:36:04 -07001651
Dianne Hackborn25994b42009-09-04 14:21:19 -07001652 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001653 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001654 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1655 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1656 ? wallpaperTarget.mAppToken.animation : null)
1657 + " upper=" + mUpperWallpaperTarget
1658 + " lower=" + mLowerWallpaperTarget);
1659 return (wallpaperTarget != null
1660 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1661 && wallpaperTarget.mAppToken.animation != null)))
1662 || mUpperWallpaperTarget != null
1663 || mLowerWallpaperTarget != null;
1664 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001665
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001666 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1667 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001668
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001669 int adjustWallpaperWindowsLocked() {
1670 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001671
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001672 final int dw = mDisplay.getWidth();
1673 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001674
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001675 // First find top-most window that has asked to be on top of the
1676 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001677 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001678 int N = localmWindows.size();
1679 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001680 WindowState foundW = null;
1681 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001682 WindowState topCurW = null;
1683 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001684 int i = N;
1685 while (i > 0) {
1686 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001687 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001688 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1689 if (topCurW == null) {
1690 topCurW = w;
1691 topCurI = i;
1692 }
1693 continue;
1694 }
1695 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001696 if (w.mAppToken != null) {
1697 // If this window's app token is hidden and not animating,
1698 // it is of no interest to us.
1699 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001701 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001702 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001703 continue;
1704 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001705 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001706 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001707 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1708 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001709 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001710 && (mWallpaperTarget == w
1711 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001712 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001713 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001714 foundW = w;
1715 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001716 if (w == mWallpaperTarget && ((w.mAppToken != null
1717 && w.mAppToken.animation != null)
1718 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001719 // The current wallpaper target is animating, so we'll
1720 // look behind it for another possible target and figure
1721 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001722 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001723 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001724 continue;
1725 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001726 break;
1727 }
1728 }
1729
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001730 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001731 // If we are currently waiting for an app transition, and either
1732 // the current target or the next target are involved with it,
1733 // then hold off on doing anything with the wallpaper.
1734 // Note that we are checking here for just whether the target
1735 // is part of an app token... which is potentially overly aggressive
1736 // (the app token may not be involved in the transition), but good
1737 // enough (we'll just wait until whatever transition is pending
1738 // executes).
1739 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001740 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001741 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001742 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001743 }
1744 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001745 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001747 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001748 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001751 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001752 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001753 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001754 + " oldTarget: " + mWallpaperTarget);
1755 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001756
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001757 mLowerWallpaperTarget = null;
1758 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001759
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001760 WindowState oldW = mWallpaperTarget;
1761 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001762
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001763 // Now what is happening... if the current and new targets are
1764 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001765 if (foundW != null && oldW != null) {
1766 boolean oldAnim = oldW.mAnimation != null
1767 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1768 boolean foundAnim = foundW.mAnimation != null
1769 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001771 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001772 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001773 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001774 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001775 int oldI = localmWindows.indexOf(oldW);
1776 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001777 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001778 }
1779 if (oldI >= 0) {
1780 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001781 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001782 + "=" + oldW + "; new#" + foundI
1783 + "=" + foundW);
1784 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001785
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001786 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001787 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001788 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001789 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001790 }
1791 mWallpaperTarget = oldW;
1792 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001793
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001794 // Now set the upper and lower wallpaper targets
1795 // correctly, and make sure that we are positioning
1796 // the wallpaper below the lower.
1797 if (foundI > oldI) {
1798 // The new target is on top of the old one.
1799 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001801 }
1802 mUpperWallpaperTarget = foundW;
1803 mLowerWallpaperTarget = oldW;
1804 foundW = oldW;
1805 foundI = oldI;
1806 } else {
1807 // The new target is below the old one.
1808 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001810 }
1811 mUpperWallpaperTarget = oldW;
1812 mLowerWallpaperTarget = foundW;
1813 }
1814 }
1815 }
1816 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001817
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001818 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001819 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001820 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1821 || (mLowerWallpaperTarget.mAppToken != null
1822 && mLowerWallpaperTarget.mAppToken.animation != null);
1823 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1824 || (mUpperWallpaperTarget.mAppToken != null
1825 && mUpperWallpaperTarget.mAppToken.animation != null);
1826 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001827 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001828 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001829 }
1830 mLowerWallpaperTarget = null;
1831 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001832 }
1833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001834
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001835 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001836 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001837 // The window is visible to the compositor... but is it visible
1838 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001839 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001840 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001842 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001843 // its layer adjustment. Only do this if we are not transfering
1844 // between two wallpaper targets.
1845 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001846 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001847 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001848
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001849 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1850 * TYPE_LAYER_MULTIPLIER
1851 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001852
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001853 // Now w is the window we are supposed to be behind... but we
1854 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001855 // AND any starting window associated with it, AND below the
1856 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001857 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001858 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001859 if (wb.mBaseLayer < maxLayer &&
1860 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001861 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001862 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001863 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001864 // This window is not related to the previous one in any
1865 // interesting way, so stop here.
1866 break;
1867 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001868 foundW = wb;
1869 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001870 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001871 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001872 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001873 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001874
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001875 if (foundW == null && topCurW != null) {
1876 // There is no wallpaper target, so it goes at the bottom.
1877 // We will assume it is the same place as last time, if known.
1878 foundW = topCurW;
1879 foundI = topCurI+1;
1880 } else {
1881 // Okay i is the position immediately above the wallpaper. Look at
1882 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001883 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001884 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001885
Dianne Hackborn284ac932009-08-28 10:34:25 -07001886 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001887 if (mWallpaperTarget.mWallpaperX >= 0) {
1888 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001889 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001890 }
1891 if (mWallpaperTarget.mWallpaperY >= 0) {
1892 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001893 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001894 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001895 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001896
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001897 // Start stepping backwards from here, ensuring that our wallpaper windows
1898 // are correctly placed.
1899 int curTokenIndex = mWallpaperTokens.size();
1900 while (curTokenIndex > 0) {
1901 curTokenIndex--;
1902 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001903 if (token.hidden == visible) {
1904 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1905 token.hidden = !visible;
1906 // Need to do a layout to ensure the wallpaper now has the
1907 // correct size.
1908 mLayoutNeeded = true;
1909 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001910
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001911 int curWallpaperIndex = token.windows.size();
1912 while (curWallpaperIndex > 0) {
1913 curWallpaperIndex--;
1914 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001915
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001916 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001917 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001918 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001919
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001920 // First, make sure the client has the current visibility
1921 // state.
1922 if (wallpaper.mWallpaperVisible != visible) {
1923 wallpaper.mWallpaperVisible = visible;
1924 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001925 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001926 "Setting visibility of wallpaper " + wallpaper
1927 + ": " + visible);
1928 wallpaper.mClient.dispatchAppVisibility(visible);
1929 } catch (RemoteException e) {
1930 }
1931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001932
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001933 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001934 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001935 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001936
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001937 // First, if this window is at the current index, then all
1938 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001939 if (wallpaper == foundW) {
1940 foundI--;
1941 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001942 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001943 continue;
1944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001945
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001946 // The window didn't match... the current wallpaper window,
1947 // wherever it is, is in the wrong place, so make sure it is
1948 // not in the list.
1949 int oldIndex = localmWindows.indexOf(wallpaper);
1950 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001951 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001952 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001953 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001954 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001955 if (oldIndex < foundI) {
1956 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001957 }
1958 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001959
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001960 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001961 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001962 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001963 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001964
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001965 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001966 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001967 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001968 }
1969 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001970
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001971 return changed;
1972 }
1973
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001974 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001975 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001976 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001977 mWallpaperAnimLayerAdjustment = adj;
1978 int curTokenIndex = mWallpaperTokens.size();
1979 while (curTokenIndex > 0) {
1980 curTokenIndex--;
1981 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1982 int curWallpaperIndex = token.windows.size();
1983 while (curWallpaperIndex > 0) {
1984 curWallpaperIndex--;
1985 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1986 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001987 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001988 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001989 }
1990 }
1991 }
1992
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001993 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1994 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001995 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001996 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001997 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001998 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001999 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
2000 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
2001 changed = wallpaperWin.mXOffset != offset;
2002 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002003 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002004 + wallpaperWin + " x: " + offset);
2005 wallpaperWin.mXOffset = offset;
2006 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002007 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002008 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002009 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002010 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002011 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002012
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002013 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002014 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002015 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2016 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2017 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002019 + wallpaperWin + " y: " + offset);
2020 changed = true;
2021 wallpaperWin.mYOffset = offset;
2022 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002023 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002024 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002025 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002026 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002028
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002029 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002030 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002031 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002032 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2033 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002034 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002035 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002036 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002037 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002038 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2039 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002040 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002041 if (mWaitingOnWallpaper != null) {
2042 long start = SystemClock.uptimeMillis();
2043 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2044 < start) {
2045 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002046 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002047 "Waiting for offset complete...");
2048 mWindowMap.wait(WALLPAPER_TIMEOUT);
2049 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002050 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002051 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002052 if ((start+WALLPAPER_TIMEOUT)
2053 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002055 + wallpaperWin);
2056 mLastWallpaperTimeoutTime = start;
2057 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002058 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002059 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002060 }
2061 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002062 } catch (RemoteException e) {
2063 }
2064 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002065
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002066 return changed;
2067 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002068
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002069 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002070 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002071 if (mWaitingOnWallpaper != null &&
2072 mWaitingOnWallpaper.mClient.asBinder() == window) {
2073 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002074 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002075 }
2076 }
2077 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002078
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002079 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002080 final int dw = mDisplay.getWidth();
2081 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002082
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002083 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002084
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002085 WindowState target = mWallpaperTarget;
2086 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002087 if (target.mWallpaperX >= 0) {
2088 mLastWallpaperX = target.mWallpaperX;
2089 } else if (changingTarget.mWallpaperX >= 0) {
2090 mLastWallpaperX = changingTarget.mWallpaperX;
2091 }
2092 if (target.mWallpaperY >= 0) {
2093 mLastWallpaperY = target.mWallpaperY;
2094 } else if (changingTarget.mWallpaperY >= 0) {
2095 mLastWallpaperY = changingTarget.mWallpaperY;
2096 }
2097 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002098
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002099 int curTokenIndex = mWallpaperTokens.size();
2100 while (curTokenIndex > 0) {
2101 curTokenIndex--;
2102 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2103 int curWallpaperIndex = token.windows.size();
2104 while (curWallpaperIndex > 0) {
2105 curWallpaperIndex--;
2106 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2107 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2108 wallpaper.computeShownFrameLocked();
2109 changed = true;
2110 // We only want to be synchronous with one wallpaper.
2111 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002112 }
2113 }
2114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002115
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002116 return changed;
2117 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002118
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002119 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002120 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002121 final int dw = mDisplay.getWidth();
2122 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002123
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002124 int curTokenIndex = mWallpaperTokens.size();
2125 while (curTokenIndex > 0) {
2126 curTokenIndex--;
2127 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002128 if (token.hidden == visible) {
2129 token.hidden = !visible;
2130 // Need to do a layout to ensure the wallpaper now has the
2131 // correct size.
2132 mLayoutNeeded = true;
2133 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002134
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002135 int curWallpaperIndex = token.windows.size();
2136 while (curWallpaperIndex > 0) {
2137 curWallpaperIndex--;
2138 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2139 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002140 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002141 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002142
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002143 if (wallpaper.mWallpaperVisible != visible) {
2144 wallpaper.mWallpaperVisible = visible;
2145 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002146 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002147 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002148 + ": " + visible);
2149 wallpaper.mClient.dispatchAppVisibility(visible);
2150 } catch (RemoteException e) {
2151 }
2152 }
2153 }
2154 }
2155 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 public int addWindow(Session session, IWindow client,
2158 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002159 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 int res = mPolicy.checkAddPermission(attrs);
2161 if (res != WindowManagerImpl.ADD_OKAY) {
2162 return res;
2163 }
Romain Guy06882f82009-06-10 13:36:04 -07002164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 boolean reportNewConfig = false;
2166 WindowState attachedWindow = null;
2167 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002168 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002172 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 }
Romain Guy06882f82009-06-10 13:36:04 -07002174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002176 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2178 }
2179
2180 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002181 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002183 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 + attrs.token + ". Aborting.");
2185 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2186 }
2187 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2188 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002189 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 + attrs.token + ". Aborting.");
2191 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2192 }
2193 }
2194
2195 boolean addToken = false;
2196 WindowToken token = mTokenMap.get(attrs.token);
2197 if (token == null) {
2198 if (attrs.type >= FIRST_APPLICATION_WINDOW
2199 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002200 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 + attrs.token + ". Aborting.");
2202 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2203 }
2204 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002205 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 + attrs.token + ". Aborting.");
2207 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2208 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002209 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002210 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002211 + attrs.token + ". Aborting.");
2212 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 token = new WindowToken(attrs.token, -1, false);
2215 addToken = true;
2216 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2217 && attrs.type <= LAST_APPLICATION_WINDOW) {
2218 AppWindowToken atoken = token.appWindowToken;
2219 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002220 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 + token + ". Aborting.");
2222 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2223 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002224 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 + token + ". Aborting.");
2226 return WindowManagerImpl.ADD_APP_EXITING;
2227 }
2228 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2229 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002230 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2232 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2233 }
2234 } else if (attrs.type == TYPE_INPUT_METHOD) {
2235 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002236 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 + attrs.token + ". Aborting.");
2238 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2239 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002240 } else if (attrs.type == TYPE_WALLPAPER) {
2241 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002242 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002243 + attrs.token + ". Aborting.");
2244 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 }
2247
2248 win = new WindowState(session, client, token,
2249 attachedWindow, attrs, viewVisibility);
2250 if (win.mDeathRecipient == null) {
2251 // Client has apparently died, so there is no reason to
2252 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002253 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 + " that is dead, aborting.");
2255 return WindowManagerImpl.ADD_APP_EXITING;
2256 }
2257
2258 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 res = mPolicy.prepareAddWindowLw(win, attrs);
2261 if (res != WindowManagerImpl.ADD_OKAY) {
2262 return res;
2263 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002264
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002265 if (outInputChannel != null) {
2266 String name = win.makeInputChannelName();
2267 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2268 win.mInputChannel = inputChannels[0];
2269 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2270
2271 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273
2274 // From now on, no exceptions or errors allowed!
2275
2276 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002277
Dianne Hackborn5132b372010-07-29 12:51:35 -07002278 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 if (addToken) {
2281 mTokenMap.put(attrs.token, token);
2282 mTokenList.add(token);
2283 }
2284 win.attach();
2285 mWindowMap.put(client.asBinder(), win);
2286
2287 if (attrs.type == TYPE_APPLICATION_STARTING &&
2288 token.appWindowToken != null) {
2289 token.appWindowToken.startingWindow = win;
2290 }
2291
2292 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 if (attrs.type == TYPE_INPUT_METHOD) {
2295 mInputMethodWindow = win;
2296 addInputMethodWindowToListLocked(win);
2297 imMayMove = false;
2298 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2299 mInputMethodDialogs.add(win);
2300 addWindowToListInOrderLocked(win, true);
2301 adjustInputMethodDialogsLocked();
2302 imMayMove = false;
2303 } else {
2304 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002305 if (attrs.type == TYPE_WALLPAPER) {
2306 mLastWallpaperTimeoutTime = 0;
2307 adjustWallpaperWindowsLocked();
2308 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002309 adjustWallpaperWindowsLocked();
2310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 }
Romain Guy06882f82009-06-10 13:36:04 -07002312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 if (mInTouchMode) {
2318 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2319 }
2320 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2321 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2322 }
Romain Guy06882f82009-06-10 13:36:04 -07002323
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002324 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002326 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2327 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 imMayMove = false;
2329 }
2330 }
Romain Guy06882f82009-06-10 13:36:04 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002333 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 }
Romain Guy06882f82009-06-10 13:36:04 -07002335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002336 assignLayersLocked();
2337 // Don't do layout here, the window must call
2338 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 //dump();
2341
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002342 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002343 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002344 }
Jeff Brown349703e2010-06-22 01:27:15 -07002345
Joe Onorato8a9b2202010-02-26 18:56:32 -08002346 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 TAG, "New client " + client.asBinder()
2348 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002349
2350 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2351 reportNewConfig = true;
2352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 }
2354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 if (reportNewConfig) {
2356 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 return res;
2362 }
Romain Guy06882f82009-06-10 13:36:04 -07002363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 public void removeWindow(Session session, IWindow client) {
2365 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002366 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 if (win == null) {
2368 return;
2369 }
2370 removeWindowLocked(session, win);
2371 }
2372 }
Romain Guy06882f82009-06-10 13:36:04 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 public void removeWindowLocked(Session session, WindowState win) {
2375
Joe Onorato8a9b2202010-02-26 18:56:32 -08002376 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 TAG, "Remove " + win + " client="
2378 + Integer.toHexString(System.identityHashCode(
2379 win.mClient.asBinder()))
2380 + ", surface=" + win.mSurface);
2381
2382 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002383
2384 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002385
Joe Onorato8a9b2202010-02-26 18:56:32 -08002386 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2388 + " mExiting=" + win.mExiting
2389 + " isAnimating=" + win.isAnimating()
2390 + " app-animation="
2391 + (win.mAppToken != null ? win.mAppToken.animation : null)
2392 + " inPendingTransaction="
2393 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2394 + " mDisplayFrozen=" + mDisplayFrozen);
2395 // Visibility of the removed window. Will be used later to update orientation later on.
2396 boolean wasVisible = false;
2397 // First, see if we need to run an animation. If we do, we have
2398 // to hold off on removing the window until the animation is done.
2399 // If the display is frozen, just remove immediately, since the
2400 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002401 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 // If we are not currently running the exit animation, we
2403 // need to see about starting one.
2404 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2407 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2408 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2409 }
2410 // Try starting an animation.
2411 if (applyAnimationLocked(win, transit, false)) {
2412 win.mExiting = true;
2413 }
2414 }
2415 if (win.mExiting || win.isAnimating()) {
2416 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002417 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 win.mExiting = true;
2419 win.mRemoveOnExit = true;
2420 mLayoutNeeded = true;
2421 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2422 performLayoutAndPlaceSurfacesLocked();
2423 if (win.mAppToken != null) {
2424 win.mAppToken.updateReportedVisibilityLocked();
2425 }
2426 //dump();
2427 Binder.restoreCallingIdentity(origId);
2428 return;
2429 }
2430 }
2431
2432 removeWindowInnerLocked(session, win);
2433 // Removing a visible window will effect the computed orientation
2434 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002435 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002436 != mForcedAppOrientation
2437 && updateOrientationFromAppTokensLocked()) {
2438 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 }
2440 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2441 Binder.restoreCallingIdentity(origId);
2442 }
Romain Guy06882f82009-06-10 13:36:04 -07002443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 if (mInputMethodTarget == win) {
2448 moveInputMethodWindowsIfNeededLocked(false);
2449 }
Romain Guy06882f82009-06-10 13:36:04 -07002450
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002451 if (false) {
2452 RuntimeException e = new RuntimeException("here");
2453 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002454 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002455 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 mPolicy.removeWindowLw(win);
2458 win.removeLocked();
2459
2460 mWindowMap.remove(win.mClient.asBinder());
2461 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002462 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002463 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464
2465 if (mInputMethodWindow == win) {
2466 mInputMethodWindow = null;
2467 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2468 mInputMethodDialogs.remove(win);
2469 }
Romain Guy06882f82009-06-10 13:36:04 -07002470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 final WindowToken token = win.mToken;
2472 final AppWindowToken atoken = win.mAppToken;
2473 token.windows.remove(win);
2474 if (atoken != null) {
2475 atoken.allAppWindows.remove(win);
2476 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002477 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 TAG, "**** Removing window " + win + ": count="
2479 + token.windows.size());
2480 if (token.windows.size() == 0) {
2481 if (!token.explicit) {
2482 mTokenMap.remove(token.token);
2483 mTokenList.remove(token);
2484 } else if (atoken != null) {
2485 atoken.firstWindowDrawn = false;
2486 }
2487 }
2488
2489 if (atoken != null) {
2490 if (atoken.startingWindow == win) {
2491 atoken.startingWindow = null;
2492 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2493 // If this is the last window and we had requested a starting
2494 // transition window, well there is no point now.
2495 atoken.startingData = null;
2496 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2497 // If this is the last window except for a starting transition
2498 // window, we need to get rid of the starting transition.
2499 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002500 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 + ": no more real windows");
2502 }
2503 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2504 mH.sendMessage(m);
2505 }
2506 }
Romain Guy06882f82009-06-10 13:36:04 -07002507
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002508 if (win.mAttrs.type == TYPE_WALLPAPER) {
2509 mLastWallpaperTimeoutTime = 0;
2510 adjustWallpaperWindowsLocked();
2511 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002512 adjustWallpaperWindowsLocked();
2513 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 if (!mInLayout) {
2516 assignLayersLocked();
2517 mLayoutNeeded = true;
2518 performLayoutAndPlaceSurfacesLocked();
2519 if (win.mAppToken != null) {
2520 win.mAppToken.updateReportedVisibilityLocked();
2521 }
2522 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002523
2524 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 }
2526
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002527 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2528 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2529 + ": " + msg + " / " + w.mAttrs.getTitle();
2530 if (where != null) {
2531 Slog.i(TAG, str, where);
2532 } else {
2533 Slog.i(TAG, str);
2534 }
2535 }
2536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2538 long origId = Binder.clearCallingIdentity();
2539 try {
2540 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002541 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002543 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 Surface.openTransaction();
2545 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002546 if (SHOW_TRANSACTIONS) logSurface(w,
2547 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002548 w.mSurface.setTransparentRegionHint(region);
2549 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002550 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 Surface.closeTransaction();
2552 }
2553 }
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(origId);
2557 }
2558 }
2559
2560 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002561 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 Rect visibleInsets) {
2563 long origId = Binder.clearCallingIdentity();
2564 try {
2565 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002566 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 if (w != null) {
2568 w.mGivenInsetsPending = false;
2569 w.mGivenContentInsets.set(contentInsets);
2570 w.mGivenVisibleInsets.set(visibleInsets);
2571 w.mTouchableInsets = touchableInsets;
2572 mLayoutNeeded = true;
2573 performLayoutAndPlaceSurfacesLocked();
2574 }
2575 }
2576 } finally {
2577 Binder.restoreCallingIdentity(origId);
2578 }
2579 }
Romain Guy06882f82009-06-10 13:36:04 -07002580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 public void getWindowDisplayFrame(Session session, IWindow client,
2582 Rect outDisplayFrame) {
2583 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002584 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 if (win == null) {
2586 outDisplayFrame.setEmpty();
2587 return;
2588 }
2589 outDisplayFrame.set(win.mDisplayFrame);
2590 }
2591 }
2592
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002593 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2594 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002595 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2596 window.mWallpaperX = x;
2597 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002598 window.mWallpaperXStep = xStep;
2599 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002600 if (updateWallpaperOffsetLocked(window, true)) {
2601 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002602 }
2603 }
2604 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002605
Dianne Hackborn75804932009-10-20 20:15:20 -07002606 void wallpaperCommandComplete(IBinder window, Bundle result) {
2607 synchronized (mWindowMap) {
2608 if (mWaitingOnWallpaper != null &&
2609 mWaitingOnWallpaper.mClient.asBinder() == window) {
2610 mWaitingOnWallpaper = null;
2611 mWindowMap.notifyAll();
2612 }
2613 }
2614 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002615
Dianne Hackborn75804932009-10-20 20:15:20 -07002616 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2617 String action, int x, int y, int z, Bundle extras, boolean sync) {
2618 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2619 || window == mUpperWallpaperTarget) {
2620 boolean doWait = sync;
2621 int curTokenIndex = mWallpaperTokens.size();
2622 while (curTokenIndex > 0) {
2623 curTokenIndex--;
2624 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2625 int curWallpaperIndex = token.windows.size();
2626 while (curWallpaperIndex > 0) {
2627 curWallpaperIndex--;
2628 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2629 try {
2630 wallpaper.mClient.dispatchWallpaperCommand(action,
2631 x, y, z, extras, sync);
2632 // We only want to be synchronous with one wallpaper.
2633 sync = false;
2634 } catch (RemoteException e) {
2635 }
2636 }
2637 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002638
Dianne Hackborn75804932009-10-20 20:15:20 -07002639 if (doWait) {
2640 // XXX Need to wait for result.
2641 }
2642 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002643
Dianne Hackborn75804932009-10-20 20:15:20 -07002644 return null;
2645 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 public int relayoutWindow(Session session, IWindow client,
2648 WindowManager.LayoutParams attrs, int requestedWidth,
2649 int requestedHeight, int viewVisibility, boolean insetsPending,
2650 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002651 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 boolean displayed = false;
2653 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002654 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002658 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 if (win == null) {
2660 return 0;
2661 }
2662 win.mRequestedWidth = requestedWidth;
2663 win.mRequestedHeight = requestedHeight;
2664
2665 if (attrs != null) {
2666 mPolicy.adjustWindowParamsLw(attrs);
2667 }
Romain Guy06882f82009-06-10 13:36:04 -07002668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 int attrChanges = 0;
2670 int flagChanges = 0;
2671 if (attrs != null) {
2672 flagChanges = win.mAttrs.flags ^= attrs.flags;
2673 attrChanges = win.mAttrs.copyFrom(attrs);
2674 }
2675
Joe Onorato8a9b2202010-02-26 18:56:32 -08002676 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677
2678 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2679 win.mAlpha = attrs.alpha;
2680 }
2681
2682 final boolean scaledWindow =
2683 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2684
2685 if (scaledWindow) {
2686 // requested{Width|Height} Surface's physical size
2687 // attrs.{width|height} Size on screen
2688 win.mHScale = (attrs.width != requestedWidth) ?
2689 (attrs.width / (float)requestedWidth) : 1.0f;
2690 win.mVScale = (attrs.height != requestedHeight) ?
2691 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002692 } else {
2693 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002694 }
2695
2696 boolean imMayMove = (flagChanges&(
2697 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2698 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 boolean focusMayChange = win.mViewVisibility != viewVisibility
2701 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2702 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002703
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002704 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2705 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 win.mRelayoutCalled = true;
2708 final int oldVisibility = win.mViewVisibility;
2709 win.mViewVisibility = viewVisibility;
2710 if (viewVisibility == View.VISIBLE &&
2711 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2712 displayed = !win.isVisibleLw();
2713 if (win.mExiting) {
2714 win.mExiting = false;
2715 win.mAnimation = null;
2716 }
2717 if (win.mDestroying) {
2718 win.mDestroying = false;
2719 mDestroySurface.remove(win);
2720 }
2721 if (oldVisibility == View.GONE) {
2722 win.mEnterAnimationPending = true;
2723 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002724 if (displayed) {
2725 if (win.mSurface != null && !win.mDrawPending
2726 && !win.mCommitDrawPending && !mDisplayFrozen
2727 && mPolicy.isScreenOn()) {
2728 applyEnterAnimationLocked(win);
2729 }
2730 if ((win.mAttrs.flags
2731 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2732 if (DEBUG_VISIBILITY) Slog.v(TAG,
2733 "Relayout window turning screen on: " + win);
2734 win.mTurnOnScreen = true;
2735 }
2736 int diff = 0;
2737 if (win.mConfiguration != mCurConfiguration
2738 && (win.mConfiguration == null
2739 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2740 win.mConfiguration = mCurConfiguration;
2741 if (DEBUG_CONFIGURATION) {
2742 Slog.i(TAG, "Window " + win + " visible with new config: "
2743 + win.mConfiguration + " / 0x"
2744 + Integer.toHexString(diff));
2745 }
2746 outConfig.setTo(mCurConfiguration);
2747 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2750 // To change the format, we need to re-build the surface.
2751 win.destroySurfaceLocked();
2752 displayed = true;
2753 }
2754 try {
2755 Surface surface = win.createSurfaceLocked();
2756 if (surface != null) {
2757 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002758 win.mReportDestroySurface = false;
2759 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002760 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002761 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002763 // For some reason there isn't a surface. Clear the
2764 // caller's object so they see the same state.
2765 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 }
2767 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002768 mInputMonitor.updateInputWindowsLw();
2769
Joe Onorato8a9b2202010-02-26 18:56:32 -08002770 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002771 + client + " (" + win.mAttrs.getTitle() + ")",
2772 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 Binder.restoreCallingIdentity(origId);
2774 return 0;
2775 }
2776 if (displayed) {
2777 focusMayChange = true;
2778 }
2779 if (win.mAttrs.type == TYPE_INPUT_METHOD
2780 && mInputMethodWindow == null) {
2781 mInputMethodWindow = win;
2782 imMayMove = true;
2783 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002784 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2785 && win.mAppToken != null
2786 && win.mAppToken.startingWindow != null) {
2787 // Special handling of starting window over the base
2788 // window of the app: propagate lock screen flags to it,
2789 // to provide the correct semantics while starting.
2790 final int mask =
2791 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002792 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2793 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002794 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2795 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 } else {
2798 win.mEnterAnimationPending = false;
2799 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002800 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002801 + ": mExiting=" + win.mExiting
2802 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 // If we are not currently running the exit animation, we
2804 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002805 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 // Try starting an animation; if there isn't one, we
2807 // can destroy the surface right away.
2808 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2809 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2810 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2811 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002812 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002814 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 } else if (win.isAnimating()) {
2817 // Currently in a hide animation... turn this into
2818 // an exit.
2819 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002820 } else if (win == mWallpaperTarget) {
2821 // If the wallpaper is currently behind this
2822 // window, we need to change both of them inside
2823 // of a transaction to avoid artifacts.
2824 win.mExiting = true;
2825 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 } else {
2827 if (mInputMethodWindow == win) {
2828 mInputMethodWindow = null;
2829 }
2830 win.destroySurfaceLocked();
2831 }
2832 }
2833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002834
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002835 if (win.mSurface == null || (win.getAttrs().flags
2836 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2837 || win.mSurfacePendingDestroy) {
2838 // We are being called from a local process, which
2839 // means outSurface holds its current surface. Ensure the
2840 // surface object is cleared, but we don't want it actually
2841 // destroyed at this point.
2842 win.mSurfacePendingDestroy = false;
2843 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002844 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002845 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002846 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002847 "Keeping surface, will report destroy: " + win);
2848 win.mReportDestroySurface = true;
2849 outSurface.copyFrom(win.mSurface);
2850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002851 }
2852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 if (focusMayChange) {
2854 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2855 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 imMayMove = false;
2857 }
2858 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2859 }
Romain Guy06882f82009-06-10 13:36:04 -07002860
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002861 // updateFocusedWindowLocked() already assigned layers so we only need to
2862 // reassign them at this point if the IM window state gets shuffled
2863 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002866 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2867 // Little hack here -- we -should- be able to rely on the
2868 // function to return true if the IME has moved and needs
2869 // its layer recomputed. However, if the IME was hidden
2870 // and isn't actually moved in the list, its layer may be
2871 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 assignLayers = true;
2873 }
2874 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002875 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002876 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002877 assignLayers = true;
2878 }
2879 }
Romain Guy06882f82009-06-10 13:36:04 -07002880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 mLayoutNeeded = true;
2882 win.mGivenInsetsPending = insetsPending;
2883 if (assignLayers) {
2884 assignLayersLocked();
2885 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002886 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002888 if (displayed && win.mIsWallpaper) {
2889 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002890 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 if (win.mAppToken != null) {
2893 win.mAppToken.updateReportedVisibilityLocked();
2894 }
2895 outFrame.set(win.mFrame);
2896 outContentInsets.set(win.mContentInsets);
2897 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002898 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002900 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 + ", requestedHeight=" + requestedHeight
2902 + ", viewVisibility=" + viewVisibility
2903 + "\nRelayout returning frame=" + outFrame
2904 + ", surface=" + outSurface);
2905
Joe Onorato8a9b2202010-02-26 18:56:32 -08002906 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2908
2909 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002910
2911 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 }
2913
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002914 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 sendNewConfiguration();
2916 }
Romain Guy06882f82009-06-10 13:36:04 -07002917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2921 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2922 }
2923
2924 public void finishDrawingWindow(Session session, IWindow client) {
2925 final long origId = Binder.clearCallingIdentity();
2926 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002927 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002929 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2930 adjustWallpaperWindowsLocked();
2931 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 mLayoutNeeded = true;
2933 performLayoutAndPlaceSurfacesLocked();
2934 }
2935 }
2936 Binder.restoreCallingIdentity(origId);
2937 }
2938
2939 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002940 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 + (lp != null ? lp.packageName : null)
2942 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2943 if (lp != null && lp.windowAnimations != 0) {
2944 // If this is a system resource, don't try to load it from the
2945 // application resources. It is nice to avoid loading application
2946 // resources if we can.
2947 String packageName = lp.packageName != null ? lp.packageName : "android";
2948 int resId = lp.windowAnimations;
2949 if ((resId&0xFF000000) == 0x01000000) {
2950 packageName = "android";
2951 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002952 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 + packageName);
2954 return AttributeCache.instance().get(packageName, resId,
2955 com.android.internal.R.styleable.WindowAnimation);
2956 }
2957 return null;
2958 }
Romain Guy06882f82009-06-10 13:36:04 -07002959
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002960 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002961 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002962 + packageName + " resId=0x" + Integer.toHexString(resId));
2963 if (packageName != null) {
2964 if ((resId&0xFF000000) == 0x01000000) {
2965 packageName = "android";
2966 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002967 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002968 + packageName);
2969 return AttributeCache.instance().get(packageName, resId,
2970 com.android.internal.R.styleable.WindowAnimation);
2971 }
2972 return null;
2973 }
2974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 private void applyEnterAnimationLocked(WindowState win) {
2976 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2977 if (win.mEnterAnimationPending) {
2978 win.mEnterAnimationPending = false;
2979 transit = WindowManagerPolicy.TRANSIT_ENTER;
2980 }
2981
2982 applyAnimationLocked(win, transit, true);
2983 }
2984
2985 private boolean applyAnimationLocked(WindowState win,
2986 int transit, boolean isEntrance) {
2987 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2988 // If we are trying to apply an animation, but already running
2989 // an animation of the same type, then just leave that one alone.
2990 return true;
2991 }
Romain Guy06882f82009-06-10 13:36:04 -07002992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 // Only apply an animation if the display isn't frozen. If it is
2994 // frozen, there is no reason to animate and it can cause strange
2995 // artifacts when we unfreeze the display if some different animation
2996 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002997 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 int anim = mPolicy.selectAnimationLw(win, transit);
2999 int attr = -1;
3000 Animation a = null;
3001 if (anim != 0) {
3002 a = AnimationUtils.loadAnimation(mContext, anim);
3003 } else {
3004 switch (transit) {
3005 case WindowManagerPolicy.TRANSIT_ENTER:
3006 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
3007 break;
3008 case WindowManagerPolicy.TRANSIT_EXIT:
3009 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
3010 break;
3011 case WindowManagerPolicy.TRANSIT_SHOW:
3012 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3013 break;
3014 case WindowManagerPolicy.TRANSIT_HIDE:
3015 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3016 break;
3017 }
3018 if (attr >= 0) {
3019 a = loadAnimation(win.mAttrs, attr);
3020 }
3021 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003022 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3024 + " mAnimation=" + win.mAnimation
3025 + " isEntrance=" + isEntrance);
3026 if (a != null) {
3027 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003028 RuntimeException e = null;
3029 if (!HIDE_STACK_CRAWLS) {
3030 e = new RuntimeException();
3031 e.fillInStackTrace();
3032 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003033 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003034 }
3035 win.setAnimation(a);
3036 win.mAnimationIsEntrance = isEntrance;
3037 }
3038 } else {
3039 win.clearAnimation();
3040 }
3041
3042 return win.mAnimation != null;
3043 }
3044
3045 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3046 int anim = 0;
3047 Context context = mContext;
3048 if (animAttr >= 0) {
3049 AttributeCache.Entry ent = getCachedAnimations(lp);
3050 if (ent != null) {
3051 context = ent.context;
3052 anim = ent.array.getResourceId(animAttr, 0);
3053 }
3054 }
3055 if (anim != 0) {
3056 return AnimationUtils.loadAnimation(context, anim);
3057 }
3058 return null;
3059 }
Romain Guy06882f82009-06-10 13:36:04 -07003060
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003061 private Animation loadAnimation(String packageName, int resId) {
3062 int anim = 0;
3063 Context context = mContext;
3064 if (resId >= 0) {
3065 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3066 if (ent != null) {
3067 context = ent.context;
3068 anim = resId;
3069 }
3070 }
3071 if (anim != 0) {
3072 return AnimationUtils.loadAnimation(context, anim);
3073 }
3074 return null;
3075 }
3076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 private boolean applyAnimationLocked(AppWindowToken wtoken,
3078 WindowManager.LayoutParams lp, int transit, boolean enter) {
3079 // Only apply an animation if the display isn't frozen. If it is
3080 // frozen, there is no reason to animate and it can cause strange
3081 // artifacts when we unfreeze the display if some different animation
3082 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003083 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003084 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003085 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003086 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003087 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003088 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003089 } else if (mNextAppTransitionPackage != null) {
3090 a = loadAnimation(mNextAppTransitionPackage, enter ?
3091 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003092 } else {
3093 int animAttr = 0;
3094 switch (transit) {
3095 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3096 animAttr = enter
3097 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3098 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3099 break;
3100 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3101 animAttr = enter
3102 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3103 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3104 break;
3105 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3106 animAttr = enter
3107 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3108 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3109 break;
3110 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3111 animAttr = enter
3112 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3113 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3114 break;
3115 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3116 animAttr = enter
3117 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3118 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3119 break;
3120 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3121 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003122 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003123 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3124 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003125 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003126 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003127 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3128 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003129 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003130 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003131 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003132 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3133 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3134 break;
3135 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3136 animAttr = enter
3137 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3138 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3139 break;
3140 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3141 animAttr = enter
3142 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3143 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003144 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003145 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003146 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003147 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003148 + " anim=" + a
3149 + " animAttr=0x" + Integer.toHexString(animAttr)
3150 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 if (a != null) {
3153 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003154 RuntimeException e = null;
3155 if (!HIDE_STACK_CRAWLS) {
3156 e = new RuntimeException();
3157 e.fillInStackTrace();
3158 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003159 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 }
3161 wtoken.setAnimation(a);
3162 }
3163 } else {
3164 wtoken.clearAnimation();
3165 }
3166
3167 return wtoken.animation != null;
3168 }
3169
3170 // -------------------------------------------------------------
3171 // Application Window Tokens
3172 // -------------------------------------------------------------
3173
3174 public void validateAppTokens(List tokens) {
3175 int v = tokens.size()-1;
3176 int m = mAppTokens.size()-1;
3177 while (v >= 0 && m >= 0) {
3178 AppWindowToken wtoken = mAppTokens.get(m);
3179 if (wtoken.removed) {
3180 m--;
3181 continue;
3182 }
3183 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003184 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3186 }
3187 v--;
3188 m--;
3189 }
3190 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003191 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 v--;
3193 }
3194 while (m >= 0) {
3195 AppWindowToken wtoken = mAppTokens.get(m);
3196 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003197 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 }
3199 m--;
3200 }
3201 }
3202
3203 boolean checkCallingPermission(String permission, String func) {
3204 // Quick check: if the calling permission is me, it's all okay.
3205 if (Binder.getCallingPid() == Process.myPid()) {
3206 return true;
3207 }
Romain Guy06882f82009-06-10 13:36:04 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 if (mContext.checkCallingPermission(permission)
3210 == PackageManager.PERMISSION_GRANTED) {
3211 return true;
3212 }
3213 String msg = "Permission Denial: " + func + " from pid="
3214 + Binder.getCallingPid()
3215 + ", uid=" + Binder.getCallingUid()
3216 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003217 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 return false;
3219 }
Romain Guy06882f82009-06-10 13:36:04 -07003220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 AppWindowToken findAppWindowToken(IBinder token) {
3222 WindowToken wtoken = mTokenMap.get(token);
3223 if (wtoken == null) {
3224 return null;
3225 }
3226 return wtoken.appWindowToken;
3227 }
Romain Guy06882f82009-06-10 13:36:04 -07003228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 public void addWindowToken(IBinder token, int type) {
3230 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3231 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003232 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 }
Romain Guy06882f82009-06-10 13:36:04 -07003234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 synchronized(mWindowMap) {
3236 WindowToken wtoken = mTokenMap.get(token);
3237 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003238 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 return;
3240 }
3241 wtoken = new WindowToken(token, type, true);
3242 mTokenMap.put(token, wtoken);
3243 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003244 if (type == TYPE_WALLPAPER) {
3245 mWallpaperTokens.add(wtoken);
3246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247 }
3248 }
Romain Guy06882f82009-06-10 13:36:04 -07003249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 public void removeWindowToken(IBinder token) {
3251 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3252 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003253 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 }
3255
3256 final long origId = Binder.clearCallingIdentity();
3257 synchronized(mWindowMap) {
3258 WindowToken wtoken = mTokenMap.remove(token);
3259 mTokenList.remove(wtoken);
3260 if (wtoken != null) {
3261 boolean delayed = false;
3262 if (!wtoken.hidden) {
3263 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 final int N = wtoken.windows.size();
3266 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 for (int i=0; i<N; i++) {
3269 WindowState win = wtoken.windows.get(i);
3270
3271 if (win.isAnimating()) {
3272 delayed = true;
3273 }
Romain Guy06882f82009-06-10 13:36:04 -07003274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 if (win.isVisibleNow()) {
3276 applyAnimationLocked(win,
3277 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 changed = true;
3279 }
3280 }
3281
3282 if (changed) {
3283 mLayoutNeeded = true;
3284 performLayoutAndPlaceSurfacesLocked();
3285 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3286 }
Romain Guy06882f82009-06-10 13:36:04 -07003287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 if (delayed) {
3289 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003290 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3291 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 }
3293 }
Romain Guy06882f82009-06-10 13:36:04 -07003294
Jeff Brownc5ed5912010-07-14 18:48:53 -07003295 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003297 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 }
3299 }
3300 Binder.restoreCallingIdentity(origId);
3301 }
3302
3303 public void addAppToken(int addPos, IApplicationToken token,
3304 int groupId, int requestedOrientation, boolean fullscreen) {
3305 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3306 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003307 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 }
Jeff Brown349703e2010-06-22 01:27:15 -07003309
3310 // Get the dispatching timeout here while we are not holding any locks so that it
3311 // can be cached by the AppWindowToken. The timeout value is used later by the
3312 // input dispatcher in code that does hold locks. If we did not cache the value
3313 // here we would run the chance of introducing a deadlock between the window manager
3314 // (which holds locks while updating the input dispatcher state) and the activity manager
3315 // (which holds locks while querying the application token).
3316 long inputDispatchingTimeoutNanos;
3317 try {
3318 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3319 } catch (RemoteException ex) {
3320 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3321 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3322 }
Romain Guy06882f82009-06-10 13:36:04 -07003323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 synchronized(mWindowMap) {
3325 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3326 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003327 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 return;
3329 }
3330 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003331 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 wtoken.groupId = groupId;
3333 wtoken.appFullscreen = fullscreen;
3334 wtoken.requestedOrientation = requestedOrientation;
3335 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003336 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 mTokenMap.put(token.asBinder(), wtoken);
3338 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 // Application tokens start out hidden.
3341 wtoken.hidden = true;
3342 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 //dump();
3345 }
3346 }
Romain Guy06882f82009-06-10 13:36:04 -07003347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 public void setAppGroupId(IBinder token, int groupId) {
3349 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3350 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003351 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 }
3353
3354 synchronized(mWindowMap) {
3355 AppWindowToken wtoken = findAppWindowToken(token);
3356 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003357 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 return;
3359 }
3360 wtoken.groupId = groupId;
3361 }
3362 }
Romain Guy06882f82009-06-10 13:36:04 -07003363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 public int getOrientationFromWindowsLocked() {
3365 int pos = mWindows.size() - 1;
3366 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003367 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 pos--;
3369 if (wtoken.mAppToken != null) {
3370 // We hit an application window. so the orientation will be determined by the
3371 // app window. No point in continuing further.
3372 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3373 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003374 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 continue;
3376 }
3377 int req = wtoken.mAttrs.screenOrientation;
3378 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3379 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3380 continue;
3381 } else {
3382 return req;
3383 }
3384 }
3385 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3386 }
Romain Guy06882f82009-06-10 13:36:04 -07003387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003389 int pos = mAppTokens.size() - 1;
3390 int curGroup = 0;
3391 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3392 boolean findingBehind = false;
3393 boolean haveGroup = false;
3394 boolean lastFullscreen = false;
3395 while (pos >= 0) {
3396 AppWindowToken wtoken = mAppTokens.get(pos);
3397 pos--;
3398 // if we're about to tear down this window and not seek for
3399 // the behind activity, don't use it for orientation
3400 if (!findingBehind
3401 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3402 continue;
3403 }
3404
3405 if (!haveGroup) {
3406 // We ignore any hidden applications on the top.
3407 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003408 continue;
3409 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003410 haveGroup = true;
3411 curGroup = wtoken.groupId;
3412 lastOrientation = wtoken.requestedOrientation;
3413 } else if (curGroup != wtoken.groupId) {
3414 // If we have hit a new application group, and the bottom
3415 // of the previous group didn't explicitly say to use
3416 // the orientation behind it, and the last app was
3417 // full screen, then we'll stick with the
3418 // user's orientation.
3419 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3420 && lastFullscreen) {
3421 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003424 int or = wtoken.requestedOrientation;
3425 // If this application is fullscreen, and didn't explicitly say
3426 // to use the orientation behind it, then just take whatever
3427 // orientation it has and ignores whatever is under it.
3428 lastFullscreen = wtoken.appFullscreen;
3429 if (lastFullscreen
3430 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3431 return or;
3432 }
3433 // If this application has requested an explicit orientation,
3434 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003435 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3436 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003437 return or;
3438 }
3439 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3440 }
3441 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003442 }
Romain Guy06882f82009-06-10 13:36:04 -07003443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003445 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003446 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3447 "updateOrientationFromAppTokens()")) {
3448 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3449 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003450
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003451 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003453
3454 synchronized(mWindowMap) {
3455 if (updateOrientationFromAppTokensLocked()) {
3456 if (freezeThisOneIfNeeded != null) {
3457 AppWindowToken wtoken = findAppWindowToken(
3458 freezeThisOneIfNeeded);
3459 if (wtoken != null) {
3460 startAppFreezingScreenLocked(wtoken,
3461 ActivityInfo.CONFIG_ORIENTATION);
3462 }
3463 }
3464 config = computeNewConfigurationLocked();
3465
3466 } else if (currentConfig != null) {
3467 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003468 // state mismatches the activity manager's, update it,
3469 // disregarding font scale, which should remain set to
3470 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003471 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003472 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003473 if (computeNewConfigurationLocked(mTempConfiguration)) {
3474 if (currentConfig.diff(mTempConfiguration) != 0) {
3475 mWaitingForConfig = true;
3476 mLayoutNeeded = true;
3477 startFreezingDisplayLocked();
3478 config = new Configuration(mTempConfiguration);
3479 }
3480 }
3481 }
3482 }
3483
Dianne Hackborncfaef692009-06-15 14:24:44 -07003484 Binder.restoreCallingIdentity(ident);
3485 return config;
3486 }
3487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003489 * Determine the new desired orientation of the display, returning
3490 * a non-null new Configuration if it has changed from the current
3491 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3492 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3493 * SCREEN. This will typically be done for you if you call
3494 * sendNewConfiguration().
3495 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 * The orientation is computed from non-application windows first. If none of
3497 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003498 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003499 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3500 * android.os.IBinder)
3501 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003502 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003503 if (mDisplayFrozen) {
3504 // If the display is frozen, some activities may be in the middle
3505 // of restarting, and thus have removed their old window. If the
3506 // window has the flag to hide the lock screen, then the lock screen
3507 // can re-appear and inflict its own orientation on us. Keep the
3508 // orientation stable until this all settles down.
3509 return false;
3510 }
3511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 long ident = Binder.clearCallingIdentity();
3514 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003515 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 mForcedAppOrientation = req;
3519 //send a message to Policy indicating orientation change to take
3520 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003521 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003522 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3523 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3524 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003525 }
3526 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003527
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003528 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 } finally {
3530 Binder.restoreCallingIdentity(ident);
3531 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 }
Romain Guy06882f82009-06-10 13:36:04 -07003533
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003534 int computeForcedAppOrientationLocked() {
3535 int req = getOrientationFromWindowsLocked();
3536 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3537 req = getOrientationFromAppTokensLocked();
3538 }
3539 return req;
3540 }
Romain Guy06882f82009-06-10 13:36:04 -07003541
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003542 public void setNewConfiguration(Configuration config) {
3543 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3544 "setNewConfiguration()")) {
3545 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3546 }
3547
3548 synchronized(mWindowMap) {
3549 mCurConfiguration = new Configuration(config);
3550 mWaitingForConfig = false;
3551 performLayoutAndPlaceSurfacesLocked();
3552 }
3553 }
3554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003555 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3556 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3557 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003558 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 }
Romain Guy06882f82009-06-10 13:36:04 -07003560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 synchronized(mWindowMap) {
3562 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3563 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003564 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003565 return;
3566 }
Romain Guy06882f82009-06-10 13:36:04 -07003567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 wtoken.requestedOrientation = requestedOrientation;
3569 }
3570 }
Romain Guy06882f82009-06-10 13:36:04 -07003571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 public int getAppOrientation(IApplicationToken token) {
3573 synchronized(mWindowMap) {
3574 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3575 if (wtoken == null) {
3576 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3577 }
Romain Guy06882f82009-06-10 13:36:04 -07003578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 return wtoken.requestedOrientation;
3580 }
3581 }
Romain Guy06882f82009-06-10 13:36:04 -07003582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3584 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3585 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003586 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 }
3588
3589 synchronized(mWindowMap) {
3590 boolean changed = false;
3591 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003592 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 changed = mFocusedApp != null;
3594 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003595 if (changed) {
3596 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003597 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 } else {
3599 AppWindowToken newFocus = findAppWindowToken(token);
3600 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003601 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 return;
3603 }
3604 changed = mFocusedApp != newFocus;
3605 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003606 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003607 if (changed) {
3608 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003609 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 }
3611
3612 if (moveFocusNow && changed) {
3613 final long origId = Binder.clearCallingIdentity();
3614 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3615 Binder.restoreCallingIdentity(origId);
3616 }
3617 }
3618 }
3619
3620 public void prepareAppTransition(int transit) {
3621 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3622 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003623 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 }
Romain Guy06882f82009-06-10 13:36:04 -07003625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003627 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 TAG, "Prepare app transition: transit=" + transit
3629 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003630 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003631 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3632 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003634 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3635 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3636 // Opening a new task always supersedes a close for the anim.
3637 mNextAppTransition = transit;
3638 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3639 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3640 // Opening a new activity always supersedes a close for the anim.
3641 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 }
3643 mAppTransitionReady = false;
3644 mAppTransitionTimeout = false;
3645 mStartingIconInTransition = false;
3646 mSkipAppTransitionAnimation = false;
3647 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3648 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3649 5000);
3650 }
3651 }
3652 }
3653
3654 public int getPendingAppTransition() {
3655 return mNextAppTransition;
3656 }
Romain Guy06882f82009-06-10 13:36:04 -07003657
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003658 public void overridePendingAppTransition(String packageName,
3659 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003660 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003661 mNextAppTransitionPackage = packageName;
3662 mNextAppTransitionEnter = enterAnim;
3663 mNextAppTransitionExit = exitAnim;
3664 }
3665 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 public void executeAppTransition() {
3668 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3669 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003670 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 }
Romain Guy06882f82009-06-10 13:36:04 -07003672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003674 if (DEBUG_APP_TRANSITIONS) {
3675 RuntimeException e = new RuntimeException("here");
3676 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003677 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003678 + mNextAppTransition, e);
3679 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003680 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 mAppTransitionReady = true;
3682 final long origId = Binder.clearCallingIdentity();
3683 performLayoutAndPlaceSurfacesLocked();
3684 Binder.restoreCallingIdentity(origId);
3685 }
3686 }
3687 }
3688
3689 public void setAppStartingWindow(IBinder token, String pkg,
3690 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3691 IBinder transferFrom, boolean createIfNeeded) {
3692 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3693 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003694 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 }
3696
3697 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003698 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3700 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702 AppWindowToken wtoken = findAppWindowToken(token);
3703 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003704 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003705 return;
3706 }
3707
3708 // If the display is frozen, we won't do anything until the
3709 // actual window is displayed so there is no reason to put in
3710 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003711 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 return;
3713 }
Romain Guy06882f82009-06-10 13:36:04 -07003714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 if (wtoken.startingData != null) {
3716 return;
3717 }
Romain Guy06882f82009-06-10 13:36:04 -07003718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 if (transferFrom != null) {
3720 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3721 if (ttoken != null) {
3722 WindowState startingWindow = ttoken.startingWindow;
3723 if (startingWindow != null) {
3724 if (mStartingIconInTransition) {
3725 // In this case, the starting icon has already
3726 // been displayed, so start letting windows get
3727 // shown immediately without any more transitions.
3728 mSkipAppTransitionAnimation = true;
3729 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003730 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 "Moving existing starting from " + ttoken
3732 + " to " + wtoken);
3733 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 // Transfer the starting window over to the new
3736 // token.
3737 wtoken.startingData = ttoken.startingData;
3738 wtoken.startingView = ttoken.startingView;
3739 wtoken.startingWindow = startingWindow;
3740 ttoken.startingData = null;
3741 ttoken.startingView = null;
3742 ttoken.startingWindow = null;
3743 ttoken.startingMoved = true;
3744 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003745 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003747 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003748 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003750 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 ttoken.windows.remove(startingWindow);
3752 ttoken.allAppWindows.remove(startingWindow);
3753 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 // Propagate other interesting state between the
3756 // tokens. If the old token is displayed, we should
3757 // immediately force the new one to be displayed. If
3758 // it is animating, we need to move that animation to
3759 // the new one.
3760 if (ttoken.allDrawn) {
3761 wtoken.allDrawn = true;
3762 }
3763 if (ttoken.firstWindowDrawn) {
3764 wtoken.firstWindowDrawn = true;
3765 }
3766 if (!ttoken.hidden) {
3767 wtoken.hidden = false;
3768 wtoken.hiddenRequested = false;
3769 wtoken.willBeHidden = false;
3770 }
3771 if (wtoken.clientHidden != ttoken.clientHidden) {
3772 wtoken.clientHidden = ttoken.clientHidden;
3773 wtoken.sendAppVisibilityToClients();
3774 }
3775 if (ttoken.animation != null) {
3776 wtoken.animation = ttoken.animation;
3777 wtoken.animating = ttoken.animating;
3778 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3779 ttoken.animation = null;
3780 ttoken.animLayerAdjustment = 0;
3781 wtoken.updateLayers();
3782 ttoken.updateLayers();
3783 }
Romain Guy06882f82009-06-10 13:36:04 -07003784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003785 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 mLayoutNeeded = true;
3787 performLayoutAndPlaceSurfacesLocked();
3788 Binder.restoreCallingIdentity(origId);
3789 return;
3790 } else if (ttoken.startingData != null) {
3791 // The previous app was getting ready to show a
3792 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003793 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 "Moving pending starting from " + ttoken
3795 + " to " + wtoken);
3796 wtoken.startingData = ttoken.startingData;
3797 ttoken.startingData = null;
3798 ttoken.startingMoved = true;
3799 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3800 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3801 // want to process the message ASAP, before any other queued
3802 // messages.
3803 mH.sendMessageAtFrontOfQueue(m);
3804 return;
3805 }
3806 }
3807 }
3808
3809 // There is no existing starting window, and the caller doesn't
3810 // want us to create one, so that's it!
3811 if (!createIfNeeded) {
3812 return;
3813 }
Romain Guy06882f82009-06-10 13:36:04 -07003814
Dianne Hackborn284ac932009-08-28 10:34:25 -07003815 // If this is a translucent or wallpaper window, then don't
3816 // show a starting window -- the current effect (a full-screen
3817 // opaque starting window that fades away to the real contents
3818 // when it is ready) does not work for this.
3819 if (theme != 0) {
3820 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3821 com.android.internal.R.styleable.Window);
3822 if (ent.array.getBoolean(
3823 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3824 return;
3825 }
3826 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003827 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3828 return;
3829 }
3830 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003831 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3832 return;
3833 }
3834 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 mStartingIconInTransition = true;
3837 wtoken.startingData = new StartingData(
3838 pkg, theme, nonLocalizedLabel,
3839 labelRes, icon);
3840 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3841 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3842 // want to process the message ASAP, before any other queued
3843 // messages.
3844 mH.sendMessageAtFrontOfQueue(m);
3845 }
3846 }
3847
3848 public void setAppWillBeHidden(IBinder token) {
3849 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3850 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003851 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 }
3853
3854 AppWindowToken wtoken;
3855
3856 synchronized(mWindowMap) {
3857 wtoken = findAppWindowToken(token);
3858 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003859 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 -08003860 return;
3861 }
3862 wtoken.willBeHidden = true;
3863 }
3864 }
Romain Guy06882f82009-06-10 13:36:04 -07003865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003866 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3867 boolean visible, int transit, boolean performLayout) {
3868 boolean delayed = false;
3869
3870 if (wtoken.clientHidden == visible) {
3871 wtoken.clientHidden = !visible;
3872 wtoken.sendAppVisibilityToClients();
3873 }
Romain Guy06882f82009-06-10 13:36:04 -07003874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 wtoken.willBeHidden = false;
3876 if (wtoken.hidden == visible) {
3877 final int N = wtoken.allAppWindows.size();
3878 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003879 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3881 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003884
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003885 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 if (wtoken.animation == sDummyAnimation) {
3887 wtoken.animation = null;
3888 }
3889 applyAnimationLocked(wtoken, lp, transit, visible);
3890 changed = true;
3891 if (wtoken.animation != null) {
3892 delayed = runningAppAnimation = true;
3893 }
3894 }
Romain Guy06882f82009-06-10 13:36:04 -07003895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 for (int i=0; i<N; i++) {
3897 WindowState win = wtoken.allAppWindows.get(i);
3898 if (win == wtoken.startingWindow) {
3899 continue;
3900 }
3901
3902 if (win.isAnimating()) {
3903 delayed = true;
3904 }
Romain Guy06882f82009-06-10 13:36:04 -07003905
Joe Onorato8a9b2202010-02-26 18:56:32 -08003906 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 //win.dump(" ");
3908 if (visible) {
3909 if (!win.isVisibleNow()) {
3910 if (!runningAppAnimation) {
3911 applyAnimationLocked(win,
3912 WindowManagerPolicy.TRANSIT_ENTER, true);
3913 }
3914 changed = true;
3915 }
3916 } else if (win.isVisibleNow()) {
3917 if (!runningAppAnimation) {
3918 applyAnimationLocked(win,
3919 WindowManagerPolicy.TRANSIT_EXIT, false);
3920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 changed = true;
3922 }
3923 }
3924
3925 wtoken.hidden = wtoken.hiddenRequested = !visible;
3926 if (!visible) {
3927 unsetAppFreezingScreenLocked(wtoken, true, true);
3928 } else {
3929 // If we are being set visible, and the starting window is
3930 // not yet displayed, then make sure it doesn't get displayed.
3931 WindowState swin = wtoken.startingWindow;
3932 if (swin != null && (swin.mDrawPending
3933 || swin.mCommitDrawPending)) {
3934 swin.mPolicyVisibility = false;
3935 swin.mPolicyVisibilityAfterAnim = false;
3936 }
3937 }
Romain Guy06882f82009-06-10 13:36:04 -07003938
Joe Onorato8a9b2202010-02-26 18:56:32 -08003939 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3941 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003942
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003943 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003945 if (performLayout) {
3946 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3947 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003948 } else {
3949 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003951 }
3952 }
3953
3954 if (wtoken.animation != null) {
3955 delayed = true;
3956 }
Romain Guy06882f82009-06-10 13:36:04 -07003957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 return delayed;
3959 }
3960
3961 public void setAppVisibility(IBinder token, boolean visible) {
3962 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3963 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003964 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 }
3966
3967 AppWindowToken wtoken;
3968
3969 synchronized(mWindowMap) {
3970 wtoken = findAppWindowToken(token);
3971 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003972 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 return;
3974 }
3975
3976 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003977 RuntimeException e = null;
3978 if (!HIDE_STACK_CRAWLS) {
3979 e = new RuntimeException();
3980 e.fillInStackTrace();
3981 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003982 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 + "): mNextAppTransition=" + mNextAppTransition
3984 + " hidden=" + wtoken.hidden
3985 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3986 }
Romain Guy06882f82009-06-10 13:36:04 -07003987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 // If we are preparing an app transition, then delay changing
3989 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003990 if (!mDisplayFrozen && mPolicy.isScreenOn()
3991 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 // Already in requested state, don't do anything more.
3993 if (wtoken.hiddenRequested != visible) {
3994 return;
3995 }
3996 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003997
Joe Onorato8a9b2202010-02-26 18:56:32 -08003998 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 TAG, "Setting dummy animation on: " + wtoken);
4000 wtoken.setDummyAnimation();
4001 mOpeningApps.remove(wtoken);
4002 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004003 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 wtoken.inPendingTransaction = true;
4005 if (visible) {
4006 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 wtoken.startingDisplayed = false;
4008 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004009
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004010 // If the token is currently hidden (should be the
4011 // common case), then we need to set up to wait for
4012 // its windows to be ready.
4013 if (wtoken.hidden) {
4014 wtoken.allDrawn = false;
4015 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004016
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004017 if (wtoken.clientHidden) {
4018 // In the case where we are making an app visible
4019 // but holding off for a transition, we still need
4020 // to tell the client to make its windows visible so
4021 // they get drawn. Otherwise, we will wait on
4022 // performing the transition until all windows have
4023 // been drawn, they never will be, and we are sad.
4024 wtoken.clientHidden = false;
4025 wtoken.sendAppVisibilityToClients();
4026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004027 }
4028 } else {
4029 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004030
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004031 // If the token is currently visible (should be the
4032 // common case), then set up to wait for it to be hidden.
4033 if (!wtoken.hidden) {
4034 wtoken.waitingToHide = true;
4035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004036 }
4037 return;
4038 }
Romain Guy06882f82009-06-10 13:36:04 -07004039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004041 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004042 wtoken.updateReportedVisibilityLocked();
4043 Binder.restoreCallingIdentity(origId);
4044 }
4045 }
4046
4047 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4048 boolean unfreezeSurfaceNow, boolean force) {
4049 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004050 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004051 + " force=" + force);
4052 final int N = wtoken.allAppWindows.size();
4053 boolean unfrozeWindows = false;
4054 for (int i=0; i<N; i++) {
4055 WindowState w = wtoken.allAppWindows.get(i);
4056 if (w.mAppFreezing) {
4057 w.mAppFreezing = false;
4058 if (w.mSurface != null && !w.mOrientationChanging) {
4059 w.mOrientationChanging = true;
4060 }
4061 unfrozeWindows = true;
4062 }
4063 }
4064 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004065 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 wtoken.freezingScreen = false;
4067 mAppsFreezingScreen--;
4068 }
4069 if (unfreezeSurfaceNow) {
4070 if (unfrozeWindows) {
4071 mLayoutNeeded = true;
4072 performLayoutAndPlaceSurfacesLocked();
4073 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004074 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 }
4076 }
4077 }
Romain Guy06882f82009-06-10 13:36:04 -07004078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4080 int configChanges) {
4081 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004082 RuntimeException e = null;
4083 if (!HIDE_STACK_CRAWLS) {
4084 e = new RuntimeException();
4085 e.fillInStackTrace();
4086 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004087 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 + ": hidden=" + wtoken.hidden + " freezing="
4089 + wtoken.freezingScreen, e);
4090 }
4091 if (!wtoken.hiddenRequested) {
4092 if (!wtoken.freezingScreen) {
4093 wtoken.freezingScreen = true;
4094 mAppsFreezingScreen++;
4095 if (mAppsFreezingScreen == 1) {
4096 startFreezingDisplayLocked();
4097 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4098 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4099 5000);
4100 }
4101 }
4102 final int N = wtoken.allAppWindows.size();
4103 for (int i=0; i<N; i++) {
4104 WindowState w = wtoken.allAppWindows.get(i);
4105 w.mAppFreezing = true;
4106 }
4107 }
4108 }
Romain Guy06882f82009-06-10 13:36:04 -07004109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 public void startAppFreezingScreen(IBinder token, int configChanges) {
4111 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4112 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004113 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 }
4115
4116 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004117 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004118 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 return;
4120 }
Romain Guy06882f82009-06-10 13:36:04 -07004121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004122 AppWindowToken wtoken = findAppWindowToken(token);
4123 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004124 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 return;
4126 }
4127 final long origId = Binder.clearCallingIdentity();
4128 startAppFreezingScreenLocked(wtoken, configChanges);
4129 Binder.restoreCallingIdentity(origId);
4130 }
4131 }
Romain Guy06882f82009-06-10 13:36:04 -07004132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 public void stopAppFreezingScreen(IBinder token, boolean force) {
4134 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4135 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004136 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004137 }
4138
4139 synchronized(mWindowMap) {
4140 AppWindowToken wtoken = findAppWindowToken(token);
4141 if (wtoken == null || wtoken.appToken == null) {
4142 return;
4143 }
4144 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004145 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004146 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4147 unsetAppFreezingScreenLocked(wtoken, true, force);
4148 Binder.restoreCallingIdentity(origId);
4149 }
4150 }
Romain Guy06882f82009-06-10 13:36:04 -07004151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 public void removeAppToken(IBinder token) {
4153 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4154 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004155 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004156 }
4157
4158 AppWindowToken wtoken = null;
4159 AppWindowToken startingToken = null;
4160 boolean delayed = false;
4161
4162 final long origId = Binder.clearCallingIdentity();
4163 synchronized(mWindowMap) {
4164 WindowToken basewtoken = mTokenMap.remove(token);
4165 mTokenList.remove(basewtoken);
4166 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004167 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004168 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 wtoken.inPendingTransaction = false;
4170 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004171 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 if (mClosingApps.contains(wtoken)) {
4173 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004174 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004176 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 delayed = true;
4178 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004179 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180 TAG, "Removing app " + wtoken + " delayed=" + delayed
4181 + " animation=" + wtoken.animation
4182 + " animating=" + wtoken.animating);
4183 if (delayed) {
4184 // set the token aside because it has an active animation to be finished
4185 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004186 } else {
4187 // Make sure there is no animation running on this token,
4188 // so any windows associated with it will be removed as
4189 // soon as their animations are complete
4190 wtoken.animation = null;
4191 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 }
4193 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004194 if (mLastEnterAnimToken == wtoken) {
4195 mLastEnterAnimToken = null;
4196 mLastEnterAnimParams = null;
4197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004198 wtoken.removed = true;
4199 if (wtoken.startingData != null) {
4200 startingToken = wtoken;
4201 }
4202 unsetAppFreezingScreenLocked(wtoken, true, true);
4203 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004204 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 mFocusedApp = null;
4206 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004207 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 }
4209 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004210 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 }
Romain Guy06882f82009-06-10 13:36:04 -07004212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213 if (!delayed && wtoken != null) {
4214 wtoken.updateReportedVisibilityLocked();
4215 }
4216 }
4217 Binder.restoreCallingIdentity(origId);
4218
4219 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004220 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 + startingToken + ": app token removed");
4222 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4223 mH.sendMessage(m);
4224 }
4225 }
4226
4227 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4228 final int NW = token.windows.size();
4229 for (int i=0; i<NW; i++) {
4230 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004231 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004232 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004233 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004234 int j = win.mChildWindows.size();
4235 while (j > 0) {
4236 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004237 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004238 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004239 "Tmp removing child window " + cwin);
4240 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004241 }
4242 }
4243 return NW > 0;
4244 }
4245
4246 void dumpAppTokensLocked() {
4247 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004248 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 }
4250 }
Romain Guy06882f82009-06-10 13:36:04 -07004251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 void dumpWindowsLocked() {
4253 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004254 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 }
4256 }
Romain Guy06882f82009-06-10 13:36:04 -07004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 private int findWindowOffsetLocked(int tokenPos) {
4259 final int NW = mWindows.size();
4260
4261 if (tokenPos >= mAppTokens.size()) {
4262 int i = NW;
4263 while (i > 0) {
4264 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004265 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 if (win.getAppToken() != null) {
4267 return i+1;
4268 }
4269 }
4270 }
4271
4272 while (tokenPos > 0) {
4273 // Find the first app token below the new position that has
4274 // a window displayed.
4275 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004276 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004278 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004279 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004280 "Skipping token -- currently sending to bottom");
4281 tokenPos--;
4282 continue;
4283 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004284 int i = wtoken.windows.size();
4285 while (i > 0) {
4286 i--;
4287 WindowState win = wtoken.windows.get(i);
4288 int j = win.mChildWindows.size();
4289 while (j > 0) {
4290 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004291 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004292 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 for (int pos=NW-1; pos>=0; pos--) {
4294 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004295 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 "Found child win @" + (pos+1));
4297 return pos+1;
4298 }
4299 }
4300 }
4301 }
4302 for (int pos=NW-1; pos>=0; pos--) {
4303 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004304 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 return pos+1;
4306 }
4307 }
4308 }
4309 tokenPos--;
4310 }
4311
4312 return 0;
4313 }
4314
4315 private final int reAddWindowLocked(int index, WindowState win) {
4316 final int NCW = win.mChildWindows.size();
4317 boolean added = false;
4318 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004319 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004321 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004322 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 mWindows.add(index, win);
4324 index++;
4325 added = true;
4326 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004327 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004328 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 mWindows.add(index, cwin);
4330 index++;
4331 }
4332 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004333 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004334 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 mWindows.add(index, win);
4336 index++;
4337 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004338 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 return index;
4340 }
Romain Guy06882f82009-06-10 13:36:04 -07004341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4343 final int NW = token.windows.size();
4344 for (int i=0; i<NW; i++) {
4345 index = reAddWindowLocked(index, token.windows.get(i));
4346 }
4347 return index;
4348 }
4349
4350 public void moveAppToken(int index, IBinder token) {
4351 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4352 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004353 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 }
4355
4356 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004357 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 if (DEBUG_REORDER) dumpAppTokensLocked();
4359 final AppWindowToken wtoken = findAppWindowToken(token);
4360 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004361 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 + token + " (" + wtoken + ")");
4363 return;
4364 }
4365 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004366 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004370 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004371 if (DEBUG_REORDER) dumpWindowsLocked();
4372 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004373 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004374 if (DEBUG_REORDER) dumpWindowsLocked();
4375 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004376 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004377 if (DEBUG_REORDER) dumpWindowsLocked();
4378 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 mLayoutNeeded = true;
4380 performLayoutAndPlaceSurfacesLocked();
4381 }
4382 Binder.restoreCallingIdentity(origId);
4383 }
4384 }
4385
4386 private void removeAppTokensLocked(List<IBinder> tokens) {
4387 // XXX This should be done more efficiently!
4388 // (take advantage of the fact that both lists should be
4389 // ordered in the same way.)
4390 int N = tokens.size();
4391 for (int i=0; i<N; i++) {
4392 IBinder token = tokens.get(i);
4393 final AppWindowToken wtoken = findAppWindowToken(token);
4394 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004395 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 + token + " (" + wtoken + ")");
4397 i--;
4398 N--;
4399 }
4400 }
4401 }
4402
Dianne Hackborna8f60182009-09-01 19:01:50 -07004403 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4404 boolean updateFocusAndLayout) {
4405 // First remove all of the windows from the list.
4406 tmpRemoveAppWindowsLocked(wtoken);
4407
4408 // Where to start adding?
4409 int pos = findWindowOffsetLocked(tokenPos);
4410
4411 // And now add them back at the correct place.
4412 pos = reAddAppWindowsLocked(pos, wtoken);
4413
4414 if (updateFocusAndLayout) {
4415 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4416 assignLayersLocked();
4417 }
4418 mLayoutNeeded = true;
4419 performLayoutAndPlaceSurfacesLocked();
4420 }
4421 }
4422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4424 // First remove all of the windows from the list.
4425 final int N = tokens.size();
4426 int i;
4427 for (i=0; i<N; i++) {
4428 WindowToken token = mTokenMap.get(tokens.get(i));
4429 if (token != null) {
4430 tmpRemoveAppWindowsLocked(token);
4431 }
4432 }
4433
4434 // Where to start adding?
4435 int pos = findWindowOffsetLocked(tokenPos);
4436
4437 // And now add them back at the correct place.
4438 for (i=0; i<N; i++) {
4439 WindowToken token = mTokenMap.get(tokens.get(i));
4440 if (token != null) {
4441 pos = reAddAppWindowsLocked(pos, token);
4442 }
4443 }
4444
Dianne Hackborna8f60182009-09-01 19:01:50 -07004445 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4446 assignLayersLocked();
4447 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 mLayoutNeeded = true;
4449 performLayoutAndPlaceSurfacesLocked();
4450
4451 //dump();
4452 }
4453
4454 public void moveAppTokensToTop(List<IBinder> tokens) {
4455 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4456 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004457 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 }
4459
4460 final long origId = Binder.clearCallingIdentity();
4461 synchronized(mWindowMap) {
4462 removeAppTokensLocked(tokens);
4463 final int N = tokens.size();
4464 for (int i=0; i<N; i++) {
4465 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4466 if (wt != null) {
4467 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004468 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004469 mToTopApps.remove(wt);
4470 mToBottomApps.remove(wt);
4471 mToTopApps.add(wt);
4472 wt.sendingToBottom = false;
4473 wt.sendingToTop = true;
4474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 }
4476 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004477
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004478 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004479 moveAppWindowsLocked(tokens, mAppTokens.size());
4480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 }
4482 Binder.restoreCallingIdentity(origId);
4483 }
4484
4485 public void moveAppTokensToBottom(List<IBinder> tokens) {
4486 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4487 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004488 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 }
4490
4491 final long origId = Binder.clearCallingIdentity();
4492 synchronized(mWindowMap) {
4493 removeAppTokensLocked(tokens);
4494 final int N = tokens.size();
4495 int pos = 0;
4496 for (int i=0; i<N; i++) {
4497 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4498 if (wt != null) {
4499 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004500 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004501 mToTopApps.remove(wt);
4502 mToBottomApps.remove(wt);
4503 mToBottomApps.add(i, wt);
4504 wt.sendingToTop = false;
4505 wt.sendingToBottom = true;
4506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 pos++;
4508 }
4509 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004510
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004511 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004512 moveAppWindowsLocked(tokens, 0);
4513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 }
4515 Binder.restoreCallingIdentity(origId);
4516 }
4517
4518 // -------------------------------------------------------------
4519 // Misc IWindowSession methods
4520 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004521
Jim Miller284b62e2010-06-08 14:27:42 -07004522 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004523 {
Jim Miller284b62e2010-06-08 14:27:42 -07004524 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4525 // called before DevicePolicyManagerService has started.
4526 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4527 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4528 Context.DEVICE_POLICY_SERVICE);
4529 if (dpm != null) {
4530 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4531 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4532 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4533 }
Jim Millerd6b57052010-06-07 17:52:42 -07004534 }
Jim Miller284b62e2010-06-08 14:27:42 -07004535 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004536 }
4537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004539 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 != PackageManager.PERMISSION_GRANTED) {
4541 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4542 }
Jim Millerd6b57052010-06-07 17:52:42 -07004543
Jim Miller284b62e2010-06-08 14:27:42 -07004544 synchronized (mKeyguardTokenWatcher) {
4545 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 }
4548
4549 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004550 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551 != PackageManager.PERMISSION_GRANTED) {
4552 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004554
Jim Miller284b62e2010-06-08 14:27:42 -07004555 synchronized (mKeyguardTokenWatcher) {
4556 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004557
Jim Miller284b62e2010-06-08 14:27:42 -07004558 if (!mKeyguardTokenWatcher.isAcquired()) {
4559 // If we are the last one to reenable the keyguard wait until
4560 // we have actually finished reenabling until returning.
4561 // It is possible that reenableKeyguard() can be called before
4562 // the previous disableKeyguard() is handled, in which case
4563 // neither mKeyguardTokenWatcher.acquired() or released() would
4564 // be called. In that case mKeyguardDisabled will be false here
4565 // and we have nothing to wait for.
4566 while (mKeyguardDisabled) {
4567 try {
4568 mKeyguardTokenWatcher.wait();
4569 } catch (InterruptedException e) {
4570 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 }
4572 }
4573 }
4574 }
4575 }
4576
4577 /**
4578 * @see android.app.KeyguardManager#exitKeyguardSecurely
4579 */
4580 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004581 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004582 != PackageManager.PERMISSION_GRANTED) {
4583 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4584 }
4585 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4586 public void onKeyguardExitResult(boolean success) {
4587 try {
4588 callback.onKeyguardExitResult(success);
4589 } catch (RemoteException e) {
4590 // Client has died, we don't care.
4591 }
4592 }
4593 });
4594 }
4595
4596 public boolean inKeyguardRestrictedInputMode() {
4597 return mPolicy.inKeyguardRestrictedKeyInputMode();
4598 }
Romain Guy06882f82009-06-10 13:36:04 -07004599
Dianne Hackbornffa42482009-09-23 22:20:11 -07004600 public void closeSystemDialogs(String reason) {
4601 synchronized(mWindowMap) {
4602 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004603 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004604 if (w.mSurface != null) {
4605 try {
4606 w.mClient.closeSystemDialogs(reason);
4607 } catch (RemoteException e) {
4608 }
4609 }
4610 }
4611 }
4612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004614 static float fixScale(float scale) {
4615 if (scale < 0) scale = 0;
4616 else if (scale > 20) scale = 20;
4617 return Math.abs(scale);
4618 }
Romain Guy06882f82009-06-10 13:36:04 -07004619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 public void setAnimationScale(int which, float scale) {
4621 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4622 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004623 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004624 }
4625
4626 if (scale < 0) scale = 0;
4627 else if (scale > 20) scale = 20;
4628 scale = Math.abs(scale);
4629 switch (which) {
4630 case 0: mWindowAnimationScale = fixScale(scale); break;
4631 case 1: mTransitionAnimationScale = fixScale(scale); break;
4632 }
Romain Guy06882f82009-06-10 13:36:04 -07004633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004634 // Persist setting
4635 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4636 }
Romain Guy06882f82009-06-10 13:36:04 -07004637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004638 public void setAnimationScales(float[] scales) {
4639 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4640 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004641 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 }
4643
4644 if (scales != null) {
4645 if (scales.length >= 1) {
4646 mWindowAnimationScale = fixScale(scales[0]);
4647 }
4648 if (scales.length >= 2) {
4649 mTransitionAnimationScale = fixScale(scales[1]);
4650 }
4651 }
Romain Guy06882f82009-06-10 13:36:04 -07004652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 // Persist setting
4654 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4655 }
Romain Guy06882f82009-06-10 13:36:04 -07004656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 public float getAnimationScale(int which) {
4658 switch (which) {
4659 case 0: return mWindowAnimationScale;
4660 case 1: return mTransitionAnimationScale;
4661 }
4662 return 0;
4663 }
Romain Guy06882f82009-06-10 13:36:04 -07004664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665 public float[] getAnimationScales() {
4666 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4667 }
Romain Guy06882f82009-06-10 13:36:04 -07004668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004669 public int getSwitchState(int sw) {
4670 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4671 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004672 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004673 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004674 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004675 }
Romain Guy06882f82009-06-10 13:36:04 -07004676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004677 public int getSwitchStateForDevice(int devid, int sw) {
4678 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4679 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004680 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004682 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
Romain Guy06882f82009-06-10 13:36:04 -07004684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 public int getScancodeState(int sw) {
4686 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4687 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004688 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004690 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004691 }
Romain Guy06882f82009-06-10 13:36:04 -07004692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 public int getScancodeStateForDevice(int devid, int sw) {
4694 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4695 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004696 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004698 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 }
Romain Guy06882f82009-06-10 13:36:04 -07004700
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004701 public int getTrackballScancodeState(int sw) {
4702 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4703 "getTrackballScancodeState()")) {
4704 throw new SecurityException("Requires READ_INPUT_STATE permission");
4705 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004706 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004707 }
4708
4709 public int getDPadScancodeState(int sw) {
4710 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4711 "getDPadScancodeState()")) {
4712 throw new SecurityException("Requires READ_INPUT_STATE permission");
4713 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004714 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004715 }
4716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004717 public int getKeycodeState(int sw) {
4718 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4719 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004720 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004721 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004722 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004723 }
Romain Guy06882f82009-06-10 13:36:04 -07004724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004725 public int getKeycodeStateForDevice(int devid, int sw) {
4726 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4727 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004728 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004729 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004730 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004731 }
Romain Guy06882f82009-06-10 13:36:04 -07004732
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004733 public int getTrackballKeycodeState(int sw) {
4734 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4735 "getTrackballKeycodeState()")) {
4736 throw new SecurityException("Requires READ_INPUT_STATE permission");
4737 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004738 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004739 }
4740
4741 public int getDPadKeycodeState(int sw) {
4742 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4743 "getDPadKeycodeState()")) {
4744 throw new SecurityException("Requires READ_INPUT_STATE permission");
4745 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004746 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004747 }
Jeff Browna41ca772010-08-11 14:46:32 -07004748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004749 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004750 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004751 }
Romain Guy06882f82009-06-10 13:36:04 -07004752
Jeff Browna41ca772010-08-11 14:46:32 -07004753 public InputChannel monitorInput(String inputChannelName) {
4754 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4755 "monitorInput()")) {
4756 throw new SecurityException("Requires READ_INPUT_STATE permission");
4757 }
4758 return mInputManager.monitorInput(inputChannelName);
4759 }
4760
Jeff Brown8d608662010-08-30 03:02:23 -07004761 public InputDevice getInputDevice(int deviceId) {
4762 return mInputManager.getInputDevice(deviceId);
4763 }
4764
4765 public int[] getInputDeviceIds() {
4766 return mInputManager.getInputDeviceIds();
4767 }
4768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 public void enableScreenAfterBoot() {
4770 synchronized(mWindowMap) {
4771 if (mSystemBooted) {
4772 return;
4773 }
4774 mSystemBooted = true;
4775 }
Romain Guy06882f82009-06-10 13:36:04 -07004776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004777 performEnableScreen();
4778 }
Romain Guy06882f82009-06-10 13:36:04 -07004779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004780 public void enableScreenIfNeededLocked() {
4781 if (mDisplayEnabled) {
4782 return;
4783 }
4784 if (!mSystemBooted) {
4785 return;
4786 }
4787 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4788 }
Romain Guy06882f82009-06-10 13:36:04 -07004789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 public void performEnableScreen() {
4791 synchronized(mWindowMap) {
4792 if (mDisplayEnabled) {
4793 return;
4794 }
4795 if (!mSystemBooted) {
4796 return;
4797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 // Don't enable the screen until all existing windows
4800 // have been drawn.
4801 final int N = mWindows.size();
4802 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004803 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004804 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 return;
4806 }
4807 }
Romain Guy06882f82009-06-10 13:36:04 -07004808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004809 mDisplayEnabled = true;
4810 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004811 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 StringWriter sw = new StringWriter();
4813 PrintWriter pw = new PrintWriter(sw);
4814 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004815 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 }
4817 try {
4818 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4819 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004820 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 Parcel data = Parcel.obtain();
4822 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4823 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4824 data, null, 0);
4825 data.recycle();
4826 }
4827 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004828 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004829 }
4830 }
Romain Guy06882f82009-06-10 13:36:04 -07004831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004832 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004835 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4836 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 }
Romain Guy06882f82009-06-10 13:36:04 -07004838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004839 public void setInTouchMode(boolean mode) {
4840 synchronized(mWindowMap) {
4841 mInTouchMode = mode;
4842 }
4843 }
4844
Romain Guy06882f82009-06-10 13:36:04 -07004845 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004846 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004847 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004848 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004849 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 }
4851
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004852 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 }
Romain Guy06882f82009-06-10 13:36:04 -07004854
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004855 public void setRotationUnchecked(int rotation,
4856 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004857 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004858 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 long origId = Binder.clearCallingIdentity();
4861 boolean changed;
4862 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004863 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004864 }
Romain Guy06882f82009-06-10 13:36:04 -07004865
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004866 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 sendNewConfiguration();
4868 }
Romain Guy06882f82009-06-10 13:36:04 -07004869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 Binder.restoreCallingIdentity(origId);
4871 }
Romain Guy06882f82009-06-10 13:36:04 -07004872
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004873 /**
4874 * Apply a new rotation to the screen, respecting the requests of
4875 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4876 * re-evaluate the desired rotation.
4877 *
4878 * Returns null if the rotation has been changed. In this case YOU
4879 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4880 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004881 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004882 boolean changed;
4883 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4884 rotation = mRequestedRotation;
4885 } else {
4886 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004887 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004888 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004889 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004890 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004892 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004893 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004895 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004896 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 "Rotation changed to " + rotation
4898 + " from " + mRotation
4899 + " (forceApp=" + mForcedAppOrientation
4900 + ", req=" + mRequestedRotation + ")");
4901 mRotation = rotation;
4902 mWindowsFreezingScreen = true;
4903 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4904 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4905 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004906 mWaitingForConfig = true;
4907 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004909 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004910 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004912 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 }
4914 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004915 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 if (w.mSurface != null) {
4917 w.mOrientationChanging = true;
4918 }
4919 }
4920 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4921 try {
4922 mRotationWatchers.get(i).onRotationChanged(rotation);
4923 } catch (RemoteException e) {
4924 }
4925 }
4926 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 return changed;
4929 }
Romain Guy06882f82009-06-10 13:36:04 -07004930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 public int getRotation() {
4932 return mRotation;
4933 }
4934
4935 public int watchRotation(IRotationWatcher watcher) {
4936 final IBinder watcherBinder = watcher.asBinder();
4937 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4938 public void binderDied() {
4939 synchronized (mWindowMap) {
4940 for (int i=0; i<mRotationWatchers.size(); i++) {
4941 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004942 IRotationWatcher removed = mRotationWatchers.remove(i);
4943 if (removed != null) {
4944 removed.asBinder().unlinkToDeath(this, 0);
4945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004946 i--;
4947 }
4948 }
4949 }
4950 }
4951 };
Romain Guy06882f82009-06-10 13:36:04 -07004952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953 synchronized (mWindowMap) {
4954 try {
4955 watcher.asBinder().linkToDeath(dr, 0);
4956 mRotationWatchers.add(watcher);
4957 } catch (RemoteException e) {
4958 // Client died, no cleanup needed.
4959 }
Romain Guy06882f82009-06-10 13:36:04 -07004960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961 return mRotation;
4962 }
4963 }
4964
4965 /**
4966 * Starts the view server on the specified port.
4967 *
4968 * @param port The port to listener to.
4969 *
4970 * @return True if the server was successfully started, false otherwise.
4971 *
4972 * @see com.android.server.ViewServer
4973 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4974 */
4975 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004976 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004977 return false;
4978 }
4979
4980 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4981 return false;
4982 }
4983
4984 if (port < 1024) {
4985 return false;
4986 }
4987
4988 if (mViewServer != null) {
4989 if (!mViewServer.isRunning()) {
4990 try {
4991 return mViewServer.start();
4992 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004993 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004994 }
4995 }
4996 return false;
4997 }
4998
4999 try {
5000 mViewServer = new ViewServer(this, port);
5001 return mViewServer.start();
5002 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005003 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005004 }
5005 return false;
5006 }
5007
Romain Guy06882f82009-06-10 13:36:04 -07005008 private boolean isSystemSecure() {
5009 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5010 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5011 }
5012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005013 /**
5014 * Stops the view server if it exists.
5015 *
5016 * @return True if the server stopped, false if it wasn't started or
5017 * couldn't be stopped.
5018 *
5019 * @see com.android.server.ViewServer
5020 */
5021 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005022 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005023 return false;
5024 }
5025
5026 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5027 return false;
5028 }
5029
5030 if (mViewServer != null) {
5031 return mViewServer.stop();
5032 }
5033 return false;
5034 }
5035
5036 /**
5037 * Indicates whether the view server is running.
5038 *
5039 * @return True if the server is running, false otherwise.
5040 *
5041 * @see com.android.server.ViewServer
5042 */
5043 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005044 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 return false;
5046 }
5047
5048 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5049 return false;
5050 }
5051
5052 return mViewServer != null && mViewServer.isRunning();
5053 }
5054
5055 /**
5056 * Lists all availble windows in the system. The listing is written in the
5057 * specified Socket's output stream with the following syntax:
5058 * windowHashCodeInHexadecimal windowName
5059 * Each line of the ouput represents a different window.
5060 *
5061 * @param client The remote client to send the listing to.
5062 * @return False if an error occured, true otherwise.
5063 */
5064 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005065 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005066 return false;
5067 }
5068
5069 boolean result = true;
5070
Jeff Browne33348b2010-07-15 23:54:05 -07005071 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005072 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005073 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005074 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005075 }
5076
5077 BufferedWriter out = null;
5078
5079 // Any uncaught exception will crash the system process
5080 try {
5081 OutputStream clientStream = client.getOutputStream();
5082 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5083
5084 final int count = windows.length;
5085 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005086 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005087 out.write(Integer.toHexString(System.identityHashCode(w)));
5088 out.write(' ');
5089 out.append(w.mAttrs.getTitle());
5090 out.write('\n');
5091 }
5092
5093 out.write("DONE.\n");
5094 out.flush();
5095 } catch (Exception e) {
5096 result = false;
5097 } finally {
5098 if (out != null) {
5099 try {
5100 out.close();
5101 } catch (IOException e) {
5102 result = false;
5103 }
5104 }
5105 }
5106
5107 return result;
5108 }
5109
5110 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005111 * Returns the focused window in the following format:
5112 * windowHashCodeInHexadecimal windowName
5113 *
5114 * @param client The remote client to send the listing to.
5115 * @return False if an error occurred, true otherwise.
5116 */
5117 boolean viewServerGetFocusedWindow(Socket client) {
5118 if (isSystemSecure()) {
5119 return false;
5120 }
5121
5122 boolean result = true;
5123
5124 WindowState focusedWindow = getFocusedWindow();
5125
5126 BufferedWriter out = null;
5127
5128 // Any uncaught exception will crash the system process
5129 try {
5130 OutputStream clientStream = client.getOutputStream();
5131 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5132
5133 if(focusedWindow != null) {
5134 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5135 out.write(' ');
5136 out.append(focusedWindow.mAttrs.getTitle());
5137 }
5138 out.write('\n');
5139 out.flush();
5140 } catch (Exception e) {
5141 result = false;
5142 } finally {
5143 if (out != null) {
5144 try {
5145 out.close();
5146 } catch (IOException e) {
5147 result = false;
5148 }
5149 }
5150 }
5151
5152 return result;
5153 }
5154
5155 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156 * Sends a command to a target window. The result of the command, if any, will be
5157 * written in the output stream of the specified socket.
5158 *
5159 * The parameters must follow this syntax:
5160 * windowHashcode extra
5161 *
5162 * Where XX is the length in characeters of the windowTitle.
5163 *
5164 * The first parameter is the target window. The window with the specified hashcode
5165 * will be the target. If no target can be found, nothing happens. The extra parameters
5166 * will be delivered to the target window and as parameters to the command itself.
5167 *
5168 * @param client The remote client to sent the result, if any, to.
5169 * @param command The command to execute.
5170 * @param parameters The command parameters.
5171 *
5172 * @return True if the command was successfully delivered, false otherwise. This does
5173 * not indicate whether the command itself was successful.
5174 */
5175 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005176 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005177 return false;
5178 }
5179
5180 boolean success = true;
5181 Parcel data = null;
5182 Parcel reply = null;
5183
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005184 BufferedWriter out = null;
5185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005186 // Any uncaught exception will crash the system process
5187 try {
5188 // Find the hashcode of the window
5189 int index = parameters.indexOf(' ');
5190 if (index == -1) {
5191 index = parameters.length();
5192 }
5193 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005194 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005195
5196 // Extract the command's parameter after the window description
5197 if (index < parameters.length()) {
5198 parameters = parameters.substring(index + 1);
5199 } else {
5200 parameters = "";
5201 }
5202
5203 final WindowManagerService.WindowState window = findWindow(hashCode);
5204 if (window == null) {
5205 return false;
5206 }
5207
5208 data = Parcel.obtain();
5209 data.writeInterfaceToken("android.view.IWindow");
5210 data.writeString(command);
5211 data.writeString(parameters);
5212 data.writeInt(1);
5213 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5214
5215 reply = Parcel.obtain();
5216
5217 final IBinder binder = window.mClient.asBinder();
5218 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5219 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5220
5221 reply.readException();
5222
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005223 if (!client.isOutputShutdown()) {
5224 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5225 out.write("DONE\n");
5226 out.flush();
5227 }
5228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005229 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005230 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 success = false;
5232 } finally {
5233 if (data != null) {
5234 data.recycle();
5235 }
5236 if (reply != null) {
5237 reply.recycle();
5238 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005239 if (out != null) {
5240 try {
5241 out.close();
5242 } catch (IOException e) {
5243
5244 }
5245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005246 }
5247
5248 return success;
5249 }
5250
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005251 public void addWindowChangeListener(WindowChangeListener listener) {
5252 synchronized(mWindowMap) {
5253 mWindowChangeListeners.add(listener);
5254 }
5255 }
5256
5257 public void removeWindowChangeListener(WindowChangeListener listener) {
5258 synchronized(mWindowMap) {
5259 mWindowChangeListeners.remove(listener);
5260 }
5261 }
5262
5263 private void notifyWindowsChanged() {
5264 WindowChangeListener[] windowChangeListeners;
5265 synchronized(mWindowMap) {
5266 if(mWindowChangeListeners.isEmpty()) {
5267 return;
5268 }
5269 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5270 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5271 }
5272 int N = windowChangeListeners.length;
5273 for(int i = 0; i < N; i++) {
5274 windowChangeListeners[i].windowsChanged();
5275 }
5276 }
5277
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005278 private void notifyFocusChanged() {
5279 WindowChangeListener[] windowChangeListeners;
5280 synchronized(mWindowMap) {
5281 if(mWindowChangeListeners.isEmpty()) {
5282 return;
5283 }
5284 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5285 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5286 }
5287 int N = windowChangeListeners.length;
5288 for(int i = 0; i < N; i++) {
5289 windowChangeListeners[i].focusChanged();
5290 }
5291 }
5292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005293 private WindowState findWindow(int hashCode) {
5294 if (hashCode == -1) {
5295 return getFocusedWindow();
5296 }
5297
5298 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005299 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005300 final int count = windows.size();
5301
5302 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005303 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005304 if (System.identityHashCode(w) == hashCode) {
5305 return w;
5306 }
5307 }
5308 }
5309
5310 return null;
5311 }
5312
5313 /*
5314 * Instruct the Activity Manager to fetch the current configuration and broadcast
5315 * that to config-changed listeners if appropriate.
5316 */
5317 void sendNewConfiguration() {
5318 try {
5319 mActivityManager.updateConfiguration(null);
5320 } catch (RemoteException e) {
5321 }
5322 }
Romain Guy06882f82009-06-10 13:36:04 -07005323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005324 public Configuration computeNewConfiguration() {
5325 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005326 return computeNewConfigurationLocked();
5327 }
5328 }
Romain Guy06882f82009-06-10 13:36:04 -07005329
Dianne Hackbornc485a602009-03-24 22:39:49 -07005330 Configuration computeNewConfigurationLocked() {
5331 Configuration config = new Configuration();
5332 if (!computeNewConfigurationLocked(config)) {
5333 return null;
5334 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005335 return config;
5336 }
Romain Guy06882f82009-06-10 13:36:04 -07005337
Dianne Hackbornc485a602009-03-24 22:39:49 -07005338 boolean computeNewConfigurationLocked(Configuration config) {
5339 if (mDisplay == null) {
5340 return false;
5341 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005342
5343 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005344
5345 // Use the effective "visual" dimensions based on current rotation
5346 final boolean rotated = (mRotation == Surface.ROTATION_90
5347 || mRotation == Surface.ROTATION_270);
5348 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5349 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5350
Dianne Hackbornc485a602009-03-24 22:39:49 -07005351 int orientation = Configuration.ORIENTATION_SQUARE;
5352 if (dw < dh) {
5353 orientation = Configuration.ORIENTATION_PORTRAIT;
5354 } else if (dw > dh) {
5355 orientation = Configuration.ORIENTATION_LANDSCAPE;
5356 }
5357 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005358
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005359 DisplayMetrics dm = new DisplayMetrics();
5360 mDisplay.getMetrics(dm);
5361 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5362
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005363 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005364 // Note we only do this once because at this point we don't
5365 // expect the screen to change in this way at runtime, and want
5366 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005367 int longSize = dw;
5368 int shortSize = dh;
5369 if (longSize < shortSize) {
5370 int tmp = longSize;
5371 longSize = shortSize;
5372 shortSize = tmp;
5373 }
5374 longSize = (int)(longSize/dm.density);
5375 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005376
Dianne Hackborn723738c2009-06-25 19:48:04 -07005377 // These semi-magic numbers define our compatibility modes for
5378 // applications with different screens. Don't change unless you
5379 // make sure to test lots and lots of apps!
5380 if (longSize < 470) {
5381 // This is shorter than an HVGA normal density screen (which
5382 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005383 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5384 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005385 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005386 // What size is this screen screen?
5387 if (longSize >= 800 && shortSize >= 600) {
5388 // SVGA or larger screens at medium density are the point
5389 // at which we consider it to be an extra large screen.
5390 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005391 } else if (longSize >= 530 && shortSize >= 400) {
5392 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005393 // at which we consider it to be a large screen.
5394 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5395 } else {
5396 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005397
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005398 // If this screen is wider than normal HVGA, or taller
5399 // than FWVGA, then for old apps we want to run in size
5400 // compatibility mode.
5401 if (shortSize > 321 || longSize > 570) {
5402 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5403 }
5404 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005405
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005406 // Is this a long screen?
5407 if (((longSize*3)/5) >= (shortSize-1)) {
5408 // Anything wider than WVGA (5:3) is considering to be long.
5409 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5410 } else {
5411 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5412 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005413 }
5414 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005415 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005416
Dianne Hackbornc485a602009-03-24 22:39:49 -07005417 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5418 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5419 mPolicy.adjustConfigurationLw(config);
5420 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005421 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005422
5423 // -------------------------------------------------------------
5424 // Drag and drop
5425 // -------------------------------------------------------------
5426
5427 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5428 boolean localOnly, int width, int height, Surface outSurface) {
5429 if (DEBUG_DRAG) {
5430 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5431 + " local=" + localOnly + " win=" + window
5432 + " asbinder=" + window.asBinder());
5433 }
5434
5435 final int callerPid = Binder.getCallingPid();
5436 final long origId = Binder.clearCallingIdentity();
5437 IBinder token = null;
5438
5439 try {
5440 synchronized (mWindowMap) {
5441 try {
5442 // !!! TODO: fail if the given window does not currently have touch focus?
5443
5444 if (mDragState == null) {
5445 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5446 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5447 outSurface.copyFrom(surface);
5448 token = new Binder();
5449 mDragState = new DragState(token, surface, localOnly);
5450 mDragState.mSurface = surface;
5451 mDragState.mLocalOnly = localOnly;
5452 token = mDragState.mToken = new Binder();
5453
5454 // 5 second timeout for this window to actually begin the drag
5455 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5456 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5457 mH.sendMessageDelayed(msg, 5000);
5458 } else {
5459 Slog.w(TAG, "Drag already in progress");
5460 }
5461 } catch (Surface.OutOfResourcesException e) {
5462 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5463 if (mDragState != null) {
5464 mDragState.reset();
5465 mDragState = null;
5466 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005467 }
5468 }
5469 } finally {
5470 Binder.restoreCallingIdentity(origId);
5471 }
5472
5473 return token;
5474 }
5475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005476 // -------------------------------------------------------------
5477 // Input Events and Focus Management
5478 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005479
Jeff Brown349703e2010-06-22 01:27:15 -07005480 InputMonitor mInputMonitor = new InputMonitor();
5481
5482 /* Tracks the progress of input dispatch and ensures that input dispatch state
5483 * is kept in sync with changes in window focus, visibility, registration, and
5484 * other relevant Window Manager state transitions. */
5485 final class InputMonitor {
5486 // Current window with input focus for keys and other non-touch events. May be null.
5487 private WindowState mInputFocus;
5488
5489 // When true, prevents input dispatch from proceeding until set to false again.
5490 private boolean mInputDispatchFrozen;
5491
5492 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5493 private boolean mInputDispatchEnabled = true;
5494
5495 // Temporary list of windows information to provide to the input dispatcher.
5496 private InputWindowList mTempInputWindows = new InputWindowList();
5497
5498 // Temporary input application object to provide to the input dispatcher.
5499 private InputApplication mTempInputApplication = new InputApplication();
5500
5501 /* Notifies the window manager about a broken input channel.
5502 *
5503 * Called by the InputManager.
5504 */
5505 public void notifyInputChannelBroken(InputChannel inputChannel) {
5506 synchronized (mWindowMap) {
5507 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5508 if (windowState == null) {
5509 return; // irrelevant
5510 }
5511
5512 Slog.i(TAG, "WINDOW DIED " + windowState);
5513 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005514 }
5515 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005516
Jeff Brown519e0242010-09-15 15:18:56 -07005517 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005518 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005519 *
5520 * Called by the InputManager.
5521 */
Jeff Brown519e0242010-09-15 15:18:56 -07005522 public long notifyANR(Object token, InputChannel inputChannel) {
5523 AppWindowToken appWindowToken = null;
5524 if (inputChannel != null) {
5525 synchronized (mWindowMap) {
5526 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5527 if (windowState != null) {
5528 Slog.i(TAG, "Input event dispatching timed out sending to "
5529 + windowState.mAttrs.getTitle());
5530 appWindowToken = windowState.mAppToken;
5531 }
Jeff Brown349703e2010-06-22 01:27:15 -07005532 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005533 }
5534
Jeff Brown519e0242010-09-15 15:18:56 -07005535 if (appWindowToken == null && token != null) {
5536 appWindowToken = (AppWindowToken) token;
5537 Slog.i(TAG, "Input event dispatching timed out sending to application "
5538 + appWindowToken.stringName);
5539 }
Jeff Brown349703e2010-06-22 01:27:15 -07005540
Jeff Brown519e0242010-09-15 15:18:56 -07005541 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005542 try {
5543 // Notify the activity manager about the timeout and let it decide whether
5544 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005545 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005546 if (! abort) {
5547 // The activity manager declined to abort dispatching.
5548 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005549 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005550 }
Jeff Brown349703e2010-06-22 01:27:15 -07005551 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005552 }
5553 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005554 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005555 }
5556
Jeff Brown349703e2010-06-22 01:27:15 -07005557 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5558 synchronized (mWindowMap) {
5559 return getWindowStateForInputChannelLocked(inputChannel);
5560 }
5561 }
5562
5563 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5564 int windowCount = mWindows.size();
5565 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005566 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005567 if (windowState.mInputChannel == inputChannel) {
5568 return windowState;
5569 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005570 }
5571
Jeff Brown349703e2010-06-22 01:27:15 -07005572 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005573 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005574
Chris Tatea32dcf72010-10-14 12:13:50 -07005575 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005576 final InputWindow inputWindow = windowList.add();
5577 inputWindow.inputChannel = mDragState.mServerChannel;
5578 inputWindow.name = "drag";
5579 inputWindow.layoutParamsFlags = 0;
5580 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5581 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5582 inputWindow.visible = true;
5583 inputWindow.canReceiveKeys = false;
5584 inputWindow.hasFocus = true;
5585 inputWindow.hasWallpaper = false;
5586 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005587 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005588 inputWindow.ownerPid = Process.myPid();
5589 inputWindow.ownerUid = Process.myUid();
5590
5591 // The drag window covers the entire display
5592 inputWindow.frameLeft = 0;
5593 inputWindow.frameTop = 0;
5594 inputWindow.frameRight = mDisplay.getWidth();
5595 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005596
Christopher Tatea53146c2010-09-07 11:57:52 -07005597 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5598 inputWindow.visibleFrameTop = inputWindow.frameTop;
5599 inputWindow.visibleFrameRight = inputWindow.frameRight;
5600 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5601
5602 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5603 inputWindow.touchableAreaTop = inputWindow.frameTop;
5604 inputWindow.touchableAreaRight = inputWindow.frameRight;
5605 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5606 }
5607
Jeff Brown349703e2010-06-22 01:27:15 -07005608 /* Updates the cached window information provided to the input dispatcher. */
5609 public void updateInputWindowsLw() {
5610 // Populate the input window list with information about all of the windows that
5611 // could potentially receive input.
5612 // As an optimization, we could try to prune the list of windows but this turns
5613 // out to be difficult because only the native code knows for sure which window
5614 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005615 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005616
5617 // If there's a drag in flight, provide a pseudowindow to catch drag input
5618 final boolean inDrag = (mDragState != null);
5619 if (inDrag) {
5620 if (DEBUG_DRAG) {
5621 Log.d(TAG, "Inserting drag window");
5622 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005623 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005624 }
5625
Jeff Brown7fbdc842010-06-17 20:52:56 -07005626 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005627 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005628 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005629 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005630 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005631 continue;
5632 }
5633
Jeff Brown349703e2010-06-22 01:27:15 -07005634 final int flags = child.mAttrs.flags;
5635 final int type = child.mAttrs.type;
5636
5637 final boolean hasFocus = (child == mInputFocus);
5638 final boolean isVisible = child.isVisibleLw();
5639 final boolean hasWallpaper = (child == mWallpaperTarget)
5640 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005641
5642 // If there's a drag in progress and 'child' is a potential drop target,
5643 // make sure it's been told about the drag
5644 if (inDrag && isVisible) {
5645 mDragState.sendDragStartedIfNeededLw(child);
5646 }
5647
Jeff Brown349703e2010-06-22 01:27:15 -07005648 // Add a window to our list of input windows.
5649 final InputWindow inputWindow = mTempInputWindows.add();
5650 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005651 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005652 inputWindow.layoutParamsFlags = flags;
5653 inputWindow.layoutParamsType = type;
5654 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5655 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005656 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005657 inputWindow.hasFocus = hasFocus;
5658 inputWindow.hasWallpaper = hasWallpaper;
5659 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005660 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005661 inputWindow.ownerPid = child.mSession.mPid;
5662 inputWindow.ownerUid = child.mSession.mUid;
5663
5664 final Rect frame = child.mFrame;
5665 inputWindow.frameLeft = frame.left;
5666 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005667 inputWindow.frameRight = frame.right;
5668 inputWindow.frameBottom = frame.bottom;
5669
5670 final Rect visibleFrame = child.mVisibleFrame;
5671 inputWindow.visibleFrameLeft = visibleFrame.left;
5672 inputWindow.visibleFrameTop = visibleFrame.top;
5673 inputWindow.visibleFrameRight = visibleFrame.right;
5674 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005675
5676 switch (child.mTouchableInsets) {
5677 default:
5678 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5679 inputWindow.touchableAreaLeft = frame.left;
5680 inputWindow.touchableAreaTop = frame.top;
5681 inputWindow.touchableAreaRight = frame.right;
5682 inputWindow.touchableAreaBottom = frame.bottom;
5683 break;
5684
5685 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5686 Rect inset = child.mGivenContentInsets;
5687 inputWindow.touchableAreaLeft = frame.left + inset.left;
5688 inputWindow.touchableAreaTop = frame.top + inset.top;
5689 inputWindow.touchableAreaRight = frame.right - inset.right;
5690 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5691 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005692 }
Jeff Brown349703e2010-06-22 01:27:15 -07005693
5694 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5695 Rect inset = child.mGivenVisibleInsets;
5696 inputWindow.touchableAreaLeft = frame.left + inset.left;
5697 inputWindow.touchableAreaTop = frame.top + inset.top;
5698 inputWindow.touchableAreaRight = frame.right - inset.right;
5699 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005700 break;
5701 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005702 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005703 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005704
Jeff Brown349703e2010-06-22 01:27:15 -07005705 // Send windows to native code.
5706 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005707
Jeff Brown349703e2010-06-22 01:27:15 -07005708 // Clear the list in preparation for the next round.
5709 // Also avoids keeping InputChannel objects referenced unnecessarily.
5710 mTempInputWindows.clear();
5711 }
5712
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005713 /* Notifies that the lid switch changed state. */
5714 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5715 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5716 }
5717
Jeff Brown349703e2010-06-22 01:27:15 -07005718 /* Provides an opportunity for the window manager policy to intercept early key
5719 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005720 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5721 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5722 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5723 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005724 }
5725
5726 /* Provides an opportunity for the window manager policy to process a key before
5727 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005728 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005729 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005730 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005731 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005732 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005733 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005734 }
5735
5736 /* Called when the current input focus changes.
5737 * Layer assignment is assumed to be complete by the time this is called.
5738 */
5739 public void setInputFocusLw(WindowState newWindow) {
5740 if (DEBUG_INPUT) {
5741 Slog.d(TAG, "Input focus has changed to " + newWindow);
5742 }
5743
5744 if (newWindow != mInputFocus) {
5745 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005746 // Displaying a window implicitly causes dispatching to be unpaused.
5747 // This is to protect against bugs if someone pauses dispatching but
5748 // forgets to resume.
5749 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005750 }
Jeff Brown349703e2010-06-22 01:27:15 -07005751
5752 mInputFocus = newWindow;
5753 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005754 }
5755 }
5756
Jeff Brown349703e2010-06-22 01:27:15 -07005757 public void setFocusedAppLw(AppWindowToken newApp) {
5758 // Focused app has changed.
5759 if (newApp == null) {
5760 mInputManager.setFocusedApplication(null);
5761 } else {
5762 mTempInputApplication.name = newApp.toString();
5763 mTempInputApplication.dispatchingTimeoutNanos =
5764 newApp.inputDispatchingTimeoutNanos;
5765 mTempInputApplication.token = newApp;
5766
5767 mInputManager.setFocusedApplication(mTempInputApplication);
5768 }
5769 }
5770
Jeff Brown349703e2010-06-22 01:27:15 -07005771 public void pauseDispatchingLw(WindowToken window) {
5772 if (! window.paused) {
5773 if (DEBUG_INPUT) {
5774 Slog.v(TAG, "Pausing WindowToken " + window);
5775 }
5776
5777 window.paused = true;
5778 updateInputWindowsLw();
5779 }
5780 }
5781
5782 public void resumeDispatchingLw(WindowToken window) {
5783 if (window.paused) {
5784 if (DEBUG_INPUT) {
5785 Slog.v(TAG, "Resuming WindowToken " + window);
5786 }
5787
5788 window.paused = false;
5789 updateInputWindowsLw();
5790 }
5791 }
5792
5793 public void freezeInputDispatchingLw() {
5794 if (! mInputDispatchFrozen) {
5795 if (DEBUG_INPUT) {
5796 Slog.v(TAG, "Freezing input dispatching");
5797 }
5798
5799 mInputDispatchFrozen = true;
5800 updateInputDispatchModeLw();
5801 }
5802 }
5803
5804 public void thawInputDispatchingLw() {
5805 if (mInputDispatchFrozen) {
5806 if (DEBUG_INPUT) {
5807 Slog.v(TAG, "Thawing input dispatching");
5808 }
5809
5810 mInputDispatchFrozen = false;
5811 updateInputDispatchModeLw();
5812 }
5813 }
5814
5815 public void setEventDispatchingLw(boolean enabled) {
5816 if (mInputDispatchEnabled != enabled) {
5817 if (DEBUG_INPUT) {
5818 Slog.v(TAG, "Setting event dispatching to " + enabled);
5819 }
5820
5821 mInputDispatchEnabled = enabled;
5822 updateInputDispatchModeLw();
5823 }
5824 }
5825
5826 private void updateInputDispatchModeLw() {
5827 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5828 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005829 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005831 public void pauseKeyDispatching(IBinder _token) {
5832 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5833 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005834 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005835 }
5836
5837 synchronized (mWindowMap) {
5838 WindowToken token = mTokenMap.get(_token);
5839 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005840 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005841 }
5842 }
5843 }
5844
5845 public void resumeKeyDispatching(IBinder _token) {
5846 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5847 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005848 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005849 }
5850
5851 synchronized (mWindowMap) {
5852 WindowToken token = mTokenMap.get(_token);
5853 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005854 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005855 }
5856 }
5857 }
5858
5859 public void setEventDispatching(boolean enabled) {
5860 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5861 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005862 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005863 }
5864
5865 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005866 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005867 }
5868 }
Romain Guy06882f82009-06-10 13:36:04 -07005869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005870 /**
5871 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005872 * Even when sync is false, this method may block while waiting for current
5873 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005874 *
5875 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005876 * {@link SystemClock#uptimeMillis()} as the timebase.)
5877 * @param sync If true, wait for the event to be completed before returning to the caller.
5878 * @return Returns true if event was dispatched, false if it was dropped for any reason
5879 */
5880 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5881 long downTime = ev.getDownTime();
5882 long eventTime = ev.getEventTime();
5883
5884 int action = ev.getAction();
5885 int code = ev.getKeyCode();
5886 int repeatCount = ev.getRepeatCount();
5887 int metaState = ev.getMetaState();
5888 int deviceId = ev.getDeviceId();
5889 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005890 int source = ev.getSource();
5891
5892 if (source == InputDevice.SOURCE_UNKNOWN) {
5893 source = InputDevice.SOURCE_KEYBOARD;
5894 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005895
5896 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5897 if (downTime == 0) downTime = eventTime;
5898
5899 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005900 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005902 final int pid = Binder.getCallingPid();
5903 final int uid = Binder.getCallingUid();
5904 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005905
Jeff Brownbbda99d2010-07-28 15:48:59 -07005906 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5907 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5908 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5909 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005910
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005911 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005912 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005913 }
5914
5915 /**
5916 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005917 * Even when sync is false, this method may block while waiting for current
5918 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005919 *
5920 * @param ev A motion event describing the pointer (touch) action. (As noted in
5921 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005922 * {@link SystemClock#uptimeMillis()} as the timebase.)
5923 * @param sync If true, wait for the event to be completed before returning to the caller.
5924 * @return Returns true if event was dispatched, false if it was dropped for any reason
5925 */
5926 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005927 final int pid = Binder.getCallingPid();
5928 final int uid = Binder.getCallingUid();
5929 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005930
Jeff Brownc5ed5912010-07-14 18:48:53 -07005931 MotionEvent newEvent = MotionEvent.obtain(ev);
5932 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5933 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5934 }
5935
Jeff Brownbbda99d2010-07-28 15:48:59 -07005936 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5937 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5938 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5939 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005940
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005941 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005942 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005943 }
Romain Guy06882f82009-06-10 13:36:04 -07005944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005945 /**
5946 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005947 * Even when sync is false, this method may block while waiting for current
5948 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005949 *
5950 * @param ev A motion event describing the trackball action. (As noted in
5951 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005952 * {@link SystemClock#uptimeMillis()} as the timebase.)
5953 * @param sync If true, wait for the event to be completed before returning to the caller.
5954 * @return Returns true if event was dispatched, false if it was dropped for any reason
5955 */
5956 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005957 final int pid = Binder.getCallingPid();
5958 final int uid = Binder.getCallingUid();
5959 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005960
Jeff Brownc5ed5912010-07-14 18:48:53 -07005961 MotionEvent newEvent = MotionEvent.obtain(ev);
5962 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5963 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5964 }
5965
Jeff Brownbbda99d2010-07-28 15:48:59 -07005966 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5967 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5968 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5969 INJECTION_TIMEOUT_MILLIS);
5970
5971 Binder.restoreCallingIdentity(ident);
5972 return reportInjectionResult(result);
5973 }
5974
5975 /**
5976 * Inject an input event into the UI without waiting for dispatch to commence.
5977 * This variant is useful for fire-and-forget input event injection. It does not
5978 * block any longer than it takes to enqueue the input event.
5979 *
5980 * @param ev An input event. (Be sure to set the input source correctly.)
5981 * @return Returns true if event was dispatched, false if it was dropped for any reason
5982 */
5983 public boolean injectInputEventNoWait(InputEvent ev) {
5984 final int pid = Binder.getCallingPid();
5985 final int uid = Binder.getCallingUid();
5986 final long ident = Binder.clearCallingIdentity();
5987
5988 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5989 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5990 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005991
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005992 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005993 return reportInjectionResult(result);
5994 }
5995
5996 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005997 switch (result) {
5998 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5999 Slog.w(TAG, "Input event injection permission denied.");
6000 throw new SecurityException(
6001 "Injecting to another application requires INJECT_EVENTS permission");
6002 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006003 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006004 return true;
6005 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6006 Slog.w(TAG, "Input event injection timed out.");
6007 return false;
6008 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6009 default:
6010 Slog.w(TAG, "Input event injection failed.");
6011 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006012 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006013 }
Romain Guy06882f82009-06-10 13:36:04 -07006014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006015 private WindowState getFocusedWindow() {
6016 synchronized (mWindowMap) {
6017 return getFocusedWindowLocked();
6018 }
6019 }
6020
6021 private WindowState getFocusedWindowLocked() {
6022 return mCurrentFocus;
6023 }
Romain Guy06882f82009-06-10 13:36:04 -07006024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006025 public boolean detectSafeMode() {
6026 mSafeMode = mPolicy.detectSafeMode();
6027 return mSafeMode;
6028 }
Romain Guy06882f82009-06-10 13:36:04 -07006029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006030 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006031 synchronized(mWindowMap) {
6032 if (mDisplay != null) {
6033 throw new IllegalStateException("Display already initialized");
6034 }
6035 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6036 mDisplay = wm.getDefaultDisplay();
6037 mInitialDisplayWidth = mDisplay.getWidth();
6038 mInitialDisplayHeight = mDisplay.getHeight();
6039 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6040 }
6041
6042 try {
6043 mActivityManager.updateConfiguration(null);
6044 } catch (RemoteException e) {
6045 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006046
6047 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006048 }
6049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006050 // -------------------------------------------------------------
6051 // Client Session State
6052 // -------------------------------------------------------------
6053
6054 private final class Session extends IWindowSession.Stub
6055 implements IBinder.DeathRecipient {
6056 final IInputMethodClient mClient;
6057 final IInputContext mInputContext;
6058 final int mUid;
6059 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006060 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006061 SurfaceSession mSurfaceSession;
6062 int mNumWindow = 0;
6063 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 public Session(IInputMethodClient client, IInputContext inputContext) {
6066 mClient = client;
6067 mInputContext = inputContext;
6068 mUid = Binder.getCallingUid();
6069 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006070 StringBuilder sb = new StringBuilder();
6071 sb.append("Session{");
6072 sb.append(Integer.toHexString(System.identityHashCode(this)));
6073 sb.append(" uid ");
6074 sb.append(mUid);
6075 sb.append("}");
6076 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 synchronized (mWindowMap) {
6079 if (mInputMethodManager == null && mHaveInputMethods) {
6080 IBinder b = ServiceManager.getService(
6081 Context.INPUT_METHOD_SERVICE);
6082 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6083 }
6084 }
6085 long ident = Binder.clearCallingIdentity();
6086 try {
6087 // Note: it is safe to call in to the input method manager
6088 // here because we are not holding our lock.
6089 if (mInputMethodManager != null) {
6090 mInputMethodManager.addClient(client, inputContext,
6091 mUid, mPid);
6092 } else {
6093 client.setUsingInputMethod(false);
6094 }
6095 client.asBinder().linkToDeath(this, 0);
6096 } catch (RemoteException e) {
6097 // The caller has died, so we can just forget about this.
6098 try {
6099 if (mInputMethodManager != null) {
6100 mInputMethodManager.removeClient(client);
6101 }
6102 } catch (RemoteException ee) {
6103 }
6104 } finally {
6105 Binder.restoreCallingIdentity(ident);
6106 }
6107 }
Romain Guy06882f82009-06-10 13:36:04 -07006108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006109 @Override
6110 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6111 throws RemoteException {
6112 try {
6113 return super.onTransact(code, data, reply, flags);
6114 } catch (RuntimeException e) {
6115 // Log all 'real' exceptions thrown to the caller
6116 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006117 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 }
6119 throw e;
6120 }
6121 }
6122
6123 public void binderDied() {
6124 // Note: it is safe to call in to the input method manager
6125 // here because we are not holding our lock.
6126 try {
6127 if (mInputMethodManager != null) {
6128 mInputMethodManager.removeClient(mClient);
6129 }
6130 } catch (RemoteException e) {
6131 }
6132 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006133 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006134 mClientDead = true;
6135 killSessionLocked();
6136 }
6137 }
6138
6139 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006140 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6141 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6142 outInputChannel);
6143 }
6144
6145 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006146 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006147 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 }
Romain Guy06882f82009-06-10 13:36:04 -07006149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 public void remove(IWindow window) {
6151 removeWindow(this, window);
6152 }
Romain Guy06882f82009-06-10 13:36:04 -07006153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6155 int requestedWidth, int requestedHeight, int viewFlags,
6156 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006157 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006158 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6159 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006161 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006162 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6163 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006164 }
Romain Guy06882f82009-06-10 13:36:04 -07006165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 public void setTransparentRegion(IWindow window, Region region) {
6167 setTransparentRegionWindow(this, window, region);
6168 }
Romain Guy06882f82009-06-10 13:36:04 -07006169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 public void setInsets(IWindow window, int touchableInsets,
6171 Rect contentInsets, Rect visibleInsets) {
6172 setInsetsWindow(this, window, touchableInsets, contentInsets,
6173 visibleInsets);
6174 }
Romain Guy06882f82009-06-10 13:36:04 -07006175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006176 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6177 getWindowDisplayFrame(this, window, outDisplayFrame);
6178 }
Romain Guy06882f82009-06-10 13:36:04 -07006179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006181 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006182 TAG, "IWindow finishDrawing called for " + window);
6183 finishDrawingWindow(this, window);
6184 }
6185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 public void setInTouchMode(boolean mode) {
6187 synchronized(mWindowMap) {
6188 mInTouchMode = mode;
6189 }
6190 }
6191
6192 public boolean getInTouchMode() {
6193 synchronized(mWindowMap) {
6194 return mInTouchMode;
6195 }
6196 }
6197
6198 public boolean performHapticFeedback(IWindow window, int effectId,
6199 boolean always) {
6200 synchronized(mWindowMap) {
6201 long ident = Binder.clearCallingIdentity();
6202 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006203 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006204 windowForClientLocked(this, window, true),
6205 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 } finally {
6207 Binder.restoreCallingIdentity(ident);
6208 }
6209 }
6210 }
Romain Guy06882f82009-06-10 13:36:04 -07006211
Christopher Tatea53146c2010-09-07 11:57:52 -07006212 /* Drag/drop */
6213 public IBinder prepareDrag(IWindow window, boolean localOnly,
6214 int width, int height, Surface outSurface) {
6215 return prepareDragSurface(window, mSurfaceSession, localOnly,
6216 width, height, outSurface);
6217 }
6218
6219 public boolean performDrag(IWindow window, IBinder dragToken,
6220 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6221 ClipData data) {
6222 if (DEBUG_DRAG) {
6223 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6224 }
6225
6226 synchronized (mWindowMap) {
6227 if (mDragState == null) {
6228 Slog.w(TAG, "No drag prepared");
6229 throw new IllegalStateException("performDrag() without prepareDrag()");
6230 }
6231
6232 if (dragToken != mDragState.mToken) {
6233 Slog.w(TAG, "Performing mismatched drag");
6234 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6235 }
6236
6237 WindowState callingWin = windowForClientLocked(null, window, false);
6238 if (callingWin == null) {
6239 Slog.w(TAG, "Bad requesting window " + window);
6240 return false; // !!! TODO: throw here?
6241 }
6242
6243 // !!! TODO: if input is not still focused on the initiating window, fail
6244 // the drag initiation (e.g. an alarm window popped up just as the application
6245 // called performDrag()
6246
6247 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6248
Christopher Tate2c095f32010-10-04 14:13:40 -07006249 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6250 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006251
Chris Tateb478f462010-10-15 16:02:26 -07006252 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6253 // the actual drag event dispatch stuff in the dragstate
6254
Christopher Tatea53146c2010-09-07 11:57:52 -07006255 mDragState.register();
6256 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006257 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6258 mDragState.mServerChannel)) {
6259 Slog.e(TAG, "Unable to transfer touch focus");
6260 mDragState.unregister();
6261 mDragState = null;
6262 mInputMonitor.updateInputWindowsLw();
6263 return false;
6264 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006265
6266 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006267 mDragState.mCurrentX = touchX;
6268 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006269 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006270
6271 // remember the thumb offsets for later
6272 mDragState.mThumbOffsetX = thumbCenterX;
6273 mDragState.mThumbOffsetY = thumbCenterY;
6274
6275 // Make the surface visible at the proper location
6276 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006277 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006278 try {
6279 surface.setPosition((int)(touchX - thumbCenterX),
6280 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006281 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006282 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006283 surface.show();
6284 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006285 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006286 }
6287 }
6288
6289 return true; // success!
6290 }
6291
Chris Tated4533f142010-10-19 15:15:08 -07006292 public void reportDropResult(IWindow window, boolean consumed) {
6293 IBinder token = window.asBinder();
6294 if (DEBUG_DRAG) {
6295 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6296 }
6297
6298 synchronized (mWindowMap) {
6299 if (mDragState.mToken != token) {
6300 Slog.w(TAG, "Invalid drop-result claim by " + window);
6301 throw new IllegalStateException("reportDropResult() by non-recipient");
6302 }
6303
6304 // The right window has responded, even if it's no longer around,
6305 // so be sure to halt the timeout even if the later WindowState
6306 // lookup fails.
6307 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6308
6309 WindowState callingWin = windowForClientLocked(null, window, false);
6310 if (callingWin == null) {
6311 Slog.w(TAG, "Bad result-reporting window " + window);
6312 return; // !!! TODO: throw here?
6313 }
6314
6315 mDragState.mDragResult = consumed;
6316 mDragState.endDragLw();
6317 }
6318 }
6319
Christopher Tatea53146c2010-09-07 11:57:52 -07006320 public void dragRecipientEntered(IWindow window) {
6321 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006322 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006323 }
6324 }
6325
6326 public void dragRecipientExited(IWindow window) {
6327 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006328 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006329 }
6330 }
6331
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006332 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006333 synchronized(mWindowMap) {
6334 long ident = Binder.clearCallingIdentity();
6335 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006336 setWindowWallpaperPositionLocked(
6337 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006338 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006339 } finally {
6340 Binder.restoreCallingIdentity(ident);
6341 }
6342 }
6343 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006344
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006345 public void wallpaperOffsetsComplete(IBinder window) {
6346 WindowManagerService.this.wallpaperOffsetsComplete(window);
6347 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006348
Dianne Hackborn75804932009-10-20 20:15:20 -07006349 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6350 int z, Bundle extras, boolean sync) {
6351 synchronized(mWindowMap) {
6352 long ident = Binder.clearCallingIdentity();
6353 try {
6354 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006355 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006356 action, x, y, z, extras, sync);
6357 } finally {
6358 Binder.restoreCallingIdentity(ident);
6359 }
6360 }
6361 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006362
Dianne Hackborn75804932009-10-20 20:15:20 -07006363 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6364 WindowManagerService.this.wallpaperCommandComplete(window, result);
6365 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 void windowAddedLocked() {
6368 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006369 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 TAG, "First window added to " + this + ", creating SurfaceSession");
6371 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006372 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006373 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 mSessions.add(this);
6375 }
6376 mNumWindow++;
6377 }
6378
6379 void windowRemovedLocked() {
6380 mNumWindow--;
6381 killSessionLocked();
6382 }
Romain Guy06882f82009-06-10 13:36:04 -07006383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006384 void killSessionLocked() {
6385 if (mNumWindow <= 0 && mClientDead) {
6386 mSessions.remove(this);
6387 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006388 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 TAG, "Last window removed from " + this
6390 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006391 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006392 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006393 try {
6394 mSurfaceSession.kill();
6395 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006396 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 + mSurfaceSession + " in session " + this
6398 + ": " + e.toString());
6399 }
6400 mSurfaceSession = null;
6401 }
6402 }
6403 }
Romain Guy06882f82009-06-10 13:36:04 -07006404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006405 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006406 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6407 pw.print(" mClientDead="); pw.print(mClientDead);
6408 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 }
6410
6411 @Override
6412 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006413 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 }
6415 }
6416
6417 // -------------------------------------------------------------
6418 // Client Window State
6419 // -------------------------------------------------------------
6420
6421 private final class WindowState implements WindowManagerPolicy.WindowState {
6422 final Session mSession;
6423 final IWindow mClient;
6424 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006425 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006426 AppWindowToken mAppToken;
6427 AppWindowToken mTargetAppToken;
6428 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6429 final DeathRecipient mDeathRecipient;
6430 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006431 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 final int mBaseLayer;
6433 final int mSubLayer;
6434 final boolean mLayoutAttached;
6435 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006436 final boolean mIsWallpaper;
6437 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 int mViewVisibility;
6439 boolean mPolicyVisibility = true;
6440 boolean mPolicyVisibilityAfterAnim = true;
6441 boolean mAppFreezing;
6442 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006443 boolean mReportDestroySurface;
6444 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006445 boolean mAttachedHidden; // is our parent window hidden?
6446 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006447 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 int mRequestedWidth;
6449 int mRequestedHeight;
6450 int mLastRequestedWidth;
6451 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 int mLayer;
6453 int mAnimLayer;
6454 int mLastLayer;
6455 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006456 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006457 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006459 int mLayoutSeq = -1;
6460
6461 Configuration mConfiguration = null;
6462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006463 // Actual frame shown on-screen (may be modified by animation)
6464 final Rect mShownFrame = new Rect();
6465 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006468 * Set when we have changed the size of the surface, to know that
6469 * we must tell them application to resize (and thus redraw itself).
6470 */
6471 boolean mSurfaceResized;
6472
6473 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006474 * Insets that determine the actually visible area
6475 */
6476 final Rect mVisibleInsets = new Rect();
6477 final Rect mLastVisibleInsets = new Rect();
6478 boolean mVisibleInsetsChanged;
6479
6480 /**
6481 * Insets that are covered by system windows
6482 */
6483 final Rect mContentInsets = new Rect();
6484 final Rect mLastContentInsets = new Rect();
6485 boolean mContentInsetsChanged;
6486
6487 /**
6488 * Set to true if we are waiting for this window to receive its
6489 * given internal insets before laying out other windows based on it.
6490 */
6491 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006493 /**
6494 * These are the content insets that were given during layout for
6495 * this window, to be applied to windows behind it.
6496 */
6497 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006499 /**
6500 * These are the visible insets that were given during layout for
6501 * this window, to be applied to windows behind it.
6502 */
6503 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 /**
6506 * Flag indicating whether the touchable region should be adjusted by
6507 * the visible insets; if false the area outside the visible insets is
6508 * NOT touchable, so we must use those to adjust the frame during hit
6509 * tests.
6510 */
6511 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 // Current transformation being applied.
6514 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6515 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6516 float mHScale=1, mVScale=1;
6517 float mLastHScale=1, mLastVScale=1;
6518 final Matrix mTmpMatrix = new Matrix();
6519
6520 // "Real" frame that the application sees.
6521 final Rect mFrame = new Rect();
6522 final Rect mLastFrame = new Rect();
6523
6524 final Rect mContainingFrame = new Rect();
6525 final Rect mDisplayFrame = new Rect();
6526 final Rect mContentFrame = new Rect();
6527 final Rect mVisibleFrame = new Rect();
6528
6529 float mShownAlpha = 1;
6530 float mAlpha = 1;
6531 float mLastAlpha = 1;
6532
6533 // Set to true if, when the window gets displayed, it should perform
6534 // an enter animation.
6535 boolean mEnterAnimationPending;
6536
6537 // Currently running animation.
6538 boolean mAnimating;
6539 boolean mLocalAnimating;
6540 Animation mAnimation;
6541 boolean mAnimationIsEntrance;
6542 boolean mHasTransformation;
6543 boolean mHasLocalTransformation;
6544 final Transformation mTransformation = new Transformation();
6545
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006546 // If a window showing a wallpaper: the requested offset for the
6547 // wallpaper; if a wallpaper window: the currently applied offset.
6548 float mWallpaperX = -1;
6549 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006550
6551 // If a window showing a wallpaper: what fraction of the offset
6552 // range corresponds to a full virtual screen.
6553 float mWallpaperXStep = -1;
6554 float mWallpaperYStep = -1;
6555
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006556 // Wallpaper windows: pixels offset based on above variables.
6557 int mXOffset;
6558 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006560 // This is set after IWindowSession.relayout() has been called at
6561 // least once for the window. It allows us to detect the situation
6562 // where we don't yet have a surface, but should have one soon, so
6563 // we can give the window focus before waiting for the relayout.
6564 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006566 // This is set after the Surface has been created but before the
6567 // window has been drawn. During this time the surface is hidden.
6568 boolean mDrawPending;
6569
6570 // This is set after the window has finished drawing for the first
6571 // time but before its surface is shown. The surface will be
6572 // displayed when the next layout is run.
6573 boolean mCommitDrawPending;
6574
6575 // This is set during the time after the window's drawing has been
6576 // committed, and before its surface is actually shown. It is used
6577 // to delay showing the surface until all windows in a token are ready
6578 // to be shown.
6579 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006581 // Set when the window has been shown in the screen the first time.
6582 boolean mHasDrawn;
6583
6584 // Currently running an exit animation?
6585 boolean mExiting;
6586
6587 // Currently on the mDestroySurface list?
6588 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 // Completely remove from window manager after exit animation?
6591 boolean mRemoveOnExit;
6592
6593 // Set when the orientation is changing and this window has not yet
6594 // been updated for the new orientation.
6595 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 // Is this window now (or just being) removed?
6598 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006599
Dianne Hackborn16064f92010-03-25 00:47:24 -07006600 // For debugging, this is the last information given to the surface flinger.
6601 boolean mSurfaceShown;
6602 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6603 int mSurfaceLayer;
6604 float mSurfaceAlpha;
6605
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006606 // Input channel
6607 InputChannel mInputChannel;
6608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006609 WindowState(Session s, IWindow c, WindowToken token,
6610 WindowState attachedWindow, WindowManager.LayoutParams a,
6611 int viewVisibility) {
6612 mSession = s;
6613 mClient = c;
6614 mToken = token;
6615 mAttrs.copyFrom(a);
6616 mViewVisibility = viewVisibility;
6617 DeathRecipient deathRecipient = new DeathRecipient();
6618 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006619 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006620 TAG, "Window " + this + " client=" + c.asBinder()
6621 + " token=" + token + " (" + mAttrs.token + ")");
6622 try {
6623 c.asBinder().linkToDeath(deathRecipient, 0);
6624 } catch (RemoteException e) {
6625 mDeathRecipient = null;
6626 mAttachedWindow = null;
6627 mLayoutAttached = false;
6628 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006629 mIsWallpaper = false;
6630 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006631 mBaseLayer = 0;
6632 mSubLayer = 0;
6633 return;
6634 }
6635 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006637 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6638 mAttrs.type <= LAST_SUB_WINDOW)) {
6639 // The multiplier here is to reserve space for multiple
6640 // windows in the same type layer.
6641 mBaseLayer = mPolicy.windowTypeToLayerLw(
6642 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6643 + TYPE_LAYER_OFFSET;
6644 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6645 mAttachedWindow = attachedWindow;
6646 mAttachedWindow.mChildWindows.add(this);
6647 mLayoutAttached = mAttrs.type !=
6648 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6649 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6650 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006651 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6652 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006653 } else {
6654 // The multiplier here is to reserve space for multiple
6655 // windows in the same type layer.
6656 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6657 * TYPE_LAYER_MULTIPLIER
6658 + TYPE_LAYER_OFFSET;
6659 mSubLayer = 0;
6660 mAttachedWindow = null;
6661 mLayoutAttached = false;
6662 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6663 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006664 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6665 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006666 }
6667
6668 WindowState appWin = this;
6669 while (appWin.mAttachedWindow != null) {
6670 appWin = mAttachedWindow;
6671 }
6672 WindowToken appToken = appWin.mToken;
6673 while (appToken.appWindowToken == null) {
6674 WindowToken parent = mTokenMap.get(appToken.token);
6675 if (parent == null || appToken == parent) {
6676 break;
6677 }
6678 appToken = parent;
6679 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006680 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006681 mAppToken = appToken.appWindowToken;
6682
6683 mSurface = null;
6684 mRequestedWidth = 0;
6685 mRequestedHeight = 0;
6686 mLastRequestedWidth = 0;
6687 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006688 mXOffset = 0;
6689 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 mLayer = 0;
6691 mAnimLayer = 0;
6692 mLastLayer = 0;
6693 }
6694
6695 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006696 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006697 TAG, "Attaching " + this + " token=" + mToken
6698 + ", list=" + mToken.windows);
6699 mSession.windowAddedLocked();
6700 }
6701
6702 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6703 mHaveFrame = true;
6704
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006705 final Rect container = mContainingFrame;
6706 container.set(pf);
6707
6708 final Rect display = mDisplayFrame;
6709 display.set(df);
6710
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006711 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006712 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006713 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6714 display.intersect(mCompatibleScreenFrame);
6715 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006716 }
6717
6718 final int pw = container.right - container.left;
6719 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006720
6721 int w,h;
6722 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6723 w = mAttrs.width < 0 ? pw : mAttrs.width;
6724 h = mAttrs.height< 0 ? ph : mAttrs.height;
6725 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006726 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6727 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 }
Romain Guy06882f82009-06-10 13:36:04 -07006729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006730 final Rect content = mContentFrame;
6731 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006733 final Rect visible = mVisibleFrame;
6734 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006736 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006737 final int fw = frame.width();
6738 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6741 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6742
6743 Gravity.apply(mAttrs.gravity, w, h, container,
6744 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6745 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6746
6747 //System.out.println("Out: " + mFrame);
6748
6749 // Now make sure the window fits in the overall display.
6750 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 // Make sure the content and visible frames are inside of the
6753 // final window frame.
6754 if (content.left < frame.left) content.left = frame.left;
6755 if (content.top < frame.top) content.top = frame.top;
6756 if (content.right > frame.right) content.right = frame.right;
6757 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6758 if (visible.left < frame.left) visible.left = frame.left;
6759 if (visible.top < frame.top) visible.top = frame.top;
6760 if (visible.right > frame.right) visible.right = frame.right;
6761 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006763 final Rect contentInsets = mContentInsets;
6764 contentInsets.left = content.left-frame.left;
6765 contentInsets.top = content.top-frame.top;
6766 contentInsets.right = frame.right-content.right;
6767 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 final Rect visibleInsets = mVisibleInsets;
6770 visibleInsets.left = visible.left-frame.left;
6771 visibleInsets.top = visible.top-frame.top;
6772 visibleInsets.right = frame.right-visible.right;
6773 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006774
Dianne Hackborn284ac932009-08-28 10:34:25 -07006775 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6776 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006777 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006778 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 if (localLOGV) {
6781 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6782 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006783 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 + mRequestedWidth + ", mRequestedheight="
6785 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6786 + "): frame=" + mFrame.toShortString()
6787 + " ci=" + contentInsets.toShortString()
6788 + " vi=" + visibleInsets.toShortString());
6789 //}
6790 }
6791 }
Romain Guy06882f82009-06-10 13:36:04 -07006792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006793 public Rect getFrameLw() {
6794 return mFrame;
6795 }
6796
6797 public Rect getShownFrameLw() {
6798 return mShownFrame;
6799 }
6800
6801 public Rect getDisplayFrameLw() {
6802 return mDisplayFrame;
6803 }
6804
6805 public Rect getContentFrameLw() {
6806 return mContentFrame;
6807 }
6808
6809 public Rect getVisibleFrameLw() {
6810 return mVisibleFrame;
6811 }
6812
6813 public boolean getGivenInsetsPendingLw() {
6814 return mGivenInsetsPending;
6815 }
6816
6817 public Rect getGivenContentInsetsLw() {
6818 return mGivenContentInsets;
6819 }
Romain Guy06882f82009-06-10 13:36:04 -07006820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006821 public Rect getGivenVisibleInsetsLw() {
6822 return mGivenVisibleInsets;
6823 }
Romain Guy06882f82009-06-10 13:36:04 -07006824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 public WindowManager.LayoutParams getAttrs() {
6826 return mAttrs;
6827 }
6828
6829 public int getSurfaceLayer() {
6830 return mLayer;
6831 }
Romain Guy06882f82009-06-10 13:36:04 -07006832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006833 public IApplicationToken getAppToken() {
6834 return mAppToken != null ? mAppToken.appToken : null;
6835 }
Jeff Brown349703e2010-06-22 01:27:15 -07006836
6837 public long getInputDispatchingTimeoutNanos() {
6838 return mAppToken != null
6839 ? mAppToken.inputDispatchingTimeoutNanos
6840 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6841 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006842
6843 public boolean hasAppShownWindows() {
6844 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6845 }
6846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006848 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006849 TAG, "Setting animation in " + this + ": " + anim);
6850 mAnimating = false;
6851 mLocalAnimating = false;
6852 mAnimation = anim;
6853 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6854 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6855 }
6856
6857 public void clearAnimation() {
6858 if (mAnimation != null) {
6859 mAnimating = true;
6860 mLocalAnimating = false;
6861 mAnimation = null;
6862 }
6863 }
Romain Guy06882f82009-06-10 13:36:04 -07006864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006865 Surface createSurfaceLocked() {
6866 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006867 mReportDestroySurface = false;
6868 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 mDrawPending = true;
6870 mCommitDrawPending = false;
6871 mReadyToShow = false;
6872 if (mAppToken != null) {
6873 mAppToken.allDrawn = false;
6874 }
6875
6876 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006877 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 flags |= Surface.PUSH_BUFFERS;
6879 }
6880
6881 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6882 flags |= Surface.SECURE;
6883 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006884 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006885 TAG, "Creating surface in session "
6886 + mSession.mSurfaceSession + " window " + this
6887 + " w=" + mFrame.width()
6888 + " h=" + mFrame.height() + " format="
6889 + mAttrs.format + " flags=" + flags);
6890
6891 int w = mFrame.width();
6892 int h = mFrame.height();
6893 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6894 // for a scaled surface, we always want the requested
6895 // size.
6896 w = mRequestedWidth;
6897 h = mRequestedHeight;
6898 }
6899
Romain Guy9825ec62009-10-01 00:58:09 -07006900 // Something is wrong and SurfaceFlinger will not like this,
6901 // try to revert to sane values
6902 if (w <= 0) w = 1;
6903 if (h <= 0) h = 1;
6904
Dianne Hackborn16064f92010-03-25 00:47:24 -07006905 mSurfaceShown = false;
6906 mSurfaceLayer = 0;
6907 mSurfaceAlpha = 1;
6908 mSurfaceX = 0;
6909 mSurfaceY = 0;
6910 mSurfaceW = w;
6911 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006912 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006913 final boolean isHwAccelerated = (mAttrs.flags &
6914 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6915 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6916 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6917 flags |= Surface.OPAQUE;
6918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006919 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006920 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006921 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006922 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006923 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006924 + mSurface + " IN SESSION "
6925 + mSession.mSurfaceSession
6926 + ": pid=" + mSession.mPid + " format="
6927 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006928 + Integer.toHexString(flags)
6929 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006930 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006931 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 reclaimSomeSurfaceMemoryLocked(this, "create");
6933 return null;
6934 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006935 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 return null;
6937 }
Romain Guy06882f82009-06-10 13:36:04 -07006938
Joe Onorato8a9b2202010-02-26 18:56:32 -08006939 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006940 TAG, "Got surface: " + mSurface
6941 + ", set left=" + mFrame.left + " top=" + mFrame.top
6942 + ", animLayer=" + mAnimLayer);
6943 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006944 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006945 if (SHOW_TRANSACTIONS) logSurface(this,
6946 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6947 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6948 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 }
6950 Surface.openTransaction();
6951 try {
6952 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006953 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006954 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006955 mSurface.setPosition(mSurfaceX, mSurfaceY);
6956 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006958 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 mSurface.hide();
6960 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006961 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 mSurface.setFlags(Surface.SURFACE_DITHER,
6963 Surface.SURFACE_DITHER);
6964 }
6965 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006966 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006967 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6968 }
6969 mLastHidden = true;
6970 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006971 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006972 Surface.closeTransaction();
6973 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006974 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006975 TAG, "Created surface " + this);
6976 }
6977 return mSurface;
6978 }
Romain Guy06882f82009-06-10 13:36:04 -07006979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006980 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 if (mAppToken != null && this == mAppToken.startingWindow) {
6982 mAppToken.startingDisplayed = false;
6983 }
Romain Guy06882f82009-06-10 13:36:04 -07006984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006985 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006986 mDrawPending = false;
6987 mCommitDrawPending = false;
6988 mReadyToShow = false;
6989
6990 int i = mChildWindows.size();
6991 while (i > 0) {
6992 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006993 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006994 c.mAttachedHidden = true;
6995 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006996
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006997 if (mReportDestroySurface) {
6998 mReportDestroySurface = false;
6999 mSurfacePendingDestroy = true;
7000 try {
7001 mClient.dispatchGetNewSurface();
7002 // We'll really destroy on the next time around.
7003 return;
7004 } catch (RemoteException e) {
7005 }
7006 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007008 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007009 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007010 RuntimeException e = null;
7011 if (!HIDE_STACK_CRAWLS) {
7012 e = new RuntimeException();
7013 e.fillInStackTrace();
7014 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007015 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007016 + mSurface + ", session " + mSession, e);
7017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007019 RuntimeException e = null;
7020 if (!HIDE_STACK_CRAWLS) {
7021 e = new RuntimeException();
7022 e.fillInStackTrace();
7023 }
7024 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007025 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007026 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007027 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007028 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007029 + " surface " + mSurface + " session " + mSession
7030 + ": " + e.toString());
7031 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007032
Dianne Hackborn16064f92010-03-25 00:47:24 -07007033 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 }
7036 }
7037
7038 boolean finishDrawingLocked() {
7039 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007040 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007041 TAG, "finishDrawingLocked: " + mSurface);
7042 mCommitDrawPending = true;
7043 mDrawPending = false;
7044 return true;
7045 }
7046 return false;
7047 }
7048
7049 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007050 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007051 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007052 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007053 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 }
7055 mCommitDrawPending = false;
7056 mReadyToShow = true;
7057 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7058 final AppWindowToken atoken = mAppToken;
7059 if (atoken == null || atoken.allDrawn || starting) {
7060 performShowLocked();
7061 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007062 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 }
7064
7065 // This must be called while inside a transaction.
7066 boolean performShowLocked() {
7067 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007068 RuntimeException e = null;
7069 if (!HIDE_STACK_CRAWLS) {
7070 e = new RuntimeException();
7071 e.fillInStackTrace();
7072 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007073 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7075 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7076 }
7077 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007078 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7079 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007080 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007081 + " during animation: policyVis=" + mPolicyVisibility
7082 + " attHidden=" + mAttachedHidden
7083 + " tok.hiddenRequested="
7084 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007085 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007086 + (mAppToken != null ? mAppToken.hidden : false)
7087 + " animating=" + mAnimating
7088 + " tok animating="
7089 + (mAppToken != null ? mAppToken.animating : false));
7090 if (!showSurfaceRobustlyLocked(this)) {
7091 return false;
7092 }
7093 mLastAlpha = -1;
7094 mHasDrawn = true;
7095 mLastHidden = false;
7096 mReadyToShow = false;
7097 enableScreenIfNeededLocked();
7098
7099 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 int i = mChildWindows.size();
7102 while (i > 0) {
7103 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007104 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007105 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007107 if (c.mSurface != null) {
7108 c.performShowLocked();
7109 // It hadn't been shown, which means layout not
7110 // performed on it, so now we want to make sure to
7111 // do a layout. If called from within the transaction
7112 // loop, this will cause it to restart with a new
7113 // layout.
7114 mLayoutNeeded = true;
7115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007116 }
7117 }
Romain Guy06882f82009-06-10 13:36:04 -07007118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007119 if (mAttrs.type != TYPE_APPLICATION_STARTING
7120 && mAppToken != null) {
7121 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007122
Dianne Hackborn248b1882009-09-16 16:46:44 -07007123 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007124 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007125 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007127 // If this initial window is animating, stop it -- we
7128 // will do an animation to reveal it from behind the
7129 // starting window, so there is no need for it to also
7130 // be doing its own stuff.
7131 if (mAnimation != null) {
7132 mAnimation = null;
7133 // Make sure we clean up the animation.
7134 mAnimating = true;
7135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 mFinishedStarting.add(mAppToken);
7137 mH.sendEmptyMessage(H.FINISHED_STARTING);
7138 }
7139 mAppToken.updateReportedVisibilityLocked();
7140 }
7141 }
7142 return true;
7143 }
Romain Guy06882f82009-06-10 13:36:04 -07007144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 // This must be called while inside a transaction. Returns true if
7146 // there is more animation to run.
7147 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007148 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007149 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007151 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7152 mHasTransformation = true;
7153 mHasLocalTransformation = true;
7154 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007155 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 TAG, "Starting animation in " + this +
7157 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7158 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7159 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7160 mAnimation.setStartTime(currentTime);
7161 mLocalAnimating = true;
7162 mAnimating = true;
7163 }
7164 mTransformation.clear();
7165 final boolean more = mAnimation.getTransformation(
7166 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007167 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007168 TAG, "Stepped animation in " + this +
7169 ": more=" + more + ", xform=" + mTransformation);
7170 if (more) {
7171 // we're not done!
7172 return true;
7173 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007174 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007175 TAG, "Finished animation in " + this +
7176 " @ " + currentTime);
7177 mAnimation = null;
7178 //WindowManagerService.this.dump();
7179 }
7180 mHasLocalTransformation = false;
7181 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007182 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007183 // When our app token is animating, we kind-of pretend like
7184 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7185 // part of this check means that we will only do this if
7186 // our window is not currently exiting, or it is not
7187 // locally animating itself. The idea being that one that
7188 // is exiting and doing a local animation should be removed
7189 // once that animation is done.
7190 mAnimating = true;
7191 mHasTransformation = true;
7192 mTransformation.clear();
7193 return false;
7194 } else if (mHasTransformation) {
7195 // Little trick to get through the path below to act like
7196 // we have finished an animation.
7197 mAnimating = true;
7198 } else if (isAnimating()) {
7199 mAnimating = true;
7200 }
7201 } else if (mAnimation != null) {
7202 // If the display is frozen, and there is a pending animation,
7203 // clear it and make sure we run the cleanup code.
7204 mAnimating = true;
7205 mLocalAnimating = true;
7206 mAnimation = null;
7207 }
Romain Guy06882f82009-06-10 13:36:04 -07007208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007209 if (!mAnimating && !mLocalAnimating) {
7210 return false;
7211 }
7212
Joe Onorato8a9b2202010-02-26 18:56:32 -08007213 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007214 TAG, "Animation done in " + this + ": exiting=" + mExiting
7215 + ", reportedVisible="
7216 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 mAnimating = false;
7219 mLocalAnimating = false;
7220 mAnimation = null;
7221 mAnimLayer = mLayer;
7222 if (mIsImWindow) {
7223 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007224 } else if (mIsWallpaper) {
7225 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007226 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007227 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007228 + " anim layer: " + mAnimLayer);
7229 mHasTransformation = false;
7230 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007231 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7232 if (DEBUG_VISIBILITY) {
7233 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7234 + mPolicyVisibilityAfterAnim);
7235 }
7236 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7237 if (!mPolicyVisibility) {
7238 if (mCurrentFocus == this) {
7239 mFocusMayChange = true;
7240 }
7241 // Window is no longer visible -- make sure if we were waiting
7242 // for it to be displayed before enabling the display, that
7243 // we allow the display to be enabled now.
7244 enableScreenIfNeededLocked();
7245 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007247 mTransformation.clear();
7248 if (mHasDrawn
7249 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7250 && mAppToken != null
7251 && mAppToken.firstWindowDrawn
7252 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007253 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007254 + mToken + ": first real window done animating");
7255 mFinishedStarting.add(mAppToken);
7256 mH.sendEmptyMessage(H.FINISHED_STARTING);
7257 }
Romain Guy06882f82009-06-10 13:36:04 -07007258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007259 finishExit();
7260
7261 if (mAppToken != null) {
7262 mAppToken.updateReportedVisibilityLocked();
7263 }
7264
7265 return false;
7266 }
7267
7268 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007269 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007270 TAG, "finishExit in " + this
7271 + ": exiting=" + mExiting
7272 + " remove=" + mRemoveOnExit
7273 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 final int N = mChildWindows.size();
7276 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007277 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007278 }
Romain Guy06882f82009-06-10 13:36:04 -07007279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007280 if (!mExiting) {
7281 return;
7282 }
Romain Guy06882f82009-06-10 13:36:04 -07007283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 if (isWindowAnimating()) {
7285 return;
7286 }
7287
Joe Onorato8a9b2202010-02-26 18:56:32 -08007288 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 TAG, "Exit animation finished in " + this
7290 + ": remove=" + mRemoveOnExit);
7291 if (mSurface != null) {
7292 mDestroySurface.add(this);
7293 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007294 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007295 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007296 try {
7297 mSurface.hide();
7298 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007299 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 }
7301 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007302 }
7303 mExiting = false;
7304 if (mRemoveOnExit) {
7305 mPendingRemove.add(this);
7306 mRemoveOnExit = false;
7307 }
7308 }
Romain Guy06882f82009-06-10 13:36:04 -07007309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007310 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7311 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7312 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7313 if (dtdx < -.000001f || dtdx > .000001f) return false;
7314 if (dsdy < -.000001f || dsdy > .000001f) return false;
7315 return true;
7316 }
Romain Guy06882f82009-06-10 13:36:04 -07007317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007318 void computeShownFrameLocked() {
7319 final boolean selfTransformation = mHasLocalTransformation;
7320 Transformation attachedTransformation =
7321 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7322 ? mAttachedWindow.mTransformation : null;
7323 Transformation appTransformation =
7324 (mAppToken != null && mAppToken.hasTransformation)
7325 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007326
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007327 // Wallpapers are animated based on the "real" window they
7328 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007329 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007330 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007331 if (mWallpaperTarget.mHasLocalTransformation &&
7332 mWallpaperTarget.mAnimation != null &&
7333 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007334 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007335 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007336 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007337 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007338 }
7339 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007340 mWallpaperTarget.mAppToken.hasTransformation &&
7341 mWallpaperTarget.mAppToken.animation != null &&
7342 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007343 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007344 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007345 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007346 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007347 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007348 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 if (selfTransformation || attachedTransformation != null
7351 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007352 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353 final Rect frame = mFrame;
7354 final float tmpFloats[] = mTmpFloats;
7355 final Matrix tmpMatrix = mTmpMatrix;
7356
7357 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007358 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007360 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007361 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007362 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007363 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007364 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007365 }
7366 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007367 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 }
7369
7370 // "convert" it into SurfaceFlinger's format
7371 // (a 2x2 matrix + an offset)
7372 // Here we must not transform the position of the surface
7373 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007374 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 tmpMatrix.getValues(tmpFloats);
7377 mDsDx = tmpFloats[Matrix.MSCALE_X];
7378 mDtDx = tmpFloats[Matrix.MSKEW_X];
7379 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7380 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007381 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7382 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 int w = frame.width();
7384 int h = frame.height();
7385 mShownFrame.set(x, y, x+w, y+h);
7386
7387 // Now set the alpha... but because our current hardware
7388 // can't do alpha transformation on a non-opaque surface,
7389 // turn it off if we are running an animation that is also
7390 // transforming since it is more important to have that
7391 // animation be smooth.
7392 mShownAlpha = mAlpha;
7393 if (!mLimitedAlphaCompositing
7394 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7395 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7396 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007397 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007398 if (selfTransformation) {
7399 mShownAlpha *= mTransformation.getAlpha();
7400 }
7401 if (attachedTransformation != null) {
7402 mShownAlpha *= attachedTransformation.getAlpha();
7403 }
7404 if (appTransformation != null) {
7405 mShownAlpha *= appTransformation.getAlpha();
7406 }
7407 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007408 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 }
Romain Guy06882f82009-06-10 13:36:04 -07007410
Joe Onorato8a9b2202010-02-26 18:56:32 -08007411 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007412 TAG, "Continuing animation in " + this +
7413 ": " + mShownFrame +
7414 ", alpha=" + mTransformation.getAlpha());
7415 return;
7416 }
Romain Guy06882f82009-06-10 13:36:04 -07007417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007419 if (mXOffset != 0 || mYOffset != 0) {
7420 mShownFrame.offset(mXOffset, mYOffset);
7421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007422 mShownAlpha = mAlpha;
7423 mDsDx = 1;
7424 mDtDx = 0;
7425 mDsDy = 0;
7426 mDtDy = 1;
7427 }
Romain Guy06882f82009-06-10 13:36:04 -07007428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 /**
7430 * Is this window visible? It is not visible if there is no
7431 * surface, or we are in the process of running an exit animation
7432 * that will remove the surface, or its app token has been hidden.
7433 */
7434 public boolean isVisibleLw() {
7435 final AppWindowToken atoken = mAppToken;
7436 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7437 && (atoken == null || !atoken.hiddenRequested)
7438 && !mExiting && !mDestroying;
7439 }
7440
7441 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007442 * Like {@link #isVisibleLw}, but also counts a window that is currently
7443 * "hidden" behind the keyguard as visible. This allows us to apply
7444 * things like window flags that impact the keyguard.
7445 * XXX I am starting to think we need to have ANOTHER visibility flag
7446 * for this "hidden behind keyguard" state rather than overloading
7447 * mPolicyVisibility. Ungh.
7448 */
7449 public boolean isVisibleOrBehindKeyguardLw() {
7450 final AppWindowToken atoken = mAppToken;
7451 return mSurface != null && !mAttachedHidden
7452 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007453 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007454 && !mExiting && !mDestroying;
7455 }
7456
7457 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007458 * Is this window visible, ignoring its app token? It is not visible
7459 * if there is no surface, or we are in the process of running an exit animation
7460 * that will remove the surface.
7461 */
7462 public boolean isWinVisibleLw() {
7463 final AppWindowToken atoken = mAppToken;
7464 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7465 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7466 && !mExiting && !mDestroying;
7467 }
7468
7469 /**
7470 * The same as isVisible(), but follows the current hidden state of
7471 * the associated app token, not the pending requested hidden state.
7472 */
7473 boolean isVisibleNow() {
7474 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007475 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 }
7477
7478 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007479 * Can this window possibly be a drag/drop target? The test here is
7480 * a combination of the above "visible now" with the check that the
7481 * Input Manager uses when discarding windows from input consideration.
7482 */
7483 boolean isPotentialDragTarget() {
7484 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7485 }
7486
7487 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007488 * Same as isVisible(), but we also count it as visible between the
7489 * call to IWindowSession.add() and the first relayout().
7490 */
7491 boolean isVisibleOrAdding() {
7492 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007493 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7495 && mPolicyVisibility && !mAttachedHidden
7496 && (atoken == null || !atoken.hiddenRequested)
7497 && !mExiting && !mDestroying;
7498 }
7499
7500 /**
7501 * Is this window currently on-screen? It is on-screen either if it
7502 * is visible or it is currently running an animation before no longer
7503 * being visible.
7504 */
7505 boolean isOnScreen() {
7506 final AppWindowToken atoken = mAppToken;
7507 if (atoken != null) {
7508 return mSurface != null && mPolicyVisibility && !mDestroying
7509 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007510 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 } else {
7512 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007513 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007514 }
7515 }
Romain Guy06882f82009-06-10 13:36:04 -07007516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 /**
7518 * Like isOnScreen(), but we don't return true if the window is part
7519 * of a transition that has not yet been started.
7520 */
7521 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007522 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007523 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007524 return false;
7525 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007527 final boolean animating = atoken != null
7528 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007529 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007530 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7531 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007532 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007533 }
7534
7535 /** Is the window or its container currently animating? */
7536 boolean isAnimating() {
7537 final WindowState attached = mAttachedWindow;
7538 final AppWindowToken atoken = mAppToken;
7539 return mAnimation != null
7540 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007541 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007542 (atoken.animation != null
7543 || atoken.inPendingTransaction));
7544 }
7545
7546 /** Is this window currently animating? */
7547 boolean isWindowAnimating() {
7548 return mAnimation != null;
7549 }
7550
7551 /**
7552 * Like isOnScreen, but returns false if the surface hasn't yet
7553 * been drawn.
7554 */
7555 public boolean isDisplayedLw() {
7556 final AppWindowToken atoken = mAppToken;
7557 return mSurface != null && mPolicyVisibility && !mDestroying
7558 && !mDrawPending && !mCommitDrawPending
7559 && ((!mAttachedHidden &&
7560 (atoken == null || !atoken.hiddenRequested))
7561 || mAnimating);
7562 }
7563
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007564 /**
7565 * Returns true if the window has a surface that it has drawn a
7566 * complete UI in to.
7567 */
7568 public boolean isDrawnLw() {
7569 final AppWindowToken atoken = mAppToken;
7570 return mSurface != null && !mDestroying
7571 && !mDrawPending && !mCommitDrawPending;
7572 }
7573
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007574 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007575 * Return true if the window is opaque and fully drawn. This indicates
7576 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007577 */
7578 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007579 return (mAttrs.format == PixelFormat.OPAQUE
7580 || mAttrs.type == TYPE_WALLPAPER)
7581 && mSurface != null && mAnimation == null
7582 && (mAppToken == null || mAppToken.animation == null)
7583 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007584 }
7585
7586 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7587 return
7588 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007589 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7590 // only if it's visible
7591 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007592 // and only if the application fills the compatible screen
7593 mFrame.left <= mCompatibleScreenFrame.left &&
7594 mFrame.top <= mCompatibleScreenFrame.top &&
7595 mFrame.right >= mCompatibleScreenFrame.right &&
7596 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007597 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007598 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007599 }
7600
7601 boolean isFullscreen(int screenWidth, int screenHeight) {
7602 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007603 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007604 }
7605
7606 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007607 disposeInputChannel();
7608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 if (mAttachedWindow != null) {
7610 mAttachedWindow.mChildWindows.remove(this);
7611 }
7612 destroySurfaceLocked();
7613 mSession.windowRemovedLocked();
7614 try {
7615 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7616 } catch (RuntimeException e) {
7617 // Ignore if it has already been removed (usually because
7618 // we are doing this as part of processing a death note.)
7619 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007620 }
7621
7622 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007623 if (mInputChannel != null) {
7624 mInputManager.unregisterInputChannel(mInputChannel);
7625
7626 mInputChannel.dispose();
7627 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 }
7630
7631 private class DeathRecipient implements IBinder.DeathRecipient {
7632 public void binderDied() {
7633 try {
7634 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007635 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007636 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007637 if (win != null) {
7638 removeWindowLocked(mSession, win);
7639 }
7640 }
7641 } catch (IllegalArgumentException ex) {
7642 // This will happen if the window has already been
7643 // removed.
7644 }
7645 }
7646 }
7647
7648 /** Returns true if this window desires key events. */
7649 public final boolean canReceiveKeys() {
7650 return isVisibleOrAdding()
7651 && (mViewVisibility == View.VISIBLE)
7652 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7653 }
7654
7655 public boolean hasDrawnLw() {
7656 return mHasDrawn;
7657 }
7658
7659 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007660 return showLw(doAnimation, true);
7661 }
7662
7663 boolean showLw(boolean doAnimation, boolean requestAnim) {
7664 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7665 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007666 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007667 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007668 if (doAnimation) {
7669 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7670 + mPolicyVisibility + " mAnimation=" + mAnimation);
7671 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7672 doAnimation = false;
7673 } else if (mPolicyVisibility && mAnimation == null) {
7674 // Check for the case where we are currently visible and
7675 // not animating; we do not want to do animation at such a
7676 // point to become visible when we already are.
7677 doAnimation = false;
7678 }
7679 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007680 mPolicyVisibility = true;
7681 mPolicyVisibilityAfterAnim = true;
7682 if (doAnimation) {
7683 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7684 }
7685 if (requestAnim) {
7686 requestAnimationLocked(0);
7687 }
7688 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 }
7690
7691 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007692 return hideLw(doAnimation, true);
7693 }
7694
7695 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007696 if (doAnimation) {
7697 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7698 doAnimation = false;
7699 }
7700 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007701 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7702 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007703 if (!current) {
7704 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007705 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007706 if (doAnimation) {
7707 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7708 if (mAnimation == null) {
7709 doAnimation = false;
7710 }
7711 }
7712 if (doAnimation) {
7713 mPolicyVisibilityAfterAnim = false;
7714 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007715 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007716 mPolicyVisibilityAfterAnim = false;
7717 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007718 // Window is no longer visible -- make sure if we were waiting
7719 // for it to be displayed before enabling the display, that
7720 // we allow the display to be enabled now.
7721 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007722 if (mCurrentFocus == this) {
7723 mFocusMayChange = true;
7724 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007725 }
7726 if (requestAnim) {
7727 requestAnimationLocked(0);
7728 }
7729 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 }
7731
7732 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007733 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7734 pw.print(" mClient="); pw.println(mClient.asBinder());
7735 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7736 if (mAttachedWindow != null || mLayoutAttached) {
7737 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7738 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7739 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007740 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7741 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7742 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007743 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7744 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007745 }
7746 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7747 pw.print(" mSubLayer="); pw.print(mSubLayer);
7748 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7749 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7750 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7751 pw.print("="); pw.print(mAnimLayer);
7752 pw.print(" mLastLayer="); pw.println(mLastLayer);
7753 if (mSurface != null) {
7754 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007755 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7756 pw.print(" layer="); pw.print(mSurfaceLayer);
7757 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7758 pw.print(" rect=("); pw.print(mSurfaceX);
7759 pw.print(","); pw.print(mSurfaceY);
7760 pw.print(") "); pw.print(mSurfaceW);
7761 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007762 }
7763 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7764 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7765 if (mAppToken != null) {
7766 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7767 }
7768 if (mTargetAppToken != null) {
7769 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7770 }
7771 pw.print(prefix); pw.print("mViewVisibility=0x");
7772 pw.print(Integer.toHexString(mViewVisibility));
7773 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007774 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7775 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007776 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7777 pw.print(prefix); pw.print("mPolicyVisibility=");
7778 pw.print(mPolicyVisibility);
7779 pw.print(" mPolicyVisibilityAfterAnim=");
7780 pw.print(mPolicyVisibilityAfterAnim);
7781 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7782 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007783 if (!mRelayoutCalled) {
7784 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7785 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007786 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007787 pw.print(" h="); pw.print(mRequestedHeight);
7788 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007789 if (mXOffset != 0 || mYOffset != 0) {
7790 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7791 pw.print(" y="); pw.println(mYOffset);
7792 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007793 pw.print(prefix); pw.print("mGivenContentInsets=");
7794 mGivenContentInsets.printShortString(pw);
7795 pw.print(" mGivenVisibleInsets=");
7796 mGivenVisibleInsets.printShortString(pw);
7797 pw.println();
7798 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7799 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7800 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7801 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007802 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007803 pw.print(prefix); pw.print("mShownFrame=");
7804 mShownFrame.printShortString(pw);
7805 pw.print(" last="); mLastShownFrame.printShortString(pw);
7806 pw.println();
7807 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7808 pw.print(" last="); mLastFrame.printShortString(pw);
7809 pw.println();
7810 pw.print(prefix); pw.print("mContainingFrame=");
7811 mContainingFrame.printShortString(pw);
7812 pw.print(" mDisplayFrame=");
7813 mDisplayFrame.printShortString(pw);
7814 pw.println();
7815 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7816 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7817 pw.println();
7818 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7819 pw.print(" last="); mLastContentInsets.printShortString(pw);
7820 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7821 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7822 pw.println();
7823 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7824 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7825 pw.print(" mAlpha="); pw.print(mAlpha);
7826 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7827 }
7828 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7829 || mAnimation != null) {
7830 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7831 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7832 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7833 pw.print(" mAnimation="); pw.println(mAnimation);
7834 }
7835 if (mHasTransformation || mHasLocalTransformation) {
7836 pw.print(prefix); pw.print("XForm: has=");
7837 pw.print(mHasTransformation);
7838 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7839 pw.print(" "); mTransformation.printShortString(pw);
7840 pw.println();
7841 }
7842 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7843 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7844 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7845 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7846 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7847 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7848 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7849 pw.print(" mDestroying="); pw.print(mDestroying);
7850 pw.print(" mRemoved="); pw.println(mRemoved);
7851 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007852 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007853 pw.print(prefix); pw.print("mOrientationChanging=");
7854 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007855 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7856 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007857 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007858 if (mHScale != 1 || mVScale != 1) {
7859 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7860 pw.print(" mVScale="); pw.println(mVScale);
7861 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007862 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007863 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7864 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7865 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007866 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7867 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7868 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007871
7872 String makeInputChannelName() {
7873 return Integer.toHexString(System.identityHashCode(this))
7874 + " " + mAttrs.getTitle();
7875 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876
7877 @Override
7878 public String toString() {
7879 return "Window{"
7880 + Integer.toHexString(System.identityHashCode(this))
7881 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7882 }
7883 }
Romain Guy06882f82009-06-10 13:36:04 -07007884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885 // -------------------------------------------------------------
7886 // Window Token State
7887 // -------------------------------------------------------------
7888
7889 class WindowToken {
7890 // The actual token.
7891 final IBinder token;
7892
7893 // The type of window this token is for, as per WindowManager.LayoutParams.
7894 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007896 // Set if this token was explicitly added by a client, so should
7897 // not be removed when all windows are removed.
7898 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007899
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007900 // For printing.
7901 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007903 // If this is an AppWindowToken, this is non-null.
7904 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007906 // All of the windows associated with this token.
7907 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7908
7909 // Is key dispatching paused for this token?
7910 boolean paused = false;
7911
7912 // Should this token's windows be hidden?
7913 boolean hidden;
7914
7915 // Temporary for finding which tokens no longer have visible windows.
7916 boolean hasVisible;
7917
Dianne Hackborna8f60182009-09-01 19:01:50 -07007918 // Set to true when this token is in a pending transaction where it
7919 // will be shown.
7920 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007921
Dianne Hackborna8f60182009-09-01 19:01:50 -07007922 // Set to true when this token is in a pending transaction where it
7923 // will be hidden.
7924 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007925
Dianne Hackborna8f60182009-09-01 19:01:50 -07007926 // Set to true when this token is in a pending transaction where its
7927 // windows will be put to the bottom of the list.
7928 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007929
Dianne Hackborna8f60182009-09-01 19:01:50 -07007930 // Set to true when this token is in a pending transaction where its
7931 // windows will be put to the top of the list.
7932 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007934 WindowToken(IBinder _token, int type, boolean _explicit) {
7935 token = _token;
7936 windowType = type;
7937 explicit = _explicit;
7938 }
7939
7940 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007941 pw.print(prefix); pw.print("token="); pw.println(token);
7942 pw.print(prefix); pw.print("windows="); pw.println(windows);
7943 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7944 pw.print(" hidden="); pw.print(hidden);
7945 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007946 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7947 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7948 pw.print(" waitingToHide="); pw.print(waitingToHide);
7949 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7950 pw.print(" sendingToTop="); pw.println(sendingToTop);
7951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007952 }
7953
7954 @Override
7955 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007956 if (stringName == null) {
7957 StringBuilder sb = new StringBuilder();
7958 sb.append("WindowToken{");
7959 sb.append(Integer.toHexString(System.identityHashCode(this)));
7960 sb.append(" token="); sb.append(token); sb.append('}');
7961 stringName = sb.toString();
7962 }
7963 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007964 }
7965 };
7966
7967 class AppWindowToken extends WindowToken {
7968 // Non-null only for application tokens.
7969 final IApplicationToken appToken;
7970
7971 // All of the windows and child windows that are included in this
7972 // application token. Note this list is NOT sorted!
7973 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7974
7975 int groupId = -1;
7976 boolean appFullscreen;
7977 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007978
7979 // The input dispatching timeout for this application token in nanoseconds.
7980 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007982 // These are used for determining when all windows associated with
7983 // an activity have been drawn, so they can be made visible together
7984 // at the same time.
7985 int lastTransactionSequence = mTransactionSequence-1;
7986 int numInterestingWindows;
7987 int numDrawnWindows;
7988 boolean inPendingTransaction;
7989 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007991 // Is this token going to be hidden in a little while? If so, it
7992 // won't be taken into account for setting the screen orientation.
7993 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007995 // Is this window's surface needed? This is almost like hidden, except
7996 // it will sometimes be true a little earlier: when the token has
7997 // been shown, but is still waiting for its app transition to execute
7998 // before making its windows shown.
7999 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008001 // Have we told the window clients to hide themselves?
8002 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 // Last visibility state we reported to the app token.
8005 boolean reportedVisible;
8006
8007 // Set to true when the token has been removed from the window mgr.
8008 boolean removed;
8009
8010 // Have we been asked to have this token keep the screen frozen?
8011 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008013 boolean animating;
8014 Animation animation;
8015 boolean hasTransformation;
8016 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008018 // Offset to the window of all layers in the token, for use by
8019 // AppWindowToken animations.
8020 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 // Information about an application starting window if displayed.
8023 StartingData startingData;
8024 WindowState startingWindow;
8025 View startingView;
8026 boolean startingDisplayed;
8027 boolean startingMoved;
8028 boolean firstWindowDrawn;
8029
8030 AppWindowToken(IApplicationToken _token) {
8031 super(_token.asBinder(),
8032 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8033 appWindowToken = this;
8034 appToken = _token;
8035 }
Romain Guy06882f82009-06-10 13:36:04 -07008036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008037 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008038 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008039 TAG, "Setting animation in " + this + ": " + anim);
8040 animation = anim;
8041 animating = false;
8042 anim.restrictDuration(MAX_ANIMATION_DURATION);
8043 anim.scaleCurrentDuration(mTransitionAnimationScale);
8044 int zorder = anim.getZAdjustment();
8045 int adj = 0;
8046 if (zorder == Animation.ZORDER_TOP) {
8047 adj = TYPE_LAYER_OFFSET;
8048 } else if (zorder == Animation.ZORDER_BOTTOM) {
8049 adj = -TYPE_LAYER_OFFSET;
8050 }
Romain Guy06882f82009-06-10 13:36:04 -07008051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 if (animLayerAdjustment != adj) {
8053 animLayerAdjustment = adj;
8054 updateLayers();
8055 }
8056 }
Romain Guy06882f82009-06-10 13:36:04 -07008057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 public void setDummyAnimation() {
8059 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008060 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008061 TAG, "Setting dummy animation in " + this);
8062 animation = sDummyAnimation;
8063 }
8064 }
8065
8066 public void clearAnimation() {
8067 if (animation != null) {
8068 animation = null;
8069 animating = true;
8070 }
8071 }
Romain Guy06882f82009-06-10 13:36:04 -07008072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008073 void updateLayers() {
8074 final int N = allAppWindows.size();
8075 final int adj = animLayerAdjustment;
8076 for (int i=0; i<N; i++) {
8077 WindowState w = allAppWindows.get(i);
8078 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008079 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008080 + w.mAnimLayer);
8081 if (w == mInputMethodTarget) {
8082 setInputMethodAnimLayerAdjustment(adj);
8083 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008084 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008085 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008087 }
8088 }
Romain Guy06882f82009-06-10 13:36:04 -07008089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008090 void sendAppVisibilityToClients() {
8091 final int N = allAppWindows.size();
8092 for (int i=0; i<N; i++) {
8093 WindowState win = allAppWindows.get(i);
8094 if (win == startingWindow && clientHidden) {
8095 // Don't hide the starting window.
8096 continue;
8097 }
8098 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008099 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008100 "Setting visibility of " + win + ": " + (!clientHidden));
8101 win.mClient.dispatchAppVisibility(!clientHidden);
8102 } catch (RemoteException e) {
8103 }
8104 }
8105 }
Romain Guy06882f82009-06-10 13:36:04 -07008106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 void showAllWindowsLocked() {
8108 final int NW = allAppWindows.size();
8109 for (int i=0; i<NW; i++) {
8110 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008111 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008112 "performing show on: " + w);
8113 w.performShowLocked();
8114 }
8115 }
Romain Guy06882f82009-06-10 13:36:04 -07008116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008117 // This must be called while inside a transaction.
8118 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008119 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008122 if (animation == sDummyAnimation) {
8123 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008124 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 // when it is really time to animate, this will be set to
8126 // a real animation and the next call will execute normally.
8127 return false;
8128 }
Romain Guy06882f82009-06-10 13:36:04 -07008129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008130 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8131 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008132 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 TAG, "Starting animation in " + this +
8134 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8135 + " scale=" + mTransitionAnimationScale
8136 + " allDrawn=" + allDrawn + " animating=" + animating);
8137 animation.initialize(dw, dh, dw, dh);
8138 animation.setStartTime(currentTime);
8139 animating = true;
8140 }
8141 transformation.clear();
8142 final boolean more = animation.getTransformation(
8143 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008144 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 TAG, "Stepped animation in " + this +
8146 ": more=" + more + ", xform=" + transformation);
8147 if (more) {
8148 // we're done!
8149 hasTransformation = true;
8150 return true;
8151 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008152 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008153 TAG, "Finished animation in " + this +
8154 " @ " + currentTime);
8155 animation = null;
8156 }
8157 } else if (animation != null) {
8158 // If the display is frozen, and there is a pending animation,
8159 // clear it and make sure we run the cleanup code.
8160 animating = true;
8161 animation = null;
8162 }
8163
8164 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008166 if (!animating) {
8167 return false;
8168 }
8169
8170 clearAnimation();
8171 animating = false;
8172 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8173 moveInputMethodWindowsIfNeededLocked(true);
8174 }
Romain Guy06882f82009-06-10 13:36:04 -07008175
Joe Onorato8a9b2202010-02-26 18:56:32 -08008176 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008177 TAG, "Animation done in " + this
8178 + ": reportedVisible=" + reportedVisible);
8179
8180 transformation.clear();
8181 if (animLayerAdjustment != 0) {
8182 animLayerAdjustment = 0;
8183 updateLayers();
8184 }
Romain Guy06882f82009-06-10 13:36:04 -07008185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008186 final int N = windows.size();
8187 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008188 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008189 }
8190 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008192 return false;
8193 }
8194
8195 void updateReportedVisibilityLocked() {
8196 if (appToken == null) {
8197 return;
8198 }
Romain Guy06882f82009-06-10 13:36:04 -07008199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008200 int numInteresting = 0;
8201 int numVisible = 0;
8202 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008203
Joe Onorato8a9b2202010-02-26 18:56:32 -08008204 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 final int N = allAppWindows.size();
8206 for (int i=0; i<N; i++) {
8207 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008208 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008209 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008210 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8211 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 continue;
8213 }
8214 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008215 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008216 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008217 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008218 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008219 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008220 + " pv=" + win.mPolicyVisibility
8221 + " dp=" + win.mDrawPending
8222 + " cdp=" + win.mCommitDrawPending
8223 + " ah=" + win.mAttachedHidden
8224 + " th="
8225 + (win.mAppToken != null
8226 ? win.mAppToken.hiddenRequested : false)
8227 + " a=" + win.mAnimating);
8228 }
8229 }
8230 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008231 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008232 if (!win.isAnimating()) {
8233 numVisible++;
8234 }
8235 nowGone = false;
8236 } else if (win.isAnimating()) {
8237 nowGone = false;
8238 }
8239 }
Romain Guy06882f82009-06-10 13:36:04 -07008240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008241 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008242 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008243 + numInteresting + " visible=" + numVisible);
8244 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008245 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008246 TAG, "Visibility changed in " + this
8247 + ": vis=" + nowVisible);
8248 reportedVisible = nowVisible;
8249 Message m = mH.obtainMessage(
8250 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8251 nowVisible ? 1 : 0,
8252 nowGone ? 1 : 0,
8253 this);
8254 mH.sendMessage(m);
8255 }
8256 }
Romain Guy06882f82009-06-10 13:36:04 -07008257
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008258 WindowState findMainWindow() {
8259 int j = windows.size();
8260 while (j > 0) {
8261 j--;
8262 WindowState win = windows.get(j);
8263 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8264 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8265 return win;
8266 }
8267 }
8268 return null;
8269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008271 void dump(PrintWriter pw, String prefix) {
8272 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008273 if (appToken != null) {
8274 pw.print(prefix); pw.println("app=true");
8275 }
8276 if (allAppWindows.size() > 0) {
8277 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8278 }
8279 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008280 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008281 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8282 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8283 pw.print(" clientHidden="); pw.print(clientHidden);
8284 pw.print(" willBeHidden="); pw.print(willBeHidden);
8285 pw.print(" reportedVisible="); pw.println(reportedVisible);
8286 if (paused || freezingScreen) {
8287 pw.print(prefix); pw.print("paused="); pw.print(paused);
8288 pw.print(" freezingScreen="); pw.println(freezingScreen);
8289 }
8290 if (numInterestingWindows != 0 || numDrawnWindows != 0
8291 || inPendingTransaction || allDrawn) {
8292 pw.print(prefix); pw.print("numInterestingWindows=");
8293 pw.print(numInterestingWindows);
8294 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8295 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8296 pw.print(" allDrawn="); pw.println(allDrawn);
8297 }
8298 if (animating || animation != null) {
8299 pw.print(prefix); pw.print("animating="); pw.print(animating);
8300 pw.print(" animation="); pw.println(animation);
8301 }
8302 if (animLayerAdjustment != 0) {
8303 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8304 }
8305 if (hasTransformation) {
8306 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8307 pw.print(" transformation="); transformation.printShortString(pw);
8308 pw.println();
8309 }
8310 if (startingData != null || removed || firstWindowDrawn) {
8311 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8312 pw.print(" removed="); pw.print(removed);
8313 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8314 }
8315 if (startingWindow != null || startingView != null
8316 || startingDisplayed || startingMoved) {
8317 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8318 pw.print(" startingView="); pw.print(startingView);
8319 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8320 pw.print(" startingMoved"); pw.println(startingMoved);
8321 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008322 }
8323
8324 @Override
8325 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008326 if (stringName == null) {
8327 StringBuilder sb = new StringBuilder();
8328 sb.append("AppWindowToken{");
8329 sb.append(Integer.toHexString(System.identityHashCode(this)));
8330 sb.append(" token="); sb.append(token); sb.append('}');
8331 stringName = sb.toString();
8332 }
8333 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008334 }
8335 }
Romain Guy06882f82009-06-10 13:36:04 -07008336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008337 // -------------------------------------------------------------
8338 // DummyAnimation
8339 // -------------------------------------------------------------
8340
8341 // This is an animation that does nothing: it just immediately finishes
8342 // itself every time it is called. It is used as a stub animation in cases
8343 // where we want to synchronize multiple things that may be animating.
8344 static final class DummyAnimation extends Animation {
8345 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8346 return false;
8347 }
8348 }
8349 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008351 // -------------------------------------------------------------
8352 // Async Handler
8353 // -------------------------------------------------------------
8354
8355 static final class StartingData {
8356 final String pkg;
8357 final int theme;
8358 final CharSequence nonLocalizedLabel;
8359 final int labelRes;
8360 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008362 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8363 int _labelRes, int _icon) {
8364 pkg = _pkg;
8365 theme = _theme;
8366 nonLocalizedLabel = _nonLocalizedLabel;
8367 labelRes = _labelRes;
8368 icon = _icon;
8369 }
8370 }
8371
8372 private final class H extends Handler {
8373 public static final int REPORT_FOCUS_CHANGE = 2;
8374 public static final int REPORT_LOSING_FOCUS = 3;
8375 public static final int ANIMATE = 4;
8376 public static final int ADD_STARTING = 5;
8377 public static final int REMOVE_STARTING = 6;
8378 public static final int FINISHED_STARTING = 7;
8379 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008380 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8381 public static final int HOLD_SCREEN_CHANGED = 12;
8382 public static final int APP_TRANSITION_TIMEOUT = 13;
8383 public static final int PERSIST_ANIMATION_SCALE = 14;
8384 public static final int FORCE_GC = 15;
8385 public static final int ENABLE_SCREEN = 16;
8386 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008387 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008388 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008389 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008390 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008392 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008394 public H() {
8395 }
Romain Guy06882f82009-06-10 13:36:04 -07008396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 @Override
8398 public void handleMessage(Message msg) {
8399 switch (msg.what) {
8400 case REPORT_FOCUS_CHANGE: {
8401 WindowState lastFocus;
8402 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008404 synchronized(mWindowMap) {
8405 lastFocus = mLastFocus;
8406 newFocus = mCurrentFocus;
8407 if (lastFocus == newFocus) {
8408 // Focus is not changing, so nothing to do.
8409 return;
8410 }
8411 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008412 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008413 // + " to " + newFocus);
8414 if (newFocus != null && lastFocus != null
8415 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008416 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 mLosingFocus.add(lastFocus);
8418 lastFocus = null;
8419 }
8420 }
8421
8422 if (lastFocus != newFocus) {
8423 //System.out.println("Changing focus from " + lastFocus
8424 // + " to " + newFocus);
8425 if (newFocus != null) {
8426 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008427 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008428 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8429 } catch (RemoteException e) {
8430 // Ignore if process has died.
8431 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008432 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 }
8434
8435 if (lastFocus != null) {
8436 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008437 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8439 } catch (RemoteException e) {
8440 // Ignore if process has died.
8441 }
8442 }
8443 }
8444 } break;
8445
8446 case REPORT_LOSING_FOCUS: {
8447 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008449 synchronized(mWindowMap) {
8450 losers = mLosingFocus;
8451 mLosingFocus = new ArrayList<WindowState>();
8452 }
8453
8454 final int N = losers.size();
8455 for (int i=0; i<N; i++) {
8456 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008457 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8459 } catch (RemoteException e) {
8460 // Ignore if process has died.
8461 }
8462 }
8463 } break;
8464
8465 case ANIMATE: {
8466 synchronized(mWindowMap) {
8467 mAnimationPending = false;
8468 performLayoutAndPlaceSurfacesLocked();
8469 }
8470 } break;
8471
8472 case ADD_STARTING: {
8473 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8474 final StartingData sd = wtoken.startingData;
8475
8476 if (sd == null) {
8477 // Animation has been canceled... do nothing.
8478 return;
8479 }
Romain Guy06882f82009-06-10 13:36:04 -07008480
Joe Onorato8a9b2202010-02-26 18:56:32 -08008481 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008482 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008484 View view = null;
8485 try {
8486 view = mPolicy.addStartingWindow(
8487 wtoken.token, sd.pkg,
8488 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8489 sd.icon);
8490 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008491 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008492 }
8493
8494 if (view != null) {
8495 boolean abort = false;
8496
8497 synchronized(mWindowMap) {
8498 if (wtoken.removed || wtoken.startingData == null) {
8499 // If the window was successfully added, then
8500 // we need to remove it.
8501 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008502 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 "Aborted starting " + wtoken
8504 + ": removed=" + wtoken.removed
8505 + " startingData=" + wtoken.startingData);
8506 wtoken.startingWindow = null;
8507 wtoken.startingData = null;
8508 abort = true;
8509 }
8510 } else {
8511 wtoken.startingView = view;
8512 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008513 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 "Added starting " + wtoken
8515 + ": startingWindow="
8516 + wtoken.startingWindow + " startingView="
8517 + wtoken.startingView);
8518 }
8519
8520 if (abort) {
8521 try {
8522 mPolicy.removeStartingWindow(wtoken.token, view);
8523 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008524 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 }
8526 }
8527 }
8528 } break;
8529
8530 case REMOVE_STARTING: {
8531 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8532 IBinder token = null;
8533 View view = null;
8534 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008535 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 + wtoken + ": startingWindow="
8537 + wtoken.startingWindow + " startingView="
8538 + wtoken.startingView);
8539 if (wtoken.startingWindow != null) {
8540 view = wtoken.startingView;
8541 token = wtoken.token;
8542 wtoken.startingData = null;
8543 wtoken.startingView = null;
8544 wtoken.startingWindow = null;
8545 }
8546 }
8547 if (view != null) {
8548 try {
8549 mPolicy.removeStartingWindow(token, view);
8550 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008551 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 }
8553 }
8554 } break;
8555
8556 case FINISHED_STARTING: {
8557 IBinder token = null;
8558 View view = null;
8559 while (true) {
8560 synchronized (mWindowMap) {
8561 final int N = mFinishedStarting.size();
8562 if (N <= 0) {
8563 break;
8564 }
8565 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8566
Joe Onorato8a9b2202010-02-26 18:56:32 -08008567 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 "Finished starting " + wtoken
8569 + ": startingWindow=" + wtoken.startingWindow
8570 + " startingView=" + wtoken.startingView);
8571
8572 if (wtoken.startingWindow == null) {
8573 continue;
8574 }
8575
8576 view = wtoken.startingView;
8577 token = wtoken.token;
8578 wtoken.startingData = null;
8579 wtoken.startingView = null;
8580 wtoken.startingWindow = null;
8581 }
8582
8583 try {
8584 mPolicy.removeStartingWindow(token, view);
8585 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008586 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008587 }
8588 }
8589 } break;
8590
8591 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8592 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8593
8594 boolean nowVisible = msg.arg1 != 0;
8595 boolean nowGone = msg.arg2 != 0;
8596
8597 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008598 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008599 TAG, "Reporting visible in " + wtoken
8600 + " visible=" + nowVisible
8601 + " gone=" + nowGone);
8602 if (nowVisible) {
8603 wtoken.appToken.windowsVisible();
8604 } else {
8605 wtoken.appToken.windowsGone();
8606 }
8607 } catch (RemoteException ex) {
8608 }
8609 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 case WINDOW_FREEZE_TIMEOUT: {
8612 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008613 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008614 int i = mWindows.size();
8615 while (i > 0) {
8616 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008617 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008618 if (w.mOrientationChanging) {
8619 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008620 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008621 }
8622 }
8623 performLayoutAndPlaceSurfacesLocked();
8624 }
8625 break;
8626 }
Romain Guy06882f82009-06-10 13:36:04 -07008627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 case HOLD_SCREEN_CHANGED: {
8629 Session oldHold;
8630 Session newHold;
8631 synchronized (mWindowMap) {
8632 oldHold = mLastReportedHold;
8633 newHold = (Session)msg.obj;
8634 mLastReportedHold = newHold;
8635 }
Romain Guy06882f82009-06-10 13:36:04 -07008636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 if (oldHold != newHold) {
8638 try {
8639 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008640 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 "window",
8642 BatteryStats.WAKE_TYPE_WINDOW);
8643 }
8644 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008645 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008646 "window",
8647 BatteryStats.WAKE_TYPE_WINDOW);
8648 }
8649 } catch (RemoteException e) {
8650 }
8651 }
8652 break;
8653 }
Romain Guy06882f82009-06-10 13:36:04 -07008654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 case APP_TRANSITION_TIMEOUT: {
8656 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008657 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008658 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 "*** APP TRANSITION TIMEOUT");
8660 mAppTransitionReady = true;
8661 mAppTransitionTimeout = true;
8662 performLayoutAndPlaceSurfacesLocked();
8663 }
8664 }
8665 break;
8666 }
Romain Guy06882f82009-06-10 13:36:04 -07008667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 case PERSIST_ANIMATION_SCALE: {
8669 Settings.System.putFloat(mContext.getContentResolver(),
8670 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8671 Settings.System.putFloat(mContext.getContentResolver(),
8672 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8673 break;
8674 }
Romain Guy06882f82009-06-10 13:36:04 -07008675
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008676 case FORCE_GC: {
8677 synchronized(mWindowMap) {
8678 if (mAnimationPending) {
8679 // If we are animating, don't do the gc now but
8680 // delay a bit so we don't interrupt the animation.
8681 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8682 2000);
8683 return;
8684 }
8685 // If we are currently rotating the display, it will
8686 // schedule a new message when done.
8687 if (mDisplayFrozen) {
8688 return;
8689 }
8690 mFreezeGcPending = 0;
8691 }
8692 Runtime.getRuntime().gc();
8693 break;
8694 }
Romain Guy06882f82009-06-10 13:36:04 -07008695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 case ENABLE_SCREEN: {
8697 performEnableScreen();
8698 break;
8699 }
Romain Guy06882f82009-06-10 13:36:04 -07008700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008701 case APP_FREEZE_TIMEOUT: {
8702 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008703 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 int i = mAppTokens.size();
8705 while (i > 0) {
8706 i--;
8707 AppWindowToken tok = mAppTokens.get(i);
8708 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008709 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 unsetAppFreezingScreenLocked(tok, true, true);
8711 }
8712 }
8713 }
8714 break;
8715 }
Romain Guy06882f82009-06-10 13:36:04 -07008716
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008717 case SEND_NEW_CONFIGURATION: {
8718 removeMessages(SEND_NEW_CONFIGURATION);
8719 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008720 break;
8721 }
Romain Guy06882f82009-06-10 13:36:04 -07008722
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008723 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008724 if (mWindowsChanged) {
8725 synchronized (mWindowMap) {
8726 mWindowsChanged = false;
8727 }
8728 notifyWindowsChanged();
8729 }
8730 break;
8731 }
8732
Christopher Tatea53146c2010-09-07 11:57:52 -07008733 case DRAG_START_TIMEOUT: {
8734 IBinder win = (IBinder)msg.obj;
8735 if (DEBUG_DRAG) {
8736 Slog.w(TAG, "Timeout starting drag by win " + win);
8737 }
8738 synchronized (mWindowMap) {
8739 // !!! TODO: ANR the app that has failed to start the drag in time
8740 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008741 mDragState.unregister();
8742 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008743 mDragState.reset();
8744 mDragState = null;
8745 }
8746 }
Chris Tated4533f142010-10-19 15:15:08 -07008747 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008748 }
8749
Chris Tated4533f142010-10-19 15:15:08 -07008750 case DRAG_END_TIMEOUT: {
8751 IBinder win = (IBinder)msg.obj;
8752 if (DEBUG_DRAG) {
8753 Slog.w(TAG, "Timeout ending drag to win " + win);
8754 }
8755 synchronized (mWindowMap) {
8756 // !!! TODO: ANR the drag-receiving app
8757 mDragState.mDragResult = false;
8758 mDragState.endDragLw();
8759 }
8760 break;
8761 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008762 }
8763 }
8764 }
8765
8766 // -------------------------------------------------------------
8767 // IWindowManager API
8768 // -------------------------------------------------------------
8769
8770 public IWindowSession openSession(IInputMethodClient client,
8771 IInputContext inputContext) {
8772 if (client == null) throw new IllegalArgumentException("null client");
8773 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008774 Session session = new Session(client, inputContext);
8775 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008776 }
8777
8778 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8779 synchronized (mWindowMap) {
8780 // The focus for the client is the window immediately below
8781 // where we would place the input method window.
8782 int idx = findDesiredInputMethodWindowIndexLocked(false);
8783 WindowState imFocus;
8784 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008785 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 if (imFocus != null) {
8787 if (imFocus.mSession.mClient != null &&
8788 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8789 return true;
8790 }
8791 }
8792 }
8793 }
8794 return false;
8795 }
Romain Guy06882f82009-06-10 13:36:04 -07008796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008797 // -------------------------------------------------------------
8798 // Internals
8799 // -------------------------------------------------------------
8800
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008801 final WindowState windowForClientLocked(Session session, IWindow client,
8802 boolean throwOnError) {
8803 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 }
Romain Guy06882f82009-06-10 13:36:04 -07008805
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008806 final WindowState windowForClientLocked(Session session, IBinder client,
8807 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008808 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008809 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008810 TAG, "Looking up client " + client + ": " + win);
8811 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008812 RuntimeException ex = new IllegalArgumentException(
8813 "Requested window " + client + " does not exist");
8814 if (throwOnError) {
8815 throw ex;
8816 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008817 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008818 return null;
8819 }
8820 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008821 RuntimeException ex = new IllegalArgumentException(
8822 "Requested window " + client + " is in session " +
8823 win.mSession + ", not " + session);
8824 if (throwOnError) {
8825 throw ex;
8826 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008827 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008828 return null;
8829 }
8830
8831 return win;
8832 }
8833
Dianne Hackborna8f60182009-09-01 19:01:50 -07008834 final void rebuildAppWindowListLocked() {
8835 int NW = mWindows.size();
8836 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008837 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008838 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008839
Dianne Hackborna8f60182009-09-01 19:01:50 -07008840 // First remove all existing app windows.
8841 i=0;
8842 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008843 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008844 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008845 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008846 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008847 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008848 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008849 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008850 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008851 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008852 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8853 && lastWallpaper == i-1) {
8854 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008855 }
8856 i++;
8857 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008858
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008859 // The wallpaper window(s) typically live at the bottom of the stack,
8860 // so skip them before adding app tokens.
8861 lastWallpaper++;
8862 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008863
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008864 // First add all of the exiting app tokens... these are no longer
8865 // in the main app list, but still have windows shown. We put them
8866 // in the back because now that the animation is over we no longer
8867 // will care about them.
8868 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008869 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008870 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8871 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008872
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008873 // And add in the still active app tokens in Z order.
8874 NT = mAppTokens.size();
8875 for (int j=0; j<NT; j++) {
8876 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008877 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008878
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008879 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008880 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008881 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008882 + " windows but added " + i);
8883 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008884 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008886 private final void assignLayersLocked() {
8887 int N = mWindows.size();
8888 int curBaseLayer = 0;
8889 int curLayer = 0;
8890 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008892 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008893 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008894 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8895 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008896 curLayer += WINDOW_LAYER_MULTIPLIER;
8897 w.mLayer = curLayer;
8898 } else {
8899 curBaseLayer = curLayer = w.mBaseLayer;
8900 w.mLayer = curLayer;
8901 }
8902 if (w.mTargetAppToken != null) {
8903 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8904 } else if (w.mAppToken != null) {
8905 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8906 } else {
8907 w.mAnimLayer = w.mLayer;
8908 }
8909 if (w.mIsImWindow) {
8910 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008911 } else if (w.mIsWallpaper) {
8912 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008913 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008914 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008915 + w.mAnimLayer);
8916 //System.out.println(
8917 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8918 }
8919 }
8920
8921 private boolean mInLayout = false;
8922 private final void performLayoutAndPlaceSurfacesLocked() {
8923 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008924 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008925 throw new RuntimeException("Recursive call!");
8926 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008927 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008928 return;
8929 }
8930
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008931 if (mWaitingForConfig) {
8932 // Our configuration has changed (most likely rotation), but we
8933 // don't yet have the complete configuration to report to
8934 // applications. Don't do any window layout until we have it.
8935 return;
8936 }
8937
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008938 if (mDisplay == null) {
8939 // Not yet initialized, nothing to do.
8940 return;
8941 }
8942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 boolean recoveringMemory = false;
8944 if (mForceRemoves != null) {
8945 recoveringMemory = true;
8946 // Wait a little it for things to settle down, and off we go.
8947 for (int i=0; i<mForceRemoves.size(); i++) {
8948 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008949 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008950 removeWindowInnerLocked(ws.mSession, ws);
8951 }
8952 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008953 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008954 Object tmp = new Object();
8955 synchronized (tmp) {
8956 try {
8957 tmp.wait(250);
8958 } catch (InterruptedException e) {
8959 }
8960 }
8961 }
Romain Guy06882f82009-06-10 13:36:04 -07008962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008963 mInLayout = true;
8964 try {
8965 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 int i = mPendingRemove.size()-1;
8968 if (i >= 0) {
8969 while (i >= 0) {
8970 WindowState w = mPendingRemove.get(i);
8971 removeWindowInnerLocked(w.mSession, w);
8972 i--;
8973 }
8974 mPendingRemove.clear();
8975
8976 mInLayout = false;
8977 assignLayersLocked();
8978 mLayoutNeeded = true;
8979 performLayoutAndPlaceSurfacesLocked();
8980
8981 } else {
8982 mInLayout = false;
8983 if (mLayoutNeeded) {
8984 requestAnimationLocked(0);
8985 }
8986 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008987 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008988 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8989 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008990 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008991 } catch (RuntimeException e) {
8992 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008993 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008994 }
8995 }
8996
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008997 private final int performLayoutLockedInner() {
8998 if (!mLayoutNeeded) {
8999 return 0;
9000 }
9001
9002 mLayoutNeeded = false;
9003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009004 final int dw = mDisplay.getWidth();
9005 final int dh = mDisplay.getHeight();
9006
9007 final int N = mWindows.size();
9008 int i;
9009
Joe Onorato8a9b2202010-02-26 18:56:32 -08009010 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009011 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9012
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009013 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009014
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009015 int seq = mLayoutSeq+1;
9016 if (seq < 0) seq = 0;
9017 mLayoutSeq = seq;
9018
9019 // First perform layout of any root windows (not attached
9020 // to another window).
9021 int topAttached = -1;
9022 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009023 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009024
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009025 // Don't do layout of a window if it is not visible, or
9026 // soon won't be visible, to avoid wasting time and funky
9027 // changes while a window is animating away.
9028 final AppWindowToken atoken = win.mAppToken;
9029 final boolean gone = win.mViewVisibility == View.GONE
9030 || !win.mRelayoutCalled
9031 || win.mRootToken.hidden
9032 || (atoken != null && atoken.hiddenRequested)
9033 || win.mAttachedHidden
9034 || win.mExiting || win.mDestroying;
9035
9036 if (!win.mLayoutAttached) {
9037 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9038 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9039 + " mLayoutAttached=" + win.mLayoutAttached);
9040 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9041 + win.mViewVisibility + " mRelayoutCalled="
9042 + win.mRelayoutCalled + " hidden="
9043 + win.mRootToken.hidden + " hiddenRequested="
9044 + (atoken != null && atoken.hiddenRequested)
9045 + " mAttachedHidden=" + win.mAttachedHidden);
9046 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009047
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009048 // If this view is GONE, then skip it -- keep the current
9049 // frame, and let the caller know so they can ignore it
9050 // if they want. (We do the normal layout for INVISIBLE
9051 // windows, since that means "perform layout as normal,
9052 // just don't display").
9053 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009054 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009055 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9056 win.mLayoutSeq = seq;
9057 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9058 + win.mFrame + " mContainingFrame="
9059 + win.mContainingFrame + " mDisplayFrame="
9060 + win.mDisplayFrame);
9061 } else {
9062 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009063 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009065 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009066
9067 // Now perform layout of attached windows, which usually
9068 // depend on the position of the window they are attached to.
9069 // XXX does not deal with windows that are attached to windows
9070 // that are themselves attached.
9071 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009072 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009073
9074 // If this view is GONE, then skip it -- keep the current
9075 // frame, and let the caller know so they can ignore it
9076 // if they want. (We do the normal layout for INVISIBLE
9077 // windows, since that means "perform layout as normal,
9078 // just don't display").
9079 if (win.mLayoutAttached) {
9080 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9081 + " mHaveFrame=" + win.mHaveFrame
9082 + " mViewVisibility=" + win.mViewVisibility
9083 + " mRelayoutCalled=" + win.mRelayoutCalled);
9084 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9085 || !win.mHaveFrame) {
9086 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9087 win.mLayoutSeq = seq;
9088 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9089 + win.mFrame + " mContainingFrame="
9090 + win.mContainingFrame + " mDisplayFrame="
9091 + win.mDisplayFrame);
9092 }
9093 }
9094 }
Jeff Brown349703e2010-06-22 01:27:15 -07009095
9096 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009097 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009098
9099 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009100 }
Romain Guy06882f82009-06-10 13:36:04 -07009101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009102 private final void performLayoutAndPlaceSurfacesLockedInner(
9103 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009104 if (mDisplay == null) {
9105 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9106 return;
9107 }
9108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 final long currentTime = SystemClock.uptimeMillis();
9110 final int dw = mDisplay.getWidth();
9111 final int dh = mDisplay.getHeight();
9112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009113 int i;
9114
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009115 if (mFocusMayChange) {
9116 mFocusMayChange = false;
9117 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9118 }
9119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009120 // Initialize state of exiting tokens.
9121 for (i=mExitingTokens.size()-1; i>=0; i--) {
9122 mExitingTokens.get(i).hasVisible = false;
9123 }
9124
9125 // Initialize state of exiting applications.
9126 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9127 mExitingAppTokens.get(i).hasVisible = false;
9128 }
9129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009130 boolean orientationChangeComplete = true;
9131 Session holdScreen = null;
9132 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009133 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009134 boolean focusDisplayed = false;
9135 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009136 boolean createWatermark = false;
9137
9138 if (mFxSession == null) {
9139 mFxSession = new SurfaceSession();
9140 createWatermark = true;
9141 }
9142
9143 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009144
9145 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009146
9147 if (createWatermark) {
9148 createWatermark();
9149 }
9150 if (mWatermark != null) {
9151 mWatermark.positionSurface(dw, dh);
9152 }
9153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009154 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009155 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009156 int repeats = 0;
9157 int changes = 0;
9158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009159 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009160 repeats++;
9161 if (repeats > 6) {
9162 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9163 mLayoutNeeded = false;
9164 break;
9165 }
9166
9167 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9168 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9169 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9170 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9171 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9172 assignLayersLocked();
9173 mLayoutNeeded = true;
9174 }
9175 }
9176 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9177 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9178 if (updateOrientationFromAppTokensLocked()) {
9179 mLayoutNeeded = true;
9180 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9181 }
9182 }
9183 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9184 mLayoutNeeded = true;
9185 }
9186 }
9187
9188 // FIRST LOOP: Perform a layout, if needed.
9189 if (repeats < 4) {
9190 changes = performLayoutLockedInner();
9191 if (changes != 0) {
9192 continue;
9193 }
9194 } else {
9195 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9196 changes = 0;
9197 }
9198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009199 final int transactionSequence = ++mTransactionSequence;
9200
9201 // Update animations of all applications, including those
9202 // associated with exiting/removed apps
9203 boolean tokensAnimating = false;
9204 final int NAT = mAppTokens.size();
9205 for (i=0; i<NAT; i++) {
9206 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9207 tokensAnimating = true;
9208 }
9209 }
9210 final int NEAT = mExitingAppTokens.size();
9211 for (i=0; i<NEAT; i++) {
9212 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9213 tokensAnimating = true;
9214 }
9215 }
9216
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009217 // SECOND LOOP: Execute animations and update visibility of windows.
9218
Joe Onorato8a9b2202010-02-26 18:56:32 -08009219 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009220 + transactionSequence + " tokensAnimating="
9221 + tokensAnimating);
9222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009223 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224
9225 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009226 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009227 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009228
9229 mPolicy.beginAnimationLw(dw, dh);
9230
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009231 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009233 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009234 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009235
9236 final WindowManager.LayoutParams attrs = w.mAttrs;
9237
9238 if (w.mSurface != null) {
9239 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009240 if (w.commitFinishDrawingLocked(currentTime)) {
9241 if ((w.mAttrs.flags
9242 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009243 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009244 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009245 wallpaperMayChange = true;
9246 }
9247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009248
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009249 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009250 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9251 animating = true;
9252 //w.dump(" ");
9253 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009254 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9255 wallpaperMayChange = true;
9256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009257
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009258 if (mPolicy.doesForceHide(w, attrs)) {
9259 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009260 if (DEBUG_VISIBILITY) Slog.v(TAG,
9261 "Animation done that could impact force hide: "
9262 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009263 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009264 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009265 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9266 forceHiding = true;
9267 }
9268 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9269 boolean changed;
9270 if (forceHiding) {
9271 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009272 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9273 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009274 } else {
9275 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009276 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9277 "Now policy shown: " + w);
9278 if (changed) {
9279 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009280 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009281 // Assume we will need to animate. If
9282 // we don't (because the wallpaper will
9283 // stay with the lock screen), then we will
9284 // clean up later.
9285 Animation a = mPolicy.createForceHideEnterAnimation();
9286 if (a != null) {
9287 w.setAnimation(a);
9288 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009289 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009290 if (mCurrentFocus == null ||
9291 mCurrentFocus.mLayer < w.mLayer) {
9292 // We are showing on to of the current
9293 // focus, so re-evaluate focus to make
9294 // sure it is correct.
9295 mFocusMayChange = true;
9296 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009297 }
9298 }
9299 if (changed && (attrs.flags
9300 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9301 wallpaperMayChange = true;
9302 }
9303 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009305 mPolicy.animatingWindowLw(w, attrs);
9306 }
9307
9308 final AppWindowToken atoken = w.mAppToken;
9309 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9310 if (atoken.lastTransactionSequence != transactionSequence) {
9311 atoken.lastTransactionSequence = transactionSequence;
9312 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9313 atoken.startingDisplayed = false;
9314 }
9315 if ((w.isOnScreen() || w.mAttrs.type
9316 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9317 && !w.mExiting && !w.mDestroying) {
9318 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009319 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009320 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009321 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009322 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009323 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009324 + " pv=" + w.mPolicyVisibility
9325 + " dp=" + w.mDrawPending
9326 + " cdp=" + w.mCommitDrawPending
9327 + " ah=" + w.mAttachedHidden
9328 + " th=" + atoken.hiddenRequested
9329 + " a=" + w.mAnimating);
9330 }
9331 }
9332 if (w != atoken.startingWindow) {
9333 if (!atoken.freezingScreen || !w.mAppFreezing) {
9334 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009335 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009336 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009337 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009338 "tokenMayBeDrawn: " + atoken
9339 + " freezingScreen=" + atoken.freezingScreen
9340 + " mAppFreezing=" + w.mAppFreezing);
9341 tokenMayBeDrawn = true;
9342 }
9343 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009344 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009345 atoken.startingDisplayed = true;
9346 }
9347 }
9348 } else if (w.mReadyToShow) {
9349 w.performShowLocked();
9350 }
9351 }
9352
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009353 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354
9355 if (tokenMayBeDrawn) {
9356 // See if any windows have been drawn, so they (and others
9357 // associated with them) can now be shown.
9358 final int NT = mTokenList.size();
9359 for (i=0; i<NT; i++) {
9360 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9361 if (wtoken == null) {
9362 continue;
9363 }
9364 if (wtoken.freezingScreen) {
9365 int numInteresting = wtoken.numInterestingWindows;
9366 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009367 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009368 "allDrawn: " + wtoken
9369 + " interesting=" + numInteresting
9370 + " drawn=" + wtoken.numDrawnWindows);
9371 wtoken.showAllWindowsLocked();
9372 unsetAppFreezingScreenLocked(wtoken, false, true);
9373 orientationChangeComplete = true;
9374 }
9375 } else if (!wtoken.allDrawn) {
9376 int numInteresting = wtoken.numInterestingWindows;
9377 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009378 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009379 "allDrawn: " + wtoken
9380 + " interesting=" + numInteresting
9381 + " drawn=" + wtoken.numDrawnWindows);
9382 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009383 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384
9385 // We can now show all of the drawn windows!
9386 if (!mOpeningApps.contains(wtoken)) {
9387 wtoken.showAllWindowsLocked();
9388 }
9389 }
9390 }
9391 }
9392 }
9393
9394 // If we are ready to perform an app transition, check through
9395 // all of the app tokens to be shown and see if they are ready
9396 // to go.
9397 if (mAppTransitionReady) {
9398 int NN = mOpeningApps.size();
9399 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009400 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009401 "Checking " + NN + " opening apps (frozen="
9402 + mDisplayFrozen + " timeout="
9403 + mAppTransitionTimeout + ")...");
9404 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9405 // If the display isn't frozen, wait to do anything until
9406 // all of the apps are ready. Otherwise just go because
9407 // we'll unfreeze the display when everyone is ready.
9408 for (i=0; i<NN && goodToGo; i++) {
9409 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009410 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 "Check opening app" + wtoken + ": allDrawn="
9412 + wtoken.allDrawn + " startingDisplayed="
9413 + wtoken.startingDisplayed);
9414 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9415 && !wtoken.startingMoved) {
9416 goodToGo = false;
9417 }
9418 }
9419 }
9420 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009421 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 int transit = mNextAppTransition;
9423 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009424 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009425 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009426 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009428 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 mAppTransitionTimeout = false;
9430 mStartingIconInTransition = false;
9431 mSkipAppTransitionAnimation = false;
9432
9433 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9434
Dianne Hackborna8f60182009-09-01 19:01:50 -07009435 // If there are applications waiting to come to the
9436 // top of the stack, now is the time to move their windows.
9437 // (Note that we don't do apps going to the bottom
9438 // here -- we want to keep their windows in the old
9439 // Z-order until the animation completes.)
9440 if (mToTopApps.size() > 0) {
9441 NN = mAppTokens.size();
9442 for (i=0; i<NN; i++) {
9443 AppWindowToken wtoken = mAppTokens.get(i);
9444 if (wtoken.sendingToTop) {
9445 wtoken.sendingToTop = false;
9446 moveAppWindowsLocked(wtoken, NN, false);
9447 }
9448 }
9449 mToTopApps.clear();
9450 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009451
Dianne Hackborn25994b42009-09-04 14:21:19 -07009452 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009453
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009454 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009455 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009456
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009457 // The top-most window will supply the layout params,
9458 // and we will determine it below.
9459 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009460 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009461 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009462
Joe Onorato8a9b2202010-02-26 18:56:32 -08009463 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009464 "New wallpaper target=" + mWallpaperTarget
9465 + ", lower target=" + mLowerWallpaperTarget
9466 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009467 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009468 // Do a first pass through the tokens for two
9469 // things:
9470 // (1) Determine if both the closing and opening
9471 // app token sets are wallpaper targets, in which
9472 // case special animations are needed
9473 // (since the wallpaper needs to stay static
9474 // behind them).
9475 // (2) Find the layout params of the top-most
9476 // application window in the tokens, which is
9477 // what will control the animation theme.
9478 final int NC = mClosingApps.size();
9479 NN = NC + mOpeningApps.size();
9480 for (i=0; i<NN; i++) {
9481 AppWindowToken wtoken;
9482 int mode;
9483 if (i < NC) {
9484 wtoken = mClosingApps.get(i);
9485 mode = 1;
9486 } else {
9487 wtoken = mOpeningApps.get(i-NC);
9488 mode = 2;
9489 }
9490 if (mLowerWallpaperTarget != null) {
9491 if (mLowerWallpaperTarget.mAppToken == wtoken
9492 || mUpperWallpaperTarget.mAppToken == wtoken) {
9493 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009494 }
9495 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009496 if (wtoken.appFullscreen) {
9497 WindowState ws = wtoken.findMainWindow();
9498 if (ws != null) {
9499 // If this is a compatibility mode
9500 // window, we will always use its anim.
9501 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9502 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009503 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009504 bestAnimLayer = Integer.MAX_VALUE;
9505 } else if (ws.mLayer > bestAnimLayer) {
9506 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009507 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009508 bestAnimLayer = ws.mLayer;
9509 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009510 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009511 }
9512 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009513
Dianne Hackborn25994b42009-09-04 14:21:19 -07009514 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009515 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009516 "Wallpaper animation!");
9517 switch (transit) {
9518 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9519 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9520 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9521 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9522 break;
9523 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9524 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9525 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9526 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9527 break;
9528 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009529 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009530 "New transit: " + transit);
9531 } else if (oldWallpaper != null) {
9532 // We are transitioning from an activity with
9533 // a wallpaper to one without.
9534 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009535 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009536 "New transit away from wallpaper: " + transit);
9537 } else if (mWallpaperTarget != null) {
9538 // We are transitioning from an activity without
9539 // a wallpaper to now showing the wallpaper
9540 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009541 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009542 "New transit into wallpaper: " + transit);
9543 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009544
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009545 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9546 mLastEnterAnimToken = animToken;
9547 mLastEnterAnimParams = animLp;
9548 } else if (mLastEnterAnimParams != null) {
9549 animLp = mLastEnterAnimParams;
9550 mLastEnterAnimToken = null;
9551 mLastEnterAnimParams = null;
9552 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009553
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009554 // If all closing windows are obscured, then there is
9555 // no need to do an animation. This is the case, for
9556 // example, when this transition is being done behind
9557 // the lock screen.
9558 if (!mPolicy.allowAppAnimationsLw()) {
9559 animLp = null;
9560 }
9561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562 NN = mOpeningApps.size();
9563 for (i=0; i<NN; i++) {
9564 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009565 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009566 "Now opening app" + wtoken);
9567 wtoken.reportedVisible = false;
9568 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009569 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009570 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009571 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009572 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009573 wtoken.showAllWindowsLocked();
9574 }
9575 NN = mClosingApps.size();
9576 for (i=0; i<NN; i++) {
9577 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009578 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009579 "Now closing app" + wtoken);
9580 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009581 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009582 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009583 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009584 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009585 // Force the allDrawn flag, because we want to start
9586 // this guy's animations regardless of whether it's
9587 // gotten drawn.
9588 wtoken.allDrawn = true;
9589 }
9590
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009591 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 mOpeningApps.clear();
9594 mClosingApps.clear();
9595
9596 // This has changed the visibility of windows, so perform
9597 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009598 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009599 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009600 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9601 assignLayersLocked();
9602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009604 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 }
9606 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009607
Dianne Hackborn16064f92010-03-25 00:47:24 -07009608 int adjResult = 0;
9609
Dianne Hackborna8f60182009-09-01 19:01:50 -07009610 if (!animating && mAppTransitionRunning) {
9611 // We have finished the animation of an app transition. To do
9612 // this, we have delayed a lot of operations like showing and
9613 // hiding apps, moving apps in Z-order, etc. The app token list
9614 // reflects the correct Z-order, but the window list may now
9615 // be out of sync with it. So here we will just rebuild the
9616 // entire app window list. Fun!
9617 mAppTransitionRunning = false;
9618 // Clear information about apps that were moving.
9619 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009620
Dianne Hackborna8f60182009-09-01 19:01:50 -07009621 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009622 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009623 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009624 moveInputMethodWindowsIfNeededLocked(false);
9625 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009626 // Since the window list has been rebuilt, focus might
9627 // have to be recomputed since the actual order of windows
9628 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009629 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009630 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009631
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009632 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009633 // At this point, there was a window with a wallpaper that
9634 // was force hiding other windows behind it, but now it
9635 // is going away. This may be simple -- just animate
9636 // away the wallpaper and its window -- or it may be
9637 // hard -- the wallpaper now needs to be shown behind
9638 // something that was hidden.
9639 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009640 if (mLowerWallpaperTarget != null
9641 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009642 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009643 "wallpaperForceHiding changed with lower="
9644 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009645 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009646 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9647 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9648 if (mLowerWallpaperTarget.mAppToken.hidden) {
9649 // The lower target has become hidden before we
9650 // actually started the animation... let's completely
9651 // re-evaluate everything.
9652 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009653 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009654 }
9655 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009656 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009657 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009658 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009659 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009660 + " NEW: " + mWallpaperTarget
9661 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009662 if (mLowerWallpaperTarget == null) {
9663 // Whoops, we don't need a special wallpaper animation.
9664 // Clear them out.
9665 forceHiding = false;
9666 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009667 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009668 if (w.mSurface != null) {
9669 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009670 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009671 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009672 forceHiding = true;
9673 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9674 if (!w.mAnimating) {
9675 // We set the animation above so it
9676 // is not yet running.
9677 w.clearAnimation();
9678 }
9679 }
9680 }
9681 }
9682 }
9683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009684
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009685 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009686 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009687 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009688 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009689 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009690
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009691 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009692 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009693 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009694 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009695 assignLayersLocked();
9696 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009697 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009698 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009699 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009701
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009702 if (mFocusMayChange) {
9703 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009704 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009705 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009706 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009707 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009708 }
9709
9710 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009711 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009712 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009713
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009714 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9715 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009716
Jeff Browne33348b2010-07-15 23:54:05 -07009717 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009718 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719
9720 // THIRD LOOP: Update the surfaces of all windows.
9721
9722 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9723
9724 boolean obscured = false;
9725 boolean blurring = false;
9726 boolean dimming = false;
9727 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009728 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009729 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009730
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009731 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009733 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009734 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009735
9736 boolean displayed = false;
9737 final WindowManager.LayoutParams attrs = w.mAttrs;
9738 final int attrFlags = attrs.flags;
9739
9740 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009741 // XXX NOTE: The logic here could be improved. We have
9742 // the decision about whether to resize a window separated
9743 // from whether to hide the surface. This can cause us to
9744 // resize a surface even if we are going to hide it. You
9745 // can see this by (1) holding device in landscape mode on
9746 // home screen; (2) tapping browser icon (device will rotate
9747 // to landscape; (3) tap home. The wallpaper will be resized
9748 // in step 2 but then immediately hidden, causing us to
9749 // have to resize and then redraw it again in step 3. It
9750 // would be nice to figure out how to avoid this, but it is
9751 // difficult because we do need to resize surfaces in some
9752 // cases while they are hidden such as when first showing a
9753 // window.
9754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009756 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009757 TAG, "Placing surface #" + i + " " + w.mSurface
9758 + ": new=" + w.mShownFrame + ", old="
9759 + w.mLastShownFrame);
9760
9761 boolean resize;
9762 int width, height;
9763 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9764 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9765 w.mLastRequestedHeight != w.mRequestedHeight;
9766 // for a scaled surface, we just want to use
9767 // the requested size.
9768 width = w.mRequestedWidth;
9769 height = w.mRequestedHeight;
9770 w.mLastRequestedWidth = width;
9771 w.mLastRequestedHeight = height;
9772 w.mLastShownFrame.set(w.mShownFrame);
9773 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009774 if (SHOW_TRANSACTIONS) logSurface(w,
9775 "POS " + w.mShownFrame.left
9776 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009777 w.mSurfaceX = w.mShownFrame.left;
9778 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009779 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9780 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009781 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 if (!recoveringMemory) {
9783 reclaimSomeSurfaceMemoryLocked(w, "position");
9784 }
9785 }
9786 } else {
9787 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9788 width = w.mShownFrame.width();
9789 height = w.mShownFrame.height();
9790 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 }
9792
9793 if (resize) {
9794 if (width < 1) width = 1;
9795 if (height < 1) height = 1;
9796 if (w.mSurface != null) {
9797 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009798 if (SHOW_TRANSACTIONS) logSurface(w,
9799 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009800 + w.mShownFrame.top + " SIZE "
9801 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009802 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009803 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009804 w.mSurfaceW = width;
9805 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009807 w.mSurfaceX = w.mShownFrame.left;
9808 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009809 w.mSurface.setPosition(w.mShownFrame.left,
9810 w.mShownFrame.top);
9811 } catch (RuntimeException e) {
9812 // If something goes wrong with the surface (such
9813 // as running out of memory), don't take down the
9814 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009815 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 + "size=(" + width + "x" + height
9817 + "), pos=(" + w.mShownFrame.left
9818 + "," + w.mShownFrame.top + ")", e);
9819 if (!recoveringMemory) {
9820 reclaimSomeSurfaceMemoryLocked(w, "size");
9821 }
9822 }
9823 }
9824 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009825 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 w.mContentInsetsChanged =
9827 !w.mLastContentInsets.equals(w.mContentInsets);
9828 w.mVisibleInsetsChanged =
9829 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009830 boolean configChanged =
9831 w.mConfiguration != mCurConfiguration
9832 && (w.mConfiguration == null
9833 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009834 if (DEBUG_CONFIGURATION && configChanged) {
9835 Slog.v(TAG, "Win " + w + " config changed: "
9836 + mCurConfiguration);
9837 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009838 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009839 + ": configChanged=" + configChanged
9840 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009841 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009842 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009843 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009844 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009845 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 w.mLastFrame.set(w.mFrame);
9847 w.mLastContentInsets.set(w.mContentInsets);
9848 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009849 // If the screen is currently frozen, then keep
9850 // it frozen until this window draws at its new
9851 // orientation.
9852 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009853 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009854 "Resizing while display frozen: " + w);
9855 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009856 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009857 mWindowsFreezingScreen = true;
9858 // XXX should probably keep timeout from
9859 // when we first froze the display.
9860 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9861 mH.sendMessageDelayed(mH.obtainMessage(
9862 H.WINDOW_FREEZE_TIMEOUT), 2000);
9863 }
9864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009865 // If the orientation is changing, then we need to
9866 // hold off on unfreezing the display until this
9867 // window has been redrawn; to do that, we need
9868 // to go through the process of getting informed
9869 // by the application when it has finished drawing.
9870 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009871 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 "Orientation start waiting for draw in "
9873 + w + ", surface " + w.mSurface);
9874 w.mDrawPending = true;
9875 w.mCommitDrawPending = false;
9876 w.mReadyToShow = false;
9877 if (w.mAppToken != null) {
9878 w.mAppToken.allDrawn = false;
9879 }
9880 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009881 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 "Resizing window " + w + " to " + w.mFrame);
9883 mResizingWindows.add(w);
9884 } else if (w.mOrientationChanging) {
9885 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009886 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009887 "Orientation not waiting for draw in "
9888 + w + ", surface " + w.mSurface);
9889 w.mOrientationChanging = false;
9890 }
9891 }
9892 }
9893
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009894 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009895 if (!w.mLastHidden) {
9896 //dump();
9897 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009898 if (SHOW_TRANSACTIONS) logSurface(w,
9899 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009901 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 try {
9903 w.mSurface.hide();
9904 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009905 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009906 }
9907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009908 }
9909 // If we are waiting for this window to handle an
9910 // orientation change, well, it is hidden, so
9911 // doesn't really matter. Note that this does
9912 // introduce a potential glitch if the window
9913 // becomes unhidden before it has drawn for the
9914 // new orientation.
9915 if (w.mOrientationChanging) {
9916 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009917 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009918 "Orientation change skips hidden " + w);
9919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920 } else if (w.mLastLayer != w.mAnimLayer
9921 || w.mLastAlpha != w.mShownAlpha
9922 || w.mLastDsDx != w.mDsDx
9923 || w.mLastDtDx != w.mDtDx
9924 || w.mLastDsDy != w.mDsDy
9925 || w.mLastDtDy != w.mDtDy
9926 || w.mLastHScale != w.mHScale
9927 || w.mLastVScale != w.mVScale
9928 || w.mLastHidden) {
9929 displayed = true;
9930 w.mLastAlpha = w.mShownAlpha;
9931 w.mLastLayer = w.mAnimLayer;
9932 w.mLastDsDx = w.mDsDx;
9933 w.mLastDtDx = w.mDtDx;
9934 w.mLastDsDy = w.mDsDy;
9935 w.mLastDtDy = w.mDtDy;
9936 w.mLastHScale = w.mHScale;
9937 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009938 if (SHOW_TRANSACTIONS) logSurface(w,
9939 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009940 + " matrix=[" + (w.mDsDx*w.mHScale)
9941 + "," + (w.mDtDx*w.mVScale)
9942 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009943 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009944 if (w.mSurface != null) {
9945 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009946 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009947 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009948 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009949 w.mSurface.setLayer(w.mAnimLayer);
9950 w.mSurface.setMatrix(
9951 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9952 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9953 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009954 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955 if (!recoveringMemory) {
9956 reclaimSomeSurfaceMemoryLocked(w, "update");
9957 }
9958 }
9959 }
9960
9961 if (w.mLastHidden && !w.mDrawPending
9962 && !w.mCommitDrawPending
9963 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009964 if (SHOW_TRANSACTIONS) logSurface(w,
9965 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009966 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009967 + " during relayout");
9968 if (showSurfaceRobustlyLocked(w)) {
9969 w.mHasDrawn = true;
9970 w.mLastHidden = false;
9971 } else {
9972 w.mOrientationChanging = false;
9973 }
9974 }
9975 if (w.mSurface != null) {
9976 w.mToken.hasVisible = true;
9977 }
9978 } else {
9979 displayed = true;
9980 }
9981
9982 if (displayed) {
9983 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009984 if (attrs.width == LayoutParams.MATCH_PARENT
9985 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 covered = true;
9987 }
9988 }
9989 if (w.mOrientationChanging) {
9990 if (w.mDrawPending || w.mCommitDrawPending) {
9991 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009992 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 "Orientation continue waiting for draw in " + w);
9994 } else {
9995 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009996 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009997 "Orientation change complete in " + w);
9998 }
9999 }
10000 w.mToken.hasVisible = true;
10001 }
10002 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010003 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 "Orientation change skips hidden " + w);
10005 w.mOrientationChanging = false;
10006 }
10007
10008 final boolean canBeSeen = w.isDisplayedLw();
10009
10010 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10011 focusDisplayed = true;
10012 }
10013
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010014 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010016 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010017 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 if (w.mSurface != null) {
10019 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10020 holdScreen = w.mSession;
10021 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010022 if (!syswin && w.mAttrs.screenBrightness >= 0
10023 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 screenBrightness = w.mAttrs.screenBrightness;
10025 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010026 if (!syswin && w.mAttrs.buttonBrightness >= 0
10027 && buttonBrightness < 0) {
10028 buttonBrightness = w.mAttrs.buttonBrightness;
10029 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010030 if (canBeSeen
10031 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10032 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10033 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010034 syswin = true;
10035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010037
Dianne Hackborn25994b42009-09-04 14:21:19 -070010038 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10039 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010040 // This window completely covers everything behind it,
10041 // so we want to leave all of them as unblurred (for
10042 // performance reasons).
10043 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010044 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010045 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010046 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010047 obscured = true;
10048 if (mBackgroundFillerSurface == null) {
10049 try {
10050 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010051 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010052 0, dw, dh,
10053 PixelFormat.OPAQUE,
10054 Surface.FX_SURFACE_NORMAL);
10055 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010056 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010057 }
10058 }
10059 try {
10060 mBackgroundFillerSurface.setPosition(0, 0);
10061 mBackgroundFillerSurface.setSize(dw, dh);
10062 // Using the same layer as Dim because they will never be shown at the
10063 // same time.
10064 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10065 mBackgroundFillerSurface.show();
10066 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010067 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010068 }
10069 backgroundFillerShown = true;
10070 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010071 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010072 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010073 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010074 + ": blurring=" + blurring
10075 + " obscured=" + obscured
10076 + " displayed=" + displayed);
10077 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10078 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010079 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010080 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010081 if (mDimAnimator == null) {
10082 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010083 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010084 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010085 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010087 }
10088 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10089 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010090 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010091 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010092 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010093 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010094 + mBlurSurface + ": CREATE");
10095 try {
Romain Guy06882f82009-06-10 13:36:04 -070010096 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010097 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010098 -1, 16, 16,
10099 PixelFormat.OPAQUE,
10100 Surface.FX_SURFACE_BLUR);
10101 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010102 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 }
10104 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010105 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010106 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10107 + mBlurSurface + ": pos=(0,0) (" +
10108 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010109 mBlurSurface.setPosition(0, 0);
10110 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010111 mBlurSurface.setLayer(w.mAnimLayer-2);
10112 if (!mBlurShown) {
10113 try {
10114 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10115 + mBlurSurface + ": SHOW");
10116 mBlurSurface.show();
10117 } catch (RuntimeException e) {
10118 Slog.w(TAG, "Failure showing blur surface", e);
10119 }
10120 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010121 }
10122 }
10123 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010124 }
10125 }
10126 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010127
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010128 if (obscuredChanged && mWallpaperTarget == w) {
10129 // This is the wallpaper target and its obscured state
10130 // changed... make sure the current wallaper's visibility
10131 // has been updated accordingly.
10132 updateWallpaperVisibilityLocked();
10133 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010134 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010135
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010136 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10137 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010138 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010139 try {
10140 mBackgroundFillerSurface.hide();
10141 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010142 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010143 }
10144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010145
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010146 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010147 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10148 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010149 }
Romain Guy06882f82009-06-10 13:36:04 -070010150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010151 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010152 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010153 + ": HIDE");
10154 try {
10155 mBlurSurface.hide();
10156 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010157 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 }
10159 mBlurShown = false;
10160 }
10161
Joe Onorato8a9b2202010-02-26 18:56:32 -080010162 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010163 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010164 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010165 }
10166
Jeff Browne33348b2010-07-15 23:54:05 -070010167 mInputMonitor.updateInputWindowsLw();
10168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010169 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010170
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010171 if (mWatermark != null) {
10172 mWatermark.drawIfNeeded();
10173 }
10174
Joe Onorato8a9b2202010-02-26 18:56:32 -080010175 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010176 "With display frozen, orientationChangeComplete="
10177 + orientationChangeComplete);
10178 if (orientationChangeComplete) {
10179 if (mWindowsFreezingScreen) {
10180 mWindowsFreezingScreen = false;
10181 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10182 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010183 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010184 }
Romain Guy06882f82009-06-10 13:36:04 -070010185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010186 i = mResizingWindows.size();
10187 if (i > 0) {
10188 do {
10189 i--;
10190 WindowState win = mResizingWindows.get(i);
10191 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010192 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10193 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010194 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010195 boolean configChanged =
10196 win.mConfiguration != mCurConfiguration
10197 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010198 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10199 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10200 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010201 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010202 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010203 + " / " + mCurConfiguration + " / 0x"
10204 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010205 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010206 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010207 win.mClient.resized(win.mFrame.width(),
10208 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010209 win.mLastVisibleInsets, win.mDrawPending,
10210 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010211 win.mContentInsetsChanged = false;
10212 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010213 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010214 } catch (RemoteException e) {
10215 win.mOrientationChanging = false;
10216 }
10217 } while (i > 0);
10218 mResizingWindows.clear();
10219 }
Romain Guy06882f82009-06-10 13:36:04 -070010220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010221 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010222 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010223 i = mDestroySurface.size();
10224 if (i > 0) {
10225 do {
10226 i--;
10227 WindowState win = mDestroySurface.get(i);
10228 win.mDestroying = false;
10229 if (mInputMethodWindow == win) {
10230 mInputMethodWindow = null;
10231 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010232 if (win == mWallpaperTarget) {
10233 wallpaperDestroyed = true;
10234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010235 win.destroySurfaceLocked();
10236 } while (i > 0);
10237 mDestroySurface.clear();
10238 }
10239
10240 // Time to remove any exiting tokens?
10241 for (i=mExitingTokens.size()-1; i>=0; i--) {
10242 WindowToken token = mExitingTokens.get(i);
10243 if (!token.hasVisible) {
10244 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010245 if (token.windowType == TYPE_WALLPAPER) {
10246 mWallpaperTokens.remove(token);
10247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010248 }
10249 }
10250
10251 // Time to remove any exiting applications?
10252 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10253 AppWindowToken token = mExitingAppTokens.get(i);
10254 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010255 // Make sure there is no animation running on this token,
10256 // so any windows associated with it will be removed as
10257 // soon as their animations are complete
10258 token.animation = null;
10259 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010260 mAppTokens.remove(token);
10261 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010262 if (mLastEnterAnimToken == token) {
10263 mLastEnterAnimToken = null;
10264 mLastEnterAnimParams = null;
10265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010266 }
10267 }
10268
Dianne Hackborna8f60182009-09-01 19:01:50 -070010269 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010270
Dianne Hackborna8f60182009-09-01 19:01:50 -070010271 if (!animating && mAppTransitionRunning) {
10272 // We have finished the animation of an app transition. To do
10273 // this, we have delayed a lot of operations like showing and
10274 // hiding apps, moving apps in Z-order, etc. The app token list
10275 // reflects the correct Z-order, but the window list may now
10276 // be out of sync with it. So here we will just rebuild the
10277 // entire app window list. Fun!
10278 mAppTransitionRunning = false;
10279 needRelayout = true;
10280 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010281 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010282 // Clear information about apps that were moving.
10283 mToBottomApps.clear();
10284 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 if (focusDisplayed) {
10287 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10288 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010289 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010290 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010291 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010292 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010293 requestAnimationLocked(0);
10294 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10296 }
Jeff Browneb857f12010-07-16 10:06:33 -070010297
Jeff Browne33348b2010-07-15 23:54:05 -070010298 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010299
Jeff Brown8e03b752010-06-13 19:16:55 -070010300 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010301 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10302 mPowerManager.setScreenBrightnessOverride(-1);
10303 } else {
10304 mPowerManager.setScreenBrightnessOverride((int)
10305 (screenBrightness * Power.BRIGHTNESS_ON));
10306 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010307 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10308 mPowerManager.setButtonBrightnessOverride(-1);
10309 } else {
10310 mPowerManager.setButtonBrightnessOverride((int)
10311 (buttonBrightness * Power.BRIGHTNESS_ON));
10312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010313 if (holdScreen != mHoldingScreenOn) {
10314 mHoldingScreenOn = holdScreen;
10315 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10316 mH.sendMessage(m);
10317 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010318
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010319 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010320 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010321 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10322 LocalPowerManager.BUTTON_EVENT, true);
10323 mTurnOnScreen = false;
10324 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010325
10326 // Check to see if we are now in a state where the screen should
10327 // be enabled, because the window obscured flags have changed.
10328 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010330
10331 /**
10332 * Must be called with the main window manager lock held.
10333 */
10334 void setHoldScreenLocked(boolean holding) {
10335 boolean state = mHoldingScreenWakeLock.isHeld();
10336 if (holding != state) {
10337 if (holding) {
10338 mHoldingScreenWakeLock.acquire();
10339 } else {
10340 mPolicy.screenOnStoppedLw();
10341 mHoldingScreenWakeLock.release();
10342 }
10343 }
10344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010345
10346 void requestAnimationLocked(long delay) {
10347 if (!mAnimationPending) {
10348 mAnimationPending = true;
10349 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10350 }
10351 }
Romain Guy06882f82009-06-10 13:36:04 -070010352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 /**
10354 * Have the surface flinger show a surface, robustly dealing with
10355 * error conditions. In particular, if there is not enough memory
10356 * to show the surface, then we will try to get rid of other surfaces
10357 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010358 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010359 * @return Returns true if the surface was successfully shown.
10360 */
10361 boolean showSurfaceRobustlyLocked(WindowState win) {
10362 try {
10363 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010364 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010366 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010367 if (DEBUG_VISIBILITY) Slog.v(TAG,
10368 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010369 win.mTurnOnScreen = false;
10370 mTurnOnScreen = true;
10371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010372 }
10373 return true;
10374 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010375 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010376 }
Romain Guy06882f82009-06-10 13:36:04 -070010377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010378 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010380 return false;
10381 }
Romain Guy06882f82009-06-10 13:36:04 -070010382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010383 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10384 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010385
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010386 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010389 if (mForceRemoves == null) {
10390 mForceRemoves = new ArrayList<WindowState>();
10391 }
Romain Guy06882f82009-06-10 13:36:04 -070010392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 long callingIdentity = Binder.clearCallingIdentity();
10394 try {
10395 // There was some problem... first, do a sanity check of the
10396 // window list to make sure we haven't left any dangling surfaces
10397 // around.
10398 int N = mWindows.size();
10399 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010400 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010402 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 if (ws.mSurface != null) {
10404 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010405 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010406 + ws + " surface=" + ws.mSurface
10407 + " token=" + win.mToken
10408 + " pid=" + ws.mSession.mPid
10409 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010410 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010411 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 ws.mSurface = null;
10413 mForceRemoves.add(ws);
10414 i--;
10415 N--;
10416 leakedSurface = true;
10417 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010418 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010419 + ws + " surface=" + ws.mSurface
10420 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010421 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010422 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 ws.mSurface = null;
10424 leakedSurface = true;
10425 }
10426 }
10427 }
Romain Guy06882f82009-06-10 13:36:04 -070010428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 boolean killedApps = false;
10430 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010431 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 SparseIntArray pidCandidates = new SparseIntArray();
10433 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010434 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010435 if (ws.mSurface != null) {
10436 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10437 }
10438 }
10439 if (pidCandidates.size() > 0) {
10440 int[] pids = new int[pidCandidates.size()];
10441 for (int i=0; i<pids.length; i++) {
10442 pids[i] = pidCandidates.keyAt(i);
10443 }
10444 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010445 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010446 killedApps = true;
10447 }
10448 } catch (RemoteException e) {
10449 }
10450 }
10451 }
Romain Guy06882f82009-06-10 13:36:04 -070010452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010453 if (leakedSurface || killedApps) {
10454 // We managed to reclaim some memory, so get rid of the trouble
10455 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010456 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010457 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010458 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010459 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010460 win.mSurface = null;
10461 }
Romain Guy06882f82009-06-10 13:36:04 -070010462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010463 try {
10464 win.mClient.dispatchGetNewSurface();
10465 } catch (RemoteException e) {
10466 }
10467 }
10468 } finally {
10469 Binder.restoreCallingIdentity(callingIdentity);
10470 }
10471 }
Romain Guy06882f82009-06-10 13:36:04 -070010472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 private boolean updateFocusedWindowLocked(int mode) {
10474 WindowState newFocus = computeFocusedWindowLocked();
10475 if (mCurrentFocus != newFocus) {
10476 // This check makes sure that we don't already have the focus
10477 // change message pending.
10478 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10479 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010480 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010481 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10482 final WindowState oldFocus = mCurrentFocus;
10483 mCurrentFocus = newFocus;
10484 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010486 final WindowState imWindow = mInputMethodWindow;
10487 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010488 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010489 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010490 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10491 mLayoutNeeded = true;
10492 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10494 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010495 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10496 // Client will do the layout, but we need to assign layers
10497 // for handleNewWindowLocked() below.
10498 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010499 }
10500 }
Jeff Brown349703e2010-06-22 01:27:15 -070010501
10502 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10503 // If we defer assigning layers, then the caller is responsible for
10504 // doing this part.
10505 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010507 return true;
10508 }
10509 return false;
10510 }
Jeff Brown349703e2010-06-22 01:27:15 -070010511
10512 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010513 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515
10516 private WindowState computeFocusedWindowLocked() {
10517 WindowState result = null;
10518 WindowState win;
10519
10520 int i = mWindows.size() - 1;
10521 int nextAppIndex = mAppTokens.size()-1;
10522 WindowToken nextApp = nextAppIndex >= 0
10523 ? mAppTokens.get(nextAppIndex) : null;
10524
10525 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010526 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010527
Joe Onorato8a9b2202010-02-26 18:56:32 -080010528 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010529 TAG, "Looking for focus: " + i
10530 + " = " + win
10531 + ", flags=" + win.mAttrs.flags
10532 + ", canReceive=" + win.canReceiveKeys());
10533
10534 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536 // If this window's application has been removed, just skip it.
10537 if (thisApp != null && thisApp.removed) {
10538 i--;
10539 continue;
10540 }
Romain Guy06882f82009-06-10 13:36:04 -070010541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010542 // If there is a focused app, don't allow focus to go to any
10543 // windows below it. If this is an application window, step
10544 // through the app tokens until we find its app.
10545 if (thisApp != null && nextApp != null && thisApp != nextApp
10546 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10547 int origAppIndex = nextAppIndex;
10548 while (nextAppIndex > 0) {
10549 if (nextApp == mFocusedApp) {
10550 // Whoops, we are below the focused app... no focus
10551 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010552 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010553 TAG, "Reached focused app: " + mFocusedApp);
10554 return null;
10555 }
10556 nextAppIndex--;
10557 nextApp = mAppTokens.get(nextAppIndex);
10558 if (nextApp == thisApp) {
10559 break;
10560 }
10561 }
10562 if (thisApp != nextApp) {
10563 // Uh oh, the app token doesn't exist! This shouldn't
10564 // happen, but if it does we can get totally hosed...
10565 // so restart at the original app.
10566 nextAppIndex = origAppIndex;
10567 nextApp = mAppTokens.get(nextAppIndex);
10568 }
10569 }
10570
10571 // Dispatch to this window if it is wants key events.
10572 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010573 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010574 TAG, "Found focus @ " + i + " = " + win);
10575 result = win;
10576 break;
10577 }
10578
10579 i--;
10580 }
10581
10582 return result;
10583 }
10584
10585 private void startFreezingDisplayLocked() {
10586 if (mDisplayFrozen) {
10587 return;
10588 }
Romain Guy06882f82009-06-10 13:36:04 -070010589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010592 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010593 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 if (mFreezeGcPending != 0) {
10595 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010596 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010597 mH.removeMessages(H.FORCE_GC);
10598 Runtime.getRuntime().gc();
10599 mFreezeGcPending = now;
10600 }
10601 } else {
10602 mFreezeGcPending = now;
10603 }
Romain Guy06882f82009-06-10 13:36:04 -070010604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010605 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010606
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010607 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010608
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010609 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10610 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010611 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010612 mAppTransitionReady = true;
10613 }
Romain Guy06882f82009-06-10 13:36:04 -070010614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010615 if (PROFILE_ORIENTATION) {
10616 File file = new File("/data/system/frozen");
10617 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10618 }
10619 Surface.freezeDisplay(0);
10620 }
Romain Guy06882f82009-06-10 13:36:04 -070010621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010622 private void stopFreezingDisplayLocked() {
10623 if (!mDisplayFrozen) {
10624 return;
10625 }
Romain Guy06882f82009-06-10 13:36:04 -070010626
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010627 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10628 return;
10629 }
10630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010631 mDisplayFrozen = false;
10632 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10633 if (PROFILE_ORIENTATION) {
10634 Debug.stopMethodTracing();
10635 }
10636 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010637
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010638 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010639
Christopher Tateb696aee2010-04-02 19:08:30 -070010640 // While the display is frozen we don't re-compute the orientation
10641 // to avoid inconsistent states. However, something interesting
10642 // could have actually changed during that time so re-evaluate it
10643 // now to catch that.
10644 if (updateOrientationFromAppTokensLocked()) {
10645 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10646 }
10647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010648 // A little kludge: a lot could have happened while the
10649 // display was frozen, so now that we are coming back we
10650 // do a gc so that any remote references the system
10651 // processes holds on others can be released if they are
10652 // no longer needed.
10653 mH.removeMessages(H.FORCE_GC);
10654 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10655 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010657 mScreenFrozenLock.release();
10658 }
Romain Guy06882f82009-06-10 13:36:04 -070010659
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010660 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10661 DisplayMetrics dm) {
10662 if (index < tokens.length) {
10663 String str = tokens[index];
10664 if (str != null && str.length() > 0) {
10665 try {
10666 int val = Integer.parseInt(str);
10667 return val;
10668 } catch (Exception e) {
10669 }
10670 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010671 }
10672 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10673 return defDps;
10674 }
10675 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10676 return val;
10677 }
10678
10679 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010680 final String[] mTokens;
10681 final String mText;
10682 final Paint mTextPaint;
10683 final int mTextWidth;
10684 final int mTextHeight;
10685 final int mTextAscent;
10686 final int mTextDescent;
10687 final int mDeltaX;
10688 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010689
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010690 Surface mSurface;
10691 int mLastDW;
10692 int mLastDH;
10693 boolean mDrawNeeded;
10694
10695 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010696 final DisplayMetrics dm = new DisplayMetrics();
10697 mDisplay.getMetrics(dm);
10698
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010699 if (false) {
10700 Log.i(TAG, "*********************** WATERMARK");
10701 for (int i=0; i<tokens.length; i++) {
10702 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10703 }
10704 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010705
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010706 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010707
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010708 StringBuilder builder = new StringBuilder(32);
10709 int len = mTokens[0].length();
10710 len = len & ~1;
10711 for (int i=0; i<len; i+=2) {
10712 int c1 = mTokens[0].charAt(i);
10713 int c2 = mTokens[0].charAt(i+1);
10714 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10715 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10716 else c1 -= '0';
10717 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10718 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10719 else c2 -= '0';
10720 builder.append((char)(255-((c1*16)+c2)));
10721 }
10722 mText = builder.toString();
10723 if (false) {
10724 Log.i(TAG, "Final text: " + mText);
10725 }
10726
10727 int fontSize = getPropertyInt(tokens, 1,
10728 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10729
10730 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10731 mTextPaint.setTextSize(fontSize);
10732 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10733
10734 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10735 mTextWidth = (int)mTextPaint.measureText(mText);
10736 mTextAscent = fm.ascent;
10737 mTextDescent = fm.descent;
10738 mTextHeight = fm.descent - fm.ascent;
10739
10740 mDeltaX = getPropertyInt(tokens, 2,
10741 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10742 mDeltaY = getPropertyInt(tokens, 3,
10743 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10744 int shadowColor = getPropertyInt(tokens, 4,
10745 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10746 int color = getPropertyInt(tokens, 5,
10747 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10748 int shadowRadius = getPropertyInt(tokens, 6,
10749 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10750 int shadowDx = getPropertyInt(tokens, 8,
10751 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10752 int shadowDy = getPropertyInt(tokens, 9,
10753 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10754
10755 mTextPaint.setColor(color);
10756 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010757
10758 try {
10759 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010760 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010761 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010762 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010763 mSurface.show();
10764 } catch (OutOfResourcesException e) {
10765 }
10766 }
10767
10768 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010769 if (mLastDW != dw || mLastDH != dh) {
10770 mLastDW = dw;
10771 mLastDH = dh;
10772 mSurface.setSize(dw, dh);
10773 mDrawNeeded = true;
10774 }
10775 }
10776
10777 void drawIfNeeded() {
10778 if (mDrawNeeded) {
10779 final int dw = mLastDW;
10780 final int dh = mLastDH;
10781
10782 mDrawNeeded = false;
10783 Rect dirty = new Rect(0, 0, dw, dh);
10784 Canvas c = null;
10785 try {
10786 c = mSurface.lockCanvas(dirty);
10787 } catch (IllegalArgumentException e) {
10788 } catch (OutOfResourcesException e) {
10789 }
10790 if (c != null) {
10791 int deltaX = mDeltaX;
10792 int deltaY = mDeltaY;
10793
10794 // deltaX shouldn't be close to a round fraction of our
10795 // x step, or else things will line up too much.
10796 int div = (dw+mTextWidth)/deltaX;
10797 int rem = (dw+mTextWidth) - (div*deltaX);
10798 int qdelta = deltaX/4;
10799 if (rem < qdelta || rem > (deltaX-qdelta)) {
10800 deltaX += deltaX/3;
10801 }
10802
10803 int y = -mTextHeight;
10804 int x = -mTextWidth;
10805 while (y < (dh+mTextHeight)) {
10806 c.drawText(mText, x, y, mTextPaint);
10807 x += deltaX;
10808 if (x >= dw) {
10809 x -= (dw+mTextWidth);
10810 y += deltaY;
10811 }
10812 }
10813 mSurface.unlockCanvasAndPost(c);
10814 }
10815 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010816 }
10817 }
10818
10819 void createWatermark() {
10820 if (mWatermark != null) {
10821 return;
10822 }
10823
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010824 File file = new File("/system/etc/setup.conf");
10825 FileInputStream in = null;
10826 try {
10827 in = new FileInputStream(file);
10828 DataInputStream ind = new DataInputStream(in);
10829 String line = ind.readLine();
10830 if (line != null) {
10831 String[] toks = line.split("%");
10832 if (toks != null && toks.length > 0) {
10833 mWatermark = new Watermark(mFxSession, toks);
10834 }
10835 }
10836 } catch (FileNotFoundException e) {
10837 } catch (IOException e) {
10838 } finally {
10839 if (in != null) {
10840 try {
10841 in.close();
10842 } catch (IOException e) {
10843 }
10844 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010845 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010846 }
10847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010848 @Override
10849 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10850 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10851 != PackageManager.PERMISSION_GRANTED) {
10852 pw.println("Permission Denial: can't dump WindowManager from from pid="
10853 + Binder.getCallingPid()
10854 + ", uid=" + Binder.getCallingUid());
10855 return;
10856 }
Romain Guy06882f82009-06-10 13:36:04 -070010857
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010858 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010859 pw.println(" ");
10860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010861 synchronized(mWindowMap) {
10862 pw.println("Current Window Manager state:");
10863 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010864 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010865 pw.print(" Window #"); pw.print(i); pw.print(' ');
10866 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010867 w.dump(pw, " ");
10868 }
10869 if (mInputMethodDialogs.size() > 0) {
10870 pw.println(" ");
10871 pw.println(" Input method dialogs:");
10872 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10873 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010874 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010875 }
10876 }
10877 if (mPendingRemove.size() > 0) {
10878 pw.println(" ");
10879 pw.println(" Remove pending for:");
10880 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10881 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010882 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10883 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 w.dump(pw, " ");
10885 }
10886 }
10887 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10888 pw.println(" ");
10889 pw.println(" Windows force removing:");
10890 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10891 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010892 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10893 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010894 w.dump(pw, " ");
10895 }
10896 }
10897 if (mDestroySurface.size() > 0) {
10898 pw.println(" ");
10899 pw.println(" Windows waiting to destroy their surface:");
10900 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10901 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010902 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10903 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010904 w.dump(pw, " ");
10905 }
10906 }
10907 if (mLosingFocus.size() > 0) {
10908 pw.println(" ");
10909 pw.println(" Windows losing focus:");
10910 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10911 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010912 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10913 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010914 w.dump(pw, " ");
10915 }
10916 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010917 if (mResizingWindows.size() > 0) {
10918 pw.println(" ");
10919 pw.println(" Windows waiting to resize:");
10920 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10921 WindowState w = mResizingWindows.get(i);
10922 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10923 pw.print(w); pw.println(":");
10924 w.dump(pw, " ");
10925 }
10926 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010927 if (mSessions.size() > 0) {
10928 pw.println(" ");
10929 pw.println(" All active sessions:");
10930 Iterator<Session> it = mSessions.iterator();
10931 while (it.hasNext()) {
10932 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010933 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010934 s.dump(pw, " ");
10935 }
10936 }
10937 if (mTokenMap.size() > 0) {
10938 pw.println(" ");
10939 pw.println(" All tokens:");
10940 Iterator<WindowToken> it = mTokenMap.values().iterator();
10941 while (it.hasNext()) {
10942 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010943 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010944 token.dump(pw, " ");
10945 }
10946 }
10947 if (mTokenList.size() > 0) {
10948 pw.println(" ");
10949 pw.println(" Window token list:");
10950 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010951 pw.print(" #"); pw.print(i); pw.print(": ");
10952 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010953 }
10954 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010955 if (mWallpaperTokens.size() > 0) {
10956 pw.println(" ");
10957 pw.println(" Wallpaper tokens:");
10958 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10959 WindowToken token = mWallpaperTokens.get(i);
10960 pw.print(" Wallpaper #"); pw.print(i);
10961 pw.print(' '); pw.print(token); pw.println(':');
10962 token.dump(pw, " ");
10963 }
10964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010965 if (mAppTokens.size() > 0) {
10966 pw.println(" ");
10967 pw.println(" Application tokens in Z order:");
10968 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010969 pw.print(" App #"); pw.print(i); pw.print(": ");
10970 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010971 }
10972 }
10973 if (mFinishedStarting.size() > 0) {
10974 pw.println(" ");
10975 pw.println(" Finishing start of application tokens:");
10976 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10977 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010978 pw.print(" Finished Starting #"); pw.print(i);
10979 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 token.dump(pw, " ");
10981 }
10982 }
10983 if (mExitingTokens.size() > 0) {
10984 pw.println(" ");
10985 pw.println(" Exiting tokens:");
10986 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10987 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010988 pw.print(" Exiting #"); pw.print(i);
10989 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010990 token.dump(pw, " ");
10991 }
10992 }
10993 if (mExitingAppTokens.size() > 0) {
10994 pw.println(" ");
10995 pw.println(" Exiting application tokens:");
10996 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10997 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010998 pw.print(" Exiting App #"); pw.print(i);
10999 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011000 token.dump(pw, " ");
11001 }
11002 }
11003 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011004 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11005 pw.print(" mLastFocus="); pw.println(mLastFocus);
11006 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11007 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11008 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011009 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011010 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11011 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11012 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11013 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011014 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11015 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11016 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011017 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11018 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11019 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11020 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011021 if (mDimAnimator != null) {
11022 mDimAnimator.printTo(pw);
11023 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011024 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011025 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011026 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011027 pw.print(mInputMethodAnimLayerAdjustment);
11028 pw.print(" mWallpaperAnimLayerAdjustment=");
11029 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011030 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11031 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011032 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11033 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011034 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11035 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011036 pw.print(" mRotation="); pw.print(mRotation);
11037 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11038 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11039 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11040 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11041 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11042 pw.print(" mNextAppTransition=0x");
11043 pw.print(Integer.toHexString(mNextAppTransition));
11044 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011045 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011046 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011047 if (mNextAppTransitionPackage != null) {
11048 pw.print(" mNextAppTransitionPackage=");
11049 pw.print(mNextAppTransitionPackage);
11050 pw.print(", mNextAppTransitionEnter=0x");
11051 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11052 pw.print(", mNextAppTransitionExit=0x");
11053 pw.print(Integer.toHexString(mNextAppTransitionExit));
11054 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011055 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11056 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011057 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11058 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11059 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11060 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011061 if (mOpeningApps.size() > 0) {
11062 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11063 }
11064 if (mClosingApps.size() > 0) {
11065 pw.print(" mClosingApps="); pw.println(mClosingApps);
11066 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011067 if (mToTopApps.size() > 0) {
11068 pw.print(" mToTopApps="); pw.println(mToTopApps);
11069 }
11070 if (mToBottomApps.size() > 0) {
11071 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11072 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011073 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11074 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011075 }
11076 }
11077
Jeff Brown349703e2010-06-22 01:27:15 -070011078 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011079 public void monitor() {
11080 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011081 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011082 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011083
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011084 /**
11085 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011086 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011087 */
11088 private static class DimAnimator {
11089 Surface mDimSurface;
11090 boolean mDimShown = false;
11091 float mDimCurrentAlpha;
11092 float mDimTargetAlpha;
11093 float mDimDeltaPerMs;
11094 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011095
11096 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011097
11098 DimAnimator (SurfaceSession session) {
11099 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011100 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011101 + mDimSurface + ": CREATE");
11102 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011103 mDimSurface = new Surface(session, 0,
11104 "DimSurface",
11105 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011106 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011107 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011108 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011109 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011110 }
11111 }
11112 }
11113
11114 /**
11115 * Show the dim surface.
11116 */
11117 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011118 if (!mDimShown) {
11119 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11120 dw + "x" + dh + ")");
11121 mDimShown = true;
11122 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011123 mLastDimWidth = dw;
11124 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011125 mDimSurface.setPosition(0, 0);
11126 mDimSurface.setSize(dw, dh);
11127 mDimSurface.show();
11128 } catch (RuntimeException e) {
11129 Slog.w(TAG, "Failure showing dim surface", e);
11130 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011131 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11132 mLastDimWidth = dw;
11133 mLastDimHeight = dh;
11134 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011135 }
11136 }
11137
11138 /**
11139 * Set's the dim surface's layer and update dim parameters that will be used in
11140 * {@link updateSurface} after all windows are examined.
11141 */
11142 void updateParameters(WindowState w, long currentTime) {
11143 mDimSurface.setLayer(w.mAnimLayer-1);
11144
11145 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011146 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011147 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011148 if (mDimTargetAlpha != target) {
11149 // If the desired dim level has changed, then
11150 // start an animation to it.
11151 mLastDimAnimTime = currentTime;
11152 long duration = (w.mAnimating && w.mAnimation != null)
11153 ? w.mAnimation.computeDurationHint()
11154 : DEFAULT_DIM_DURATION;
11155 if (target > mDimTargetAlpha) {
11156 // This is happening behind the activity UI,
11157 // so we can make it run a little longer to
11158 // give a stronger impression without disrupting
11159 // the user.
11160 duration *= DIM_DURATION_MULTIPLIER;
11161 }
11162 if (duration < 1) {
11163 // Don't divide by zero
11164 duration = 1;
11165 }
11166 mDimTargetAlpha = target;
11167 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11168 }
11169 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011170
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011171 /**
11172 * Updating the surface's alpha. Returns true if the animation continues, or returns
11173 * false when the animation is finished and the dim surface is hidden.
11174 */
11175 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11176 if (!dimming) {
11177 if (mDimTargetAlpha != 0) {
11178 mLastDimAnimTime = currentTime;
11179 mDimTargetAlpha = 0;
11180 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11181 }
11182 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011183
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011184 boolean animating = false;
11185 if (mLastDimAnimTime != 0) {
11186 mDimCurrentAlpha += mDimDeltaPerMs
11187 * (currentTime-mLastDimAnimTime);
11188 boolean more = true;
11189 if (displayFrozen) {
11190 // If the display is frozen, there is no reason to animate.
11191 more = false;
11192 } else if (mDimDeltaPerMs > 0) {
11193 if (mDimCurrentAlpha > mDimTargetAlpha) {
11194 more = false;
11195 }
11196 } else if (mDimDeltaPerMs < 0) {
11197 if (mDimCurrentAlpha < mDimTargetAlpha) {
11198 more = false;
11199 }
11200 } else {
11201 more = false;
11202 }
11203
11204 // Do we need to continue animating?
11205 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011206 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011207 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11208 mLastDimAnimTime = currentTime;
11209 mDimSurface.setAlpha(mDimCurrentAlpha);
11210 animating = true;
11211 } else {
11212 mDimCurrentAlpha = mDimTargetAlpha;
11213 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011214 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011215 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11216 mDimSurface.setAlpha(mDimCurrentAlpha);
11217 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011218 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011219 + ": HIDE");
11220 try {
11221 mDimSurface.hide();
11222 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011223 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011224 }
11225 mDimShown = false;
11226 }
11227 }
11228 }
11229 return animating;
11230 }
11231
11232 public void printTo(PrintWriter pw) {
11233 pw.print(" mDimShown="); pw.print(mDimShown);
11234 pw.print(" current="); pw.print(mDimCurrentAlpha);
11235 pw.print(" target="); pw.print(mDimTargetAlpha);
11236 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11237 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11238 }
11239 }
11240
11241 /**
11242 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11243 * This is used for opening/closing transition for apps in compatible mode.
11244 */
11245 private static class FadeInOutAnimation extends Animation {
11246 int mWidth;
11247 boolean mFadeIn;
11248
11249 public FadeInOutAnimation(boolean fadeIn) {
11250 setInterpolator(new AccelerateInterpolator());
11251 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11252 mFadeIn = fadeIn;
11253 }
11254
11255 @Override
11256 protected void applyTransformation(float interpolatedTime, Transformation t) {
11257 float x = interpolatedTime;
11258 if (!mFadeIn) {
11259 x = 1.0f - x; // reverse the interpolation for fade out
11260 }
11261 if (x < 0.5) {
11262 // move the window out of the screen.
11263 t.getMatrix().setTranslate(mWidth, 0);
11264 } else {
11265 t.getMatrix().setTranslate(0, 0);// show
11266 t.setAlpha((x - 0.5f) * 2);
11267 }
11268 }
11269
11270 @Override
11271 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11272 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11273 mWidth = width;
11274 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011275
11276 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011277 public int getZAdjustment() {
11278 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011279 }
11280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011281}