blob: 41b3da681cf74299541349725d1438716da6937b [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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-10-19 15:15:08 -0700648 mNotifiedWindows.clear();
649 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700650 evt.recycle();
651 }
652
Chris Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Tated4533f12010-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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-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
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004845 public void freezeRotation() {
4846 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4847 "setRotation()")) {
4848 throw new SecurityException("Requires SET_ORIENTATION permission");
4849 }
4850
4851 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4852 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4853 }
4854
4855 public void thawRotation() {
4856 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4857 "setRotation()")) {
4858 throw new SecurityException("Requires SET_ORIENTATION permission");
4859 }
4860
4861 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4862 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4863 }
4864
Romain Guy06882f82009-06-10 13:36:04 -07004865 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004866 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004868 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004869 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 }
4871
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004872 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
Romain Guy06882f82009-06-10 13:36:04 -07004874
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004875 public void setRotationUnchecked(int rotation,
4876 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004877 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004878 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880 long origId = Binder.clearCallingIdentity();
4881 boolean changed;
4882 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004883 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 }
Romain Guy06882f82009-06-10 13:36:04 -07004885
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004886 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004887 sendNewConfiguration();
4888 }
Romain Guy06882f82009-06-10 13:36:04 -07004889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004890 Binder.restoreCallingIdentity(origId);
4891 }
Romain Guy06882f82009-06-10 13:36:04 -07004892
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004893 /**
4894 * Apply a new rotation to the screen, respecting the requests of
4895 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4896 * re-evaluate the desired rotation.
4897 *
4898 * Returns null if the rotation has been changed. In this case YOU
4899 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4900 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004901 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 boolean changed;
4903 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4904 rotation = mRequestedRotation;
4905 } else {
4906 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004907 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004908 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004909 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004910 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004911 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004912 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004916 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 "Rotation changed to " + rotation
4918 + " from " + mRotation
4919 + " (forceApp=" + mForcedAppOrientation
4920 + ", req=" + mRequestedRotation + ")");
4921 mRotation = rotation;
4922 mWindowsFreezingScreen = true;
4923 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4924 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4925 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004926 mWaitingForConfig = true;
4927 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004928 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004929 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004930 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004931 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004932 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933 }
4934 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004935 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 if (w.mSurface != null) {
4937 w.mOrientationChanging = true;
4938 }
4939 }
4940 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4941 try {
4942 mRotationWatchers.get(i).onRotationChanged(rotation);
4943 } catch (RemoteException e) {
4944 }
4945 }
4946 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004948 return changed;
4949 }
Romain Guy06882f82009-06-10 13:36:04 -07004950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004951 public int getRotation() {
4952 return mRotation;
4953 }
4954
4955 public int watchRotation(IRotationWatcher watcher) {
4956 final IBinder watcherBinder = watcher.asBinder();
4957 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4958 public void binderDied() {
4959 synchronized (mWindowMap) {
4960 for (int i=0; i<mRotationWatchers.size(); i++) {
4961 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004962 IRotationWatcher removed = mRotationWatchers.remove(i);
4963 if (removed != null) {
4964 removed.asBinder().unlinkToDeath(this, 0);
4965 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004966 i--;
4967 }
4968 }
4969 }
4970 }
4971 };
Romain Guy06882f82009-06-10 13:36:04 -07004972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004973 synchronized (mWindowMap) {
4974 try {
4975 watcher.asBinder().linkToDeath(dr, 0);
4976 mRotationWatchers.add(watcher);
4977 } catch (RemoteException e) {
4978 // Client died, no cleanup needed.
4979 }
Romain Guy06882f82009-06-10 13:36:04 -07004980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 return mRotation;
4982 }
4983 }
4984
4985 /**
4986 * Starts the view server on the specified port.
4987 *
4988 * @param port The port to listener to.
4989 *
4990 * @return True if the server was successfully started, false otherwise.
4991 *
4992 * @see com.android.server.ViewServer
4993 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4994 */
4995 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004996 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004997 return false;
4998 }
4999
5000 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
5001 return false;
5002 }
5003
5004 if (port < 1024) {
5005 return false;
5006 }
5007
5008 if (mViewServer != null) {
5009 if (!mViewServer.isRunning()) {
5010 try {
5011 return mViewServer.start();
5012 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005013 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005014 }
5015 }
5016 return false;
5017 }
5018
5019 try {
5020 mViewServer = new ViewServer(this, port);
5021 return mViewServer.start();
5022 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005023 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005024 }
5025 return false;
5026 }
5027
Romain Guy06882f82009-06-10 13:36:04 -07005028 private boolean isSystemSecure() {
5029 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5030 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5031 }
5032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 /**
5034 * Stops the view server if it exists.
5035 *
5036 * @return True if the server stopped, false if it wasn't started or
5037 * couldn't be stopped.
5038 *
5039 * @see com.android.server.ViewServer
5040 */
5041 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005042 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 return false;
5044 }
5045
5046 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5047 return false;
5048 }
5049
5050 if (mViewServer != null) {
5051 return mViewServer.stop();
5052 }
5053 return false;
5054 }
5055
5056 /**
5057 * Indicates whether the view server is running.
5058 *
5059 * @return True if the server is running, false otherwise.
5060 *
5061 * @see com.android.server.ViewServer
5062 */
5063 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005064 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 return false;
5066 }
5067
5068 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5069 return false;
5070 }
5071
5072 return mViewServer != null && mViewServer.isRunning();
5073 }
5074
5075 /**
5076 * Lists all availble windows in the system. The listing is written in the
5077 * specified Socket's output stream with the following syntax:
5078 * windowHashCodeInHexadecimal windowName
5079 * Each line of the ouput represents a different window.
5080 *
5081 * @param client The remote client to send the listing to.
5082 * @return False if an error occured, true otherwise.
5083 */
5084 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005085 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005086 return false;
5087 }
5088
5089 boolean result = true;
5090
Jeff Browne33348b2010-07-15 23:54:05 -07005091 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005092 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005093 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005094 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005095 }
5096
5097 BufferedWriter out = null;
5098
5099 // Any uncaught exception will crash the system process
5100 try {
5101 OutputStream clientStream = client.getOutputStream();
5102 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5103
5104 final int count = windows.length;
5105 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005106 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005107 out.write(Integer.toHexString(System.identityHashCode(w)));
5108 out.write(' ');
5109 out.append(w.mAttrs.getTitle());
5110 out.write('\n');
5111 }
5112
5113 out.write("DONE.\n");
5114 out.flush();
5115 } catch (Exception e) {
5116 result = false;
5117 } finally {
5118 if (out != null) {
5119 try {
5120 out.close();
5121 } catch (IOException e) {
5122 result = false;
5123 }
5124 }
5125 }
5126
5127 return result;
5128 }
5129
5130 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005131 * Returns the focused window in the following format:
5132 * windowHashCodeInHexadecimal windowName
5133 *
5134 * @param client The remote client to send the listing to.
5135 * @return False if an error occurred, true otherwise.
5136 */
5137 boolean viewServerGetFocusedWindow(Socket client) {
5138 if (isSystemSecure()) {
5139 return false;
5140 }
5141
5142 boolean result = true;
5143
5144 WindowState focusedWindow = getFocusedWindow();
5145
5146 BufferedWriter out = null;
5147
5148 // Any uncaught exception will crash the system process
5149 try {
5150 OutputStream clientStream = client.getOutputStream();
5151 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5152
5153 if(focusedWindow != null) {
5154 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5155 out.write(' ');
5156 out.append(focusedWindow.mAttrs.getTitle());
5157 }
5158 out.write('\n');
5159 out.flush();
5160 } catch (Exception e) {
5161 result = false;
5162 } finally {
5163 if (out != null) {
5164 try {
5165 out.close();
5166 } catch (IOException e) {
5167 result = false;
5168 }
5169 }
5170 }
5171
5172 return result;
5173 }
5174
5175 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005176 * Sends a command to a target window. The result of the command, if any, will be
5177 * written in the output stream of the specified socket.
5178 *
5179 * The parameters must follow this syntax:
5180 * windowHashcode extra
5181 *
5182 * Where XX is the length in characeters of the windowTitle.
5183 *
5184 * The first parameter is the target window. The window with the specified hashcode
5185 * will be the target. If no target can be found, nothing happens. The extra parameters
5186 * will be delivered to the target window and as parameters to the command itself.
5187 *
5188 * @param client The remote client to sent the result, if any, to.
5189 * @param command The command to execute.
5190 * @param parameters The command parameters.
5191 *
5192 * @return True if the command was successfully delivered, false otherwise. This does
5193 * not indicate whether the command itself was successful.
5194 */
5195 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005196 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005197 return false;
5198 }
5199
5200 boolean success = true;
5201 Parcel data = null;
5202 Parcel reply = null;
5203
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005204 BufferedWriter out = null;
5205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005206 // Any uncaught exception will crash the system process
5207 try {
5208 // Find the hashcode of the window
5209 int index = parameters.indexOf(' ');
5210 if (index == -1) {
5211 index = parameters.length();
5212 }
5213 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005214 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005215
5216 // Extract the command's parameter after the window description
5217 if (index < parameters.length()) {
5218 parameters = parameters.substring(index + 1);
5219 } else {
5220 parameters = "";
5221 }
5222
5223 final WindowManagerService.WindowState window = findWindow(hashCode);
5224 if (window == null) {
5225 return false;
5226 }
5227
5228 data = Parcel.obtain();
5229 data.writeInterfaceToken("android.view.IWindow");
5230 data.writeString(command);
5231 data.writeString(parameters);
5232 data.writeInt(1);
5233 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5234
5235 reply = Parcel.obtain();
5236
5237 final IBinder binder = window.mClient.asBinder();
5238 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5239 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5240
5241 reply.readException();
5242
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005243 if (!client.isOutputShutdown()) {
5244 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5245 out.write("DONE\n");
5246 out.flush();
5247 }
5248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005250 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 success = false;
5252 } finally {
5253 if (data != null) {
5254 data.recycle();
5255 }
5256 if (reply != null) {
5257 reply.recycle();
5258 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005259 if (out != null) {
5260 try {
5261 out.close();
5262 } catch (IOException e) {
5263
5264 }
5265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005266 }
5267
5268 return success;
5269 }
5270
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005271 public void addWindowChangeListener(WindowChangeListener listener) {
5272 synchronized(mWindowMap) {
5273 mWindowChangeListeners.add(listener);
5274 }
5275 }
5276
5277 public void removeWindowChangeListener(WindowChangeListener listener) {
5278 synchronized(mWindowMap) {
5279 mWindowChangeListeners.remove(listener);
5280 }
5281 }
5282
5283 private void notifyWindowsChanged() {
5284 WindowChangeListener[] windowChangeListeners;
5285 synchronized(mWindowMap) {
5286 if(mWindowChangeListeners.isEmpty()) {
5287 return;
5288 }
5289 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5290 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5291 }
5292 int N = windowChangeListeners.length;
5293 for(int i = 0; i < N; i++) {
5294 windowChangeListeners[i].windowsChanged();
5295 }
5296 }
5297
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005298 private void notifyFocusChanged() {
5299 WindowChangeListener[] windowChangeListeners;
5300 synchronized(mWindowMap) {
5301 if(mWindowChangeListeners.isEmpty()) {
5302 return;
5303 }
5304 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5305 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5306 }
5307 int N = windowChangeListeners.length;
5308 for(int i = 0; i < N; i++) {
5309 windowChangeListeners[i].focusChanged();
5310 }
5311 }
5312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 private WindowState findWindow(int hashCode) {
5314 if (hashCode == -1) {
5315 return getFocusedWindow();
5316 }
5317
5318 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005319 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005320 final int count = windows.size();
5321
5322 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005323 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005324 if (System.identityHashCode(w) == hashCode) {
5325 return w;
5326 }
5327 }
5328 }
5329
5330 return null;
5331 }
5332
5333 /*
5334 * Instruct the Activity Manager to fetch the current configuration and broadcast
5335 * that to config-changed listeners if appropriate.
5336 */
5337 void sendNewConfiguration() {
5338 try {
5339 mActivityManager.updateConfiguration(null);
5340 } catch (RemoteException e) {
5341 }
5342 }
Romain Guy06882f82009-06-10 13:36:04 -07005343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005344 public Configuration computeNewConfiguration() {
5345 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005346 return computeNewConfigurationLocked();
5347 }
5348 }
Romain Guy06882f82009-06-10 13:36:04 -07005349
Dianne Hackbornc485a602009-03-24 22:39:49 -07005350 Configuration computeNewConfigurationLocked() {
5351 Configuration config = new Configuration();
5352 if (!computeNewConfigurationLocked(config)) {
5353 return null;
5354 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005355 return config;
5356 }
Romain Guy06882f82009-06-10 13:36:04 -07005357
Dianne Hackbornc485a602009-03-24 22:39:49 -07005358 boolean computeNewConfigurationLocked(Configuration config) {
5359 if (mDisplay == null) {
5360 return false;
5361 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005362
5363 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005364
5365 // Use the effective "visual" dimensions based on current rotation
5366 final boolean rotated = (mRotation == Surface.ROTATION_90
5367 || mRotation == Surface.ROTATION_270);
5368 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5369 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5370
Dianne Hackbornc485a602009-03-24 22:39:49 -07005371 int orientation = Configuration.ORIENTATION_SQUARE;
5372 if (dw < dh) {
5373 orientation = Configuration.ORIENTATION_PORTRAIT;
5374 } else if (dw > dh) {
5375 orientation = Configuration.ORIENTATION_LANDSCAPE;
5376 }
5377 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005378
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005379 DisplayMetrics dm = new DisplayMetrics();
5380 mDisplay.getMetrics(dm);
5381 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5382
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005383 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005384 // Note we only do this once because at this point we don't
5385 // expect the screen to change in this way at runtime, and want
5386 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005387 int longSize = dw;
5388 int shortSize = dh;
5389 if (longSize < shortSize) {
5390 int tmp = longSize;
5391 longSize = shortSize;
5392 shortSize = tmp;
5393 }
5394 longSize = (int)(longSize/dm.density);
5395 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005396
Dianne Hackborn723738c2009-06-25 19:48:04 -07005397 // These semi-magic numbers define our compatibility modes for
5398 // applications with different screens. Don't change unless you
5399 // make sure to test lots and lots of apps!
5400 if (longSize < 470) {
5401 // This is shorter than an HVGA normal density screen (which
5402 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005403 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5404 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005405 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005406 // What size is this screen screen?
5407 if (longSize >= 800 && shortSize >= 600) {
5408 // SVGA or larger screens at medium density are the point
5409 // at which we consider it to be an extra large screen.
5410 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005411 } else if (longSize >= 530 && shortSize >= 400) {
5412 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005413 // at which we consider it to be a large screen.
5414 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5415 } else {
5416 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005417
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005418 // If this screen is wider than normal HVGA, or taller
5419 // than FWVGA, then for old apps we want to run in size
5420 // compatibility mode.
5421 if (shortSize > 321 || longSize > 570) {
5422 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5423 }
5424 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005425
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005426 // Is this a long screen?
5427 if (((longSize*3)/5) >= (shortSize-1)) {
5428 // Anything wider than WVGA (5:3) is considering to be long.
5429 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5430 } else {
5431 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5432 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005433 }
5434 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005435 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005436
Dianne Hackbornc485a602009-03-24 22:39:49 -07005437 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5438 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5439 mPolicy.adjustConfigurationLw(config);
5440 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005441 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005442
5443 // -------------------------------------------------------------
5444 // Drag and drop
5445 // -------------------------------------------------------------
5446
5447 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5448 boolean localOnly, int width, int height, Surface outSurface) {
5449 if (DEBUG_DRAG) {
5450 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5451 + " local=" + localOnly + " win=" + window
5452 + " asbinder=" + window.asBinder());
5453 }
5454
5455 final int callerPid = Binder.getCallingPid();
5456 final long origId = Binder.clearCallingIdentity();
5457 IBinder token = null;
5458
5459 try {
5460 synchronized (mWindowMap) {
5461 try {
5462 // !!! TODO: fail if the given window does not currently have touch focus?
5463
5464 if (mDragState == null) {
5465 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5466 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5467 outSurface.copyFrom(surface);
5468 token = new Binder();
5469 mDragState = new DragState(token, surface, localOnly);
5470 mDragState.mSurface = surface;
5471 mDragState.mLocalOnly = localOnly;
5472 token = mDragState.mToken = new Binder();
5473
5474 // 5 second timeout for this window to actually begin the drag
5475 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5476 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5477 mH.sendMessageDelayed(msg, 5000);
5478 } else {
5479 Slog.w(TAG, "Drag already in progress");
5480 }
5481 } catch (Surface.OutOfResourcesException e) {
5482 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5483 if (mDragState != null) {
5484 mDragState.reset();
5485 mDragState = null;
5486 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005487 }
5488 }
5489 } finally {
5490 Binder.restoreCallingIdentity(origId);
5491 }
5492
5493 return token;
5494 }
5495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 // -------------------------------------------------------------
5497 // Input Events and Focus Management
5498 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005499
Jeff Brown349703e2010-06-22 01:27:15 -07005500 InputMonitor mInputMonitor = new InputMonitor();
5501
5502 /* Tracks the progress of input dispatch and ensures that input dispatch state
5503 * is kept in sync with changes in window focus, visibility, registration, and
5504 * other relevant Window Manager state transitions. */
5505 final class InputMonitor {
5506 // Current window with input focus for keys and other non-touch events. May be null.
5507 private WindowState mInputFocus;
5508
5509 // When true, prevents input dispatch from proceeding until set to false again.
5510 private boolean mInputDispatchFrozen;
5511
5512 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5513 private boolean mInputDispatchEnabled = true;
5514
5515 // Temporary list of windows information to provide to the input dispatcher.
5516 private InputWindowList mTempInputWindows = new InputWindowList();
5517
5518 // Temporary input application object to provide to the input dispatcher.
5519 private InputApplication mTempInputApplication = new InputApplication();
5520
5521 /* Notifies the window manager about a broken input channel.
5522 *
5523 * Called by the InputManager.
5524 */
5525 public void notifyInputChannelBroken(InputChannel inputChannel) {
5526 synchronized (mWindowMap) {
5527 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5528 if (windowState == null) {
5529 return; // irrelevant
5530 }
5531
5532 Slog.i(TAG, "WINDOW DIED " + windowState);
5533 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005534 }
5535 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005536
Jeff Brown519e0242010-09-15 15:18:56 -07005537 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005538 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005539 *
5540 * Called by the InputManager.
5541 */
Jeff Brown519e0242010-09-15 15:18:56 -07005542 public long notifyANR(Object token, InputChannel inputChannel) {
5543 AppWindowToken appWindowToken = null;
5544 if (inputChannel != null) {
5545 synchronized (mWindowMap) {
5546 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5547 if (windowState != null) {
5548 Slog.i(TAG, "Input event dispatching timed out sending to "
5549 + windowState.mAttrs.getTitle());
5550 appWindowToken = windowState.mAppToken;
5551 }
Jeff Brown349703e2010-06-22 01:27:15 -07005552 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005553 }
5554
Jeff Brown519e0242010-09-15 15:18:56 -07005555 if (appWindowToken == null && token != null) {
5556 appWindowToken = (AppWindowToken) token;
5557 Slog.i(TAG, "Input event dispatching timed out sending to application "
5558 + appWindowToken.stringName);
5559 }
Jeff Brown349703e2010-06-22 01:27:15 -07005560
Jeff Brown519e0242010-09-15 15:18:56 -07005561 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005562 try {
5563 // Notify the activity manager about the timeout and let it decide whether
5564 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005565 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005566 if (! abort) {
5567 // The activity manager declined to abort dispatching.
5568 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005569 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005570 }
Jeff Brown349703e2010-06-22 01:27:15 -07005571 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005572 }
5573 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005574 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005575 }
5576
Jeff Brown349703e2010-06-22 01:27:15 -07005577 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5578 synchronized (mWindowMap) {
5579 return getWindowStateForInputChannelLocked(inputChannel);
5580 }
5581 }
5582
5583 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5584 int windowCount = mWindows.size();
5585 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005586 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005587 if (windowState.mInputChannel == inputChannel) {
5588 return windowState;
5589 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005590 }
5591
Jeff Brown349703e2010-06-22 01:27:15 -07005592 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005593 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005594
Chris Tatea32dcf72010-10-14 12:13:50 -07005595 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005596 final InputWindow inputWindow = windowList.add();
5597 inputWindow.inputChannel = mDragState.mServerChannel;
5598 inputWindow.name = "drag";
5599 inputWindow.layoutParamsFlags = 0;
5600 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5601 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5602 inputWindow.visible = true;
5603 inputWindow.canReceiveKeys = false;
5604 inputWindow.hasFocus = true;
5605 inputWindow.hasWallpaper = false;
5606 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005607 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005608 inputWindow.ownerPid = Process.myPid();
5609 inputWindow.ownerUid = Process.myUid();
5610
5611 // The drag window covers the entire display
5612 inputWindow.frameLeft = 0;
5613 inputWindow.frameTop = 0;
5614 inputWindow.frameRight = mDisplay.getWidth();
5615 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005616
Christopher Tatea53146c2010-09-07 11:57:52 -07005617 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5618 inputWindow.visibleFrameTop = inputWindow.frameTop;
5619 inputWindow.visibleFrameRight = inputWindow.frameRight;
5620 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5621
5622 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5623 inputWindow.touchableAreaTop = inputWindow.frameTop;
5624 inputWindow.touchableAreaRight = inputWindow.frameRight;
5625 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5626 }
5627
Jeff Brown349703e2010-06-22 01:27:15 -07005628 /* Updates the cached window information provided to the input dispatcher. */
5629 public void updateInputWindowsLw() {
5630 // Populate the input window list with information about all of the windows that
5631 // could potentially receive input.
5632 // As an optimization, we could try to prune the list of windows but this turns
5633 // out to be difficult because only the native code knows for sure which window
5634 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005635 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005636
5637 // If there's a drag in flight, provide a pseudowindow to catch drag input
5638 final boolean inDrag = (mDragState != null);
5639 if (inDrag) {
5640 if (DEBUG_DRAG) {
5641 Log.d(TAG, "Inserting drag window");
5642 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005643 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005644 }
5645
Jeff Brown7fbdc842010-06-17 20:52:56 -07005646 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005647 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005648 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005649 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005650 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005651 continue;
5652 }
5653
Jeff Brown349703e2010-06-22 01:27:15 -07005654 final int flags = child.mAttrs.flags;
5655 final int type = child.mAttrs.type;
5656
5657 final boolean hasFocus = (child == mInputFocus);
5658 final boolean isVisible = child.isVisibleLw();
5659 final boolean hasWallpaper = (child == mWallpaperTarget)
5660 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005661
5662 // If there's a drag in progress and 'child' is a potential drop target,
5663 // make sure it's been told about the drag
5664 if (inDrag && isVisible) {
5665 mDragState.sendDragStartedIfNeededLw(child);
5666 }
5667
Jeff Brown349703e2010-06-22 01:27:15 -07005668 // Add a window to our list of input windows.
5669 final InputWindow inputWindow = mTempInputWindows.add();
5670 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005671 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005672 inputWindow.layoutParamsFlags = flags;
5673 inputWindow.layoutParamsType = type;
5674 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5675 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005676 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005677 inputWindow.hasFocus = hasFocus;
5678 inputWindow.hasWallpaper = hasWallpaper;
5679 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005680 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005681 inputWindow.ownerPid = child.mSession.mPid;
5682 inputWindow.ownerUid = child.mSession.mUid;
5683
5684 final Rect frame = child.mFrame;
5685 inputWindow.frameLeft = frame.left;
5686 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005687 inputWindow.frameRight = frame.right;
5688 inputWindow.frameBottom = frame.bottom;
5689
5690 final Rect visibleFrame = child.mVisibleFrame;
5691 inputWindow.visibleFrameLeft = visibleFrame.left;
5692 inputWindow.visibleFrameTop = visibleFrame.top;
5693 inputWindow.visibleFrameRight = visibleFrame.right;
5694 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005695
5696 switch (child.mTouchableInsets) {
5697 default:
5698 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5699 inputWindow.touchableAreaLeft = frame.left;
5700 inputWindow.touchableAreaTop = frame.top;
5701 inputWindow.touchableAreaRight = frame.right;
5702 inputWindow.touchableAreaBottom = frame.bottom;
5703 break;
5704
5705 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5706 Rect inset = child.mGivenContentInsets;
5707 inputWindow.touchableAreaLeft = frame.left + inset.left;
5708 inputWindow.touchableAreaTop = frame.top + inset.top;
5709 inputWindow.touchableAreaRight = frame.right - inset.right;
5710 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5711 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005712 }
Jeff Brown349703e2010-06-22 01:27:15 -07005713
5714 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5715 Rect inset = child.mGivenVisibleInsets;
5716 inputWindow.touchableAreaLeft = frame.left + inset.left;
5717 inputWindow.touchableAreaTop = frame.top + inset.top;
5718 inputWindow.touchableAreaRight = frame.right - inset.right;
5719 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005720 break;
5721 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005722 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005723 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005724
Jeff Brown349703e2010-06-22 01:27:15 -07005725 // Send windows to native code.
5726 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005727
Jeff Brown349703e2010-06-22 01:27:15 -07005728 // Clear the list in preparation for the next round.
5729 // Also avoids keeping InputChannel objects referenced unnecessarily.
5730 mTempInputWindows.clear();
5731 }
5732
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005733 /* Notifies that the lid switch changed state. */
5734 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5735 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5736 }
5737
Jeff Brown349703e2010-06-22 01:27:15 -07005738 /* Provides an opportunity for the window manager policy to intercept early key
5739 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005740 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5741 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5742 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5743 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005744 }
5745
5746 /* Provides an opportunity for the window manager policy to process a key before
5747 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005748 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005749 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005750 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005751 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005752 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005753 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005754 }
5755
5756 /* Called when the current input focus changes.
5757 * Layer assignment is assumed to be complete by the time this is called.
5758 */
5759 public void setInputFocusLw(WindowState newWindow) {
5760 if (DEBUG_INPUT) {
5761 Slog.d(TAG, "Input focus has changed to " + newWindow);
5762 }
5763
5764 if (newWindow != mInputFocus) {
5765 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005766 // Displaying a window implicitly causes dispatching to be unpaused.
5767 // This is to protect against bugs if someone pauses dispatching but
5768 // forgets to resume.
5769 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005770 }
Jeff Brown349703e2010-06-22 01:27:15 -07005771
5772 mInputFocus = newWindow;
5773 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005774 }
5775 }
5776
Jeff Brown349703e2010-06-22 01:27:15 -07005777 public void setFocusedAppLw(AppWindowToken newApp) {
5778 // Focused app has changed.
5779 if (newApp == null) {
5780 mInputManager.setFocusedApplication(null);
5781 } else {
5782 mTempInputApplication.name = newApp.toString();
5783 mTempInputApplication.dispatchingTimeoutNanos =
5784 newApp.inputDispatchingTimeoutNanos;
5785 mTempInputApplication.token = newApp;
5786
5787 mInputManager.setFocusedApplication(mTempInputApplication);
5788 }
5789 }
5790
Jeff Brown349703e2010-06-22 01:27:15 -07005791 public void pauseDispatchingLw(WindowToken window) {
5792 if (! window.paused) {
5793 if (DEBUG_INPUT) {
5794 Slog.v(TAG, "Pausing WindowToken " + window);
5795 }
5796
5797 window.paused = true;
5798 updateInputWindowsLw();
5799 }
5800 }
5801
5802 public void resumeDispatchingLw(WindowToken window) {
5803 if (window.paused) {
5804 if (DEBUG_INPUT) {
5805 Slog.v(TAG, "Resuming WindowToken " + window);
5806 }
5807
5808 window.paused = false;
5809 updateInputWindowsLw();
5810 }
5811 }
5812
5813 public void freezeInputDispatchingLw() {
5814 if (! mInputDispatchFrozen) {
5815 if (DEBUG_INPUT) {
5816 Slog.v(TAG, "Freezing input dispatching");
5817 }
5818
5819 mInputDispatchFrozen = true;
5820 updateInputDispatchModeLw();
5821 }
5822 }
5823
5824 public void thawInputDispatchingLw() {
5825 if (mInputDispatchFrozen) {
5826 if (DEBUG_INPUT) {
5827 Slog.v(TAG, "Thawing input dispatching");
5828 }
5829
5830 mInputDispatchFrozen = false;
5831 updateInputDispatchModeLw();
5832 }
5833 }
5834
5835 public void setEventDispatchingLw(boolean enabled) {
5836 if (mInputDispatchEnabled != enabled) {
5837 if (DEBUG_INPUT) {
5838 Slog.v(TAG, "Setting event dispatching to " + enabled);
5839 }
5840
5841 mInputDispatchEnabled = enabled;
5842 updateInputDispatchModeLw();
5843 }
5844 }
5845
5846 private void updateInputDispatchModeLw() {
5847 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5848 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005849 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005851 public void pauseKeyDispatching(IBinder _token) {
5852 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5853 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005854 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005855 }
5856
5857 synchronized (mWindowMap) {
5858 WindowToken token = mTokenMap.get(_token);
5859 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005860 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005861 }
5862 }
5863 }
5864
5865 public void resumeKeyDispatching(IBinder _token) {
5866 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5867 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005868 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005869 }
5870
5871 synchronized (mWindowMap) {
5872 WindowToken token = mTokenMap.get(_token);
5873 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005874 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 }
5876 }
5877 }
5878
5879 public void setEventDispatching(boolean enabled) {
5880 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5881 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005882 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 }
5884
5885 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005886 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005887 }
5888 }
Romain Guy06882f82009-06-10 13:36:04 -07005889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005890 /**
5891 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005892 * Even when sync is false, this method may block while waiting for current
5893 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005894 *
5895 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005896 * {@link SystemClock#uptimeMillis()} as the timebase.)
5897 * @param sync If true, wait for the event to be completed before returning to the caller.
5898 * @return Returns true if event was dispatched, false if it was dropped for any reason
5899 */
5900 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5901 long downTime = ev.getDownTime();
5902 long eventTime = ev.getEventTime();
5903
5904 int action = ev.getAction();
5905 int code = ev.getKeyCode();
5906 int repeatCount = ev.getRepeatCount();
5907 int metaState = ev.getMetaState();
5908 int deviceId = ev.getDeviceId();
5909 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005910 int source = ev.getSource();
5911
5912 if (source == InputDevice.SOURCE_UNKNOWN) {
5913 source = InputDevice.SOURCE_KEYBOARD;
5914 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915
5916 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5917 if (downTime == 0) downTime = eventTime;
5918
5919 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005920 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005921
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005922 final int pid = Binder.getCallingPid();
5923 final int uid = Binder.getCallingUid();
5924 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005925
Jeff Brownbbda99d2010-07-28 15:48:59 -07005926 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5927 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5928 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5929 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005930
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005931 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005932 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005933 }
5934
5935 /**
5936 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005937 * Even when sync is false, this method may block while waiting for current
5938 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005939 *
5940 * @param ev A motion event describing the pointer (touch) action. (As noted in
5941 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005942 * {@link SystemClock#uptimeMillis()} as the timebase.)
5943 * @param sync If true, wait for the event to be completed before returning to the caller.
5944 * @return Returns true if event was dispatched, false if it was dropped for any reason
5945 */
5946 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005947 final int pid = Binder.getCallingPid();
5948 final int uid = Binder.getCallingUid();
5949 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005950
Jeff Brownc5ed5912010-07-14 18:48:53 -07005951 MotionEvent newEvent = MotionEvent.obtain(ev);
5952 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5953 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5954 }
5955
Jeff Brownbbda99d2010-07-28 15:48:59 -07005956 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5957 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5958 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5959 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005960
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005961 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005962 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005963 }
Romain Guy06882f82009-06-10 13:36:04 -07005964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005965 /**
5966 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005967 * Even when sync is false, this method may block while waiting for current
5968 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005969 *
5970 * @param ev A motion event describing the trackball action. (As noted in
5971 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005972 * {@link SystemClock#uptimeMillis()} as the timebase.)
5973 * @param sync If true, wait for the event to be completed before returning to the caller.
5974 * @return Returns true if event was dispatched, false if it was dropped for any reason
5975 */
5976 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005977 final int pid = Binder.getCallingPid();
5978 final int uid = Binder.getCallingUid();
5979 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005980
Jeff Brownc5ed5912010-07-14 18:48:53 -07005981 MotionEvent newEvent = MotionEvent.obtain(ev);
5982 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5983 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5984 }
5985
Jeff Brownbbda99d2010-07-28 15:48:59 -07005986 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5987 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5988 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5989 INJECTION_TIMEOUT_MILLIS);
5990
5991 Binder.restoreCallingIdentity(ident);
5992 return reportInjectionResult(result);
5993 }
5994
5995 /**
5996 * Inject an input event into the UI without waiting for dispatch to commence.
5997 * This variant is useful for fire-and-forget input event injection. It does not
5998 * block any longer than it takes to enqueue the input event.
5999 *
6000 * @param ev An input event. (Be sure to set the input source correctly.)
6001 * @return Returns true if event was dispatched, false if it was dropped for any reason
6002 */
6003 public boolean injectInputEventNoWait(InputEvent ev) {
6004 final int pid = Binder.getCallingPid();
6005 final int uid = Binder.getCallingUid();
6006 final long ident = Binder.clearCallingIdentity();
6007
6008 final int result = mInputManager.injectInputEvent(ev, pid, uid,
6009 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
6010 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07006011
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006012 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006013 return reportInjectionResult(result);
6014 }
6015
6016 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006017 switch (result) {
6018 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6019 Slog.w(TAG, "Input event injection permission denied.");
6020 throw new SecurityException(
6021 "Injecting to another application requires INJECT_EVENTS permission");
6022 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006023 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006024 return true;
6025 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6026 Slog.w(TAG, "Input event injection timed out.");
6027 return false;
6028 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6029 default:
6030 Slog.w(TAG, "Input event injection failed.");
6031 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006033 }
Romain Guy06882f82009-06-10 13:36:04 -07006034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006035 private WindowState getFocusedWindow() {
6036 synchronized (mWindowMap) {
6037 return getFocusedWindowLocked();
6038 }
6039 }
6040
6041 private WindowState getFocusedWindowLocked() {
6042 return mCurrentFocus;
6043 }
Romain Guy06882f82009-06-10 13:36:04 -07006044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006045 public boolean detectSafeMode() {
6046 mSafeMode = mPolicy.detectSafeMode();
6047 return mSafeMode;
6048 }
Romain Guy06882f82009-06-10 13:36:04 -07006049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006050 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006051 synchronized(mWindowMap) {
6052 if (mDisplay != null) {
6053 throw new IllegalStateException("Display already initialized");
6054 }
6055 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6056 mDisplay = wm.getDefaultDisplay();
6057 mInitialDisplayWidth = mDisplay.getWidth();
6058 mInitialDisplayHeight = mDisplay.getHeight();
6059 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6060 }
6061
6062 try {
6063 mActivityManager.updateConfiguration(null);
6064 } catch (RemoteException e) {
6065 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006066
6067 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006068 }
6069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006070 // -------------------------------------------------------------
6071 // Client Session State
6072 // -------------------------------------------------------------
6073
6074 private final class Session extends IWindowSession.Stub
6075 implements IBinder.DeathRecipient {
6076 final IInputMethodClient mClient;
6077 final IInputContext mInputContext;
6078 final int mUid;
6079 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006080 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006081 SurfaceSession mSurfaceSession;
6082 int mNumWindow = 0;
6083 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006085 public Session(IInputMethodClient client, IInputContext inputContext) {
6086 mClient = client;
6087 mInputContext = inputContext;
6088 mUid = Binder.getCallingUid();
6089 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006090 StringBuilder sb = new StringBuilder();
6091 sb.append("Session{");
6092 sb.append(Integer.toHexString(System.identityHashCode(this)));
6093 sb.append(" uid ");
6094 sb.append(mUid);
6095 sb.append("}");
6096 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006098 synchronized (mWindowMap) {
6099 if (mInputMethodManager == null && mHaveInputMethods) {
6100 IBinder b = ServiceManager.getService(
6101 Context.INPUT_METHOD_SERVICE);
6102 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6103 }
6104 }
6105 long ident = Binder.clearCallingIdentity();
6106 try {
6107 // Note: it is safe to call in to the input method manager
6108 // here because we are not holding our lock.
6109 if (mInputMethodManager != null) {
6110 mInputMethodManager.addClient(client, inputContext,
6111 mUid, mPid);
6112 } else {
6113 client.setUsingInputMethod(false);
6114 }
6115 client.asBinder().linkToDeath(this, 0);
6116 } catch (RemoteException e) {
6117 // The caller has died, so we can just forget about this.
6118 try {
6119 if (mInputMethodManager != null) {
6120 mInputMethodManager.removeClient(client);
6121 }
6122 } catch (RemoteException ee) {
6123 }
6124 } finally {
6125 Binder.restoreCallingIdentity(ident);
6126 }
6127 }
Romain Guy06882f82009-06-10 13:36:04 -07006128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006129 @Override
6130 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6131 throws RemoteException {
6132 try {
6133 return super.onTransact(code, data, reply, flags);
6134 } catch (RuntimeException e) {
6135 // Log all 'real' exceptions thrown to the caller
6136 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006137 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 }
6139 throw e;
6140 }
6141 }
6142
6143 public void binderDied() {
6144 // Note: it is safe to call in to the input method manager
6145 // here because we are not holding our lock.
6146 try {
6147 if (mInputMethodManager != null) {
6148 mInputMethodManager.removeClient(mClient);
6149 }
6150 } catch (RemoteException e) {
6151 }
6152 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006153 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006154 mClientDead = true;
6155 killSessionLocked();
6156 }
6157 }
6158
6159 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07006160 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6161 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6162 outInputChannel);
6163 }
6164
6165 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07006167 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 }
Romain Guy06882f82009-06-10 13:36:04 -07006169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006170 public void remove(IWindow window) {
6171 removeWindow(this, window);
6172 }
Romain Guy06882f82009-06-10 13:36:04 -07006173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6175 int requestedWidth, int requestedHeight, int viewFlags,
6176 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006177 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006178 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6179 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006180 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006181 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006182 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6183 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006184 }
Romain Guy06882f82009-06-10 13:36:04 -07006185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006186 public void setTransparentRegion(IWindow window, Region region) {
6187 setTransparentRegionWindow(this, window, region);
6188 }
Romain Guy06882f82009-06-10 13:36:04 -07006189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006190 public void setInsets(IWindow window, int touchableInsets,
6191 Rect contentInsets, Rect visibleInsets) {
6192 setInsetsWindow(this, window, touchableInsets, contentInsets,
6193 visibleInsets);
6194 }
Romain Guy06882f82009-06-10 13:36:04 -07006195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6197 getWindowDisplayFrame(this, window, outDisplayFrame);
6198 }
Romain Guy06882f82009-06-10 13:36:04 -07006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006201 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006202 TAG, "IWindow finishDrawing called for " + window);
6203 finishDrawingWindow(this, window);
6204 }
6205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 public void setInTouchMode(boolean mode) {
6207 synchronized(mWindowMap) {
6208 mInTouchMode = mode;
6209 }
6210 }
6211
6212 public boolean getInTouchMode() {
6213 synchronized(mWindowMap) {
6214 return mInTouchMode;
6215 }
6216 }
6217
6218 public boolean performHapticFeedback(IWindow window, int effectId,
6219 boolean always) {
6220 synchronized(mWindowMap) {
6221 long ident = Binder.clearCallingIdentity();
6222 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006223 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006224 windowForClientLocked(this, window, true),
6225 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006226 } finally {
6227 Binder.restoreCallingIdentity(ident);
6228 }
6229 }
6230 }
Romain Guy06882f82009-06-10 13:36:04 -07006231
Christopher Tatea53146c2010-09-07 11:57:52 -07006232 /* Drag/drop */
6233 public IBinder prepareDrag(IWindow window, boolean localOnly,
6234 int width, int height, Surface outSurface) {
6235 return prepareDragSurface(window, mSurfaceSession, localOnly,
6236 width, height, outSurface);
6237 }
6238
6239 public boolean performDrag(IWindow window, IBinder dragToken,
6240 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6241 ClipData data) {
6242 if (DEBUG_DRAG) {
6243 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6244 }
6245
6246 synchronized (mWindowMap) {
6247 if (mDragState == null) {
6248 Slog.w(TAG, "No drag prepared");
6249 throw new IllegalStateException("performDrag() without prepareDrag()");
6250 }
6251
6252 if (dragToken != mDragState.mToken) {
6253 Slog.w(TAG, "Performing mismatched drag");
6254 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6255 }
6256
6257 WindowState callingWin = windowForClientLocked(null, window, false);
6258 if (callingWin == null) {
6259 Slog.w(TAG, "Bad requesting window " + window);
6260 return false; // !!! TODO: throw here?
6261 }
6262
6263 // !!! TODO: if input is not still focused on the initiating window, fail
6264 // the drag initiation (e.g. an alarm window popped up just as the application
6265 // called performDrag()
6266
6267 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6268
Christopher Tate2c095f32010-10-04 14:13:40 -07006269 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6270 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006271
Chris Tateb478f462010-10-15 16:02:26 -07006272 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6273 // the actual drag event dispatch stuff in the dragstate
6274
Christopher Tatea53146c2010-09-07 11:57:52 -07006275 mDragState.register();
6276 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006277 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6278 mDragState.mServerChannel)) {
6279 Slog.e(TAG, "Unable to transfer touch focus");
6280 mDragState.unregister();
6281 mDragState = null;
6282 mInputMonitor.updateInputWindowsLw();
6283 return false;
6284 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006285
6286 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006287 mDragState.mCurrentX = touchX;
6288 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006289 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006290
6291 // remember the thumb offsets for later
6292 mDragState.mThumbOffsetX = thumbCenterX;
6293 mDragState.mThumbOffsetY = thumbCenterY;
6294
6295 // Make the surface visible at the proper location
6296 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006297 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006298 try {
6299 surface.setPosition((int)(touchX - thumbCenterX),
6300 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006301 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006302 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006303 surface.show();
6304 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006305 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006306 }
6307 }
6308
6309 return true; // success!
6310 }
6311
Chris Tated4533f12010-10-19 15:15:08 -07006312 public void reportDropResult(IWindow window, boolean consumed) {
6313 IBinder token = window.asBinder();
6314 if (DEBUG_DRAG) {
6315 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6316 }
6317
6318 synchronized (mWindowMap) {
6319 if (mDragState.mToken != token) {
6320 Slog.w(TAG, "Invalid drop-result claim by " + window);
6321 throw new IllegalStateException("reportDropResult() by non-recipient");
6322 }
6323
6324 // The right window has responded, even if it's no longer around,
6325 // so be sure to halt the timeout even if the later WindowState
6326 // lookup fails.
6327 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6328
6329 WindowState callingWin = windowForClientLocked(null, window, false);
6330 if (callingWin == null) {
6331 Slog.w(TAG, "Bad result-reporting window " + window);
6332 return; // !!! TODO: throw here?
6333 }
6334
6335 mDragState.mDragResult = consumed;
6336 mDragState.endDragLw();
6337 }
6338 }
6339
Christopher Tatea53146c2010-09-07 11:57:52 -07006340 public void dragRecipientEntered(IWindow window) {
6341 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006342 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006343 }
6344 }
6345
6346 public void dragRecipientExited(IWindow window) {
6347 if (DEBUG_DRAG) {
Chris Tated4533f12010-10-19 15:15:08 -07006348 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006349 }
6350 }
6351
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006352 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006353 synchronized(mWindowMap) {
6354 long ident = Binder.clearCallingIdentity();
6355 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006356 setWindowWallpaperPositionLocked(
6357 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006358 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006359 } finally {
6360 Binder.restoreCallingIdentity(ident);
6361 }
6362 }
6363 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006364
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006365 public void wallpaperOffsetsComplete(IBinder window) {
6366 WindowManagerService.this.wallpaperOffsetsComplete(window);
6367 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006368
Dianne Hackborn75804932009-10-20 20:15:20 -07006369 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6370 int z, Bundle extras, boolean sync) {
6371 synchronized(mWindowMap) {
6372 long ident = Binder.clearCallingIdentity();
6373 try {
6374 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006375 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006376 action, x, y, z, extras, sync);
6377 } finally {
6378 Binder.restoreCallingIdentity(ident);
6379 }
6380 }
6381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006382
Dianne Hackborn75804932009-10-20 20:15:20 -07006383 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6384 WindowManagerService.this.wallpaperCommandComplete(window, result);
6385 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 void windowAddedLocked() {
6388 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006389 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006390 TAG, "First window added to " + this + ", creating SurfaceSession");
6391 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006392 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006393 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 mSessions.add(this);
6395 }
6396 mNumWindow++;
6397 }
6398
6399 void windowRemovedLocked() {
6400 mNumWindow--;
6401 killSessionLocked();
6402 }
Romain Guy06882f82009-06-10 13:36:04 -07006403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006404 void killSessionLocked() {
6405 if (mNumWindow <= 0 && mClientDead) {
6406 mSessions.remove(this);
6407 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006408 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 TAG, "Last window removed from " + this
6410 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006411 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006412 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006413 try {
6414 mSurfaceSession.kill();
6415 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006416 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006417 + mSurfaceSession + " in session " + this
6418 + ": " + e.toString());
6419 }
6420 mSurfaceSession = null;
6421 }
6422 }
6423 }
Romain Guy06882f82009-06-10 13:36:04 -07006424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006425 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006426 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6427 pw.print(" mClientDead="); pw.print(mClientDead);
6428 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 }
6430
6431 @Override
6432 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006433 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006434 }
6435 }
6436
6437 // -------------------------------------------------------------
6438 // Client Window State
6439 // -------------------------------------------------------------
6440
6441 private final class WindowState implements WindowManagerPolicy.WindowState {
6442 final Session mSession;
6443 final IWindow mClient;
6444 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006445 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006446 AppWindowToken mAppToken;
6447 AppWindowToken mTargetAppToken;
6448 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6449 final DeathRecipient mDeathRecipient;
6450 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006451 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006452 final int mBaseLayer;
6453 final int mSubLayer;
6454 final boolean mLayoutAttached;
6455 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006456 final boolean mIsWallpaper;
6457 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 int mViewVisibility;
6459 boolean mPolicyVisibility = true;
6460 boolean mPolicyVisibilityAfterAnim = true;
6461 boolean mAppFreezing;
6462 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006463 boolean mReportDestroySurface;
6464 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 boolean mAttachedHidden; // is our parent window hidden?
6466 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006467 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006468 int mRequestedWidth;
6469 int mRequestedHeight;
6470 int mLastRequestedWidth;
6471 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 int mLayer;
6473 int mAnimLayer;
6474 int mLastLayer;
6475 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006476 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006477 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006478
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006479 int mLayoutSeq = -1;
6480
6481 Configuration mConfiguration = null;
6482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 // Actual frame shown on-screen (may be modified by animation)
6484 final Rect mShownFrame = new Rect();
6485 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006488 * Set when we have changed the size of the surface, to know that
6489 * we must tell them application to resize (and thus redraw itself).
6490 */
6491 boolean mSurfaceResized;
6492
6493 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 * Insets that determine the actually visible area
6495 */
6496 final Rect mVisibleInsets = new Rect();
6497 final Rect mLastVisibleInsets = new Rect();
6498 boolean mVisibleInsetsChanged;
6499
6500 /**
6501 * Insets that are covered by system windows
6502 */
6503 final Rect mContentInsets = new Rect();
6504 final Rect mLastContentInsets = new Rect();
6505 boolean mContentInsetsChanged;
6506
6507 /**
6508 * Set to true if we are waiting for this window to receive its
6509 * given internal insets before laying out other windows based on it.
6510 */
6511 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006513 /**
6514 * These are the content insets that were given during layout for
6515 * this window, to be applied to windows behind it.
6516 */
6517 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 /**
6520 * These are the visible insets that were given during layout for
6521 * this window, to be applied to windows behind it.
6522 */
6523 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 /**
6526 * Flag indicating whether the touchable region should be adjusted by
6527 * the visible insets; if false the area outside the visible insets is
6528 * NOT touchable, so we must use those to adjust the frame during hit
6529 * tests.
6530 */
6531 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006533 // Current transformation being applied.
6534 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6535 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6536 float mHScale=1, mVScale=1;
6537 float mLastHScale=1, mLastVScale=1;
6538 final Matrix mTmpMatrix = new Matrix();
6539
6540 // "Real" frame that the application sees.
6541 final Rect mFrame = new Rect();
6542 final Rect mLastFrame = new Rect();
6543
6544 final Rect mContainingFrame = new Rect();
6545 final Rect mDisplayFrame = new Rect();
6546 final Rect mContentFrame = new Rect();
6547 final Rect mVisibleFrame = new Rect();
6548
6549 float mShownAlpha = 1;
6550 float mAlpha = 1;
6551 float mLastAlpha = 1;
6552
6553 // Set to true if, when the window gets displayed, it should perform
6554 // an enter animation.
6555 boolean mEnterAnimationPending;
6556
6557 // Currently running animation.
6558 boolean mAnimating;
6559 boolean mLocalAnimating;
6560 Animation mAnimation;
6561 boolean mAnimationIsEntrance;
6562 boolean mHasTransformation;
6563 boolean mHasLocalTransformation;
6564 final Transformation mTransformation = new Transformation();
6565
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006566 // If a window showing a wallpaper: the requested offset for the
6567 // wallpaper; if a wallpaper window: the currently applied offset.
6568 float mWallpaperX = -1;
6569 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006570
6571 // If a window showing a wallpaper: what fraction of the offset
6572 // range corresponds to a full virtual screen.
6573 float mWallpaperXStep = -1;
6574 float mWallpaperYStep = -1;
6575
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006576 // Wallpaper windows: pixels offset based on above variables.
6577 int mXOffset;
6578 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580 // This is set after IWindowSession.relayout() has been called at
6581 // least once for the window. It allows us to detect the situation
6582 // where we don't yet have a surface, but should have one soon, so
6583 // we can give the window focus before waiting for the relayout.
6584 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006586 // This is set after the Surface has been created but before the
6587 // window has been drawn. During this time the surface is hidden.
6588 boolean mDrawPending;
6589
6590 // This is set after the window has finished drawing for the first
6591 // time but before its surface is shown. The surface will be
6592 // displayed when the next layout is run.
6593 boolean mCommitDrawPending;
6594
6595 // This is set during the time after the window's drawing has been
6596 // committed, and before its surface is actually shown. It is used
6597 // to delay showing the surface until all windows in a token are ready
6598 // to be shown.
6599 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006601 // Set when the window has been shown in the screen the first time.
6602 boolean mHasDrawn;
6603
6604 // Currently running an exit animation?
6605 boolean mExiting;
6606
6607 // Currently on the mDestroySurface list?
6608 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006610 // Completely remove from window manager after exit animation?
6611 boolean mRemoveOnExit;
6612
6613 // Set when the orientation is changing and this window has not yet
6614 // been updated for the new orientation.
6615 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006617 // Is this window now (or just being) removed?
6618 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006619
Dianne Hackborn16064f92010-03-25 00:47:24 -07006620 // For debugging, this is the last information given to the surface flinger.
6621 boolean mSurfaceShown;
6622 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6623 int mSurfaceLayer;
6624 float mSurfaceAlpha;
6625
Jeff Brown46b9ac02010-04-22 18:58:52 -07006626 // Input channel
6627 InputChannel mInputChannel;
6628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 WindowState(Session s, IWindow c, WindowToken token,
6630 WindowState attachedWindow, WindowManager.LayoutParams a,
6631 int viewVisibility) {
6632 mSession = s;
6633 mClient = c;
6634 mToken = token;
6635 mAttrs.copyFrom(a);
6636 mViewVisibility = viewVisibility;
6637 DeathRecipient deathRecipient = new DeathRecipient();
6638 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006639 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 TAG, "Window " + this + " client=" + c.asBinder()
6641 + " token=" + token + " (" + mAttrs.token + ")");
6642 try {
6643 c.asBinder().linkToDeath(deathRecipient, 0);
6644 } catch (RemoteException e) {
6645 mDeathRecipient = null;
6646 mAttachedWindow = null;
6647 mLayoutAttached = false;
6648 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006649 mIsWallpaper = false;
6650 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006651 mBaseLayer = 0;
6652 mSubLayer = 0;
6653 return;
6654 }
6655 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006657 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6658 mAttrs.type <= LAST_SUB_WINDOW)) {
6659 // The multiplier here is to reserve space for multiple
6660 // windows in the same type layer.
6661 mBaseLayer = mPolicy.windowTypeToLayerLw(
6662 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6663 + TYPE_LAYER_OFFSET;
6664 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6665 mAttachedWindow = attachedWindow;
6666 mAttachedWindow.mChildWindows.add(this);
6667 mLayoutAttached = mAttrs.type !=
6668 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6669 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6670 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006671 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6672 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006673 } else {
6674 // The multiplier here is to reserve space for multiple
6675 // windows in the same type layer.
6676 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6677 * TYPE_LAYER_MULTIPLIER
6678 + TYPE_LAYER_OFFSET;
6679 mSubLayer = 0;
6680 mAttachedWindow = null;
6681 mLayoutAttached = false;
6682 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6683 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006684 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6685 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006686 }
6687
6688 WindowState appWin = this;
6689 while (appWin.mAttachedWindow != null) {
6690 appWin = mAttachedWindow;
6691 }
6692 WindowToken appToken = appWin.mToken;
6693 while (appToken.appWindowToken == null) {
6694 WindowToken parent = mTokenMap.get(appToken.token);
6695 if (parent == null || appToken == parent) {
6696 break;
6697 }
6698 appToken = parent;
6699 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006700 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 mAppToken = appToken.appWindowToken;
6702
6703 mSurface = null;
6704 mRequestedWidth = 0;
6705 mRequestedHeight = 0;
6706 mLastRequestedWidth = 0;
6707 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006708 mXOffset = 0;
6709 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 mLayer = 0;
6711 mAnimLayer = 0;
6712 mLastLayer = 0;
6713 }
6714
6715 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006716 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006717 TAG, "Attaching " + this + " token=" + mToken
6718 + ", list=" + mToken.windows);
6719 mSession.windowAddedLocked();
6720 }
6721
6722 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6723 mHaveFrame = true;
6724
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006725 final Rect container = mContainingFrame;
6726 container.set(pf);
6727
6728 final Rect display = mDisplayFrame;
6729 display.set(df);
6730
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006731 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006732 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006733 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6734 display.intersect(mCompatibleScreenFrame);
6735 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006736 }
6737
6738 final int pw = container.right - container.left;
6739 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740
6741 int w,h;
6742 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6743 w = mAttrs.width < 0 ? pw : mAttrs.width;
6744 h = mAttrs.height< 0 ? ph : mAttrs.height;
6745 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006746 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6747 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006748 }
Romain Guy06882f82009-06-10 13:36:04 -07006749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006750 final Rect content = mContentFrame;
6751 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 final Rect visible = mVisibleFrame;
6754 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006756 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006757 final int fw = frame.width();
6758 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6761 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6762
6763 Gravity.apply(mAttrs.gravity, w, h, container,
6764 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6765 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6766
6767 //System.out.println("Out: " + mFrame);
6768
6769 // Now make sure the window fits in the overall display.
6770 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 // Make sure the content and visible frames are inside of the
6773 // final window frame.
6774 if (content.left < frame.left) content.left = frame.left;
6775 if (content.top < frame.top) content.top = frame.top;
6776 if (content.right > frame.right) content.right = frame.right;
6777 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6778 if (visible.left < frame.left) visible.left = frame.left;
6779 if (visible.top < frame.top) visible.top = frame.top;
6780 if (visible.right > frame.right) visible.right = frame.right;
6781 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006783 final Rect contentInsets = mContentInsets;
6784 contentInsets.left = content.left-frame.left;
6785 contentInsets.top = content.top-frame.top;
6786 contentInsets.right = frame.right-content.right;
6787 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 final Rect visibleInsets = mVisibleInsets;
6790 visibleInsets.left = visible.left-frame.left;
6791 visibleInsets.top = visible.top-frame.top;
6792 visibleInsets.right = frame.right-visible.right;
6793 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006794
Dianne Hackborn284ac932009-08-28 10:34:25 -07006795 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6796 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006797 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006798 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 if (localLOGV) {
6801 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6802 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006803 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006804 + mRequestedWidth + ", mRequestedheight="
6805 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6806 + "): frame=" + mFrame.toShortString()
6807 + " ci=" + contentInsets.toShortString()
6808 + " vi=" + visibleInsets.toShortString());
6809 //}
6810 }
6811 }
Romain Guy06882f82009-06-10 13:36:04 -07006812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006813 public Rect getFrameLw() {
6814 return mFrame;
6815 }
6816
6817 public Rect getShownFrameLw() {
6818 return mShownFrame;
6819 }
6820
6821 public Rect getDisplayFrameLw() {
6822 return mDisplayFrame;
6823 }
6824
6825 public Rect getContentFrameLw() {
6826 return mContentFrame;
6827 }
6828
6829 public Rect getVisibleFrameLw() {
6830 return mVisibleFrame;
6831 }
6832
6833 public boolean getGivenInsetsPendingLw() {
6834 return mGivenInsetsPending;
6835 }
6836
6837 public Rect getGivenContentInsetsLw() {
6838 return mGivenContentInsets;
6839 }
Romain Guy06882f82009-06-10 13:36:04 -07006840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 public Rect getGivenVisibleInsetsLw() {
6842 return mGivenVisibleInsets;
6843 }
Romain Guy06882f82009-06-10 13:36:04 -07006844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845 public WindowManager.LayoutParams getAttrs() {
6846 return mAttrs;
6847 }
6848
6849 public int getSurfaceLayer() {
6850 return mLayer;
6851 }
Romain Guy06882f82009-06-10 13:36:04 -07006852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 public IApplicationToken getAppToken() {
6854 return mAppToken != null ? mAppToken.appToken : null;
6855 }
Jeff Brown349703e2010-06-22 01:27:15 -07006856
6857 public long getInputDispatchingTimeoutNanos() {
6858 return mAppToken != null
6859 ? mAppToken.inputDispatchingTimeoutNanos
6860 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006862
6863 public boolean hasAppShownWindows() {
6864 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6865 }
6866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006867 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006868 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 TAG, "Setting animation in " + this + ": " + anim);
6870 mAnimating = false;
6871 mLocalAnimating = false;
6872 mAnimation = anim;
6873 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6874 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6875 }
6876
6877 public void clearAnimation() {
6878 if (mAnimation != null) {
6879 mAnimating = true;
6880 mLocalAnimating = false;
6881 mAnimation = null;
6882 }
6883 }
Romain Guy06882f82009-06-10 13:36:04 -07006884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006885 Surface createSurfaceLocked() {
6886 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006887 mReportDestroySurface = false;
6888 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 mDrawPending = true;
6890 mCommitDrawPending = false;
6891 mReadyToShow = false;
6892 if (mAppToken != null) {
6893 mAppToken.allDrawn = false;
6894 }
6895
6896 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006897 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006898 flags |= Surface.PUSH_BUFFERS;
6899 }
6900
6901 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6902 flags |= Surface.SECURE;
6903 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006904 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 TAG, "Creating surface in session "
6906 + mSession.mSurfaceSession + " window " + this
6907 + " w=" + mFrame.width()
6908 + " h=" + mFrame.height() + " format="
6909 + mAttrs.format + " flags=" + flags);
6910
6911 int w = mFrame.width();
6912 int h = mFrame.height();
6913 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6914 // for a scaled surface, we always want the requested
6915 // size.
6916 w = mRequestedWidth;
6917 h = mRequestedHeight;
6918 }
6919
Romain Guy9825ec62009-10-01 00:58:09 -07006920 // Something is wrong and SurfaceFlinger will not like this,
6921 // try to revert to sane values
6922 if (w <= 0) w = 1;
6923 if (h <= 0) h = 1;
6924
Dianne Hackborn16064f92010-03-25 00:47:24 -07006925 mSurfaceShown = false;
6926 mSurfaceLayer = 0;
6927 mSurfaceAlpha = 1;
6928 mSurfaceX = 0;
6929 mSurfaceY = 0;
6930 mSurfaceW = w;
6931 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006932 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006933 final boolean isHwAccelerated = (mAttrs.flags &
6934 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6935 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6936 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6937 flags |= Surface.OPAQUE;
6938 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006940 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006941 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006942 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006943 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006944 + mSurface + " IN SESSION "
6945 + mSession.mSurfaceSession
6946 + ": pid=" + mSession.mPid + " format="
6947 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006948 + Integer.toHexString(flags)
6949 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006951 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 reclaimSomeSurfaceMemoryLocked(this, "create");
6953 return null;
6954 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006955 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006956 return null;
6957 }
Romain Guy06882f82009-06-10 13:36:04 -07006958
Joe Onorato8a9b2202010-02-26 18:56:32 -08006959 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006960 TAG, "Got surface: " + mSurface
6961 + ", set left=" + mFrame.left + " top=" + mFrame.top
6962 + ", animLayer=" + mAnimLayer);
6963 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006964 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006965 if (SHOW_TRANSACTIONS) logSurface(this,
6966 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6967 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6968 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006969 }
6970 Surface.openTransaction();
6971 try {
6972 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006973 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006974 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006975 mSurface.setPosition(mSurfaceX, mSurfaceY);
6976 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006978 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006979 mSurface.hide();
6980 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006981 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006982 mSurface.setFlags(Surface.SURFACE_DITHER,
6983 Surface.SURFACE_DITHER);
6984 }
6985 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006986 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006987 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6988 }
6989 mLastHidden = true;
6990 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006991 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006992 Surface.closeTransaction();
6993 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006994 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 TAG, "Created surface " + this);
6996 }
6997 return mSurface;
6998 }
Romain Guy06882f82009-06-10 13:36:04 -07006999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007000 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007001 if (mAppToken != null && this == mAppToken.startingWindow) {
7002 mAppToken.startingDisplayed = false;
7003 }
Romain Guy06882f82009-06-10 13:36:04 -07007004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007005 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007006 mDrawPending = false;
7007 mCommitDrawPending = false;
7008 mReadyToShow = false;
7009
7010 int i = mChildWindows.size();
7011 while (i > 0) {
7012 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007013 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007014 c.mAttachedHidden = true;
7015 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007016
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007017 if (mReportDestroySurface) {
7018 mReportDestroySurface = false;
7019 mSurfacePendingDestroy = true;
7020 try {
7021 mClient.dispatchGetNewSurface();
7022 // We'll really destroy on the next time around.
7023 return;
7024 } catch (RemoteException e) {
7025 }
7026 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007028 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007029 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007030 RuntimeException e = null;
7031 if (!HIDE_STACK_CRAWLS) {
7032 e = new RuntimeException();
7033 e.fillInStackTrace();
7034 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007035 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007036 + mSurface + ", session " + mSession, e);
7037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007039 RuntimeException e = null;
7040 if (!HIDE_STACK_CRAWLS) {
7041 e = new RuntimeException();
7042 e.fillInStackTrace();
7043 }
7044 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007046 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007047 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007048 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007049 + " surface " + mSurface + " session " + mSession
7050 + ": " + e.toString());
7051 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007052
Dianne Hackborn16064f92010-03-25 00:47:24 -07007053 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007054 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007055 }
7056 }
7057
7058 boolean finishDrawingLocked() {
7059 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007060 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 TAG, "finishDrawingLocked: " + mSurface);
7062 mCommitDrawPending = true;
7063 mDrawPending = false;
7064 return true;
7065 }
7066 return false;
7067 }
7068
7069 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007070 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007071 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007073 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074 }
7075 mCommitDrawPending = false;
7076 mReadyToShow = true;
7077 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7078 final AppWindowToken atoken = mAppToken;
7079 if (atoken == null || atoken.allDrawn || starting) {
7080 performShowLocked();
7081 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007082 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 }
7084
7085 // This must be called while inside a transaction.
7086 boolean performShowLocked() {
7087 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007088 RuntimeException e = null;
7089 if (!HIDE_STACK_CRAWLS) {
7090 e = new RuntimeException();
7091 e.fillInStackTrace();
7092 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007093 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007094 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7095 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7096 }
7097 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007098 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7099 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007100 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007101 + " during animation: policyVis=" + mPolicyVisibility
7102 + " attHidden=" + mAttachedHidden
7103 + " tok.hiddenRequested="
7104 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007105 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007106 + (mAppToken != null ? mAppToken.hidden : false)
7107 + " animating=" + mAnimating
7108 + " tok animating="
7109 + (mAppToken != null ? mAppToken.animating : false));
7110 if (!showSurfaceRobustlyLocked(this)) {
7111 return false;
7112 }
7113 mLastAlpha = -1;
7114 mHasDrawn = true;
7115 mLastHidden = false;
7116 mReadyToShow = false;
7117 enableScreenIfNeededLocked();
7118
7119 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 int i = mChildWindows.size();
7122 while (i > 0) {
7123 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007124 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007125 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007126 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007127 if (c.mSurface != null) {
7128 c.performShowLocked();
7129 // It hadn't been shown, which means layout not
7130 // performed on it, so now we want to make sure to
7131 // do a layout. If called from within the transaction
7132 // loop, this will cause it to restart with a new
7133 // layout.
7134 mLayoutNeeded = true;
7135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 }
7137 }
Romain Guy06882f82009-06-10 13:36:04 -07007138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007139 if (mAttrs.type != TYPE_APPLICATION_STARTING
7140 && mAppToken != null) {
7141 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007142
Dianne Hackborn248b1882009-09-16 16:46:44 -07007143 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007144 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007145 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007146 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007147 // If this initial window is animating, stop it -- we
7148 // will do an animation to reveal it from behind the
7149 // starting window, so there is no need for it to also
7150 // be doing its own stuff.
7151 if (mAnimation != null) {
7152 mAnimation = null;
7153 // Make sure we clean up the animation.
7154 mAnimating = true;
7155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 mFinishedStarting.add(mAppToken);
7157 mH.sendEmptyMessage(H.FINISHED_STARTING);
7158 }
7159 mAppToken.updateReportedVisibilityLocked();
7160 }
7161 }
7162 return true;
7163 }
Romain Guy06882f82009-06-10 13:36:04 -07007164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 // This must be called while inside a transaction. Returns true if
7166 // there is more animation to run.
7167 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007168 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007169 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007171 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7172 mHasTransformation = true;
7173 mHasLocalTransformation = true;
7174 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007175 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007176 TAG, "Starting animation in " + this +
7177 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7178 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7179 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7180 mAnimation.setStartTime(currentTime);
7181 mLocalAnimating = true;
7182 mAnimating = true;
7183 }
7184 mTransformation.clear();
7185 final boolean more = mAnimation.getTransformation(
7186 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007187 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007188 TAG, "Stepped animation in " + this +
7189 ": more=" + more + ", xform=" + mTransformation);
7190 if (more) {
7191 // we're not done!
7192 return true;
7193 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007194 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007195 TAG, "Finished animation in " + this +
7196 " @ " + currentTime);
7197 mAnimation = null;
7198 //WindowManagerService.this.dump();
7199 }
7200 mHasLocalTransformation = false;
7201 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007202 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 // When our app token is animating, we kind-of pretend like
7204 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7205 // part of this check means that we will only do this if
7206 // our window is not currently exiting, or it is not
7207 // locally animating itself. The idea being that one that
7208 // is exiting and doing a local animation should be removed
7209 // once that animation is done.
7210 mAnimating = true;
7211 mHasTransformation = true;
7212 mTransformation.clear();
7213 return false;
7214 } else if (mHasTransformation) {
7215 // Little trick to get through the path below to act like
7216 // we have finished an animation.
7217 mAnimating = true;
7218 } else if (isAnimating()) {
7219 mAnimating = true;
7220 }
7221 } else if (mAnimation != null) {
7222 // If the display is frozen, and there is a pending animation,
7223 // clear it and make sure we run the cleanup code.
7224 mAnimating = true;
7225 mLocalAnimating = true;
7226 mAnimation = null;
7227 }
Romain Guy06882f82009-06-10 13:36:04 -07007228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007229 if (!mAnimating && !mLocalAnimating) {
7230 return false;
7231 }
7232
Joe Onorato8a9b2202010-02-26 18:56:32 -08007233 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007234 TAG, "Animation done in " + this + ": exiting=" + mExiting
7235 + ", reportedVisible="
7236 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007238 mAnimating = false;
7239 mLocalAnimating = false;
7240 mAnimation = null;
7241 mAnimLayer = mLayer;
7242 if (mIsImWindow) {
7243 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007244 } else if (mIsWallpaper) {
7245 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007246 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007247 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007248 + " anim layer: " + mAnimLayer);
7249 mHasTransformation = false;
7250 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007251 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7252 if (DEBUG_VISIBILITY) {
7253 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7254 + mPolicyVisibilityAfterAnim);
7255 }
7256 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7257 if (!mPolicyVisibility) {
7258 if (mCurrentFocus == this) {
7259 mFocusMayChange = true;
7260 }
7261 // Window is no longer visible -- make sure if we were waiting
7262 // for it to be displayed before enabling the display, that
7263 // we allow the display to be enabled now.
7264 enableScreenIfNeededLocked();
7265 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007266 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007267 mTransformation.clear();
7268 if (mHasDrawn
7269 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7270 && mAppToken != null
7271 && mAppToken.firstWindowDrawn
7272 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007273 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007274 + mToken + ": first real window done animating");
7275 mFinishedStarting.add(mAppToken);
7276 mH.sendEmptyMessage(H.FINISHED_STARTING);
7277 }
Romain Guy06882f82009-06-10 13:36:04 -07007278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 finishExit();
7280
7281 if (mAppToken != null) {
7282 mAppToken.updateReportedVisibilityLocked();
7283 }
7284
7285 return false;
7286 }
7287
7288 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007289 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 TAG, "finishExit in " + this
7291 + ": exiting=" + mExiting
7292 + " remove=" + mRemoveOnExit
7293 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007295 final int N = mChildWindows.size();
7296 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007297 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 }
Romain Guy06882f82009-06-10 13:36:04 -07007299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007300 if (!mExiting) {
7301 return;
7302 }
Romain Guy06882f82009-06-10 13:36:04 -07007303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007304 if (isWindowAnimating()) {
7305 return;
7306 }
7307
Joe Onorato8a9b2202010-02-26 18:56:32 -08007308 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 TAG, "Exit animation finished in " + this
7310 + ": remove=" + mRemoveOnExit);
7311 if (mSurface != null) {
7312 mDestroySurface.add(this);
7313 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007314 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007315 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007316 try {
7317 mSurface.hide();
7318 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007319 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007320 }
7321 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007322 }
7323 mExiting = false;
7324 if (mRemoveOnExit) {
7325 mPendingRemove.add(this);
7326 mRemoveOnExit = false;
7327 }
7328 }
Romain Guy06882f82009-06-10 13:36:04 -07007329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007330 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7331 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7332 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7333 if (dtdx < -.000001f || dtdx > .000001f) return false;
7334 if (dsdy < -.000001f || dsdy > .000001f) return false;
7335 return true;
7336 }
Romain Guy06882f82009-06-10 13:36:04 -07007337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 void computeShownFrameLocked() {
7339 final boolean selfTransformation = mHasLocalTransformation;
7340 Transformation attachedTransformation =
7341 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7342 ? mAttachedWindow.mTransformation : null;
7343 Transformation appTransformation =
7344 (mAppToken != null && mAppToken.hasTransformation)
7345 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007346
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007347 // Wallpapers are animated based on the "real" window they
7348 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007349 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007350 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007351 if (mWallpaperTarget.mHasLocalTransformation &&
7352 mWallpaperTarget.mAnimation != null &&
7353 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007354 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007355 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007356 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007357 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007358 }
7359 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007360 mWallpaperTarget.mAppToken.hasTransformation &&
7361 mWallpaperTarget.mAppToken.animation != null &&
7362 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007363 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007364 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007365 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007366 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007367 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007368 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007370 if (selfTransformation || attachedTransformation != null
7371 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007372 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007373 final Rect frame = mFrame;
7374 final float tmpFloats[] = mTmpFloats;
7375 final Matrix tmpMatrix = mTmpMatrix;
7376
7377 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007378 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007379 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007380 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007381 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007382 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007383 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007384 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 }
7386 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007387 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 }
7389
7390 // "convert" it into SurfaceFlinger's format
7391 // (a 2x2 matrix + an offset)
7392 // Here we must not transform the position of the surface
7393 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007394 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007396 tmpMatrix.getValues(tmpFloats);
7397 mDsDx = tmpFloats[Matrix.MSCALE_X];
7398 mDtDx = tmpFloats[Matrix.MSKEW_X];
7399 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7400 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007401 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7402 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007403 int w = frame.width();
7404 int h = frame.height();
7405 mShownFrame.set(x, y, x+w, y+h);
7406
7407 // Now set the alpha... but because our current hardware
7408 // can't do alpha transformation on a non-opaque surface,
7409 // turn it off if we are running an animation that is also
7410 // transforming since it is more important to have that
7411 // animation be smooth.
7412 mShownAlpha = mAlpha;
7413 if (!mLimitedAlphaCompositing
7414 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7415 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7416 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007417 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 if (selfTransformation) {
7419 mShownAlpha *= mTransformation.getAlpha();
7420 }
7421 if (attachedTransformation != null) {
7422 mShownAlpha *= attachedTransformation.getAlpha();
7423 }
7424 if (appTransformation != null) {
7425 mShownAlpha *= appTransformation.getAlpha();
7426 }
7427 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007428 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 }
Romain Guy06882f82009-06-10 13:36:04 -07007430
Joe Onorato8a9b2202010-02-26 18:56:32 -08007431 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007432 TAG, "Continuing animation in " + this +
7433 ": " + mShownFrame +
7434 ", alpha=" + mTransformation.getAlpha());
7435 return;
7436 }
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007439 if (mXOffset != 0 || mYOffset != 0) {
7440 mShownFrame.offset(mXOffset, mYOffset);
7441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 mShownAlpha = mAlpha;
7443 mDsDx = 1;
7444 mDtDx = 0;
7445 mDsDy = 0;
7446 mDtDy = 1;
7447 }
Romain Guy06882f82009-06-10 13:36:04 -07007448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 /**
7450 * Is this window visible? It is not visible if there is no
7451 * surface, or we are in the process of running an exit animation
7452 * that will remove the surface, or its app token has been hidden.
7453 */
7454 public boolean isVisibleLw() {
7455 final AppWindowToken atoken = mAppToken;
7456 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7457 && (atoken == null || !atoken.hiddenRequested)
7458 && !mExiting && !mDestroying;
7459 }
7460
7461 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007462 * Like {@link #isVisibleLw}, but also counts a window that is currently
7463 * "hidden" behind the keyguard as visible. This allows us to apply
7464 * things like window flags that impact the keyguard.
7465 * XXX I am starting to think we need to have ANOTHER visibility flag
7466 * for this "hidden behind keyguard" state rather than overloading
7467 * mPolicyVisibility. Ungh.
7468 */
7469 public boolean isVisibleOrBehindKeyguardLw() {
7470 final AppWindowToken atoken = mAppToken;
7471 return mSurface != null && !mAttachedHidden
7472 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007473 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007474 && !mExiting && !mDestroying;
7475 }
7476
7477 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 * Is this window visible, ignoring its app token? It is not visible
7479 * if there is no surface, or we are in the process of running an exit animation
7480 * that will remove the surface.
7481 */
7482 public boolean isWinVisibleLw() {
7483 final AppWindowToken atoken = mAppToken;
7484 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7485 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7486 && !mExiting && !mDestroying;
7487 }
7488
7489 /**
7490 * The same as isVisible(), but follows the current hidden state of
7491 * the associated app token, not the pending requested hidden state.
7492 */
7493 boolean isVisibleNow() {
7494 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007495 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007496 }
7497
7498 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007499 * Can this window possibly be a drag/drop target? The test here is
7500 * a combination of the above "visible now" with the check that the
7501 * Input Manager uses when discarding windows from input consideration.
7502 */
7503 boolean isPotentialDragTarget() {
7504 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7505 }
7506
7507 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 * Same as isVisible(), but we also count it as visible between the
7509 * call to IWindowSession.add() and the first relayout().
7510 */
7511 boolean isVisibleOrAdding() {
7512 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007513 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007514 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7515 && mPolicyVisibility && !mAttachedHidden
7516 && (atoken == null || !atoken.hiddenRequested)
7517 && !mExiting && !mDestroying;
7518 }
7519
7520 /**
7521 * Is this window currently on-screen? It is on-screen either if it
7522 * is visible or it is currently running an animation before no longer
7523 * being visible.
7524 */
7525 boolean isOnScreen() {
7526 final AppWindowToken atoken = mAppToken;
7527 if (atoken != null) {
7528 return mSurface != null && mPolicyVisibility && !mDestroying
7529 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007530 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 } else {
7532 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007533 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007534 }
7535 }
Romain Guy06882f82009-06-10 13:36:04 -07007536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 /**
7538 * Like isOnScreen(), but we don't return true if the window is part
7539 * of a transition that has not yet been started.
7540 */
7541 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007542 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007543 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007544 return false;
7545 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007547 final boolean animating = atoken != null
7548 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007549 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007550 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7551 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007552 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 }
7554
7555 /** Is the window or its container currently animating? */
7556 boolean isAnimating() {
7557 final WindowState attached = mAttachedWindow;
7558 final AppWindowToken atoken = mAppToken;
7559 return mAnimation != null
7560 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007561 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007562 (atoken.animation != null
7563 || atoken.inPendingTransaction));
7564 }
7565
7566 /** Is this window currently animating? */
7567 boolean isWindowAnimating() {
7568 return mAnimation != null;
7569 }
7570
7571 /**
7572 * Like isOnScreen, but returns false if the surface hasn't yet
7573 * been drawn.
7574 */
7575 public boolean isDisplayedLw() {
7576 final AppWindowToken atoken = mAppToken;
7577 return mSurface != null && mPolicyVisibility && !mDestroying
7578 && !mDrawPending && !mCommitDrawPending
7579 && ((!mAttachedHidden &&
7580 (atoken == null || !atoken.hiddenRequested))
7581 || mAnimating);
7582 }
7583
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007584 /**
7585 * Returns true if the window has a surface that it has drawn a
7586 * complete UI in to.
7587 */
7588 public boolean isDrawnLw() {
7589 final AppWindowToken atoken = mAppToken;
7590 return mSurface != null && !mDestroying
7591 && !mDrawPending && !mCommitDrawPending;
7592 }
7593
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007594 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007595 * Return true if the window is opaque and fully drawn. This indicates
7596 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007597 */
7598 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007599 return (mAttrs.format == PixelFormat.OPAQUE
7600 || mAttrs.type == TYPE_WALLPAPER)
7601 && mSurface != null && mAnimation == null
7602 && (mAppToken == null || mAppToken.animation == null)
7603 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007604 }
7605
7606 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7607 return
7608 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007609 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7610 // only if it's visible
7611 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007612 // and only if the application fills the compatible screen
7613 mFrame.left <= mCompatibleScreenFrame.left &&
7614 mFrame.top <= mCompatibleScreenFrame.top &&
7615 mFrame.right >= mCompatibleScreenFrame.right &&
7616 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007617 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007618 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007619 }
7620
7621 boolean isFullscreen(int screenWidth, int screenHeight) {
7622 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007623 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007624 }
7625
7626 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007627 disposeInputChannel();
7628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 if (mAttachedWindow != null) {
7630 mAttachedWindow.mChildWindows.remove(this);
7631 }
7632 destroySurfaceLocked();
7633 mSession.windowRemovedLocked();
7634 try {
7635 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7636 } catch (RuntimeException e) {
7637 // Ignore if it has already been removed (usually because
7638 // we are doing this as part of processing a death note.)
7639 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007640 }
7641
7642 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007643 if (mInputChannel != null) {
7644 mInputManager.unregisterInputChannel(mInputChannel);
7645
7646 mInputChannel.dispose();
7647 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07007648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007649 }
7650
7651 private class DeathRecipient implements IBinder.DeathRecipient {
7652 public void binderDied() {
7653 try {
7654 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007655 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007656 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 if (win != null) {
7658 removeWindowLocked(mSession, win);
7659 }
7660 }
7661 } catch (IllegalArgumentException ex) {
7662 // This will happen if the window has already been
7663 // removed.
7664 }
7665 }
7666 }
7667
7668 /** Returns true if this window desires key events. */
7669 public final boolean canReceiveKeys() {
7670 return isVisibleOrAdding()
7671 && (mViewVisibility == View.VISIBLE)
7672 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7673 }
7674
7675 public boolean hasDrawnLw() {
7676 return mHasDrawn;
7677 }
7678
7679 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007680 return showLw(doAnimation, true);
7681 }
7682
7683 boolean showLw(boolean doAnimation, boolean requestAnim) {
7684 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7685 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007686 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007687 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007688 if (doAnimation) {
7689 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7690 + mPolicyVisibility + " mAnimation=" + mAnimation);
7691 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7692 doAnimation = false;
7693 } else if (mPolicyVisibility && mAnimation == null) {
7694 // Check for the case where we are currently visible and
7695 // not animating; we do not want to do animation at such a
7696 // point to become visible when we already are.
7697 doAnimation = false;
7698 }
7699 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007700 mPolicyVisibility = true;
7701 mPolicyVisibilityAfterAnim = true;
7702 if (doAnimation) {
7703 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7704 }
7705 if (requestAnim) {
7706 requestAnimationLocked(0);
7707 }
7708 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007709 }
7710
7711 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007712 return hideLw(doAnimation, true);
7713 }
7714
7715 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007716 if (doAnimation) {
7717 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7718 doAnimation = false;
7719 }
7720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007721 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7722 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007723 if (!current) {
7724 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007725 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007726 if (doAnimation) {
7727 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7728 if (mAnimation == null) {
7729 doAnimation = false;
7730 }
7731 }
7732 if (doAnimation) {
7733 mPolicyVisibilityAfterAnim = false;
7734 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007735 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007736 mPolicyVisibilityAfterAnim = false;
7737 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007738 // Window is no longer visible -- make sure if we were waiting
7739 // for it to be displayed before enabling the display, that
7740 // we allow the display to be enabled now.
7741 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007742 if (mCurrentFocus == this) {
7743 mFocusMayChange = true;
7744 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007745 }
7746 if (requestAnim) {
7747 requestAnimationLocked(0);
7748 }
7749 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007750 }
7751
7752 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007753 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7754 pw.print(" mClient="); pw.println(mClient.asBinder());
7755 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7756 if (mAttachedWindow != null || mLayoutAttached) {
7757 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7758 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7759 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007760 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7761 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7762 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007763 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7764 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007765 }
7766 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7767 pw.print(" mSubLayer="); pw.print(mSubLayer);
7768 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7769 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7770 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7771 pw.print("="); pw.print(mAnimLayer);
7772 pw.print(" mLastLayer="); pw.println(mLastLayer);
7773 if (mSurface != null) {
7774 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007775 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7776 pw.print(" layer="); pw.print(mSurfaceLayer);
7777 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7778 pw.print(" rect=("); pw.print(mSurfaceX);
7779 pw.print(","); pw.print(mSurfaceY);
7780 pw.print(") "); pw.print(mSurfaceW);
7781 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007782 }
7783 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7784 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7785 if (mAppToken != null) {
7786 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7787 }
7788 if (mTargetAppToken != null) {
7789 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7790 }
7791 pw.print(prefix); pw.print("mViewVisibility=0x");
7792 pw.print(Integer.toHexString(mViewVisibility));
7793 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007794 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7795 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007796 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7797 pw.print(prefix); pw.print("mPolicyVisibility=");
7798 pw.print(mPolicyVisibility);
7799 pw.print(" mPolicyVisibilityAfterAnim=");
7800 pw.print(mPolicyVisibilityAfterAnim);
7801 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7802 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007803 if (!mRelayoutCalled) {
7804 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7805 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007806 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007807 pw.print(" h="); pw.print(mRequestedHeight);
7808 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007809 if (mXOffset != 0 || mYOffset != 0) {
7810 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7811 pw.print(" y="); pw.println(mYOffset);
7812 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007813 pw.print(prefix); pw.print("mGivenContentInsets=");
7814 mGivenContentInsets.printShortString(pw);
7815 pw.print(" mGivenVisibleInsets=");
7816 mGivenVisibleInsets.printShortString(pw);
7817 pw.println();
7818 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7819 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7820 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7821 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007822 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007823 pw.print(prefix); pw.print("mShownFrame=");
7824 mShownFrame.printShortString(pw);
7825 pw.print(" last="); mLastShownFrame.printShortString(pw);
7826 pw.println();
7827 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7828 pw.print(" last="); mLastFrame.printShortString(pw);
7829 pw.println();
7830 pw.print(prefix); pw.print("mContainingFrame=");
7831 mContainingFrame.printShortString(pw);
7832 pw.print(" mDisplayFrame=");
7833 mDisplayFrame.printShortString(pw);
7834 pw.println();
7835 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7836 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7837 pw.println();
7838 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7839 pw.print(" last="); mLastContentInsets.printShortString(pw);
7840 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7841 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7842 pw.println();
7843 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7844 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7845 pw.print(" mAlpha="); pw.print(mAlpha);
7846 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7847 }
7848 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7849 || mAnimation != null) {
7850 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7851 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7852 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7853 pw.print(" mAnimation="); pw.println(mAnimation);
7854 }
7855 if (mHasTransformation || mHasLocalTransformation) {
7856 pw.print(prefix); pw.print("XForm: has=");
7857 pw.print(mHasTransformation);
7858 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7859 pw.print(" "); mTransformation.printShortString(pw);
7860 pw.println();
7861 }
7862 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7863 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7864 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7865 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7866 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7867 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7868 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7869 pw.print(" mDestroying="); pw.print(mDestroying);
7870 pw.print(" mRemoved="); pw.println(mRemoved);
7871 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007872 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007873 pw.print(prefix); pw.print("mOrientationChanging=");
7874 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007875 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7876 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007877 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007878 if (mHScale != 1 || mVScale != 1) {
7879 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7880 pw.print(" mVScale="); pw.println(mVScale);
7881 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007882 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007883 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7884 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7885 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007886 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7887 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7888 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7889 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007890 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007891
7892 String makeInputChannelName() {
7893 return Integer.toHexString(System.identityHashCode(this))
7894 + " " + mAttrs.getTitle();
7895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007896
7897 @Override
7898 public String toString() {
7899 return "Window{"
7900 + Integer.toHexString(System.identityHashCode(this))
7901 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7902 }
7903 }
Romain Guy06882f82009-06-10 13:36:04 -07007904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007905 // -------------------------------------------------------------
7906 // Window Token State
7907 // -------------------------------------------------------------
7908
7909 class WindowToken {
7910 // The actual token.
7911 final IBinder token;
7912
7913 // The type of window this token is for, as per WindowManager.LayoutParams.
7914 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007916 // Set if this token was explicitly added by a client, so should
7917 // not be removed when all windows are removed.
7918 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007919
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007920 // For printing.
7921 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007923 // If this is an AppWindowToken, this is non-null.
7924 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007926 // All of the windows associated with this token.
7927 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7928
7929 // Is key dispatching paused for this token?
7930 boolean paused = false;
7931
7932 // Should this token's windows be hidden?
7933 boolean hidden;
7934
7935 // Temporary for finding which tokens no longer have visible windows.
7936 boolean hasVisible;
7937
Dianne Hackborna8f60182009-09-01 19:01:50 -07007938 // Set to true when this token is in a pending transaction where it
7939 // will be shown.
7940 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007941
Dianne Hackborna8f60182009-09-01 19:01:50 -07007942 // Set to true when this token is in a pending transaction where it
7943 // will be hidden.
7944 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007945
Dianne Hackborna8f60182009-09-01 19:01:50 -07007946 // Set to true when this token is in a pending transaction where its
7947 // windows will be put to the bottom of the list.
7948 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007949
Dianne Hackborna8f60182009-09-01 19:01:50 -07007950 // Set to true when this token is in a pending transaction where its
7951 // windows will be put to the top of the list.
7952 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007954 WindowToken(IBinder _token, int type, boolean _explicit) {
7955 token = _token;
7956 windowType = type;
7957 explicit = _explicit;
7958 }
7959
7960 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007961 pw.print(prefix); pw.print("token="); pw.println(token);
7962 pw.print(prefix); pw.print("windows="); pw.println(windows);
7963 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7964 pw.print(" hidden="); pw.print(hidden);
7965 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007966 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7967 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7968 pw.print(" waitingToHide="); pw.print(waitingToHide);
7969 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7970 pw.print(" sendingToTop="); pw.println(sendingToTop);
7971 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007972 }
7973
7974 @Override
7975 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007976 if (stringName == null) {
7977 StringBuilder sb = new StringBuilder();
7978 sb.append("WindowToken{");
7979 sb.append(Integer.toHexString(System.identityHashCode(this)));
7980 sb.append(" token="); sb.append(token); sb.append('}');
7981 stringName = sb.toString();
7982 }
7983 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007984 }
7985 };
7986
7987 class AppWindowToken extends WindowToken {
7988 // Non-null only for application tokens.
7989 final IApplicationToken appToken;
7990
7991 // All of the windows and child windows that are included in this
7992 // application token. Note this list is NOT sorted!
7993 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7994
7995 int groupId = -1;
7996 boolean appFullscreen;
7997 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007998
7999 // The input dispatching timeout for this application token in nanoseconds.
8000 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07008001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008002 // These are used for determining when all windows associated with
8003 // an activity have been drawn, so they can be made visible together
8004 // at the same time.
8005 int lastTransactionSequence = mTransactionSequence-1;
8006 int numInterestingWindows;
8007 int numDrawnWindows;
8008 boolean inPendingTransaction;
8009 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07008010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008011 // Is this token going to be hidden in a little while? If so, it
8012 // won't be taken into account for setting the screen orientation.
8013 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008015 // Is this window's surface needed? This is almost like hidden, except
8016 // it will sometimes be true a little earlier: when the token has
8017 // been shown, but is still waiting for its app transition to execute
8018 // before making its windows shown.
8019 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 // Have we told the window clients to hide themselves?
8022 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008024 // Last visibility state we reported to the app token.
8025 boolean reportedVisible;
8026
8027 // Set to true when the token has been removed from the window mgr.
8028 boolean removed;
8029
8030 // Have we been asked to have this token keep the screen frozen?
8031 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008033 boolean animating;
8034 Animation animation;
8035 boolean hasTransformation;
8036 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 // Offset to the window of all layers in the token, for use by
8039 // AppWindowToken animations.
8040 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008042 // Information about an application starting window if displayed.
8043 StartingData startingData;
8044 WindowState startingWindow;
8045 View startingView;
8046 boolean startingDisplayed;
8047 boolean startingMoved;
8048 boolean firstWindowDrawn;
8049
8050 AppWindowToken(IApplicationToken _token) {
8051 super(_token.asBinder(),
8052 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8053 appWindowToken = this;
8054 appToken = _token;
8055 }
Romain Guy06882f82009-06-10 13:36:04 -07008056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008057 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008058 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 TAG, "Setting animation in " + this + ": " + anim);
8060 animation = anim;
8061 animating = false;
8062 anim.restrictDuration(MAX_ANIMATION_DURATION);
8063 anim.scaleCurrentDuration(mTransitionAnimationScale);
8064 int zorder = anim.getZAdjustment();
8065 int adj = 0;
8066 if (zorder == Animation.ZORDER_TOP) {
8067 adj = TYPE_LAYER_OFFSET;
8068 } else if (zorder == Animation.ZORDER_BOTTOM) {
8069 adj = -TYPE_LAYER_OFFSET;
8070 }
Romain Guy06882f82009-06-10 13:36:04 -07008071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008072 if (animLayerAdjustment != adj) {
8073 animLayerAdjustment = adj;
8074 updateLayers();
8075 }
8076 }
Romain Guy06882f82009-06-10 13:36:04 -07008077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008078 public void setDummyAnimation() {
8079 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008080 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008081 TAG, "Setting dummy animation in " + this);
8082 animation = sDummyAnimation;
8083 }
8084 }
8085
8086 public void clearAnimation() {
8087 if (animation != null) {
8088 animation = null;
8089 animating = true;
8090 }
8091 }
Romain Guy06882f82009-06-10 13:36:04 -07008092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008093 void updateLayers() {
8094 final int N = allAppWindows.size();
8095 final int adj = animLayerAdjustment;
8096 for (int i=0; i<N; i++) {
8097 WindowState w = allAppWindows.get(i);
8098 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008099 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008100 + w.mAnimLayer);
8101 if (w == mInputMethodTarget) {
8102 setInputMethodAnimLayerAdjustment(adj);
8103 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008104 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008105 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 }
8108 }
Romain Guy06882f82009-06-10 13:36:04 -07008109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008110 void sendAppVisibilityToClients() {
8111 final int N = allAppWindows.size();
8112 for (int i=0; i<N; i++) {
8113 WindowState win = allAppWindows.get(i);
8114 if (win == startingWindow && clientHidden) {
8115 // Don't hide the starting window.
8116 continue;
8117 }
8118 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008119 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 "Setting visibility of " + win + ": " + (!clientHidden));
8121 win.mClient.dispatchAppVisibility(!clientHidden);
8122 } catch (RemoteException e) {
8123 }
8124 }
8125 }
Romain Guy06882f82009-06-10 13:36:04 -07008126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008127 void showAllWindowsLocked() {
8128 final int NW = allAppWindows.size();
8129 for (int i=0; i<NW; i++) {
8130 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008131 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008132 "performing show on: " + w);
8133 w.performShowLocked();
8134 }
8135 }
Romain Guy06882f82009-06-10 13:36:04 -07008136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008137 // This must be called while inside a transaction.
8138 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008139 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008142 if (animation == sDummyAnimation) {
8143 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008144 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 // when it is really time to animate, this will be set to
8146 // a real animation and the next call will execute normally.
8147 return false;
8148 }
Romain Guy06882f82009-06-10 13:36:04 -07008149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008150 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8151 if (!animating) {
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, "Starting animation in " + this +
8154 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8155 + " scale=" + mTransitionAnimationScale
8156 + " allDrawn=" + allDrawn + " animating=" + animating);
8157 animation.initialize(dw, dh, dw, dh);
8158 animation.setStartTime(currentTime);
8159 animating = true;
8160 }
8161 transformation.clear();
8162 final boolean more = animation.getTransformation(
8163 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008164 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008165 TAG, "Stepped animation in " + this +
8166 ": more=" + more + ", xform=" + transformation);
8167 if (more) {
8168 // we're done!
8169 hasTransformation = true;
8170 return true;
8171 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008172 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008173 TAG, "Finished animation in " + this +
8174 " @ " + currentTime);
8175 animation = null;
8176 }
8177 } else if (animation != null) {
8178 // If the display is frozen, and there is a pending animation,
8179 // clear it and make sure we run the cleanup code.
8180 animating = true;
8181 animation = null;
8182 }
8183
8184 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008186 if (!animating) {
8187 return false;
8188 }
8189
8190 clearAnimation();
8191 animating = false;
8192 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8193 moveInputMethodWindowsIfNeededLocked(true);
8194 }
Romain Guy06882f82009-06-10 13:36:04 -07008195
Joe Onorato8a9b2202010-02-26 18:56:32 -08008196 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008197 TAG, "Animation done in " + this
8198 + ": reportedVisible=" + reportedVisible);
8199
8200 transformation.clear();
8201 if (animLayerAdjustment != 0) {
8202 animLayerAdjustment = 0;
8203 updateLayers();
8204 }
Romain Guy06882f82009-06-10 13:36:04 -07008205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008206 final int N = windows.size();
8207 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008208 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008209 }
8210 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 return false;
8213 }
8214
8215 void updateReportedVisibilityLocked() {
8216 if (appToken == null) {
8217 return;
8218 }
Romain Guy06882f82009-06-10 13:36:04 -07008219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008220 int numInteresting = 0;
8221 int numVisible = 0;
8222 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008223
Joe Onorato8a9b2202010-02-26 18:56:32 -08008224 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 final int N = allAppWindows.size();
8226 for (int i=0; i<N; i++) {
8227 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008228 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008229 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008230 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8231 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008232 continue;
8233 }
8234 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008235 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008236 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008237 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008238 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008239 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008240 + " pv=" + win.mPolicyVisibility
8241 + " dp=" + win.mDrawPending
8242 + " cdp=" + win.mCommitDrawPending
8243 + " ah=" + win.mAttachedHidden
8244 + " th="
8245 + (win.mAppToken != null
8246 ? win.mAppToken.hiddenRequested : false)
8247 + " a=" + win.mAnimating);
8248 }
8249 }
8250 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008251 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008252 if (!win.isAnimating()) {
8253 numVisible++;
8254 }
8255 nowGone = false;
8256 } else if (win.isAnimating()) {
8257 nowGone = false;
8258 }
8259 }
Romain Guy06882f82009-06-10 13:36:04 -07008260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008261 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008262 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008263 + numInteresting + " visible=" + numVisible);
8264 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008265 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008266 TAG, "Visibility changed in " + this
8267 + ": vis=" + nowVisible);
8268 reportedVisible = nowVisible;
8269 Message m = mH.obtainMessage(
8270 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8271 nowVisible ? 1 : 0,
8272 nowGone ? 1 : 0,
8273 this);
8274 mH.sendMessage(m);
8275 }
8276 }
Romain Guy06882f82009-06-10 13:36:04 -07008277
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008278 WindowState findMainWindow() {
8279 int j = windows.size();
8280 while (j > 0) {
8281 j--;
8282 WindowState win = windows.get(j);
8283 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8284 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8285 return win;
8286 }
8287 }
8288 return null;
8289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008291 void dump(PrintWriter pw, String prefix) {
8292 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008293 if (appToken != null) {
8294 pw.print(prefix); pw.println("app=true");
8295 }
8296 if (allAppWindows.size() > 0) {
8297 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8298 }
8299 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008300 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008301 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8302 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8303 pw.print(" clientHidden="); pw.print(clientHidden);
8304 pw.print(" willBeHidden="); pw.print(willBeHidden);
8305 pw.print(" reportedVisible="); pw.println(reportedVisible);
8306 if (paused || freezingScreen) {
8307 pw.print(prefix); pw.print("paused="); pw.print(paused);
8308 pw.print(" freezingScreen="); pw.println(freezingScreen);
8309 }
8310 if (numInterestingWindows != 0 || numDrawnWindows != 0
8311 || inPendingTransaction || allDrawn) {
8312 pw.print(prefix); pw.print("numInterestingWindows=");
8313 pw.print(numInterestingWindows);
8314 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8315 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8316 pw.print(" allDrawn="); pw.println(allDrawn);
8317 }
8318 if (animating || animation != null) {
8319 pw.print(prefix); pw.print("animating="); pw.print(animating);
8320 pw.print(" animation="); pw.println(animation);
8321 }
8322 if (animLayerAdjustment != 0) {
8323 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8324 }
8325 if (hasTransformation) {
8326 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8327 pw.print(" transformation="); transformation.printShortString(pw);
8328 pw.println();
8329 }
8330 if (startingData != null || removed || firstWindowDrawn) {
8331 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8332 pw.print(" removed="); pw.print(removed);
8333 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8334 }
8335 if (startingWindow != null || startingView != null
8336 || startingDisplayed || startingMoved) {
8337 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8338 pw.print(" startingView="); pw.print(startingView);
8339 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8340 pw.print(" startingMoved"); pw.println(startingMoved);
8341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008342 }
8343
8344 @Override
8345 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008346 if (stringName == null) {
8347 StringBuilder sb = new StringBuilder();
8348 sb.append("AppWindowToken{");
8349 sb.append(Integer.toHexString(System.identityHashCode(this)));
8350 sb.append(" token="); sb.append(token); sb.append('}');
8351 stringName = sb.toString();
8352 }
8353 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 }
8355 }
Romain Guy06882f82009-06-10 13:36:04 -07008356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 // -------------------------------------------------------------
8358 // DummyAnimation
8359 // -------------------------------------------------------------
8360
8361 // This is an animation that does nothing: it just immediately finishes
8362 // itself every time it is called. It is used as a stub animation in cases
8363 // where we want to synchronize multiple things that may be animating.
8364 static final class DummyAnimation extends Animation {
8365 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8366 return false;
8367 }
8368 }
8369 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008371 // -------------------------------------------------------------
8372 // Async Handler
8373 // -------------------------------------------------------------
8374
8375 static final class StartingData {
8376 final String pkg;
8377 final int theme;
8378 final CharSequence nonLocalizedLabel;
8379 final int labelRes;
8380 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008382 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8383 int _labelRes, int _icon) {
8384 pkg = _pkg;
8385 theme = _theme;
8386 nonLocalizedLabel = _nonLocalizedLabel;
8387 labelRes = _labelRes;
8388 icon = _icon;
8389 }
8390 }
8391
8392 private final class H extends Handler {
8393 public static final int REPORT_FOCUS_CHANGE = 2;
8394 public static final int REPORT_LOSING_FOCUS = 3;
8395 public static final int ANIMATE = 4;
8396 public static final int ADD_STARTING = 5;
8397 public static final int REMOVE_STARTING = 6;
8398 public static final int FINISHED_STARTING = 7;
8399 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008400 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8401 public static final int HOLD_SCREEN_CHANGED = 12;
8402 public static final int APP_TRANSITION_TIMEOUT = 13;
8403 public static final int PERSIST_ANIMATION_SCALE = 14;
8404 public static final int FORCE_GC = 15;
8405 public static final int ENABLE_SCREEN = 16;
8406 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008407 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008408 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008409 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f12010-10-19 15:15:08 -07008410 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008412 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 public H() {
8415 }
Romain Guy06882f82009-06-10 13:36:04 -07008416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008417 @Override
8418 public void handleMessage(Message msg) {
8419 switch (msg.what) {
8420 case REPORT_FOCUS_CHANGE: {
8421 WindowState lastFocus;
8422 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008424 synchronized(mWindowMap) {
8425 lastFocus = mLastFocus;
8426 newFocus = mCurrentFocus;
8427 if (lastFocus == newFocus) {
8428 // Focus is not changing, so nothing to do.
8429 return;
8430 }
8431 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008432 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008433 // + " to " + newFocus);
8434 if (newFocus != null && lastFocus != null
8435 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008436 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 mLosingFocus.add(lastFocus);
8438 lastFocus = null;
8439 }
8440 }
8441
8442 if (lastFocus != newFocus) {
8443 //System.out.println("Changing focus from " + lastFocus
8444 // + " to " + newFocus);
8445 if (newFocus != null) {
8446 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008447 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008448 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8449 } catch (RemoteException e) {
8450 // Ignore if process has died.
8451 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008452 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008453 }
8454
8455 if (lastFocus != null) {
8456 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008457 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8459 } catch (RemoteException e) {
8460 // Ignore if process has died.
8461 }
8462 }
8463 }
8464 } break;
8465
8466 case REPORT_LOSING_FOCUS: {
8467 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008469 synchronized(mWindowMap) {
8470 losers = mLosingFocus;
8471 mLosingFocus = new ArrayList<WindowState>();
8472 }
8473
8474 final int N = losers.size();
8475 for (int i=0; i<N; i++) {
8476 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008477 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008478 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8479 } catch (RemoteException e) {
8480 // Ignore if process has died.
8481 }
8482 }
8483 } break;
8484
8485 case ANIMATE: {
8486 synchronized(mWindowMap) {
8487 mAnimationPending = false;
8488 performLayoutAndPlaceSurfacesLocked();
8489 }
8490 } break;
8491
8492 case ADD_STARTING: {
8493 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8494 final StartingData sd = wtoken.startingData;
8495
8496 if (sd == null) {
8497 // Animation has been canceled... do nothing.
8498 return;
8499 }
Romain Guy06882f82009-06-10 13:36:04 -07008500
Joe Onorato8a9b2202010-02-26 18:56:32 -08008501 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008502 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008504 View view = null;
8505 try {
8506 view = mPolicy.addStartingWindow(
8507 wtoken.token, sd.pkg,
8508 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8509 sd.icon);
8510 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008511 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008512 }
8513
8514 if (view != null) {
8515 boolean abort = false;
8516
8517 synchronized(mWindowMap) {
8518 if (wtoken.removed || wtoken.startingData == null) {
8519 // If the window was successfully added, then
8520 // we need to remove it.
8521 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008522 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 "Aborted starting " + wtoken
8524 + ": removed=" + wtoken.removed
8525 + " startingData=" + wtoken.startingData);
8526 wtoken.startingWindow = null;
8527 wtoken.startingData = null;
8528 abort = true;
8529 }
8530 } else {
8531 wtoken.startingView = view;
8532 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008533 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 "Added starting " + wtoken
8535 + ": startingWindow="
8536 + wtoken.startingWindow + " startingView="
8537 + wtoken.startingView);
8538 }
8539
8540 if (abort) {
8541 try {
8542 mPolicy.removeStartingWindow(wtoken.token, view);
8543 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008544 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 }
8546 }
8547 }
8548 } break;
8549
8550 case REMOVE_STARTING: {
8551 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8552 IBinder token = null;
8553 View view = null;
8554 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008555 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 + wtoken + ": startingWindow="
8557 + wtoken.startingWindow + " startingView="
8558 + wtoken.startingView);
8559 if (wtoken.startingWindow != null) {
8560 view = wtoken.startingView;
8561 token = wtoken.token;
8562 wtoken.startingData = null;
8563 wtoken.startingView = null;
8564 wtoken.startingWindow = null;
8565 }
8566 }
8567 if (view != null) {
8568 try {
8569 mPolicy.removeStartingWindow(token, view);
8570 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008571 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572 }
8573 }
8574 } break;
8575
8576 case FINISHED_STARTING: {
8577 IBinder token = null;
8578 View view = null;
8579 while (true) {
8580 synchronized (mWindowMap) {
8581 final int N = mFinishedStarting.size();
8582 if (N <= 0) {
8583 break;
8584 }
8585 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8586
Joe Onorato8a9b2202010-02-26 18:56:32 -08008587 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008588 "Finished starting " + wtoken
8589 + ": startingWindow=" + wtoken.startingWindow
8590 + " startingView=" + wtoken.startingView);
8591
8592 if (wtoken.startingWindow == null) {
8593 continue;
8594 }
8595
8596 view = wtoken.startingView;
8597 token = wtoken.token;
8598 wtoken.startingData = null;
8599 wtoken.startingView = null;
8600 wtoken.startingWindow = null;
8601 }
8602
8603 try {
8604 mPolicy.removeStartingWindow(token, view);
8605 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008606 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008607 }
8608 }
8609 } break;
8610
8611 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8612 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8613
8614 boolean nowVisible = msg.arg1 != 0;
8615 boolean nowGone = msg.arg2 != 0;
8616
8617 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008618 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 TAG, "Reporting visible in " + wtoken
8620 + " visible=" + nowVisible
8621 + " gone=" + nowGone);
8622 if (nowVisible) {
8623 wtoken.appToken.windowsVisible();
8624 } else {
8625 wtoken.appToken.windowsGone();
8626 }
8627 } catch (RemoteException ex) {
8628 }
8629 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008631 case WINDOW_FREEZE_TIMEOUT: {
8632 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008633 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008634 int i = mWindows.size();
8635 while (i > 0) {
8636 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008637 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 if (w.mOrientationChanging) {
8639 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008640 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 }
8642 }
8643 performLayoutAndPlaceSurfacesLocked();
8644 }
8645 break;
8646 }
Romain Guy06882f82009-06-10 13:36:04 -07008647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008648 case HOLD_SCREEN_CHANGED: {
8649 Session oldHold;
8650 Session newHold;
8651 synchronized (mWindowMap) {
8652 oldHold = mLastReportedHold;
8653 newHold = (Session)msg.obj;
8654 mLastReportedHold = newHold;
8655 }
Romain Guy06882f82009-06-10 13:36:04 -07008656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008657 if (oldHold != newHold) {
8658 try {
8659 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008660 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008661 "window",
8662 BatteryStats.WAKE_TYPE_WINDOW);
8663 }
8664 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008665 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008666 "window",
8667 BatteryStats.WAKE_TYPE_WINDOW);
8668 }
8669 } catch (RemoteException e) {
8670 }
8671 }
8672 break;
8673 }
Romain Guy06882f82009-06-10 13:36:04 -07008674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008675 case APP_TRANSITION_TIMEOUT: {
8676 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008677 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008678 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008679 "*** APP TRANSITION TIMEOUT");
8680 mAppTransitionReady = true;
8681 mAppTransitionTimeout = true;
8682 performLayoutAndPlaceSurfacesLocked();
8683 }
8684 }
8685 break;
8686 }
Romain Guy06882f82009-06-10 13:36:04 -07008687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008688 case PERSIST_ANIMATION_SCALE: {
8689 Settings.System.putFloat(mContext.getContentResolver(),
8690 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8691 Settings.System.putFloat(mContext.getContentResolver(),
8692 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8693 break;
8694 }
Romain Guy06882f82009-06-10 13:36:04 -07008695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 case FORCE_GC: {
8697 synchronized(mWindowMap) {
8698 if (mAnimationPending) {
8699 // If we are animating, don't do the gc now but
8700 // delay a bit so we don't interrupt the animation.
8701 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8702 2000);
8703 return;
8704 }
8705 // If we are currently rotating the display, it will
8706 // schedule a new message when done.
8707 if (mDisplayFrozen) {
8708 return;
8709 }
8710 mFreezeGcPending = 0;
8711 }
8712 Runtime.getRuntime().gc();
8713 break;
8714 }
Romain Guy06882f82009-06-10 13:36:04 -07008715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008716 case ENABLE_SCREEN: {
8717 performEnableScreen();
8718 break;
8719 }
Romain Guy06882f82009-06-10 13:36:04 -07008720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008721 case APP_FREEZE_TIMEOUT: {
8722 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008723 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008724 int i = mAppTokens.size();
8725 while (i > 0) {
8726 i--;
8727 AppWindowToken tok = mAppTokens.get(i);
8728 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008729 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008730 unsetAppFreezingScreenLocked(tok, true, true);
8731 }
8732 }
8733 }
8734 break;
8735 }
Romain Guy06882f82009-06-10 13:36:04 -07008736
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008737 case SEND_NEW_CONFIGURATION: {
8738 removeMessages(SEND_NEW_CONFIGURATION);
8739 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008740 break;
8741 }
Romain Guy06882f82009-06-10 13:36:04 -07008742
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008743 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008744 if (mWindowsChanged) {
8745 synchronized (mWindowMap) {
8746 mWindowsChanged = false;
8747 }
8748 notifyWindowsChanged();
8749 }
8750 break;
8751 }
8752
Christopher Tatea53146c2010-09-07 11:57:52 -07008753 case DRAG_START_TIMEOUT: {
8754 IBinder win = (IBinder)msg.obj;
8755 if (DEBUG_DRAG) {
8756 Slog.w(TAG, "Timeout starting drag by win " + win);
8757 }
8758 synchronized (mWindowMap) {
8759 // !!! TODO: ANR the app that has failed to start the drag in time
8760 if (mDragState != null) {
Chris Tated4533f12010-10-19 15:15:08 -07008761 mDragState.unregister();
8762 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008763 mDragState.reset();
8764 mDragState = null;
8765 }
8766 }
Chris Tated4533f12010-10-19 15:15:08 -07008767 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008768 }
8769
Chris Tated4533f12010-10-19 15:15:08 -07008770 case DRAG_END_TIMEOUT: {
8771 IBinder win = (IBinder)msg.obj;
8772 if (DEBUG_DRAG) {
8773 Slog.w(TAG, "Timeout ending drag to win " + win);
8774 }
8775 synchronized (mWindowMap) {
8776 // !!! TODO: ANR the drag-receiving app
8777 mDragState.mDragResult = false;
8778 mDragState.endDragLw();
8779 }
8780 break;
8781 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008782 }
8783 }
8784 }
8785
8786 // -------------------------------------------------------------
8787 // IWindowManager API
8788 // -------------------------------------------------------------
8789
8790 public IWindowSession openSession(IInputMethodClient client,
8791 IInputContext inputContext) {
8792 if (client == null) throw new IllegalArgumentException("null client");
8793 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008794 Session session = new Session(client, inputContext);
8795 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 }
8797
8798 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8799 synchronized (mWindowMap) {
8800 // The focus for the client is the window immediately below
8801 // where we would place the input method window.
8802 int idx = findDesiredInputMethodWindowIndexLocked(false);
8803 WindowState imFocus;
8804 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008805 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008806 if (imFocus != null) {
8807 if (imFocus.mSession.mClient != null &&
8808 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8809 return true;
8810 }
8811 }
8812 }
8813 }
8814 return false;
8815 }
Romain Guy06882f82009-06-10 13:36:04 -07008816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008817 // -------------------------------------------------------------
8818 // Internals
8819 // -------------------------------------------------------------
8820
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008821 final WindowState windowForClientLocked(Session session, IWindow client,
8822 boolean throwOnError) {
8823 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008824 }
Romain Guy06882f82009-06-10 13:36:04 -07008825
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008826 final WindowState windowForClientLocked(Session session, IBinder client,
8827 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008828 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008829 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008830 TAG, "Looking up client " + client + ": " + win);
8831 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008832 RuntimeException ex = new IllegalArgumentException(
8833 "Requested window " + client + " does not exist");
8834 if (throwOnError) {
8835 throw ex;
8836 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008837 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008838 return null;
8839 }
8840 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008841 RuntimeException ex = new IllegalArgumentException(
8842 "Requested window " + client + " is in session " +
8843 win.mSession + ", not " + session);
8844 if (throwOnError) {
8845 throw ex;
8846 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008847 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008848 return null;
8849 }
8850
8851 return win;
8852 }
8853
Dianne Hackborna8f60182009-09-01 19:01:50 -07008854 final void rebuildAppWindowListLocked() {
8855 int NW = mWindows.size();
8856 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008857 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008858 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008859
Dianne Hackborna8f60182009-09-01 19:01:50 -07008860 // First remove all existing app windows.
8861 i=0;
8862 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008863 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008864 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008865 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008866 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008867 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008868 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008869 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008870 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008871 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008872 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8873 && lastWallpaper == i-1) {
8874 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008875 }
8876 i++;
8877 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008878
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008879 // The wallpaper window(s) typically live at the bottom of the stack,
8880 // so skip them before adding app tokens.
8881 lastWallpaper++;
8882 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008883
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008884 // First add all of the exiting app tokens... these are no longer
8885 // in the main app list, but still have windows shown. We put them
8886 // in the back because now that the animation is over we no longer
8887 // will care about them.
8888 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008889 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008890 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8891 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008892
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008893 // And add in the still active app tokens in Z order.
8894 NT = mAppTokens.size();
8895 for (int j=0; j<NT; j++) {
8896 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008898
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008899 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008900 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008901 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008902 + " windows but added " + i);
8903 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008906 private final void assignLayersLocked() {
8907 int N = mWindows.size();
8908 int curBaseLayer = 0;
8909 int curLayer = 0;
8910 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008912 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008913 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008914 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8915 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008916 curLayer += WINDOW_LAYER_MULTIPLIER;
8917 w.mLayer = curLayer;
8918 } else {
8919 curBaseLayer = curLayer = w.mBaseLayer;
8920 w.mLayer = curLayer;
8921 }
8922 if (w.mTargetAppToken != null) {
8923 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8924 } else if (w.mAppToken != null) {
8925 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8926 } else {
8927 w.mAnimLayer = w.mLayer;
8928 }
8929 if (w.mIsImWindow) {
8930 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008931 } else if (w.mIsWallpaper) {
8932 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008933 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008934 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008935 + w.mAnimLayer);
8936 //System.out.println(
8937 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8938 }
8939 }
8940
8941 private boolean mInLayout = false;
8942 private final void performLayoutAndPlaceSurfacesLocked() {
8943 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008944 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008945 throw new RuntimeException("Recursive call!");
8946 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008947 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008948 return;
8949 }
8950
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008951 if (mWaitingForConfig) {
8952 // Our configuration has changed (most likely rotation), but we
8953 // don't yet have the complete configuration to report to
8954 // applications. Don't do any window layout until we have it.
8955 return;
8956 }
8957
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008958 if (mDisplay == null) {
8959 // Not yet initialized, nothing to do.
8960 return;
8961 }
8962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008963 boolean recoveringMemory = false;
8964 if (mForceRemoves != null) {
8965 recoveringMemory = true;
8966 // Wait a little it for things to settle down, and off we go.
8967 for (int i=0; i<mForceRemoves.size(); i++) {
8968 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008969 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008970 removeWindowInnerLocked(ws.mSession, ws);
8971 }
8972 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008973 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008974 Object tmp = new Object();
8975 synchronized (tmp) {
8976 try {
8977 tmp.wait(250);
8978 } catch (InterruptedException e) {
8979 }
8980 }
8981 }
Romain Guy06882f82009-06-10 13:36:04 -07008982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008983 mInLayout = true;
8984 try {
8985 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 int i = mPendingRemove.size()-1;
8988 if (i >= 0) {
8989 while (i >= 0) {
8990 WindowState w = mPendingRemove.get(i);
8991 removeWindowInnerLocked(w.mSession, w);
8992 i--;
8993 }
8994 mPendingRemove.clear();
8995
8996 mInLayout = false;
8997 assignLayersLocked();
8998 mLayoutNeeded = true;
8999 performLayoutAndPlaceSurfacesLocked();
9000
9001 } else {
9002 mInLayout = false;
9003 if (mLayoutNeeded) {
9004 requestAnimationLocked(0);
9005 }
9006 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009007 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07009008 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
9009 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07009010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009011 } catch (RuntimeException e) {
9012 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009013 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009014 }
9015 }
9016
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009017 private final int performLayoutLockedInner() {
9018 if (!mLayoutNeeded) {
9019 return 0;
9020 }
9021
9022 mLayoutNeeded = false;
9023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009024 final int dw = mDisplay.getWidth();
9025 final int dh = mDisplay.getHeight();
9026
9027 final int N = mWindows.size();
9028 int i;
9029
Joe Onorato8a9b2202010-02-26 18:56:32 -08009030 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009031 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9032
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009033 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009034
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009035 int seq = mLayoutSeq+1;
9036 if (seq < 0) seq = 0;
9037 mLayoutSeq = seq;
9038
9039 // First perform layout of any root windows (not attached
9040 // to another window).
9041 int topAttached = -1;
9042 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009043 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009044
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009045 // Don't do layout of a window if it is not visible, or
9046 // soon won't be visible, to avoid wasting time and funky
9047 // changes while a window is animating away.
9048 final AppWindowToken atoken = win.mAppToken;
9049 final boolean gone = win.mViewVisibility == View.GONE
9050 || !win.mRelayoutCalled
9051 || win.mRootToken.hidden
9052 || (atoken != null && atoken.hiddenRequested)
9053 || win.mAttachedHidden
9054 || win.mExiting || win.mDestroying;
9055
9056 if (!win.mLayoutAttached) {
9057 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9058 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9059 + " mLayoutAttached=" + win.mLayoutAttached);
9060 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9061 + win.mViewVisibility + " mRelayoutCalled="
9062 + win.mRelayoutCalled + " hidden="
9063 + win.mRootToken.hidden + " hiddenRequested="
9064 + (atoken != null && atoken.hiddenRequested)
9065 + " mAttachedHidden=" + win.mAttachedHidden);
9066 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009067
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009068 // If this view is GONE, then skip it -- keep the current
9069 // frame, and let the caller know so they can ignore it
9070 // if they want. (We do the normal layout for INVISIBLE
9071 // windows, since that means "perform layout as normal,
9072 // just don't display").
9073 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009074 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009075 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9076 win.mLayoutSeq = seq;
9077 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9078 + win.mFrame + " mContainingFrame="
9079 + win.mContainingFrame + " mDisplayFrame="
9080 + win.mDisplayFrame);
9081 } else {
9082 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009083 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009085 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009086
9087 // Now perform layout of attached windows, which usually
9088 // depend on the position of the window they are attached to.
9089 // XXX does not deal with windows that are attached to windows
9090 // that are themselves attached.
9091 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009092 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009093
9094 // If this view is GONE, then skip it -- keep the current
9095 // frame, and let the caller know so they can ignore it
9096 // if they want. (We do the normal layout for INVISIBLE
9097 // windows, since that means "perform layout as normal,
9098 // just don't display").
9099 if (win.mLayoutAttached) {
9100 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9101 + " mHaveFrame=" + win.mHaveFrame
9102 + " mViewVisibility=" + win.mViewVisibility
9103 + " mRelayoutCalled=" + win.mRelayoutCalled);
9104 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9105 || !win.mHaveFrame) {
9106 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9107 win.mLayoutSeq = seq;
9108 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9109 + win.mFrame + " mContainingFrame="
9110 + win.mContainingFrame + " mDisplayFrame="
9111 + win.mDisplayFrame);
9112 }
9113 }
9114 }
Jeff Brown349703e2010-06-22 01:27:15 -07009115
9116 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009117 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009118
9119 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009120 }
Romain Guy06882f82009-06-10 13:36:04 -07009121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009122 private final void performLayoutAndPlaceSurfacesLockedInner(
9123 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009124 if (mDisplay == null) {
9125 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9126 return;
9127 }
9128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009129 final long currentTime = SystemClock.uptimeMillis();
9130 final int dw = mDisplay.getWidth();
9131 final int dh = mDisplay.getHeight();
9132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133 int i;
9134
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009135 if (mFocusMayChange) {
9136 mFocusMayChange = false;
9137 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9138 }
9139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009140 // Initialize state of exiting tokens.
9141 for (i=mExitingTokens.size()-1; i>=0; i--) {
9142 mExitingTokens.get(i).hasVisible = false;
9143 }
9144
9145 // Initialize state of exiting applications.
9146 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9147 mExitingAppTokens.get(i).hasVisible = false;
9148 }
9149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 boolean orientationChangeComplete = true;
9151 Session holdScreen = null;
9152 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009153 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009154 boolean focusDisplayed = false;
9155 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009156 boolean createWatermark = false;
9157
9158 if (mFxSession == null) {
9159 mFxSession = new SurfaceSession();
9160 createWatermark = true;
9161 }
9162
9163 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009164
9165 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009166
9167 if (createWatermark) {
9168 createWatermark();
9169 }
9170 if (mWatermark != null) {
9171 mWatermark.positionSurface(dw, dh);
9172 }
9173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009174 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009175 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009176 int repeats = 0;
9177 int changes = 0;
9178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009179 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009180 repeats++;
9181 if (repeats > 6) {
9182 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9183 mLayoutNeeded = false;
9184 break;
9185 }
9186
9187 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9188 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9189 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9190 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9191 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9192 assignLayersLocked();
9193 mLayoutNeeded = true;
9194 }
9195 }
9196 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9197 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9198 if (updateOrientationFromAppTokensLocked()) {
9199 mLayoutNeeded = true;
9200 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9201 }
9202 }
9203 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9204 mLayoutNeeded = true;
9205 }
9206 }
9207
9208 // FIRST LOOP: Perform a layout, if needed.
9209 if (repeats < 4) {
9210 changes = performLayoutLockedInner();
9211 if (changes != 0) {
9212 continue;
9213 }
9214 } else {
9215 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9216 changes = 0;
9217 }
9218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 final int transactionSequence = ++mTransactionSequence;
9220
9221 // Update animations of all applications, including those
9222 // associated with exiting/removed apps
9223 boolean tokensAnimating = false;
9224 final int NAT = mAppTokens.size();
9225 for (i=0; i<NAT; i++) {
9226 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9227 tokensAnimating = true;
9228 }
9229 }
9230 final int NEAT = mExitingAppTokens.size();
9231 for (i=0; i<NEAT; i++) {
9232 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9233 tokensAnimating = true;
9234 }
9235 }
9236
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009237 // SECOND LOOP: Execute animations and update visibility of windows.
9238
Joe Onorato8a9b2202010-02-26 18:56:32 -08009239 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009240 + transactionSequence + " tokensAnimating="
9241 + tokensAnimating);
9242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244
9245 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009246 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009247 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009248
9249 mPolicy.beginAnimationLw(dw, dh);
9250
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009251 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009253 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009254 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009255
9256 final WindowManager.LayoutParams attrs = w.mAttrs;
9257
9258 if (w.mSurface != null) {
9259 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009260 if (w.commitFinishDrawingLocked(currentTime)) {
9261 if ((w.mAttrs.flags
9262 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009263 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009264 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009265 wallpaperMayChange = true;
9266 }
9267 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009268
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009269 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9271 animating = true;
9272 //w.dump(" ");
9273 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009274 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9275 wallpaperMayChange = true;
9276 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009277
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009278 if (mPolicy.doesForceHide(w, attrs)) {
9279 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009280 if (DEBUG_VISIBILITY) Slog.v(TAG,
9281 "Animation done that could impact force hide: "
9282 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009283 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009284 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009285 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9286 forceHiding = true;
9287 }
9288 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9289 boolean changed;
9290 if (forceHiding) {
9291 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009292 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9293 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009294 } else {
9295 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009296 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9297 "Now policy shown: " + w);
9298 if (changed) {
9299 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009300 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009301 // Assume we will need to animate. If
9302 // we don't (because the wallpaper will
9303 // stay with the lock screen), then we will
9304 // clean up later.
9305 Animation a = mPolicy.createForceHideEnterAnimation();
9306 if (a != null) {
9307 w.setAnimation(a);
9308 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009309 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009310 if (mCurrentFocus == null ||
9311 mCurrentFocus.mLayer < w.mLayer) {
9312 // We are showing on to of the current
9313 // focus, so re-evaluate focus to make
9314 // sure it is correct.
9315 mFocusMayChange = true;
9316 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009317 }
9318 }
9319 if (changed && (attrs.flags
9320 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9321 wallpaperMayChange = true;
9322 }
9323 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009325 mPolicy.animatingWindowLw(w, attrs);
9326 }
9327
9328 final AppWindowToken atoken = w.mAppToken;
9329 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9330 if (atoken.lastTransactionSequence != transactionSequence) {
9331 atoken.lastTransactionSequence = transactionSequence;
9332 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9333 atoken.startingDisplayed = false;
9334 }
9335 if ((w.isOnScreen() || w.mAttrs.type
9336 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9337 && !w.mExiting && !w.mDestroying) {
9338 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009339 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009340 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009341 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009342 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009343 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 + " pv=" + w.mPolicyVisibility
9345 + " dp=" + w.mDrawPending
9346 + " cdp=" + w.mCommitDrawPending
9347 + " ah=" + w.mAttachedHidden
9348 + " th=" + atoken.hiddenRequested
9349 + " a=" + w.mAnimating);
9350 }
9351 }
9352 if (w != atoken.startingWindow) {
9353 if (!atoken.freezingScreen || !w.mAppFreezing) {
9354 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009355 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009356 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009357 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 "tokenMayBeDrawn: " + atoken
9359 + " freezingScreen=" + atoken.freezingScreen
9360 + " mAppFreezing=" + w.mAppFreezing);
9361 tokenMayBeDrawn = true;
9362 }
9363 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009364 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009365 atoken.startingDisplayed = true;
9366 }
9367 }
9368 } else if (w.mReadyToShow) {
9369 w.performShowLocked();
9370 }
9371 }
9372
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009373 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009374
9375 if (tokenMayBeDrawn) {
9376 // See if any windows have been drawn, so they (and others
9377 // associated with them) can now be shown.
9378 final int NT = mTokenList.size();
9379 for (i=0; i<NT; i++) {
9380 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9381 if (wtoken == null) {
9382 continue;
9383 }
9384 if (wtoken.freezingScreen) {
9385 int numInteresting = wtoken.numInterestingWindows;
9386 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009387 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009388 "allDrawn: " + wtoken
9389 + " interesting=" + numInteresting
9390 + " drawn=" + wtoken.numDrawnWindows);
9391 wtoken.showAllWindowsLocked();
9392 unsetAppFreezingScreenLocked(wtoken, false, true);
9393 orientationChangeComplete = true;
9394 }
9395 } else if (!wtoken.allDrawn) {
9396 int numInteresting = wtoken.numInterestingWindows;
9397 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009398 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009399 "allDrawn: " + wtoken
9400 + " interesting=" + numInteresting
9401 + " drawn=" + wtoken.numDrawnWindows);
9402 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009403 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404
9405 // We can now show all of the drawn windows!
9406 if (!mOpeningApps.contains(wtoken)) {
9407 wtoken.showAllWindowsLocked();
9408 }
9409 }
9410 }
9411 }
9412 }
9413
9414 // If we are ready to perform an app transition, check through
9415 // all of the app tokens to be shown and see if they are ready
9416 // to go.
9417 if (mAppTransitionReady) {
9418 int NN = mOpeningApps.size();
9419 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009420 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009421 "Checking " + NN + " opening apps (frozen="
9422 + mDisplayFrozen + " timeout="
9423 + mAppTransitionTimeout + ")...");
9424 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9425 // If the display isn't frozen, wait to do anything until
9426 // all of the apps are ready. Otherwise just go because
9427 // we'll unfreeze the display when everyone is ready.
9428 for (i=0; i<NN && goodToGo; i++) {
9429 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009430 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009431 "Check opening app" + wtoken + ": allDrawn="
9432 + wtoken.allDrawn + " startingDisplayed="
9433 + wtoken.startingDisplayed);
9434 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9435 && !wtoken.startingMoved) {
9436 goodToGo = false;
9437 }
9438 }
9439 }
9440 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009441 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 int transit = mNextAppTransition;
9443 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009444 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009445 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009446 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009448 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009449 mAppTransitionTimeout = false;
9450 mStartingIconInTransition = false;
9451 mSkipAppTransitionAnimation = false;
9452
9453 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9454
Dianne Hackborna8f60182009-09-01 19:01:50 -07009455 // If there are applications waiting to come to the
9456 // top of the stack, now is the time to move their windows.
9457 // (Note that we don't do apps going to the bottom
9458 // here -- we want to keep their windows in the old
9459 // Z-order until the animation completes.)
9460 if (mToTopApps.size() > 0) {
9461 NN = mAppTokens.size();
9462 for (i=0; i<NN; i++) {
9463 AppWindowToken wtoken = mAppTokens.get(i);
9464 if (wtoken.sendingToTop) {
9465 wtoken.sendingToTop = false;
9466 moveAppWindowsLocked(wtoken, NN, false);
9467 }
9468 }
9469 mToTopApps.clear();
9470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009471
Dianne Hackborn25994b42009-09-04 14:21:19 -07009472 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009473
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009474 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009475 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009476
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009477 // The top-most window will supply the layout params,
9478 // and we will determine it below.
9479 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009480 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009481 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009482
Joe Onorato8a9b2202010-02-26 18:56:32 -08009483 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009484 "New wallpaper target=" + mWallpaperTarget
9485 + ", lower target=" + mLowerWallpaperTarget
9486 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009487 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009488 // Do a first pass through the tokens for two
9489 // things:
9490 // (1) Determine if both the closing and opening
9491 // app token sets are wallpaper targets, in which
9492 // case special animations are needed
9493 // (since the wallpaper needs to stay static
9494 // behind them).
9495 // (2) Find the layout params of the top-most
9496 // application window in the tokens, which is
9497 // what will control the animation theme.
9498 final int NC = mClosingApps.size();
9499 NN = NC + mOpeningApps.size();
9500 for (i=0; i<NN; i++) {
9501 AppWindowToken wtoken;
9502 int mode;
9503 if (i < NC) {
9504 wtoken = mClosingApps.get(i);
9505 mode = 1;
9506 } else {
9507 wtoken = mOpeningApps.get(i-NC);
9508 mode = 2;
9509 }
9510 if (mLowerWallpaperTarget != null) {
9511 if (mLowerWallpaperTarget.mAppToken == wtoken
9512 || mUpperWallpaperTarget.mAppToken == wtoken) {
9513 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009514 }
9515 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009516 if (wtoken.appFullscreen) {
9517 WindowState ws = wtoken.findMainWindow();
9518 if (ws != null) {
9519 // If this is a compatibility mode
9520 // window, we will always use its anim.
9521 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9522 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009523 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009524 bestAnimLayer = Integer.MAX_VALUE;
9525 } else if (ws.mLayer > bestAnimLayer) {
9526 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009527 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009528 bestAnimLayer = ws.mLayer;
9529 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009530 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009531 }
9532 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009533
Dianne Hackborn25994b42009-09-04 14:21:19 -07009534 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009535 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009536 "Wallpaper animation!");
9537 switch (transit) {
9538 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9539 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9540 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9541 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9542 break;
9543 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9544 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9545 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9546 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9547 break;
9548 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009549 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009550 "New transit: " + transit);
9551 } else if (oldWallpaper != null) {
9552 // We are transitioning from an activity with
9553 // a wallpaper to one without.
9554 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009555 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009556 "New transit away from wallpaper: " + transit);
9557 } else if (mWallpaperTarget != null) {
9558 // We are transitioning from an activity without
9559 // a wallpaper to now showing the wallpaper
9560 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009561 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009562 "New transit into wallpaper: " + transit);
9563 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009564
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009565 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9566 mLastEnterAnimToken = animToken;
9567 mLastEnterAnimParams = animLp;
9568 } else if (mLastEnterAnimParams != null) {
9569 animLp = mLastEnterAnimParams;
9570 mLastEnterAnimToken = null;
9571 mLastEnterAnimParams = null;
9572 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009573
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009574 // If all closing windows are obscured, then there is
9575 // no need to do an animation. This is the case, for
9576 // example, when this transition is being done behind
9577 // the lock screen.
9578 if (!mPolicy.allowAppAnimationsLw()) {
9579 animLp = null;
9580 }
9581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009582 NN = mOpeningApps.size();
9583 for (i=0; i<NN; i++) {
9584 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009585 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 "Now opening app" + wtoken);
9587 wtoken.reportedVisible = false;
9588 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009589 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009590 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009591 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009592 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 wtoken.showAllWindowsLocked();
9594 }
9595 NN = mClosingApps.size();
9596 for (i=0; i<NN; i++) {
9597 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009598 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009599 "Now closing app" + wtoken);
9600 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009601 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009602 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009604 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 // Force the allDrawn flag, because we want to start
9606 // this guy's animations regardless of whether it's
9607 // gotten drawn.
9608 wtoken.allDrawn = true;
9609 }
9610
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009611 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009613 mOpeningApps.clear();
9614 mClosingApps.clear();
9615
9616 // This has changed the visibility of windows, so perform
9617 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009618 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009619 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009620 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9621 assignLayersLocked();
9622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009623 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009624 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009625 }
9626 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009627
Dianne Hackborn16064f92010-03-25 00:47:24 -07009628 int adjResult = 0;
9629
Dianne Hackborna8f60182009-09-01 19:01:50 -07009630 if (!animating && mAppTransitionRunning) {
9631 // We have finished the animation of an app transition. To do
9632 // this, we have delayed a lot of operations like showing and
9633 // hiding apps, moving apps in Z-order, etc. The app token list
9634 // reflects the correct Z-order, but the window list may now
9635 // be out of sync with it. So here we will just rebuild the
9636 // entire app window list. Fun!
9637 mAppTransitionRunning = false;
9638 // Clear information about apps that were moving.
9639 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009640
Dianne Hackborna8f60182009-09-01 19:01:50 -07009641 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009642 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009643 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009644 moveInputMethodWindowsIfNeededLocked(false);
9645 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009646 // Since the window list has been rebuilt, focus might
9647 // have to be recomputed since the actual order of windows
9648 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009649 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009650 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009651
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009652 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009653 // At this point, there was a window with a wallpaper that
9654 // was force hiding other windows behind it, but now it
9655 // is going away. This may be simple -- just animate
9656 // away the wallpaper and its window -- or it may be
9657 // hard -- the wallpaper now needs to be shown behind
9658 // something that was hidden.
9659 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009660 if (mLowerWallpaperTarget != null
9661 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009662 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009663 "wallpaperForceHiding changed with lower="
9664 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009665 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009666 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9667 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9668 if (mLowerWallpaperTarget.mAppToken.hidden) {
9669 // The lower target has become hidden before we
9670 // actually started the animation... let's completely
9671 // re-evaluate everything.
9672 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009673 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009674 }
9675 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009676 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009677 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009678 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009679 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009680 + " NEW: " + mWallpaperTarget
9681 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009682 if (mLowerWallpaperTarget == null) {
9683 // Whoops, we don't need a special wallpaper animation.
9684 // Clear them out.
9685 forceHiding = false;
9686 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009687 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009688 if (w.mSurface != null) {
9689 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009690 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009691 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009692 forceHiding = true;
9693 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9694 if (!w.mAnimating) {
9695 // We set the animation above so it
9696 // is not yet running.
9697 w.clearAnimation();
9698 }
9699 }
9700 }
9701 }
9702 }
9703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009704
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009705 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009706 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009707 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009708 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009710
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009711 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009712 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009713 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009714 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009715 assignLayersLocked();
9716 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009717 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009718 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009719 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009721
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009722 if (mFocusMayChange) {
9723 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009724 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009725 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009726 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009727 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009728 }
9729
9730 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009731 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009732 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009733
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009734 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9735 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009736
Jeff Browne33348b2010-07-15 23:54:05 -07009737 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009738 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739
9740 // THIRD LOOP: Update the surfaces of all windows.
9741
9742 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9743
9744 boolean obscured = false;
9745 boolean blurring = false;
9746 boolean dimming = false;
9747 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009748 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009749 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009750
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009751 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009754 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755
9756 boolean displayed = false;
9757 final WindowManager.LayoutParams attrs = w.mAttrs;
9758 final int attrFlags = attrs.flags;
9759
9760 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009761 // XXX NOTE: The logic here could be improved. We have
9762 // the decision about whether to resize a window separated
9763 // from whether to hide the surface. This can cause us to
9764 // resize a surface even if we are going to hide it. You
9765 // can see this by (1) holding device in landscape mode on
9766 // home screen; (2) tapping browser icon (device will rotate
9767 // to landscape; (3) tap home. The wallpaper will be resized
9768 // in step 2 but then immediately hidden, causing us to
9769 // have to resize and then redraw it again in step 3. It
9770 // would be nice to figure out how to avoid this, but it is
9771 // difficult because we do need to resize surfaces in some
9772 // cases while they are hidden such as when first showing a
9773 // window.
9774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009776 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009777 TAG, "Placing surface #" + i + " " + w.mSurface
9778 + ": new=" + w.mShownFrame + ", old="
9779 + w.mLastShownFrame);
9780
9781 boolean resize;
9782 int width, height;
9783 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9784 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9785 w.mLastRequestedHeight != w.mRequestedHeight;
9786 // for a scaled surface, we just want to use
9787 // the requested size.
9788 width = w.mRequestedWidth;
9789 height = w.mRequestedHeight;
9790 w.mLastRequestedWidth = width;
9791 w.mLastRequestedHeight = height;
9792 w.mLastShownFrame.set(w.mShownFrame);
9793 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009794 if (SHOW_TRANSACTIONS) logSurface(w,
9795 "POS " + w.mShownFrame.left
9796 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009797 w.mSurfaceX = w.mShownFrame.left;
9798 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009799 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9800 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009801 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009802 if (!recoveringMemory) {
9803 reclaimSomeSurfaceMemoryLocked(w, "position");
9804 }
9805 }
9806 } else {
9807 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9808 width = w.mShownFrame.width();
9809 height = w.mShownFrame.height();
9810 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811 }
9812
9813 if (resize) {
9814 if (width < 1) width = 1;
9815 if (height < 1) height = 1;
9816 if (w.mSurface != null) {
9817 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009818 if (SHOW_TRANSACTIONS) logSurface(w,
9819 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009820 + w.mShownFrame.top + " SIZE "
9821 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009822 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009823 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009824 w.mSurfaceW = width;
9825 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009827 w.mSurfaceX = w.mShownFrame.left;
9828 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 w.mSurface.setPosition(w.mShownFrame.left,
9830 w.mShownFrame.top);
9831 } catch (RuntimeException e) {
9832 // If something goes wrong with the surface (such
9833 // as running out of memory), don't take down the
9834 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009835 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009836 + "size=(" + width + "x" + height
9837 + "), pos=(" + w.mShownFrame.left
9838 + "," + w.mShownFrame.top + ")", e);
9839 if (!recoveringMemory) {
9840 reclaimSomeSurfaceMemoryLocked(w, "size");
9841 }
9842 }
9843 }
9844 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009845 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 w.mContentInsetsChanged =
9847 !w.mLastContentInsets.equals(w.mContentInsets);
9848 w.mVisibleInsetsChanged =
9849 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009850 boolean configChanged =
9851 w.mConfiguration != mCurConfiguration
9852 && (w.mConfiguration == null
9853 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009854 if (DEBUG_CONFIGURATION && configChanged) {
9855 Slog.v(TAG, "Win " + w + " config changed: "
9856 + mCurConfiguration);
9857 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009858 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009859 + ": configChanged=" + configChanged
9860 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009861 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009862 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009863 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009864 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009865 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009866 w.mLastFrame.set(w.mFrame);
9867 w.mLastContentInsets.set(w.mContentInsets);
9868 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009869 // If the screen is currently frozen, then keep
9870 // it frozen until this window draws at its new
9871 // orientation.
9872 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009873 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009874 "Resizing while display frozen: " + w);
9875 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009876 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009877 mWindowsFreezingScreen = true;
9878 // XXX should probably keep timeout from
9879 // when we first froze the display.
9880 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9881 mH.sendMessageDelayed(mH.obtainMessage(
9882 H.WINDOW_FREEZE_TIMEOUT), 2000);
9883 }
9884 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009885 // If the orientation is changing, then we need to
9886 // hold off on unfreezing the display until this
9887 // window has been redrawn; to do that, we need
9888 // to go through the process of getting informed
9889 // by the application when it has finished drawing.
9890 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009891 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 "Orientation start waiting for draw in "
9893 + w + ", surface " + w.mSurface);
9894 w.mDrawPending = true;
9895 w.mCommitDrawPending = false;
9896 w.mReadyToShow = false;
9897 if (w.mAppToken != null) {
9898 w.mAppToken.allDrawn = false;
9899 }
9900 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009901 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009902 "Resizing window " + w + " to " + w.mFrame);
9903 mResizingWindows.add(w);
9904 } else if (w.mOrientationChanging) {
9905 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009906 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009907 "Orientation not waiting for draw in "
9908 + w + ", surface " + w.mSurface);
9909 w.mOrientationChanging = false;
9910 }
9911 }
9912 }
9913
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009914 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 if (!w.mLastHidden) {
9916 //dump();
9917 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009918 if (SHOW_TRANSACTIONS) logSurface(w,
9919 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009920 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009921 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 try {
9923 w.mSurface.hide();
9924 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009925 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926 }
9927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009928 }
9929 // If we are waiting for this window to handle an
9930 // orientation change, well, it is hidden, so
9931 // doesn't really matter. Note that this does
9932 // introduce a potential glitch if the window
9933 // becomes unhidden before it has drawn for the
9934 // new orientation.
9935 if (w.mOrientationChanging) {
9936 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009937 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009938 "Orientation change skips hidden " + w);
9939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 } else if (w.mLastLayer != w.mAnimLayer
9941 || w.mLastAlpha != w.mShownAlpha
9942 || w.mLastDsDx != w.mDsDx
9943 || w.mLastDtDx != w.mDtDx
9944 || w.mLastDsDy != w.mDsDy
9945 || w.mLastDtDy != w.mDtDy
9946 || w.mLastHScale != w.mHScale
9947 || w.mLastVScale != w.mVScale
9948 || w.mLastHidden) {
9949 displayed = true;
9950 w.mLastAlpha = w.mShownAlpha;
9951 w.mLastLayer = w.mAnimLayer;
9952 w.mLastDsDx = w.mDsDx;
9953 w.mLastDtDx = w.mDtDx;
9954 w.mLastDsDy = w.mDsDy;
9955 w.mLastDtDy = w.mDtDy;
9956 w.mLastHScale = w.mHScale;
9957 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009958 if (SHOW_TRANSACTIONS) logSurface(w,
9959 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009960 + " matrix=[" + (w.mDsDx*w.mHScale)
9961 + "," + (w.mDtDx*w.mVScale)
9962 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009963 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 if (w.mSurface != null) {
9965 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009966 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009967 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009968 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009969 w.mSurface.setLayer(w.mAnimLayer);
9970 w.mSurface.setMatrix(
9971 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9972 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9973 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009974 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009975 if (!recoveringMemory) {
9976 reclaimSomeSurfaceMemoryLocked(w, "update");
9977 }
9978 }
9979 }
9980
9981 if (w.mLastHidden && !w.mDrawPending
9982 && !w.mCommitDrawPending
9983 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009984 if (SHOW_TRANSACTIONS) logSurface(w,
9985 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009986 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009987 + " during relayout");
9988 if (showSurfaceRobustlyLocked(w)) {
9989 w.mHasDrawn = true;
9990 w.mLastHidden = false;
9991 } else {
9992 w.mOrientationChanging = false;
9993 }
9994 }
9995 if (w.mSurface != null) {
9996 w.mToken.hasVisible = true;
9997 }
9998 } else {
9999 displayed = true;
10000 }
10001
10002 if (displayed) {
10003 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -080010004 if (attrs.width == LayoutParams.MATCH_PARENT
10005 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 covered = true;
10007 }
10008 }
10009 if (w.mOrientationChanging) {
10010 if (w.mDrawPending || w.mCommitDrawPending) {
10011 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010012 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 "Orientation continue waiting for draw in " + w);
10014 } else {
10015 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010016 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010017 "Orientation change complete in " + w);
10018 }
10019 }
10020 w.mToken.hasVisible = true;
10021 }
10022 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010023 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 "Orientation change skips hidden " + w);
10025 w.mOrientationChanging = false;
10026 }
10027
10028 final boolean canBeSeen = w.isDisplayedLw();
10029
10030 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10031 focusDisplayed = true;
10032 }
10033
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010034 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010037 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010038 if (w.mSurface != null) {
10039 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10040 holdScreen = w.mSession;
10041 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010042 if (!syswin && w.mAttrs.screenBrightness >= 0
10043 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010044 screenBrightness = w.mAttrs.screenBrightness;
10045 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010046 if (!syswin && w.mAttrs.buttonBrightness >= 0
10047 && buttonBrightness < 0) {
10048 buttonBrightness = w.mAttrs.buttonBrightness;
10049 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010050 if (canBeSeen
10051 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10052 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10053 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010054 syswin = true;
10055 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010056 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010057
Dianne Hackborn25994b42009-09-04 14:21:19 -070010058 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10059 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010060 // This window completely covers everything behind it,
10061 // so we want to leave all of them as unblurred (for
10062 // performance reasons).
10063 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010064 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010065 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010066 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010067 obscured = true;
10068 if (mBackgroundFillerSurface == null) {
10069 try {
10070 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010071 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010072 0, dw, dh,
10073 PixelFormat.OPAQUE,
10074 Surface.FX_SURFACE_NORMAL);
10075 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010076 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010077 }
10078 }
10079 try {
10080 mBackgroundFillerSurface.setPosition(0, 0);
10081 mBackgroundFillerSurface.setSize(dw, dh);
10082 // Using the same layer as Dim because they will never be shown at the
10083 // same time.
10084 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10085 mBackgroundFillerSurface.show();
10086 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010087 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010088 }
10089 backgroundFillerShown = true;
10090 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010091 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010092 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010093 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010094 + ": blurring=" + blurring
10095 + " obscured=" + obscured
10096 + " displayed=" + displayed);
10097 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10098 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010099 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010100 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010101 if (mDimAnimator == null) {
10102 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010104 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010105 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 }
10108 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10109 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010110 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010111 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010113 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010114 + mBlurSurface + ": CREATE");
10115 try {
Romain Guy06882f82009-06-10 13:36:04 -070010116 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010117 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 -1, 16, 16,
10119 PixelFormat.OPAQUE,
10120 Surface.FX_SURFACE_BLUR);
10121 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010122 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 }
10124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010125 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010126 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10127 + mBlurSurface + ": pos=(0,0) (" +
10128 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010129 mBlurSurface.setPosition(0, 0);
10130 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010131 mBlurSurface.setLayer(w.mAnimLayer-2);
10132 if (!mBlurShown) {
10133 try {
10134 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10135 + mBlurSurface + ": SHOW");
10136 mBlurSurface.show();
10137 } catch (RuntimeException e) {
10138 Slog.w(TAG, "Failure showing blur surface", e);
10139 }
10140 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010141 }
10142 }
10143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010144 }
10145 }
10146 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010147
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010148 if (obscuredChanged && mWallpaperTarget == w) {
10149 // This is the wallpaper target and its obscured state
10150 // changed... make sure the current wallaper's visibility
10151 // has been updated accordingly.
10152 updateWallpaperVisibilityLocked();
10153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010155
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010156 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10157 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010158 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010159 try {
10160 mBackgroundFillerSurface.hide();
10161 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010162 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010163 }
10164 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010165
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010166 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010167 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10168 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010169 }
Romain Guy06882f82009-06-10 13:36:04 -070010170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010171 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010172 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010173 + ": HIDE");
10174 try {
10175 mBlurSurface.hide();
10176 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010177 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010178 }
10179 mBlurShown = false;
10180 }
10181
Joe Onorato8a9b2202010-02-26 18:56:32 -080010182 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010183 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010184 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010185 }
10186
Jeff Browne33348b2010-07-15 23:54:05 -070010187 mInputMonitor.updateInputWindowsLw();
10188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010190
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010191 if (mWatermark != null) {
10192 mWatermark.drawIfNeeded();
10193 }
10194
Joe Onorato8a9b2202010-02-26 18:56:32 -080010195 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010196 "With display frozen, orientationChangeComplete="
10197 + orientationChangeComplete);
10198 if (orientationChangeComplete) {
10199 if (mWindowsFreezingScreen) {
10200 mWindowsFreezingScreen = false;
10201 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10202 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010203 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010204 }
Romain Guy06882f82009-06-10 13:36:04 -070010205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010206 i = mResizingWindows.size();
10207 if (i > 0) {
10208 do {
10209 i--;
10210 WindowState win = mResizingWindows.get(i);
10211 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010212 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10213 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010214 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010215 boolean configChanged =
10216 win.mConfiguration != mCurConfiguration
10217 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010218 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10219 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10220 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010221 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010222 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010223 + " / " + mCurConfiguration + " / 0x"
10224 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010225 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010226 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010227 win.mClient.resized(win.mFrame.width(),
10228 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010229 win.mLastVisibleInsets, win.mDrawPending,
10230 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010231 win.mContentInsetsChanged = false;
10232 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010233 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010234 } catch (RemoteException e) {
10235 win.mOrientationChanging = false;
10236 }
10237 } while (i > 0);
10238 mResizingWindows.clear();
10239 }
Romain Guy06882f82009-06-10 13:36:04 -070010240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010241 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010242 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010243 i = mDestroySurface.size();
10244 if (i > 0) {
10245 do {
10246 i--;
10247 WindowState win = mDestroySurface.get(i);
10248 win.mDestroying = false;
10249 if (mInputMethodWindow == win) {
10250 mInputMethodWindow = null;
10251 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010252 if (win == mWallpaperTarget) {
10253 wallpaperDestroyed = true;
10254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010255 win.destroySurfaceLocked();
10256 } while (i > 0);
10257 mDestroySurface.clear();
10258 }
10259
10260 // Time to remove any exiting tokens?
10261 for (i=mExitingTokens.size()-1; i>=0; i--) {
10262 WindowToken token = mExitingTokens.get(i);
10263 if (!token.hasVisible) {
10264 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010265 if (token.windowType == TYPE_WALLPAPER) {
10266 mWallpaperTokens.remove(token);
10267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010268 }
10269 }
10270
10271 // Time to remove any exiting applications?
10272 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10273 AppWindowToken token = mExitingAppTokens.get(i);
10274 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010275 // Make sure there is no animation running on this token,
10276 // so any windows associated with it will be removed as
10277 // soon as their animations are complete
10278 token.animation = null;
10279 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 mAppTokens.remove(token);
10281 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010282 if (mLastEnterAnimToken == token) {
10283 mLastEnterAnimToken = null;
10284 mLastEnterAnimParams = null;
10285 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010286 }
10287 }
10288
Dianne Hackborna8f60182009-09-01 19:01:50 -070010289 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010290
Dianne Hackborna8f60182009-09-01 19:01:50 -070010291 if (!animating && mAppTransitionRunning) {
10292 // We have finished the animation of an app transition. To do
10293 // this, we have delayed a lot of operations like showing and
10294 // hiding apps, moving apps in Z-order, etc. The app token list
10295 // reflects the correct Z-order, but the window list may now
10296 // be out of sync with it. So here we will just rebuild the
10297 // entire app window list. Fun!
10298 mAppTransitionRunning = false;
10299 needRelayout = true;
10300 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010301 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010302 // Clear information about apps that were moving.
10303 mToBottomApps.clear();
10304 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 if (focusDisplayed) {
10307 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10308 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010309 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010310 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010311 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010312 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010313 requestAnimationLocked(0);
10314 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010315 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10316 }
Jeff Browneb857f12010-07-16 10:06:33 -070010317
Jeff Browne33348b2010-07-15 23:54:05 -070010318 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010319
Jeff Brown8e03b752010-06-13 19:16:55 -070010320 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010321 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10322 mPowerManager.setScreenBrightnessOverride(-1);
10323 } else {
10324 mPowerManager.setScreenBrightnessOverride((int)
10325 (screenBrightness * Power.BRIGHTNESS_ON));
10326 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010327 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10328 mPowerManager.setButtonBrightnessOverride(-1);
10329 } else {
10330 mPowerManager.setButtonBrightnessOverride((int)
10331 (buttonBrightness * Power.BRIGHTNESS_ON));
10332 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010333 if (holdScreen != mHoldingScreenOn) {
10334 mHoldingScreenOn = holdScreen;
10335 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10336 mH.sendMessage(m);
10337 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010338
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010339 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010340 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010341 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10342 LocalPowerManager.BUTTON_EVENT, true);
10343 mTurnOnScreen = false;
10344 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010345
10346 // Check to see if we are now in a state where the screen should
10347 // be enabled, because the window obscured flags have changed.
10348 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010349 }
Jeff Brown46b9ac02010-04-22 18:58:52 -070010350
10351 /**
10352 * Must be called with the main window manager lock held.
10353 */
10354 void setHoldScreenLocked(boolean holding) {
10355 boolean state = mHoldingScreenWakeLock.isHeld();
10356 if (holding != state) {
10357 if (holding) {
10358 mHoldingScreenWakeLock.acquire();
10359 } else {
10360 mPolicy.screenOnStoppedLw();
10361 mHoldingScreenWakeLock.release();
10362 }
10363 }
10364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010365
10366 void requestAnimationLocked(long delay) {
10367 if (!mAnimationPending) {
10368 mAnimationPending = true;
10369 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10370 }
10371 }
Romain Guy06882f82009-06-10 13:36:04 -070010372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 /**
10374 * Have the surface flinger show a surface, robustly dealing with
10375 * error conditions. In particular, if there is not enough memory
10376 * to show the surface, then we will try to get rid of other surfaces
10377 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010378 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010379 * @return Returns true if the surface was successfully shown.
10380 */
10381 boolean showSurfaceRobustlyLocked(WindowState win) {
10382 try {
10383 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010384 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010386 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010387 if (DEBUG_VISIBILITY) Slog.v(TAG,
10388 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010389 win.mTurnOnScreen = false;
10390 mTurnOnScreen = true;
10391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010392 }
10393 return true;
10394 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010395 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010396 }
Romain Guy06882f82009-06-10 13:36:04 -070010397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010400 return false;
10401 }
Romain Guy06882f82009-06-10 13:36:04 -070010402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010403 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10404 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010405
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010406 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010409 if (mForceRemoves == null) {
10410 mForceRemoves = new ArrayList<WindowState>();
10411 }
Romain Guy06882f82009-06-10 13:36:04 -070010412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010413 long callingIdentity = Binder.clearCallingIdentity();
10414 try {
10415 // There was some problem... first, do a sanity check of the
10416 // window list to make sure we haven't left any dangling surfaces
10417 // around.
10418 int N = mWindows.size();
10419 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010420 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010422 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010423 if (ws.mSurface != null) {
10424 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010425 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010426 + ws + " surface=" + ws.mSurface
10427 + " token=" + win.mToken
10428 + " pid=" + ws.mSession.mPid
10429 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010430 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010431 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010432 ws.mSurface = null;
10433 mForceRemoves.add(ws);
10434 i--;
10435 N--;
10436 leakedSurface = true;
10437 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010438 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010439 + ws + " surface=" + ws.mSurface
10440 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010441 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010442 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010443 ws.mSurface = null;
10444 leakedSurface = true;
10445 }
10446 }
10447 }
Romain Guy06882f82009-06-10 13:36:04 -070010448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010449 boolean killedApps = false;
10450 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010451 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010452 SparseIntArray pidCandidates = new SparseIntArray();
10453 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010454 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 if (ws.mSurface != null) {
10456 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10457 }
10458 }
10459 if (pidCandidates.size() > 0) {
10460 int[] pids = new int[pidCandidates.size()];
10461 for (int i=0; i<pids.length; i++) {
10462 pids[i] = pidCandidates.keyAt(i);
10463 }
10464 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010465 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 killedApps = true;
10467 }
10468 } catch (RemoteException e) {
10469 }
10470 }
10471 }
Romain Guy06882f82009-06-10 13:36:04 -070010472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010473 if (leakedSurface || killedApps) {
10474 // We managed to reclaim some memory, so get rid of the trouble
10475 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010476 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010477 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010478 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010479 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010480 win.mSurface = null;
10481 }
Romain Guy06882f82009-06-10 13:36:04 -070010482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010483 try {
10484 win.mClient.dispatchGetNewSurface();
10485 } catch (RemoteException e) {
10486 }
10487 }
10488 } finally {
10489 Binder.restoreCallingIdentity(callingIdentity);
10490 }
10491 }
Romain Guy06882f82009-06-10 13:36:04 -070010492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010493 private boolean updateFocusedWindowLocked(int mode) {
10494 WindowState newFocus = computeFocusedWindowLocked();
10495 if (mCurrentFocus != newFocus) {
10496 // This check makes sure that we don't already have the focus
10497 // change message pending.
10498 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10499 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010500 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010501 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10502 final WindowState oldFocus = mCurrentFocus;
10503 mCurrentFocus = newFocus;
10504 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010506 final WindowState imWindow = mInputMethodWindow;
10507 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010508 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010509 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010510 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10511 mLayoutNeeded = true;
10512 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010513 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10514 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010515 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10516 // Client will do the layout, but we need to assign layers
10517 // for handleNewWindowLocked() below.
10518 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010519 }
10520 }
Jeff Brown349703e2010-06-22 01:27:15 -070010521
10522 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10523 // If we defer assigning layers, then the caller is responsible for
10524 // doing this part.
10525 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010527 return true;
10528 }
10529 return false;
10530 }
Jeff Brown349703e2010-06-22 01:27:15 -070010531
10532 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010533 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010535
10536 private WindowState computeFocusedWindowLocked() {
10537 WindowState result = null;
10538 WindowState win;
10539
10540 int i = mWindows.size() - 1;
10541 int nextAppIndex = mAppTokens.size()-1;
10542 WindowToken nextApp = nextAppIndex >= 0
10543 ? mAppTokens.get(nextAppIndex) : null;
10544
10545 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010546 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010547
Joe Onorato8a9b2202010-02-26 18:56:32 -080010548 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010549 TAG, "Looking for focus: " + i
10550 + " = " + win
10551 + ", flags=" + win.mAttrs.flags
10552 + ", canReceive=" + win.canReceiveKeys());
10553
10554 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010556 // If this window's application has been removed, just skip it.
10557 if (thisApp != null && thisApp.removed) {
10558 i--;
10559 continue;
10560 }
Romain Guy06882f82009-06-10 13:36:04 -070010561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010562 // If there is a focused app, don't allow focus to go to any
10563 // windows below it. If this is an application window, step
10564 // through the app tokens until we find its app.
10565 if (thisApp != null && nextApp != null && thisApp != nextApp
10566 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10567 int origAppIndex = nextAppIndex;
10568 while (nextAppIndex > 0) {
10569 if (nextApp == mFocusedApp) {
10570 // Whoops, we are below the focused app... no focus
10571 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010572 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010573 TAG, "Reached focused app: " + mFocusedApp);
10574 return null;
10575 }
10576 nextAppIndex--;
10577 nextApp = mAppTokens.get(nextAppIndex);
10578 if (nextApp == thisApp) {
10579 break;
10580 }
10581 }
10582 if (thisApp != nextApp) {
10583 // Uh oh, the app token doesn't exist! This shouldn't
10584 // happen, but if it does we can get totally hosed...
10585 // so restart at the original app.
10586 nextAppIndex = origAppIndex;
10587 nextApp = mAppTokens.get(nextAppIndex);
10588 }
10589 }
10590
10591 // Dispatch to this window if it is wants key events.
10592 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010593 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010594 TAG, "Found focus @ " + i + " = " + win);
10595 result = win;
10596 break;
10597 }
10598
10599 i--;
10600 }
10601
10602 return result;
10603 }
10604
10605 private void startFreezingDisplayLocked() {
10606 if (mDisplayFrozen) {
10607 return;
10608 }
Romain Guy06882f82009-06-10 13:36:04 -070010609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010610 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010612 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010613 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010614 if (mFreezeGcPending != 0) {
10615 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010616 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010617 mH.removeMessages(H.FORCE_GC);
10618 Runtime.getRuntime().gc();
10619 mFreezeGcPending = now;
10620 }
10621 } else {
10622 mFreezeGcPending = now;
10623 }
Romain Guy06882f82009-06-10 13:36:04 -070010624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010625 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010626
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010627 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010628
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010629 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10630 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010631 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010632 mAppTransitionReady = true;
10633 }
Romain Guy06882f82009-06-10 13:36:04 -070010634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010635 if (PROFILE_ORIENTATION) {
10636 File file = new File("/data/system/frozen");
10637 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10638 }
10639 Surface.freezeDisplay(0);
10640 }
Romain Guy06882f82009-06-10 13:36:04 -070010641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010642 private void stopFreezingDisplayLocked() {
10643 if (!mDisplayFrozen) {
10644 return;
10645 }
Romain Guy06882f82009-06-10 13:36:04 -070010646
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010647 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10648 return;
10649 }
10650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010651 mDisplayFrozen = false;
10652 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10653 if (PROFILE_ORIENTATION) {
10654 Debug.stopMethodTracing();
10655 }
10656 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010657
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010658 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010659
Christopher Tateb696aee2010-04-02 19:08:30 -070010660 // While the display is frozen we don't re-compute the orientation
10661 // to avoid inconsistent states. However, something interesting
10662 // could have actually changed during that time so re-evaluate it
10663 // now to catch that.
10664 if (updateOrientationFromAppTokensLocked()) {
10665 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10666 }
10667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010668 // A little kludge: a lot could have happened while the
10669 // display was frozen, so now that we are coming back we
10670 // do a gc so that any remote references the system
10671 // processes holds on others can be released if they are
10672 // no longer needed.
10673 mH.removeMessages(H.FORCE_GC);
10674 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10675 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010677 mScreenFrozenLock.release();
10678 }
Romain Guy06882f82009-06-10 13:36:04 -070010679
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010680 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10681 DisplayMetrics dm) {
10682 if (index < tokens.length) {
10683 String str = tokens[index];
10684 if (str != null && str.length() > 0) {
10685 try {
10686 int val = Integer.parseInt(str);
10687 return val;
10688 } catch (Exception e) {
10689 }
10690 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010691 }
10692 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10693 return defDps;
10694 }
10695 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10696 return val;
10697 }
10698
10699 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010700 final String[] mTokens;
10701 final String mText;
10702 final Paint mTextPaint;
10703 final int mTextWidth;
10704 final int mTextHeight;
10705 final int mTextAscent;
10706 final int mTextDescent;
10707 final int mDeltaX;
10708 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010709
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010710 Surface mSurface;
10711 int mLastDW;
10712 int mLastDH;
10713 boolean mDrawNeeded;
10714
10715 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010716 final DisplayMetrics dm = new DisplayMetrics();
10717 mDisplay.getMetrics(dm);
10718
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010719 if (false) {
10720 Log.i(TAG, "*********************** WATERMARK");
10721 for (int i=0; i<tokens.length; i++) {
10722 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10723 }
10724 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010725
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010726 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010727
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010728 StringBuilder builder = new StringBuilder(32);
10729 int len = mTokens[0].length();
10730 len = len & ~1;
10731 for (int i=0; i<len; i+=2) {
10732 int c1 = mTokens[0].charAt(i);
10733 int c2 = mTokens[0].charAt(i+1);
10734 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10735 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10736 else c1 -= '0';
10737 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10738 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10739 else c2 -= '0';
10740 builder.append((char)(255-((c1*16)+c2)));
10741 }
10742 mText = builder.toString();
10743 if (false) {
10744 Log.i(TAG, "Final text: " + mText);
10745 }
10746
10747 int fontSize = getPropertyInt(tokens, 1,
10748 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10749
10750 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10751 mTextPaint.setTextSize(fontSize);
10752 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10753
10754 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10755 mTextWidth = (int)mTextPaint.measureText(mText);
10756 mTextAscent = fm.ascent;
10757 mTextDescent = fm.descent;
10758 mTextHeight = fm.descent - fm.ascent;
10759
10760 mDeltaX = getPropertyInt(tokens, 2,
10761 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10762 mDeltaY = getPropertyInt(tokens, 3,
10763 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10764 int shadowColor = getPropertyInt(tokens, 4,
10765 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10766 int color = getPropertyInt(tokens, 5,
10767 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10768 int shadowRadius = getPropertyInt(tokens, 6,
10769 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10770 int shadowDx = getPropertyInt(tokens, 8,
10771 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10772 int shadowDy = getPropertyInt(tokens, 9,
10773 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10774
10775 mTextPaint.setColor(color);
10776 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010777
10778 try {
10779 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010780 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010781 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010782 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010783 mSurface.show();
10784 } catch (OutOfResourcesException e) {
10785 }
10786 }
10787
10788 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010789 if (mLastDW != dw || mLastDH != dh) {
10790 mLastDW = dw;
10791 mLastDH = dh;
10792 mSurface.setSize(dw, dh);
10793 mDrawNeeded = true;
10794 }
10795 }
10796
10797 void drawIfNeeded() {
10798 if (mDrawNeeded) {
10799 final int dw = mLastDW;
10800 final int dh = mLastDH;
10801
10802 mDrawNeeded = false;
10803 Rect dirty = new Rect(0, 0, dw, dh);
10804 Canvas c = null;
10805 try {
10806 c = mSurface.lockCanvas(dirty);
10807 } catch (IllegalArgumentException e) {
10808 } catch (OutOfResourcesException e) {
10809 }
10810 if (c != null) {
10811 int deltaX = mDeltaX;
10812 int deltaY = mDeltaY;
10813
10814 // deltaX shouldn't be close to a round fraction of our
10815 // x step, or else things will line up too much.
10816 int div = (dw+mTextWidth)/deltaX;
10817 int rem = (dw+mTextWidth) - (div*deltaX);
10818 int qdelta = deltaX/4;
10819 if (rem < qdelta || rem > (deltaX-qdelta)) {
10820 deltaX += deltaX/3;
10821 }
10822
10823 int y = -mTextHeight;
10824 int x = -mTextWidth;
10825 while (y < (dh+mTextHeight)) {
10826 c.drawText(mText, x, y, mTextPaint);
10827 x += deltaX;
10828 if (x >= dw) {
10829 x -= (dw+mTextWidth);
10830 y += deltaY;
10831 }
10832 }
10833 mSurface.unlockCanvasAndPost(c);
10834 }
10835 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010836 }
10837 }
10838
10839 void createWatermark() {
10840 if (mWatermark != null) {
10841 return;
10842 }
10843
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010844 File file = new File("/system/etc/setup.conf");
10845 FileInputStream in = null;
10846 try {
10847 in = new FileInputStream(file);
10848 DataInputStream ind = new DataInputStream(in);
10849 String line = ind.readLine();
10850 if (line != null) {
10851 String[] toks = line.split("%");
10852 if (toks != null && toks.length > 0) {
10853 mWatermark = new Watermark(mFxSession, toks);
10854 }
10855 }
10856 } catch (FileNotFoundException e) {
10857 } catch (IOException e) {
10858 } finally {
10859 if (in != null) {
10860 try {
10861 in.close();
10862 } catch (IOException e) {
10863 }
10864 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010865 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010866 }
10867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010868 @Override
10869 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10870 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10871 != PackageManager.PERMISSION_GRANTED) {
10872 pw.println("Permission Denial: can't dump WindowManager from from pid="
10873 + Binder.getCallingPid()
10874 + ", uid=" + Binder.getCallingUid());
10875 return;
10876 }
Romain Guy06882f82009-06-10 13:36:04 -070010877
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010878 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010879 pw.println(" ");
10880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010881 synchronized(mWindowMap) {
10882 pw.println("Current Window Manager state:");
10883 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010884 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010885 pw.print(" Window #"); pw.print(i); pw.print(' ');
10886 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010887 w.dump(pw, " ");
10888 }
10889 if (mInputMethodDialogs.size() > 0) {
10890 pw.println(" ");
10891 pw.println(" Input method dialogs:");
10892 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10893 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010894 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010895 }
10896 }
10897 if (mPendingRemove.size() > 0) {
10898 pw.println(" ");
10899 pw.println(" Remove pending for:");
10900 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10901 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010902 pw.print(" Remove #"); 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 (mForceRemoves != null && mForceRemoves.size() > 0) {
10908 pw.println(" ");
10909 pw.println(" Windows force removing:");
10910 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10911 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010912 pw.print(" Removing #"); 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 }
10917 if (mDestroySurface.size() > 0) {
10918 pw.println(" ");
10919 pw.println(" Windows waiting to destroy their surface:");
10920 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10921 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010922 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10923 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010924 w.dump(pw, " ");
10925 }
10926 }
10927 if (mLosingFocus.size() > 0) {
10928 pw.println(" ");
10929 pw.println(" Windows losing focus:");
10930 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10931 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010932 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10933 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010934 w.dump(pw, " ");
10935 }
10936 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010937 if (mResizingWindows.size() > 0) {
10938 pw.println(" ");
10939 pw.println(" Windows waiting to resize:");
10940 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10941 WindowState w = mResizingWindows.get(i);
10942 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10943 pw.print(w); pw.println(":");
10944 w.dump(pw, " ");
10945 }
10946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010947 if (mSessions.size() > 0) {
10948 pw.println(" ");
10949 pw.println(" All active sessions:");
10950 Iterator<Session> it = mSessions.iterator();
10951 while (it.hasNext()) {
10952 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010953 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010954 s.dump(pw, " ");
10955 }
10956 }
10957 if (mTokenMap.size() > 0) {
10958 pw.println(" ");
10959 pw.println(" All tokens:");
10960 Iterator<WindowToken> it = mTokenMap.values().iterator();
10961 while (it.hasNext()) {
10962 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010963 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010964 token.dump(pw, " ");
10965 }
10966 }
10967 if (mTokenList.size() > 0) {
10968 pw.println(" ");
10969 pw.println(" Window token list:");
10970 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010971 pw.print(" #"); pw.print(i); pw.print(": ");
10972 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010973 }
10974 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010975 if (mWallpaperTokens.size() > 0) {
10976 pw.println(" ");
10977 pw.println(" Wallpaper tokens:");
10978 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10979 WindowToken token = mWallpaperTokens.get(i);
10980 pw.print(" Wallpaper #"); pw.print(i);
10981 pw.print(' '); pw.print(token); pw.println(':');
10982 token.dump(pw, " ");
10983 }
10984 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010985 if (mAppTokens.size() > 0) {
10986 pw.println(" ");
10987 pw.println(" Application tokens in Z order:");
10988 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010989 pw.print(" App #"); pw.print(i); pw.print(": ");
10990 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010991 }
10992 }
10993 if (mFinishedStarting.size() > 0) {
10994 pw.println(" ");
10995 pw.println(" Finishing start of application tokens:");
10996 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10997 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010998 pw.print(" Finished Starting #"); 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 if (mExitingTokens.size() > 0) {
11004 pw.println(" ");
11005 pw.println(" Exiting tokens:");
11006 for (int i=mExitingTokens.size()-1; i>=0; i--) {
11007 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011008 pw.print(" Exiting #"); pw.print(i);
11009 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011010 token.dump(pw, " ");
11011 }
11012 }
11013 if (mExitingAppTokens.size() > 0) {
11014 pw.println(" ");
11015 pw.println(" Exiting application tokens:");
11016 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11017 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011018 pw.print(" Exiting App #"); pw.print(i);
11019 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011020 token.dump(pw, " ");
11021 }
11022 }
11023 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011024 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11025 pw.print(" mLastFocus="); pw.println(mLastFocus);
11026 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11027 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11028 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011029 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011030 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11031 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11032 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11033 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011034 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11035 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11036 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011037 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11038 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11039 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11040 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011041 if (mDimAnimator != null) {
11042 mDimAnimator.printTo(pw);
11043 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011044 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011045 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011046 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011047 pw.print(mInputMethodAnimLayerAdjustment);
11048 pw.print(" mWallpaperAnimLayerAdjustment=");
11049 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011050 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11051 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011052 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11053 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011054 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11055 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011056 pw.print(" mRotation="); pw.print(mRotation);
11057 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11058 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11059 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11060 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11061 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11062 pw.print(" mNextAppTransition=0x");
11063 pw.print(Integer.toHexString(mNextAppTransition));
11064 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011065 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011066 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011067 if (mNextAppTransitionPackage != null) {
11068 pw.print(" mNextAppTransitionPackage=");
11069 pw.print(mNextAppTransitionPackage);
11070 pw.print(", mNextAppTransitionEnter=0x");
11071 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11072 pw.print(", mNextAppTransitionExit=0x");
11073 pw.print(Integer.toHexString(mNextAppTransitionExit));
11074 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011075 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11076 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011077 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11078 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11079 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11080 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011081 if (mOpeningApps.size() > 0) {
11082 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11083 }
11084 if (mClosingApps.size() > 0) {
11085 pw.print(" mClosingApps="); pw.println(mClosingApps);
11086 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011087 if (mToTopApps.size() > 0) {
11088 pw.print(" mToTopApps="); pw.println(mToTopApps);
11089 }
11090 if (mToBottomApps.size() > 0) {
11091 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11092 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011093 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11094 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011095 }
11096 }
11097
Jeff Brown349703e2010-06-22 01:27:15 -070011098 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011099 public void monitor() {
11100 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011101 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011103
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011104 /**
11105 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011106 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011107 */
11108 private static class DimAnimator {
11109 Surface mDimSurface;
11110 boolean mDimShown = false;
11111 float mDimCurrentAlpha;
11112 float mDimTargetAlpha;
11113 float mDimDeltaPerMs;
11114 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011115
11116 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011117
11118 DimAnimator (SurfaceSession session) {
11119 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011120 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011121 + mDimSurface + ": CREATE");
11122 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011123 mDimSurface = new Surface(session, 0,
11124 "DimSurface",
11125 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011126 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011127 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011128 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011129 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011130 }
11131 }
11132 }
11133
11134 /**
11135 * Show the dim surface.
11136 */
11137 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011138 if (!mDimShown) {
11139 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11140 dw + "x" + dh + ")");
11141 mDimShown = true;
11142 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011143 mLastDimWidth = dw;
11144 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011145 mDimSurface.setPosition(0, 0);
11146 mDimSurface.setSize(dw, dh);
11147 mDimSurface.show();
11148 } catch (RuntimeException e) {
11149 Slog.w(TAG, "Failure showing dim surface", e);
11150 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011151 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11152 mLastDimWidth = dw;
11153 mLastDimHeight = dh;
11154 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011155 }
11156 }
11157
11158 /**
11159 * Set's the dim surface's layer and update dim parameters that will be used in
11160 * {@link updateSurface} after all windows are examined.
11161 */
11162 void updateParameters(WindowState w, long currentTime) {
11163 mDimSurface.setLayer(w.mAnimLayer-1);
11164
11165 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011166 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011167 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011168 if (mDimTargetAlpha != target) {
11169 // If the desired dim level has changed, then
11170 // start an animation to it.
11171 mLastDimAnimTime = currentTime;
11172 long duration = (w.mAnimating && w.mAnimation != null)
11173 ? w.mAnimation.computeDurationHint()
11174 : DEFAULT_DIM_DURATION;
11175 if (target > mDimTargetAlpha) {
11176 // This is happening behind the activity UI,
11177 // so we can make it run a little longer to
11178 // give a stronger impression without disrupting
11179 // the user.
11180 duration *= DIM_DURATION_MULTIPLIER;
11181 }
11182 if (duration < 1) {
11183 // Don't divide by zero
11184 duration = 1;
11185 }
11186 mDimTargetAlpha = target;
11187 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11188 }
11189 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011190
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011191 /**
11192 * Updating the surface's alpha. Returns true if the animation continues, or returns
11193 * false when the animation is finished and the dim surface is hidden.
11194 */
11195 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11196 if (!dimming) {
11197 if (mDimTargetAlpha != 0) {
11198 mLastDimAnimTime = currentTime;
11199 mDimTargetAlpha = 0;
11200 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11201 }
11202 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011203
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011204 boolean animating = false;
11205 if (mLastDimAnimTime != 0) {
11206 mDimCurrentAlpha += mDimDeltaPerMs
11207 * (currentTime-mLastDimAnimTime);
11208 boolean more = true;
11209 if (displayFrozen) {
11210 // If the display is frozen, there is no reason to animate.
11211 more = false;
11212 } else if (mDimDeltaPerMs > 0) {
11213 if (mDimCurrentAlpha > mDimTargetAlpha) {
11214 more = false;
11215 }
11216 } else if (mDimDeltaPerMs < 0) {
11217 if (mDimCurrentAlpha < mDimTargetAlpha) {
11218 more = false;
11219 }
11220 } else {
11221 more = false;
11222 }
11223
11224 // Do we need to continue animating?
11225 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011226 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011227 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11228 mLastDimAnimTime = currentTime;
11229 mDimSurface.setAlpha(mDimCurrentAlpha);
11230 animating = true;
11231 } else {
11232 mDimCurrentAlpha = mDimTargetAlpha;
11233 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011234 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011235 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11236 mDimSurface.setAlpha(mDimCurrentAlpha);
11237 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011238 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011239 + ": HIDE");
11240 try {
11241 mDimSurface.hide();
11242 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011243 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011244 }
11245 mDimShown = false;
11246 }
11247 }
11248 }
11249 return animating;
11250 }
11251
11252 public void printTo(PrintWriter pw) {
11253 pw.print(" mDimShown="); pw.print(mDimShown);
11254 pw.print(" current="); pw.print(mDimCurrentAlpha);
11255 pw.print(" target="); pw.print(mDimTargetAlpha);
11256 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11257 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11258 }
11259 }
11260
11261 /**
11262 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11263 * This is used for opening/closing transition for apps in compatible mode.
11264 */
11265 private static class FadeInOutAnimation extends Animation {
11266 int mWidth;
11267 boolean mFadeIn;
11268
11269 public FadeInOutAnimation(boolean fadeIn) {
11270 setInterpolator(new AccelerateInterpolator());
11271 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11272 mFadeIn = fadeIn;
11273 }
11274
11275 @Override
11276 protected void applyTransformation(float interpolatedTime, Transformation t) {
11277 float x = interpolatedTime;
11278 if (!mFadeIn) {
11279 x = 1.0f - x; // reverse the interpolation for fade out
11280 }
11281 if (x < 0.5) {
11282 // move the window out of the screen.
11283 t.getMatrix().setTranslate(mWidth, 0);
11284 } else {
11285 t.getMatrix().setTranslate(0, 0);// show
11286 t.setAlpha((x - 0.5f) * 2);
11287 }
11288 }
11289
11290 @Override
11291 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11292 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11293 mWidth = width;
11294 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011295
11296 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011297 public int getZAdjustment() {
11298 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011299 }
11300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011301}