blob: e812fa927835932b871e98a7e37932cd439298b9 [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;
88import android.os.SystemClock;
89import android.os.SystemProperties;
90import android.os.TokenWatcher;
91import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070092import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070094import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080095import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070097import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -070099import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700101import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700163 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_APP_TRANSITIONS = false;
165 static final boolean DEBUG_STARTING_WINDOW = false;
166 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700167 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700168 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700170 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 static final boolean PROFILE_ORIENTATION = false;
173 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700174 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to multiply the policy's type layer, to reserve room
177 * for multiple windows of the same type and Z-ordering adjustment
178 * with TYPE_LAYER_OFFSET. */
179 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
182 * or below others in the same layer. */
183 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /** How much to increment the layer for each window, to reserve room
186 * for effect surfaces between them.
187 */
188 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /** The maximum length we will accept for a loaded animation duration:
191 * this is 10 seconds.
192 */
193 static final int MAX_ANIMATION_DURATION = 10*1000;
194
195 /** Amount of time (in milliseconds) to animate the dim surface from one
196 * value to another, when no window animation is driving it.
197 */
198 static final int DEFAULT_DIM_DURATION = 200;
199
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700200 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
201 * compatible windows.
202 */
203 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /** Adjustment to time to perform a dim, to make it more dramatic.
206 */
207 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700208
209 // Maximum number of milliseconds to wait for input event injection.
210 // FIXME is this value reasonable?
211 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700212
213 // Default input dispatching timeout in nanoseconds.
214 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 static final int UPDATE_FOCUS_NORMAL = 0;
217 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
218 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
219 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700222 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 /**
225 * Condition waited on by {@link #reenableKeyguard} to know the call to
226 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500227 * This is set to true only if mKeyguardTokenWatcher.acquired() has
228 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
Jim Miller284b62e2010-06-08 14:27:42 -0700232 private static final int ALLOW_DISABLE_YES = 1;
233 private static final int ALLOW_DISABLE_NO = 0;
234 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
235 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
236
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
238 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700240 if (shouldAllowDisableKeyguard()) {
241 mPolicy.enableKeyguard(false);
242 mKeyguardDisabled = true;
243 } else {
244 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 }
247 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700248 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500249 synchronized (mKeyguardTokenWatcher) {
250 mKeyguardDisabled = false;
251 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253 }
254 };
255
Jim Miller284b62e2010-06-08 14:27:42 -0700256 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 mPolicy.enableKeyguard(true);
260 synchronized(mKeyguardTokenWatcher) {
261 // lazily evaluate this next time we're asked to disable keyguard
262 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
263 mKeyguardDisabled = false;
264 }
265 }
266 };
267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 final Context mContext;
269
270 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
275
276 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * All currently active sessions with clients.
282 */
283 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Mapping from an IWindow IBinder to the server's Window object.
287 * This is also used as the lock for all of our state.
288 */
289 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
290
291 /**
292 * Mapping from a token IBinder to a WindowToken object.
293 */
294 final HashMap<IBinder, WindowToken> mTokenMap =
295 new HashMap<IBinder, WindowToken>();
296
297 /**
298 * The same tokens as mTokenMap, stored in a list for efficient iteration
299 * over them.
300 */
301 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * Window tokens that are in the process of exiting, but still
305 * on screen for animations.
306 */
307 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
308
309 /**
310 * Z-ordered (bottom-most first) list of all application tokens, for
311 * controlling the ordering of windows in different applications. This
312 * contains WindowToken objects.
313 */
314 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
315
316 /**
317 * Application tokens that are in the process of exiting, but still
318 * on screen for animations.
319 */
320 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
321
322 /**
323 * List of window tokens that have finished starting their application,
324 * and now need to have the policy remove their windows.
325 */
326 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
327
328 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700329 * This was the app token that was used to retrieve the last enter
330 * animation. It will be used for the next exit animation.
331 */
332 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800333
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700334 /**
335 * These were the layout params used to retrieve the last enter animation.
336 * They will be used for the next exit animation.
337 */
338 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800339
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700340 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * Z-ordered (bottom-most first) list of all Window objects.
342 */
Jeff Browne33348b2010-07-15 23:54:05 -0700343 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 /**
346 * Windows that are being resized. Used so we can tell the client about
347 * the resize after closing the transaction in which we resized the
348 * underlying surface.
349 */
350 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
351
352 /**
353 * Windows whose animations have ended and now must be removed.
354 */
355 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
356
357 /**
358 * Windows whose surface should be destroyed.
359 */
360 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
361
362 /**
363 * Windows that have lost input focus and are waiting for the new
364 * focus window to be displayed before they are told about this.
365 */
366 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
367
368 /**
369 * This is set when we have run out of memory, and will either be an empty
370 * list or contain windows that need to be force removed.
371 */
372 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 final float[] mTmpFloats = new float[9];
385
386 boolean mSafeMode;
387 boolean mDisplayEnabled = false;
388 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700389 int mInitialDisplayWidth = 0;
390 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 int mRotation = 0;
392 int mRequestedRotation = 0;
393 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700394 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 ArrayList<IRotationWatcher> mRotationWatchers
396 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 boolean mLayoutNeeded = true;
399 boolean mAnimationPending = false;
400 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800401 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mWindowsFreezingScreen = false;
403 long mFreezeGcPending = 0;
404 int mAppsFreezingScreen = 0;
405
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 int mLayoutSeq = 0;
407
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800408 // State while inside of layoutAndPlaceSurfacesLocked().
409 boolean mFocusMayChange;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 Configuration mCurConfiguration = new Configuration();
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This is held as long as we have the screen frozen, to give us time to
414 // perform a rotation animation when turning off shows the lock screen which
415 // changes the orientation.
416 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // State management of app transitions. When we are preparing for a
419 // transition, mNextAppTransition will be the kind of transition to
420 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
421 // mOpeningApps and mClosingApps are the lists of tokens that will be
422 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700423 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700424 String mNextAppTransitionPackage;
425 int mNextAppTransitionEnter;
426 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700428 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionTimeout = false;
430 boolean mStartingIconInTransition = false;
431 boolean mSkipAppTransitionAnimation = false;
432 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700434 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 H mH = new H();
440
441 WindowState mCurrentFocus = null;
442 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 // This just indicates the window the input method is on top of, not
445 // necessarily the window its input is going to.
446 WindowState mInputMethodTarget = null;
447 WindowState mUpcomingInputMethodTarget = null;
448 boolean mInputMethodTargetWaitingAnim;
449 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 WindowState mInputMethodWindow = null;
452 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
453
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700454 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800455
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 // If non-null, this is the currently visible window that is associated
457 // with the wallpaper.
458 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the lower one in Z-order.
461 WindowState mLowerWallpaperTarget = null;
462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the higher one in Z-order.
464 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700465 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700466 float mLastWallpaperX = -1;
467 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800468 float mLastWallpaperXStep = -1;
469 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700470 // This is set when we are waiting for a wallpaper to tell us it is done
471 // changing its scroll position.
472 WindowState mWaitingOnWallpaper;
473 // The last time we had a timeout when waiting for a wallpaper.
474 long mLastWallpaperTimeoutTime;
475 // We give a wallpaper up to 150ms to finish scrolling.
476 static final long WALLPAPER_TIMEOUT = 150;
477 // Time we wait after a timeout before trying to wait again.
478 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 AppWindowToken mFocusedApp = null;
481
482 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 float mWindowAnimationScale = 1.0f;
485 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700486
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488
489 // Who is holding the screen on.
490 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700491 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700493 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700496 * Drag/drop state
497 */
498 class DragState {
499 IBinder mToken;
500 Surface mSurface;
501 boolean mLocalOnly;
502 ClipData mData;
503 ClipDescription mDataDescription;
Chris Tated4533f142010-10-19 15:15:08 -0700504 boolean mDragResult;
Chris Tateb478f462010-10-15 16:02:26 -0700505 float mCurrentX, mCurrentY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700506 float mThumbOffsetX, mThumbOffsetY;
507 InputChannel mServerChannel, mClientChannel;
508 WindowState mTargetWindow;
509 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700510 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700511
512 private final Rect tmpRect = new Rect();
513
514 DragState(IBinder token, Surface surface, boolean localOnly) {
515 mToken = token;
516 mSurface = surface;
517 mLocalOnly = localOnly;
518 mNotifiedWindows = new ArrayList<WindowState>();
519 }
520
521 void reset() {
522 if (mSurface != null) {
523 mSurface.destroy();
524 }
525 mSurface = null;
526 mLocalOnly = false;
527 mToken = null;
528 mData = null;
529 mThumbOffsetX = mThumbOffsetY = 0;
530 mNotifiedWindows = null;
531 }
532
533 void register() {
534 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
535 if (mClientChannel != null) {
536 Slog.e(TAG, "Duplicate register of drag input channel");
537 } else {
538 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
539 mServerChannel = channels[0];
540 mClientChannel = channels[1];
541 mInputManager.registerInputChannel(mServerChannel);
542 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
543 mH.getLooper().getQueue());
544 }
545 }
546
547 void unregister() {
548 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
549 if (mClientChannel == null) {
550 Slog.e(TAG, "Unregister of nonexistent drag input channel");
551 } else {
552 mInputManager.unregisterInputChannel(mServerChannel);
553 InputQueue.unregisterInputChannel(mClientChannel);
554 mClientChannel.dispose();
Chris Tateef70a072010-10-22 19:10:34 -0700555 mServerChannel.dispose();
Christopher Tatea53146c2010-09-07 11:57:52 -0700556 mClientChannel = null;
557 mServerChannel = null;
558 }
559 }
560
Chris Tatea32dcf72010-10-14 12:13:50 -0700561 int getDragLayerLw() {
562 return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG)
563 * TYPE_LAYER_MULTIPLIER
564 + TYPE_LAYER_OFFSET;
565 }
566
Christopher Tatea53146c2010-09-07 11:57:52 -0700567 /* call out to each visible window/session informing it about the drag
568 */
Chris Tateb8203e92010-10-12 14:23:21 -0700569 void broadcastDragStartedLw(final float touchX, final float touchY) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700570 // Cache a base-class instance of the clip metadata so that parceling
571 // works correctly in calling out to the apps.
Dianne Hackbornf834dfa2010-10-26 12:43:57 -0700572 mDataDescription = mData.getDescription();
Christopher Tatea53146c2010-09-07 11:57:52 -0700573 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700574 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700575
576 if (DEBUG_DRAG) {
Chris Tateb478f462010-10-15 16:02:26 -0700577 Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
Christopher Tatea53146c2010-09-07 11:57:52 -0700578 }
579
Christopher Tate2c095f32010-10-04 14:13:40 -0700580 final int N = mWindows.size();
581 for (int i = 0; i < N; i++) {
Chris Tateb478f462010-10-15 16:02:26 -0700582 sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700583 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700584 }
585
586 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
587 * designated window is potentially a drop recipient. There are race situations
588 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
589 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700590 *
591 * This method clones the 'event' parameter if it's being delivered to the same
592 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700593 */
Chris Tateb478f462010-10-15 16:02:26 -0700594 private void sendDragStartedLw(WindowState newWin, float touchX, float touchY,
595 ClipDescription desc) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700596 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Chris Tateb478f462010-10-15 16:02:26 -0700597 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
598 touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700599 desc, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700600 try {
601 newWin.mClient.dispatchDragEvent(event);
602 // track each window that we've notified that the drag is starting
603 mNotifiedWindows.add(newWin);
604 } catch (RemoteException e) {
605 Slog.w(TAG, "Unable to drag-start window " + newWin);
Chris Tateb478f462010-10-15 16:02:26 -0700606 } finally {
607 // if the callee was local, the dispatch has already recycled the event
608 if (Process.myPid() != newWin.mSession.mPid) {
609 event.recycle();
610 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700611 }
612 }
613 }
614
615 /* helper - construct and send a DRAG_STARTED event only if the window has not
616 * previously been notified, i.e. it became visible after the drag operation
617 * was begun. This is a rare case.
618 */
619 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700620 if (mDragInProgress) {
621 // If we have sent the drag-started, we needn't do so again
622 for (WindowState ws : mNotifiedWindows) {
623 if (ws == newWin) {
624 return;
625 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700626 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700627 if (DEBUG_DRAG) {
Chris Tateef70a072010-10-22 19:10:34 -0700628 Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin);
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700629 }
Chris Tateb478f462010-10-15 16:02:26 -0700630 sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription);
Christopher Tatea53146c2010-09-07 11:57:52 -0700631 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700632 }
633
Chris Tated4533f142010-10-19 15:15:08 -0700634 void broadcastDragEndedLw() {
Christopher Tatea53146c2010-09-07 11:57:52 -0700635 if (DEBUG_DRAG) {
636 Slog.d(TAG, "broadcasting DRAG_ENDED");
637 }
Chris Tated4533f142010-10-19 15:15:08 -0700638 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
639 0, 0, null, null, mDragResult);
640 for (WindowState ws: mNotifiedWindows) {
641 try {
642 ws.mClient.dispatchDragEvent(evt);
643 } catch (RemoteException e) {
644 Slog.w(TAG, "Unable to drag-end window " + ws);
Christopher Tatea53146c2010-09-07 11:57:52 -0700645 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700646 }
Chris Tated4533f142010-10-19 15:15:08 -0700647 mNotifiedWindows.clear();
648 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700649 evt.recycle();
650 }
651
Chris Tated4533f142010-10-19 15:15:08 -0700652 void endDragLw() {
653 mDragState.broadcastDragEndedLw();
654
655 // stop intercepting input
656 mDragState.unregister();
657 mInputMonitor.updateInputWindowsLw();
658
659 // free our resources and drop all the object references
660 mDragState.reset();
661 mDragState = null;
662 }
663
Christopher Tatea53146c2010-09-07 11:57:52 -0700664 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700665 final int myPid = Process.myPid();
666
667 // Move the surface to the given touch
668 mSurface.openTransaction();
669 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
670 mSurface.closeTransaction();
671
672 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700673 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
674 try {
675 // have we dragged over a new window?
676 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
677 if (DEBUG_DRAG) {
678 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
679 }
680 // force DRAG_EXITED_EVENT if appropriate
681 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
Chris Tateb478f462010-10-15 16:02:26 -0700682 x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700683 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700684 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700685 if (myPid != mTargetWindow.mSession.mPid) {
686 evt.recycle();
687 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700688 }
689 if (touchedWin != null) {
Chris Tate9d1ab882010-11-02 15:55:39 -0700690 if (false && DEBUG_DRAG) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700691 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
692 }
693 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
Chris Tateb478f462010-10-15 16:02:26 -0700694 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
Chris Tated4533f142010-10-19 15:15:08 -0700695 null, null, false);
Christopher Tatea53146c2010-09-07 11:57:52 -0700696 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700697 if (myPid != touchedWin.mSession.mPid) {
698 evt.recycle();
699 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700700 }
701 } catch (RemoteException e) {
702 Slog.w(TAG, "can't send drag notification to windows");
703 }
704 mTargetWindow = touchedWin;
705 }
706
Chris Tated4533f142010-10-19 15:15:08 -0700707 // Tell the drop target about the data. Returns 'true' if we can immediately
708 // dispatch the global drag-ended message, 'false' if we need to wait for a
709 // result from the recipient.
710 boolean notifyDropLw(float x, float y) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700711 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
Chris Tated4533f142010-10-19 15:15:08 -0700712 if (touchedWin == null) {
713 // "drop" outside a valid window -- no recipient to apply a
714 // timeout to, and we can send the drag-ended message immediately.
715 mDragResult = false;
716 return true;
717 }
718
719 if (DEBUG_DRAG) {
720 Slog.d(TAG, "sending DROP to " + touchedWin);
721 }
722 final int myPid = Process.myPid();
723 final IBinder token = touchedWin.mClient.asBinder();
724 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
725 x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
726 null, mData, false);
727 try {
728 touchedWin.mClient.dispatchDragEvent(evt);
729
730 // 5 second timeout for this window to respond to the drop
731 mH.removeMessages(H.DRAG_END_TIMEOUT, token);
732 Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
733 mH.sendMessageDelayed(msg, 5000);
734 } catch (RemoteException e) {
735 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
736 return true;
737 } finally {
Christopher Tate2c095f32010-10-04 14:13:40 -0700738 if (myPid != touchedWin.mSession.mPid) {
739 evt.recycle();
740 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700741 }
Chris Tated4533f142010-10-19 15:15:08 -0700742 mToken = token;
743 return false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700744 }
745
746 // Find the visible, touch-deliverable window under the given point
747 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
748 WindowState touchedWin = null;
749 final int x = (int) xf;
750 final int y = (int) yf;
751 final ArrayList<WindowState> windows = mWindows;
752 final int N = windows.size();
753 for (int i = N - 1; i >= 0; i--) {
754 WindowState child = windows.get(i);
755 final int flags = child.mAttrs.flags;
756 if (!child.isVisibleLw()) {
757 // not visible == don't tell about drags
758 continue;
759 }
760 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
761 // not touchable == don't tell about drags
762 continue;
763 }
764 // account for the window's decor etc
765 tmpRect.set(child.mFrame);
766 if (child.mTouchableInsets == ViewTreeObserver
767 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
768 // The point is inside of the window if it is
769 // inside the frame, AND the content part of that
770 // frame that was given by the application.
771 tmpRect.left += child.mGivenContentInsets.left;
772 tmpRect.top += child.mGivenContentInsets.top;
773 tmpRect.right -= child.mGivenContentInsets.right;
774 tmpRect.bottom -= child.mGivenContentInsets.bottom;
775 } else if (child.mTouchableInsets == ViewTreeObserver
776 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
777 // The point is inside of the window if it is
778 // inside the frame, AND the visible part of that
779 // frame that was given by the application.
780 tmpRect.left += child.mGivenVisibleInsets.left;
781 tmpRect.top += child.mGivenVisibleInsets.top;
782 tmpRect.right -= child.mGivenVisibleInsets.right;
783 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
784 }
785 final int touchFlags = flags &
786 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
787 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
788 if (tmpRect.contains(x, y) || touchFlags == 0) {
789 // Found it
790 touchedWin = child;
791 break;
792 }
793 }
794
795 return touchedWin;
796 }
797 }
798
799 DragState mDragState = null;
800 private final InputHandler mDragInputHandler = new BaseInputHandler() {
801 @Override
802 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
803 boolean endDrag = false;
804 final float newX = event.getRawX();
805 final float newY = event.getRawY();
806
807 try {
808 if (mDragState != null) {
809 switch (event.getAction()) {
810 case MotionEvent.ACTION_DOWN: {
811 if (DEBUG_DRAG) {
812 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
813 }
814 } break;
815
816 case MotionEvent.ACTION_MOVE: {
817 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700818 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700819 mDragState.notifyMoveLw(newX, newY);
820 }
821 } break;
822
823 case MotionEvent.ACTION_UP: {
824 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
825 + newX + "," + newY);
826 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700827 endDrag = mDragState.notifyDropLw(newX, newY);
Christopher Tatea53146c2010-09-07 11:57:52 -0700828 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700829 } break;
830
831 case MotionEvent.ACTION_CANCEL: {
832 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
833 endDrag = true;
834 } break;
835 }
836
837 if (endDrag) {
838 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
839 // tell all the windows that the drag has ended
Chris Tate59943592010-10-11 20:33:44 -0700840 synchronized (mWindowMap) {
Chris Tated4533f142010-10-19 15:15:08 -0700841 mDragState.endDragLw();
Chris Tate59943592010-10-11 20:33:44 -0700842 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700843 }
844 }
845 } catch (Exception e) {
846 Slog.e(TAG, "Exception caught by drag handleMotion", e);
847 } finally {
848 finishedCallback.run();
849 }
850 }
851 };
852
853 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 * Whether the UI is currently running in touch mode (not showing
855 * navigational focus because the user is directly pressing the screen).
856 */
857 boolean mInTouchMode = false;
858
859 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700860 private ArrayList<WindowChangeListener> mWindowChangeListeners =
861 new ArrayList<WindowChangeListener>();
862 private boolean mWindowsChanged = false;
863
864 public interface WindowChangeListener {
865 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700866 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700867 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868
Dianne Hackbornc485a602009-03-24 22:39:49 -0700869 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700870 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700871
872 // The frame use to limit the size of the app running in compatibility mode.
873 Rect mCompatibleScreenFrame = new Rect();
874 // The surface used to fill the outer rim of the app running in compatibility mode.
875 Surface mBackgroundFillerSurface = null;
876 boolean mBackgroundFillerShown = false;
877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 public static WindowManagerService main(Context context,
879 PowerManagerService pm, boolean haveInputMethods) {
880 WMThread thr = new WMThread(context, pm, haveInputMethods);
881 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 synchronized (thr) {
884 while (thr.mService == null) {
885 try {
886 thr.wait();
887 } catch (InterruptedException e) {
888 }
889 }
890 }
Romain Guy06882f82009-06-10 13:36:04 -0700891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 return thr.mService;
893 }
Romain Guy06882f82009-06-10 13:36:04 -0700894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 static class WMThread extends Thread {
896 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 private final Context mContext;
899 private final PowerManagerService mPM;
900 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 public WMThread(Context context, PowerManagerService pm,
903 boolean haveInputMethods) {
904 super("WindowManager");
905 mContext = context;
906 mPM = pm;
907 mHaveInputMethods = haveInputMethods;
908 }
Romain Guy06882f82009-06-10 13:36:04 -0700909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 public void run() {
911 Looper.prepare();
912 WindowManagerService s = new WindowManagerService(mContext, mPM,
913 mHaveInputMethods);
914 android.os.Process.setThreadPriority(
915 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700916 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 synchronized (this) {
919 mService = s;
920 notifyAll();
921 }
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 Looper.loop();
924 }
925 }
926
927 static class PolicyThread extends Thread {
928 private final WindowManagerPolicy mPolicy;
929 private final WindowManagerService mService;
930 private final Context mContext;
931 private final PowerManagerService mPM;
932 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 public PolicyThread(WindowManagerPolicy policy,
935 WindowManagerService service, Context context,
936 PowerManagerService pm) {
937 super("WindowManagerPolicy");
938 mPolicy = policy;
939 mService = service;
940 mContext = context;
941 mPM = pm;
942 }
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 public void run() {
945 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800946 WindowManagerPolicyThread.set(this, Looper.myLooper());
947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800949 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 android.os.Process.setThreadPriority(
951 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700952 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 synchronized (this) {
956 mRunning = true;
957 notifyAll();
958 }
Romain Guy06882f82009-06-10 13:36:04 -0700959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 Looper.loop();
961 }
962 }
963
964 private WindowManagerService(Context context, PowerManagerService pm,
965 boolean haveInputMethods) {
966 mContext = context;
967 mHaveInputMethods = haveInputMethods;
968 mLimitedAlphaCompositing = context.getResources().getBoolean(
969 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 mPowerManager = pm;
972 mPowerManager.setPolicy(mPolicy);
973 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
974 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
975 "SCREEN_FROZEN");
976 mScreenFrozenLock.setReferenceCounted(false);
977
978 mActivityManager = ActivityManagerNative.getDefault();
979 mBatteryStats = BatteryStatsService.getService();
980
981 // Get persisted window scale setting
982 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
983 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
984 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
985 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700986
Jim Miller284b62e2010-06-08 14:27:42 -0700987 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
988 IntentFilter filter = new IntentFilter();
989 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
990 mContext.registerReceiver(mBroadcastReceiver, filter);
991
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700992 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
993 "KEEP_SCREEN_ON_FLAG");
994 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995
Jeff Browne33348b2010-07-15 23:54:05 -0700996 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
999 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -07001000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 synchronized (thr) {
1002 while (!thr.mRunning) {
1003 try {
1004 thr.wait();
1005 } catch (InterruptedException e) {
1006 }
1007 }
1008 }
Romain Guy06882f82009-06-10 13:36:04 -07001009
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001010 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -07001011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 // Add ourself to the Watchdog monitors.
1013 Watchdog.getInstance().addMonitor(this);
1014 }
1015
1016 @Override
1017 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1018 throws RemoteException {
1019 try {
1020 return super.onTransact(code, data, reply, flags);
1021 } catch (RuntimeException e) {
1022 // The window manager only throws security exceptions, so let's
1023 // log all others.
1024 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001025 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 }
1027 throw e;
1028 }
1029 }
1030
Jeff Browne33348b2010-07-15 23:54:05 -07001031 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001033 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 TAG, "Adding window " + window + " at "
1035 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1036 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001037 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 }
1039
Jeff Browne33348b2010-07-15 23:54:05 -07001040 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001042 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 TAG, "Adding window " + window + " at "
1044 + i + " of " + mWindows.size() + " (before " + pos + ")");
1045 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001046 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 }
1048
1049 //This method finds out the index of a window that has the same app token as
1050 //win. used for z ordering the windows in mWindows
1051 private int findIdxBasedOnAppTokens(WindowState win) {
1052 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001053 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 int jmax = localmWindows.size();
1055 if(jmax == 0) {
1056 return -1;
1057 }
1058 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001059 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 if(wentry.mAppToken == win.mAppToken) {
1061 return j;
1062 }
1063 }
1064 return -1;
1065 }
Romain Guy06882f82009-06-10 13:36:04 -07001066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1068 final IWindow client = win.mClient;
1069 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001070 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 final int N = localmWindows.size();
1073 final WindowState attached = win.mAttachedWindow;
1074 int i;
1075 if (attached == null) {
1076 int tokenWindowsPos = token.windows.size();
1077 if (token.appWindowToken != null) {
1078 int index = tokenWindowsPos-1;
1079 if (index >= 0) {
1080 // If this application has existing windows, we
1081 // simply place the new window on top of them... but
1082 // keep the starting window on top.
1083 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1084 // Base windows go behind everything else.
1085 placeWindowBefore(token.windows.get(0), win);
1086 tokenWindowsPos = 0;
1087 } else {
1088 AppWindowToken atoken = win.mAppToken;
1089 if (atoken != null &&
1090 token.windows.get(index) == atoken.startingWindow) {
1091 placeWindowBefore(token.windows.get(index), win);
1092 tokenWindowsPos--;
1093 } else {
1094 int newIdx = findIdxBasedOnAppTokens(win);
1095 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001096 //there is a window above this one associated with the same
1097 //apptoken note that the window could be a floating window
1098 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001101 TAG, "Adding window " + win + " at "
1102 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001104 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
1107 }
1108 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001109 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 TAG, "Figuring out where to add app window "
1111 + client.asBinder() + " (token=" + token + ")");
1112 // Figure out where the window should go, based on the
1113 // order of applications.
1114 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001115 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 for (i=NA-1; i>=0; i--) {
1117 AppWindowToken t = mAppTokens.get(i);
1118 if (t == token) {
1119 i--;
1120 break;
1121 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001122
Dianne Hackborna8f60182009-09-01 19:01:50 -07001123 // We haven't reached the token yet; if this token
1124 // is not going to the bottom and has windows, we can
1125 // use it as an anchor for when we do reach the token.
1126 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 pos = t.windows.get(0);
1128 }
1129 }
1130 // We now know the index into the apps. If we found
1131 // an app window above, that gives us the position; else
1132 // we need to look some more.
1133 if (pos != null) {
1134 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001135 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 if (atoken != null) {
1137 final int NC = atoken.windows.size();
1138 if (NC > 0) {
1139 WindowState bottom = atoken.windows.get(0);
1140 if (bottom.mSubLayer < 0) {
1141 pos = bottom;
1142 }
1143 }
1144 }
1145 placeWindowBefore(pos, win);
1146 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001147 // Continue looking down until we find the first
1148 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 while (i >= 0) {
1150 AppWindowToken t = mAppTokens.get(i);
1151 final int NW = t.windows.size();
1152 if (NW > 0) {
1153 pos = t.windows.get(NW-1);
1154 break;
1155 }
1156 i--;
1157 }
1158 if (pos != null) {
1159 // Move in front of any windows attached to this
1160 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001161 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 if (atoken != null) {
1163 final int NC = atoken.windows.size();
1164 if (NC > 0) {
1165 WindowState top = atoken.windows.get(NC-1);
1166 if (top.mSubLayer >= 0) {
1167 pos = top;
1168 }
1169 }
1170 }
1171 placeWindowAfter(pos, win);
1172 } else {
1173 // Just search for the start of this layer.
1174 final int myLayer = win.mBaseLayer;
1175 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001176 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 if (w.mBaseLayer > myLayer) {
1178 break;
1179 }
1180 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001181 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001182 TAG, "Adding window " + win + " at "
1183 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001185 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 }
1187 }
1188 }
1189 } else {
1190 // Figure out where window should go, based on layer.
1191 final int myLayer = win.mBaseLayer;
1192 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001193 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 i++;
1195 break;
1196 }
1197 }
1198 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001199 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001200 TAG, "Adding window " + win + " at "
1201 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001203 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 }
1205 if (addToToken) {
1206 token.windows.add(tokenWindowsPos, win);
1207 }
1208
1209 } else {
1210 // Figure out this window's ordering relative to the window
1211 // it is attached to.
1212 final int NA = token.windows.size();
1213 final int sublayer = win.mSubLayer;
1214 int largestSublayer = Integer.MIN_VALUE;
1215 WindowState windowWithLargestSublayer = null;
1216 for (i=0; i<NA; i++) {
1217 WindowState w = token.windows.get(i);
1218 final int wSublayer = w.mSubLayer;
1219 if (wSublayer >= largestSublayer) {
1220 largestSublayer = wSublayer;
1221 windowWithLargestSublayer = w;
1222 }
1223 if (sublayer < 0) {
1224 // For negative sublayers, we go below all windows
1225 // in the same sublayer.
1226 if (wSublayer >= sublayer) {
1227 if (addToToken) {
1228 token.windows.add(i, win);
1229 }
1230 placeWindowBefore(
1231 wSublayer >= 0 ? attached : w, win);
1232 break;
1233 }
1234 } else {
1235 // For positive sublayers, we go above all windows
1236 // in the same sublayer.
1237 if (wSublayer > sublayer) {
1238 if (addToToken) {
1239 token.windows.add(i, win);
1240 }
1241 placeWindowBefore(w, win);
1242 break;
1243 }
1244 }
1245 }
1246 if (i >= NA) {
1247 if (addToToken) {
1248 token.windows.add(win);
1249 }
1250 if (sublayer < 0) {
1251 placeWindowBefore(attached, win);
1252 } else {
1253 placeWindowAfter(largestSublayer >= 0
1254 ? windowWithLargestSublayer
1255 : attached,
1256 win);
1257 }
1258 }
1259 }
Romain Guy06882f82009-06-10 13:36:04 -07001260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 if (win.mAppToken != null && addToToken) {
1262 win.mAppToken.allAppWindows.add(win);
1263 }
1264 }
Romain Guy06882f82009-06-10 13:36:04 -07001265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 static boolean canBeImeTarget(WindowState w) {
1267 final int fl = w.mAttrs.flags
1268 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1269 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1270 return w.isVisibleOrAdding();
1271 }
1272 return false;
1273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001276 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 final int N = localmWindows.size();
1278 WindowState w = null;
1279 int i = N;
1280 while (i > 0) {
1281 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001282 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001283
Joe Onorato8a9b2202010-02-26 18:56:32 -08001284 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 // + Integer.toHexString(w.mAttrs.flags));
1286 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001287 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 // Yet more tricksyness! If this window is a "starting"
1290 // window, we do actually want to be on top of it, but
1291 // it is not -really- where input will go. So if the caller
1292 // is not actually looking to move the IME, look down below
1293 // for a real window to target...
1294 if (!willMove
1295 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1296 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001297 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1299 i--;
1300 w = wb;
1301 }
1302 }
1303 break;
1304 }
1305 }
Romain Guy06882f82009-06-10 13:36:04 -07001306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001308
Joe Onorato8a9b2202010-02-26 18:56:32 -08001309 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001310 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 if (willMove && w != null) {
1313 final WindowState curTarget = mInputMethodTarget;
1314 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 // Now some fun for dealing with window animations that
1317 // modify the Z order. We need to look at all windows below
1318 // the current target that are in this app, finding the highest
1319 // visible one in layering.
1320 AppWindowToken token = curTarget.mAppToken;
1321 WindowState highestTarget = null;
1322 int highestPos = 0;
1323 if (token.animating || token.animation != null) {
1324 int pos = 0;
1325 pos = localmWindows.indexOf(curTarget);
1326 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001327 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 if (win.mAppToken != token) {
1329 break;
1330 }
1331 if (!win.mRemoved) {
1332 if (highestTarget == null || win.mAnimLayer >
1333 highestTarget.mAnimLayer) {
1334 highestTarget = win;
1335 highestPos = pos;
1336 }
1337 }
1338 pos--;
1339 }
1340 }
Romain Guy06882f82009-06-10 13:36:04 -07001341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001343 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 + mNextAppTransition + " " + highestTarget
1345 + " animating=" + highestTarget.isAnimating()
1346 + " layer=" + highestTarget.mAnimLayer
1347 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001348
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001349 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001350 // If we are currently setting up for an animation,
1351 // hold everything until we can find out what will happen.
1352 mInputMethodTargetWaitingAnim = true;
1353 mInputMethodTarget = highestTarget;
1354 return highestPos + 1;
1355 } else if (highestTarget.isAnimating() &&
1356 highestTarget.mAnimLayer > w.mAnimLayer) {
1357 // If the window we are currently targeting is involved
1358 // with an animation, and it is on top of the next target
1359 // we will be over, then hold off on moving until
1360 // that is done.
1361 mInputMethodTarget = highestTarget;
1362 return highestPos + 1;
1363 }
1364 }
1365 }
1366 }
Romain Guy06882f82009-06-10 13:36:04 -07001367
Joe Onorato8a9b2202010-02-26 18:56:32 -08001368 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 if (w != null) {
1370 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001371 if (DEBUG_INPUT_METHOD) {
1372 RuntimeException e = null;
1373 if (!HIDE_STACK_CRAWLS) {
1374 e = new RuntimeException();
1375 e.fillInStackTrace();
1376 }
1377 Slog.w(TAG, "Moving IM target from "
1378 + mInputMethodTarget + " to " + w, e);
1379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 mInputMethodTarget = w;
1381 if (w.mAppToken != null) {
1382 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1383 } else {
1384 setInputMethodAnimLayerAdjustment(0);
1385 }
1386 }
1387 return i+1;
1388 }
1389 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001390 if (DEBUG_INPUT_METHOD) {
1391 RuntimeException e = null;
1392 if (!HIDE_STACK_CRAWLS) {
1393 e = new RuntimeException();
1394 e.fillInStackTrace();
1395 }
1396 Slog.w(TAG, "Moving IM target from "
1397 + mInputMethodTarget + " to null", e);
1398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 mInputMethodTarget = null;
1400 setInputMethodAnimLayerAdjustment(0);
1401 }
1402 return -1;
1403 }
Romain Guy06882f82009-06-10 13:36:04 -07001404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 void addInputMethodWindowToListLocked(WindowState win) {
1406 int pos = findDesiredInputMethodWindowIndexLocked(true);
1407 if (pos >= 0) {
1408 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001409 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001410 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001412 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 moveInputMethodDialogsLocked(pos+1);
1414 return;
1415 }
1416 win.mTargetAppToken = null;
1417 addWindowToListInOrderLocked(win, true);
1418 moveInputMethodDialogsLocked(pos);
1419 }
Romain Guy06882f82009-06-10 13:36:04 -07001420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001421 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001422 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 mInputMethodAnimLayerAdjustment = adj;
1424 WindowState imw = mInputMethodWindow;
1425 if (imw != null) {
1426 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001427 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 + " anim layer: " + imw.mAnimLayer);
1429 int wi = imw.mChildWindows.size();
1430 while (wi > 0) {
1431 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001432 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001434 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 + " anim layer: " + cw.mAnimLayer);
1436 }
1437 }
1438 int di = mInputMethodDialogs.size();
1439 while (di > 0) {
1440 di --;
1441 imw = mInputMethodDialogs.get(di);
1442 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001443 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 + " anim layer: " + imw.mAnimLayer);
1445 }
1446 }
Romain Guy06882f82009-06-10 13:36:04 -07001447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1449 int wpos = mWindows.indexOf(win);
1450 if (wpos >= 0) {
1451 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001452 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001454 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 int NC = win.mChildWindows.size();
1456 while (NC > 0) {
1457 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001458 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 int cpos = mWindows.indexOf(cw);
1460 if (cpos >= 0) {
1461 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001463 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 mWindows.remove(cpos);
1465 }
1466 }
1467 }
1468 return interestingPos;
1469 }
Romain Guy06882f82009-06-10 13:36:04 -07001470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 private void reAddWindowToListInOrderLocked(WindowState win) {
1472 addWindowToListInOrderLocked(win, false);
1473 // This is a hack to get all of the child windows added as well
1474 // at the right position. Child windows should be rare and
1475 // this case should be rare, so it shouldn't be that big a deal.
1476 int wpos = mWindows.indexOf(win);
1477 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001478 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001479 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001481 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 reAddWindowLocked(wpos, win);
1483 }
1484 }
Romain Guy06882f82009-06-10 13:36:04 -07001485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 void logWindowList(String prefix) {
1487 int N = mWindows.size();
1488 while (N > 0) {
1489 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001490 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 }
1492 }
Romain Guy06882f82009-06-10 13:36:04 -07001493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 void moveInputMethodDialogsLocked(int pos) {
1495 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 for (int i=0; i<N; i++) {
1500 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1501 }
1502 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001503 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 logWindowList(" ");
1505 }
Romain Guy06882f82009-06-10 13:36:04 -07001506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 if (pos >= 0) {
1508 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1509 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001510 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 if (wp == mInputMethodWindow) {
1512 pos++;
1513 }
1514 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001515 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 for (int i=0; i<N; i++) {
1517 WindowState win = dialogs.get(i);
1518 win.mTargetAppToken = targetAppToken;
1519 pos = reAddWindowLocked(pos, win);
1520 }
1521 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001522 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 logWindowList(" ");
1524 }
1525 return;
1526 }
1527 for (int i=0; i<N; i++) {
1528 WindowState win = dialogs.get(i);
1529 win.mTargetAppToken = null;
1530 reAddWindowToListInOrderLocked(win);
1531 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001532 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 logWindowList(" ");
1534 }
1535 }
1536 }
Romain Guy06882f82009-06-10 13:36:04 -07001537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1539 final WindowState imWin = mInputMethodWindow;
1540 final int DN = mInputMethodDialogs.size();
1541 if (imWin == null && DN == 0) {
1542 return false;
1543 }
Romain Guy06882f82009-06-10 13:36:04 -07001544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1546 if (imPos >= 0) {
1547 // In this case, the input method windows are to be placed
1548 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 // First check to see if the input method windows are already
1551 // located here, and contiguous.
1552 final int N = mWindows.size();
1553 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001554 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 // Figure out the actual input method window that should be
1557 // at the bottom of their stack.
1558 WindowState baseImWin = imWin != null
1559 ? imWin : mInputMethodDialogs.get(0);
1560 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001561 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 if (cw.mSubLayer < 0) baseImWin = cw;
1563 }
Romain Guy06882f82009-06-10 13:36:04 -07001564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 if (firstImWin == baseImWin) {
1566 // The windows haven't moved... but are they still contiguous?
1567 // First find the top IM window.
1568 int pos = imPos+1;
1569 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001570 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 break;
1572 }
1573 pos++;
1574 }
1575 pos++;
1576 // Now there should be no more input method windows above.
1577 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001578 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 break;
1580 }
1581 pos++;
1582 }
1583 if (pos >= N) {
1584 // All is good!
1585 return false;
1586 }
1587 }
Romain Guy06882f82009-06-10 13:36:04 -07001588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 if (imWin != null) {
1590 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001591 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 logWindowList(" ");
1593 }
1594 imPos = tmpRemoveWindowLocked(imPos, imWin);
1595 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001596 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 logWindowList(" ");
1598 }
1599 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1600 reAddWindowLocked(imPos, imWin);
1601 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 logWindowList(" ");
1604 }
1605 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1606 } else {
1607 moveInputMethodDialogsLocked(imPos);
1608 }
Romain Guy06882f82009-06-10 13:36:04 -07001609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 } else {
1611 // In this case, the input method windows go in a fixed layer,
1612 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001615 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 tmpRemoveWindowLocked(0, imWin);
1617 imWin.mTargetAppToken = null;
1618 reAddWindowToListInOrderLocked(imWin);
1619 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001620 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 logWindowList(" ");
1622 }
1623 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1624 } else {
1625 moveInputMethodDialogsLocked(-1);;
1626 }
Romain Guy06882f82009-06-10 13:36:04 -07001627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
Romain Guy06882f82009-06-10 13:36:04 -07001629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 if (needAssignLayers) {
1631 assignLayersLocked();
1632 }
Romain Guy06882f82009-06-10 13:36:04 -07001633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 return true;
1635 }
Romain Guy06882f82009-06-10 13:36:04 -07001636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 void adjustInputMethodDialogsLocked() {
1638 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1639 }
Romain Guy06882f82009-06-10 13:36:04 -07001640
Dianne Hackborn25994b42009-09-04 14:21:19 -07001641 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001642 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001643 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1644 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1645 ? wallpaperTarget.mAppToken.animation : null)
1646 + " upper=" + mUpperWallpaperTarget
1647 + " lower=" + mLowerWallpaperTarget);
1648 return (wallpaperTarget != null
1649 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1650 && wallpaperTarget.mAppToken.animation != null)))
1651 || mUpperWallpaperTarget != null
1652 || mLowerWallpaperTarget != null;
1653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001654
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001655 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1656 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001657
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001658 int adjustWallpaperWindowsLocked() {
1659 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001660
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001661 final int dw = mDisplay.getWidth();
1662 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001663
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001664 // First find top-most window that has asked to be on top of the
1665 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001666 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001667 int N = localmWindows.size();
1668 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001669 WindowState foundW = null;
1670 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001671 WindowState topCurW = null;
1672 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001673 int i = N;
1674 while (i > 0) {
1675 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001676 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001677 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1678 if (topCurW == null) {
1679 topCurW = w;
1680 topCurI = i;
1681 }
1682 continue;
1683 }
1684 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001685 if (w.mAppToken != null) {
1686 // If this window's app token is hidden and not animating,
1687 // it is of no interest to us.
1688 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001689 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001690 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001691 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001692 continue;
1693 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001694 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001695 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001696 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1697 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001698 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001699 && (mWallpaperTarget == w
1700 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001701 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001702 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001703 foundW = w;
1704 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001705 if (w == mWallpaperTarget && ((w.mAppToken != null
1706 && w.mAppToken.animation != null)
1707 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001708 // The current wallpaper target is animating, so we'll
1709 // look behind it for another possible target and figure
1710 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001711 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001712 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001713 continue;
1714 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001715 break;
1716 }
1717 }
1718
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001719 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001720 // If we are currently waiting for an app transition, and either
1721 // the current target or the next target are involved with it,
1722 // then hold off on doing anything with the wallpaper.
1723 // Note that we are checking here for just whether the target
1724 // is part of an app token... which is potentially overly aggressive
1725 // (the app token may not be involved in the transition), but good
1726 // enough (we'll just wait until whatever transition is pending
1727 // executes).
1728 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001729 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001730 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001731 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001732 }
1733 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001734 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001735 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001736 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001737 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001738 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001739
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001740 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001741 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001742 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001743 + " oldTarget: " + mWallpaperTarget);
1744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 mLowerWallpaperTarget = null;
1747 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001749 WindowState oldW = mWallpaperTarget;
1750 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001751
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001752 // Now what is happening... if the current and new targets are
1753 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001754 if (foundW != null && oldW != null) {
1755 boolean oldAnim = oldW.mAnimation != null
1756 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1757 boolean foundAnim = foundW.mAnimation != null
1758 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001759 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001760 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001761 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001762 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001763 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001764 int oldI = localmWindows.indexOf(oldW);
1765 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001766 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001767 }
1768 if (oldI >= 0) {
1769 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001770 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001771 + "=" + oldW + "; new#" + foundI
1772 + "=" + foundW);
1773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001774
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001775 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001776 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001777 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001778 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001779 }
1780 mWallpaperTarget = oldW;
1781 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001782
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001783 // Now set the upper and lower wallpaper targets
1784 // correctly, and make sure that we are positioning
1785 // the wallpaper below the lower.
1786 if (foundI > oldI) {
1787 // The new target is on top of the old one.
1788 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001789 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001790 }
1791 mUpperWallpaperTarget = foundW;
1792 mLowerWallpaperTarget = oldW;
1793 foundW = oldW;
1794 foundI = oldI;
1795 } else {
1796 // The new target is below the old one.
1797 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001798 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001799 }
1800 mUpperWallpaperTarget = oldW;
1801 mLowerWallpaperTarget = foundW;
1802 }
1803 }
1804 }
1805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001806
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001807 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001808 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001809 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1810 || (mLowerWallpaperTarget.mAppToken != null
1811 && mLowerWallpaperTarget.mAppToken.animation != null);
1812 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1813 || (mUpperWallpaperTarget.mAppToken != null
1814 && mUpperWallpaperTarget.mAppToken.animation != null);
1815 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001816 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001817 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001818 }
1819 mLowerWallpaperTarget = null;
1820 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001821 }
1822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001823
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001824 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001825 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001826 // The window is visible to the compositor... but is it visible
1827 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001828 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001829 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001830
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001831 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001832 // its layer adjustment. Only do this if we are not transfering
1833 // between two wallpaper targets.
1834 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001835 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001836 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001837
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001838 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1839 * TYPE_LAYER_MULTIPLIER
1840 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001841
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 // Now w is the window we are supposed to be behind... but we
1843 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001844 // AND any starting window associated with it, AND below the
1845 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001846 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001847 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001848 if (wb.mBaseLayer < maxLayer &&
1849 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001850 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001851 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001852 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001853 // This window is not related to the previous one in any
1854 // interesting way, so stop here.
1855 break;
1856 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001857 foundW = wb;
1858 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001859 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001860 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001861 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001862 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001863
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001864 if (foundW == null && topCurW != null) {
1865 // There is no wallpaper target, so it goes at the bottom.
1866 // We will assume it is the same place as last time, if known.
1867 foundW = topCurW;
1868 foundI = topCurI+1;
1869 } else {
1870 // Okay i is the position immediately above the wallpaper. Look at
1871 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001872 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001873 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001874
Dianne Hackborn284ac932009-08-28 10:34:25 -07001875 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001876 if (mWallpaperTarget.mWallpaperX >= 0) {
1877 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001878 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001879 }
1880 if (mWallpaperTarget.mWallpaperY >= 0) {
1881 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001882 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001883 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001884 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001885
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001886 // Start stepping backwards from here, ensuring that our wallpaper windows
1887 // are correctly placed.
1888 int curTokenIndex = mWallpaperTokens.size();
1889 while (curTokenIndex > 0) {
1890 curTokenIndex--;
1891 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001892 if (token.hidden == visible) {
1893 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1894 token.hidden = !visible;
1895 // Need to do a layout to ensure the wallpaper now has the
1896 // correct size.
1897 mLayoutNeeded = true;
1898 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001899
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001900 int curWallpaperIndex = token.windows.size();
1901 while (curWallpaperIndex > 0) {
1902 curWallpaperIndex--;
1903 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001904
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001905 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001906 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001907 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001908
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001909 // First, make sure the client has the current visibility
1910 // state.
1911 if (wallpaper.mWallpaperVisible != visible) {
1912 wallpaper.mWallpaperVisible = visible;
1913 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001914 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001915 "Setting visibility of wallpaper " + wallpaper
1916 + ": " + visible);
1917 wallpaper.mClient.dispatchAppVisibility(visible);
1918 } catch (RemoteException e) {
1919 }
1920 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001921
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001922 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001923 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001924 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001925
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001926 // First, if this window is at the current index, then all
1927 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001928 if (wallpaper == foundW) {
1929 foundI--;
1930 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001931 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001932 continue;
1933 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001934
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001935 // The window didn't match... the current wallpaper window,
1936 // wherever it is, is in the wrong place, so make sure it is
1937 // not in the list.
1938 int oldIndex = localmWindows.indexOf(wallpaper);
1939 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001940 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001941 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001943 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001944 if (oldIndex < foundI) {
1945 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001946 }
1947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001948
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001949 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001950 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001951 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001952 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001953
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001954 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001955 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001956 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
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 return changed;
1961 }
1962
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001963 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001964 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001965 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001966 mWallpaperAnimLayerAdjustment = adj;
1967 int curTokenIndex = mWallpaperTokens.size();
1968 while (curTokenIndex > 0) {
1969 curTokenIndex--;
1970 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1971 int curWallpaperIndex = token.windows.size();
1972 while (curWallpaperIndex > 0) {
1973 curWallpaperIndex--;
1974 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1975 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001976 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001977 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001978 }
1979 }
1980 }
1981
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001982 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1983 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001984 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001985 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001986 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001987 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001988 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1989 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1990 changed = wallpaperWin.mXOffset != offset;
1991 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001992 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001993 + wallpaperWin + " x: " + offset);
1994 wallpaperWin.mXOffset = offset;
1995 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001996 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001997 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001998 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001999 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002001
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002002 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002003 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002004 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
2005 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
2006 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002007 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002008 + wallpaperWin + " y: " + offset);
2009 changed = true;
2010 wallpaperWin.mYOffset = offset;
2011 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002012 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002013 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002014 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002015 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002016 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002017
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07002018 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002019 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002020 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002021 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
2022 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002023 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002024 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002025 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002026 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002027 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
2028 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002029 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002030 if (mWaitingOnWallpaper != null) {
2031 long start = SystemClock.uptimeMillis();
2032 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2033 < start) {
2034 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002035 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002036 "Waiting for offset complete...");
2037 mWindowMap.wait(WALLPAPER_TIMEOUT);
2038 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002039 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002040 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002041 if ((start+WALLPAPER_TIMEOUT)
2042 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002043 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002044 + wallpaperWin);
2045 mLastWallpaperTimeoutTime = start;
2046 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002047 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002048 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002049 }
2050 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002051 } catch (RemoteException e) {
2052 }
2053 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002054
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002055 return changed;
2056 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002057
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002058 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002059 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002060 if (mWaitingOnWallpaper != null &&
2061 mWaitingOnWallpaper.mClient.asBinder() == window) {
2062 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002063 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002064 }
2065 }
2066 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002067
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002068 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002069 final int dw = mDisplay.getWidth();
2070 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002071
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002072 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002073
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002074 WindowState target = mWallpaperTarget;
2075 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002076 if (target.mWallpaperX >= 0) {
2077 mLastWallpaperX = target.mWallpaperX;
2078 } else if (changingTarget.mWallpaperX >= 0) {
2079 mLastWallpaperX = changingTarget.mWallpaperX;
2080 }
2081 if (target.mWallpaperY >= 0) {
2082 mLastWallpaperY = target.mWallpaperY;
2083 } else if (changingTarget.mWallpaperY >= 0) {
2084 mLastWallpaperY = changingTarget.mWallpaperY;
2085 }
2086 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002087
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002088 int curTokenIndex = mWallpaperTokens.size();
2089 while (curTokenIndex > 0) {
2090 curTokenIndex--;
2091 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2092 int curWallpaperIndex = token.windows.size();
2093 while (curWallpaperIndex > 0) {
2094 curWallpaperIndex--;
2095 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2096 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2097 wallpaper.computeShownFrameLocked();
2098 changed = true;
2099 // We only want to be synchronous with one wallpaper.
2100 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002101 }
2102 }
2103 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002104
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002105 return changed;
2106 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002107
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002108 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002109 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002110 final int dw = mDisplay.getWidth();
2111 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002112
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002113 int curTokenIndex = mWallpaperTokens.size();
2114 while (curTokenIndex > 0) {
2115 curTokenIndex--;
2116 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002117 if (token.hidden == visible) {
2118 token.hidden = !visible;
2119 // Need to do a layout to ensure the wallpaper now has the
2120 // correct size.
2121 mLayoutNeeded = true;
2122 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002123
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002124 int curWallpaperIndex = token.windows.size();
2125 while (curWallpaperIndex > 0) {
2126 curWallpaperIndex--;
2127 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2128 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002129 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002130 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002131
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002132 if (wallpaper.mWallpaperVisible != visible) {
2133 wallpaper.mWallpaperVisible = visible;
2134 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002135 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002136 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002137 + ": " + visible);
2138 wallpaper.mClient.dispatchAppVisibility(visible);
2139 } catch (RemoteException e) {
2140 }
2141 }
2142 }
2143 }
2144 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002146 public int addWindow(Session session, IWindow client,
2147 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002148 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 int res = mPolicy.checkAddPermission(attrs);
2150 if (res != WindowManagerImpl.ADD_OKAY) {
2151 return res;
2152 }
Romain Guy06882f82009-06-10 13:36:04 -07002153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 boolean reportNewConfig = false;
2155 WindowState attachedWindow = null;
2156 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002157 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002161 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 }
Romain Guy06882f82009-06-10 13:36:04 -07002163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002165 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2167 }
2168
2169 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002170 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002172 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 + attrs.token + ". Aborting.");
2174 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2175 }
2176 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2177 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002178 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 + attrs.token + ". Aborting.");
2180 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2181 }
2182 }
2183
2184 boolean addToken = false;
2185 WindowToken token = mTokenMap.get(attrs.token);
2186 if (token == null) {
2187 if (attrs.type >= FIRST_APPLICATION_WINDOW
2188 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002189 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 + attrs.token + ". Aborting.");
2191 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2192 }
2193 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002194 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 + attrs.token + ". Aborting.");
2196 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2197 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002198 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002199 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002200 + attrs.token + ". Aborting.");
2201 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2202 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 token = new WindowToken(attrs.token, -1, false);
2204 addToken = true;
2205 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2206 && attrs.type <= LAST_APPLICATION_WINDOW) {
2207 AppWindowToken atoken = token.appWindowToken;
2208 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002209 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 + token + ". Aborting.");
2211 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2212 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 + token + ". Aborting.");
2215 return WindowManagerImpl.ADD_APP_EXITING;
2216 }
2217 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2218 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002219 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2221 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2222 }
2223 } else if (attrs.type == TYPE_INPUT_METHOD) {
2224 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002225 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 + attrs.token + ". Aborting.");
2227 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2228 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002229 } else if (attrs.type == TYPE_WALLPAPER) {
2230 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002231 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002232 + attrs.token + ". Aborting.");
2233 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235 }
2236
2237 win = new WindowState(session, client, token,
2238 attachedWindow, attrs, viewVisibility);
2239 if (win.mDeathRecipient == null) {
2240 // Client has apparently died, so there is no reason to
2241 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002242 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 + " that is dead, aborting.");
2244 return WindowManagerImpl.ADD_APP_EXITING;
2245 }
2246
2247 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002249 res = mPolicy.prepareAddWindowLw(win, attrs);
2250 if (res != WindowManagerImpl.ADD_OKAY) {
2251 return res;
2252 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002253
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002254 if (outInputChannel != null) {
2255 String name = win.makeInputChannelName();
2256 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2257 win.mInputChannel = inputChannels[0];
2258 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2259
2260 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262
2263 // From now on, no exceptions or errors allowed!
2264
2265 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002266
Dianne Hackborn5132b372010-07-29 12:51:35 -07002267 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002269 if (addToken) {
2270 mTokenMap.put(attrs.token, token);
2271 mTokenList.add(token);
2272 }
2273 win.attach();
2274 mWindowMap.put(client.asBinder(), win);
2275
2276 if (attrs.type == TYPE_APPLICATION_STARTING &&
2277 token.appWindowToken != null) {
2278 token.appWindowToken.startingWindow = win;
2279 }
2280
2281 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 if (attrs.type == TYPE_INPUT_METHOD) {
2284 mInputMethodWindow = win;
2285 addInputMethodWindowToListLocked(win);
2286 imMayMove = false;
2287 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2288 mInputMethodDialogs.add(win);
2289 addWindowToListInOrderLocked(win, true);
2290 adjustInputMethodDialogsLocked();
2291 imMayMove = false;
2292 } else {
2293 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002294 if (attrs.type == TYPE_WALLPAPER) {
2295 mLastWallpaperTimeoutTime = 0;
2296 adjustWallpaperWindowsLocked();
2297 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002298 adjustWallpaperWindowsLocked();
2299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 }
Romain Guy06882f82009-06-10 13:36:04 -07002301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 if (mInTouchMode) {
2307 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2308 }
2309 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2310 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2311 }
Romain Guy06882f82009-06-10 13:36:04 -07002312
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002313 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002315 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2316 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 imMayMove = false;
2318 }
2319 }
Romain Guy06882f82009-06-10 13:36:04 -07002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002322 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 }
Romain Guy06882f82009-06-10 13:36:04 -07002324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 assignLayersLocked();
2326 // Don't do layout here, the window must call
2327 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 //dump();
2330
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002331 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002332 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002333 }
Jeff Brown349703e2010-06-22 01:27:15 -07002334
Joe Onorato8a9b2202010-02-26 18:56:32 -08002335 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002336 TAG, "New client " + client.asBinder()
2337 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002338
2339 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2340 reportNewConfig = true;
2341 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 }
2343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 if (reportNewConfig) {
2345 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 return res;
2351 }
Romain Guy06882f82009-06-10 13:36:04 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 public void removeWindow(Session session, IWindow client) {
2354 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002355 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 if (win == null) {
2357 return;
2358 }
2359 removeWindowLocked(session, win);
2360 }
2361 }
Romain Guy06882f82009-06-10 13:36:04 -07002362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 public void removeWindowLocked(Session session, WindowState win) {
2364
Joe Onorato8a9b2202010-02-26 18:56:32 -08002365 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 TAG, "Remove " + win + " client="
2367 + Integer.toHexString(System.identityHashCode(
2368 win.mClient.asBinder()))
2369 + ", surface=" + win.mSurface);
2370
2371 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002372
2373 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002374
Joe Onorato8a9b2202010-02-26 18:56:32 -08002375 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2377 + " mExiting=" + win.mExiting
2378 + " isAnimating=" + win.isAnimating()
2379 + " app-animation="
2380 + (win.mAppToken != null ? win.mAppToken.animation : null)
2381 + " inPendingTransaction="
2382 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2383 + " mDisplayFrozen=" + mDisplayFrozen);
2384 // Visibility of the removed window. Will be used later to update orientation later on.
2385 boolean wasVisible = false;
2386 // First, see if we need to run an animation. If we do, we have
2387 // to hold off on removing the window until the animation is done.
2388 // If the display is frozen, just remove immediately, since the
2389 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002390 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 // If we are not currently running the exit animation, we
2392 // need to see about starting one.
2393 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2396 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2397 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2398 }
2399 // Try starting an animation.
2400 if (applyAnimationLocked(win, transit, false)) {
2401 win.mExiting = true;
2402 }
2403 }
2404 if (win.mExiting || win.isAnimating()) {
2405 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002406 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 win.mExiting = true;
2408 win.mRemoveOnExit = true;
2409 mLayoutNeeded = true;
2410 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2411 performLayoutAndPlaceSurfacesLocked();
2412 if (win.mAppToken != null) {
2413 win.mAppToken.updateReportedVisibilityLocked();
2414 }
2415 //dump();
2416 Binder.restoreCallingIdentity(origId);
2417 return;
2418 }
2419 }
2420
2421 removeWindowInnerLocked(session, win);
2422 // Removing a visible window will effect the computed orientation
2423 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002424 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002425 != mForcedAppOrientation
2426 && updateOrientationFromAppTokensLocked()) {
2427 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 }
2429 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2430 Binder.restoreCallingIdentity(origId);
2431 }
Romain Guy06882f82009-06-10 13:36:04 -07002432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 if (mInputMethodTarget == win) {
2437 moveInputMethodWindowsIfNeededLocked(false);
2438 }
Romain Guy06882f82009-06-10 13:36:04 -07002439
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002440 if (false) {
2441 RuntimeException e = new RuntimeException("here");
2442 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002443 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 mPolicy.removeWindowLw(win);
2447 win.removeLocked();
2448
2449 mWindowMap.remove(win.mClient.asBinder());
2450 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002451 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002452 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453
2454 if (mInputMethodWindow == win) {
2455 mInputMethodWindow = null;
2456 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2457 mInputMethodDialogs.remove(win);
2458 }
Romain Guy06882f82009-06-10 13:36:04 -07002459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 final WindowToken token = win.mToken;
2461 final AppWindowToken atoken = win.mAppToken;
2462 token.windows.remove(win);
2463 if (atoken != null) {
2464 atoken.allAppWindows.remove(win);
2465 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002466 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 TAG, "**** Removing window " + win + ": count="
2468 + token.windows.size());
2469 if (token.windows.size() == 0) {
2470 if (!token.explicit) {
2471 mTokenMap.remove(token.token);
2472 mTokenList.remove(token);
2473 } else if (atoken != null) {
2474 atoken.firstWindowDrawn = false;
2475 }
2476 }
2477
2478 if (atoken != null) {
2479 if (atoken.startingWindow == win) {
2480 atoken.startingWindow = null;
2481 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2482 // If this is the last window and we had requested a starting
2483 // transition window, well there is no point now.
2484 atoken.startingData = null;
2485 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2486 // If this is the last window except for a starting transition
2487 // window, we need to get rid of the starting transition.
2488 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002489 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 + ": no more real windows");
2491 }
2492 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2493 mH.sendMessage(m);
2494 }
2495 }
Romain Guy06882f82009-06-10 13:36:04 -07002496
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002497 if (win.mAttrs.type == TYPE_WALLPAPER) {
2498 mLastWallpaperTimeoutTime = 0;
2499 adjustWallpaperWindowsLocked();
2500 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002501 adjustWallpaperWindowsLocked();
2502 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 if (!mInLayout) {
2505 assignLayersLocked();
2506 mLayoutNeeded = true;
2507 performLayoutAndPlaceSurfacesLocked();
2508 if (win.mAppToken != null) {
2509 win.mAppToken.updateReportedVisibilityLocked();
2510 }
2511 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002512
2513 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 }
2515
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002516 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2517 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2518 + ": " + msg + " / " + w.mAttrs.getTitle();
2519 if (where != null) {
2520 Slog.i(TAG, str, where);
2521 } else {
2522 Slog.i(TAG, str);
2523 }
2524 }
2525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2527 long origId = Binder.clearCallingIdentity();
2528 try {
2529 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002530 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002532 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 Surface.openTransaction();
2534 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002535 if (SHOW_TRANSACTIONS) logSurface(w,
2536 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 w.mSurface.setTransparentRegionHint(region);
2538 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002539 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 Surface.closeTransaction();
2541 }
2542 }
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(origId);
2546 }
2547 }
2548
2549 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002550 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 Rect visibleInsets) {
2552 long origId = Binder.clearCallingIdentity();
2553 try {
2554 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002555 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 if (w != null) {
2557 w.mGivenInsetsPending = false;
2558 w.mGivenContentInsets.set(contentInsets);
2559 w.mGivenVisibleInsets.set(visibleInsets);
2560 w.mTouchableInsets = touchableInsets;
2561 mLayoutNeeded = true;
2562 performLayoutAndPlaceSurfacesLocked();
2563 }
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(origId);
2567 }
2568 }
Romain Guy06882f82009-06-10 13:36:04 -07002569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 public void getWindowDisplayFrame(Session session, IWindow client,
2571 Rect outDisplayFrame) {
2572 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002573 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 if (win == null) {
2575 outDisplayFrame.setEmpty();
2576 return;
2577 }
2578 outDisplayFrame.set(win.mDisplayFrame);
2579 }
2580 }
2581
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002582 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2583 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002584 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2585 window.mWallpaperX = x;
2586 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002587 window.mWallpaperXStep = xStep;
2588 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002589 if (updateWallpaperOffsetLocked(window, true)) {
2590 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002591 }
2592 }
2593 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002594
Dianne Hackborn75804932009-10-20 20:15:20 -07002595 void wallpaperCommandComplete(IBinder window, Bundle result) {
2596 synchronized (mWindowMap) {
2597 if (mWaitingOnWallpaper != null &&
2598 mWaitingOnWallpaper.mClient.asBinder() == window) {
2599 mWaitingOnWallpaper = null;
2600 mWindowMap.notifyAll();
2601 }
2602 }
2603 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002604
Dianne Hackborn75804932009-10-20 20:15:20 -07002605 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2606 String action, int x, int y, int z, Bundle extras, boolean sync) {
2607 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2608 || window == mUpperWallpaperTarget) {
2609 boolean doWait = sync;
2610 int curTokenIndex = mWallpaperTokens.size();
2611 while (curTokenIndex > 0) {
2612 curTokenIndex--;
2613 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2614 int curWallpaperIndex = token.windows.size();
2615 while (curWallpaperIndex > 0) {
2616 curWallpaperIndex--;
2617 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2618 try {
2619 wallpaper.mClient.dispatchWallpaperCommand(action,
2620 x, y, z, extras, sync);
2621 // We only want to be synchronous with one wallpaper.
2622 sync = false;
2623 } catch (RemoteException e) {
2624 }
2625 }
2626 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002627
Dianne Hackborn75804932009-10-20 20:15:20 -07002628 if (doWait) {
2629 // XXX Need to wait for result.
2630 }
2631 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002632
Dianne Hackborn75804932009-10-20 20:15:20 -07002633 return null;
2634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 public int relayoutWindow(Session session, IWindow client,
2637 WindowManager.LayoutParams attrs, int requestedWidth,
2638 int requestedHeight, int viewVisibility, boolean insetsPending,
2639 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002640 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 boolean displayed = false;
2642 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002643 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002647 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 if (win == null) {
2649 return 0;
2650 }
2651 win.mRequestedWidth = requestedWidth;
2652 win.mRequestedHeight = requestedHeight;
2653
2654 if (attrs != null) {
2655 mPolicy.adjustWindowParamsLw(attrs);
2656 }
Romain Guy06882f82009-06-10 13:36:04 -07002657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 int attrChanges = 0;
2659 int flagChanges = 0;
2660 if (attrs != null) {
2661 flagChanges = win.mAttrs.flags ^= attrs.flags;
2662 attrChanges = win.mAttrs.copyFrom(attrs);
2663 }
2664
Joe Onorato8a9b2202010-02-26 18:56:32 -08002665 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666
2667 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2668 win.mAlpha = attrs.alpha;
2669 }
2670
2671 final boolean scaledWindow =
2672 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2673
2674 if (scaledWindow) {
2675 // requested{Width|Height} Surface's physical size
2676 // attrs.{width|height} Size on screen
2677 win.mHScale = (attrs.width != requestedWidth) ?
2678 (attrs.width / (float)requestedWidth) : 1.0f;
2679 win.mVScale = (attrs.height != requestedHeight) ?
2680 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002681 } else {
2682 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 }
2684
2685 boolean imMayMove = (flagChanges&(
2686 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2687 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 boolean focusMayChange = win.mViewVisibility != viewVisibility
2690 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2691 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002692
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002693 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2694 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 win.mRelayoutCalled = true;
2697 final int oldVisibility = win.mViewVisibility;
2698 win.mViewVisibility = viewVisibility;
2699 if (viewVisibility == View.VISIBLE &&
2700 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2701 displayed = !win.isVisibleLw();
2702 if (win.mExiting) {
2703 win.mExiting = false;
2704 win.mAnimation = null;
2705 }
2706 if (win.mDestroying) {
2707 win.mDestroying = false;
2708 mDestroySurface.remove(win);
2709 }
2710 if (oldVisibility == View.GONE) {
2711 win.mEnterAnimationPending = true;
2712 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002713 if (displayed) {
2714 if (win.mSurface != null && !win.mDrawPending
2715 && !win.mCommitDrawPending && !mDisplayFrozen
2716 && mPolicy.isScreenOn()) {
2717 applyEnterAnimationLocked(win);
2718 }
2719 if ((win.mAttrs.flags
2720 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2721 if (DEBUG_VISIBILITY) Slog.v(TAG,
2722 "Relayout window turning screen on: " + win);
2723 win.mTurnOnScreen = true;
2724 }
2725 int diff = 0;
2726 if (win.mConfiguration != mCurConfiguration
2727 && (win.mConfiguration == null
2728 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2729 win.mConfiguration = mCurConfiguration;
2730 if (DEBUG_CONFIGURATION) {
2731 Slog.i(TAG, "Window " + win + " visible with new config: "
2732 + win.mConfiguration + " / 0x"
2733 + Integer.toHexString(diff));
2734 }
2735 outConfig.setTo(mCurConfiguration);
2736 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002737 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2739 // To change the format, we need to re-build the surface.
2740 win.destroySurfaceLocked();
2741 displayed = true;
2742 }
2743 try {
2744 Surface surface = win.createSurfaceLocked();
2745 if (surface != null) {
2746 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002747 win.mReportDestroySurface = false;
2748 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002749 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002750 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002752 // For some reason there isn't a surface. Clear the
2753 // caller's object so they see the same state.
2754 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 }
2756 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002757 mInputMonitor.updateInputWindowsLw();
2758
Joe Onorato8a9b2202010-02-26 18:56:32 -08002759 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002760 + client + " (" + win.mAttrs.getTitle() + ")",
2761 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 Binder.restoreCallingIdentity(origId);
2763 return 0;
2764 }
2765 if (displayed) {
2766 focusMayChange = true;
2767 }
2768 if (win.mAttrs.type == TYPE_INPUT_METHOD
2769 && mInputMethodWindow == null) {
2770 mInputMethodWindow = win;
2771 imMayMove = true;
2772 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002773 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2774 && win.mAppToken != null
2775 && win.mAppToken.startingWindow != null) {
2776 // Special handling of starting window over the base
2777 // window of the app: propagate lock screen flags to it,
2778 // to provide the correct semantics while starting.
2779 final int mask =
2780 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002781 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2782 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002783 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2784 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 } else {
2787 win.mEnterAnimationPending = false;
2788 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002789 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002790 + ": mExiting=" + win.mExiting
2791 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 // If we are not currently running the exit animation, we
2793 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002794 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 // Try starting an animation; if there isn't one, we
2796 // can destroy the surface right away.
2797 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2798 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2799 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2800 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002801 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002803 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 } else if (win.isAnimating()) {
2806 // Currently in a hide animation... turn this into
2807 // an exit.
2808 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002809 } else if (win == mWallpaperTarget) {
2810 // If the wallpaper is currently behind this
2811 // window, we need to change both of them inside
2812 // of a transaction to avoid artifacts.
2813 win.mExiting = true;
2814 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 } else {
2816 if (mInputMethodWindow == win) {
2817 mInputMethodWindow = null;
2818 }
2819 win.destroySurfaceLocked();
2820 }
2821 }
2822 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002823
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002824 if (win.mSurface == null || (win.getAttrs().flags
2825 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2826 || win.mSurfacePendingDestroy) {
2827 // We are being called from a local process, which
2828 // means outSurface holds its current surface. Ensure the
2829 // surface object is cleared, but we don't want it actually
2830 // destroyed at this point.
2831 win.mSurfacePendingDestroy = false;
2832 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002833 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002834 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002835 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002836 "Keeping surface, will report destroy: " + win);
2837 win.mReportDestroySurface = true;
2838 outSurface.copyFrom(win.mSurface);
2839 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 }
2841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 if (focusMayChange) {
2843 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2844 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 imMayMove = false;
2846 }
2847 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2848 }
Romain Guy06882f82009-06-10 13:36:04 -07002849
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002850 // updateFocusedWindowLocked() already assigned layers so we only need to
2851 // reassign them at this point if the IM window state gets shuffled
2852 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002855 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2856 // Little hack here -- we -should- be able to rely on the
2857 // function to return true if the IME has moved and needs
2858 // its layer recomputed. However, if the IME was hidden
2859 // and isn't actually moved in the list, its layer may be
2860 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 assignLayers = true;
2862 }
2863 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002864 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002865 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002866 assignLayers = true;
2867 }
2868 }
Romain Guy06882f82009-06-10 13:36:04 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 mLayoutNeeded = true;
2871 win.mGivenInsetsPending = insetsPending;
2872 if (assignLayers) {
2873 assignLayersLocked();
2874 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002875 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002877 if (displayed && win.mIsWallpaper) {
2878 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002879 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 if (win.mAppToken != null) {
2882 win.mAppToken.updateReportedVisibilityLocked();
2883 }
2884 outFrame.set(win.mFrame);
2885 outContentInsets.set(win.mContentInsets);
2886 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002887 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002889 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 + ", requestedHeight=" + requestedHeight
2891 + ", viewVisibility=" + viewVisibility
2892 + "\nRelayout returning frame=" + outFrame
2893 + ", surface=" + outSurface);
2894
Joe Onorato8a9b2202010-02-26 18:56:32 -08002895 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2897
2898 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002899
2900 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 }
2902
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002903 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 sendNewConfiguration();
2905 }
Romain Guy06882f82009-06-10 13:36:04 -07002906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2910 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2911 }
2912
2913 public void finishDrawingWindow(Session session, IWindow client) {
2914 final long origId = Binder.clearCallingIdentity();
2915 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002916 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002918 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2919 adjustWallpaperWindowsLocked();
2920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 mLayoutNeeded = true;
2922 performLayoutAndPlaceSurfacesLocked();
2923 }
2924 }
2925 Binder.restoreCallingIdentity(origId);
2926 }
2927
2928 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002929 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 + (lp != null ? lp.packageName : null)
2931 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2932 if (lp != null && lp.windowAnimations != 0) {
2933 // If this is a system resource, don't try to load it from the
2934 // application resources. It is nice to avoid loading application
2935 // resources if we can.
2936 String packageName = lp.packageName != null ? lp.packageName : "android";
2937 int resId = lp.windowAnimations;
2938 if ((resId&0xFF000000) == 0x01000000) {
2939 packageName = "android";
2940 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002941 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 + packageName);
2943 return AttributeCache.instance().get(packageName, resId,
2944 com.android.internal.R.styleable.WindowAnimation);
2945 }
2946 return null;
2947 }
Romain Guy06882f82009-06-10 13:36:04 -07002948
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002949 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002950 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002951 + packageName + " resId=0x" + Integer.toHexString(resId));
2952 if (packageName != null) {
2953 if ((resId&0xFF000000) == 0x01000000) {
2954 packageName = "android";
2955 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002956 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002957 + packageName);
2958 return AttributeCache.instance().get(packageName, resId,
2959 com.android.internal.R.styleable.WindowAnimation);
2960 }
2961 return null;
2962 }
2963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 private void applyEnterAnimationLocked(WindowState win) {
2965 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2966 if (win.mEnterAnimationPending) {
2967 win.mEnterAnimationPending = false;
2968 transit = WindowManagerPolicy.TRANSIT_ENTER;
2969 }
2970
2971 applyAnimationLocked(win, transit, true);
2972 }
2973
2974 private boolean applyAnimationLocked(WindowState win,
2975 int transit, boolean isEntrance) {
2976 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2977 // If we are trying to apply an animation, but already running
2978 // an animation of the same type, then just leave that one alone.
2979 return true;
2980 }
Romain Guy06882f82009-06-10 13:36:04 -07002981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 // Only apply an animation if the display isn't frozen. If it is
2983 // frozen, there is no reason to animate and it can cause strange
2984 // artifacts when we unfreeze the display if some different animation
2985 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002986 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 int anim = mPolicy.selectAnimationLw(win, transit);
2988 int attr = -1;
2989 Animation a = null;
2990 if (anim != 0) {
2991 a = AnimationUtils.loadAnimation(mContext, anim);
2992 } else {
2993 switch (transit) {
2994 case WindowManagerPolicy.TRANSIT_ENTER:
2995 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2996 break;
2997 case WindowManagerPolicy.TRANSIT_EXIT:
2998 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2999 break;
3000 case WindowManagerPolicy.TRANSIT_SHOW:
3001 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
3002 break;
3003 case WindowManagerPolicy.TRANSIT_HIDE:
3004 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
3005 break;
3006 }
3007 if (attr >= 0) {
3008 a = loadAnimation(win.mAttrs, attr);
3009 }
3010 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003011 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
3013 + " mAnimation=" + win.mAnimation
3014 + " isEntrance=" + isEntrance);
3015 if (a != null) {
3016 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003017 RuntimeException e = null;
3018 if (!HIDE_STACK_CRAWLS) {
3019 e = new RuntimeException();
3020 e.fillInStackTrace();
3021 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003022 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 }
3024 win.setAnimation(a);
3025 win.mAnimationIsEntrance = isEntrance;
3026 }
3027 } else {
3028 win.clearAnimation();
3029 }
3030
3031 return win.mAnimation != null;
3032 }
3033
3034 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3035 int anim = 0;
3036 Context context = mContext;
3037 if (animAttr >= 0) {
3038 AttributeCache.Entry ent = getCachedAnimations(lp);
3039 if (ent != null) {
3040 context = ent.context;
3041 anim = ent.array.getResourceId(animAttr, 0);
3042 }
3043 }
3044 if (anim != 0) {
3045 return AnimationUtils.loadAnimation(context, anim);
3046 }
3047 return null;
3048 }
Romain Guy06882f82009-06-10 13:36:04 -07003049
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003050 private Animation loadAnimation(String packageName, int resId) {
3051 int anim = 0;
3052 Context context = mContext;
3053 if (resId >= 0) {
3054 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3055 if (ent != null) {
3056 context = ent.context;
3057 anim = resId;
3058 }
3059 }
3060 if (anim != 0) {
3061 return AnimationUtils.loadAnimation(context, anim);
3062 }
3063 return null;
3064 }
3065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 private boolean applyAnimationLocked(AppWindowToken wtoken,
3067 WindowManager.LayoutParams lp, int transit, boolean enter) {
3068 // Only apply an animation if the display isn't frozen. If it is
3069 // frozen, there is no reason to animate and it can cause strange
3070 // artifacts when we unfreeze the display if some different animation
3071 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003072 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003073 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003074 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003075 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003076 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003077 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003078 } else if (mNextAppTransitionPackage != null) {
3079 a = loadAnimation(mNextAppTransitionPackage, enter ?
3080 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003081 } else {
3082 int animAttr = 0;
3083 switch (transit) {
3084 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3085 animAttr = enter
3086 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3087 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3088 break;
3089 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3090 animAttr = enter
3091 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3092 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3093 break;
3094 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3095 animAttr = enter
3096 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3097 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3098 break;
3099 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3100 animAttr = enter
3101 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3102 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3103 break;
3104 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3105 animAttr = enter
3106 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3107 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3108 break;
3109 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3110 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003111 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003112 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3113 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003114 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003115 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003116 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3117 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003118 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003119 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003120 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003121 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3122 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3123 break;
3124 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3125 animAttr = enter
3126 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3127 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3128 break;
3129 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3130 animAttr = enter
3131 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3132 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003133 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003134 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003135 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003136 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003137 + " anim=" + a
3138 + " animAttr=0x" + Integer.toHexString(animAttr)
3139 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 if (a != null) {
3142 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003143 RuntimeException e = null;
3144 if (!HIDE_STACK_CRAWLS) {
3145 e = new RuntimeException();
3146 e.fillInStackTrace();
3147 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003148 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 }
3150 wtoken.setAnimation(a);
3151 }
3152 } else {
3153 wtoken.clearAnimation();
3154 }
3155
3156 return wtoken.animation != null;
3157 }
3158
3159 // -------------------------------------------------------------
3160 // Application Window Tokens
3161 // -------------------------------------------------------------
3162
3163 public void validateAppTokens(List tokens) {
3164 int v = tokens.size()-1;
3165 int m = mAppTokens.size()-1;
3166 while (v >= 0 && m >= 0) {
3167 AppWindowToken wtoken = mAppTokens.get(m);
3168 if (wtoken.removed) {
3169 m--;
3170 continue;
3171 }
3172 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003173 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3175 }
3176 v--;
3177 m--;
3178 }
3179 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003180 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 v--;
3182 }
3183 while (m >= 0) {
3184 AppWindowToken wtoken = mAppTokens.get(m);
3185 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003186 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 }
3188 m--;
3189 }
3190 }
3191
3192 boolean checkCallingPermission(String permission, String func) {
3193 // Quick check: if the calling permission is me, it's all okay.
3194 if (Binder.getCallingPid() == Process.myPid()) {
3195 return true;
3196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 if (mContext.checkCallingPermission(permission)
3199 == PackageManager.PERMISSION_GRANTED) {
3200 return true;
3201 }
3202 String msg = "Permission Denial: " + func + " from pid="
3203 + Binder.getCallingPid()
3204 + ", uid=" + Binder.getCallingUid()
3205 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003206 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 return false;
3208 }
Romain Guy06882f82009-06-10 13:36:04 -07003209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 AppWindowToken findAppWindowToken(IBinder token) {
3211 WindowToken wtoken = mTokenMap.get(token);
3212 if (wtoken == null) {
3213 return null;
3214 }
3215 return wtoken.appWindowToken;
3216 }
Romain Guy06882f82009-06-10 13:36:04 -07003217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 public void addWindowToken(IBinder token, int type) {
3219 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3220 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003221 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 }
Romain Guy06882f82009-06-10 13:36:04 -07003223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 synchronized(mWindowMap) {
3225 WindowToken wtoken = mTokenMap.get(token);
3226 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003227 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 return;
3229 }
3230 wtoken = new WindowToken(token, type, true);
3231 mTokenMap.put(token, wtoken);
3232 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003233 if (type == TYPE_WALLPAPER) {
3234 mWallpaperTokens.add(wtoken);
3235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 }
3237 }
Romain Guy06882f82009-06-10 13:36:04 -07003238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 public void removeWindowToken(IBinder token) {
3240 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3241 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003242 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 }
3244
3245 final long origId = Binder.clearCallingIdentity();
3246 synchronized(mWindowMap) {
3247 WindowToken wtoken = mTokenMap.remove(token);
3248 mTokenList.remove(wtoken);
3249 if (wtoken != null) {
3250 boolean delayed = false;
3251 if (!wtoken.hidden) {
3252 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 final int N = wtoken.windows.size();
3255 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 for (int i=0; i<N; i++) {
3258 WindowState win = wtoken.windows.get(i);
3259
3260 if (win.isAnimating()) {
3261 delayed = true;
3262 }
Romain Guy06882f82009-06-10 13:36:04 -07003263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 if (win.isVisibleNow()) {
3265 applyAnimationLocked(win,
3266 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 changed = true;
3268 }
3269 }
3270
3271 if (changed) {
3272 mLayoutNeeded = true;
3273 performLayoutAndPlaceSurfacesLocked();
3274 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3275 }
Romain Guy06882f82009-06-10 13:36:04 -07003276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 if (delayed) {
3278 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003279 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3280 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 }
3282 }
Romain Guy06882f82009-06-10 13:36:04 -07003283
Jeff Brownc5ed5912010-07-14 18:48:53 -07003284 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003286 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003287 }
3288 }
3289 Binder.restoreCallingIdentity(origId);
3290 }
3291
3292 public void addAppToken(int addPos, IApplicationToken token,
3293 int groupId, int requestedOrientation, boolean fullscreen) {
3294 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3295 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003296 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
Jeff Brown349703e2010-06-22 01:27:15 -07003298
3299 // Get the dispatching timeout here while we are not holding any locks so that it
3300 // can be cached by the AppWindowToken. The timeout value is used later by the
3301 // input dispatcher in code that does hold locks. If we did not cache the value
3302 // here we would run the chance of introducing a deadlock between the window manager
3303 // (which holds locks while updating the input dispatcher state) and the activity manager
3304 // (which holds locks while querying the application token).
3305 long inputDispatchingTimeoutNanos;
3306 try {
3307 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3308 } catch (RemoteException ex) {
3309 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3310 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3311 }
Romain Guy06882f82009-06-10 13:36:04 -07003312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003313 synchronized(mWindowMap) {
3314 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3315 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003316 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 return;
3318 }
3319 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003320 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 wtoken.groupId = groupId;
3322 wtoken.appFullscreen = fullscreen;
3323 wtoken.requestedOrientation = requestedOrientation;
3324 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003325 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 mTokenMap.put(token.asBinder(), wtoken);
3327 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 // Application tokens start out hidden.
3330 wtoken.hidden = true;
3331 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 //dump();
3334 }
3335 }
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 public void setAppGroupId(IBinder token, int groupId) {
3338 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3339 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003340 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 }
3342
3343 synchronized(mWindowMap) {
3344 AppWindowToken wtoken = findAppWindowToken(token);
3345 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003346 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 return;
3348 }
3349 wtoken.groupId = groupId;
3350 }
3351 }
Romain Guy06882f82009-06-10 13:36:04 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 public int getOrientationFromWindowsLocked() {
3354 int pos = mWindows.size() - 1;
3355 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003356 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 pos--;
3358 if (wtoken.mAppToken != null) {
3359 // We hit an application window. so the orientation will be determined by the
3360 // app window. No point in continuing further.
3361 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3362 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003363 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003364 continue;
3365 }
3366 int req = wtoken.mAttrs.screenOrientation;
3367 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3368 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3369 continue;
3370 } else {
3371 return req;
3372 }
3373 }
3374 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3375 }
Romain Guy06882f82009-06-10 13:36:04 -07003376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003378 int pos = mAppTokens.size() - 1;
3379 int curGroup = 0;
3380 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3381 boolean findingBehind = false;
3382 boolean haveGroup = false;
3383 boolean lastFullscreen = false;
3384 while (pos >= 0) {
3385 AppWindowToken wtoken = mAppTokens.get(pos);
3386 pos--;
3387 // if we're about to tear down this window and not seek for
3388 // the behind activity, don't use it for orientation
3389 if (!findingBehind
3390 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3391 continue;
3392 }
3393
3394 if (!haveGroup) {
3395 // We ignore any hidden applications on the top.
3396 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003397 continue;
3398 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003399 haveGroup = true;
3400 curGroup = wtoken.groupId;
3401 lastOrientation = wtoken.requestedOrientation;
3402 } else if (curGroup != wtoken.groupId) {
3403 // If we have hit a new application group, and the bottom
3404 // of the previous group didn't explicitly say to use
3405 // the orientation behind it, and the last app was
3406 // full screen, then we'll stick with the
3407 // user's orientation.
3408 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3409 && lastFullscreen) {
3410 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003413 int or = wtoken.requestedOrientation;
3414 // If this application is fullscreen, and didn't explicitly say
3415 // to use the orientation behind it, then just take whatever
3416 // orientation it has and ignores whatever is under it.
3417 lastFullscreen = wtoken.appFullscreen;
3418 if (lastFullscreen
3419 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3420 return or;
3421 }
3422 // If this application has requested an explicit orientation,
3423 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003424 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3425 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003426 return or;
3427 }
3428 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3429 }
3430 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 }
Romain Guy06882f82009-06-10 13:36:04 -07003432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003434 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003435 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3436 "updateOrientationFromAppTokens()")) {
3437 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3438 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003439
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003440 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003442
3443 synchronized(mWindowMap) {
3444 if (updateOrientationFromAppTokensLocked()) {
3445 if (freezeThisOneIfNeeded != null) {
3446 AppWindowToken wtoken = findAppWindowToken(
3447 freezeThisOneIfNeeded);
3448 if (wtoken != null) {
3449 startAppFreezingScreenLocked(wtoken,
3450 ActivityInfo.CONFIG_ORIENTATION);
3451 }
3452 }
3453 config = computeNewConfigurationLocked();
3454
3455 } else if (currentConfig != null) {
3456 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003457 // state mismatches the activity manager's, update it,
3458 // disregarding font scale, which should remain set to
3459 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003460 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003461 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003462 if (computeNewConfigurationLocked(mTempConfiguration)) {
3463 if (currentConfig.diff(mTempConfiguration) != 0) {
3464 mWaitingForConfig = true;
3465 mLayoutNeeded = true;
3466 startFreezingDisplayLocked();
3467 config = new Configuration(mTempConfiguration);
3468 }
3469 }
3470 }
3471 }
3472
Dianne Hackborncfaef692009-06-15 14:24:44 -07003473 Binder.restoreCallingIdentity(ident);
3474 return config;
3475 }
3476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003477 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003478 * Determine the new desired orientation of the display, returning
3479 * a non-null new Configuration if it has changed from the current
3480 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3481 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3482 * SCREEN. This will typically be done for you if you call
3483 * sendNewConfiguration().
3484 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 * The orientation is computed from non-application windows first. If none of
3486 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003487 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3489 * android.os.IBinder)
3490 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003491 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003492 if (mDisplayFrozen) {
3493 // If the display is frozen, some activities may be in the middle
3494 // of restarting, and thus have removed their old window. If the
3495 // window has the flag to hide the lock screen, then the lock screen
3496 // can re-appear and inflict its own orientation on us. Keep the
3497 // orientation stable until this all settles down.
3498 return false;
3499 }
3500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 long ident = Binder.clearCallingIdentity();
3503 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003504 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 mForcedAppOrientation = req;
3508 //send a message to Policy indicating orientation change to take
3509 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003510 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003511 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3512 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3513 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 }
3515 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003516
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003517 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 } finally {
3519 Binder.restoreCallingIdentity(ident);
3520 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 }
Romain Guy06882f82009-06-10 13:36:04 -07003522
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003523 int computeForcedAppOrientationLocked() {
3524 int req = getOrientationFromWindowsLocked();
3525 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3526 req = getOrientationFromAppTokensLocked();
3527 }
3528 return req;
3529 }
Romain Guy06882f82009-06-10 13:36:04 -07003530
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003531 public void setNewConfiguration(Configuration config) {
3532 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3533 "setNewConfiguration()")) {
3534 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3535 }
3536
3537 synchronized(mWindowMap) {
3538 mCurConfiguration = new Configuration(config);
3539 mWaitingForConfig = false;
3540 performLayoutAndPlaceSurfacesLocked();
3541 }
3542 }
3543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3545 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3546 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003547 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 }
Romain Guy06882f82009-06-10 13:36:04 -07003549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 synchronized(mWindowMap) {
3551 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3552 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003553 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 return;
3555 }
Romain Guy06882f82009-06-10 13:36:04 -07003556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 wtoken.requestedOrientation = requestedOrientation;
3558 }
3559 }
Romain Guy06882f82009-06-10 13:36:04 -07003560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 public int getAppOrientation(IApplicationToken token) {
3562 synchronized(mWindowMap) {
3563 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3564 if (wtoken == null) {
3565 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3566 }
Romain Guy06882f82009-06-10 13:36:04 -07003567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 return wtoken.requestedOrientation;
3569 }
3570 }
Romain Guy06882f82009-06-10 13:36:04 -07003571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3573 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3574 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003575 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 }
3577
3578 synchronized(mWindowMap) {
3579 boolean changed = false;
3580 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003581 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 changed = mFocusedApp != null;
3583 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003584 if (changed) {
3585 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 } else {
3588 AppWindowToken newFocus = findAppWindowToken(token);
3589 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003590 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 return;
3592 }
3593 changed = mFocusedApp != newFocus;
3594 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003595 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003596 if (changed) {
3597 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 }
3600
3601 if (moveFocusNow && changed) {
3602 final long origId = Binder.clearCallingIdentity();
3603 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3604 Binder.restoreCallingIdentity(origId);
3605 }
3606 }
3607 }
3608
3609 public void prepareAppTransition(int transit) {
3610 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3611 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003612 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 }
Romain Guy06882f82009-06-10 13:36:04 -07003614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003616 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 TAG, "Prepare app transition: transit=" + transit
3618 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003619 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003620 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3621 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003623 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3624 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3625 // Opening a new task always supersedes a close for the anim.
3626 mNextAppTransition = transit;
3627 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3628 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3629 // Opening a new activity always supersedes a close for the anim.
3630 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 }
3632 mAppTransitionReady = false;
3633 mAppTransitionTimeout = false;
3634 mStartingIconInTransition = false;
3635 mSkipAppTransitionAnimation = false;
3636 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3637 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3638 5000);
3639 }
3640 }
3641 }
3642
3643 public int getPendingAppTransition() {
3644 return mNextAppTransition;
3645 }
Romain Guy06882f82009-06-10 13:36:04 -07003646
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003647 public void overridePendingAppTransition(String packageName,
3648 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003649 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003650 mNextAppTransitionPackage = packageName;
3651 mNextAppTransitionEnter = enterAnim;
3652 mNextAppTransitionExit = exitAnim;
3653 }
3654 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 public void executeAppTransition() {
3657 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3658 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003659 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 }
Romain Guy06882f82009-06-10 13:36:04 -07003661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003663 if (DEBUG_APP_TRANSITIONS) {
3664 RuntimeException e = new RuntimeException("here");
3665 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003666 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003667 + mNextAppTransition, e);
3668 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003669 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 mAppTransitionReady = true;
3671 final long origId = Binder.clearCallingIdentity();
3672 performLayoutAndPlaceSurfacesLocked();
3673 Binder.restoreCallingIdentity(origId);
3674 }
3675 }
3676 }
3677
3678 public void setAppStartingWindow(IBinder token, String pkg,
3679 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3680 IBinder transferFrom, boolean createIfNeeded) {
3681 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3682 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003683 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 }
3685
3686 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003687 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3689 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 AppWindowToken wtoken = findAppWindowToken(token);
3692 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003693 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 return;
3695 }
3696
3697 // If the display is frozen, we won't do anything until the
3698 // actual window is displayed so there is no reason to put in
3699 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003700 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 return;
3702 }
Romain Guy06882f82009-06-10 13:36:04 -07003703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 if (wtoken.startingData != null) {
3705 return;
3706 }
Romain Guy06882f82009-06-10 13:36:04 -07003707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 if (transferFrom != null) {
3709 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3710 if (ttoken != null) {
3711 WindowState startingWindow = ttoken.startingWindow;
3712 if (startingWindow != null) {
3713 if (mStartingIconInTransition) {
3714 // In this case, the starting icon has already
3715 // been displayed, so start letting windows get
3716 // shown immediately without any more transitions.
3717 mSkipAppTransitionAnimation = true;
3718 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003719 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 "Moving existing starting from " + ttoken
3721 + " to " + wtoken);
3722 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 // Transfer the starting window over to the new
3725 // token.
3726 wtoken.startingData = ttoken.startingData;
3727 wtoken.startingView = ttoken.startingView;
3728 wtoken.startingWindow = startingWindow;
3729 ttoken.startingData = null;
3730 ttoken.startingView = null;
3731 ttoken.startingWindow = null;
3732 ttoken.startingMoved = true;
3733 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003734 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003736 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003737 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003739 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 ttoken.windows.remove(startingWindow);
3741 ttoken.allAppWindows.remove(startingWindow);
3742 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 // Propagate other interesting state between the
3745 // tokens. If the old token is displayed, we should
3746 // immediately force the new one to be displayed. If
3747 // it is animating, we need to move that animation to
3748 // the new one.
3749 if (ttoken.allDrawn) {
3750 wtoken.allDrawn = true;
3751 }
3752 if (ttoken.firstWindowDrawn) {
3753 wtoken.firstWindowDrawn = true;
3754 }
3755 if (!ttoken.hidden) {
3756 wtoken.hidden = false;
3757 wtoken.hiddenRequested = false;
3758 wtoken.willBeHidden = false;
3759 }
3760 if (wtoken.clientHidden != ttoken.clientHidden) {
3761 wtoken.clientHidden = ttoken.clientHidden;
3762 wtoken.sendAppVisibilityToClients();
3763 }
3764 if (ttoken.animation != null) {
3765 wtoken.animation = ttoken.animation;
3766 wtoken.animating = ttoken.animating;
3767 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3768 ttoken.animation = null;
3769 ttoken.animLayerAdjustment = 0;
3770 wtoken.updateLayers();
3771 ttoken.updateLayers();
3772 }
Romain Guy06882f82009-06-10 13:36:04 -07003773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 mLayoutNeeded = true;
3776 performLayoutAndPlaceSurfacesLocked();
3777 Binder.restoreCallingIdentity(origId);
3778 return;
3779 } else if (ttoken.startingData != null) {
3780 // The previous app was getting ready to show a
3781 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003782 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 "Moving pending starting from " + ttoken
3784 + " to " + wtoken);
3785 wtoken.startingData = ttoken.startingData;
3786 ttoken.startingData = null;
3787 ttoken.startingMoved = true;
3788 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3789 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3790 // want to process the message ASAP, before any other queued
3791 // messages.
3792 mH.sendMessageAtFrontOfQueue(m);
3793 return;
3794 }
3795 }
3796 }
3797
3798 // There is no existing starting window, and the caller doesn't
3799 // want us to create one, so that's it!
3800 if (!createIfNeeded) {
3801 return;
3802 }
Romain Guy06882f82009-06-10 13:36:04 -07003803
Dianne Hackborn284ac932009-08-28 10:34:25 -07003804 // If this is a translucent or wallpaper window, then don't
3805 // show a starting window -- the current effect (a full-screen
3806 // opaque starting window that fades away to the real contents
3807 // when it is ready) does not work for this.
3808 if (theme != 0) {
3809 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3810 com.android.internal.R.styleable.Window);
3811 if (ent.array.getBoolean(
3812 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3813 return;
3814 }
3815 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003816 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3817 return;
3818 }
3819 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003820 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3821 return;
3822 }
3823 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 mStartingIconInTransition = true;
3826 wtoken.startingData = new StartingData(
3827 pkg, theme, nonLocalizedLabel,
3828 labelRes, icon);
3829 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3830 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3831 // want to process the message ASAP, before any other queued
3832 // messages.
3833 mH.sendMessageAtFrontOfQueue(m);
3834 }
3835 }
3836
3837 public void setAppWillBeHidden(IBinder token) {
3838 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3839 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003840 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 }
3842
3843 AppWindowToken wtoken;
3844
3845 synchronized(mWindowMap) {
3846 wtoken = findAppWindowToken(token);
3847 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003848 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 -08003849 return;
3850 }
3851 wtoken.willBeHidden = true;
3852 }
3853 }
Romain Guy06882f82009-06-10 13:36:04 -07003854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3856 boolean visible, int transit, boolean performLayout) {
3857 boolean delayed = false;
3858
3859 if (wtoken.clientHidden == visible) {
3860 wtoken.clientHidden = !visible;
3861 wtoken.sendAppVisibilityToClients();
3862 }
Romain Guy06882f82009-06-10 13:36:04 -07003863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 wtoken.willBeHidden = false;
3865 if (wtoken.hidden == visible) {
3866 final int N = wtoken.allAppWindows.size();
3867 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003868 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3870 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003872 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003873
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003874 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 if (wtoken.animation == sDummyAnimation) {
3876 wtoken.animation = null;
3877 }
3878 applyAnimationLocked(wtoken, lp, transit, visible);
3879 changed = true;
3880 if (wtoken.animation != null) {
3881 delayed = runningAppAnimation = true;
3882 }
3883 }
Romain Guy06882f82009-06-10 13:36:04 -07003884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 for (int i=0; i<N; i++) {
3886 WindowState win = wtoken.allAppWindows.get(i);
3887 if (win == wtoken.startingWindow) {
3888 continue;
3889 }
3890
3891 if (win.isAnimating()) {
3892 delayed = true;
3893 }
Romain Guy06882f82009-06-10 13:36:04 -07003894
Joe Onorato8a9b2202010-02-26 18:56:32 -08003895 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 //win.dump(" ");
3897 if (visible) {
3898 if (!win.isVisibleNow()) {
3899 if (!runningAppAnimation) {
3900 applyAnimationLocked(win,
3901 WindowManagerPolicy.TRANSIT_ENTER, true);
3902 }
3903 changed = true;
3904 }
3905 } else if (win.isVisibleNow()) {
3906 if (!runningAppAnimation) {
3907 applyAnimationLocked(win,
3908 WindowManagerPolicy.TRANSIT_EXIT, false);
3909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 changed = true;
3911 }
3912 }
3913
3914 wtoken.hidden = wtoken.hiddenRequested = !visible;
3915 if (!visible) {
3916 unsetAppFreezingScreenLocked(wtoken, true, true);
3917 } else {
3918 // If we are being set visible, and the starting window is
3919 // not yet displayed, then make sure it doesn't get displayed.
3920 WindowState swin = wtoken.startingWindow;
3921 if (swin != null && (swin.mDrawPending
3922 || swin.mCommitDrawPending)) {
3923 swin.mPolicyVisibility = false;
3924 swin.mPolicyVisibilityAfterAnim = false;
3925 }
3926 }
Romain Guy06882f82009-06-10 13:36:04 -07003927
Joe Onorato8a9b2202010-02-26 18:56:32 -08003928 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3930 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003931
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003932 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003934 if (performLayout) {
3935 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3936 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003937 } else {
3938 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 }
3941 }
3942
3943 if (wtoken.animation != null) {
3944 delayed = true;
3945 }
Romain Guy06882f82009-06-10 13:36:04 -07003946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003947 return delayed;
3948 }
3949
3950 public void setAppVisibility(IBinder token, boolean visible) {
3951 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3952 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003953 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 }
3955
3956 AppWindowToken wtoken;
3957
3958 synchronized(mWindowMap) {
3959 wtoken = findAppWindowToken(token);
3960 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003961 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003962 return;
3963 }
3964
3965 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003966 RuntimeException e = null;
3967 if (!HIDE_STACK_CRAWLS) {
3968 e = new RuntimeException();
3969 e.fillInStackTrace();
3970 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003971 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 + "): mNextAppTransition=" + mNextAppTransition
3973 + " hidden=" + wtoken.hidden
3974 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3975 }
Romain Guy06882f82009-06-10 13:36:04 -07003976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 // If we are preparing an app transition, then delay changing
3978 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003979 if (!mDisplayFrozen && mPolicy.isScreenOn()
3980 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 // Already in requested state, don't do anything more.
3982 if (wtoken.hiddenRequested != visible) {
3983 return;
3984 }
3985 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003986
Joe Onorato8a9b2202010-02-26 18:56:32 -08003987 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 TAG, "Setting dummy animation on: " + wtoken);
3989 wtoken.setDummyAnimation();
3990 mOpeningApps.remove(wtoken);
3991 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003992 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 wtoken.inPendingTransaction = true;
3994 if (visible) {
3995 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 wtoken.startingDisplayed = false;
3997 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003998
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003999 // If the token is currently hidden (should be the
4000 // common case), then we need to set up to wait for
4001 // its windows to be ready.
4002 if (wtoken.hidden) {
4003 wtoken.allDrawn = false;
4004 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004005
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004006 if (wtoken.clientHidden) {
4007 // In the case where we are making an app visible
4008 // but holding off for a transition, we still need
4009 // to tell the client to make its windows visible so
4010 // they get drawn. Otherwise, we will wait on
4011 // performing the transition until all windows have
4012 // been drawn, they never will be, and we are sad.
4013 wtoken.clientHidden = false;
4014 wtoken.sendAppVisibilityToClients();
4015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 }
4017 } else {
4018 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004019
Dianne Hackborn195f6a02009-11-24 11:26:00 -08004020 // If the token is currently visible (should be the
4021 // common case), then set up to wait for it to be hidden.
4022 if (!wtoken.hidden) {
4023 wtoken.waitingToHide = true;
4024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004025 }
4026 return;
4027 }
Romain Guy06882f82009-06-10 13:36:04 -07004028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004030 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 wtoken.updateReportedVisibilityLocked();
4032 Binder.restoreCallingIdentity(origId);
4033 }
4034 }
4035
4036 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4037 boolean unfreezeSurfaceNow, boolean force) {
4038 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004039 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 + " force=" + force);
4041 final int N = wtoken.allAppWindows.size();
4042 boolean unfrozeWindows = false;
4043 for (int i=0; i<N; i++) {
4044 WindowState w = wtoken.allAppWindows.get(i);
4045 if (w.mAppFreezing) {
4046 w.mAppFreezing = false;
4047 if (w.mSurface != null && !w.mOrientationChanging) {
4048 w.mOrientationChanging = true;
4049 }
4050 unfrozeWindows = true;
4051 }
4052 }
4053 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004054 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004055 wtoken.freezingScreen = false;
4056 mAppsFreezingScreen--;
4057 }
4058 if (unfreezeSurfaceNow) {
4059 if (unfrozeWindows) {
4060 mLayoutNeeded = true;
4061 performLayoutAndPlaceSurfacesLocked();
4062 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004063 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 }
4065 }
4066 }
Romain Guy06882f82009-06-10 13:36:04 -07004067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4069 int configChanges) {
4070 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004071 RuntimeException e = null;
4072 if (!HIDE_STACK_CRAWLS) {
4073 e = new RuntimeException();
4074 e.fillInStackTrace();
4075 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004076 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 + ": hidden=" + wtoken.hidden + " freezing="
4078 + wtoken.freezingScreen, e);
4079 }
4080 if (!wtoken.hiddenRequested) {
4081 if (!wtoken.freezingScreen) {
4082 wtoken.freezingScreen = true;
4083 mAppsFreezingScreen++;
4084 if (mAppsFreezingScreen == 1) {
4085 startFreezingDisplayLocked();
4086 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4087 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4088 5000);
4089 }
4090 }
4091 final int N = wtoken.allAppWindows.size();
4092 for (int i=0; i<N; i++) {
4093 WindowState w = wtoken.allAppWindows.get(i);
4094 w.mAppFreezing = true;
4095 }
4096 }
4097 }
Romain Guy06882f82009-06-10 13:36:04 -07004098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004099 public void startAppFreezingScreen(IBinder token, int configChanges) {
4100 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4101 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004102 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 }
4104
4105 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004106 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004107 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 return;
4109 }
Romain Guy06882f82009-06-10 13:36:04 -07004110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 AppWindowToken wtoken = findAppWindowToken(token);
4112 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004113 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 return;
4115 }
4116 final long origId = Binder.clearCallingIdentity();
4117 startAppFreezingScreenLocked(wtoken, configChanges);
4118 Binder.restoreCallingIdentity(origId);
4119 }
4120 }
Romain Guy06882f82009-06-10 13:36:04 -07004121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004122 public void stopAppFreezingScreen(IBinder token, boolean force) {
4123 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4124 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004125 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126 }
4127
4128 synchronized(mWindowMap) {
4129 AppWindowToken wtoken = findAppWindowToken(token);
4130 if (wtoken == null || wtoken.appToken == null) {
4131 return;
4132 }
4133 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004134 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4136 unsetAppFreezingScreenLocked(wtoken, true, force);
4137 Binder.restoreCallingIdentity(origId);
4138 }
4139 }
Romain Guy06882f82009-06-10 13:36:04 -07004140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 public void removeAppToken(IBinder token) {
4142 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4143 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004144 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 }
4146
4147 AppWindowToken wtoken = null;
4148 AppWindowToken startingToken = null;
4149 boolean delayed = false;
4150
4151 final long origId = Binder.clearCallingIdentity();
4152 synchronized(mWindowMap) {
4153 WindowToken basewtoken = mTokenMap.remove(token);
4154 mTokenList.remove(basewtoken);
4155 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004156 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004157 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 wtoken.inPendingTransaction = false;
4159 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004160 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 if (mClosingApps.contains(wtoken)) {
4162 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004163 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004165 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 delayed = true;
4167 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004168 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004169 TAG, "Removing app " + wtoken + " delayed=" + delayed
4170 + " animation=" + wtoken.animation
4171 + " animating=" + wtoken.animating);
4172 if (delayed) {
4173 // set the token aside because it has an active animation to be finished
4174 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004175 } else {
4176 // Make sure there is no animation running on this token,
4177 // so any windows associated with it will be removed as
4178 // soon as their animations are complete
4179 wtoken.animation = null;
4180 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 }
4182 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004183 if (mLastEnterAnimToken == wtoken) {
4184 mLastEnterAnimToken = null;
4185 mLastEnterAnimParams = null;
4186 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 wtoken.removed = true;
4188 if (wtoken.startingData != null) {
4189 startingToken = wtoken;
4190 }
4191 unsetAppFreezingScreenLocked(wtoken, true, true);
4192 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004193 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 mFocusedApp = null;
4195 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004196 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 }
4198 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004199 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200 }
Romain Guy06882f82009-06-10 13:36:04 -07004201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004202 if (!delayed && wtoken != null) {
4203 wtoken.updateReportedVisibilityLocked();
4204 }
4205 }
4206 Binder.restoreCallingIdentity(origId);
4207
4208 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004209 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 + startingToken + ": app token removed");
4211 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4212 mH.sendMessage(m);
4213 }
4214 }
4215
4216 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4217 final int NW = token.windows.size();
4218 for (int i=0; i<NW; i++) {
4219 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004220 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004222 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004223 int j = win.mChildWindows.size();
4224 while (j > 0) {
4225 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004226 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004227 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004228 "Tmp removing child window " + cwin);
4229 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004230 }
4231 }
4232 return NW > 0;
4233 }
4234
4235 void dumpAppTokensLocked() {
4236 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004237 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 }
4239 }
Romain Guy06882f82009-06-10 13:36:04 -07004240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004241 void dumpWindowsLocked() {
4242 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004243 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 }
4245 }
Romain Guy06882f82009-06-10 13:36:04 -07004246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004247 private int findWindowOffsetLocked(int tokenPos) {
4248 final int NW = mWindows.size();
4249
4250 if (tokenPos >= mAppTokens.size()) {
4251 int i = NW;
4252 while (i > 0) {
4253 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004254 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 if (win.getAppToken() != null) {
4256 return i+1;
4257 }
4258 }
4259 }
4260
4261 while (tokenPos > 0) {
4262 // Find the first app token below the new position that has
4263 // a window displayed.
4264 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004265 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004267 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004268 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004269 "Skipping token -- currently sending to bottom");
4270 tokenPos--;
4271 continue;
4272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 int i = wtoken.windows.size();
4274 while (i > 0) {
4275 i--;
4276 WindowState win = wtoken.windows.get(i);
4277 int j = win.mChildWindows.size();
4278 while (j > 0) {
4279 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004280 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004281 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 for (int pos=NW-1; pos>=0; pos--) {
4283 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004284 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 "Found child win @" + (pos+1));
4286 return pos+1;
4287 }
4288 }
4289 }
4290 }
4291 for (int pos=NW-1; pos>=0; pos--) {
4292 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004293 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 return pos+1;
4295 }
4296 }
4297 }
4298 tokenPos--;
4299 }
4300
4301 return 0;
4302 }
4303
4304 private final int reAddWindowLocked(int index, WindowState win) {
4305 final int NCW = win.mChildWindows.size();
4306 boolean added = false;
4307 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004308 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004310 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004311 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 mWindows.add(index, win);
4313 index++;
4314 added = true;
4315 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004316 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004317 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 mWindows.add(index, cwin);
4319 index++;
4320 }
4321 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004322 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004323 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 mWindows.add(index, win);
4325 index++;
4326 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004327 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 return index;
4329 }
Romain Guy06882f82009-06-10 13:36:04 -07004330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4332 final int NW = token.windows.size();
4333 for (int i=0; i<NW; i++) {
4334 index = reAddWindowLocked(index, token.windows.get(i));
4335 }
4336 return index;
4337 }
4338
4339 public void moveAppToken(int index, IBinder token) {
4340 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4341 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004342 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 }
4344
4345 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004346 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 if (DEBUG_REORDER) dumpAppTokensLocked();
4348 final AppWindowToken wtoken = findAppWindowToken(token);
4349 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004350 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 + token + " (" + wtoken + ")");
4352 return;
4353 }
4354 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004355 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004359 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 if (DEBUG_REORDER) dumpWindowsLocked();
4361 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004362 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 if (DEBUG_REORDER) dumpWindowsLocked();
4364 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004365 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 if (DEBUG_REORDER) dumpWindowsLocked();
4367 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 mLayoutNeeded = true;
4369 performLayoutAndPlaceSurfacesLocked();
4370 }
4371 Binder.restoreCallingIdentity(origId);
4372 }
4373 }
4374
4375 private void removeAppTokensLocked(List<IBinder> tokens) {
4376 // XXX This should be done more efficiently!
4377 // (take advantage of the fact that both lists should be
4378 // ordered in the same way.)
4379 int N = tokens.size();
4380 for (int i=0; i<N; i++) {
4381 IBinder token = tokens.get(i);
4382 final AppWindowToken wtoken = findAppWindowToken(token);
4383 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004384 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 + token + " (" + wtoken + ")");
4386 i--;
4387 N--;
4388 }
4389 }
4390 }
4391
Dianne Hackborna8f60182009-09-01 19:01:50 -07004392 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4393 boolean updateFocusAndLayout) {
4394 // First remove all of the windows from the list.
4395 tmpRemoveAppWindowsLocked(wtoken);
4396
4397 // Where to start adding?
4398 int pos = findWindowOffsetLocked(tokenPos);
4399
4400 // And now add them back at the correct place.
4401 pos = reAddAppWindowsLocked(pos, wtoken);
4402
4403 if (updateFocusAndLayout) {
4404 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4405 assignLayersLocked();
4406 }
4407 mLayoutNeeded = true;
4408 performLayoutAndPlaceSurfacesLocked();
4409 }
4410 }
4411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004412 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4413 // First remove all of the windows from the list.
4414 final int N = tokens.size();
4415 int i;
4416 for (i=0; i<N; i++) {
4417 WindowToken token = mTokenMap.get(tokens.get(i));
4418 if (token != null) {
4419 tmpRemoveAppWindowsLocked(token);
4420 }
4421 }
4422
4423 // Where to start adding?
4424 int pos = findWindowOffsetLocked(tokenPos);
4425
4426 // And now add them back at the correct place.
4427 for (i=0; i<N; i++) {
4428 WindowToken token = mTokenMap.get(tokens.get(i));
4429 if (token != null) {
4430 pos = reAddAppWindowsLocked(pos, token);
4431 }
4432 }
4433
Dianne Hackborna8f60182009-09-01 19:01:50 -07004434 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4435 assignLayersLocked();
4436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 mLayoutNeeded = true;
4438 performLayoutAndPlaceSurfacesLocked();
4439
4440 //dump();
4441 }
4442
4443 public void moveAppTokensToTop(List<IBinder> tokens) {
4444 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4445 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004446 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 }
4448
4449 final long origId = Binder.clearCallingIdentity();
4450 synchronized(mWindowMap) {
4451 removeAppTokensLocked(tokens);
4452 final int N = tokens.size();
4453 for (int i=0; i<N; i++) {
4454 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4455 if (wt != null) {
4456 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004457 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004458 mToTopApps.remove(wt);
4459 mToBottomApps.remove(wt);
4460 mToTopApps.add(wt);
4461 wt.sendingToBottom = false;
4462 wt.sendingToTop = true;
4463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 }
4465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004466
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004467 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004468 moveAppWindowsLocked(tokens, mAppTokens.size());
4469 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 }
4471 Binder.restoreCallingIdentity(origId);
4472 }
4473
4474 public void moveAppTokensToBottom(List<IBinder> tokens) {
4475 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4476 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004477 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 }
4479
4480 final long origId = Binder.clearCallingIdentity();
4481 synchronized(mWindowMap) {
4482 removeAppTokensLocked(tokens);
4483 final int N = tokens.size();
4484 int pos = 0;
4485 for (int i=0; i<N; i++) {
4486 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4487 if (wt != null) {
4488 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004489 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004490 mToTopApps.remove(wt);
4491 mToBottomApps.remove(wt);
4492 mToBottomApps.add(i, wt);
4493 wt.sendingToTop = false;
4494 wt.sendingToBottom = true;
4495 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 pos++;
4497 }
4498 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004499
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004500 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004501 moveAppWindowsLocked(tokens, 0);
4502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503 }
4504 Binder.restoreCallingIdentity(origId);
4505 }
4506
4507 // -------------------------------------------------------------
4508 // Misc IWindowSession methods
4509 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004510
Jim Miller284b62e2010-06-08 14:27:42 -07004511 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004512 {
Jim Miller284b62e2010-06-08 14:27:42 -07004513 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4514 // called before DevicePolicyManagerService has started.
4515 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4516 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4517 Context.DEVICE_POLICY_SERVICE);
4518 if (dpm != null) {
4519 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4520 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4521 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4522 }
Jim Millerd6b57052010-06-07 17:52:42 -07004523 }
Jim Miller284b62e2010-06-08 14:27:42 -07004524 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004525 }
4526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004528 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 != PackageManager.PERMISSION_GRANTED) {
4530 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4531 }
Jim Millerd6b57052010-06-07 17:52:42 -07004532
Jim Miller284b62e2010-06-08 14:27:42 -07004533 synchronized (mKeyguardTokenWatcher) {
4534 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004536 }
4537
4538 public void reenableKeyguard(IBinder token) {
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 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543
Jim Miller284b62e2010-06-08 14:27:42 -07004544 synchronized (mKeyguardTokenWatcher) {
4545 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004546
Jim Miller284b62e2010-06-08 14:27:42 -07004547 if (!mKeyguardTokenWatcher.isAcquired()) {
4548 // If we are the last one to reenable the keyguard wait until
4549 // we have actually finished reenabling until returning.
4550 // It is possible that reenableKeyguard() can be called before
4551 // the previous disableKeyguard() is handled, in which case
4552 // neither mKeyguardTokenWatcher.acquired() or released() would
4553 // be called. In that case mKeyguardDisabled will be false here
4554 // and we have nothing to wait for.
4555 while (mKeyguardDisabled) {
4556 try {
4557 mKeyguardTokenWatcher.wait();
4558 } catch (InterruptedException e) {
4559 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004560 }
4561 }
4562 }
4563 }
4564 }
4565
4566 /**
4567 * @see android.app.KeyguardManager#exitKeyguardSecurely
4568 */
4569 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004570 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 != PackageManager.PERMISSION_GRANTED) {
4572 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4573 }
4574 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4575 public void onKeyguardExitResult(boolean success) {
4576 try {
4577 callback.onKeyguardExitResult(success);
4578 } catch (RemoteException e) {
4579 // Client has died, we don't care.
4580 }
4581 }
4582 });
4583 }
4584
4585 public boolean inKeyguardRestrictedInputMode() {
4586 return mPolicy.inKeyguardRestrictedKeyInputMode();
4587 }
Romain Guy06882f82009-06-10 13:36:04 -07004588
Dianne Hackbornffa42482009-09-23 22:20:11 -07004589 public void closeSystemDialogs(String reason) {
4590 synchronized(mWindowMap) {
4591 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004592 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004593 if (w.mSurface != null) {
4594 try {
4595 w.mClient.closeSystemDialogs(reason);
4596 } catch (RemoteException e) {
4597 }
4598 }
4599 }
4600 }
4601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004603 static float fixScale(float scale) {
4604 if (scale < 0) scale = 0;
4605 else if (scale > 20) scale = 20;
4606 return Math.abs(scale);
4607 }
Romain Guy06882f82009-06-10 13:36:04 -07004608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004609 public void setAnimationScale(int which, float scale) {
4610 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4611 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004612 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 }
4614
4615 if (scale < 0) scale = 0;
4616 else if (scale > 20) scale = 20;
4617 scale = Math.abs(scale);
4618 switch (which) {
4619 case 0: mWindowAnimationScale = fixScale(scale); break;
4620 case 1: mTransitionAnimationScale = fixScale(scale); break;
4621 }
Romain Guy06882f82009-06-10 13:36:04 -07004622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 // Persist setting
4624 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4625 }
Romain Guy06882f82009-06-10 13:36:04 -07004626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004627 public void setAnimationScales(float[] scales) {
4628 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4629 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004630 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 }
4632
4633 if (scales != null) {
4634 if (scales.length >= 1) {
4635 mWindowAnimationScale = fixScale(scales[0]);
4636 }
4637 if (scales.length >= 2) {
4638 mTransitionAnimationScale = fixScale(scales[1]);
4639 }
4640 }
Romain Guy06882f82009-06-10 13:36:04 -07004641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 // Persist setting
4643 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4644 }
Romain Guy06882f82009-06-10 13:36:04 -07004645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 public float getAnimationScale(int which) {
4647 switch (which) {
4648 case 0: return mWindowAnimationScale;
4649 case 1: return mTransitionAnimationScale;
4650 }
4651 return 0;
4652 }
Romain Guy06882f82009-06-10 13:36:04 -07004653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004654 public float[] getAnimationScales() {
4655 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4656 }
Romain Guy06882f82009-06-10 13:36:04 -07004657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 public int getSwitchState(int sw) {
4659 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4660 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004661 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004662 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004663 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 }
Romain Guy06882f82009-06-10 13:36:04 -07004665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004666 public int getSwitchStateForDevice(int devid, int sw) {
4667 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4668 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004669 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004670 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004671 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 }
Romain Guy06882f82009-06-10 13:36:04 -07004673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004674 public int getScancodeState(int sw) {
4675 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4676 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004677 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004679 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 }
Romain Guy06882f82009-06-10 13:36:04 -07004681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 public int getScancodeStateForDevice(int devid, int sw) {
4683 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4684 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004685 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004686 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004687 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 }
Romain Guy06882f82009-06-10 13:36:04 -07004689
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004690 public int getTrackballScancodeState(int sw) {
4691 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4692 "getTrackballScancodeState()")) {
4693 throw new SecurityException("Requires READ_INPUT_STATE permission");
4694 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004695 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004696 }
4697
4698 public int getDPadScancodeState(int sw) {
4699 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4700 "getDPadScancodeState()")) {
4701 throw new SecurityException("Requires READ_INPUT_STATE permission");
4702 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004703 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004704 }
4705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004706 public int getKeycodeState(int sw) {
4707 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4708 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004709 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004711 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 }
Romain Guy06882f82009-06-10 13:36:04 -07004713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 public int getKeycodeStateForDevice(int devid, int sw) {
4715 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4716 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004717 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004719 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004720 }
Romain Guy06882f82009-06-10 13:36:04 -07004721
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004722 public int getTrackballKeycodeState(int sw) {
4723 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4724 "getTrackballKeycodeState()")) {
4725 throw new SecurityException("Requires READ_INPUT_STATE permission");
4726 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004727 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004728 }
4729
4730 public int getDPadKeycodeState(int sw) {
4731 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4732 "getDPadKeycodeState()")) {
4733 throw new SecurityException("Requires READ_INPUT_STATE permission");
4734 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004735 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004736 }
Jeff Browna41ca772010-08-11 14:46:32 -07004737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004738 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004739 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004740 }
Romain Guy06882f82009-06-10 13:36:04 -07004741
Jeff Browna41ca772010-08-11 14:46:32 -07004742 public InputChannel monitorInput(String inputChannelName) {
4743 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4744 "monitorInput()")) {
4745 throw new SecurityException("Requires READ_INPUT_STATE permission");
4746 }
4747 return mInputManager.monitorInput(inputChannelName);
4748 }
4749
Jeff Brown8d608662010-08-30 03:02:23 -07004750 public InputDevice getInputDevice(int deviceId) {
4751 return mInputManager.getInputDevice(deviceId);
4752 }
4753
4754 public int[] getInputDeviceIds() {
4755 return mInputManager.getInputDeviceIds();
4756 }
4757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004758 public void enableScreenAfterBoot() {
4759 synchronized(mWindowMap) {
4760 if (mSystemBooted) {
4761 return;
4762 }
4763 mSystemBooted = true;
4764 }
Romain Guy06882f82009-06-10 13:36:04 -07004765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 performEnableScreen();
4767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 public void enableScreenIfNeededLocked() {
4770 if (mDisplayEnabled) {
4771 return;
4772 }
4773 if (!mSystemBooted) {
4774 return;
4775 }
4776 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4777 }
Romain Guy06882f82009-06-10 13:36:04 -07004778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004779 public void performEnableScreen() {
4780 synchronized(mWindowMap) {
4781 if (mDisplayEnabled) {
4782 return;
4783 }
4784 if (!mSystemBooted) {
4785 return;
4786 }
Romain Guy06882f82009-06-10 13:36:04 -07004787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 // Don't enable the screen until all existing windows
4789 // have been drawn.
4790 final int N = mWindows.size();
4791 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004792 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004793 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 return;
4795 }
4796 }
Romain Guy06882f82009-06-10 13:36:04 -07004797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 mDisplayEnabled = true;
4799 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004800 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004801 StringWriter sw = new StringWriter();
4802 PrintWriter pw = new PrintWriter(sw);
4803 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004804 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 }
4806 try {
4807 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4808 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004809 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 Parcel data = Parcel.obtain();
4811 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4812 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4813 data, null, 0);
4814 data.recycle();
4815 }
4816 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004817 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 }
4819 }
Romain Guy06882f82009-06-10 13:36:04 -07004820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004823 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004824 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4825 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004826 }
Romain Guy06882f82009-06-10 13:36:04 -07004827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004828 public void setInTouchMode(boolean mode) {
4829 synchronized(mWindowMap) {
4830 mInTouchMode = mode;
4831 }
4832 }
4833
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004834 public void freezeRotation() {
4835 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4836 "setRotation()")) {
4837 throw new SecurityException("Requires SET_ORIENTATION permission");
4838 }
4839
4840 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
4841 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4842 }
4843
4844 public void thawRotation() {
4845 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
4846 "setRotation()")) {
4847 throw new SecurityException("Requires SET_ORIENTATION permission");
4848 }
4849
4850 mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0);
4851 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0);
4852 }
4853
Romain Guy06882f82009-06-10 13:36:04 -07004854 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004855 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004857 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004858 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859 }
4860
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004861 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 }
Romain Guy06882f82009-06-10 13:36:04 -07004863
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004864 public void setRotationUnchecked(int rotation,
4865 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004866 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004867 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004869 long origId = Binder.clearCallingIdentity();
4870 boolean changed;
4871 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004872 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
Romain Guy06882f82009-06-10 13:36:04 -07004874
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004875 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 sendNewConfiguration();
4877 }
Romain Guy06882f82009-06-10 13:36:04 -07004878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004879 Binder.restoreCallingIdentity(origId);
4880 }
Romain Guy06882f82009-06-10 13:36:04 -07004881
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004882 /**
4883 * Apply a new rotation to the screen, respecting the requests of
4884 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4885 * re-evaluate the desired rotation.
4886 *
4887 * Returns null if the rotation has been changed. In this case YOU
4888 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4889 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004890 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 boolean changed;
4892 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4893 rotation = mRequestedRotation;
4894 } else {
4895 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004896 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004897 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004898 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004899 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004901 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004904 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004905 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004906 "Rotation changed to " + rotation
4907 + " from " + mRotation
4908 + " (forceApp=" + mForcedAppOrientation
4909 + ", req=" + mRequestedRotation + ")");
4910 mRotation = rotation;
4911 mWindowsFreezingScreen = true;
4912 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4913 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4914 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004915 mWaitingForConfig = true;
4916 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004918 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004919 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004921 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004922 }
4923 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004924 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 if (w.mSurface != null) {
4926 w.mOrientationChanging = true;
4927 }
4928 }
4929 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4930 try {
4931 mRotationWatchers.get(i).onRotationChanged(rotation);
4932 } catch (RemoteException e) {
4933 }
4934 }
4935 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 return changed;
4938 }
Romain Guy06882f82009-06-10 13:36:04 -07004939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004940 public int getRotation() {
4941 return mRotation;
4942 }
4943
4944 public int watchRotation(IRotationWatcher watcher) {
4945 final IBinder watcherBinder = watcher.asBinder();
4946 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4947 public void binderDied() {
4948 synchronized (mWindowMap) {
4949 for (int i=0; i<mRotationWatchers.size(); i++) {
4950 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004951 IRotationWatcher removed = mRotationWatchers.remove(i);
4952 if (removed != null) {
4953 removed.asBinder().unlinkToDeath(this, 0);
4954 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004955 i--;
4956 }
4957 }
4958 }
4959 }
4960 };
Romain Guy06882f82009-06-10 13:36:04 -07004961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004962 synchronized (mWindowMap) {
4963 try {
4964 watcher.asBinder().linkToDeath(dr, 0);
4965 mRotationWatchers.add(watcher);
4966 } catch (RemoteException e) {
4967 // Client died, no cleanup needed.
4968 }
Romain Guy06882f82009-06-10 13:36:04 -07004969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004970 return mRotation;
4971 }
4972 }
4973
4974 /**
4975 * Starts the view server on the specified port.
4976 *
4977 * @param port The port to listener to.
4978 *
4979 * @return True if the server was successfully started, false otherwise.
4980 *
4981 * @see com.android.server.ViewServer
4982 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4983 */
4984 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004985 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004986 return false;
4987 }
4988
4989 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4990 return false;
4991 }
4992
4993 if (port < 1024) {
4994 return false;
4995 }
4996
4997 if (mViewServer != null) {
4998 if (!mViewServer.isRunning()) {
4999 try {
5000 return mViewServer.start();
5001 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005002 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005003 }
5004 }
5005 return false;
5006 }
5007
5008 try {
5009 mViewServer = new ViewServer(this, port);
5010 return mViewServer.start();
5011 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005012 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005013 }
5014 return false;
5015 }
5016
Romain Guy06882f82009-06-10 13:36:04 -07005017 private boolean isSystemSecure() {
5018 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
5019 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
5020 }
5021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005022 /**
5023 * Stops the view server if it exists.
5024 *
5025 * @return True if the server stopped, false if it wasn't started or
5026 * couldn't be stopped.
5027 *
5028 * @see com.android.server.ViewServer
5029 */
5030 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07005031 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 return false;
5033 }
5034
5035 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
5036 return false;
5037 }
5038
5039 if (mViewServer != null) {
5040 return mViewServer.stop();
5041 }
5042 return false;
5043 }
5044
5045 /**
5046 * Indicates whether the view server is running.
5047 *
5048 * @return True if the server is running, false otherwise.
5049 *
5050 * @see com.android.server.ViewServer
5051 */
5052 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005053 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005054 return false;
5055 }
5056
5057 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5058 return false;
5059 }
5060
5061 return mViewServer != null && mViewServer.isRunning();
5062 }
5063
5064 /**
5065 * Lists all availble windows in the system. The listing is written in the
5066 * specified Socket's output stream with the following syntax:
5067 * windowHashCodeInHexadecimal windowName
5068 * Each line of the ouput represents a different window.
5069 *
5070 * @param client The remote client to send the listing to.
5071 * @return False if an error occured, true otherwise.
5072 */
5073 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005074 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005075 return false;
5076 }
5077
5078 boolean result = true;
5079
Jeff Browne33348b2010-07-15 23:54:05 -07005080 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005081 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005082 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005083 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005084 }
5085
5086 BufferedWriter out = null;
5087
5088 // Any uncaught exception will crash the system process
5089 try {
5090 OutputStream clientStream = client.getOutputStream();
5091 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5092
5093 final int count = windows.length;
5094 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005095 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005096 out.write(Integer.toHexString(System.identityHashCode(w)));
5097 out.write(' ');
5098 out.append(w.mAttrs.getTitle());
5099 out.write('\n');
5100 }
5101
5102 out.write("DONE.\n");
5103 out.flush();
5104 } catch (Exception e) {
5105 result = false;
5106 } finally {
5107 if (out != null) {
5108 try {
5109 out.close();
5110 } catch (IOException e) {
5111 result = false;
5112 }
5113 }
5114 }
5115
5116 return result;
5117 }
5118
5119 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005120 * Returns the focused window in the following format:
5121 * windowHashCodeInHexadecimal windowName
5122 *
5123 * @param client The remote client to send the listing to.
5124 * @return False if an error occurred, true otherwise.
5125 */
5126 boolean viewServerGetFocusedWindow(Socket client) {
5127 if (isSystemSecure()) {
5128 return false;
5129 }
5130
5131 boolean result = true;
5132
5133 WindowState focusedWindow = getFocusedWindow();
5134
5135 BufferedWriter out = null;
5136
5137 // Any uncaught exception will crash the system process
5138 try {
5139 OutputStream clientStream = client.getOutputStream();
5140 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5141
5142 if(focusedWindow != null) {
5143 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5144 out.write(' ');
5145 out.append(focusedWindow.mAttrs.getTitle());
5146 }
5147 out.write('\n');
5148 out.flush();
5149 } catch (Exception e) {
5150 result = false;
5151 } finally {
5152 if (out != null) {
5153 try {
5154 out.close();
5155 } catch (IOException e) {
5156 result = false;
5157 }
5158 }
5159 }
5160
5161 return result;
5162 }
5163
5164 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005165 * Sends a command to a target window. The result of the command, if any, will be
5166 * written in the output stream of the specified socket.
5167 *
5168 * The parameters must follow this syntax:
5169 * windowHashcode extra
5170 *
5171 * Where XX is the length in characeters of the windowTitle.
5172 *
5173 * The first parameter is the target window. The window with the specified hashcode
5174 * will be the target. If no target can be found, nothing happens. The extra parameters
5175 * will be delivered to the target window and as parameters to the command itself.
5176 *
5177 * @param client The remote client to sent the result, if any, to.
5178 * @param command The command to execute.
5179 * @param parameters The command parameters.
5180 *
5181 * @return True if the command was successfully delivered, false otherwise. This does
5182 * not indicate whether the command itself was successful.
5183 */
5184 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005185 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005186 return false;
5187 }
5188
5189 boolean success = true;
5190 Parcel data = null;
5191 Parcel reply = null;
5192
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005193 BufferedWriter out = null;
5194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005195 // Any uncaught exception will crash the system process
5196 try {
5197 // Find the hashcode of the window
5198 int index = parameters.indexOf(' ');
5199 if (index == -1) {
5200 index = parameters.length();
5201 }
5202 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005203 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005204
5205 // Extract the command's parameter after the window description
5206 if (index < parameters.length()) {
5207 parameters = parameters.substring(index + 1);
5208 } else {
5209 parameters = "";
5210 }
5211
5212 final WindowManagerService.WindowState window = findWindow(hashCode);
5213 if (window == null) {
5214 return false;
5215 }
5216
5217 data = Parcel.obtain();
5218 data.writeInterfaceToken("android.view.IWindow");
5219 data.writeString(command);
5220 data.writeString(parameters);
5221 data.writeInt(1);
5222 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5223
5224 reply = Parcel.obtain();
5225
5226 final IBinder binder = window.mClient.asBinder();
5227 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5228 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5229
5230 reply.readException();
5231
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005232 if (!client.isOutputShutdown()) {
5233 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5234 out.write("DONE\n");
5235 out.flush();
5236 }
5237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005238 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005239 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240 success = false;
5241 } finally {
5242 if (data != null) {
5243 data.recycle();
5244 }
5245 if (reply != null) {
5246 reply.recycle();
5247 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005248 if (out != null) {
5249 try {
5250 out.close();
5251 } catch (IOException e) {
5252
5253 }
5254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005255 }
5256
5257 return success;
5258 }
5259
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005260 public void addWindowChangeListener(WindowChangeListener listener) {
5261 synchronized(mWindowMap) {
5262 mWindowChangeListeners.add(listener);
5263 }
5264 }
5265
5266 public void removeWindowChangeListener(WindowChangeListener listener) {
5267 synchronized(mWindowMap) {
5268 mWindowChangeListeners.remove(listener);
5269 }
5270 }
5271
5272 private void notifyWindowsChanged() {
5273 WindowChangeListener[] windowChangeListeners;
5274 synchronized(mWindowMap) {
5275 if(mWindowChangeListeners.isEmpty()) {
5276 return;
5277 }
5278 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5279 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5280 }
5281 int N = windowChangeListeners.length;
5282 for(int i = 0; i < N; i++) {
5283 windowChangeListeners[i].windowsChanged();
5284 }
5285 }
5286
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005287 private void notifyFocusChanged() {
5288 WindowChangeListener[] windowChangeListeners;
5289 synchronized(mWindowMap) {
5290 if(mWindowChangeListeners.isEmpty()) {
5291 return;
5292 }
5293 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5294 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5295 }
5296 int N = windowChangeListeners.length;
5297 for(int i = 0; i < N; i++) {
5298 windowChangeListeners[i].focusChanged();
5299 }
5300 }
5301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005302 private WindowState findWindow(int hashCode) {
5303 if (hashCode == -1) {
5304 return getFocusedWindow();
5305 }
5306
5307 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005308 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005309 final int count = windows.size();
5310
5311 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005312 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 if (System.identityHashCode(w) == hashCode) {
5314 return w;
5315 }
5316 }
5317 }
5318
5319 return null;
5320 }
5321
5322 /*
5323 * Instruct the Activity Manager to fetch the current configuration and broadcast
5324 * that to config-changed listeners if appropriate.
5325 */
5326 void sendNewConfiguration() {
5327 try {
5328 mActivityManager.updateConfiguration(null);
5329 } catch (RemoteException e) {
5330 }
5331 }
Romain Guy06882f82009-06-10 13:36:04 -07005332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333 public Configuration computeNewConfiguration() {
5334 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005335 return computeNewConfigurationLocked();
5336 }
5337 }
Romain Guy06882f82009-06-10 13:36:04 -07005338
Dianne Hackbornc485a602009-03-24 22:39:49 -07005339 Configuration computeNewConfigurationLocked() {
5340 Configuration config = new Configuration();
5341 if (!computeNewConfigurationLocked(config)) {
5342 return null;
5343 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005344 return config;
5345 }
Romain Guy06882f82009-06-10 13:36:04 -07005346
Dianne Hackbornc485a602009-03-24 22:39:49 -07005347 boolean computeNewConfigurationLocked(Configuration config) {
5348 if (mDisplay == null) {
5349 return false;
5350 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005351
5352 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005353
5354 // Use the effective "visual" dimensions based on current rotation
5355 final boolean rotated = (mRotation == Surface.ROTATION_90
5356 || mRotation == Surface.ROTATION_270);
5357 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5358 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5359
Dianne Hackbornc485a602009-03-24 22:39:49 -07005360 int orientation = Configuration.ORIENTATION_SQUARE;
5361 if (dw < dh) {
5362 orientation = Configuration.ORIENTATION_PORTRAIT;
5363 } else if (dw > dh) {
5364 orientation = Configuration.ORIENTATION_LANDSCAPE;
5365 }
5366 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005367
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005368 DisplayMetrics dm = new DisplayMetrics();
5369 mDisplay.getMetrics(dm);
5370 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5371
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005372 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005373 // Note we only do this once because at this point we don't
5374 // expect the screen to change in this way at runtime, and want
5375 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005376 int longSize = dw;
5377 int shortSize = dh;
5378 if (longSize < shortSize) {
5379 int tmp = longSize;
5380 longSize = shortSize;
5381 shortSize = tmp;
5382 }
5383 longSize = (int)(longSize/dm.density);
5384 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005385
Dianne Hackborn723738c2009-06-25 19:48:04 -07005386 // These semi-magic numbers define our compatibility modes for
5387 // applications with different screens. Don't change unless you
5388 // make sure to test lots and lots of apps!
5389 if (longSize < 470) {
5390 // This is shorter than an HVGA normal density screen (which
5391 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005392 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5393 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005394 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005395 // What size is this screen screen?
5396 if (longSize >= 800 && shortSize >= 600) {
5397 // SVGA or larger screens at medium density are the point
5398 // at which we consider it to be an extra large screen.
5399 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
Dianne Hackbornb51dc0f2010-10-21 15:34:47 -07005400 } else if (longSize >= 530 && shortSize >= 400) {
5401 // SVGA or larger screens at high density are the point
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005402 // at which we consider it to be a large screen.
5403 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5404 } else {
5405 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005406
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005407 // If this screen is wider than normal HVGA, or taller
5408 // than FWVGA, then for old apps we want to run in size
5409 // compatibility mode.
5410 if (shortSize > 321 || longSize > 570) {
5411 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5412 }
5413 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005414
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005415 // Is this a long screen?
5416 if (((longSize*3)/5) >= (shortSize-1)) {
5417 // Anything wider than WVGA (5:3) is considering to be long.
5418 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5419 } else {
5420 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5421 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005422 }
5423 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005424 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005425
Dianne Hackbornc485a602009-03-24 22:39:49 -07005426 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5427 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5428 mPolicy.adjustConfigurationLw(config);
5429 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005430 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005431
5432 // -------------------------------------------------------------
5433 // Drag and drop
5434 // -------------------------------------------------------------
5435
5436 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5437 boolean localOnly, int width, int height, Surface outSurface) {
5438 if (DEBUG_DRAG) {
5439 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5440 + " local=" + localOnly + " win=" + window
5441 + " asbinder=" + window.asBinder());
5442 }
5443
5444 final int callerPid = Binder.getCallingPid();
5445 final long origId = Binder.clearCallingIdentity();
5446 IBinder token = null;
5447
5448 try {
5449 synchronized (mWindowMap) {
5450 try {
5451 // !!! TODO: fail if the given window does not currently have touch focus?
5452
5453 if (mDragState == null) {
5454 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5455 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5456 outSurface.copyFrom(surface);
5457 token = new Binder();
5458 mDragState = new DragState(token, surface, localOnly);
5459 mDragState.mSurface = surface;
5460 mDragState.mLocalOnly = localOnly;
5461 token = mDragState.mToken = new Binder();
5462
5463 // 5 second timeout for this window to actually begin the drag
5464 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5465 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5466 mH.sendMessageDelayed(msg, 5000);
5467 } else {
5468 Slog.w(TAG, "Drag already in progress");
5469 }
5470 } catch (Surface.OutOfResourcesException e) {
5471 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5472 if (mDragState != null) {
5473 mDragState.reset();
5474 mDragState = null;
5475 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005476 }
5477 }
5478 } finally {
5479 Binder.restoreCallingIdentity(origId);
5480 }
5481
5482 return token;
5483 }
5484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005485 // -------------------------------------------------------------
5486 // Input Events and Focus Management
5487 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005488
Jeff Brown349703e2010-06-22 01:27:15 -07005489 InputMonitor mInputMonitor = new InputMonitor();
5490
5491 /* Tracks the progress of input dispatch and ensures that input dispatch state
5492 * is kept in sync with changes in window focus, visibility, registration, and
5493 * other relevant Window Manager state transitions. */
5494 final class InputMonitor {
5495 // Current window with input focus for keys and other non-touch events. May be null.
5496 private WindowState mInputFocus;
5497
5498 // When true, prevents input dispatch from proceeding until set to false again.
5499 private boolean mInputDispatchFrozen;
5500
5501 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5502 private boolean mInputDispatchEnabled = true;
5503
5504 // Temporary list of windows information to provide to the input dispatcher.
5505 private InputWindowList mTempInputWindows = new InputWindowList();
5506
5507 // Temporary input application object to provide to the input dispatcher.
5508 private InputApplication mTempInputApplication = new InputApplication();
5509
5510 /* Notifies the window manager about a broken input channel.
5511 *
5512 * Called by the InputManager.
5513 */
5514 public void notifyInputChannelBroken(InputChannel inputChannel) {
5515 synchronized (mWindowMap) {
5516 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5517 if (windowState == null) {
5518 return; // irrelevant
5519 }
5520
5521 Slog.i(TAG, "WINDOW DIED " + windowState);
5522 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005523 }
5524 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005525
Jeff Brown519e0242010-09-15 15:18:56 -07005526 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005527 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005528 *
5529 * Called by the InputManager.
5530 */
Jeff Brown519e0242010-09-15 15:18:56 -07005531 public long notifyANR(Object token, InputChannel inputChannel) {
5532 AppWindowToken appWindowToken = null;
5533 if (inputChannel != null) {
5534 synchronized (mWindowMap) {
5535 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5536 if (windowState != null) {
5537 Slog.i(TAG, "Input event dispatching timed out sending to "
5538 + windowState.mAttrs.getTitle());
5539 appWindowToken = windowState.mAppToken;
5540 }
Jeff Brown349703e2010-06-22 01:27:15 -07005541 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005542 }
5543
Jeff Brown519e0242010-09-15 15:18:56 -07005544 if (appWindowToken == null && token != null) {
5545 appWindowToken = (AppWindowToken) token;
5546 Slog.i(TAG, "Input event dispatching timed out sending to application "
5547 + appWindowToken.stringName);
5548 }
Jeff Brown349703e2010-06-22 01:27:15 -07005549
Jeff Brown519e0242010-09-15 15:18:56 -07005550 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005551 try {
5552 // Notify the activity manager about the timeout and let it decide whether
5553 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005554 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005555 if (! abort) {
5556 // The activity manager declined to abort dispatching.
5557 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005558 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005559 }
Jeff Brown349703e2010-06-22 01:27:15 -07005560 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005561 }
5562 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005563 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005564 }
5565
Jeff Brown349703e2010-06-22 01:27:15 -07005566 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5567 synchronized (mWindowMap) {
5568 return getWindowStateForInputChannelLocked(inputChannel);
5569 }
5570 }
5571
5572 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5573 int windowCount = mWindows.size();
5574 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005575 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005576 if (windowState.mInputChannel == inputChannel) {
5577 return windowState;
5578 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005579 }
5580
Jeff Brown349703e2010-06-22 01:27:15 -07005581 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005582 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005583
Chris Tatea32dcf72010-10-14 12:13:50 -07005584 private void addDragInputWindowLw(InputWindowList windowList) {
Christopher Tatea53146c2010-09-07 11:57:52 -07005585 final InputWindow inputWindow = windowList.add();
5586 inputWindow.inputChannel = mDragState.mServerChannel;
5587 inputWindow.name = "drag";
5588 inputWindow.layoutParamsFlags = 0;
5589 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5590 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5591 inputWindow.visible = true;
5592 inputWindow.canReceiveKeys = false;
5593 inputWindow.hasFocus = true;
5594 inputWindow.hasWallpaper = false;
5595 inputWindow.paused = false;
Chris Tatea32dcf72010-10-14 12:13:50 -07005596 inputWindow.layer = mDragState.getDragLayerLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07005597 inputWindow.ownerPid = Process.myPid();
5598 inputWindow.ownerUid = Process.myUid();
5599
5600 // The drag window covers the entire display
5601 inputWindow.frameLeft = 0;
5602 inputWindow.frameTop = 0;
5603 inputWindow.frameRight = mDisplay.getWidth();
5604 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005605
Christopher Tatea53146c2010-09-07 11:57:52 -07005606 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5607 inputWindow.visibleFrameTop = inputWindow.frameTop;
5608 inputWindow.visibleFrameRight = inputWindow.frameRight;
5609 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5610
5611 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5612 inputWindow.touchableAreaTop = inputWindow.frameTop;
5613 inputWindow.touchableAreaRight = inputWindow.frameRight;
5614 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5615 }
5616
Jeff Brown349703e2010-06-22 01:27:15 -07005617 /* Updates the cached window information provided to the input dispatcher. */
5618 public void updateInputWindowsLw() {
5619 // Populate the input window list with information about all of the windows that
5620 // could potentially receive input.
5621 // As an optimization, we could try to prune the list of windows but this turns
5622 // out to be difficult because only the native code knows for sure which window
5623 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005624 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005625
5626 // If there's a drag in flight, provide a pseudowindow to catch drag input
5627 final boolean inDrag = (mDragState != null);
5628 if (inDrag) {
5629 if (DEBUG_DRAG) {
5630 Log.d(TAG, "Inserting drag window");
5631 }
Chris Tatea32dcf72010-10-14 12:13:50 -07005632 addDragInputWindowLw(mTempInputWindows);
Christopher Tatea53146c2010-09-07 11:57:52 -07005633 }
5634
Jeff Brown7fbdc842010-06-17 20:52:56 -07005635 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005636 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005637 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005638 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005639 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005640 continue;
5641 }
5642
Jeff Brown349703e2010-06-22 01:27:15 -07005643 final int flags = child.mAttrs.flags;
5644 final int type = child.mAttrs.type;
5645
5646 final boolean hasFocus = (child == mInputFocus);
5647 final boolean isVisible = child.isVisibleLw();
5648 final boolean hasWallpaper = (child == mWallpaperTarget)
5649 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005650
5651 // If there's a drag in progress and 'child' is a potential drop target,
5652 // make sure it's been told about the drag
5653 if (inDrag && isVisible) {
5654 mDragState.sendDragStartedIfNeededLw(child);
5655 }
5656
Jeff Brown349703e2010-06-22 01:27:15 -07005657 // Add a window to our list of input windows.
5658 final InputWindow inputWindow = mTempInputWindows.add();
5659 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005660 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005661 inputWindow.layoutParamsFlags = flags;
5662 inputWindow.layoutParamsType = type;
5663 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5664 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005665 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005666 inputWindow.hasFocus = hasFocus;
5667 inputWindow.hasWallpaper = hasWallpaper;
5668 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005669 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005670 inputWindow.ownerPid = child.mSession.mPid;
5671 inputWindow.ownerUid = child.mSession.mUid;
5672
5673 final Rect frame = child.mFrame;
5674 inputWindow.frameLeft = frame.left;
5675 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005676 inputWindow.frameRight = frame.right;
5677 inputWindow.frameBottom = frame.bottom;
5678
5679 final Rect visibleFrame = child.mVisibleFrame;
5680 inputWindow.visibleFrameLeft = visibleFrame.left;
5681 inputWindow.visibleFrameTop = visibleFrame.top;
5682 inputWindow.visibleFrameRight = visibleFrame.right;
5683 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005684
5685 switch (child.mTouchableInsets) {
5686 default:
5687 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5688 inputWindow.touchableAreaLeft = frame.left;
5689 inputWindow.touchableAreaTop = frame.top;
5690 inputWindow.touchableAreaRight = frame.right;
5691 inputWindow.touchableAreaBottom = frame.bottom;
5692 break;
5693
5694 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5695 Rect inset = child.mGivenContentInsets;
5696 inputWindow.touchableAreaLeft = frame.left + inset.left;
5697 inputWindow.touchableAreaTop = frame.top + inset.top;
5698 inputWindow.touchableAreaRight = frame.right - inset.right;
5699 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5700 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005701 }
Jeff Brown349703e2010-06-22 01:27:15 -07005702
5703 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5704 Rect inset = child.mGivenVisibleInsets;
5705 inputWindow.touchableAreaLeft = frame.left + inset.left;
5706 inputWindow.touchableAreaTop = frame.top + inset.top;
5707 inputWindow.touchableAreaRight = frame.right - inset.right;
5708 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005709 break;
5710 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005711 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005712 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005713
Jeff Brown349703e2010-06-22 01:27:15 -07005714 // Send windows to native code.
5715 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005716
Jeff Brown349703e2010-06-22 01:27:15 -07005717 // Clear the list in preparation for the next round.
5718 // Also avoids keeping InputChannel objects referenced unnecessarily.
5719 mTempInputWindows.clear();
5720 }
5721
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005722 /* Notifies that the lid switch changed state. */
5723 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5724 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5725 }
5726
Jeff Brown349703e2010-06-22 01:27:15 -07005727 /* Provides an opportunity for the window manager policy to intercept early key
5728 * processing as soon as the key has been read from the device. */
Jeff Brown4d396052010-10-29 21:50:21 -07005729 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
5730 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
5731 return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags,
5732 keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005733 }
5734
5735 /* Provides an opportunity for the window manager policy to process a key before
5736 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005737 public boolean interceptKeyBeforeDispatching(InputChannel focus,
Jeff Brown4d396052010-10-29 21:50:21 -07005738 int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount,
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005739 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005740 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005741 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
Jeff Brown4d396052010-10-29 21:50:21 -07005742 keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005743 }
5744
5745 /* Called when the current input focus changes.
5746 * Layer assignment is assumed to be complete by the time this is called.
5747 */
5748 public void setInputFocusLw(WindowState newWindow) {
5749 if (DEBUG_INPUT) {
5750 Slog.d(TAG, "Input focus has changed to " + newWindow);
5751 }
5752
5753 if (newWindow != mInputFocus) {
5754 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005755 // Displaying a window implicitly causes dispatching to be unpaused.
5756 // This is to protect against bugs if someone pauses dispatching but
5757 // forgets to resume.
5758 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005759 }
Jeff Brown349703e2010-06-22 01:27:15 -07005760
5761 mInputFocus = newWindow;
5762 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005763 }
5764 }
5765
Jeff Brown349703e2010-06-22 01:27:15 -07005766 public void setFocusedAppLw(AppWindowToken newApp) {
5767 // Focused app has changed.
5768 if (newApp == null) {
5769 mInputManager.setFocusedApplication(null);
5770 } else {
5771 mTempInputApplication.name = newApp.toString();
5772 mTempInputApplication.dispatchingTimeoutNanos =
5773 newApp.inputDispatchingTimeoutNanos;
5774 mTempInputApplication.token = newApp;
5775
5776 mInputManager.setFocusedApplication(mTempInputApplication);
5777 }
5778 }
5779
Jeff Brown349703e2010-06-22 01:27:15 -07005780 public void pauseDispatchingLw(WindowToken window) {
5781 if (! window.paused) {
5782 if (DEBUG_INPUT) {
5783 Slog.v(TAG, "Pausing WindowToken " + window);
5784 }
5785
5786 window.paused = true;
5787 updateInputWindowsLw();
5788 }
5789 }
5790
5791 public void resumeDispatchingLw(WindowToken window) {
5792 if (window.paused) {
5793 if (DEBUG_INPUT) {
5794 Slog.v(TAG, "Resuming WindowToken " + window);
5795 }
5796
5797 window.paused = false;
5798 updateInputWindowsLw();
5799 }
5800 }
5801
5802 public void freezeInputDispatchingLw() {
5803 if (! mInputDispatchFrozen) {
5804 if (DEBUG_INPUT) {
5805 Slog.v(TAG, "Freezing input dispatching");
5806 }
5807
5808 mInputDispatchFrozen = true;
5809 updateInputDispatchModeLw();
5810 }
5811 }
5812
5813 public void thawInputDispatchingLw() {
5814 if (mInputDispatchFrozen) {
5815 if (DEBUG_INPUT) {
5816 Slog.v(TAG, "Thawing input dispatching");
5817 }
5818
5819 mInputDispatchFrozen = false;
5820 updateInputDispatchModeLw();
5821 }
5822 }
5823
5824 public void setEventDispatchingLw(boolean enabled) {
5825 if (mInputDispatchEnabled != enabled) {
5826 if (DEBUG_INPUT) {
5827 Slog.v(TAG, "Setting event dispatching to " + enabled);
5828 }
5829
5830 mInputDispatchEnabled = enabled;
5831 updateInputDispatchModeLw();
5832 }
5833 }
5834
5835 private void updateInputDispatchModeLw() {
5836 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5837 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 public void pauseKeyDispatching(IBinder _token) {
5841 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5842 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005843 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 }
5845
5846 synchronized (mWindowMap) {
5847 WindowToken token = mTokenMap.get(_token);
5848 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005849 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 }
5851 }
5852 }
5853
5854 public void resumeKeyDispatching(IBinder _token) {
5855 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5856 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005857 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005858 }
5859
5860 synchronized (mWindowMap) {
5861 WindowToken token = mTokenMap.get(_token);
5862 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005863 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864 }
5865 }
5866 }
5867
5868 public void setEventDispatching(boolean enabled) {
5869 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5870 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005871 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005872 }
5873
5874 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005875 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005876 }
5877 }
Romain Guy06882f82009-06-10 13:36:04 -07005878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 /**
5880 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005881 * Even when sync is false, this method may block while waiting for current
5882 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005883 *
5884 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005885 * {@link SystemClock#uptimeMillis()} as the timebase.)
5886 * @param sync If true, wait for the event to be completed before returning to the caller.
5887 * @return Returns true if event was dispatched, false if it was dropped for any reason
5888 */
5889 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5890 long downTime = ev.getDownTime();
5891 long eventTime = ev.getEventTime();
5892
5893 int action = ev.getAction();
5894 int code = ev.getKeyCode();
5895 int repeatCount = ev.getRepeatCount();
5896 int metaState = ev.getMetaState();
5897 int deviceId = ev.getDeviceId();
5898 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005899 int source = ev.getSource();
5900
5901 if (source == InputDevice.SOURCE_UNKNOWN) {
5902 source = InputDevice.SOURCE_KEYBOARD;
5903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904
5905 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5906 if (downTime == 0) downTime = eventTime;
5907
5908 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005909 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005910
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005911 final int pid = Binder.getCallingPid();
5912 final int uid = Binder.getCallingUid();
5913 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005914
Jeff Brownbbda99d2010-07-28 15:48:59 -07005915 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5916 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5917 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5918 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005919
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005920 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005921 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005922 }
5923
5924 /**
5925 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005926 * Even when sync is false, this method may block while waiting for current
5927 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005928 *
5929 * @param ev A motion event describing the pointer (touch) action. (As noted in
5930 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005931 * {@link SystemClock#uptimeMillis()} as the timebase.)
5932 * @param sync If true, wait for the event to be completed before returning to the caller.
5933 * @return Returns true if event was dispatched, false if it was dropped for any reason
5934 */
5935 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005936 final int pid = Binder.getCallingPid();
5937 final int uid = Binder.getCallingUid();
5938 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005939
Jeff Brownc5ed5912010-07-14 18:48:53 -07005940 MotionEvent newEvent = MotionEvent.obtain(ev);
5941 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5942 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5943 }
5944
Jeff Brownbbda99d2010-07-28 15:48:59 -07005945 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5946 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5947 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5948 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005949
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005950 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005951 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005952 }
Romain Guy06882f82009-06-10 13:36:04 -07005953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005954 /**
5955 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005956 * Even when sync is false, this method may block while waiting for current
5957 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005958 *
5959 * @param ev A motion event describing the trackball action. (As noted in
5960 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005961 * {@link SystemClock#uptimeMillis()} as the timebase.)
5962 * @param sync If true, wait for the event to be completed before returning to the caller.
5963 * @return Returns true if event was dispatched, false if it was dropped for any reason
5964 */
5965 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005966 final int pid = Binder.getCallingPid();
5967 final int uid = Binder.getCallingUid();
5968 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005969
Jeff Brownc5ed5912010-07-14 18:48:53 -07005970 MotionEvent newEvent = MotionEvent.obtain(ev);
5971 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5972 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5973 }
5974
Jeff Brownbbda99d2010-07-28 15:48:59 -07005975 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5976 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5977 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5978 INJECTION_TIMEOUT_MILLIS);
5979
5980 Binder.restoreCallingIdentity(ident);
5981 return reportInjectionResult(result);
5982 }
5983
5984 /**
5985 * Inject an input event into the UI without waiting for dispatch to commence.
5986 * This variant is useful for fire-and-forget input event injection. It does not
5987 * block any longer than it takes to enqueue the input event.
5988 *
5989 * @param ev An input event. (Be sure to set the input source correctly.)
5990 * @return Returns true if event was dispatched, false if it was dropped for any reason
5991 */
5992 public boolean injectInputEventNoWait(InputEvent ev) {
5993 final int pid = Binder.getCallingPid();
5994 final int uid = Binder.getCallingUid();
5995 final long ident = Binder.clearCallingIdentity();
5996
5997 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5998 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5999 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006000
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07006001 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07006002 return reportInjectionResult(result);
6003 }
6004
6005 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006006 switch (result) {
6007 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
6008 Slog.w(TAG, "Input event injection permission denied.");
6009 throw new SecurityException(
6010 "Injecting to another application requires INJECT_EVENTS permission");
6011 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07006012 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006013 return true;
6014 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
6015 Slog.w(TAG, "Input event injection timed out.");
6016 return false;
6017 case InputManager.INPUT_EVENT_INJECTION_FAILED:
6018 default:
6019 Slog.w(TAG, "Input event injection failed.");
6020 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07006021 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006022 }
Romain Guy06882f82009-06-10 13:36:04 -07006023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006024 private WindowState getFocusedWindow() {
6025 synchronized (mWindowMap) {
6026 return getFocusedWindowLocked();
6027 }
6028 }
6029
6030 private WindowState getFocusedWindowLocked() {
6031 return mCurrentFocus;
6032 }
Romain Guy06882f82009-06-10 13:36:04 -07006033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006034 public boolean detectSafeMode() {
6035 mSafeMode = mPolicy.detectSafeMode();
6036 return mSafeMode;
6037 }
Romain Guy06882f82009-06-10 13:36:04 -07006038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006039 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07006040 synchronized(mWindowMap) {
6041 if (mDisplay != null) {
6042 throw new IllegalStateException("Display already initialized");
6043 }
6044 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
6045 mDisplay = wm.getDefaultDisplay();
6046 mInitialDisplayWidth = mDisplay.getWidth();
6047 mInitialDisplayHeight = mDisplay.getHeight();
6048 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6049 }
6050
6051 try {
6052 mActivityManager.updateConfiguration(null);
6053 } catch (RemoteException e) {
6054 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006055
6056 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006057 }
6058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059 // -------------------------------------------------------------
6060 // Client Session State
6061 // -------------------------------------------------------------
6062
6063 private final class Session extends IWindowSession.Stub
6064 implements IBinder.DeathRecipient {
6065 final IInputMethodClient mClient;
6066 final IInputContext mInputContext;
6067 final int mUid;
6068 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006069 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006070 SurfaceSession mSurfaceSession;
6071 int mNumWindow = 0;
6072 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006074 public Session(IInputMethodClient client, IInputContext inputContext) {
6075 mClient = client;
6076 mInputContext = inputContext;
6077 mUid = Binder.getCallingUid();
6078 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006079 StringBuilder sb = new StringBuilder();
6080 sb.append("Session{");
6081 sb.append(Integer.toHexString(System.identityHashCode(this)));
6082 sb.append(" uid ");
6083 sb.append(mUid);
6084 sb.append("}");
6085 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006087 synchronized (mWindowMap) {
6088 if (mInputMethodManager == null && mHaveInputMethods) {
6089 IBinder b = ServiceManager.getService(
6090 Context.INPUT_METHOD_SERVICE);
6091 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6092 }
6093 }
6094 long ident = Binder.clearCallingIdentity();
6095 try {
6096 // Note: it is safe to call in to the input method manager
6097 // here because we are not holding our lock.
6098 if (mInputMethodManager != null) {
6099 mInputMethodManager.addClient(client, inputContext,
6100 mUid, mPid);
6101 } else {
6102 client.setUsingInputMethod(false);
6103 }
6104 client.asBinder().linkToDeath(this, 0);
6105 } catch (RemoteException e) {
6106 // The caller has died, so we can just forget about this.
6107 try {
6108 if (mInputMethodManager != null) {
6109 mInputMethodManager.removeClient(client);
6110 }
6111 } catch (RemoteException ee) {
6112 }
6113 } finally {
6114 Binder.restoreCallingIdentity(ident);
6115 }
6116 }
Romain Guy06882f82009-06-10 13:36:04 -07006117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 @Override
6119 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6120 throws RemoteException {
6121 try {
6122 return super.onTransact(code, data, reply, flags);
6123 } catch (RuntimeException e) {
6124 // Log all 'real' exceptions thrown to the caller
6125 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006126 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006127 }
6128 throw e;
6129 }
6130 }
6131
6132 public void binderDied() {
6133 // Note: it is safe to call in to the input method manager
6134 // here because we are not holding our lock.
6135 try {
6136 if (mInputMethodManager != null) {
6137 mInputMethodManager.removeClient(mClient);
6138 }
6139 } catch (RemoteException e) {
6140 }
6141 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006142 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006143 mClientDead = true;
6144 killSessionLocked();
6145 }
6146 }
6147
6148 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006149 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6150 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6151 outInputChannel);
6152 }
6153
6154 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006156 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006157 }
Romain Guy06882f82009-06-10 13:36:04 -07006158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 public void remove(IWindow window) {
6160 removeWindow(this, window);
6161 }
Romain Guy06882f82009-06-10 13:36:04 -07006162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006163 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6164 int requestedWidth, int requestedHeight, int viewFlags,
6165 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006166 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006167 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6168 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006169 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006170 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006171 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6172 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006173 }
Romain Guy06882f82009-06-10 13:36:04 -07006174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006175 public void setTransparentRegion(IWindow window, Region region) {
6176 setTransparentRegionWindow(this, window, region);
6177 }
Romain Guy06882f82009-06-10 13:36:04 -07006178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006179 public void setInsets(IWindow window, int touchableInsets,
6180 Rect contentInsets, Rect visibleInsets) {
6181 setInsetsWindow(this, window, touchableInsets, contentInsets,
6182 visibleInsets);
6183 }
Romain Guy06882f82009-06-10 13:36:04 -07006184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006185 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6186 getWindowDisplayFrame(this, window, outDisplayFrame);
6187 }
Romain Guy06882f82009-06-10 13:36:04 -07006188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006189 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006190 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 TAG, "IWindow finishDrawing called for " + window);
6192 finishDrawingWindow(this, window);
6193 }
6194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006195 public void setInTouchMode(boolean mode) {
6196 synchronized(mWindowMap) {
6197 mInTouchMode = mode;
6198 }
6199 }
6200
6201 public boolean getInTouchMode() {
6202 synchronized(mWindowMap) {
6203 return mInTouchMode;
6204 }
6205 }
6206
6207 public boolean performHapticFeedback(IWindow window, int effectId,
6208 boolean always) {
6209 synchronized(mWindowMap) {
6210 long ident = Binder.clearCallingIdentity();
6211 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006212 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006213 windowForClientLocked(this, window, true),
6214 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215 } finally {
6216 Binder.restoreCallingIdentity(ident);
6217 }
6218 }
6219 }
Romain Guy06882f82009-06-10 13:36:04 -07006220
Christopher Tatea53146c2010-09-07 11:57:52 -07006221 /* Drag/drop */
6222 public IBinder prepareDrag(IWindow window, boolean localOnly,
6223 int width, int height, Surface outSurface) {
6224 return prepareDragSurface(window, mSurfaceSession, localOnly,
6225 width, height, outSurface);
6226 }
6227
6228 public boolean performDrag(IWindow window, IBinder dragToken,
6229 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6230 ClipData data) {
6231 if (DEBUG_DRAG) {
6232 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6233 }
6234
6235 synchronized (mWindowMap) {
6236 if (mDragState == null) {
6237 Slog.w(TAG, "No drag prepared");
6238 throw new IllegalStateException("performDrag() without prepareDrag()");
6239 }
6240
6241 if (dragToken != mDragState.mToken) {
6242 Slog.w(TAG, "Performing mismatched drag");
6243 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6244 }
6245
6246 WindowState callingWin = windowForClientLocked(null, window, false);
6247 if (callingWin == null) {
6248 Slog.w(TAG, "Bad requesting window " + window);
6249 return false; // !!! TODO: throw here?
6250 }
6251
6252 // !!! TODO: if input is not still focused on the initiating window, fail
6253 // the drag initiation (e.g. an alarm window popped up just as the application
6254 // called performDrag()
6255
6256 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6257
Christopher Tate2c095f32010-10-04 14:13:40 -07006258 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6259 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006260
Chris Tateb478f462010-10-15 16:02:26 -07006261 // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
6262 // the actual drag event dispatch stuff in the dragstate
6263
Christopher Tatea53146c2010-09-07 11:57:52 -07006264 mDragState.register();
6265 mInputMonitor.updateInputWindowsLw();
Chris Tateef70a072010-10-22 19:10:34 -07006266 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
6267 mDragState.mServerChannel)) {
6268 Slog.e(TAG, "Unable to transfer touch focus");
6269 mDragState.unregister();
6270 mDragState = null;
6271 mInputMonitor.updateInputWindowsLw();
6272 return false;
6273 }
Christopher Tatea53146c2010-09-07 11:57:52 -07006274
6275 mDragState.mData = data;
Chris Tateb478f462010-10-15 16:02:26 -07006276 mDragState.mCurrentX = touchX;
6277 mDragState.mCurrentY = touchY;
Chris Tateb8203e92010-10-12 14:23:21 -07006278 mDragState.broadcastDragStartedLw(touchX, touchY);
Christopher Tatea53146c2010-09-07 11:57:52 -07006279
6280 // remember the thumb offsets for later
6281 mDragState.mThumbOffsetX = thumbCenterX;
6282 mDragState.mThumbOffsetY = thumbCenterY;
6283
6284 // Make the surface visible at the proper location
6285 final Surface surface = mDragState.mSurface;
Chris Tateb478f462010-10-15 16:02:26 -07006286 Surface.openTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006287 try {
6288 surface.setPosition((int)(touchX - thumbCenterX),
6289 (int)(touchY - thumbCenterY));
Chris Tateb478f462010-10-15 16:02:26 -07006290 surface.setAlpha(.7071f);
Chris Tatea32dcf72010-10-14 12:13:50 -07006291 surface.setLayer(mDragState.getDragLayerLw());
Christopher Tatea53146c2010-09-07 11:57:52 -07006292 surface.show();
6293 } finally {
Chris Tateb478f462010-10-15 16:02:26 -07006294 Surface.closeTransaction();
Christopher Tatea53146c2010-09-07 11:57:52 -07006295 }
6296 }
6297
6298 return true; // success!
6299 }
6300
Chris Tated4533f142010-10-19 15:15:08 -07006301 public void reportDropResult(IWindow window, boolean consumed) {
6302 IBinder token = window.asBinder();
6303 if (DEBUG_DRAG) {
6304 Slog.d(TAG, "Drop result=" + consumed + " reported by " + token);
6305 }
6306
6307 synchronized (mWindowMap) {
6308 if (mDragState.mToken != token) {
6309 Slog.w(TAG, "Invalid drop-result claim by " + window);
6310 throw new IllegalStateException("reportDropResult() by non-recipient");
6311 }
6312
6313 // The right window has responded, even if it's no longer around,
6314 // so be sure to halt the timeout even if the later WindowState
6315 // lookup fails.
6316 mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
6317
6318 WindowState callingWin = windowForClientLocked(null, window, false);
6319 if (callingWin == null) {
6320 Slog.w(TAG, "Bad result-reporting window " + window);
6321 return; // !!! TODO: throw here?
6322 }
6323
6324 mDragState.mDragResult = consumed;
6325 mDragState.endDragLw();
6326 }
6327 }
6328
Christopher Tatea53146c2010-09-07 11:57:52 -07006329 public void dragRecipientEntered(IWindow window) {
6330 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006331 Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006332 }
6333 }
6334
6335 public void dragRecipientExited(IWindow window) {
6336 if (DEBUG_DRAG) {
Chris Tated4533f142010-10-19 15:15:08 -07006337 Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder());
Christopher Tatea53146c2010-09-07 11:57:52 -07006338 }
6339 }
6340
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006341 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006342 synchronized(mWindowMap) {
6343 long ident = Binder.clearCallingIdentity();
6344 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006345 setWindowWallpaperPositionLocked(
6346 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006347 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006348 } finally {
6349 Binder.restoreCallingIdentity(ident);
6350 }
6351 }
6352 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006353
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006354 public void wallpaperOffsetsComplete(IBinder window) {
6355 WindowManagerService.this.wallpaperOffsetsComplete(window);
6356 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006357
Dianne Hackborn75804932009-10-20 20:15:20 -07006358 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6359 int z, Bundle extras, boolean sync) {
6360 synchronized(mWindowMap) {
6361 long ident = Binder.clearCallingIdentity();
6362 try {
6363 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006364 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006365 action, x, y, z, extras, sync);
6366 } finally {
6367 Binder.restoreCallingIdentity(ident);
6368 }
6369 }
6370 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006371
Dianne Hackborn75804932009-10-20 20:15:20 -07006372 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6373 WindowManagerService.this.wallpaperCommandComplete(window, result);
6374 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 void windowAddedLocked() {
6377 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006378 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 TAG, "First window added to " + this + ", creating SurfaceSession");
6380 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006381 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006382 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 mSessions.add(this);
6384 }
6385 mNumWindow++;
6386 }
6387
6388 void windowRemovedLocked() {
6389 mNumWindow--;
6390 killSessionLocked();
6391 }
Romain Guy06882f82009-06-10 13:36:04 -07006392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006393 void killSessionLocked() {
6394 if (mNumWindow <= 0 && mClientDead) {
6395 mSessions.remove(this);
6396 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006397 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 TAG, "Last window removed from " + this
6399 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006400 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006401 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 try {
6403 mSurfaceSession.kill();
6404 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006405 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406 + mSurfaceSession + " in session " + this
6407 + ": " + e.toString());
6408 }
6409 mSurfaceSession = null;
6410 }
6411 }
6412 }
Romain Guy06882f82009-06-10 13:36:04 -07006413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006415 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6416 pw.print(" mClientDead="); pw.print(mClientDead);
6417 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006418 }
6419
6420 @Override
6421 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006422 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006423 }
6424 }
6425
6426 // -------------------------------------------------------------
6427 // Client Window State
6428 // -------------------------------------------------------------
6429
6430 private final class WindowState implements WindowManagerPolicy.WindowState {
6431 final Session mSession;
6432 final IWindow mClient;
6433 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006434 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006435 AppWindowToken mAppToken;
6436 AppWindowToken mTargetAppToken;
6437 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6438 final DeathRecipient mDeathRecipient;
6439 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006440 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006441 final int mBaseLayer;
6442 final int mSubLayer;
6443 final boolean mLayoutAttached;
6444 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006445 final boolean mIsWallpaper;
6446 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447 int mViewVisibility;
6448 boolean mPolicyVisibility = true;
6449 boolean mPolicyVisibilityAfterAnim = true;
6450 boolean mAppFreezing;
6451 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006452 boolean mReportDestroySurface;
6453 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 boolean mAttachedHidden; // is our parent window hidden?
6455 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006456 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006457 int mRequestedWidth;
6458 int mRequestedHeight;
6459 int mLastRequestedWidth;
6460 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006461 int mLayer;
6462 int mAnimLayer;
6463 int mLastLayer;
6464 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006465 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006466 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006467
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006468 int mLayoutSeq = -1;
6469
6470 Configuration mConfiguration = null;
6471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006472 // Actual frame shown on-screen (may be modified by animation)
6473 final Rect mShownFrame = new Rect();
6474 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006477 * Set when we have changed the size of the surface, to know that
6478 * we must tell them application to resize (and thus redraw itself).
6479 */
6480 boolean mSurfaceResized;
6481
6482 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 * Insets that determine the actually visible area
6484 */
6485 final Rect mVisibleInsets = new Rect();
6486 final Rect mLastVisibleInsets = new Rect();
6487 boolean mVisibleInsetsChanged;
6488
6489 /**
6490 * Insets that are covered by system windows
6491 */
6492 final Rect mContentInsets = new Rect();
6493 final Rect mLastContentInsets = new Rect();
6494 boolean mContentInsetsChanged;
6495
6496 /**
6497 * Set to true if we are waiting for this window to receive its
6498 * given internal insets before laying out other windows based on it.
6499 */
6500 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006502 /**
6503 * These are the content insets that were given during layout for
6504 * this window, to be applied to windows behind it.
6505 */
6506 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006508 /**
6509 * These are the visible insets that were given during layout for
6510 * this window, to be applied to windows behind it.
6511 */
6512 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 /**
6515 * Flag indicating whether the touchable region should be adjusted by
6516 * the visible insets; if false the area outside the visible insets is
6517 * NOT touchable, so we must use those to adjust the frame during hit
6518 * tests.
6519 */
6520 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006522 // Current transformation being applied.
6523 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6524 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6525 float mHScale=1, mVScale=1;
6526 float mLastHScale=1, mLastVScale=1;
6527 final Matrix mTmpMatrix = new Matrix();
6528
6529 // "Real" frame that the application sees.
6530 final Rect mFrame = new Rect();
6531 final Rect mLastFrame = new Rect();
6532
6533 final Rect mContainingFrame = new Rect();
6534 final Rect mDisplayFrame = new Rect();
6535 final Rect mContentFrame = new Rect();
6536 final Rect mVisibleFrame = new Rect();
6537
6538 float mShownAlpha = 1;
6539 float mAlpha = 1;
6540 float mLastAlpha = 1;
6541
6542 // Set to true if, when the window gets displayed, it should perform
6543 // an enter animation.
6544 boolean mEnterAnimationPending;
6545
6546 // Currently running animation.
6547 boolean mAnimating;
6548 boolean mLocalAnimating;
6549 Animation mAnimation;
6550 boolean mAnimationIsEntrance;
6551 boolean mHasTransformation;
6552 boolean mHasLocalTransformation;
6553 final Transformation mTransformation = new Transformation();
6554
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006555 // If a window showing a wallpaper: the requested offset for the
6556 // wallpaper; if a wallpaper window: the currently applied offset.
6557 float mWallpaperX = -1;
6558 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006559
6560 // If a window showing a wallpaper: what fraction of the offset
6561 // range corresponds to a full virtual screen.
6562 float mWallpaperXStep = -1;
6563 float mWallpaperYStep = -1;
6564
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006565 // Wallpaper windows: pixels offset based on above variables.
6566 int mXOffset;
6567 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006569 // This is set after IWindowSession.relayout() has been called at
6570 // least once for the window. It allows us to detect the situation
6571 // where we don't yet have a surface, but should have one soon, so
6572 // we can give the window focus before waiting for the relayout.
6573 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006575 // This is set after the Surface has been created but before the
6576 // window has been drawn. During this time the surface is hidden.
6577 boolean mDrawPending;
6578
6579 // This is set after the window has finished drawing for the first
6580 // time but before its surface is shown. The surface will be
6581 // displayed when the next layout is run.
6582 boolean mCommitDrawPending;
6583
6584 // This is set during the time after the window's drawing has been
6585 // committed, and before its surface is actually shown. It is used
6586 // to delay showing the surface until all windows in a token are ready
6587 // to be shown.
6588 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006590 // Set when the window has been shown in the screen the first time.
6591 boolean mHasDrawn;
6592
6593 // Currently running an exit animation?
6594 boolean mExiting;
6595
6596 // Currently on the mDestroySurface list?
6597 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006599 // Completely remove from window manager after exit animation?
6600 boolean mRemoveOnExit;
6601
6602 // Set when the orientation is changing and this window has not yet
6603 // been updated for the new orientation.
6604 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 // Is this window now (or just being) removed?
6607 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006608
Dianne Hackborn16064f92010-03-25 00:47:24 -07006609 // For debugging, this is the last information given to the surface flinger.
6610 boolean mSurfaceShown;
6611 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6612 int mSurfaceLayer;
6613 float mSurfaceAlpha;
6614
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006615 // Input channel
6616 InputChannel mInputChannel;
6617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006618 WindowState(Session s, IWindow c, WindowToken token,
6619 WindowState attachedWindow, WindowManager.LayoutParams a,
6620 int viewVisibility) {
6621 mSession = s;
6622 mClient = c;
6623 mToken = token;
6624 mAttrs.copyFrom(a);
6625 mViewVisibility = viewVisibility;
6626 DeathRecipient deathRecipient = new DeathRecipient();
6627 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006628 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 TAG, "Window " + this + " client=" + c.asBinder()
6630 + " token=" + token + " (" + mAttrs.token + ")");
6631 try {
6632 c.asBinder().linkToDeath(deathRecipient, 0);
6633 } catch (RemoteException e) {
6634 mDeathRecipient = null;
6635 mAttachedWindow = null;
6636 mLayoutAttached = false;
6637 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006638 mIsWallpaper = false;
6639 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 mBaseLayer = 0;
6641 mSubLayer = 0;
6642 return;
6643 }
6644 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006646 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6647 mAttrs.type <= LAST_SUB_WINDOW)) {
6648 // The multiplier here is to reserve space for multiple
6649 // windows in the same type layer.
6650 mBaseLayer = mPolicy.windowTypeToLayerLw(
6651 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6652 + TYPE_LAYER_OFFSET;
6653 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6654 mAttachedWindow = attachedWindow;
6655 mAttachedWindow.mChildWindows.add(this);
6656 mLayoutAttached = mAttrs.type !=
6657 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6658 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6659 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006660 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6661 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662 } else {
6663 // The multiplier here is to reserve space for multiple
6664 // windows in the same type layer.
6665 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6666 * TYPE_LAYER_MULTIPLIER
6667 + TYPE_LAYER_OFFSET;
6668 mSubLayer = 0;
6669 mAttachedWindow = null;
6670 mLayoutAttached = false;
6671 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6672 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006673 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6674 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006675 }
6676
6677 WindowState appWin = this;
6678 while (appWin.mAttachedWindow != null) {
6679 appWin = mAttachedWindow;
6680 }
6681 WindowToken appToken = appWin.mToken;
6682 while (appToken.appWindowToken == null) {
6683 WindowToken parent = mTokenMap.get(appToken.token);
6684 if (parent == null || appToken == parent) {
6685 break;
6686 }
6687 appToken = parent;
6688 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006689 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006690 mAppToken = appToken.appWindowToken;
6691
6692 mSurface = null;
6693 mRequestedWidth = 0;
6694 mRequestedHeight = 0;
6695 mLastRequestedWidth = 0;
6696 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006697 mXOffset = 0;
6698 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 mLayer = 0;
6700 mAnimLayer = 0;
6701 mLastLayer = 0;
6702 }
6703
6704 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006705 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 TAG, "Attaching " + this + " token=" + mToken
6707 + ", list=" + mToken.windows);
6708 mSession.windowAddedLocked();
6709 }
6710
6711 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6712 mHaveFrame = true;
6713
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006714 final Rect container = mContainingFrame;
6715 container.set(pf);
6716
6717 final Rect display = mDisplayFrame;
6718 display.set(df);
6719
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006720 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006721 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006722 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6723 display.intersect(mCompatibleScreenFrame);
6724 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006725 }
6726
6727 final int pw = container.right - container.left;
6728 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729
6730 int w,h;
6731 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6732 w = mAttrs.width < 0 ? pw : mAttrs.width;
6733 h = mAttrs.height< 0 ? ph : mAttrs.height;
6734 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006735 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6736 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 }
Romain Guy06882f82009-06-10 13:36:04 -07006738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006739 final Rect content = mContentFrame;
6740 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006742 final Rect visible = mVisibleFrame;
6743 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006746 final int fw = frame.width();
6747 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6750 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6751
6752 Gravity.apply(mAttrs.gravity, w, h, container,
6753 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6754 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6755
6756 //System.out.println("Out: " + mFrame);
6757
6758 // Now make sure the window fits in the overall display.
6759 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006761 // Make sure the content and visible frames are inside of the
6762 // final window frame.
6763 if (content.left < frame.left) content.left = frame.left;
6764 if (content.top < frame.top) content.top = frame.top;
6765 if (content.right > frame.right) content.right = frame.right;
6766 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6767 if (visible.left < frame.left) visible.left = frame.left;
6768 if (visible.top < frame.top) visible.top = frame.top;
6769 if (visible.right > frame.right) visible.right = frame.right;
6770 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006772 final Rect contentInsets = mContentInsets;
6773 contentInsets.left = content.left-frame.left;
6774 contentInsets.top = content.top-frame.top;
6775 contentInsets.right = frame.right-content.right;
6776 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 final Rect visibleInsets = mVisibleInsets;
6779 visibleInsets.left = visible.left-frame.left;
6780 visibleInsets.top = visible.top-frame.top;
6781 visibleInsets.right = frame.right-visible.right;
6782 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006783
Dianne Hackborn284ac932009-08-28 10:34:25 -07006784 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6785 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006786 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006787 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006789 if (localLOGV) {
6790 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6791 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006792 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006793 + mRequestedWidth + ", mRequestedheight="
6794 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6795 + "): frame=" + mFrame.toShortString()
6796 + " ci=" + contentInsets.toShortString()
6797 + " vi=" + visibleInsets.toShortString());
6798 //}
6799 }
6800 }
Romain Guy06882f82009-06-10 13:36:04 -07006801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006802 public Rect getFrameLw() {
6803 return mFrame;
6804 }
6805
6806 public Rect getShownFrameLw() {
6807 return mShownFrame;
6808 }
6809
6810 public Rect getDisplayFrameLw() {
6811 return mDisplayFrame;
6812 }
6813
6814 public Rect getContentFrameLw() {
6815 return mContentFrame;
6816 }
6817
6818 public Rect getVisibleFrameLw() {
6819 return mVisibleFrame;
6820 }
6821
6822 public boolean getGivenInsetsPendingLw() {
6823 return mGivenInsetsPending;
6824 }
6825
6826 public Rect getGivenContentInsetsLw() {
6827 return mGivenContentInsets;
6828 }
Romain Guy06882f82009-06-10 13:36:04 -07006829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006830 public Rect getGivenVisibleInsetsLw() {
6831 return mGivenVisibleInsets;
6832 }
Romain Guy06882f82009-06-10 13:36:04 -07006833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 public WindowManager.LayoutParams getAttrs() {
6835 return mAttrs;
6836 }
6837
6838 public int getSurfaceLayer() {
6839 return mLayer;
6840 }
Romain Guy06882f82009-06-10 13:36:04 -07006841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006842 public IApplicationToken getAppToken() {
6843 return mAppToken != null ? mAppToken.appToken : null;
6844 }
Jeff Brown349703e2010-06-22 01:27:15 -07006845
6846 public long getInputDispatchingTimeoutNanos() {
6847 return mAppToken != null
6848 ? mAppToken.inputDispatchingTimeoutNanos
6849 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851
6852 public boolean hasAppShownWindows() {
6853 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6854 }
6855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006857 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 TAG, "Setting animation in " + this + ": " + anim);
6859 mAnimating = false;
6860 mLocalAnimating = false;
6861 mAnimation = anim;
6862 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6863 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6864 }
6865
6866 public void clearAnimation() {
6867 if (mAnimation != null) {
6868 mAnimating = true;
6869 mLocalAnimating = false;
6870 mAnimation = null;
6871 }
6872 }
Romain Guy06882f82009-06-10 13:36:04 -07006873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 Surface createSurfaceLocked() {
6875 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006876 mReportDestroySurface = false;
6877 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 mDrawPending = true;
6879 mCommitDrawPending = false;
6880 mReadyToShow = false;
6881 if (mAppToken != null) {
6882 mAppToken.allDrawn = false;
6883 }
6884
6885 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006886 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 flags |= Surface.PUSH_BUFFERS;
6888 }
6889
6890 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6891 flags |= Surface.SECURE;
6892 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006893 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006894 TAG, "Creating surface in session "
6895 + mSession.mSurfaceSession + " window " + this
6896 + " w=" + mFrame.width()
6897 + " h=" + mFrame.height() + " format="
6898 + mAttrs.format + " flags=" + flags);
6899
6900 int w = mFrame.width();
6901 int h = mFrame.height();
6902 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6903 // for a scaled surface, we always want the requested
6904 // size.
6905 w = mRequestedWidth;
6906 h = mRequestedHeight;
6907 }
6908
Romain Guy9825ec62009-10-01 00:58:09 -07006909 // Something is wrong and SurfaceFlinger will not like this,
6910 // try to revert to sane values
6911 if (w <= 0) w = 1;
6912 if (h <= 0) h = 1;
6913
Dianne Hackborn16064f92010-03-25 00:47:24 -07006914 mSurfaceShown = false;
6915 mSurfaceLayer = 0;
6916 mSurfaceAlpha = 1;
6917 mSurfaceX = 0;
6918 mSurfaceY = 0;
6919 mSurfaceW = w;
6920 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006921 try {
Romain Guyd10cd572010-10-10 13:33:22 -07006922 final boolean isHwAccelerated = (mAttrs.flags &
6923 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
6924 final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format;
6925 if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) {
6926 flags |= Surface.OPAQUE;
6927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006928 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006929 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006930 mAttrs.getTitle().toString(),
Romain Guyd10cd572010-10-10 13:33:22 -07006931 0, w, h, format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006932 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006933 + mSurface + " IN SESSION "
6934 + mSession.mSurfaceSession
6935 + ": pid=" + mSession.mPid + " format="
6936 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006937 + Integer.toHexString(flags)
6938 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006939 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006940 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 reclaimSomeSurfaceMemoryLocked(this, "create");
6942 return null;
6943 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006944 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 return null;
6946 }
Romain Guy06882f82009-06-10 13:36:04 -07006947
Joe Onorato8a9b2202010-02-26 18:56:32 -08006948 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 TAG, "Got surface: " + mSurface
6950 + ", set left=" + mFrame.left + " top=" + mFrame.top
6951 + ", animLayer=" + mAnimLayer);
6952 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006953 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006954 if (SHOW_TRANSACTIONS) logSurface(this,
6955 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6956 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6957 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 }
6959 Surface.openTransaction();
6960 try {
6961 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006962 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006963 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006964 mSurface.setPosition(mSurfaceX, mSurfaceY);
6965 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006966 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006967 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 mSurface.hide();
6969 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006970 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006971 mSurface.setFlags(Surface.SURFACE_DITHER,
6972 Surface.SURFACE_DITHER);
6973 }
6974 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006975 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006976 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6977 }
6978 mLastHidden = true;
6979 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006980 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 Surface.closeTransaction();
6982 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006983 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006984 TAG, "Created surface " + this);
6985 }
6986 return mSurface;
6987 }
Romain Guy06882f82009-06-10 13:36:04 -07006988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006989 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006990 if (mAppToken != null && this == mAppToken.startingWindow) {
6991 mAppToken.startingDisplayed = false;
6992 }
Romain Guy06882f82009-06-10 13:36:04 -07006993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006994 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006995 mDrawPending = false;
6996 mCommitDrawPending = false;
6997 mReadyToShow = false;
6998
6999 int i = mChildWindows.size();
7000 while (i > 0) {
7001 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007002 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007003 c.mAttachedHidden = true;
7004 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007005
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007006 if (mReportDestroySurface) {
7007 mReportDestroySurface = false;
7008 mSurfacePendingDestroy = true;
7009 try {
7010 mClient.dispatchGetNewSurface();
7011 // We'll really destroy on the next time around.
7012 return;
7013 } catch (RemoteException e) {
7014 }
7015 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007017 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007018 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007019 RuntimeException e = null;
7020 if (!HIDE_STACK_CRAWLS) {
7021 e = new RuntimeException();
7022 e.fillInStackTrace();
7023 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007024 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007025 + mSurface + ", session " + mSession, e);
7026 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007027 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007028 RuntimeException e = null;
7029 if (!HIDE_STACK_CRAWLS) {
7030 e = new RuntimeException();
7031 e.fillInStackTrace();
7032 }
7033 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007034 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07007035 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007036 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007037 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007038 + " surface " + mSurface + " session " + mSession
7039 + ": " + e.toString());
7040 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007041
Dianne Hackborn16064f92010-03-25 00:47:24 -07007042 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007043 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 }
7045 }
7046
7047 boolean finishDrawingLocked() {
7048 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007049 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007050 TAG, "finishDrawingLocked: " + mSurface);
7051 mCommitDrawPending = true;
7052 mDrawPending = false;
7053 return true;
7054 }
7055 return false;
7056 }
7057
7058 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007059 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007060 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007062 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007063 }
7064 mCommitDrawPending = false;
7065 mReadyToShow = true;
7066 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
7067 final AppWindowToken atoken = mAppToken;
7068 if (atoken == null || atoken.allDrawn || starting) {
7069 performShowLocked();
7070 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07007071 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 }
7073
7074 // This must be called while inside a transaction.
7075 boolean performShowLocked() {
7076 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007077 RuntimeException e = null;
7078 if (!HIDE_STACK_CRAWLS) {
7079 e = new RuntimeException();
7080 e.fillInStackTrace();
7081 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007082 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007083 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
7084 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
7085 }
7086 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007087 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
7088 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007089 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007090 + " during animation: policyVis=" + mPolicyVisibility
7091 + " attHidden=" + mAttachedHidden
7092 + " tok.hiddenRequested="
7093 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007094 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007095 + (mAppToken != null ? mAppToken.hidden : false)
7096 + " animating=" + mAnimating
7097 + " tok animating="
7098 + (mAppToken != null ? mAppToken.animating : false));
7099 if (!showSurfaceRobustlyLocked(this)) {
7100 return false;
7101 }
7102 mLastAlpha = -1;
7103 mHasDrawn = true;
7104 mLastHidden = false;
7105 mReadyToShow = false;
7106 enableScreenIfNeededLocked();
7107
7108 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007110 int i = mChildWindows.size();
7111 while (i > 0) {
7112 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007113 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007114 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007115 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007116 if (c.mSurface != null) {
7117 c.performShowLocked();
7118 // It hadn't been shown, which means layout not
7119 // performed on it, so now we want to make sure to
7120 // do a layout. If called from within the transaction
7121 // loop, this will cause it to restart with a new
7122 // layout.
7123 mLayoutNeeded = true;
7124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007125 }
7126 }
Romain Guy06882f82009-06-10 13:36:04 -07007127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007128 if (mAttrs.type != TYPE_APPLICATION_STARTING
7129 && mAppToken != null) {
7130 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007131
Dianne Hackborn248b1882009-09-16 16:46:44 -07007132 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007133 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007134 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007135 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007136 // If this initial window is animating, stop it -- we
7137 // will do an animation to reveal it from behind the
7138 // starting window, so there is no need for it to also
7139 // be doing its own stuff.
7140 if (mAnimation != null) {
7141 mAnimation = null;
7142 // Make sure we clean up the animation.
7143 mAnimating = true;
7144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007145 mFinishedStarting.add(mAppToken);
7146 mH.sendEmptyMessage(H.FINISHED_STARTING);
7147 }
7148 mAppToken.updateReportedVisibilityLocked();
7149 }
7150 }
7151 return true;
7152 }
Romain Guy06882f82009-06-10 13:36:04 -07007153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007154 // This must be called while inside a transaction. Returns true if
7155 // there is more animation to run.
7156 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007157 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007158 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007160 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7161 mHasTransformation = true;
7162 mHasLocalTransformation = true;
7163 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007164 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007165 TAG, "Starting animation in " + this +
7166 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7167 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7168 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7169 mAnimation.setStartTime(currentTime);
7170 mLocalAnimating = true;
7171 mAnimating = true;
7172 }
7173 mTransformation.clear();
7174 final boolean more = mAnimation.getTransformation(
7175 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007176 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007177 TAG, "Stepped animation in " + this +
7178 ": more=" + more + ", xform=" + mTransformation);
7179 if (more) {
7180 // we're not done!
7181 return true;
7182 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007183 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007184 TAG, "Finished animation in " + this +
7185 " @ " + currentTime);
7186 mAnimation = null;
7187 //WindowManagerService.this.dump();
7188 }
7189 mHasLocalTransformation = false;
7190 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007191 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007192 // When our app token is animating, we kind-of pretend like
7193 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7194 // part of this check means that we will only do this if
7195 // our window is not currently exiting, or it is not
7196 // locally animating itself. The idea being that one that
7197 // is exiting and doing a local animation should be removed
7198 // once that animation is done.
7199 mAnimating = true;
7200 mHasTransformation = true;
7201 mTransformation.clear();
7202 return false;
7203 } else if (mHasTransformation) {
7204 // Little trick to get through the path below to act like
7205 // we have finished an animation.
7206 mAnimating = true;
7207 } else if (isAnimating()) {
7208 mAnimating = true;
7209 }
7210 } else if (mAnimation != null) {
7211 // If the display is frozen, and there is a pending animation,
7212 // clear it and make sure we run the cleanup code.
7213 mAnimating = true;
7214 mLocalAnimating = true;
7215 mAnimation = null;
7216 }
Romain Guy06882f82009-06-10 13:36:04 -07007217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 if (!mAnimating && !mLocalAnimating) {
7219 return false;
7220 }
7221
Joe Onorato8a9b2202010-02-26 18:56:32 -08007222 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007223 TAG, "Animation done in " + this + ": exiting=" + mExiting
7224 + ", reportedVisible="
7225 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007227 mAnimating = false;
7228 mLocalAnimating = false;
7229 mAnimation = null;
7230 mAnimLayer = mLayer;
7231 if (mIsImWindow) {
7232 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007233 } else if (mIsWallpaper) {
7234 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007235 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007236 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007237 + " anim layer: " + mAnimLayer);
7238 mHasTransformation = false;
7239 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007240 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7241 if (DEBUG_VISIBILITY) {
7242 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7243 + mPolicyVisibilityAfterAnim);
7244 }
7245 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7246 if (!mPolicyVisibility) {
7247 if (mCurrentFocus == this) {
7248 mFocusMayChange = true;
7249 }
7250 // Window is no longer visible -- make sure if we were waiting
7251 // for it to be displayed before enabling the display, that
7252 // we allow the display to be enabled now.
7253 enableScreenIfNeededLocked();
7254 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007256 mTransformation.clear();
7257 if (mHasDrawn
7258 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7259 && mAppToken != null
7260 && mAppToken.firstWindowDrawn
7261 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007262 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007263 + mToken + ": first real window done animating");
7264 mFinishedStarting.add(mAppToken);
7265 mH.sendEmptyMessage(H.FINISHED_STARTING);
7266 }
Romain Guy06882f82009-06-10 13:36:04 -07007267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007268 finishExit();
7269
7270 if (mAppToken != null) {
7271 mAppToken.updateReportedVisibilityLocked();
7272 }
7273
7274 return false;
7275 }
7276
7277 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007278 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 TAG, "finishExit in " + this
7280 + ": exiting=" + mExiting
7281 + " remove=" + mRemoveOnExit
7282 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 final int N = mChildWindows.size();
7285 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007286 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 }
Romain Guy06882f82009-06-10 13:36:04 -07007288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007289 if (!mExiting) {
7290 return;
7291 }
Romain Guy06882f82009-06-10 13:36:04 -07007292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 if (isWindowAnimating()) {
7294 return;
7295 }
7296
Joe Onorato8a9b2202010-02-26 18:56:32 -08007297 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007298 TAG, "Exit animation finished in " + this
7299 + ": remove=" + mRemoveOnExit);
7300 if (mSurface != null) {
7301 mDestroySurface.add(this);
7302 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007303 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007304 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007305 try {
7306 mSurface.hide();
7307 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007308 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007309 }
7310 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007311 }
7312 mExiting = false;
7313 if (mRemoveOnExit) {
7314 mPendingRemove.add(this);
7315 mRemoveOnExit = false;
7316 }
7317 }
Romain Guy06882f82009-06-10 13:36:04 -07007318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007319 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7320 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7321 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7322 if (dtdx < -.000001f || dtdx > .000001f) return false;
7323 if (dsdy < -.000001f || dsdy > .000001f) return false;
7324 return true;
7325 }
Romain Guy06882f82009-06-10 13:36:04 -07007326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007327 void computeShownFrameLocked() {
7328 final boolean selfTransformation = mHasLocalTransformation;
7329 Transformation attachedTransformation =
7330 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7331 ? mAttachedWindow.mTransformation : null;
7332 Transformation appTransformation =
7333 (mAppToken != null && mAppToken.hasTransformation)
7334 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007335
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007336 // Wallpapers are animated based on the "real" window they
7337 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007338 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007339 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007340 if (mWallpaperTarget.mHasLocalTransformation &&
7341 mWallpaperTarget.mAnimation != null &&
7342 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007343 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007344 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007345 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007346 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007347 }
7348 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007349 mWallpaperTarget.mAppToken.hasTransformation &&
7350 mWallpaperTarget.mAppToken.animation != null &&
7351 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007352 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007353 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007354 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007355 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007356 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007357 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007359 if (selfTransformation || attachedTransformation != null
7360 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007361 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007362 final Rect frame = mFrame;
7363 final float tmpFloats[] = mTmpFloats;
7364 final Matrix tmpMatrix = mTmpMatrix;
7365
7366 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007367 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007368 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007369 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007370 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007371 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007372 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007373 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007374 }
7375 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007376 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007377 }
7378
7379 // "convert" it into SurfaceFlinger's format
7380 // (a 2x2 matrix + an offset)
7381 // Here we must not transform the position of the surface
7382 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007383 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 tmpMatrix.getValues(tmpFloats);
7386 mDsDx = tmpFloats[Matrix.MSCALE_X];
7387 mDtDx = tmpFloats[Matrix.MSKEW_X];
7388 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7389 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007390 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7391 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 int w = frame.width();
7393 int h = frame.height();
7394 mShownFrame.set(x, y, x+w, y+h);
7395
7396 // Now set the alpha... but because our current hardware
7397 // can't do alpha transformation on a non-opaque surface,
7398 // turn it off if we are running an animation that is also
7399 // transforming since it is more important to have that
7400 // animation be smooth.
7401 mShownAlpha = mAlpha;
7402 if (!mLimitedAlphaCompositing
7403 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7404 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7405 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007406 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 if (selfTransformation) {
7408 mShownAlpha *= mTransformation.getAlpha();
7409 }
7410 if (attachedTransformation != null) {
7411 mShownAlpha *= attachedTransformation.getAlpha();
7412 }
7413 if (appTransformation != null) {
7414 mShownAlpha *= appTransformation.getAlpha();
7415 }
7416 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007417 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007418 }
Romain Guy06882f82009-06-10 13:36:04 -07007419
Joe Onorato8a9b2202010-02-26 18:56:32 -08007420 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 TAG, "Continuing animation in " + this +
7422 ": " + mShownFrame +
7423 ", alpha=" + mTransformation.getAlpha());
7424 return;
7425 }
Romain Guy06882f82009-06-10 13:36:04 -07007426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007428 if (mXOffset != 0 || mYOffset != 0) {
7429 mShownFrame.offset(mXOffset, mYOffset);
7430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007431 mShownAlpha = mAlpha;
7432 mDsDx = 1;
7433 mDtDx = 0;
7434 mDsDy = 0;
7435 mDtDy = 1;
7436 }
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 /**
7439 * Is this window visible? It is not visible if there is no
7440 * surface, or we are in the process of running an exit animation
7441 * that will remove the surface, or its app token has been hidden.
7442 */
7443 public boolean isVisibleLw() {
7444 final AppWindowToken atoken = mAppToken;
7445 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7446 && (atoken == null || !atoken.hiddenRequested)
7447 && !mExiting && !mDestroying;
7448 }
7449
7450 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007451 * Like {@link #isVisibleLw}, but also counts a window that is currently
7452 * "hidden" behind the keyguard as visible. This allows us to apply
7453 * things like window flags that impact the keyguard.
7454 * XXX I am starting to think we need to have ANOTHER visibility flag
7455 * for this "hidden behind keyguard" state rather than overloading
7456 * mPolicyVisibility. Ungh.
7457 */
7458 public boolean isVisibleOrBehindKeyguardLw() {
7459 final AppWindowToken atoken = mAppToken;
7460 return mSurface != null && !mAttachedHidden
7461 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007462 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007463 && !mExiting && !mDestroying;
7464 }
7465
7466 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 * Is this window visible, ignoring its app token? It is not visible
7468 * if there is no surface, or we are in the process of running an exit animation
7469 * that will remove the surface.
7470 */
7471 public boolean isWinVisibleLw() {
7472 final AppWindowToken atoken = mAppToken;
7473 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7474 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7475 && !mExiting && !mDestroying;
7476 }
7477
7478 /**
7479 * The same as isVisible(), but follows the current hidden state of
7480 * the associated app token, not the pending requested hidden state.
7481 */
7482 boolean isVisibleNow() {
7483 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007484 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007485 }
7486
7487 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007488 * Can this window possibly be a drag/drop target? The test here is
7489 * a combination of the above "visible now" with the check that the
7490 * Input Manager uses when discarding windows from input consideration.
7491 */
7492 boolean isPotentialDragTarget() {
7493 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7494 }
7495
7496 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007497 * Same as isVisible(), but we also count it as visible between the
7498 * call to IWindowSession.add() and the first relayout().
7499 */
7500 boolean isVisibleOrAdding() {
7501 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007502 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7504 && mPolicyVisibility && !mAttachedHidden
7505 && (atoken == null || !atoken.hiddenRequested)
7506 && !mExiting && !mDestroying;
7507 }
7508
7509 /**
7510 * Is this window currently on-screen? It is on-screen either if it
7511 * is visible or it is currently running an animation before no longer
7512 * being visible.
7513 */
7514 boolean isOnScreen() {
7515 final AppWindowToken atoken = mAppToken;
7516 if (atoken != null) {
7517 return mSurface != null && mPolicyVisibility && !mDestroying
7518 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007519 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 } else {
7521 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007522 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007523 }
7524 }
Romain Guy06882f82009-06-10 13:36:04 -07007525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007526 /**
7527 * Like isOnScreen(), but we don't return true if the window is part
7528 * of a transition that has not yet been started.
7529 */
7530 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007531 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007532 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007533 return false;
7534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007536 final boolean animating = atoken != null
7537 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007538 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007539 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7540 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007541 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007542 }
7543
7544 /** Is the window or its container currently animating? */
7545 boolean isAnimating() {
7546 final WindowState attached = mAttachedWindow;
7547 final AppWindowToken atoken = mAppToken;
7548 return mAnimation != null
7549 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007550 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 (atoken.animation != null
7552 || atoken.inPendingTransaction));
7553 }
7554
7555 /** Is this window currently animating? */
7556 boolean isWindowAnimating() {
7557 return mAnimation != null;
7558 }
7559
7560 /**
7561 * Like isOnScreen, but returns false if the surface hasn't yet
7562 * been drawn.
7563 */
7564 public boolean isDisplayedLw() {
7565 final AppWindowToken atoken = mAppToken;
7566 return mSurface != null && mPolicyVisibility && !mDestroying
7567 && !mDrawPending && !mCommitDrawPending
7568 && ((!mAttachedHidden &&
7569 (atoken == null || !atoken.hiddenRequested))
7570 || mAnimating);
7571 }
7572
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007573 /**
7574 * Returns true if the window has a surface that it has drawn a
7575 * complete UI in to.
7576 */
7577 public boolean isDrawnLw() {
7578 final AppWindowToken atoken = mAppToken;
7579 return mSurface != null && !mDestroying
7580 && !mDrawPending && !mCommitDrawPending;
7581 }
7582
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007583 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007584 * Return true if the window is opaque and fully drawn. This indicates
7585 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007586 */
7587 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007588 return (mAttrs.format == PixelFormat.OPAQUE
7589 || mAttrs.type == TYPE_WALLPAPER)
7590 && mSurface != null && mAnimation == null
7591 && (mAppToken == null || mAppToken.animation == null)
7592 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007593 }
7594
7595 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7596 return
7597 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007598 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7599 // only if it's visible
7600 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007601 // and only if the application fills the compatible screen
7602 mFrame.left <= mCompatibleScreenFrame.left &&
7603 mFrame.top <= mCompatibleScreenFrame.top &&
7604 mFrame.right >= mCompatibleScreenFrame.right &&
7605 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007606 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007607 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007608 }
7609
7610 boolean isFullscreen(int screenWidth, int screenHeight) {
7611 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007612 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 }
7614
7615 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007616 disposeInputChannel();
7617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 if (mAttachedWindow != null) {
7619 mAttachedWindow.mChildWindows.remove(this);
7620 }
7621 destroySurfaceLocked();
7622 mSession.windowRemovedLocked();
7623 try {
7624 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7625 } catch (RuntimeException e) {
7626 // Ignore if it has already been removed (usually because
7627 // we are doing this as part of processing a death note.)
7628 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007629 }
7630
7631 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007632 if (mInputChannel != null) {
7633 mInputManager.unregisterInputChannel(mInputChannel);
7634
7635 mInputChannel.dispose();
7636 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007637 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007638 }
7639
7640 private class DeathRecipient implements IBinder.DeathRecipient {
7641 public void binderDied() {
7642 try {
7643 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007644 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007645 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007646 if (win != null) {
7647 removeWindowLocked(mSession, win);
7648 }
7649 }
7650 } catch (IllegalArgumentException ex) {
7651 // This will happen if the window has already been
7652 // removed.
7653 }
7654 }
7655 }
7656
7657 /** Returns true if this window desires key events. */
7658 public final boolean canReceiveKeys() {
7659 return isVisibleOrAdding()
7660 && (mViewVisibility == View.VISIBLE)
7661 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7662 }
7663
7664 public boolean hasDrawnLw() {
7665 return mHasDrawn;
7666 }
7667
7668 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007669 return showLw(doAnimation, true);
7670 }
7671
7672 boolean showLw(boolean doAnimation, boolean requestAnim) {
7673 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7674 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007675 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007676 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007677 if (doAnimation) {
7678 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7679 + mPolicyVisibility + " mAnimation=" + mAnimation);
7680 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7681 doAnimation = false;
7682 } else if (mPolicyVisibility && mAnimation == null) {
7683 // Check for the case where we are currently visible and
7684 // not animating; we do not want to do animation at such a
7685 // point to become visible when we already are.
7686 doAnimation = false;
7687 }
7688 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007689 mPolicyVisibility = true;
7690 mPolicyVisibilityAfterAnim = true;
7691 if (doAnimation) {
7692 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7693 }
7694 if (requestAnim) {
7695 requestAnimationLocked(0);
7696 }
7697 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007698 }
7699
7700 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007701 return hideLw(doAnimation, true);
7702 }
7703
7704 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007705 if (doAnimation) {
7706 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7707 doAnimation = false;
7708 }
7709 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007710 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7711 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007712 if (!current) {
7713 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007714 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007715 if (doAnimation) {
7716 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7717 if (mAnimation == null) {
7718 doAnimation = false;
7719 }
7720 }
7721 if (doAnimation) {
7722 mPolicyVisibilityAfterAnim = false;
7723 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007724 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007725 mPolicyVisibilityAfterAnim = false;
7726 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007727 // Window is no longer visible -- make sure if we were waiting
7728 // for it to be displayed before enabling the display, that
7729 // we allow the display to be enabled now.
7730 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007731 if (mCurrentFocus == this) {
7732 mFocusMayChange = true;
7733 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007734 }
7735 if (requestAnim) {
7736 requestAnimationLocked(0);
7737 }
7738 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007739 }
7740
7741 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007742 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7743 pw.print(" mClient="); pw.println(mClient.asBinder());
7744 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7745 if (mAttachedWindow != null || mLayoutAttached) {
7746 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7747 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7748 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007749 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7750 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7751 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007752 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7753 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007754 }
7755 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7756 pw.print(" mSubLayer="); pw.print(mSubLayer);
7757 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7758 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7759 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7760 pw.print("="); pw.print(mAnimLayer);
7761 pw.print(" mLastLayer="); pw.println(mLastLayer);
7762 if (mSurface != null) {
7763 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007764 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7765 pw.print(" layer="); pw.print(mSurfaceLayer);
7766 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7767 pw.print(" rect=("); pw.print(mSurfaceX);
7768 pw.print(","); pw.print(mSurfaceY);
7769 pw.print(") "); pw.print(mSurfaceW);
7770 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007771 }
7772 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7773 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7774 if (mAppToken != null) {
7775 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7776 }
7777 if (mTargetAppToken != null) {
7778 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7779 }
7780 pw.print(prefix); pw.print("mViewVisibility=0x");
7781 pw.print(Integer.toHexString(mViewVisibility));
7782 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007783 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7784 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007785 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7786 pw.print(prefix); pw.print("mPolicyVisibility=");
7787 pw.print(mPolicyVisibility);
7788 pw.print(" mPolicyVisibilityAfterAnim=");
7789 pw.print(mPolicyVisibilityAfterAnim);
7790 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7791 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007792 if (!mRelayoutCalled) {
7793 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7794 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007795 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007796 pw.print(" h="); pw.print(mRequestedHeight);
7797 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007798 if (mXOffset != 0 || mYOffset != 0) {
7799 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7800 pw.print(" y="); pw.println(mYOffset);
7801 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007802 pw.print(prefix); pw.print("mGivenContentInsets=");
7803 mGivenContentInsets.printShortString(pw);
7804 pw.print(" mGivenVisibleInsets=");
7805 mGivenVisibleInsets.printShortString(pw);
7806 pw.println();
7807 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7808 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7809 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7810 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007811 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007812 pw.print(prefix); pw.print("mShownFrame=");
7813 mShownFrame.printShortString(pw);
7814 pw.print(" last="); mLastShownFrame.printShortString(pw);
7815 pw.println();
7816 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7817 pw.print(" last="); mLastFrame.printShortString(pw);
7818 pw.println();
7819 pw.print(prefix); pw.print("mContainingFrame=");
7820 mContainingFrame.printShortString(pw);
7821 pw.print(" mDisplayFrame=");
7822 mDisplayFrame.printShortString(pw);
7823 pw.println();
7824 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7825 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7826 pw.println();
7827 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7828 pw.print(" last="); mLastContentInsets.printShortString(pw);
7829 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7830 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7831 pw.println();
7832 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7833 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7834 pw.print(" mAlpha="); pw.print(mAlpha);
7835 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7836 }
7837 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7838 || mAnimation != null) {
7839 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7840 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7841 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7842 pw.print(" mAnimation="); pw.println(mAnimation);
7843 }
7844 if (mHasTransformation || mHasLocalTransformation) {
7845 pw.print(prefix); pw.print("XForm: has=");
7846 pw.print(mHasTransformation);
7847 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7848 pw.print(" "); mTransformation.printShortString(pw);
7849 pw.println();
7850 }
7851 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7852 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7853 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7854 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7855 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7856 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7857 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7858 pw.print(" mDestroying="); pw.print(mDestroying);
7859 pw.print(" mRemoved="); pw.println(mRemoved);
7860 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007861 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007862 pw.print(prefix); pw.print("mOrientationChanging=");
7863 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007864 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7865 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007866 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007867 if (mHScale != 1 || mVScale != 1) {
7868 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7869 pw.print(" mVScale="); pw.println(mVScale);
7870 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007871 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007872 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7873 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7874 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007875 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7876 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7877 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007879 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007880
7881 String makeInputChannelName() {
7882 return Integer.toHexString(System.identityHashCode(this))
7883 + " " + mAttrs.getTitle();
7884 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007885
7886 @Override
7887 public String toString() {
7888 return "Window{"
7889 + Integer.toHexString(System.identityHashCode(this))
7890 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7891 }
7892 }
Romain Guy06882f82009-06-10 13:36:04 -07007893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007894 // -------------------------------------------------------------
7895 // Window Token State
7896 // -------------------------------------------------------------
7897
7898 class WindowToken {
7899 // The actual token.
7900 final IBinder token;
7901
7902 // The type of window this token is for, as per WindowManager.LayoutParams.
7903 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007905 // Set if this token was explicitly added by a client, so should
7906 // not be removed when all windows are removed.
7907 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007908
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007909 // For printing.
7910 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007912 // If this is an AppWindowToken, this is non-null.
7913 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007915 // All of the windows associated with this token.
7916 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7917
7918 // Is key dispatching paused for this token?
7919 boolean paused = false;
7920
7921 // Should this token's windows be hidden?
7922 boolean hidden;
7923
7924 // Temporary for finding which tokens no longer have visible windows.
7925 boolean hasVisible;
7926
Dianne Hackborna8f60182009-09-01 19:01:50 -07007927 // Set to true when this token is in a pending transaction where it
7928 // will be shown.
7929 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007930
Dianne Hackborna8f60182009-09-01 19:01:50 -07007931 // Set to true when this token is in a pending transaction where it
7932 // will be hidden.
7933 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007934
Dianne Hackborna8f60182009-09-01 19:01:50 -07007935 // Set to true when this token is in a pending transaction where its
7936 // windows will be put to the bottom of the list.
7937 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007938
Dianne Hackborna8f60182009-09-01 19:01:50 -07007939 // Set to true when this token is in a pending transaction where its
7940 // windows will be put to the top of the list.
7941 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007943 WindowToken(IBinder _token, int type, boolean _explicit) {
7944 token = _token;
7945 windowType = type;
7946 explicit = _explicit;
7947 }
7948
7949 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007950 pw.print(prefix); pw.print("token="); pw.println(token);
7951 pw.print(prefix); pw.print("windows="); pw.println(windows);
7952 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7953 pw.print(" hidden="); pw.print(hidden);
7954 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007955 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7956 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7957 pw.print(" waitingToHide="); pw.print(waitingToHide);
7958 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7959 pw.print(" sendingToTop="); pw.println(sendingToTop);
7960 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007961 }
7962
7963 @Override
7964 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007965 if (stringName == null) {
7966 StringBuilder sb = new StringBuilder();
7967 sb.append("WindowToken{");
7968 sb.append(Integer.toHexString(System.identityHashCode(this)));
7969 sb.append(" token="); sb.append(token); sb.append('}');
7970 stringName = sb.toString();
7971 }
7972 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 }
7974 };
7975
7976 class AppWindowToken extends WindowToken {
7977 // Non-null only for application tokens.
7978 final IApplicationToken appToken;
7979
7980 // All of the windows and child windows that are included in this
7981 // application token. Note this list is NOT sorted!
7982 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7983
7984 int groupId = -1;
7985 boolean appFullscreen;
7986 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007987
7988 // The input dispatching timeout for this application token in nanoseconds.
7989 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007991 // These are used for determining when all windows associated with
7992 // an activity have been drawn, so they can be made visible together
7993 // at the same time.
7994 int lastTransactionSequence = mTransactionSequence-1;
7995 int numInterestingWindows;
7996 int numDrawnWindows;
7997 boolean inPendingTransaction;
7998 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008000 // Is this token going to be hidden in a little while? If so, it
8001 // won't be taken into account for setting the screen orientation.
8002 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008004 // Is this window's surface needed? This is almost like hidden, except
8005 // it will sometimes be true a little earlier: when the token has
8006 // been shown, but is still waiting for its app transition to execute
8007 // before making its windows shown.
8008 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07008009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008010 // Have we told the window clients to hide themselves?
8011 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07008012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008013 // Last visibility state we reported to the app token.
8014 boolean reportedVisible;
8015
8016 // Set to true when the token has been removed from the window mgr.
8017 boolean removed;
8018
8019 // Have we been asked to have this token keep the screen frozen?
8020 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07008021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 boolean animating;
8023 Animation animation;
8024 boolean hasTransformation;
8025 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07008026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008027 // Offset to the window of all layers in the token, for use by
8028 // AppWindowToken animations.
8029 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07008030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008031 // Information about an application starting window if displayed.
8032 StartingData startingData;
8033 WindowState startingWindow;
8034 View startingView;
8035 boolean startingDisplayed;
8036 boolean startingMoved;
8037 boolean firstWindowDrawn;
8038
8039 AppWindowToken(IApplicationToken _token) {
8040 super(_token.asBinder(),
8041 WindowManager.LayoutParams.TYPE_APPLICATION, true);
8042 appWindowToken = this;
8043 appToken = _token;
8044 }
Romain Guy06882f82009-06-10 13:36:04 -07008045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008047 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008048 TAG, "Setting animation in " + this + ": " + anim);
8049 animation = anim;
8050 animating = false;
8051 anim.restrictDuration(MAX_ANIMATION_DURATION);
8052 anim.scaleCurrentDuration(mTransitionAnimationScale);
8053 int zorder = anim.getZAdjustment();
8054 int adj = 0;
8055 if (zorder == Animation.ZORDER_TOP) {
8056 adj = TYPE_LAYER_OFFSET;
8057 } else if (zorder == Animation.ZORDER_BOTTOM) {
8058 adj = -TYPE_LAYER_OFFSET;
8059 }
Romain Guy06882f82009-06-10 13:36:04 -07008060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008061 if (animLayerAdjustment != adj) {
8062 animLayerAdjustment = adj;
8063 updateLayers();
8064 }
8065 }
Romain Guy06882f82009-06-10 13:36:04 -07008066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 public void setDummyAnimation() {
8068 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008069 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008070 TAG, "Setting dummy animation in " + this);
8071 animation = sDummyAnimation;
8072 }
8073 }
8074
8075 public void clearAnimation() {
8076 if (animation != null) {
8077 animation = null;
8078 animating = true;
8079 }
8080 }
Romain Guy06882f82009-06-10 13:36:04 -07008081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008082 void updateLayers() {
8083 final int N = allAppWindows.size();
8084 final int adj = animLayerAdjustment;
8085 for (int i=0; i<N; i++) {
8086 WindowState w = allAppWindows.get(i);
8087 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008088 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 + w.mAnimLayer);
8090 if (w == mInputMethodTarget) {
8091 setInputMethodAnimLayerAdjustment(adj);
8092 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008093 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008094 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008095 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008096 }
8097 }
Romain Guy06882f82009-06-10 13:36:04 -07008098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 void sendAppVisibilityToClients() {
8100 final int N = allAppWindows.size();
8101 for (int i=0; i<N; i++) {
8102 WindowState win = allAppWindows.get(i);
8103 if (win == startingWindow && clientHidden) {
8104 // Don't hide the starting window.
8105 continue;
8106 }
8107 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008108 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008109 "Setting visibility of " + win + ": " + (!clientHidden));
8110 win.mClient.dispatchAppVisibility(!clientHidden);
8111 } catch (RemoteException e) {
8112 }
8113 }
8114 }
Romain Guy06882f82009-06-10 13:36:04 -07008115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008116 void showAllWindowsLocked() {
8117 final int NW = allAppWindows.size();
8118 for (int i=0; i<NW; i++) {
8119 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008120 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 "performing show on: " + w);
8122 w.performShowLocked();
8123 }
8124 }
Romain Guy06882f82009-06-10 13:36:04 -07008125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008126 // This must be called while inside a transaction.
8127 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008128 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008129 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008131 if (animation == sDummyAnimation) {
8132 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008133 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 // when it is really time to animate, this will be set to
8135 // a real animation and the next call will execute normally.
8136 return false;
8137 }
Romain Guy06882f82009-06-10 13:36:04 -07008138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008139 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8140 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008141 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008142 TAG, "Starting animation in " + this +
8143 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8144 + " scale=" + mTransitionAnimationScale
8145 + " allDrawn=" + allDrawn + " animating=" + animating);
8146 animation.initialize(dw, dh, dw, dh);
8147 animation.setStartTime(currentTime);
8148 animating = true;
8149 }
8150 transformation.clear();
8151 final boolean more = animation.getTransformation(
8152 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008153 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008154 TAG, "Stepped animation in " + this +
8155 ": more=" + more + ", xform=" + transformation);
8156 if (more) {
8157 // we're done!
8158 hasTransformation = true;
8159 return true;
8160 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008161 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 TAG, "Finished animation in " + this +
8163 " @ " + currentTime);
8164 animation = null;
8165 }
8166 } else if (animation != null) {
8167 // If the display is frozen, and there is a pending animation,
8168 // clear it and make sure we run the cleanup code.
8169 animating = true;
8170 animation = null;
8171 }
8172
8173 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008175 if (!animating) {
8176 return false;
8177 }
8178
8179 clearAnimation();
8180 animating = false;
8181 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8182 moveInputMethodWindowsIfNeededLocked(true);
8183 }
Romain Guy06882f82009-06-10 13:36:04 -07008184
Joe Onorato8a9b2202010-02-26 18:56:32 -08008185 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008186 TAG, "Animation done in " + this
8187 + ": reportedVisible=" + reportedVisible);
8188
8189 transformation.clear();
8190 if (animLayerAdjustment != 0) {
8191 animLayerAdjustment = 0;
8192 updateLayers();
8193 }
Romain Guy06882f82009-06-10 13:36:04 -07008194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008195 final int N = windows.size();
8196 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008197 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008198 }
8199 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008201 return false;
8202 }
8203
8204 void updateReportedVisibilityLocked() {
8205 if (appToken == null) {
8206 return;
8207 }
Romain Guy06882f82009-06-10 13:36:04 -07008208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008209 int numInteresting = 0;
8210 int numVisible = 0;
8211 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008212
Joe Onorato8a9b2202010-02-26 18:56:32 -08008213 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008214 final int N = allAppWindows.size();
8215 for (int i=0; i<N; i++) {
8216 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008217 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008218 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008219 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8220 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008221 continue;
8222 }
8223 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008224 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008225 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008226 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008227 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008228 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008229 + " pv=" + win.mPolicyVisibility
8230 + " dp=" + win.mDrawPending
8231 + " cdp=" + win.mCommitDrawPending
8232 + " ah=" + win.mAttachedHidden
8233 + " th="
8234 + (win.mAppToken != null
8235 ? win.mAppToken.hiddenRequested : false)
8236 + " a=" + win.mAnimating);
8237 }
8238 }
8239 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008240 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008241 if (!win.isAnimating()) {
8242 numVisible++;
8243 }
8244 nowGone = false;
8245 } else if (win.isAnimating()) {
8246 nowGone = false;
8247 }
8248 }
Romain Guy06882f82009-06-10 13:36:04 -07008249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008251 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008252 + numInteresting + " visible=" + numVisible);
8253 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008254 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008255 TAG, "Visibility changed in " + this
8256 + ": vis=" + nowVisible);
8257 reportedVisible = nowVisible;
8258 Message m = mH.obtainMessage(
8259 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8260 nowVisible ? 1 : 0,
8261 nowGone ? 1 : 0,
8262 this);
8263 mH.sendMessage(m);
8264 }
8265 }
Romain Guy06882f82009-06-10 13:36:04 -07008266
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008267 WindowState findMainWindow() {
8268 int j = windows.size();
8269 while (j > 0) {
8270 j--;
8271 WindowState win = windows.get(j);
8272 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8273 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8274 return win;
8275 }
8276 }
8277 return null;
8278 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008280 void dump(PrintWriter pw, String prefix) {
8281 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008282 if (appToken != null) {
8283 pw.print(prefix); pw.println("app=true");
8284 }
8285 if (allAppWindows.size() > 0) {
8286 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8287 }
8288 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008289 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008290 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8291 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8292 pw.print(" clientHidden="); pw.print(clientHidden);
8293 pw.print(" willBeHidden="); pw.print(willBeHidden);
8294 pw.print(" reportedVisible="); pw.println(reportedVisible);
8295 if (paused || freezingScreen) {
8296 pw.print(prefix); pw.print("paused="); pw.print(paused);
8297 pw.print(" freezingScreen="); pw.println(freezingScreen);
8298 }
8299 if (numInterestingWindows != 0 || numDrawnWindows != 0
8300 || inPendingTransaction || allDrawn) {
8301 pw.print(prefix); pw.print("numInterestingWindows=");
8302 pw.print(numInterestingWindows);
8303 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8304 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8305 pw.print(" allDrawn="); pw.println(allDrawn);
8306 }
8307 if (animating || animation != null) {
8308 pw.print(prefix); pw.print("animating="); pw.print(animating);
8309 pw.print(" animation="); pw.println(animation);
8310 }
8311 if (animLayerAdjustment != 0) {
8312 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8313 }
8314 if (hasTransformation) {
8315 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8316 pw.print(" transformation="); transformation.printShortString(pw);
8317 pw.println();
8318 }
8319 if (startingData != null || removed || firstWindowDrawn) {
8320 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8321 pw.print(" removed="); pw.print(removed);
8322 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8323 }
8324 if (startingWindow != null || startingView != null
8325 || startingDisplayed || startingMoved) {
8326 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8327 pw.print(" startingView="); pw.print(startingView);
8328 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8329 pw.print(" startingMoved"); pw.println(startingMoved);
8330 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008331 }
8332
8333 @Override
8334 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008335 if (stringName == null) {
8336 StringBuilder sb = new StringBuilder();
8337 sb.append("AppWindowToken{");
8338 sb.append(Integer.toHexString(System.identityHashCode(this)));
8339 sb.append(" token="); sb.append(token); sb.append('}');
8340 stringName = sb.toString();
8341 }
8342 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008343 }
8344 }
Romain Guy06882f82009-06-10 13:36:04 -07008345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008346 // -------------------------------------------------------------
8347 // DummyAnimation
8348 // -------------------------------------------------------------
8349
8350 // This is an animation that does nothing: it just immediately finishes
8351 // itself every time it is called. It is used as a stub animation in cases
8352 // where we want to synchronize multiple things that may be animating.
8353 static final class DummyAnimation extends Animation {
8354 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8355 return false;
8356 }
8357 }
8358 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 // -------------------------------------------------------------
8361 // Async Handler
8362 // -------------------------------------------------------------
8363
8364 static final class StartingData {
8365 final String pkg;
8366 final int theme;
8367 final CharSequence nonLocalizedLabel;
8368 final int labelRes;
8369 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008371 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8372 int _labelRes, int _icon) {
8373 pkg = _pkg;
8374 theme = _theme;
8375 nonLocalizedLabel = _nonLocalizedLabel;
8376 labelRes = _labelRes;
8377 icon = _icon;
8378 }
8379 }
8380
8381 private final class H extends Handler {
8382 public static final int REPORT_FOCUS_CHANGE = 2;
8383 public static final int REPORT_LOSING_FOCUS = 3;
8384 public static final int ANIMATE = 4;
8385 public static final int ADD_STARTING = 5;
8386 public static final int REMOVE_STARTING = 6;
8387 public static final int FINISHED_STARTING = 7;
8388 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008389 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8390 public static final int HOLD_SCREEN_CHANGED = 12;
8391 public static final int APP_TRANSITION_TIMEOUT = 13;
8392 public static final int PERSIST_ANIMATION_SCALE = 14;
8393 public static final int FORCE_GC = 15;
8394 public static final int ENABLE_SCREEN = 16;
8395 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008396 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008397 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008398 public static final int DRAG_START_TIMEOUT = 20;
Chris Tated4533f142010-10-19 15:15:08 -07008399 public static final int DRAG_END_TIMEOUT = 21;
Romain Guy06882f82009-06-10 13:36:04 -07008400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008401 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 public H() {
8404 }
Romain Guy06882f82009-06-10 13:36:04 -07008405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008406 @Override
8407 public void handleMessage(Message msg) {
8408 switch (msg.what) {
8409 case REPORT_FOCUS_CHANGE: {
8410 WindowState lastFocus;
8411 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008413 synchronized(mWindowMap) {
8414 lastFocus = mLastFocus;
8415 newFocus = mCurrentFocus;
8416 if (lastFocus == newFocus) {
8417 // Focus is not changing, so nothing to do.
8418 return;
8419 }
8420 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008421 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008422 // + " to " + newFocus);
8423 if (newFocus != null && lastFocus != null
8424 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008425 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008426 mLosingFocus.add(lastFocus);
8427 lastFocus = null;
8428 }
8429 }
8430
8431 if (lastFocus != newFocus) {
8432 //System.out.println("Changing focus from " + lastFocus
8433 // + " to " + newFocus);
8434 if (newFocus != null) {
8435 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008436 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008437 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8438 } catch (RemoteException e) {
8439 // Ignore if process has died.
8440 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008441 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008442 }
8443
8444 if (lastFocus != null) {
8445 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008446 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8448 } catch (RemoteException e) {
8449 // Ignore if process has died.
8450 }
8451 }
8452 }
8453 } break;
8454
8455 case REPORT_LOSING_FOCUS: {
8456 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 synchronized(mWindowMap) {
8459 losers = mLosingFocus;
8460 mLosingFocus = new ArrayList<WindowState>();
8461 }
8462
8463 final int N = losers.size();
8464 for (int i=0; i<N; i++) {
8465 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008466 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8468 } catch (RemoteException e) {
8469 // Ignore if process has died.
8470 }
8471 }
8472 } break;
8473
8474 case ANIMATE: {
8475 synchronized(mWindowMap) {
8476 mAnimationPending = false;
8477 performLayoutAndPlaceSurfacesLocked();
8478 }
8479 } break;
8480
8481 case ADD_STARTING: {
8482 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8483 final StartingData sd = wtoken.startingData;
8484
8485 if (sd == null) {
8486 // Animation has been canceled... do nothing.
8487 return;
8488 }
Romain Guy06882f82009-06-10 13:36:04 -07008489
Joe Onorato8a9b2202010-02-26 18:56:32 -08008490 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008491 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008493 View view = null;
8494 try {
8495 view = mPolicy.addStartingWindow(
8496 wtoken.token, sd.pkg,
8497 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8498 sd.icon);
8499 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008500 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 }
8502
8503 if (view != null) {
8504 boolean abort = false;
8505
8506 synchronized(mWindowMap) {
8507 if (wtoken.removed || wtoken.startingData == null) {
8508 // If the window was successfully added, then
8509 // we need to remove it.
8510 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008511 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008512 "Aborted starting " + wtoken
8513 + ": removed=" + wtoken.removed
8514 + " startingData=" + wtoken.startingData);
8515 wtoken.startingWindow = null;
8516 wtoken.startingData = null;
8517 abort = true;
8518 }
8519 } else {
8520 wtoken.startingView = view;
8521 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008522 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 "Added starting " + wtoken
8524 + ": startingWindow="
8525 + wtoken.startingWindow + " startingView="
8526 + wtoken.startingView);
8527 }
8528
8529 if (abort) {
8530 try {
8531 mPolicy.removeStartingWindow(wtoken.token, view);
8532 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008533 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 }
8535 }
8536 }
8537 } break;
8538
8539 case REMOVE_STARTING: {
8540 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8541 IBinder token = null;
8542 View view = null;
8543 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008544 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 + wtoken + ": startingWindow="
8546 + wtoken.startingWindow + " startingView="
8547 + wtoken.startingView);
8548 if (wtoken.startingWindow != null) {
8549 view = wtoken.startingView;
8550 token = wtoken.token;
8551 wtoken.startingData = null;
8552 wtoken.startingView = null;
8553 wtoken.startingWindow = null;
8554 }
8555 }
8556 if (view != null) {
8557 try {
8558 mPolicy.removeStartingWindow(token, view);
8559 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008560 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 }
8562 }
8563 } break;
8564
8565 case FINISHED_STARTING: {
8566 IBinder token = null;
8567 View view = null;
8568 while (true) {
8569 synchronized (mWindowMap) {
8570 final int N = mFinishedStarting.size();
8571 if (N <= 0) {
8572 break;
8573 }
8574 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8575
Joe Onorato8a9b2202010-02-26 18:56:32 -08008576 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 "Finished starting " + wtoken
8578 + ": startingWindow=" + wtoken.startingWindow
8579 + " startingView=" + wtoken.startingView);
8580
8581 if (wtoken.startingWindow == null) {
8582 continue;
8583 }
8584
8585 view = wtoken.startingView;
8586 token = wtoken.token;
8587 wtoken.startingData = null;
8588 wtoken.startingView = null;
8589 wtoken.startingWindow = null;
8590 }
8591
8592 try {
8593 mPolicy.removeStartingWindow(token, view);
8594 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008595 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008596 }
8597 }
8598 } break;
8599
8600 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8601 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8602
8603 boolean nowVisible = msg.arg1 != 0;
8604 boolean nowGone = msg.arg2 != 0;
8605
8606 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008607 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008608 TAG, "Reporting visible in " + wtoken
8609 + " visible=" + nowVisible
8610 + " gone=" + nowGone);
8611 if (nowVisible) {
8612 wtoken.appToken.windowsVisible();
8613 } else {
8614 wtoken.appToken.windowsGone();
8615 }
8616 } catch (RemoteException ex) {
8617 }
8618 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008620 case WINDOW_FREEZE_TIMEOUT: {
8621 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008622 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008623 int i = mWindows.size();
8624 while (i > 0) {
8625 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008626 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008627 if (w.mOrientationChanging) {
8628 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008629 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008630 }
8631 }
8632 performLayoutAndPlaceSurfacesLocked();
8633 }
8634 break;
8635 }
Romain Guy06882f82009-06-10 13:36:04 -07008636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 case HOLD_SCREEN_CHANGED: {
8638 Session oldHold;
8639 Session newHold;
8640 synchronized (mWindowMap) {
8641 oldHold = mLastReportedHold;
8642 newHold = (Session)msg.obj;
8643 mLastReportedHold = newHold;
8644 }
Romain Guy06882f82009-06-10 13:36:04 -07008645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008646 if (oldHold != newHold) {
8647 try {
8648 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008649 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008650 "window",
8651 BatteryStats.WAKE_TYPE_WINDOW);
8652 }
8653 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008654 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 "window",
8656 BatteryStats.WAKE_TYPE_WINDOW);
8657 }
8658 } catch (RemoteException e) {
8659 }
8660 }
8661 break;
8662 }
Romain Guy06882f82009-06-10 13:36:04 -07008663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664 case APP_TRANSITION_TIMEOUT: {
8665 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008666 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008667 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 "*** APP TRANSITION TIMEOUT");
8669 mAppTransitionReady = true;
8670 mAppTransitionTimeout = true;
8671 performLayoutAndPlaceSurfacesLocked();
8672 }
8673 }
8674 break;
8675 }
Romain Guy06882f82009-06-10 13:36:04 -07008676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008677 case PERSIST_ANIMATION_SCALE: {
8678 Settings.System.putFloat(mContext.getContentResolver(),
8679 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8680 Settings.System.putFloat(mContext.getContentResolver(),
8681 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8682 break;
8683 }
Romain Guy06882f82009-06-10 13:36:04 -07008684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008685 case FORCE_GC: {
8686 synchronized(mWindowMap) {
8687 if (mAnimationPending) {
8688 // If we are animating, don't do the gc now but
8689 // delay a bit so we don't interrupt the animation.
8690 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8691 2000);
8692 return;
8693 }
8694 // If we are currently rotating the display, it will
8695 // schedule a new message when done.
8696 if (mDisplayFrozen) {
8697 return;
8698 }
8699 mFreezeGcPending = 0;
8700 }
8701 Runtime.getRuntime().gc();
8702 break;
8703 }
Romain Guy06882f82009-06-10 13:36:04 -07008704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008705 case ENABLE_SCREEN: {
8706 performEnableScreen();
8707 break;
8708 }
Romain Guy06882f82009-06-10 13:36:04 -07008709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 case APP_FREEZE_TIMEOUT: {
8711 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008712 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008713 int i = mAppTokens.size();
8714 while (i > 0) {
8715 i--;
8716 AppWindowToken tok = mAppTokens.get(i);
8717 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008718 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 unsetAppFreezingScreenLocked(tok, true, true);
8720 }
8721 }
8722 }
8723 break;
8724 }
Romain Guy06882f82009-06-10 13:36:04 -07008725
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008726 case SEND_NEW_CONFIGURATION: {
8727 removeMessages(SEND_NEW_CONFIGURATION);
8728 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008729 break;
8730 }
Romain Guy06882f82009-06-10 13:36:04 -07008731
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008732 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008733 if (mWindowsChanged) {
8734 synchronized (mWindowMap) {
8735 mWindowsChanged = false;
8736 }
8737 notifyWindowsChanged();
8738 }
8739 break;
8740 }
8741
Christopher Tatea53146c2010-09-07 11:57:52 -07008742 case DRAG_START_TIMEOUT: {
8743 IBinder win = (IBinder)msg.obj;
8744 if (DEBUG_DRAG) {
8745 Slog.w(TAG, "Timeout starting drag by win " + win);
8746 }
8747 synchronized (mWindowMap) {
8748 // !!! TODO: ANR the app that has failed to start the drag in time
8749 if (mDragState != null) {
Chris Tated4533f142010-10-19 15:15:08 -07008750 mDragState.unregister();
8751 mInputMonitor.updateInputWindowsLw();
Christopher Tatea53146c2010-09-07 11:57:52 -07008752 mDragState.reset();
8753 mDragState = null;
8754 }
8755 }
Chris Tated4533f142010-10-19 15:15:08 -07008756 break;
Christopher Tatea53146c2010-09-07 11:57:52 -07008757 }
8758
Chris Tated4533f142010-10-19 15:15:08 -07008759 case DRAG_END_TIMEOUT: {
8760 IBinder win = (IBinder)msg.obj;
8761 if (DEBUG_DRAG) {
8762 Slog.w(TAG, "Timeout ending drag to win " + win);
8763 }
8764 synchronized (mWindowMap) {
8765 // !!! TODO: ANR the drag-receiving app
8766 mDragState.mDragResult = false;
8767 mDragState.endDragLw();
8768 }
8769 break;
8770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 }
8772 }
8773 }
8774
8775 // -------------------------------------------------------------
8776 // IWindowManager API
8777 // -------------------------------------------------------------
8778
8779 public IWindowSession openSession(IInputMethodClient client,
8780 IInputContext inputContext) {
8781 if (client == null) throw new IllegalArgumentException("null client");
8782 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008783 Session session = new Session(client, inputContext);
8784 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008785 }
8786
8787 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8788 synchronized (mWindowMap) {
8789 // The focus for the client is the window immediately below
8790 // where we would place the input method window.
8791 int idx = findDesiredInputMethodWindowIndexLocked(false);
8792 WindowState imFocus;
8793 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008794 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008795 if (imFocus != null) {
8796 if (imFocus.mSession.mClient != null &&
8797 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8798 return true;
8799 }
8800 }
8801 }
8802 }
8803 return false;
8804 }
Romain Guy06882f82009-06-10 13:36:04 -07008805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008806 // -------------------------------------------------------------
8807 // Internals
8808 // -------------------------------------------------------------
8809
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008810 final WindowState windowForClientLocked(Session session, IWindow client,
8811 boolean throwOnError) {
8812 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813 }
Romain Guy06882f82009-06-10 13:36:04 -07008814
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008815 final WindowState windowForClientLocked(Session session, IBinder client,
8816 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008817 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008818 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008819 TAG, "Looking up client " + client + ": " + win);
8820 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008821 RuntimeException ex = new IllegalArgumentException(
8822 "Requested window " + client + " does not exist");
8823 if (throwOnError) {
8824 throw ex;
8825 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008826 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008827 return null;
8828 }
8829 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008830 RuntimeException ex = new IllegalArgumentException(
8831 "Requested window " + client + " is in session " +
8832 win.mSession + ", not " + session);
8833 if (throwOnError) {
8834 throw ex;
8835 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008836 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008837 return null;
8838 }
8839
8840 return win;
8841 }
8842
Dianne Hackborna8f60182009-09-01 19:01:50 -07008843 final void rebuildAppWindowListLocked() {
8844 int NW = mWindows.size();
8845 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008846 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008847 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008848
Dianne Hackborna8f60182009-09-01 19:01:50 -07008849 // First remove all existing app windows.
8850 i=0;
8851 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008852 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008853 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008854 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008855 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008856 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008857 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008858 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008859 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008860 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008861 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8862 && lastWallpaper == i-1) {
8863 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008864 }
8865 i++;
8866 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008867
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008868 // The wallpaper window(s) typically live at the bottom of the stack,
8869 // so skip them before adding app tokens.
8870 lastWallpaper++;
8871 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008872
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008873 // First add all of the exiting app tokens... these are no longer
8874 // in the main app list, but still have windows shown. We put them
8875 // in the back because now that the animation is over we no longer
8876 // will care about them.
8877 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008878 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008879 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8880 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008881
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008882 // And add in the still active app tokens in Z order.
8883 NT = mAppTokens.size();
8884 for (int j=0; j<NT; j++) {
8885 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008886 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008887
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008888 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008889 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008890 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008891 + " windows but added " + i);
8892 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008893 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008895 private final void assignLayersLocked() {
8896 int N = mWindows.size();
8897 int curBaseLayer = 0;
8898 int curLayer = 0;
8899 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008902 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008903 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8904 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008905 curLayer += WINDOW_LAYER_MULTIPLIER;
8906 w.mLayer = curLayer;
8907 } else {
8908 curBaseLayer = curLayer = w.mBaseLayer;
8909 w.mLayer = curLayer;
8910 }
8911 if (w.mTargetAppToken != null) {
8912 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8913 } else if (w.mAppToken != null) {
8914 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8915 } else {
8916 w.mAnimLayer = w.mLayer;
8917 }
8918 if (w.mIsImWindow) {
8919 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008920 } else if (w.mIsWallpaper) {
8921 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008922 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008923 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924 + w.mAnimLayer);
8925 //System.out.println(
8926 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8927 }
8928 }
8929
8930 private boolean mInLayout = false;
8931 private final void performLayoutAndPlaceSurfacesLocked() {
8932 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008933 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008934 throw new RuntimeException("Recursive call!");
8935 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008936 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008937 return;
8938 }
8939
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008940 if (mWaitingForConfig) {
8941 // Our configuration has changed (most likely rotation), but we
8942 // don't yet have the complete configuration to report to
8943 // applications. Don't do any window layout until we have it.
8944 return;
8945 }
8946
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008947 if (mDisplay == null) {
8948 // Not yet initialized, nothing to do.
8949 return;
8950 }
8951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008952 boolean recoveringMemory = false;
8953 if (mForceRemoves != null) {
8954 recoveringMemory = true;
8955 // Wait a little it for things to settle down, and off we go.
8956 for (int i=0; i<mForceRemoves.size(); i++) {
8957 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008958 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008959 removeWindowInnerLocked(ws.mSession, ws);
8960 }
8961 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008962 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008963 Object tmp = new Object();
8964 synchronized (tmp) {
8965 try {
8966 tmp.wait(250);
8967 } catch (InterruptedException e) {
8968 }
8969 }
8970 }
Romain Guy06882f82009-06-10 13:36:04 -07008971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008972 mInLayout = true;
8973 try {
8974 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 int i = mPendingRemove.size()-1;
8977 if (i >= 0) {
8978 while (i >= 0) {
8979 WindowState w = mPendingRemove.get(i);
8980 removeWindowInnerLocked(w.mSession, w);
8981 i--;
8982 }
8983 mPendingRemove.clear();
8984
8985 mInLayout = false;
8986 assignLayersLocked();
8987 mLayoutNeeded = true;
8988 performLayoutAndPlaceSurfacesLocked();
8989
8990 } else {
8991 mInLayout = false;
8992 if (mLayoutNeeded) {
8993 requestAnimationLocked(0);
8994 }
8995 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008996 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008997 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8998 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008999 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009000 } catch (RuntimeException e) {
9001 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009002 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009003 }
9004 }
9005
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009006 private final int performLayoutLockedInner() {
9007 if (!mLayoutNeeded) {
9008 return 0;
9009 }
9010
9011 mLayoutNeeded = false;
9012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009013 final int dw = mDisplay.getWidth();
9014 final int dh = mDisplay.getHeight();
9015
9016 final int N = mWindows.size();
9017 int i;
9018
Joe Onorato8a9b2202010-02-26 18:56:32 -08009019 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08009020 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
9021
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009022 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07009023
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009024 int seq = mLayoutSeq+1;
9025 if (seq < 0) seq = 0;
9026 mLayoutSeq = seq;
9027
9028 // First perform layout of any root windows (not attached
9029 // to another window).
9030 int topAttached = -1;
9031 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009032 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009033
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009034 // Don't do layout of a window if it is not visible, or
9035 // soon won't be visible, to avoid wasting time and funky
9036 // changes while a window is animating away.
9037 final AppWindowToken atoken = win.mAppToken;
9038 final boolean gone = win.mViewVisibility == View.GONE
9039 || !win.mRelayoutCalled
9040 || win.mRootToken.hidden
9041 || (atoken != null && atoken.hiddenRequested)
9042 || win.mAttachedHidden
9043 || win.mExiting || win.mDestroying;
9044
9045 if (!win.mLayoutAttached) {
9046 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
9047 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
9048 + " mLayoutAttached=" + win.mLayoutAttached);
9049 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
9050 + win.mViewVisibility + " mRelayoutCalled="
9051 + win.mRelayoutCalled + " hidden="
9052 + win.mRootToken.hidden + " hiddenRequested="
9053 + (atoken != null && atoken.hiddenRequested)
9054 + " mAttachedHidden=" + win.mAttachedHidden);
9055 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009056
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009057 // If this view is GONE, then skip it -- keep the current
9058 // frame, and let the caller know so they can ignore it
9059 // if they want. (We do the normal layout for INVISIBLE
9060 // windows, since that means "perform layout as normal,
9061 // just don't display").
9062 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009063 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009064 mPolicy.layoutWindowLw(win, win.mAttrs, null);
9065 win.mLayoutSeq = seq;
9066 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9067 + win.mFrame + " mContainingFrame="
9068 + win.mContainingFrame + " mDisplayFrame="
9069 + win.mDisplayFrame);
9070 } else {
9071 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009072 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07009073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009074 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009075
9076 // Now perform layout of attached windows, which usually
9077 // depend on the position of the window they are attached to.
9078 // XXX does not deal with windows that are attached to windows
9079 // that are themselves attached.
9080 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009081 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009082
9083 // If this view is GONE, then skip it -- keep the current
9084 // frame, and let the caller know so they can ignore it
9085 // if they want. (We do the normal layout for INVISIBLE
9086 // windows, since that means "perform layout as normal,
9087 // just don't display").
9088 if (win.mLayoutAttached) {
9089 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
9090 + " mHaveFrame=" + win.mHaveFrame
9091 + " mViewVisibility=" + win.mViewVisibility
9092 + " mRelayoutCalled=" + win.mRelayoutCalled);
9093 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
9094 || !win.mHaveFrame) {
9095 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
9096 win.mLayoutSeq = seq;
9097 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
9098 + win.mFrame + " mContainingFrame="
9099 + win.mContainingFrame + " mDisplayFrame="
9100 + win.mDisplayFrame);
9101 }
9102 }
9103 }
Jeff Brown349703e2010-06-22 01:27:15 -07009104
9105 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009106 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009107
9108 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009109 }
Romain Guy06882f82009-06-10 13:36:04 -07009110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009111 private final void performLayoutAndPlaceSurfacesLockedInner(
9112 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009113 if (mDisplay == null) {
9114 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9115 return;
9116 }
9117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009118 final long currentTime = SystemClock.uptimeMillis();
9119 final int dw = mDisplay.getWidth();
9120 final int dh = mDisplay.getHeight();
9121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009122 int i;
9123
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009124 if (mFocusMayChange) {
9125 mFocusMayChange = false;
9126 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9127 }
9128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009129 // Initialize state of exiting tokens.
9130 for (i=mExitingTokens.size()-1; i>=0; i--) {
9131 mExitingTokens.get(i).hasVisible = false;
9132 }
9133
9134 // Initialize state of exiting applications.
9135 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9136 mExitingAppTokens.get(i).hasVisible = false;
9137 }
9138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009139 boolean orientationChangeComplete = true;
9140 Session holdScreen = null;
9141 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009142 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009143 boolean focusDisplayed = false;
9144 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009145 boolean createWatermark = false;
9146
9147 if (mFxSession == null) {
9148 mFxSession = new SurfaceSession();
9149 createWatermark = true;
9150 }
9151
9152 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009153
9154 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009155
9156 if (createWatermark) {
9157 createWatermark();
9158 }
9159 if (mWatermark != null) {
9160 mWatermark.positionSurface(dw, dh);
9161 }
9162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009163 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009164 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009165 int repeats = 0;
9166 int changes = 0;
9167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009168 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009169 repeats++;
9170 if (repeats > 6) {
9171 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9172 mLayoutNeeded = false;
9173 break;
9174 }
9175
9176 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9177 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9178 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9179 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9180 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9181 assignLayersLocked();
9182 mLayoutNeeded = true;
9183 }
9184 }
9185 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9186 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9187 if (updateOrientationFromAppTokensLocked()) {
9188 mLayoutNeeded = true;
9189 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9190 }
9191 }
9192 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9193 mLayoutNeeded = true;
9194 }
9195 }
9196
9197 // FIRST LOOP: Perform a layout, if needed.
9198 if (repeats < 4) {
9199 changes = performLayoutLockedInner();
9200 if (changes != 0) {
9201 continue;
9202 }
9203 } else {
9204 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9205 changes = 0;
9206 }
9207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009208 final int transactionSequence = ++mTransactionSequence;
9209
9210 // Update animations of all applications, including those
9211 // associated with exiting/removed apps
9212 boolean tokensAnimating = false;
9213 final int NAT = mAppTokens.size();
9214 for (i=0; i<NAT; i++) {
9215 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9216 tokensAnimating = true;
9217 }
9218 }
9219 final int NEAT = mExitingAppTokens.size();
9220 for (i=0; i<NEAT; i++) {
9221 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9222 tokensAnimating = true;
9223 }
9224 }
9225
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009226 // SECOND LOOP: Execute animations and update visibility of windows.
9227
Joe Onorato8a9b2202010-02-26 18:56:32 -08009228 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009229 + transactionSequence + " tokensAnimating="
9230 + tokensAnimating);
9231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009232 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009233
9234 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009235 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009236 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009237
9238 mPolicy.beginAnimationLw(dw, dh);
9239
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009240 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009243 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244
9245 final WindowManager.LayoutParams attrs = w.mAttrs;
9246
9247 if (w.mSurface != null) {
9248 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009249 if (w.commitFinishDrawingLocked(currentTime)) {
9250 if ((w.mAttrs.flags
9251 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009252 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009253 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009254 wallpaperMayChange = true;
9255 }
9256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009257
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009258 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009259 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9260 animating = true;
9261 //w.dump(" ");
9262 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009263 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9264 wallpaperMayChange = true;
9265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009266
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009267 if (mPolicy.doesForceHide(w, attrs)) {
9268 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009269 if (DEBUG_VISIBILITY) Slog.v(TAG,
9270 "Animation done that could impact force hide: "
9271 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009272 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009273 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009274 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9275 forceHiding = true;
9276 }
9277 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9278 boolean changed;
9279 if (forceHiding) {
9280 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009281 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9282 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009283 } else {
9284 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009285 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9286 "Now policy shown: " + w);
9287 if (changed) {
9288 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009289 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009290 // Assume we will need to animate. If
9291 // we don't (because the wallpaper will
9292 // stay with the lock screen), then we will
9293 // clean up later.
9294 Animation a = mPolicy.createForceHideEnterAnimation();
9295 if (a != null) {
9296 w.setAnimation(a);
9297 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009298 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009299 if (mCurrentFocus == null ||
9300 mCurrentFocus.mLayer < w.mLayer) {
9301 // We are showing on to of the current
9302 // focus, so re-evaluate focus to make
9303 // sure it is correct.
9304 mFocusMayChange = true;
9305 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009306 }
9307 }
9308 if (changed && (attrs.flags
9309 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9310 wallpaperMayChange = true;
9311 }
9312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009314 mPolicy.animatingWindowLw(w, attrs);
9315 }
9316
9317 final AppWindowToken atoken = w.mAppToken;
9318 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9319 if (atoken.lastTransactionSequence != transactionSequence) {
9320 atoken.lastTransactionSequence = transactionSequence;
9321 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9322 atoken.startingDisplayed = false;
9323 }
9324 if ((w.isOnScreen() || w.mAttrs.type
9325 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9326 && !w.mExiting && !w.mDestroying) {
9327 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009328 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009329 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009331 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009332 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009333 + " pv=" + w.mPolicyVisibility
9334 + " dp=" + w.mDrawPending
9335 + " cdp=" + w.mCommitDrawPending
9336 + " ah=" + w.mAttachedHidden
9337 + " th=" + atoken.hiddenRequested
9338 + " a=" + w.mAnimating);
9339 }
9340 }
9341 if (w != atoken.startingWindow) {
9342 if (!atoken.freezingScreen || !w.mAppFreezing) {
9343 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009344 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009345 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009346 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 "tokenMayBeDrawn: " + atoken
9348 + " freezingScreen=" + atoken.freezingScreen
9349 + " mAppFreezing=" + w.mAppFreezing);
9350 tokenMayBeDrawn = true;
9351 }
9352 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009353 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 atoken.startingDisplayed = true;
9355 }
9356 }
9357 } else if (w.mReadyToShow) {
9358 w.performShowLocked();
9359 }
9360 }
9361
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009362 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009363
9364 if (tokenMayBeDrawn) {
9365 // See if any windows have been drawn, so they (and others
9366 // associated with them) can now be shown.
9367 final int NT = mTokenList.size();
9368 for (i=0; i<NT; i++) {
9369 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9370 if (wtoken == null) {
9371 continue;
9372 }
9373 if (wtoken.freezingScreen) {
9374 int numInteresting = wtoken.numInterestingWindows;
9375 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009376 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009377 "allDrawn: " + wtoken
9378 + " interesting=" + numInteresting
9379 + " drawn=" + wtoken.numDrawnWindows);
9380 wtoken.showAllWindowsLocked();
9381 unsetAppFreezingScreenLocked(wtoken, false, true);
9382 orientationChangeComplete = true;
9383 }
9384 } else if (!wtoken.allDrawn) {
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.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009392 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009393
9394 // We can now show all of the drawn windows!
9395 if (!mOpeningApps.contains(wtoken)) {
9396 wtoken.showAllWindowsLocked();
9397 }
9398 }
9399 }
9400 }
9401 }
9402
9403 // If we are ready to perform an app transition, check through
9404 // all of the app tokens to be shown and see if they are ready
9405 // to go.
9406 if (mAppTransitionReady) {
9407 int NN = mOpeningApps.size();
9408 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009409 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 "Checking " + NN + " opening apps (frozen="
9411 + mDisplayFrozen + " timeout="
9412 + mAppTransitionTimeout + ")...");
9413 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9414 // If the display isn't frozen, wait to do anything until
9415 // all of the apps are ready. Otherwise just go because
9416 // we'll unfreeze the display when everyone is ready.
9417 for (i=0; i<NN && goodToGo; i++) {
9418 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009419 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009420 "Check opening app" + wtoken + ": allDrawn="
9421 + wtoken.allDrawn + " startingDisplayed="
9422 + wtoken.startingDisplayed);
9423 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9424 && !wtoken.startingMoved) {
9425 goodToGo = false;
9426 }
9427 }
9428 }
9429 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009430 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009431 int transit = mNextAppTransition;
9432 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009433 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009434 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009435 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009436 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009437 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009438 mAppTransitionTimeout = false;
9439 mStartingIconInTransition = false;
9440 mSkipAppTransitionAnimation = false;
9441
9442 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9443
Dianne Hackborna8f60182009-09-01 19:01:50 -07009444 // If there are applications waiting to come to the
9445 // top of the stack, now is the time to move their windows.
9446 // (Note that we don't do apps going to the bottom
9447 // here -- we want to keep their windows in the old
9448 // Z-order until the animation completes.)
9449 if (mToTopApps.size() > 0) {
9450 NN = mAppTokens.size();
9451 for (i=0; i<NN; i++) {
9452 AppWindowToken wtoken = mAppTokens.get(i);
9453 if (wtoken.sendingToTop) {
9454 wtoken.sendingToTop = false;
9455 moveAppWindowsLocked(wtoken, NN, false);
9456 }
9457 }
9458 mToTopApps.clear();
9459 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009460
Dianne Hackborn25994b42009-09-04 14:21:19 -07009461 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009462
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009463 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009464 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009465
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009466 // The top-most window will supply the layout params,
9467 // and we will determine it below.
9468 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009469 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009470 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009471
Joe Onorato8a9b2202010-02-26 18:56:32 -08009472 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009473 "New wallpaper target=" + mWallpaperTarget
9474 + ", lower target=" + mLowerWallpaperTarget
9475 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009476 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009477 // Do a first pass through the tokens for two
9478 // things:
9479 // (1) Determine if both the closing and opening
9480 // app token sets are wallpaper targets, in which
9481 // case special animations are needed
9482 // (since the wallpaper needs to stay static
9483 // behind them).
9484 // (2) Find the layout params of the top-most
9485 // application window in the tokens, which is
9486 // what will control the animation theme.
9487 final int NC = mClosingApps.size();
9488 NN = NC + mOpeningApps.size();
9489 for (i=0; i<NN; i++) {
9490 AppWindowToken wtoken;
9491 int mode;
9492 if (i < NC) {
9493 wtoken = mClosingApps.get(i);
9494 mode = 1;
9495 } else {
9496 wtoken = mOpeningApps.get(i-NC);
9497 mode = 2;
9498 }
9499 if (mLowerWallpaperTarget != null) {
9500 if (mLowerWallpaperTarget.mAppToken == wtoken
9501 || mUpperWallpaperTarget.mAppToken == wtoken) {
9502 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009503 }
9504 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009505 if (wtoken.appFullscreen) {
9506 WindowState ws = wtoken.findMainWindow();
9507 if (ws != null) {
9508 // If this is a compatibility mode
9509 // window, we will always use its anim.
9510 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9511 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009512 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009513 bestAnimLayer = Integer.MAX_VALUE;
9514 } else if (ws.mLayer > bestAnimLayer) {
9515 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009516 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009517 bestAnimLayer = ws.mLayer;
9518 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009519 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009520 }
9521 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009522
Dianne Hackborn25994b42009-09-04 14:21:19 -07009523 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009524 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009525 "Wallpaper animation!");
9526 switch (transit) {
9527 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9528 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9529 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9530 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9531 break;
9532 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9533 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9534 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9535 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9536 break;
9537 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009538 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009539 "New transit: " + transit);
9540 } else if (oldWallpaper != null) {
9541 // We are transitioning from an activity with
9542 // a wallpaper to one without.
9543 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009544 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009545 "New transit away from wallpaper: " + transit);
9546 } else if (mWallpaperTarget != null) {
9547 // We are transitioning from an activity without
9548 // a wallpaper to now showing the wallpaper
9549 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009550 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009551 "New transit into wallpaper: " + transit);
9552 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009553
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009554 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9555 mLastEnterAnimToken = animToken;
9556 mLastEnterAnimParams = animLp;
9557 } else if (mLastEnterAnimParams != null) {
9558 animLp = mLastEnterAnimParams;
9559 mLastEnterAnimToken = null;
9560 mLastEnterAnimParams = null;
9561 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009562
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009563 // If all closing windows are obscured, then there is
9564 // no need to do an animation. This is the case, for
9565 // example, when this transition is being done behind
9566 // the lock screen.
9567 if (!mPolicy.allowAppAnimationsLw()) {
9568 animLp = null;
9569 }
9570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009571 NN = mOpeningApps.size();
9572 for (i=0; i<NN; i++) {
9573 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009574 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009575 "Now opening app" + wtoken);
9576 wtoken.reportedVisible = false;
9577 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009578 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009579 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009581 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009582 wtoken.showAllWindowsLocked();
9583 }
9584 NN = mClosingApps.size();
9585 for (i=0; i<NN; i++) {
9586 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009587 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588 "Now closing app" + wtoken);
9589 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009590 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009591 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009592 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009593 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594 // Force the allDrawn flag, because we want to start
9595 // this guy's animations regardless of whether it's
9596 // gotten drawn.
9597 wtoken.allDrawn = true;
9598 }
9599
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009600 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009602 mOpeningApps.clear();
9603 mClosingApps.clear();
9604
9605 // This has changed the visibility of windows, so perform
9606 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009607 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009608 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009609 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9610 assignLayersLocked();
9611 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009612 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009613 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009614 }
9615 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009616
Dianne Hackborn16064f92010-03-25 00:47:24 -07009617 int adjResult = 0;
9618
Dianne Hackborna8f60182009-09-01 19:01:50 -07009619 if (!animating && mAppTransitionRunning) {
9620 // We have finished the animation of an app transition. To do
9621 // this, we have delayed a lot of operations like showing and
9622 // hiding apps, moving apps in Z-order, etc. The app token list
9623 // reflects the correct Z-order, but the window list may now
9624 // be out of sync with it. So here we will just rebuild the
9625 // entire app window list. Fun!
9626 mAppTransitionRunning = false;
9627 // Clear information about apps that were moving.
9628 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009629
Dianne Hackborna8f60182009-09-01 19:01:50 -07009630 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009631 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009632 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009633 moveInputMethodWindowsIfNeededLocked(false);
9634 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009635 // Since the window list has been rebuilt, focus might
9636 // have to be recomputed since the actual order of windows
9637 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009638 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009639 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009640
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009641 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009642 // At this point, there was a window with a wallpaper that
9643 // was force hiding other windows behind it, but now it
9644 // is going away. This may be simple -- just animate
9645 // away the wallpaper and its window -- or it may be
9646 // hard -- the wallpaper now needs to be shown behind
9647 // something that was hidden.
9648 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009649 if (mLowerWallpaperTarget != null
9650 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009651 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009652 "wallpaperForceHiding changed with lower="
9653 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009654 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009655 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9656 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9657 if (mLowerWallpaperTarget.mAppToken.hidden) {
9658 // The lower target has become hidden before we
9659 // actually started the animation... let's completely
9660 // re-evaluate everything.
9661 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009662 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009663 }
9664 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009665 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009666 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009667 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009668 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009669 + " NEW: " + mWallpaperTarget
9670 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009671 if (mLowerWallpaperTarget == null) {
9672 // Whoops, we don't need a special wallpaper animation.
9673 // Clear them out.
9674 forceHiding = false;
9675 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009676 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009677 if (w.mSurface != null) {
9678 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009679 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009680 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009681 forceHiding = true;
9682 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9683 if (!w.mAnimating) {
9684 // We set the animation above so it
9685 // is not yet running.
9686 w.clearAnimation();
9687 }
9688 }
9689 }
9690 }
9691 }
9692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009693
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009694 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009695 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009696 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009697 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009699
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009700 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009701 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009702 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009703 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009704 assignLayersLocked();
9705 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009706 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009707 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009708 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009710
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009711 if (mFocusMayChange) {
9712 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009713 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009714 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009715 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009716 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009717 }
9718
9719 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009720 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009722
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009723 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9724 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009725
Jeff Browne33348b2010-07-15 23:54:05 -07009726 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009727 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728
9729 // THIRD LOOP: Update the surfaces of all windows.
9730
9731 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9732
9733 boolean obscured = false;
9734 boolean blurring = false;
9735 boolean dimming = false;
9736 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009737 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009738 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009740 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009743 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009744
9745 boolean displayed = false;
9746 final WindowManager.LayoutParams attrs = w.mAttrs;
9747 final int attrFlags = attrs.flags;
9748
9749 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009750 // XXX NOTE: The logic here could be improved. We have
9751 // the decision about whether to resize a window separated
9752 // from whether to hide the surface. This can cause us to
9753 // resize a surface even if we are going to hide it. You
9754 // can see this by (1) holding device in landscape mode on
9755 // home screen; (2) tapping browser icon (device will rotate
9756 // to landscape; (3) tap home. The wallpaper will be resized
9757 // in step 2 but then immediately hidden, causing us to
9758 // have to resize and then redraw it again in step 3. It
9759 // would be nice to figure out how to avoid this, but it is
9760 // difficult because we do need to resize surfaces in some
9761 // cases while they are hidden such as when first showing a
9762 // window.
9763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009765 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009766 TAG, "Placing surface #" + i + " " + w.mSurface
9767 + ": new=" + w.mShownFrame + ", old="
9768 + w.mLastShownFrame);
9769
9770 boolean resize;
9771 int width, height;
9772 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9773 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9774 w.mLastRequestedHeight != w.mRequestedHeight;
9775 // for a scaled surface, we just want to use
9776 // the requested size.
9777 width = w.mRequestedWidth;
9778 height = w.mRequestedHeight;
9779 w.mLastRequestedWidth = width;
9780 w.mLastRequestedHeight = height;
9781 w.mLastShownFrame.set(w.mShownFrame);
9782 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009783 if (SHOW_TRANSACTIONS) logSurface(w,
9784 "POS " + w.mShownFrame.left
9785 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009786 w.mSurfaceX = w.mShownFrame.left;
9787 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9789 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009790 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 if (!recoveringMemory) {
9792 reclaimSomeSurfaceMemoryLocked(w, "position");
9793 }
9794 }
9795 } else {
9796 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9797 width = w.mShownFrame.width();
9798 height = w.mShownFrame.height();
9799 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 }
9801
9802 if (resize) {
9803 if (width < 1) width = 1;
9804 if (height < 1) height = 1;
9805 if (w.mSurface != null) {
9806 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009807 if (SHOW_TRANSACTIONS) logSurface(w,
9808 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009809 + w.mShownFrame.top + " SIZE "
9810 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009811 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009812 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009813 w.mSurfaceW = width;
9814 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009815 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009816 w.mSurfaceX = w.mShownFrame.left;
9817 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 w.mSurface.setPosition(w.mShownFrame.left,
9819 w.mShownFrame.top);
9820 } catch (RuntimeException e) {
9821 // If something goes wrong with the surface (such
9822 // as running out of memory), don't take down the
9823 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009824 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009825 + "size=(" + width + "x" + height
9826 + "), pos=(" + w.mShownFrame.left
9827 + "," + w.mShownFrame.top + ")", e);
9828 if (!recoveringMemory) {
9829 reclaimSomeSurfaceMemoryLocked(w, "size");
9830 }
9831 }
9832 }
9833 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009834 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009835 w.mContentInsetsChanged =
9836 !w.mLastContentInsets.equals(w.mContentInsets);
9837 w.mVisibleInsetsChanged =
9838 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009839 boolean configChanged =
9840 w.mConfiguration != mCurConfiguration
9841 && (w.mConfiguration == null
9842 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009843 if (DEBUG_CONFIGURATION && configChanged) {
9844 Slog.v(TAG, "Win " + w + " config changed: "
9845 + mCurConfiguration);
9846 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009847 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009848 + ": configChanged=" + configChanged
9849 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009850 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009851 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009852 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009853 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009854 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855 w.mLastFrame.set(w.mFrame);
9856 w.mLastContentInsets.set(w.mContentInsets);
9857 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009858 // If the screen is currently frozen, then keep
9859 // it frozen until this window draws at its new
9860 // orientation.
9861 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009862 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009863 "Resizing while display frozen: " + w);
9864 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009865 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009866 mWindowsFreezingScreen = true;
9867 // XXX should probably keep timeout from
9868 // when we first froze the display.
9869 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9870 mH.sendMessageDelayed(mH.obtainMessage(
9871 H.WINDOW_FREEZE_TIMEOUT), 2000);
9872 }
9873 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009874 // If the orientation is changing, then we need to
9875 // hold off on unfreezing the display until this
9876 // window has been redrawn; to do that, we need
9877 // to go through the process of getting informed
9878 // by the application when it has finished drawing.
9879 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009880 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009881 "Orientation start waiting for draw in "
9882 + w + ", surface " + w.mSurface);
9883 w.mDrawPending = true;
9884 w.mCommitDrawPending = false;
9885 w.mReadyToShow = false;
9886 if (w.mAppToken != null) {
9887 w.mAppToken.allDrawn = false;
9888 }
9889 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009890 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891 "Resizing window " + w + " to " + w.mFrame);
9892 mResizingWindows.add(w);
9893 } else if (w.mOrientationChanging) {
9894 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009895 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 "Orientation not waiting for draw in "
9897 + w + ", surface " + w.mSurface);
9898 w.mOrientationChanging = false;
9899 }
9900 }
9901 }
9902
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009903 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009904 if (!w.mLastHidden) {
9905 //dump();
9906 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009907 if (SHOW_TRANSACTIONS) logSurface(w,
9908 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009910 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009911 try {
9912 w.mSurface.hide();
9913 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009914 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 }
9916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 }
9918 // If we are waiting for this window to handle an
9919 // orientation change, well, it is hidden, so
9920 // doesn't really matter. Note that this does
9921 // introduce a potential glitch if the window
9922 // becomes unhidden before it has drawn for the
9923 // new orientation.
9924 if (w.mOrientationChanging) {
9925 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009926 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009927 "Orientation change skips hidden " + w);
9928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 } else if (w.mLastLayer != w.mAnimLayer
9930 || w.mLastAlpha != w.mShownAlpha
9931 || w.mLastDsDx != w.mDsDx
9932 || w.mLastDtDx != w.mDtDx
9933 || w.mLastDsDy != w.mDsDy
9934 || w.mLastDtDy != w.mDtDy
9935 || w.mLastHScale != w.mHScale
9936 || w.mLastVScale != w.mVScale
9937 || w.mLastHidden) {
9938 displayed = true;
9939 w.mLastAlpha = w.mShownAlpha;
9940 w.mLastLayer = w.mAnimLayer;
9941 w.mLastDsDx = w.mDsDx;
9942 w.mLastDtDx = w.mDtDx;
9943 w.mLastDsDy = w.mDsDy;
9944 w.mLastDtDy = w.mDtDy;
9945 w.mLastHScale = w.mHScale;
9946 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009947 if (SHOW_TRANSACTIONS) logSurface(w,
9948 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009949 + " matrix=[" + (w.mDsDx*w.mHScale)
9950 + "," + (w.mDtDx*w.mVScale)
9951 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009952 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009953 if (w.mSurface != null) {
9954 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009955 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009956 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009957 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009958 w.mSurface.setLayer(w.mAnimLayer);
9959 w.mSurface.setMatrix(
9960 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9961 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9962 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 if (!recoveringMemory) {
9965 reclaimSomeSurfaceMemoryLocked(w, "update");
9966 }
9967 }
9968 }
9969
9970 if (w.mLastHidden && !w.mDrawPending
9971 && !w.mCommitDrawPending
9972 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009973 if (SHOW_TRANSACTIONS) logSurface(w,
9974 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009975 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 + " during relayout");
9977 if (showSurfaceRobustlyLocked(w)) {
9978 w.mHasDrawn = true;
9979 w.mLastHidden = false;
9980 } else {
9981 w.mOrientationChanging = false;
9982 }
9983 }
9984 if (w.mSurface != null) {
9985 w.mToken.hasVisible = true;
9986 }
9987 } else {
9988 displayed = true;
9989 }
9990
9991 if (displayed) {
9992 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009993 if (attrs.width == LayoutParams.MATCH_PARENT
9994 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009995 covered = true;
9996 }
9997 }
9998 if (w.mOrientationChanging) {
9999 if (w.mDrawPending || w.mCommitDrawPending) {
10000 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010001 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010002 "Orientation continue waiting for draw in " + w);
10003 } else {
10004 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010005 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010006 "Orientation change complete in " + w);
10007 }
10008 }
10009 w.mToken.hasVisible = true;
10010 }
10011 } else if (w.mOrientationChanging) {
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 change skips hidden " + w);
10014 w.mOrientationChanging = false;
10015 }
10016
10017 final boolean canBeSeen = w.isDisplayedLw();
10018
10019 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
10020 focusDisplayed = true;
10021 }
10022
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010023 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010026 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010027 if (w.mSurface != null) {
10028 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
10029 holdScreen = w.mSession;
10030 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010031 if (!syswin && w.mAttrs.screenBrightness >= 0
10032 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 screenBrightness = w.mAttrs.screenBrightness;
10034 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010035 if (!syswin && w.mAttrs.buttonBrightness >= 0
10036 && buttonBrightness < 0) {
10037 buttonBrightness = w.mAttrs.buttonBrightness;
10038 }
Mike Lockwood46af6a82010-03-09 08:28:22 -050010039 if (canBeSeen
10040 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
10041 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
10042 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -070010043 syswin = true;
10044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010045 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010046
Dianne Hackborn25994b42009-09-04 14:21:19 -070010047 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
10048 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010049 // This window completely covers everything behind it,
10050 // so we want to leave all of them as unblurred (for
10051 // performance reasons).
10052 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010053 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010054 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010055 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010056 obscured = true;
10057 if (mBackgroundFillerSurface == null) {
10058 try {
10059 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010060 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010061 0, dw, dh,
10062 PixelFormat.OPAQUE,
10063 Surface.FX_SURFACE_NORMAL);
10064 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010065 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010066 }
10067 }
10068 try {
10069 mBackgroundFillerSurface.setPosition(0, 0);
10070 mBackgroundFillerSurface.setSize(dw, dh);
10071 // Using the same layer as Dim because they will never be shown at the
10072 // same time.
10073 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
10074 mBackgroundFillerSurface.show();
10075 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010076 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010077 }
10078 backgroundFillerShown = true;
10079 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010080 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010081 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010082 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010083 + ": blurring=" + blurring
10084 + " obscured=" + obscured
10085 + " displayed=" + displayed);
10086 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
10087 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010088 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010089 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010090 if (mDimAnimator == null) {
10091 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010092 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010093 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010094 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010095 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010096 }
10097 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
10098 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010099 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010100 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010101 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010102 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010103 + mBlurSurface + ": CREATE");
10104 try {
Romain Guy06882f82009-06-10 13:36:04 -070010105 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010106 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 -1, 16, 16,
10108 PixelFormat.OPAQUE,
10109 Surface.FX_SURFACE_BLUR);
10110 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010111 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010112 }
10113 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010114 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010115 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10116 + mBlurSurface + ": pos=(0,0) (" +
10117 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010118 mBlurSurface.setPosition(0, 0);
10119 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010120 mBlurSurface.setLayer(w.mAnimLayer-2);
10121 if (!mBlurShown) {
10122 try {
10123 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10124 + mBlurSurface + ": SHOW");
10125 mBlurSurface.show();
10126 } catch (RuntimeException e) {
10127 Slog.w(TAG, "Failure showing blur surface", e);
10128 }
10129 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010130 }
10131 }
10132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010133 }
10134 }
10135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010136
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010137 if (obscuredChanged && mWallpaperTarget == w) {
10138 // This is the wallpaper target and its obscured state
10139 // changed... make sure the current wallaper's visibility
10140 // has been updated accordingly.
10141 updateWallpaperVisibilityLocked();
10142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010143 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010144
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010145 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10146 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010147 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010148 try {
10149 mBackgroundFillerSurface.hide();
10150 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010151 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010152 }
10153 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010154
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010155 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010156 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10157 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010158 }
Romain Guy06882f82009-06-10 13:36:04 -070010159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010160 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010161 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010162 + ": HIDE");
10163 try {
10164 mBlurSurface.hide();
10165 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010166 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010167 }
10168 mBlurShown = false;
10169 }
10170
Joe Onorato8a9b2202010-02-26 18:56:32 -080010171 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010172 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010173 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010174 }
10175
Jeff Browne33348b2010-07-15 23:54:05 -070010176 mInputMonitor.updateInputWindowsLw();
10177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010178 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010179
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010180 if (mWatermark != null) {
10181 mWatermark.drawIfNeeded();
10182 }
10183
Joe Onorato8a9b2202010-02-26 18:56:32 -080010184 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010185 "With display frozen, orientationChangeComplete="
10186 + orientationChangeComplete);
10187 if (orientationChangeComplete) {
10188 if (mWindowsFreezingScreen) {
10189 mWindowsFreezingScreen = false;
10190 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10191 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010192 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 }
Romain Guy06882f82009-06-10 13:36:04 -070010194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010195 i = mResizingWindows.size();
10196 if (i > 0) {
10197 do {
10198 i--;
10199 WindowState win = mResizingWindows.get(i);
10200 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010201 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10202 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010203 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010204 boolean configChanged =
10205 win.mConfiguration != mCurConfiguration
10206 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010207 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10208 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10209 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010210 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010211 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010212 + " / " + mCurConfiguration + " / 0x"
10213 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010214 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010215 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010216 win.mClient.resized(win.mFrame.width(),
10217 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010218 win.mLastVisibleInsets, win.mDrawPending,
10219 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010220 win.mContentInsetsChanged = false;
10221 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010222 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010223 } catch (RemoteException e) {
10224 win.mOrientationChanging = false;
10225 }
10226 } while (i > 0);
10227 mResizingWindows.clear();
10228 }
Romain Guy06882f82009-06-10 13:36:04 -070010229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010230 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010231 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010232 i = mDestroySurface.size();
10233 if (i > 0) {
10234 do {
10235 i--;
10236 WindowState win = mDestroySurface.get(i);
10237 win.mDestroying = false;
10238 if (mInputMethodWindow == win) {
10239 mInputMethodWindow = null;
10240 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010241 if (win == mWallpaperTarget) {
10242 wallpaperDestroyed = true;
10243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010244 win.destroySurfaceLocked();
10245 } while (i > 0);
10246 mDestroySurface.clear();
10247 }
10248
10249 // Time to remove any exiting tokens?
10250 for (i=mExitingTokens.size()-1; i>=0; i--) {
10251 WindowToken token = mExitingTokens.get(i);
10252 if (!token.hasVisible) {
10253 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010254 if (token.windowType == TYPE_WALLPAPER) {
10255 mWallpaperTokens.remove(token);
10256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010257 }
10258 }
10259
10260 // Time to remove any exiting applications?
10261 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10262 AppWindowToken token = mExitingAppTokens.get(i);
10263 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010264 // Make sure there is no animation running on this token,
10265 // so any windows associated with it will be removed as
10266 // soon as their animations are complete
10267 token.animation = null;
10268 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010269 mAppTokens.remove(token);
10270 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010271 if (mLastEnterAnimToken == token) {
10272 mLastEnterAnimToken = null;
10273 mLastEnterAnimParams = null;
10274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010275 }
10276 }
10277
Dianne Hackborna8f60182009-09-01 19:01:50 -070010278 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010279
Dianne Hackborna8f60182009-09-01 19:01:50 -070010280 if (!animating && mAppTransitionRunning) {
10281 // We have finished the animation of an app transition. To do
10282 // this, we have delayed a lot of operations like showing and
10283 // hiding apps, moving apps in Z-order, etc. The app token list
10284 // reflects the correct Z-order, but the window list may now
10285 // be out of sync with it. So here we will just rebuild the
10286 // entire app window list. Fun!
10287 mAppTransitionRunning = false;
10288 needRelayout = true;
10289 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010290 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010291 // Clear information about apps that were moving.
10292 mToBottomApps.clear();
10293 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010295 if (focusDisplayed) {
10296 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10297 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010298 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010299 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010300 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010301 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010302 requestAnimationLocked(0);
10303 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10305 }
Jeff Browneb857f12010-07-16 10:06:33 -070010306
Jeff Browne33348b2010-07-15 23:54:05 -070010307 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010308
Jeff Brown8e03b752010-06-13 19:16:55 -070010309 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010310 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10311 mPowerManager.setScreenBrightnessOverride(-1);
10312 } else {
10313 mPowerManager.setScreenBrightnessOverride((int)
10314 (screenBrightness * Power.BRIGHTNESS_ON));
10315 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010316 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10317 mPowerManager.setButtonBrightnessOverride(-1);
10318 } else {
10319 mPowerManager.setButtonBrightnessOverride((int)
10320 (buttonBrightness * Power.BRIGHTNESS_ON));
10321 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010322 if (holdScreen != mHoldingScreenOn) {
10323 mHoldingScreenOn = holdScreen;
10324 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10325 mH.sendMessage(m);
10326 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010327
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010328 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010329 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010330 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10331 LocalPowerManager.BUTTON_EVENT, true);
10332 mTurnOnScreen = false;
10333 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010334
10335 // Check to see if we are now in a state where the screen should
10336 // be enabled, because the window obscured flags have changed.
10337 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010338 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010339
10340 /**
10341 * Must be called with the main window manager lock held.
10342 */
10343 void setHoldScreenLocked(boolean holding) {
10344 boolean state = mHoldingScreenWakeLock.isHeld();
10345 if (holding != state) {
10346 if (holding) {
10347 mHoldingScreenWakeLock.acquire();
10348 } else {
10349 mPolicy.screenOnStoppedLw();
10350 mHoldingScreenWakeLock.release();
10351 }
10352 }
10353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010354
10355 void requestAnimationLocked(long delay) {
10356 if (!mAnimationPending) {
10357 mAnimationPending = true;
10358 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10359 }
10360 }
Romain Guy06882f82009-06-10 13:36:04 -070010361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010362 /**
10363 * Have the surface flinger show a surface, robustly dealing with
10364 * error conditions. In particular, if there is not enough memory
10365 * to show the surface, then we will try to get rid of other surfaces
10366 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010367 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010368 * @return Returns true if the surface was successfully shown.
10369 */
10370 boolean showSurfaceRobustlyLocked(WindowState win) {
10371 try {
10372 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010373 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010374 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010375 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010376 if (DEBUG_VISIBILITY) Slog.v(TAG,
10377 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010378 win.mTurnOnScreen = false;
10379 mTurnOnScreen = true;
10380 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010381 }
10382 return true;
10383 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010384 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010385 }
Romain Guy06882f82009-06-10 13:36:04 -070010386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010387 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010389 return false;
10390 }
Romain Guy06882f82009-06-10 13:36:04 -070010391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010392 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10393 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010394
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010395 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010396 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010398 if (mForceRemoves == null) {
10399 mForceRemoves = new ArrayList<WindowState>();
10400 }
Romain Guy06882f82009-06-10 13:36:04 -070010401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010402 long callingIdentity = Binder.clearCallingIdentity();
10403 try {
10404 // There was some problem... first, do a sanity check of the
10405 // window list to make sure we haven't left any dangling surfaces
10406 // around.
10407 int N = mWindows.size();
10408 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010409 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010410 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010411 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010412 if (ws.mSurface != null) {
10413 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010414 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010415 + ws + " surface=" + ws.mSurface
10416 + " token=" + win.mToken
10417 + " pid=" + ws.mSession.mPid
10418 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010419 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010420 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010421 ws.mSurface = null;
10422 mForceRemoves.add(ws);
10423 i--;
10424 N--;
10425 leakedSurface = true;
10426 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010427 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010428 + ws + " surface=" + ws.mSurface
10429 + " token=" + win.mAppToken);
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 leakedSurface = true;
10434 }
10435 }
10436 }
Romain Guy06882f82009-06-10 13:36:04 -070010437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010438 boolean killedApps = false;
10439 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010440 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010441 SparseIntArray pidCandidates = new SparseIntArray();
10442 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010443 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010444 if (ws.mSurface != null) {
10445 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10446 }
10447 }
10448 if (pidCandidates.size() > 0) {
10449 int[] pids = new int[pidCandidates.size()];
10450 for (int i=0; i<pids.length; i++) {
10451 pids[i] = pidCandidates.keyAt(i);
10452 }
10453 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010454 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010455 killedApps = true;
10456 }
10457 } catch (RemoteException e) {
10458 }
10459 }
10460 }
Romain Guy06882f82009-06-10 13:36:04 -070010461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010462 if (leakedSurface || killedApps) {
10463 // We managed to reclaim some memory, so get rid of the trouble
10464 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010465 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010466 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010467 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010468 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010469 win.mSurface = null;
10470 }
Romain Guy06882f82009-06-10 13:36:04 -070010471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010472 try {
10473 win.mClient.dispatchGetNewSurface();
10474 } catch (RemoteException e) {
10475 }
10476 }
10477 } finally {
10478 Binder.restoreCallingIdentity(callingIdentity);
10479 }
10480 }
Romain Guy06882f82009-06-10 13:36:04 -070010481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010482 private boolean updateFocusedWindowLocked(int mode) {
10483 WindowState newFocus = computeFocusedWindowLocked();
10484 if (mCurrentFocus != newFocus) {
10485 // This check makes sure that we don't already have the focus
10486 // change message pending.
10487 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10488 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010489 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010490 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10491 final WindowState oldFocus = mCurrentFocus;
10492 mCurrentFocus = newFocus;
10493 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010495 final WindowState imWindow = mInputMethodWindow;
10496 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010497 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010498 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010499 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10500 mLayoutNeeded = true;
10501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010502 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10503 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010504 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10505 // Client will do the layout, but we need to assign layers
10506 // for handleNewWindowLocked() below.
10507 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010508 }
10509 }
Jeff Brown349703e2010-06-22 01:27:15 -070010510
10511 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10512 // If we defer assigning layers, then the caller is responsible for
10513 // doing this part.
10514 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010516 return true;
10517 }
10518 return false;
10519 }
Jeff Brown349703e2010-06-22 01:27:15 -070010520
10521 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010522 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010523 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010524
10525 private WindowState computeFocusedWindowLocked() {
10526 WindowState result = null;
10527 WindowState win;
10528
10529 int i = mWindows.size() - 1;
10530 int nextAppIndex = mAppTokens.size()-1;
10531 WindowToken nextApp = nextAppIndex >= 0
10532 ? mAppTokens.get(nextAppIndex) : null;
10533
10534 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010535 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010536
Joe Onorato8a9b2202010-02-26 18:56:32 -080010537 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010538 TAG, "Looking for focus: " + i
10539 + " = " + win
10540 + ", flags=" + win.mAttrs.flags
10541 + ", canReceive=" + win.canReceiveKeys());
10542
10543 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010545 // If this window's application has been removed, just skip it.
10546 if (thisApp != null && thisApp.removed) {
10547 i--;
10548 continue;
10549 }
Romain Guy06882f82009-06-10 13:36:04 -070010550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010551 // If there is a focused app, don't allow focus to go to any
10552 // windows below it. If this is an application window, step
10553 // through the app tokens until we find its app.
10554 if (thisApp != null && nextApp != null && thisApp != nextApp
10555 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10556 int origAppIndex = nextAppIndex;
10557 while (nextAppIndex > 0) {
10558 if (nextApp == mFocusedApp) {
10559 // Whoops, we are below the focused app... no focus
10560 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010561 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010562 TAG, "Reached focused app: " + mFocusedApp);
10563 return null;
10564 }
10565 nextAppIndex--;
10566 nextApp = mAppTokens.get(nextAppIndex);
10567 if (nextApp == thisApp) {
10568 break;
10569 }
10570 }
10571 if (thisApp != nextApp) {
10572 // Uh oh, the app token doesn't exist! This shouldn't
10573 // happen, but if it does we can get totally hosed...
10574 // so restart at the original app.
10575 nextAppIndex = origAppIndex;
10576 nextApp = mAppTokens.get(nextAppIndex);
10577 }
10578 }
10579
10580 // Dispatch to this window if it is wants key events.
10581 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010582 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010583 TAG, "Found focus @ " + i + " = " + win);
10584 result = win;
10585 break;
10586 }
10587
10588 i--;
10589 }
10590
10591 return result;
10592 }
10593
10594 private void startFreezingDisplayLocked() {
10595 if (mDisplayFrozen) {
10596 return;
10597 }
Romain Guy06882f82009-06-10 13:36:04 -070010598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010599 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010601 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010602 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010603 if (mFreezeGcPending != 0) {
10604 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010605 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010606 mH.removeMessages(H.FORCE_GC);
10607 Runtime.getRuntime().gc();
10608 mFreezeGcPending = now;
10609 }
10610 } else {
10611 mFreezeGcPending = now;
10612 }
Romain Guy06882f82009-06-10 13:36:04 -070010613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010614 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010615
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010616 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010617
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010618 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10619 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010620 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010621 mAppTransitionReady = true;
10622 }
Romain Guy06882f82009-06-10 13:36:04 -070010623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010624 if (PROFILE_ORIENTATION) {
10625 File file = new File("/data/system/frozen");
10626 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10627 }
10628 Surface.freezeDisplay(0);
10629 }
Romain Guy06882f82009-06-10 13:36:04 -070010630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010631 private void stopFreezingDisplayLocked() {
10632 if (!mDisplayFrozen) {
10633 return;
10634 }
Romain Guy06882f82009-06-10 13:36:04 -070010635
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010636 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10637 return;
10638 }
10639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010640 mDisplayFrozen = false;
10641 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10642 if (PROFILE_ORIENTATION) {
10643 Debug.stopMethodTracing();
10644 }
10645 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010646
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010647 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010648
Christopher Tateb696aee2010-04-02 19:08:30 -070010649 // While the display is frozen we don't re-compute the orientation
10650 // to avoid inconsistent states. However, something interesting
10651 // could have actually changed during that time so re-evaluate it
10652 // now to catch that.
10653 if (updateOrientationFromAppTokensLocked()) {
10654 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10655 }
10656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010657 // A little kludge: a lot could have happened while the
10658 // display was frozen, so now that we are coming back we
10659 // do a gc so that any remote references the system
10660 // processes holds on others can be released if they are
10661 // no longer needed.
10662 mH.removeMessages(H.FORCE_GC);
10663 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10664 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010666 mScreenFrozenLock.release();
10667 }
Romain Guy06882f82009-06-10 13:36:04 -070010668
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010669 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10670 DisplayMetrics dm) {
10671 if (index < tokens.length) {
10672 String str = tokens[index];
10673 if (str != null && str.length() > 0) {
10674 try {
10675 int val = Integer.parseInt(str);
10676 return val;
10677 } catch (Exception e) {
10678 }
10679 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010680 }
10681 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10682 return defDps;
10683 }
10684 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10685 return val;
10686 }
10687
10688 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010689 final String[] mTokens;
10690 final String mText;
10691 final Paint mTextPaint;
10692 final int mTextWidth;
10693 final int mTextHeight;
10694 final int mTextAscent;
10695 final int mTextDescent;
10696 final int mDeltaX;
10697 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010698
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010699 Surface mSurface;
10700 int mLastDW;
10701 int mLastDH;
10702 boolean mDrawNeeded;
10703
10704 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010705 final DisplayMetrics dm = new DisplayMetrics();
10706 mDisplay.getMetrics(dm);
10707
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010708 if (false) {
10709 Log.i(TAG, "*********************** WATERMARK");
10710 for (int i=0; i<tokens.length; i++) {
10711 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10712 }
10713 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010714
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010715 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010716
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010717 StringBuilder builder = new StringBuilder(32);
10718 int len = mTokens[0].length();
10719 len = len & ~1;
10720 for (int i=0; i<len; i+=2) {
10721 int c1 = mTokens[0].charAt(i);
10722 int c2 = mTokens[0].charAt(i+1);
10723 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10724 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10725 else c1 -= '0';
10726 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10727 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10728 else c2 -= '0';
10729 builder.append((char)(255-((c1*16)+c2)));
10730 }
10731 mText = builder.toString();
10732 if (false) {
10733 Log.i(TAG, "Final text: " + mText);
10734 }
10735
10736 int fontSize = getPropertyInt(tokens, 1,
10737 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10738
10739 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10740 mTextPaint.setTextSize(fontSize);
10741 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10742
10743 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10744 mTextWidth = (int)mTextPaint.measureText(mText);
10745 mTextAscent = fm.ascent;
10746 mTextDescent = fm.descent;
10747 mTextHeight = fm.descent - fm.ascent;
10748
10749 mDeltaX = getPropertyInt(tokens, 2,
10750 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10751 mDeltaY = getPropertyInt(tokens, 3,
10752 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10753 int shadowColor = getPropertyInt(tokens, 4,
10754 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10755 int color = getPropertyInt(tokens, 5,
10756 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10757 int shadowRadius = getPropertyInt(tokens, 6,
10758 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10759 int shadowDx = getPropertyInt(tokens, 8,
10760 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10761 int shadowDy = getPropertyInt(tokens, 9,
10762 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10763
10764 mTextPaint.setColor(color);
10765 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010766
10767 try {
10768 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010769 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010770 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010771 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010772 mSurface.show();
10773 } catch (OutOfResourcesException e) {
10774 }
10775 }
10776
10777 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010778 if (mLastDW != dw || mLastDH != dh) {
10779 mLastDW = dw;
10780 mLastDH = dh;
10781 mSurface.setSize(dw, dh);
10782 mDrawNeeded = true;
10783 }
10784 }
10785
10786 void drawIfNeeded() {
10787 if (mDrawNeeded) {
10788 final int dw = mLastDW;
10789 final int dh = mLastDH;
10790
10791 mDrawNeeded = false;
10792 Rect dirty = new Rect(0, 0, dw, dh);
10793 Canvas c = null;
10794 try {
10795 c = mSurface.lockCanvas(dirty);
10796 } catch (IllegalArgumentException e) {
10797 } catch (OutOfResourcesException e) {
10798 }
10799 if (c != null) {
10800 int deltaX = mDeltaX;
10801 int deltaY = mDeltaY;
10802
10803 // deltaX shouldn't be close to a round fraction of our
10804 // x step, or else things will line up too much.
10805 int div = (dw+mTextWidth)/deltaX;
10806 int rem = (dw+mTextWidth) - (div*deltaX);
10807 int qdelta = deltaX/4;
10808 if (rem < qdelta || rem > (deltaX-qdelta)) {
10809 deltaX += deltaX/3;
10810 }
10811
10812 int y = -mTextHeight;
10813 int x = -mTextWidth;
10814 while (y < (dh+mTextHeight)) {
10815 c.drawText(mText, x, y, mTextPaint);
10816 x += deltaX;
10817 if (x >= dw) {
10818 x -= (dw+mTextWidth);
10819 y += deltaY;
10820 }
10821 }
10822 mSurface.unlockCanvasAndPost(c);
10823 }
10824 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010825 }
10826 }
10827
10828 void createWatermark() {
10829 if (mWatermark != null) {
10830 return;
10831 }
10832
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010833 File file = new File("/system/etc/setup.conf");
10834 FileInputStream in = null;
10835 try {
10836 in = new FileInputStream(file);
10837 DataInputStream ind = new DataInputStream(in);
10838 String line = ind.readLine();
10839 if (line != null) {
10840 String[] toks = line.split("%");
10841 if (toks != null && toks.length > 0) {
10842 mWatermark = new Watermark(mFxSession, toks);
10843 }
10844 }
10845 } catch (FileNotFoundException e) {
10846 } catch (IOException e) {
10847 } finally {
10848 if (in != null) {
10849 try {
10850 in.close();
10851 } catch (IOException e) {
10852 }
10853 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010854 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010855 }
10856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010857 @Override
10858 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10859 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10860 != PackageManager.PERMISSION_GRANTED) {
10861 pw.println("Permission Denial: can't dump WindowManager from from pid="
10862 + Binder.getCallingPid()
10863 + ", uid=" + Binder.getCallingUid());
10864 return;
10865 }
Romain Guy06882f82009-06-10 13:36:04 -070010866
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010867 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010868 pw.println(" ");
10869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010870 synchronized(mWindowMap) {
10871 pw.println("Current Window Manager state:");
10872 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010873 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010874 pw.print(" Window #"); pw.print(i); pw.print(' ');
10875 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010876 w.dump(pw, " ");
10877 }
10878 if (mInputMethodDialogs.size() > 0) {
10879 pw.println(" ");
10880 pw.println(" Input method dialogs:");
10881 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10882 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010883 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010884 }
10885 }
10886 if (mPendingRemove.size() > 0) {
10887 pw.println(" ");
10888 pw.println(" Remove pending for:");
10889 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10890 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010891 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10892 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010893 w.dump(pw, " ");
10894 }
10895 }
10896 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10897 pw.println(" ");
10898 pw.println(" Windows force removing:");
10899 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10900 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010901 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10902 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010903 w.dump(pw, " ");
10904 }
10905 }
10906 if (mDestroySurface.size() > 0) {
10907 pw.println(" ");
10908 pw.println(" Windows waiting to destroy their surface:");
10909 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10910 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010911 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10912 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010913 w.dump(pw, " ");
10914 }
10915 }
10916 if (mLosingFocus.size() > 0) {
10917 pw.println(" ");
10918 pw.println(" Windows losing focus:");
10919 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10920 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010921 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10922 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010923 w.dump(pw, " ");
10924 }
10925 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010926 if (mResizingWindows.size() > 0) {
10927 pw.println(" ");
10928 pw.println(" Windows waiting to resize:");
10929 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10930 WindowState w = mResizingWindows.get(i);
10931 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10932 pw.print(w); pw.println(":");
10933 w.dump(pw, " ");
10934 }
10935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010936 if (mSessions.size() > 0) {
10937 pw.println(" ");
10938 pw.println(" All active sessions:");
10939 Iterator<Session> it = mSessions.iterator();
10940 while (it.hasNext()) {
10941 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010942 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010943 s.dump(pw, " ");
10944 }
10945 }
10946 if (mTokenMap.size() > 0) {
10947 pw.println(" ");
10948 pw.println(" All tokens:");
10949 Iterator<WindowToken> it = mTokenMap.values().iterator();
10950 while (it.hasNext()) {
10951 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010952 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010953 token.dump(pw, " ");
10954 }
10955 }
10956 if (mTokenList.size() > 0) {
10957 pw.println(" ");
10958 pw.println(" Window token list:");
10959 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010960 pw.print(" #"); pw.print(i); pw.print(": ");
10961 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010962 }
10963 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010964 if (mWallpaperTokens.size() > 0) {
10965 pw.println(" ");
10966 pw.println(" Wallpaper tokens:");
10967 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10968 WindowToken token = mWallpaperTokens.get(i);
10969 pw.print(" Wallpaper #"); pw.print(i);
10970 pw.print(' '); pw.print(token); pw.println(':');
10971 token.dump(pw, " ");
10972 }
10973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010974 if (mAppTokens.size() > 0) {
10975 pw.println(" ");
10976 pw.println(" Application tokens in Z order:");
10977 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010978 pw.print(" App #"); pw.print(i); pw.print(": ");
10979 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010980 }
10981 }
10982 if (mFinishedStarting.size() > 0) {
10983 pw.println(" ");
10984 pw.println(" Finishing start of application tokens:");
10985 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10986 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010987 pw.print(" Finished Starting #"); pw.print(i);
10988 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010989 token.dump(pw, " ");
10990 }
10991 }
10992 if (mExitingTokens.size() > 0) {
10993 pw.println(" ");
10994 pw.println(" Exiting tokens:");
10995 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10996 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010997 pw.print(" Exiting #"); pw.print(i);
10998 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010999 token.dump(pw, " ");
11000 }
11001 }
11002 if (mExitingAppTokens.size() > 0) {
11003 pw.println(" ");
11004 pw.println(" Exiting application tokens:");
11005 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
11006 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011007 pw.print(" Exiting App #"); pw.print(i);
11008 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011009 token.dump(pw, " ");
11010 }
11011 }
11012 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011013 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
11014 pw.print(" mLastFocus="); pw.println(mLastFocus);
11015 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
11016 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
11017 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070011018 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011019 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
11020 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
11021 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
11022 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011023 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
11024 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
11025 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011026 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
11027 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
11028 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
11029 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011030 if (mDimAnimator != null) {
11031 mDimAnimator.printTo(pw);
11032 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080011033 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011034 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011035 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070011036 pw.print(mInputMethodAnimLayerAdjustment);
11037 pw.print(" mWallpaperAnimLayerAdjustment=");
11038 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070011039 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
11040 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011041 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
11042 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080011043 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
11044 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011045 pw.print(" mRotation="); pw.print(mRotation);
11046 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
11047 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
11048 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
11049 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
11050 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
11051 pw.print(" mNextAppTransition=0x");
11052 pw.print(Integer.toHexString(mNextAppTransition));
11053 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070011054 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011055 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011056 if (mNextAppTransitionPackage != null) {
11057 pw.print(" mNextAppTransitionPackage=");
11058 pw.print(mNextAppTransitionPackage);
11059 pw.print(", mNextAppTransitionEnter=0x");
11060 pw.print(Integer.toHexString(mNextAppTransitionEnter));
11061 pw.print(", mNextAppTransitionExit=0x");
11062 pw.print(Integer.toHexString(mNextAppTransitionExit));
11063 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011064 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
11065 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070011066 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
11067 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
11068 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
11069 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011070 if (mOpeningApps.size() > 0) {
11071 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
11072 }
11073 if (mClosingApps.size() > 0) {
11074 pw.print(" mClosingApps="); pw.println(mClosingApps);
11075 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070011076 if (mToTopApps.size() > 0) {
11077 pw.print(" mToTopApps="); pw.println(mToTopApps);
11078 }
11079 if (mToBottomApps.size() > 0) {
11080 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
11081 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070011082 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
11083 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011084 }
11085 }
11086
Jeff Brown349703e2010-06-22 01:27:15 -070011087 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011088 public void monitor() {
11089 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050011090 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070011091 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011092
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011093 /**
11094 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011095 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011096 */
11097 private static class DimAnimator {
11098 Surface mDimSurface;
11099 boolean mDimShown = false;
11100 float mDimCurrentAlpha;
11101 float mDimTargetAlpha;
11102 float mDimDeltaPerMs;
11103 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011104
11105 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011106
11107 DimAnimator (SurfaceSession session) {
11108 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011109 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011110 + mDimSurface + ": CREATE");
11111 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011112 mDimSurface = new Surface(session, 0,
11113 "DimSurface",
11114 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011115 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011116 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011117 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011118 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011119 }
11120 }
11121 }
11122
11123 /**
11124 * Show the dim surface.
11125 */
11126 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011127 if (!mDimShown) {
11128 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11129 dw + "x" + dh + ")");
11130 mDimShown = true;
11131 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011132 mLastDimWidth = dw;
11133 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011134 mDimSurface.setPosition(0, 0);
11135 mDimSurface.setSize(dw, dh);
11136 mDimSurface.show();
11137 } catch (RuntimeException e) {
11138 Slog.w(TAG, "Failure showing dim surface", e);
11139 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011140 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11141 mLastDimWidth = dw;
11142 mLastDimHeight = dh;
11143 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011144 }
11145 }
11146
11147 /**
11148 * Set's the dim surface's layer and update dim parameters that will be used in
11149 * {@link updateSurface} after all windows are examined.
11150 */
11151 void updateParameters(WindowState w, long currentTime) {
11152 mDimSurface.setLayer(w.mAnimLayer-1);
11153
11154 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011155 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011156 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011157 if (mDimTargetAlpha != target) {
11158 // If the desired dim level has changed, then
11159 // start an animation to it.
11160 mLastDimAnimTime = currentTime;
11161 long duration = (w.mAnimating && w.mAnimation != null)
11162 ? w.mAnimation.computeDurationHint()
11163 : DEFAULT_DIM_DURATION;
11164 if (target > mDimTargetAlpha) {
11165 // This is happening behind the activity UI,
11166 // so we can make it run a little longer to
11167 // give a stronger impression without disrupting
11168 // the user.
11169 duration *= DIM_DURATION_MULTIPLIER;
11170 }
11171 if (duration < 1) {
11172 // Don't divide by zero
11173 duration = 1;
11174 }
11175 mDimTargetAlpha = target;
11176 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11177 }
11178 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011179
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011180 /**
11181 * Updating the surface's alpha. Returns true if the animation continues, or returns
11182 * false when the animation is finished and the dim surface is hidden.
11183 */
11184 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11185 if (!dimming) {
11186 if (mDimTargetAlpha != 0) {
11187 mLastDimAnimTime = currentTime;
11188 mDimTargetAlpha = 0;
11189 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11190 }
11191 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011192
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011193 boolean animating = false;
11194 if (mLastDimAnimTime != 0) {
11195 mDimCurrentAlpha += mDimDeltaPerMs
11196 * (currentTime-mLastDimAnimTime);
11197 boolean more = true;
11198 if (displayFrozen) {
11199 // If the display is frozen, there is no reason to animate.
11200 more = false;
11201 } else if (mDimDeltaPerMs > 0) {
11202 if (mDimCurrentAlpha > mDimTargetAlpha) {
11203 more = false;
11204 }
11205 } else if (mDimDeltaPerMs < 0) {
11206 if (mDimCurrentAlpha < mDimTargetAlpha) {
11207 more = false;
11208 }
11209 } else {
11210 more = false;
11211 }
11212
11213 // Do we need to continue animating?
11214 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011215 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011216 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11217 mLastDimAnimTime = currentTime;
11218 mDimSurface.setAlpha(mDimCurrentAlpha);
11219 animating = true;
11220 } else {
11221 mDimCurrentAlpha = mDimTargetAlpha;
11222 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011223 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011224 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11225 mDimSurface.setAlpha(mDimCurrentAlpha);
11226 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011227 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011228 + ": HIDE");
11229 try {
11230 mDimSurface.hide();
11231 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011232 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011233 }
11234 mDimShown = false;
11235 }
11236 }
11237 }
11238 return animating;
11239 }
11240
11241 public void printTo(PrintWriter pw) {
11242 pw.print(" mDimShown="); pw.print(mDimShown);
11243 pw.print(" current="); pw.print(mDimCurrentAlpha);
11244 pw.print(" target="); pw.print(mDimTargetAlpha);
11245 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11246 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11247 }
11248 }
11249
11250 /**
11251 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11252 * This is used for opening/closing transition for apps in compatible mode.
11253 */
11254 private static class FadeInOutAnimation extends Animation {
11255 int mWidth;
11256 boolean mFadeIn;
11257
11258 public FadeInOutAnimation(boolean fadeIn) {
11259 setInterpolator(new AccelerateInterpolator());
11260 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11261 mFadeIn = fadeIn;
11262 }
11263
11264 @Override
11265 protected void applyTransformation(float interpolatedTime, Transformation t) {
11266 float x = interpolatedTime;
11267 if (!mFadeIn) {
11268 x = 1.0f - x; // reverse the interpolation for fade out
11269 }
11270 if (x < 0.5) {
11271 // move the window out of the screen.
11272 t.getMatrix().setTranslate(mWidth, 0);
11273 } else {
11274 t.getMatrix().setTranslate(0, 0);// show
11275 t.setAlpha((x - 0.5f) * 2);
11276 }
11277 }
11278
11279 @Override
11280 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11281 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11282 mWidth = width;
11283 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011284
11285 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011286 public int getZAdjustment() {
11287 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011288 }
11289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011290}