blob: b50f0bac853a79e2ab5292d0f7c5119804cb36ab [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
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070056import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070059import android.content.Intent;
60import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.ActivityInfo;
62import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.content.res.Configuration;
65import android.graphics.Matrix;
66import android.graphics.PixelFormat;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070075import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
95import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700106import android.view.InputEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700107import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.KeyEvent;
109import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110import android.view.Surface;
111import android.view.SurfaceSession;
112import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700113import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.ViewTreeObserver;
115import android.view.WindowManager;
116import android.view.WindowManagerImpl;
117import android.view.WindowManagerPolicy;
118import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700119import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120import android.view.animation.Animation;
121import android.view.animation.AnimationUtils;
122import android.view.animation.Transformation;
123
124import java.io.BufferedWriter;
125import java.io.File;
126import java.io.FileDescriptor;
127import java.io.IOException;
128import java.io.OutputStream;
129import java.io.OutputStreamWriter;
130import java.io.PrintWriter;
131import java.io.StringWriter;
132import java.net.Socket;
133import java.util.ArrayList;
134import java.util.HashMap;
135import java.util.HashSet;
136import java.util.Iterator;
137import java.util.List;
138
139/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700140public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700141 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 static final String TAG = "WindowManager";
143 static final boolean DEBUG = false;
144 static final boolean DEBUG_FOCUS = false;
145 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800146 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800147 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 static final boolean DEBUG_LAYERS = false;
149 static final boolean DEBUG_INPUT = false;
150 static final boolean DEBUG_INPUT_METHOD = false;
151 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700152 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700154 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_APP_TRANSITIONS = false;
156 static final boolean DEBUG_STARTING_WINDOW = false;
157 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700158 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700160 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700161 static final boolean MEASURE_LATENCY = false;
162 static private LatencyTimer lt;
163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean PROFILE_ORIENTATION = false;
165 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700166 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /** How much to multiply the policy's type layer, to reserve room
169 * for multiple windows of the same type and Z-ordering adjustment
170 * with TYPE_LAYER_OFFSET. */
171 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
174 * or below others in the same layer. */
175 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to increment the layer for each window, to reserve room
178 * for effect surfaces between them.
179 */
180 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** The maximum length we will accept for a loaded animation duration:
183 * this is 10 seconds.
184 */
185 static final int MAX_ANIMATION_DURATION = 10*1000;
186
187 /** Amount of time (in milliseconds) to animate the dim surface from one
188 * value to another, when no window animation is driving it.
189 */
190 static final int DEFAULT_DIM_DURATION = 200;
191
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700192 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
193 * compatible windows.
194 */
195 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 /** Adjustment to time to perform a dim, to make it more dramatic.
198 */
199 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700200
201 // Maximum number of milliseconds to wait for input event injection.
202 // FIXME is this value reasonable?
203 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700204
205 // Default input dispatching timeout in nanoseconds.
206 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 static final int UPDATE_FOCUS_NORMAL = 0;
209 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
210 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
211 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700214 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215
216 /**
217 * Condition waited on by {@link #reenableKeyguard} to know the call to
218 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500219 * This is set to true only if mKeyguardTokenWatcher.acquired() has
220 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500222 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
Jim Miller284b62e2010-06-08 14:27:42 -0700224 private static final int ALLOW_DISABLE_YES = 1;
225 private static final int ALLOW_DISABLE_NO = 0;
226 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
227 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
228
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
230 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700232 if (shouldAllowDisableKeyguard()) {
233 mPolicy.enableKeyguard(false);
234 mKeyguardDisabled = true;
235 } else {
236 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 }
239 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700240 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500241 synchronized (mKeyguardTokenWatcher) {
242 mKeyguardDisabled = false;
243 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245 }
246 };
247
Jim Miller284b62e2010-06-08 14:27:42 -0700248 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
249 @Override
250 public void onReceive(Context context, Intent intent) {
251 mPolicy.enableKeyguard(true);
252 synchronized(mKeyguardTokenWatcher) {
253 // lazily evaluate this next time we're asked to disable keyguard
254 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
255 mKeyguardDisabled = false;
256 }
257 }
258 };
259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 final Context mContext;
261
262 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
267
268 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 /**
273 * All currently active sessions with clients.
274 */
275 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 /**
278 * Mapping from an IWindow IBinder to the server's Window object.
279 * This is also used as the lock for all of our state.
280 */
281 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
282
283 /**
284 * Mapping from a token IBinder to a WindowToken object.
285 */
286 final HashMap<IBinder, WindowToken> mTokenMap =
287 new HashMap<IBinder, WindowToken>();
288
289 /**
290 * The same tokens as mTokenMap, stored in a list for efficient iteration
291 * over them.
292 */
293 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 /**
296 * Window tokens that are in the process of exiting, but still
297 * on screen for animations.
298 */
299 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
300
301 /**
302 * Z-ordered (bottom-most first) list of all application tokens, for
303 * controlling the ordering of windows in different applications. This
304 * contains WindowToken objects.
305 */
306 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
307
308 /**
309 * Application tokens that are in the process of exiting, but still
310 * on screen for animations.
311 */
312 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
313
314 /**
315 * List of window tokens that have finished starting their application,
316 * and now need to have the policy remove their windows.
317 */
318 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
319
320 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700321 * This was the app token that was used to retrieve the last enter
322 * animation. It will be used for the next exit animation.
323 */
324 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800325
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700326 /**
327 * These were the layout params used to retrieve the last enter animation.
328 * They will be used for the next exit animation.
329 */
330 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800331
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700332 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 * Z-ordered (bottom-most first) list of all Window objects.
334 */
Jeff Browne33348b2010-07-15 23:54:05 -0700335 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
337 /**
338 * Windows that are being resized. Used so we can tell the client about
339 * the resize after closing the transaction in which we resized the
340 * underlying surface.
341 */
342 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
343
344 /**
345 * Windows whose animations have ended and now must be removed.
346 */
347 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
348
349 /**
350 * Windows whose surface should be destroyed.
351 */
352 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
353
354 /**
355 * Windows that have lost input focus and are waiting for the new
356 * focus window to be displayed before they are told about this.
357 */
358 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
359
360 /**
361 * This is set when we have run out of memory, and will either be an empty
362 * list or contain windows that need to be force removed.
363 */
364 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700369 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 Surface mBlurSurface;
371 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 final float[] mTmpFloats = new float[9];
376
377 boolean mSafeMode;
378 boolean mDisplayEnabled = false;
379 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700380 int mInitialDisplayWidth = 0;
381 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mRotation = 0;
383 int mRequestedRotation = 0;
384 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700385 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 ArrayList<IRotationWatcher> mRotationWatchers
387 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 boolean mLayoutNeeded = true;
390 boolean mAnimationPending = false;
391 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800392 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 boolean mWindowsFreezingScreen = false;
394 long mFreezeGcPending = 0;
395 int mAppsFreezingScreen = 0;
396
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800397 int mLayoutSeq = 0;
398
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800399 // State while inside of layoutAndPlaceSurfacesLocked().
400 boolean mFocusMayChange;
401
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800402 Configuration mCurConfiguration = new Configuration();
403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 // This is held as long as we have the screen frozen, to give us time to
405 // perform a rotation animation when turning off shows the lock screen which
406 // changes the orientation.
407 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 // State management of app transitions. When we are preparing for a
410 // transition, mNextAppTransition will be the kind of transition to
411 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
412 // mOpeningApps and mClosingApps are the lists of tokens that will be
413 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700414 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700415 String mNextAppTransitionPackage;
416 int mNextAppTransitionEnter;
417 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700419 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 boolean mAppTransitionTimeout = false;
421 boolean mStartingIconInTransition = false;
422 boolean mSkipAppTransitionAnimation = false;
423 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
424 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700425 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
426 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 H mH = new H();
431
432 WindowState mCurrentFocus = null;
433 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 // This just indicates the window the input method is on top of, not
436 // necessarily the window its input is going to.
437 WindowState mInputMethodTarget = null;
438 WindowState mUpcomingInputMethodTarget = null;
439 boolean mInputMethodTargetWaitingAnim;
440 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 WindowState mInputMethodWindow = null;
443 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
444
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700445 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800446
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700447 // If non-null, this is the currently visible window that is associated
448 // with the wallpaper.
449 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700450 // If non-null, we are in the middle of animating from one wallpaper target
451 // to another, and this is the lower one in Z-order.
452 WindowState mLowerWallpaperTarget = null;
453 // If non-null, we are in the middle of animating from one wallpaper target
454 // to another, and this is the higher one in Z-order.
455 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700457 float mLastWallpaperX = -1;
458 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800459 float mLastWallpaperXStep = -1;
460 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700461 // This is set when we are waiting for a wallpaper to tell us it is done
462 // changing its scroll position.
463 WindowState mWaitingOnWallpaper;
464 // The last time we had a timeout when waiting for a wallpaper.
465 long mLastWallpaperTimeoutTime;
466 // We give a wallpaper up to 150ms to finish scrolling.
467 static final long WALLPAPER_TIMEOUT = 150;
468 // Time we wait after a timeout before trying to wait again.
469 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 AppWindowToken mFocusedApp = null;
472
473 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 float mWindowAnimationScale = 1.0f;
476 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700477
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700478 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479
480 // Who is holding the screen on.
481 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700482 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700483
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700484 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 /**
487 * Whether the UI is currently running in touch mode (not showing
488 * navigational focus because the user is directly pressing the screen).
489 */
490 boolean mInTouchMode = false;
491
492 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700493 private ArrayList<WindowChangeListener> mWindowChangeListeners =
494 new ArrayList<WindowChangeListener>();
495 private boolean mWindowsChanged = false;
496
497 public interface WindowChangeListener {
498 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700499 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501
Dianne Hackbornc485a602009-03-24 22:39:49 -0700502 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700503 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700504
505 // The frame use to limit the size of the app running in compatibility mode.
506 Rect mCompatibleScreenFrame = new Rect();
507 // The surface used to fill the outer rim of the app running in compatibility mode.
508 Surface mBackgroundFillerSurface = null;
509 boolean mBackgroundFillerShown = false;
510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 public static WindowManagerService main(Context context,
512 PowerManagerService pm, boolean haveInputMethods) {
513 WMThread thr = new WMThread(context, pm, haveInputMethods);
514 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 synchronized (thr) {
517 while (thr.mService == null) {
518 try {
519 thr.wait();
520 } catch (InterruptedException e) {
521 }
522 }
523 }
Romain Guy06882f82009-06-10 13:36:04 -0700524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 return thr.mService;
526 }
Romain Guy06882f82009-06-10 13:36:04 -0700527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 static class WMThread extends Thread {
529 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 private final Context mContext;
532 private final PowerManagerService mPM;
533 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 public WMThread(Context context, PowerManagerService pm,
536 boolean haveInputMethods) {
537 super("WindowManager");
538 mContext = context;
539 mPM = pm;
540 mHaveInputMethods = haveInputMethods;
541 }
Romain Guy06882f82009-06-10 13:36:04 -0700542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 public void run() {
544 Looper.prepare();
545 WindowManagerService s = new WindowManagerService(mContext, mPM,
546 mHaveInputMethods);
547 android.os.Process.setThreadPriority(
548 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700549 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 synchronized (this) {
552 mService = s;
553 notifyAll();
554 }
Romain Guy06882f82009-06-10 13:36:04 -0700555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 Looper.loop();
557 }
558 }
559
560 static class PolicyThread extends Thread {
561 private final WindowManagerPolicy mPolicy;
562 private final WindowManagerService mService;
563 private final Context mContext;
564 private final PowerManagerService mPM;
565 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 public PolicyThread(WindowManagerPolicy policy,
568 WindowManagerService service, Context context,
569 PowerManagerService pm) {
570 super("WindowManagerPolicy");
571 mPolicy = policy;
572 mService = service;
573 mContext = context;
574 mPM = pm;
575 }
Romain Guy06882f82009-06-10 13:36:04 -0700576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 public void run() {
578 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800579 WindowManagerPolicyThread.set(this, Looper.myLooper());
580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800582 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 android.os.Process.setThreadPriority(
584 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700585 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 synchronized (this) {
589 mRunning = true;
590 notifyAll();
591 }
Romain Guy06882f82009-06-10 13:36:04 -0700592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 Looper.loop();
594 }
595 }
596
597 private WindowManagerService(Context context, PowerManagerService pm,
598 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700599 if (MEASURE_LATENCY) {
600 lt = new LatencyTimer(100, 1000);
601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 mContext = context;
604 mHaveInputMethods = haveInputMethods;
605 mLimitedAlphaCompositing = context.getResources().getBoolean(
606 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 mPowerManager = pm;
609 mPowerManager.setPolicy(mPolicy);
610 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
611 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
612 "SCREEN_FROZEN");
613 mScreenFrozenLock.setReferenceCounted(false);
614
615 mActivityManager = ActivityManagerNative.getDefault();
616 mBatteryStats = BatteryStatsService.getService();
617
618 // Get persisted window scale setting
619 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
620 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
621 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
622 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700623
Jim Miller284b62e2010-06-08 14:27:42 -0700624 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
625 IntentFilter filter = new IntentFilter();
626 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
627 mContext.registerReceiver(mBroadcastReceiver, filter);
628
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700629 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
630 "KEEP_SCREEN_ON_FLAG");
631 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632
Jeff Browne33348b2010-07-15 23:54:05 -0700633 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
636 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 synchronized (thr) {
639 while (!thr.mRunning) {
640 try {
641 thr.wait();
642 } catch (InterruptedException e) {
643 }
644 }
645 }
Romain Guy06882f82009-06-10 13:36:04 -0700646
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700647 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 // Add ourself to the Watchdog monitors.
650 Watchdog.getInstance().addMonitor(this);
651 }
652
653 @Override
654 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
655 throws RemoteException {
656 try {
657 return super.onTransact(code, data, reply, flags);
658 } catch (RuntimeException e) {
659 // The window manager only throws security exceptions, so let's
660 // log all others.
661 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800662 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 }
664 throw e;
665 }
666 }
667
Jeff Browne33348b2010-07-15 23:54:05 -0700668 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800670 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 TAG, "Adding window " + window + " at "
672 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
673 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700674 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 }
676
Jeff Browne33348b2010-07-15 23:54:05 -0700677 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800679 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 TAG, "Adding window " + window + " at "
681 + i + " of " + mWindows.size() + " (before " + pos + ")");
682 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700683 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
685
686 //This method finds out the index of a window that has the same app token as
687 //win. used for z ordering the windows in mWindows
688 private int findIdxBasedOnAppTokens(WindowState win) {
689 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700690 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 int jmax = localmWindows.size();
692 if(jmax == 0) {
693 return -1;
694 }
695 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700696 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 if(wentry.mAppToken == win.mAppToken) {
698 return j;
699 }
700 }
701 return -1;
702 }
Romain Guy06882f82009-06-10 13:36:04 -0700703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
705 final IWindow client = win.mClient;
706 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700707 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 final int N = localmWindows.size();
710 final WindowState attached = win.mAttachedWindow;
711 int i;
712 if (attached == null) {
713 int tokenWindowsPos = token.windows.size();
714 if (token.appWindowToken != null) {
715 int index = tokenWindowsPos-1;
716 if (index >= 0) {
717 // If this application has existing windows, we
718 // simply place the new window on top of them... but
719 // keep the starting window on top.
720 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
721 // Base windows go behind everything else.
722 placeWindowBefore(token.windows.get(0), win);
723 tokenWindowsPos = 0;
724 } else {
725 AppWindowToken atoken = win.mAppToken;
726 if (atoken != null &&
727 token.windows.get(index) == atoken.startingWindow) {
728 placeWindowBefore(token.windows.get(index), win);
729 tokenWindowsPos--;
730 } else {
731 int newIdx = findIdxBasedOnAppTokens(win);
732 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700733 //there is a window above this one associated with the same
734 //apptoken note that the window could be a floating window
735 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800737 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700738 TAG, "Adding window " + win + " at "
739 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700741 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700742 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 }
744 }
745 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800746 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 TAG, "Figuring out where to add app window "
748 + client.asBinder() + " (token=" + token + ")");
749 // Figure out where the window should go, based on the
750 // order of applications.
751 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700752 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 for (i=NA-1; i>=0; i--) {
754 AppWindowToken t = mAppTokens.get(i);
755 if (t == token) {
756 i--;
757 break;
758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800759
Dianne Hackborna8f60182009-09-01 19:01:50 -0700760 // We haven't reached the token yet; if this token
761 // is not going to the bottom and has windows, we can
762 // use it as an anchor for when we do reach the token.
763 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 pos = t.windows.get(0);
765 }
766 }
767 // We now know the index into the apps. If we found
768 // an app window above, that gives us the position; else
769 // we need to look some more.
770 if (pos != null) {
771 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700772 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 if (atoken != null) {
774 final int NC = atoken.windows.size();
775 if (NC > 0) {
776 WindowState bottom = atoken.windows.get(0);
777 if (bottom.mSubLayer < 0) {
778 pos = bottom;
779 }
780 }
781 }
782 placeWindowBefore(pos, win);
783 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700784 // Continue looking down until we find the first
785 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 while (i >= 0) {
787 AppWindowToken t = mAppTokens.get(i);
788 final int NW = t.windows.size();
789 if (NW > 0) {
790 pos = t.windows.get(NW-1);
791 break;
792 }
793 i--;
794 }
795 if (pos != null) {
796 // Move in front of any windows attached to this
797 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700798 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 if (atoken != null) {
800 final int NC = atoken.windows.size();
801 if (NC > 0) {
802 WindowState top = atoken.windows.get(NC-1);
803 if (top.mSubLayer >= 0) {
804 pos = top;
805 }
806 }
807 }
808 placeWindowAfter(pos, win);
809 } else {
810 // Just search for the start of this layer.
811 final int myLayer = win.mBaseLayer;
812 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700813 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 if (w.mBaseLayer > myLayer) {
815 break;
816 }
817 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800818 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700819 TAG, "Adding window " + win + " at "
820 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700822 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 }
824 }
825 }
826 } else {
827 // Figure out where window should go, based on layer.
828 final int myLayer = win.mBaseLayer;
829 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700830 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 i++;
832 break;
833 }
834 }
835 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800836 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700837 TAG, "Adding window " + win + " at "
838 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700840 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 }
842 if (addToToken) {
843 token.windows.add(tokenWindowsPos, win);
844 }
845
846 } else {
847 // Figure out this window's ordering relative to the window
848 // it is attached to.
849 final int NA = token.windows.size();
850 final int sublayer = win.mSubLayer;
851 int largestSublayer = Integer.MIN_VALUE;
852 WindowState windowWithLargestSublayer = null;
853 for (i=0; i<NA; i++) {
854 WindowState w = token.windows.get(i);
855 final int wSublayer = w.mSubLayer;
856 if (wSublayer >= largestSublayer) {
857 largestSublayer = wSublayer;
858 windowWithLargestSublayer = w;
859 }
860 if (sublayer < 0) {
861 // For negative sublayers, we go below all windows
862 // in the same sublayer.
863 if (wSublayer >= sublayer) {
864 if (addToToken) {
865 token.windows.add(i, win);
866 }
867 placeWindowBefore(
868 wSublayer >= 0 ? attached : w, win);
869 break;
870 }
871 } else {
872 // For positive sublayers, we go above all windows
873 // in the same sublayer.
874 if (wSublayer > sublayer) {
875 if (addToToken) {
876 token.windows.add(i, win);
877 }
878 placeWindowBefore(w, win);
879 break;
880 }
881 }
882 }
883 if (i >= NA) {
884 if (addToToken) {
885 token.windows.add(win);
886 }
887 if (sublayer < 0) {
888 placeWindowBefore(attached, win);
889 } else {
890 placeWindowAfter(largestSublayer >= 0
891 ? windowWithLargestSublayer
892 : attached,
893 win);
894 }
895 }
896 }
Romain Guy06882f82009-06-10 13:36:04 -0700897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 if (win.mAppToken != null && addToToken) {
899 win.mAppToken.allAppWindows.add(win);
900 }
901 }
Romain Guy06882f82009-06-10 13:36:04 -0700902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 static boolean canBeImeTarget(WindowState w) {
904 final int fl = w.mAttrs.flags
905 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
906 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
907 return w.isVisibleOrAdding();
908 }
909 return false;
910 }
Romain Guy06882f82009-06-10 13:36:04 -0700911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700913 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 final int N = localmWindows.size();
915 WindowState w = null;
916 int i = N;
917 while (i > 0) {
918 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700919 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700920
Joe Onorato8a9b2202010-02-26 18:56:32 -0800921 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 // + Integer.toHexString(w.mAttrs.flags));
923 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800924 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 // Yet more tricksyness! If this window is a "starting"
927 // window, we do actually want to be on top of it, but
928 // it is not -really- where input will go. So if the caller
929 // is not actually looking to move the IME, look down below
930 // for a real window to target...
931 if (!willMove
932 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
933 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700934 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800935 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
936 i--;
937 w = wb;
938 }
939 }
940 break;
941 }
942 }
Romain Guy06882f82009-06-10 13:36:04 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700945
Joe Onorato8a9b2202010-02-26 18:56:32 -0800946 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 if (willMove && w != null) {
950 final WindowState curTarget = mInputMethodTarget;
951 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 // Now some fun for dealing with window animations that
954 // modify the Z order. We need to look at all windows below
955 // the current target that are in this app, finding the highest
956 // visible one in layering.
957 AppWindowToken token = curTarget.mAppToken;
958 WindowState highestTarget = null;
959 int highestPos = 0;
960 if (token.animating || token.animation != null) {
961 int pos = 0;
962 pos = localmWindows.indexOf(curTarget);
963 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700964 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 if (win.mAppToken != token) {
966 break;
967 }
968 if (!win.mRemoved) {
969 if (highestTarget == null || win.mAnimLayer >
970 highestTarget.mAnimLayer) {
971 highestTarget = win;
972 highestPos = pos;
973 }
974 }
975 pos--;
976 }
977 }
Romain Guy06882f82009-06-10 13:36:04 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800980 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 + mNextAppTransition + " " + highestTarget
982 + " animating=" + highestTarget.isAnimating()
983 + " layer=" + highestTarget.mAnimLayer
984 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700985
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700986 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 // If we are currently setting up for an animation,
988 // hold everything until we can find out what will happen.
989 mInputMethodTargetWaitingAnim = true;
990 mInputMethodTarget = highestTarget;
991 return highestPos + 1;
992 } else if (highestTarget.isAnimating() &&
993 highestTarget.mAnimLayer > w.mAnimLayer) {
994 // If the window we are currently targeting is involved
995 // with an animation, and it is on top of the next target
996 // we will be over, then hold off on moving until
997 // that is done.
998 mInputMethodTarget = highestTarget;
999 return highestPos + 1;
1000 }
1001 }
1002 }
1003 }
Romain Guy06882f82009-06-10 13:36:04 -07001004
Joe Onorato8a9b2202010-02-26 18:56:32 -08001005 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 if (w != null) {
1007 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001008 if (DEBUG_INPUT_METHOD) {
1009 RuntimeException e = null;
1010 if (!HIDE_STACK_CRAWLS) {
1011 e = new RuntimeException();
1012 e.fillInStackTrace();
1013 }
1014 Slog.w(TAG, "Moving IM target from "
1015 + mInputMethodTarget + " to " + w, e);
1016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 mInputMethodTarget = w;
1018 if (w.mAppToken != null) {
1019 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1020 } else {
1021 setInputMethodAnimLayerAdjustment(0);
1022 }
1023 }
1024 return i+1;
1025 }
1026 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001027 if (DEBUG_INPUT_METHOD) {
1028 RuntimeException e = null;
1029 if (!HIDE_STACK_CRAWLS) {
1030 e = new RuntimeException();
1031 e.fillInStackTrace();
1032 }
1033 Slog.w(TAG, "Moving IM target from "
1034 + mInputMethodTarget + " to null", e);
1035 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 mInputMethodTarget = null;
1037 setInputMethodAnimLayerAdjustment(0);
1038 }
1039 return -1;
1040 }
Romain Guy06882f82009-06-10 13:36:04 -07001041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 void addInputMethodWindowToListLocked(WindowState win) {
1043 int pos = findDesiredInputMethodWindowIndexLocked(true);
1044 if (pos >= 0) {
1045 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001046 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001047 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001049 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 moveInputMethodDialogsLocked(pos+1);
1051 return;
1052 }
1053 win.mTargetAppToken = null;
1054 addWindowToListInOrderLocked(win, true);
1055 moveInputMethodDialogsLocked(pos);
1056 }
Romain Guy06882f82009-06-10 13:36:04 -07001057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001059 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 mInputMethodAnimLayerAdjustment = adj;
1061 WindowState imw = mInputMethodWindow;
1062 if (imw != null) {
1063 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001064 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 + " anim layer: " + imw.mAnimLayer);
1066 int wi = imw.mChildWindows.size();
1067 while (wi > 0) {
1068 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001069 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 + " anim layer: " + cw.mAnimLayer);
1073 }
1074 }
1075 int di = mInputMethodDialogs.size();
1076 while (di > 0) {
1077 di --;
1078 imw = mInputMethodDialogs.get(di);
1079 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001080 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 + " anim layer: " + imw.mAnimLayer);
1082 }
1083 }
Romain Guy06882f82009-06-10 13:36:04 -07001084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1086 int wpos = mWindows.indexOf(win);
1087 if (wpos >= 0) {
1088 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001089 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001091 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 int NC = win.mChildWindows.size();
1093 while (NC > 0) {
1094 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001095 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 int cpos = mWindows.indexOf(cw);
1097 if (cpos >= 0) {
1098 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001099 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001100 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 mWindows.remove(cpos);
1102 }
1103 }
1104 }
1105 return interestingPos;
1106 }
Romain Guy06882f82009-06-10 13:36:04 -07001107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 private void reAddWindowToListInOrderLocked(WindowState win) {
1109 addWindowToListInOrderLocked(win, false);
1110 // This is a hack to get all of the child windows added as well
1111 // at the right position. Child windows should be rare and
1112 // this case should be rare, so it shouldn't be that big a deal.
1113 int wpos = mWindows.indexOf(win);
1114 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001115 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001116 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001118 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 reAddWindowLocked(wpos, win);
1120 }
1121 }
Romain Guy06882f82009-06-10 13:36:04 -07001122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 void logWindowList(String prefix) {
1124 int N = mWindows.size();
1125 while (N > 0) {
1126 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001127 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 }
1129 }
Romain Guy06882f82009-06-10 13:36:04 -07001130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 void moveInputMethodDialogsLocked(int pos) {
1132 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001135 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 for (int i=0; i<N; i++) {
1137 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1138 }
1139 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001140 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 logWindowList(" ");
1142 }
Romain Guy06882f82009-06-10 13:36:04 -07001143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 if (pos >= 0) {
1145 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1146 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001147 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 if (wp == mInputMethodWindow) {
1149 pos++;
1150 }
1151 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001152 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 for (int i=0; i<N; i++) {
1154 WindowState win = dialogs.get(i);
1155 win.mTargetAppToken = targetAppToken;
1156 pos = reAddWindowLocked(pos, win);
1157 }
1158 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001159 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 logWindowList(" ");
1161 }
1162 return;
1163 }
1164 for (int i=0; i<N; i++) {
1165 WindowState win = dialogs.get(i);
1166 win.mTargetAppToken = null;
1167 reAddWindowToListInOrderLocked(win);
1168 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001169 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 logWindowList(" ");
1171 }
1172 }
1173 }
Romain Guy06882f82009-06-10 13:36:04 -07001174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1176 final WindowState imWin = mInputMethodWindow;
1177 final int DN = mInputMethodDialogs.size();
1178 if (imWin == null && DN == 0) {
1179 return false;
1180 }
Romain Guy06882f82009-06-10 13:36:04 -07001181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1183 if (imPos >= 0) {
1184 // In this case, the input method windows are to be placed
1185 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001187 // First check to see if the input method windows are already
1188 // located here, and contiguous.
1189 final int N = mWindows.size();
1190 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001191 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 // Figure out the actual input method window that should be
1194 // at the bottom of their stack.
1195 WindowState baseImWin = imWin != null
1196 ? imWin : mInputMethodDialogs.get(0);
1197 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001198 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 if (cw.mSubLayer < 0) baseImWin = cw;
1200 }
Romain Guy06882f82009-06-10 13:36:04 -07001201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 if (firstImWin == baseImWin) {
1203 // The windows haven't moved... but are they still contiguous?
1204 // First find the top IM window.
1205 int pos = imPos+1;
1206 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001207 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 break;
1209 }
1210 pos++;
1211 }
1212 pos++;
1213 // Now there should be no more input method windows above.
1214 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001215 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 break;
1217 }
1218 pos++;
1219 }
1220 if (pos >= N) {
1221 // All is good!
1222 return false;
1223 }
1224 }
Romain Guy06882f82009-06-10 13:36:04 -07001225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 if (imWin != null) {
1227 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001228 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 logWindowList(" ");
1230 }
1231 imPos = tmpRemoveWindowLocked(imPos, imWin);
1232 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001233 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 logWindowList(" ");
1235 }
1236 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1237 reAddWindowLocked(imPos, imWin);
1238 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001239 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 logWindowList(" ");
1241 }
1242 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1243 } else {
1244 moveInputMethodDialogsLocked(imPos);
1245 }
Romain Guy06882f82009-06-10 13:36:04 -07001246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 } else {
1248 // In this case, the input method windows go in a fixed layer,
1249 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001252 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 tmpRemoveWindowLocked(0, imWin);
1254 imWin.mTargetAppToken = null;
1255 reAddWindowToListInOrderLocked(imWin);
1256 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001257 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 logWindowList(" ");
1259 }
1260 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1261 } else {
1262 moveInputMethodDialogsLocked(-1);;
1263 }
Romain Guy06882f82009-06-10 13:36:04 -07001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 }
Romain Guy06882f82009-06-10 13:36:04 -07001266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 if (needAssignLayers) {
1268 assignLayersLocked();
1269 }
Romain Guy06882f82009-06-10 13:36:04 -07001270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 return true;
1272 }
Romain Guy06882f82009-06-10 13:36:04 -07001273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 void adjustInputMethodDialogsLocked() {
1275 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1276 }
Romain Guy06882f82009-06-10 13:36:04 -07001277
Dianne Hackborn25994b42009-09-04 14:21:19 -07001278 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001279 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001280 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1281 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1282 ? wallpaperTarget.mAppToken.animation : null)
1283 + " upper=" + mUpperWallpaperTarget
1284 + " lower=" + mLowerWallpaperTarget);
1285 return (wallpaperTarget != null
1286 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1287 && wallpaperTarget.mAppToken.animation != null)))
1288 || mUpperWallpaperTarget != null
1289 || mLowerWallpaperTarget != null;
1290 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001291
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001292 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1293 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001294
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001295 int adjustWallpaperWindowsLocked() {
1296 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001297
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001298 final int dw = mDisplay.getWidth();
1299 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001300
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001301 // First find top-most window that has asked to be on top of the
1302 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001303 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001304 int N = localmWindows.size();
1305 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001306 WindowState foundW = null;
1307 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001308 WindowState topCurW = null;
1309 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001310 int i = N;
1311 while (i > 0) {
1312 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001313 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001314 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1315 if (topCurW == null) {
1316 topCurW = w;
1317 topCurI = i;
1318 }
1319 continue;
1320 }
1321 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001322 if (w.mAppToken != null) {
1323 // If this window's app token is hidden and not animating,
1324 // it is of no interest to us.
1325 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001326 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001327 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001328 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001329 continue;
1330 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001331 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001332 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001333 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1334 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001335 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001336 && (mWallpaperTarget == w
1337 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001338 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001339 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001340 foundW = w;
1341 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001342 if (w == mWallpaperTarget && ((w.mAppToken != null
1343 && w.mAppToken.animation != null)
1344 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001345 // The current wallpaper target is animating, so we'll
1346 // look behind it for another possible target and figure
1347 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001348 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001349 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001350 continue;
1351 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001352 break;
1353 }
1354 }
1355
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001356 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001357 // If we are currently waiting for an app transition, and either
1358 // the current target or the next target are involved with it,
1359 // then hold off on doing anything with the wallpaper.
1360 // Note that we are checking here for just whether the target
1361 // is part of an app token... which is potentially overly aggressive
1362 // (the app token may not be involved in the transition), but good
1363 // enough (we'll just wait until whatever transition is pending
1364 // executes).
1365 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001366 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001367 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001368 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001369 }
1370 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001371 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001372 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001373 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001374 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001375 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001376
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001377 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001378 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001379 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 + " oldTarget: " + mWallpaperTarget);
1381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001382
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001383 mLowerWallpaperTarget = null;
1384 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001385
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 WindowState oldW = mWallpaperTarget;
1387 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001388
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001389 // Now what is happening... if the current and new targets are
1390 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001391 if (foundW != null && oldW != null) {
1392 boolean oldAnim = oldW.mAnimation != null
1393 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1394 boolean foundAnim = foundW.mAnimation != null
1395 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001396 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001397 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001399 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001400 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 int oldI = localmWindows.indexOf(oldW);
1402 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001403 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001404 }
1405 if (oldI >= 0) {
1406 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001407 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001408 + "=" + oldW + "; new#" + foundI
1409 + "=" + foundW);
1410 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001411
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001413 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001414 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001415 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001416 }
1417 mWallpaperTarget = oldW;
1418 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001419
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001420 // Now set the upper and lower wallpaper targets
1421 // correctly, and make sure that we are positioning
1422 // the wallpaper below the lower.
1423 if (foundI > oldI) {
1424 // The new target is on top of the old one.
1425 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001426 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001427 }
1428 mUpperWallpaperTarget = foundW;
1429 mLowerWallpaperTarget = oldW;
1430 foundW = oldW;
1431 foundI = oldI;
1432 } else {
1433 // The new target is below the old one.
1434 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001435 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001436 }
1437 mUpperWallpaperTarget = oldW;
1438 mLowerWallpaperTarget = foundW;
1439 }
1440 }
1441 }
1442 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001443
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001444 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001445 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001446 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1447 || (mLowerWallpaperTarget.mAppToken != null
1448 && mLowerWallpaperTarget.mAppToken.animation != null);
1449 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1450 || (mUpperWallpaperTarget.mAppToken != null
1451 && mUpperWallpaperTarget.mAppToken.animation != null);
1452 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001453 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001454 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001455 }
1456 mLowerWallpaperTarget = null;
1457 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 }
1459 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001460
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001461 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001462 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001463 // The window is visible to the compositor... but is it visible
1464 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001465 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001466 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001467
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001468 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001469 // its layer adjustment. Only do this if we are not transfering
1470 // between two wallpaper targets.
1471 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001472 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001473 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001474
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001475 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1476 * TYPE_LAYER_MULTIPLIER
1477 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001478
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001479 // Now w is the window we are supposed to be behind... but we
1480 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001481 // AND any starting window associated with it, AND below the
1482 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001483 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001484 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001485 if (wb.mBaseLayer < maxLayer &&
1486 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001487 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001488 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001489 // This window is not related to the previous one in any
1490 // interesting way, so stop here.
1491 break;
1492 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001493 foundW = wb;
1494 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001495 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001496 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001497 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001498 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001499
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001500 if (foundW == null && topCurW != null) {
1501 // There is no wallpaper target, so it goes at the bottom.
1502 // We will assume it is the same place as last time, if known.
1503 foundW = topCurW;
1504 foundI = topCurI+1;
1505 } else {
1506 // Okay i is the position immediately above the wallpaper. Look at
1507 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001508 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001509 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001510
Dianne Hackborn284ac932009-08-28 10:34:25 -07001511 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001512 if (mWallpaperTarget.mWallpaperX >= 0) {
1513 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001514 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001515 }
1516 if (mWallpaperTarget.mWallpaperY >= 0) {
1517 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001518 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001519 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001520 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001521
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001522 // Start stepping backwards from here, ensuring that our wallpaper windows
1523 // are correctly placed.
1524 int curTokenIndex = mWallpaperTokens.size();
1525 while (curTokenIndex > 0) {
1526 curTokenIndex--;
1527 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001528 if (token.hidden == visible) {
1529 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1530 token.hidden = !visible;
1531 // Need to do a layout to ensure the wallpaper now has the
1532 // correct size.
1533 mLayoutNeeded = true;
1534 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001535
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001536 int curWallpaperIndex = token.windows.size();
1537 while (curWallpaperIndex > 0) {
1538 curWallpaperIndex--;
1539 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001540
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001541 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001542 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001543 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001544
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001545 // First, make sure the client has the current visibility
1546 // state.
1547 if (wallpaper.mWallpaperVisible != visible) {
1548 wallpaper.mWallpaperVisible = visible;
1549 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001550 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001551 "Setting visibility of wallpaper " + wallpaper
1552 + ": " + visible);
1553 wallpaper.mClient.dispatchAppVisibility(visible);
1554 } catch (RemoteException e) {
1555 }
1556 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001557
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001558 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001559 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001560 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001561
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001562 // First, if this window is at the current index, then all
1563 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001564 if (wallpaper == foundW) {
1565 foundI--;
1566 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001567 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001568 continue;
1569 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001570
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001571 // The window didn't match... the current wallpaper window,
1572 // wherever it is, is in the wrong place, so make sure it is
1573 // not in the list.
1574 int oldIndex = localmWindows.indexOf(wallpaper);
1575 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001576 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001577 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001578 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001579 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001580 if (oldIndex < foundI) {
1581 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001582 }
1583 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001584
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001585 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001586 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001587 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001588 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001589
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001590 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001591 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001592 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001593 }
1594 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001595
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001596 return changed;
1597 }
1598
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001599 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001600 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001601 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001602 mWallpaperAnimLayerAdjustment = adj;
1603 int curTokenIndex = mWallpaperTokens.size();
1604 while (curTokenIndex > 0) {
1605 curTokenIndex--;
1606 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1607 int curWallpaperIndex = token.windows.size();
1608 while (curWallpaperIndex > 0) {
1609 curWallpaperIndex--;
1610 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1611 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001612 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001613 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001614 }
1615 }
1616 }
1617
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001618 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1619 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001620 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001621 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001622 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001623 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001624 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1625 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1626 changed = wallpaperWin.mXOffset != offset;
1627 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001628 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001629 + wallpaperWin + " x: " + offset);
1630 wallpaperWin.mXOffset = offset;
1631 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001632 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001633 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001634 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001635 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001637
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001638 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001639 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001640 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1641 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1642 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001643 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001644 + wallpaperWin + " y: " + offset);
1645 changed = true;
1646 wallpaperWin.mYOffset = offset;
1647 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001648 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001649 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001650 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001651 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001653
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001654 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001655 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001656 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001657 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1658 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001659 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001660 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001661 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001662 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001663 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1664 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001665 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001666 if (mWaitingOnWallpaper != null) {
1667 long start = SystemClock.uptimeMillis();
1668 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1669 < start) {
1670 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001671 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001672 "Waiting for offset complete...");
1673 mWindowMap.wait(WALLPAPER_TIMEOUT);
1674 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001675 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001676 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001677 if ((start+WALLPAPER_TIMEOUT)
1678 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001679 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001680 + wallpaperWin);
1681 mLastWallpaperTimeoutTime = start;
1682 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001684 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001685 }
1686 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001687 } catch (RemoteException e) {
1688 }
1689 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001690
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001691 return changed;
1692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001693
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001694 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001695 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001696 if (mWaitingOnWallpaper != null &&
1697 mWaitingOnWallpaper.mClient.asBinder() == window) {
1698 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001699 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001700 }
1701 }
1702 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001703
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001704 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001705 final int dw = mDisplay.getWidth();
1706 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001707
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001708 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001709
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001710 WindowState target = mWallpaperTarget;
1711 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001712 if (target.mWallpaperX >= 0) {
1713 mLastWallpaperX = target.mWallpaperX;
1714 } else if (changingTarget.mWallpaperX >= 0) {
1715 mLastWallpaperX = changingTarget.mWallpaperX;
1716 }
1717 if (target.mWallpaperY >= 0) {
1718 mLastWallpaperY = target.mWallpaperY;
1719 } else if (changingTarget.mWallpaperY >= 0) {
1720 mLastWallpaperY = changingTarget.mWallpaperY;
1721 }
1722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001723
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001724 int curTokenIndex = mWallpaperTokens.size();
1725 while (curTokenIndex > 0) {
1726 curTokenIndex--;
1727 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1728 int curWallpaperIndex = token.windows.size();
1729 while (curWallpaperIndex > 0) {
1730 curWallpaperIndex--;
1731 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1732 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1733 wallpaper.computeShownFrameLocked();
1734 changed = true;
1735 // We only want to be synchronous with one wallpaper.
1736 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001737 }
1738 }
1739 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001740
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001741 return changed;
1742 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001743
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001744 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001745 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001746 final int dw = mDisplay.getWidth();
1747 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001749 int curTokenIndex = mWallpaperTokens.size();
1750 while (curTokenIndex > 0) {
1751 curTokenIndex--;
1752 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001753 if (token.hidden == visible) {
1754 token.hidden = !visible;
1755 // Need to do a layout to ensure the wallpaper now has the
1756 // correct size.
1757 mLayoutNeeded = true;
1758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001759
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001760 int curWallpaperIndex = token.windows.size();
1761 while (curWallpaperIndex > 0) {
1762 curWallpaperIndex--;
1763 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1764 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001765 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001766 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001767
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001768 if (wallpaper.mWallpaperVisible != visible) {
1769 wallpaper.mWallpaperVisible = visible;
1770 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001771 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001772 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001773 + ": " + visible);
1774 wallpaper.mClient.dispatchAppVisibility(visible);
1775 } catch (RemoteException e) {
1776 }
1777 }
1778 }
1779 }
1780 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001782 public int addWindow(Session session, IWindow client,
1783 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001784 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001785 int res = mPolicy.checkAddPermission(attrs);
1786 if (res != WindowManagerImpl.ADD_OKAY) {
1787 return res;
1788 }
Romain Guy06882f82009-06-10 13:36:04 -07001789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 boolean reportNewConfig = false;
1791 WindowState attachedWindow = null;
1792 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001793 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001797 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 }
Romain Guy06882f82009-06-10 13:36:04 -07001799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001801 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1803 }
1804
1805 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001806 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001808 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 + attrs.token + ". Aborting.");
1810 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1811 }
1812 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1813 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001814 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 + attrs.token + ". Aborting.");
1816 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1817 }
1818 }
1819
1820 boolean addToken = false;
1821 WindowToken token = mTokenMap.get(attrs.token);
1822 if (token == null) {
1823 if (attrs.type >= FIRST_APPLICATION_WINDOW
1824 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001825 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001826 + attrs.token + ". Aborting.");
1827 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1828 }
1829 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001830 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 + attrs.token + ". Aborting.");
1832 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1833 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001834 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001835 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001836 + attrs.token + ". Aborting.");
1837 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 token = new WindowToken(attrs.token, -1, false);
1840 addToken = true;
1841 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1842 && attrs.type <= LAST_APPLICATION_WINDOW) {
1843 AppWindowToken atoken = token.appWindowToken;
1844 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 + token + ". Aborting.");
1847 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1848 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001849 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 + token + ". Aborting.");
1851 return WindowManagerImpl.ADD_APP_EXITING;
1852 }
1853 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1854 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001855 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1857 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1858 }
1859 } else if (attrs.type == TYPE_INPUT_METHOD) {
1860 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001861 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 + attrs.token + ". Aborting.");
1863 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1864 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001865 } else if (attrs.type == TYPE_WALLPAPER) {
1866 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001867 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001868 + attrs.token + ". Aborting.");
1869 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 }
1872
1873 win = new WindowState(session, client, token,
1874 attachedWindow, attrs, viewVisibility);
1875 if (win.mDeathRecipient == null) {
1876 // Client has apparently died, so there is no reason to
1877 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001878 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 + " that is dead, aborting.");
1880 return WindowManagerImpl.ADD_APP_EXITING;
1881 }
1882
1883 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 res = mPolicy.prepareAddWindowLw(win, attrs);
1886 if (res != WindowManagerImpl.ADD_OKAY) {
1887 return res;
1888 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001889
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001890 if (outInputChannel != null) {
1891 String name = win.makeInputChannelName();
1892 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1893 win.mInputChannel = inputChannels[0];
1894 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1895
1896 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898
1899 // From now on, no exceptions or errors allowed!
1900
1901 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001902
Dianne Hackborn5132b372010-07-29 12:51:35 -07001903 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 if (addToken) {
1906 mTokenMap.put(attrs.token, token);
1907 mTokenList.add(token);
1908 }
1909 win.attach();
1910 mWindowMap.put(client.asBinder(), win);
1911
1912 if (attrs.type == TYPE_APPLICATION_STARTING &&
1913 token.appWindowToken != null) {
1914 token.appWindowToken.startingWindow = win;
1915 }
1916
1917 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 if (attrs.type == TYPE_INPUT_METHOD) {
1920 mInputMethodWindow = win;
1921 addInputMethodWindowToListLocked(win);
1922 imMayMove = false;
1923 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1924 mInputMethodDialogs.add(win);
1925 addWindowToListInOrderLocked(win, true);
1926 adjustInputMethodDialogsLocked();
1927 imMayMove = false;
1928 } else {
1929 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001930 if (attrs.type == TYPE_WALLPAPER) {
1931 mLastWallpaperTimeoutTime = 0;
1932 adjustWallpaperWindowsLocked();
1933 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001934 adjustWallpaperWindowsLocked();
1935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 }
Romain Guy06882f82009-06-10 13:36:04 -07001937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 if (mInTouchMode) {
1943 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1944 }
1945 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1946 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1947 }
Romain Guy06882f82009-06-10 13:36:04 -07001948
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001949 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001951 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1952 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 imMayMove = false;
1954 }
1955 }
Romain Guy06882f82009-06-10 13:36:04 -07001956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001958 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 }
Romain Guy06882f82009-06-10 13:36:04 -07001960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 assignLayersLocked();
1962 // Don't do layout here, the window must call
1963 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 //dump();
1966
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001967 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001968 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001969 }
Jeff Brown349703e2010-06-22 01:27:15 -07001970
Joe Onorato8a9b2202010-02-26 18:56:32 -08001971 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 TAG, "New client " + client.asBinder()
1973 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001974
1975 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1976 reportNewConfig = true;
1977 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 }
1979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 if (reportNewConfig) {
1981 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07001983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 return res;
1987 }
Romain Guy06882f82009-06-10 13:36:04 -07001988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 public void removeWindow(Session session, IWindow client) {
1990 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001991 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 if (win == null) {
1993 return;
1994 }
1995 removeWindowLocked(session, win);
1996 }
1997 }
Romain Guy06882f82009-06-10 13:36:04 -07001998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 public void removeWindowLocked(Session session, WindowState win) {
2000
Joe Onorato8a9b2202010-02-26 18:56:32 -08002001 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 TAG, "Remove " + win + " client="
2003 + Integer.toHexString(System.identityHashCode(
2004 win.mClient.asBinder()))
2005 + ", surface=" + win.mSurface);
2006
2007 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002008
2009 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002010
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2013 + " mExiting=" + win.mExiting
2014 + " isAnimating=" + win.isAnimating()
2015 + " app-animation="
2016 + (win.mAppToken != null ? win.mAppToken.animation : null)
2017 + " inPendingTransaction="
2018 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2019 + " mDisplayFrozen=" + mDisplayFrozen);
2020 // Visibility of the removed window. Will be used later to update orientation later on.
2021 boolean wasVisible = false;
2022 // First, see if we need to run an animation. If we do, we have
2023 // to hold off on removing the window until the animation is done.
2024 // If the display is frozen, just remove immediately, since the
2025 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002026 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 // If we are not currently running the exit animation, we
2028 // need to see about starting one.
2029 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2032 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2033 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2034 }
2035 // Try starting an animation.
2036 if (applyAnimationLocked(win, transit, false)) {
2037 win.mExiting = true;
2038 }
2039 }
2040 if (win.mExiting || win.isAnimating()) {
2041 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002042 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 win.mExiting = true;
2044 win.mRemoveOnExit = true;
2045 mLayoutNeeded = true;
2046 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2047 performLayoutAndPlaceSurfacesLocked();
2048 if (win.mAppToken != null) {
2049 win.mAppToken.updateReportedVisibilityLocked();
2050 }
2051 //dump();
2052 Binder.restoreCallingIdentity(origId);
2053 return;
2054 }
2055 }
2056
2057 removeWindowInnerLocked(session, win);
2058 // Removing a visible window will effect the computed orientation
2059 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002060 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002061 != mForcedAppOrientation
2062 && updateOrientationFromAppTokensLocked()) {
2063 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002064 }
2065 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2066 Binder.restoreCallingIdentity(origId);
2067 }
Romain Guy06882f82009-06-10 13:36:04 -07002068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002072 if (mInputMethodTarget == win) {
2073 moveInputMethodWindowsIfNeededLocked(false);
2074 }
Romain Guy06882f82009-06-10 13:36:04 -07002075
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002076 if (false) {
2077 RuntimeException e = new RuntimeException("here");
2078 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002079 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002080 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 mPolicy.removeWindowLw(win);
2083 win.removeLocked();
2084
2085 mWindowMap.remove(win.mClient.asBinder());
2086 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002087 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002088 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089
2090 if (mInputMethodWindow == win) {
2091 mInputMethodWindow = null;
2092 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2093 mInputMethodDialogs.remove(win);
2094 }
Romain Guy06882f82009-06-10 13:36:04 -07002095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 final WindowToken token = win.mToken;
2097 final AppWindowToken atoken = win.mAppToken;
2098 token.windows.remove(win);
2099 if (atoken != null) {
2100 atoken.allAppWindows.remove(win);
2101 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002102 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103 TAG, "**** Removing window " + win + ": count="
2104 + token.windows.size());
2105 if (token.windows.size() == 0) {
2106 if (!token.explicit) {
2107 mTokenMap.remove(token.token);
2108 mTokenList.remove(token);
2109 } else if (atoken != null) {
2110 atoken.firstWindowDrawn = false;
2111 }
2112 }
2113
2114 if (atoken != null) {
2115 if (atoken.startingWindow == win) {
2116 atoken.startingWindow = null;
2117 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2118 // If this is the last window and we had requested a starting
2119 // transition window, well there is no point now.
2120 atoken.startingData = null;
2121 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2122 // If this is the last window except for a starting transition
2123 // window, we need to get rid of the starting transition.
2124 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002125 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 + ": no more real windows");
2127 }
2128 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2129 mH.sendMessage(m);
2130 }
2131 }
Romain Guy06882f82009-06-10 13:36:04 -07002132
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002133 if (win.mAttrs.type == TYPE_WALLPAPER) {
2134 mLastWallpaperTimeoutTime = 0;
2135 adjustWallpaperWindowsLocked();
2136 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002137 adjustWallpaperWindowsLocked();
2138 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 if (!mInLayout) {
2141 assignLayersLocked();
2142 mLayoutNeeded = true;
2143 performLayoutAndPlaceSurfacesLocked();
2144 if (win.mAppToken != null) {
2145 win.mAppToken.updateReportedVisibilityLocked();
2146 }
2147 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002148
2149 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 }
2151
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002152 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2153 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2154 + ": " + msg + " / " + w.mAttrs.getTitle();
2155 if (where != null) {
2156 Slog.i(TAG, str, where);
2157 } else {
2158 Slog.i(TAG, str);
2159 }
2160 }
2161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2163 long origId = Binder.clearCallingIdentity();
2164 try {
2165 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002166 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002168 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 Surface.openTransaction();
2170 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002171 if (SHOW_TRANSACTIONS) logSurface(w,
2172 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 w.mSurface.setTransparentRegionHint(region);
2174 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002175 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 Surface.closeTransaction();
2177 }
2178 }
2179 }
2180 } finally {
2181 Binder.restoreCallingIdentity(origId);
2182 }
2183 }
2184
2185 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002186 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002187 Rect visibleInsets) {
2188 long origId = Binder.clearCallingIdentity();
2189 try {
2190 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002191 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 if (w != null) {
2193 w.mGivenInsetsPending = false;
2194 w.mGivenContentInsets.set(contentInsets);
2195 w.mGivenVisibleInsets.set(visibleInsets);
2196 w.mTouchableInsets = touchableInsets;
2197 mLayoutNeeded = true;
2198 performLayoutAndPlaceSurfacesLocked();
2199 }
2200 }
2201 } finally {
2202 Binder.restoreCallingIdentity(origId);
2203 }
2204 }
Romain Guy06882f82009-06-10 13:36:04 -07002205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 public void getWindowDisplayFrame(Session session, IWindow client,
2207 Rect outDisplayFrame) {
2208 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002209 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 if (win == null) {
2211 outDisplayFrame.setEmpty();
2212 return;
2213 }
2214 outDisplayFrame.set(win.mDisplayFrame);
2215 }
2216 }
2217
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002218 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2219 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002220 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2221 window.mWallpaperX = x;
2222 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002223 window.mWallpaperXStep = xStep;
2224 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002225 if (updateWallpaperOffsetLocked(window, true)) {
2226 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002227 }
2228 }
2229 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002230
Dianne Hackborn75804932009-10-20 20:15:20 -07002231 void wallpaperCommandComplete(IBinder window, Bundle result) {
2232 synchronized (mWindowMap) {
2233 if (mWaitingOnWallpaper != null &&
2234 mWaitingOnWallpaper.mClient.asBinder() == window) {
2235 mWaitingOnWallpaper = null;
2236 mWindowMap.notifyAll();
2237 }
2238 }
2239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002240
Dianne Hackborn75804932009-10-20 20:15:20 -07002241 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2242 String action, int x, int y, int z, Bundle extras, boolean sync) {
2243 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2244 || window == mUpperWallpaperTarget) {
2245 boolean doWait = sync;
2246 int curTokenIndex = mWallpaperTokens.size();
2247 while (curTokenIndex > 0) {
2248 curTokenIndex--;
2249 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2250 int curWallpaperIndex = token.windows.size();
2251 while (curWallpaperIndex > 0) {
2252 curWallpaperIndex--;
2253 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2254 try {
2255 wallpaper.mClient.dispatchWallpaperCommand(action,
2256 x, y, z, extras, sync);
2257 // We only want to be synchronous with one wallpaper.
2258 sync = false;
2259 } catch (RemoteException e) {
2260 }
2261 }
2262 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002263
Dianne Hackborn75804932009-10-20 20:15:20 -07002264 if (doWait) {
2265 // XXX Need to wait for result.
2266 }
2267 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002268
Dianne Hackborn75804932009-10-20 20:15:20 -07002269 return null;
2270 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002272 public int relayoutWindow(Session session, IWindow client,
2273 WindowManager.LayoutParams attrs, int requestedWidth,
2274 int requestedHeight, int viewVisibility, boolean insetsPending,
2275 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002276 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 boolean displayed = false;
2278 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002279 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002283 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 if (win == null) {
2285 return 0;
2286 }
2287 win.mRequestedWidth = requestedWidth;
2288 win.mRequestedHeight = requestedHeight;
2289
2290 if (attrs != null) {
2291 mPolicy.adjustWindowParamsLw(attrs);
2292 }
Romain Guy06882f82009-06-10 13:36:04 -07002293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 int attrChanges = 0;
2295 int flagChanges = 0;
2296 if (attrs != null) {
2297 flagChanges = win.mAttrs.flags ^= attrs.flags;
2298 attrChanges = win.mAttrs.copyFrom(attrs);
2299 }
2300
Joe Onorato8a9b2202010-02-26 18:56:32 -08002301 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002302
2303 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2304 win.mAlpha = attrs.alpha;
2305 }
2306
2307 final boolean scaledWindow =
2308 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2309
2310 if (scaledWindow) {
2311 // requested{Width|Height} Surface's physical size
2312 // attrs.{width|height} Size on screen
2313 win.mHScale = (attrs.width != requestedWidth) ?
2314 (attrs.width / (float)requestedWidth) : 1.0f;
2315 win.mVScale = (attrs.height != requestedHeight) ?
2316 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002317 } else {
2318 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 }
2320
2321 boolean imMayMove = (flagChanges&(
2322 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2323 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 boolean focusMayChange = win.mViewVisibility != viewVisibility
2326 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2327 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002328
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002329 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2330 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 win.mRelayoutCalled = true;
2333 final int oldVisibility = win.mViewVisibility;
2334 win.mViewVisibility = viewVisibility;
2335 if (viewVisibility == View.VISIBLE &&
2336 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2337 displayed = !win.isVisibleLw();
2338 if (win.mExiting) {
2339 win.mExiting = false;
2340 win.mAnimation = null;
2341 }
2342 if (win.mDestroying) {
2343 win.mDestroying = false;
2344 mDestroySurface.remove(win);
2345 }
2346 if (oldVisibility == View.GONE) {
2347 win.mEnterAnimationPending = true;
2348 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002349 if (displayed) {
2350 if (win.mSurface != null && !win.mDrawPending
2351 && !win.mCommitDrawPending && !mDisplayFrozen
2352 && mPolicy.isScreenOn()) {
2353 applyEnterAnimationLocked(win);
2354 }
2355 if ((win.mAttrs.flags
2356 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2357 if (DEBUG_VISIBILITY) Slog.v(TAG,
2358 "Relayout window turning screen on: " + win);
2359 win.mTurnOnScreen = true;
2360 }
2361 int diff = 0;
2362 if (win.mConfiguration != mCurConfiguration
2363 && (win.mConfiguration == null
2364 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2365 win.mConfiguration = mCurConfiguration;
2366 if (DEBUG_CONFIGURATION) {
2367 Slog.i(TAG, "Window " + win + " visible with new config: "
2368 + win.mConfiguration + " / 0x"
2369 + Integer.toHexString(diff));
2370 }
2371 outConfig.setTo(mCurConfiguration);
2372 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002373 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2375 // To change the format, we need to re-build the surface.
2376 win.destroySurfaceLocked();
2377 displayed = true;
2378 }
2379 try {
2380 Surface surface = win.createSurfaceLocked();
2381 if (surface != null) {
2382 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002383 win.mReportDestroySurface = false;
2384 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002385 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002386 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002388 // For some reason there isn't a surface. Clear the
2389 // caller's object so they see the same state.
2390 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 }
2392 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002393 mInputMonitor.updateInputWindowsLw();
2394
Joe Onorato8a9b2202010-02-26 18:56:32 -08002395 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002396 + client + " (" + win.mAttrs.getTitle() + ")",
2397 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 Binder.restoreCallingIdentity(origId);
2399 return 0;
2400 }
2401 if (displayed) {
2402 focusMayChange = true;
2403 }
2404 if (win.mAttrs.type == TYPE_INPUT_METHOD
2405 && mInputMethodWindow == null) {
2406 mInputMethodWindow = win;
2407 imMayMove = true;
2408 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002409 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2410 && win.mAppToken != null
2411 && win.mAppToken.startingWindow != null) {
2412 // Special handling of starting window over the base
2413 // window of the app: propagate lock screen flags to it,
2414 // to provide the correct semantics while starting.
2415 final int mask =
2416 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002417 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2418 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002419 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2420 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 } else {
2423 win.mEnterAnimationPending = false;
2424 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002425 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002426 + ": mExiting=" + win.mExiting
2427 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 // If we are not currently running the exit animation, we
2429 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002430 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 // Try starting an animation; if there isn't one, we
2432 // can destroy the surface right away.
2433 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2434 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2435 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2436 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002437 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002439 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 } else if (win.isAnimating()) {
2442 // Currently in a hide animation... turn this into
2443 // an exit.
2444 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002445 } else if (win == mWallpaperTarget) {
2446 // If the wallpaper is currently behind this
2447 // window, we need to change both of them inside
2448 // of a transaction to avoid artifacts.
2449 win.mExiting = true;
2450 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 } else {
2452 if (mInputMethodWindow == win) {
2453 mInputMethodWindow = null;
2454 }
2455 win.destroySurfaceLocked();
2456 }
2457 }
2458 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002459
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002460 if (win.mSurface == null || (win.getAttrs().flags
2461 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2462 || win.mSurfacePendingDestroy) {
2463 // We are being called from a local process, which
2464 // means outSurface holds its current surface. Ensure the
2465 // surface object is cleared, but we don't want it actually
2466 // destroyed at this point.
2467 win.mSurfacePendingDestroy = false;
2468 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002469 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002470 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002471 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002472 "Keeping surface, will report destroy: " + win);
2473 win.mReportDestroySurface = true;
2474 outSurface.copyFrom(win.mSurface);
2475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 }
2477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 if (focusMayChange) {
2479 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2480 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 imMayMove = false;
2482 }
2483 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2484 }
Romain Guy06882f82009-06-10 13:36:04 -07002485
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002486 // updateFocusedWindowLocked() already assigned layers so we only need to
2487 // reassign them at this point if the IM window state gets shuffled
2488 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002491 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2492 // Little hack here -- we -should- be able to rely on the
2493 // function to return true if the IME has moved and needs
2494 // its layer recomputed. However, if the IME was hidden
2495 // and isn't actually moved in the list, its layer may be
2496 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 assignLayers = true;
2498 }
2499 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002500 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002501 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002502 assignLayers = true;
2503 }
2504 }
Romain Guy06882f82009-06-10 13:36:04 -07002505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 mLayoutNeeded = true;
2507 win.mGivenInsetsPending = insetsPending;
2508 if (assignLayers) {
2509 assignLayersLocked();
2510 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002511 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002513 if (displayed && win.mIsWallpaper) {
2514 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002515 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002516 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 if (win.mAppToken != null) {
2518 win.mAppToken.updateReportedVisibilityLocked();
2519 }
2520 outFrame.set(win.mFrame);
2521 outContentInsets.set(win.mContentInsets);
2522 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002523 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002525 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 + ", requestedHeight=" + requestedHeight
2527 + ", viewVisibility=" + viewVisibility
2528 + "\nRelayout returning frame=" + outFrame
2529 + ", surface=" + outSurface);
2530
Joe Onorato8a9b2202010-02-26 18:56:32 -08002531 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2533
2534 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002535
2536 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 }
2538
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002539 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 sendNewConfiguration();
2541 }
Romain Guy06882f82009-06-10 13:36:04 -07002542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2546 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2547 }
2548
2549 public void finishDrawingWindow(Session session, IWindow client) {
2550 final long origId = Binder.clearCallingIdentity();
2551 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002552 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002554 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2555 adjustWallpaperWindowsLocked();
2556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 mLayoutNeeded = true;
2558 performLayoutAndPlaceSurfacesLocked();
2559 }
2560 }
2561 Binder.restoreCallingIdentity(origId);
2562 }
2563
2564 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002565 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 + (lp != null ? lp.packageName : null)
2567 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2568 if (lp != null && lp.windowAnimations != 0) {
2569 // If this is a system resource, don't try to load it from the
2570 // application resources. It is nice to avoid loading application
2571 // resources if we can.
2572 String packageName = lp.packageName != null ? lp.packageName : "android";
2573 int resId = lp.windowAnimations;
2574 if ((resId&0xFF000000) == 0x01000000) {
2575 packageName = "android";
2576 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002577 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 + packageName);
2579 return AttributeCache.instance().get(packageName, resId,
2580 com.android.internal.R.styleable.WindowAnimation);
2581 }
2582 return null;
2583 }
Romain Guy06882f82009-06-10 13:36:04 -07002584
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002585 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002586 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002587 + packageName + " resId=0x" + Integer.toHexString(resId));
2588 if (packageName != null) {
2589 if ((resId&0xFF000000) == 0x01000000) {
2590 packageName = "android";
2591 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002592 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002593 + packageName);
2594 return AttributeCache.instance().get(packageName, resId,
2595 com.android.internal.R.styleable.WindowAnimation);
2596 }
2597 return null;
2598 }
2599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 private void applyEnterAnimationLocked(WindowState win) {
2601 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2602 if (win.mEnterAnimationPending) {
2603 win.mEnterAnimationPending = false;
2604 transit = WindowManagerPolicy.TRANSIT_ENTER;
2605 }
2606
2607 applyAnimationLocked(win, transit, true);
2608 }
2609
2610 private boolean applyAnimationLocked(WindowState win,
2611 int transit, boolean isEntrance) {
2612 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2613 // If we are trying to apply an animation, but already running
2614 // an animation of the same type, then just leave that one alone.
2615 return true;
2616 }
Romain Guy06882f82009-06-10 13:36:04 -07002617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 // Only apply an animation if the display isn't frozen. If it is
2619 // frozen, there is no reason to animate and it can cause strange
2620 // artifacts when we unfreeze the display if some different animation
2621 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002622 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 int anim = mPolicy.selectAnimationLw(win, transit);
2624 int attr = -1;
2625 Animation a = null;
2626 if (anim != 0) {
2627 a = AnimationUtils.loadAnimation(mContext, anim);
2628 } else {
2629 switch (transit) {
2630 case WindowManagerPolicy.TRANSIT_ENTER:
2631 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2632 break;
2633 case WindowManagerPolicy.TRANSIT_EXIT:
2634 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2635 break;
2636 case WindowManagerPolicy.TRANSIT_SHOW:
2637 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2638 break;
2639 case WindowManagerPolicy.TRANSIT_HIDE:
2640 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2641 break;
2642 }
2643 if (attr >= 0) {
2644 a = loadAnimation(win.mAttrs, attr);
2645 }
2646 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002647 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2649 + " mAnimation=" + win.mAnimation
2650 + " isEntrance=" + isEntrance);
2651 if (a != null) {
2652 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002653 RuntimeException e = null;
2654 if (!HIDE_STACK_CRAWLS) {
2655 e = new RuntimeException();
2656 e.fillInStackTrace();
2657 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002658 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 }
2660 win.setAnimation(a);
2661 win.mAnimationIsEntrance = isEntrance;
2662 }
2663 } else {
2664 win.clearAnimation();
2665 }
2666
2667 return win.mAnimation != null;
2668 }
2669
2670 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2671 int anim = 0;
2672 Context context = mContext;
2673 if (animAttr >= 0) {
2674 AttributeCache.Entry ent = getCachedAnimations(lp);
2675 if (ent != null) {
2676 context = ent.context;
2677 anim = ent.array.getResourceId(animAttr, 0);
2678 }
2679 }
2680 if (anim != 0) {
2681 return AnimationUtils.loadAnimation(context, anim);
2682 }
2683 return null;
2684 }
Romain Guy06882f82009-06-10 13:36:04 -07002685
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002686 private Animation loadAnimation(String packageName, int resId) {
2687 int anim = 0;
2688 Context context = mContext;
2689 if (resId >= 0) {
2690 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2691 if (ent != null) {
2692 context = ent.context;
2693 anim = resId;
2694 }
2695 }
2696 if (anim != 0) {
2697 return AnimationUtils.loadAnimation(context, anim);
2698 }
2699 return null;
2700 }
2701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 private boolean applyAnimationLocked(AppWindowToken wtoken,
2703 WindowManager.LayoutParams lp, int transit, boolean enter) {
2704 // Only apply an animation if the display isn't frozen. If it is
2705 // frozen, there is no reason to animate and it can cause strange
2706 // artifacts when we unfreeze the display if some different animation
2707 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002708 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002709 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002710 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002711 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002712 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002713 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002714 } else if (mNextAppTransitionPackage != null) {
2715 a = loadAnimation(mNextAppTransitionPackage, enter ?
2716 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002717 } else {
2718 int animAttr = 0;
2719 switch (transit) {
2720 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2721 animAttr = enter
2722 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2723 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2724 break;
2725 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2726 animAttr = enter
2727 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2728 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2729 break;
2730 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2731 animAttr = enter
2732 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2733 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2734 break;
2735 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2736 animAttr = enter
2737 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2738 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2739 break;
2740 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2741 animAttr = enter
2742 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2743 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2744 break;
2745 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2746 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002747 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002748 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2749 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002750 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002751 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002752 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2753 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002754 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002755 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002756 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002757 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2758 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2759 break;
2760 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2761 animAttr = enter
2762 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2763 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2764 break;
2765 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2766 animAttr = enter
2767 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2768 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002769 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002770 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002771 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002772 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002773 + " anim=" + a
2774 + " animAttr=0x" + Integer.toHexString(animAttr)
2775 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 if (a != null) {
2778 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002779 RuntimeException e = null;
2780 if (!HIDE_STACK_CRAWLS) {
2781 e = new RuntimeException();
2782 e.fillInStackTrace();
2783 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002784 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 }
2786 wtoken.setAnimation(a);
2787 }
2788 } else {
2789 wtoken.clearAnimation();
2790 }
2791
2792 return wtoken.animation != null;
2793 }
2794
2795 // -------------------------------------------------------------
2796 // Application Window Tokens
2797 // -------------------------------------------------------------
2798
2799 public void validateAppTokens(List tokens) {
2800 int v = tokens.size()-1;
2801 int m = mAppTokens.size()-1;
2802 while (v >= 0 && m >= 0) {
2803 AppWindowToken wtoken = mAppTokens.get(m);
2804 if (wtoken.removed) {
2805 m--;
2806 continue;
2807 }
2808 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002809 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2811 }
2812 v--;
2813 m--;
2814 }
2815 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002816 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002817 v--;
2818 }
2819 while (m >= 0) {
2820 AppWindowToken wtoken = mAppTokens.get(m);
2821 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002822 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 }
2824 m--;
2825 }
2826 }
2827
2828 boolean checkCallingPermission(String permission, String func) {
2829 // Quick check: if the calling permission is me, it's all okay.
2830 if (Binder.getCallingPid() == Process.myPid()) {
2831 return true;
2832 }
Romain Guy06882f82009-06-10 13:36:04 -07002833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834 if (mContext.checkCallingPermission(permission)
2835 == PackageManager.PERMISSION_GRANTED) {
2836 return true;
2837 }
2838 String msg = "Permission Denial: " + func + " from pid="
2839 + Binder.getCallingPid()
2840 + ", uid=" + Binder.getCallingUid()
2841 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002842 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 return false;
2844 }
Romain Guy06882f82009-06-10 13:36:04 -07002845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 AppWindowToken findAppWindowToken(IBinder token) {
2847 WindowToken wtoken = mTokenMap.get(token);
2848 if (wtoken == null) {
2849 return null;
2850 }
2851 return wtoken.appWindowToken;
2852 }
Romain Guy06882f82009-06-10 13:36:04 -07002853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 public void addWindowToken(IBinder token, int type) {
2855 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2856 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002857 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 }
Romain Guy06882f82009-06-10 13:36:04 -07002859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 synchronized(mWindowMap) {
2861 WindowToken wtoken = mTokenMap.get(token);
2862 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002863 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 return;
2865 }
2866 wtoken = new WindowToken(token, type, true);
2867 mTokenMap.put(token, wtoken);
2868 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002869 if (type == TYPE_WALLPAPER) {
2870 mWallpaperTokens.add(wtoken);
2871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 }
2873 }
Romain Guy06882f82009-06-10 13:36:04 -07002874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 public void removeWindowToken(IBinder token) {
2876 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2877 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002878 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 }
2880
2881 final long origId = Binder.clearCallingIdentity();
2882 synchronized(mWindowMap) {
2883 WindowToken wtoken = mTokenMap.remove(token);
2884 mTokenList.remove(wtoken);
2885 if (wtoken != null) {
2886 boolean delayed = false;
2887 if (!wtoken.hidden) {
2888 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002889
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 final int N = wtoken.windows.size();
2891 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 for (int i=0; i<N; i++) {
2894 WindowState win = wtoken.windows.get(i);
2895
2896 if (win.isAnimating()) {
2897 delayed = true;
2898 }
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 if (win.isVisibleNow()) {
2901 applyAnimationLocked(win,
2902 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 changed = true;
2904 }
2905 }
2906
2907 if (changed) {
2908 mLayoutNeeded = true;
2909 performLayoutAndPlaceSurfacesLocked();
2910 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2911 }
Romain Guy06882f82009-06-10 13:36:04 -07002912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 if (delayed) {
2914 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002915 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2916 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 }
2918 }
Romain Guy06882f82009-06-10 13:36:04 -07002919
Jeff Brownc5ed5912010-07-14 18:48:53 -07002920 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002922 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 }
2924 }
2925 Binder.restoreCallingIdentity(origId);
2926 }
2927
2928 public void addAppToken(int addPos, IApplicationToken token,
2929 int groupId, int requestedOrientation, boolean fullscreen) {
2930 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2931 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002932 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 }
Jeff Brown349703e2010-06-22 01:27:15 -07002934
2935 // Get the dispatching timeout here while we are not holding any locks so that it
2936 // can be cached by the AppWindowToken. The timeout value is used later by the
2937 // input dispatcher in code that does hold locks. If we did not cache the value
2938 // here we would run the chance of introducing a deadlock between the window manager
2939 // (which holds locks while updating the input dispatcher state) and the activity manager
2940 // (which holds locks while querying the application token).
2941 long inputDispatchingTimeoutNanos;
2942 try {
2943 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2944 } catch (RemoteException ex) {
2945 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2946 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2947 }
Romain Guy06882f82009-06-10 13:36:04 -07002948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 synchronized(mWindowMap) {
2950 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2951 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002952 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 return;
2954 }
2955 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002956 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 wtoken.groupId = groupId;
2958 wtoken.appFullscreen = fullscreen;
2959 wtoken.requestedOrientation = requestedOrientation;
2960 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002961 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 mTokenMap.put(token.asBinder(), wtoken);
2963 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 // Application tokens start out hidden.
2966 wtoken.hidden = true;
2967 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 //dump();
2970 }
2971 }
Romain Guy06882f82009-06-10 13:36:04 -07002972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 public void setAppGroupId(IBinder token, int groupId) {
2974 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2975 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002976 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 }
2978
2979 synchronized(mWindowMap) {
2980 AppWindowToken wtoken = findAppWindowToken(token);
2981 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002982 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 return;
2984 }
2985 wtoken.groupId = groupId;
2986 }
2987 }
Romain Guy06882f82009-06-10 13:36:04 -07002988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 public int getOrientationFromWindowsLocked() {
2990 int pos = mWindows.size() - 1;
2991 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07002992 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 pos--;
2994 if (wtoken.mAppToken != null) {
2995 // We hit an application window. so the orientation will be determined by the
2996 // app window. No point in continuing further.
2997 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2998 }
Christopher Tateb696aee2010-04-02 19:08:30 -07002999 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 continue;
3001 }
3002 int req = wtoken.mAttrs.screenOrientation;
3003 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3004 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3005 continue;
3006 } else {
3007 return req;
3008 }
3009 }
3010 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3011 }
Romain Guy06882f82009-06-10 13:36:04 -07003012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003014 int pos = mAppTokens.size() - 1;
3015 int curGroup = 0;
3016 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3017 boolean findingBehind = false;
3018 boolean haveGroup = false;
3019 boolean lastFullscreen = false;
3020 while (pos >= 0) {
3021 AppWindowToken wtoken = mAppTokens.get(pos);
3022 pos--;
3023 // if we're about to tear down this window and not seek for
3024 // the behind activity, don't use it for orientation
3025 if (!findingBehind
3026 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3027 continue;
3028 }
3029
3030 if (!haveGroup) {
3031 // We ignore any hidden applications on the top.
3032 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003033 continue;
3034 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003035 haveGroup = true;
3036 curGroup = wtoken.groupId;
3037 lastOrientation = wtoken.requestedOrientation;
3038 } else if (curGroup != wtoken.groupId) {
3039 // If we have hit a new application group, and the bottom
3040 // of the previous group didn't explicitly say to use
3041 // the orientation behind it, and the last app was
3042 // full screen, then we'll stick with the
3043 // user's orientation.
3044 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3045 && lastFullscreen) {
3046 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003049 int or = wtoken.requestedOrientation;
3050 // If this application is fullscreen, and didn't explicitly say
3051 // to use the orientation behind it, then just take whatever
3052 // orientation it has and ignores whatever is under it.
3053 lastFullscreen = wtoken.appFullscreen;
3054 if (lastFullscreen
3055 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3056 return or;
3057 }
3058 // If this application has requested an explicit orientation,
3059 // then use it.
3060 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3061 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3062 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3063 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3064 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3065 return or;
3066 }
3067 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3068 }
3069 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 }
Romain Guy06882f82009-06-10 13:36:04 -07003071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003073 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003074 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3075 "updateOrientationFromAppTokens()")) {
3076 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3077 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003078
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003079 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003081
3082 synchronized(mWindowMap) {
3083 if (updateOrientationFromAppTokensLocked()) {
3084 if (freezeThisOneIfNeeded != null) {
3085 AppWindowToken wtoken = findAppWindowToken(
3086 freezeThisOneIfNeeded);
3087 if (wtoken != null) {
3088 startAppFreezingScreenLocked(wtoken,
3089 ActivityInfo.CONFIG_ORIENTATION);
3090 }
3091 }
3092 config = computeNewConfigurationLocked();
3093
3094 } else if (currentConfig != null) {
3095 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003096 // state mismatches the activity manager's, update it,
3097 // disregarding font scale, which should remain set to
3098 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003099 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003100 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003101 if (computeNewConfigurationLocked(mTempConfiguration)) {
3102 if (currentConfig.diff(mTempConfiguration) != 0) {
3103 mWaitingForConfig = true;
3104 mLayoutNeeded = true;
3105 startFreezingDisplayLocked();
3106 config = new Configuration(mTempConfiguration);
3107 }
3108 }
3109 }
3110 }
3111
Dianne Hackborncfaef692009-06-15 14:24:44 -07003112 Binder.restoreCallingIdentity(ident);
3113 return config;
3114 }
3115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003116 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003117 * Determine the new desired orientation of the display, returning
3118 * a non-null new Configuration if it has changed from the current
3119 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3120 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3121 * SCREEN. This will typically be done for you if you call
3122 * sendNewConfiguration().
3123 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003124 * The orientation is computed from non-application windows first. If none of
3125 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003126 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003127 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3128 * android.os.IBinder)
3129 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003130 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003131 if (mDisplayFrozen) {
3132 // If the display is frozen, some activities may be in the middle
3133 // of restarting, and thus have removed their old window. If the
3134 // window has the flag to hide the lock screen, then the lock screen
3135 // can re-appear and inflict its own orientation on us. Keep the
3136 // orientation stable until this all settles down.
3137 return false;
3138 }
3139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 long ident = Binder.clearCallingIdentity();
3142 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003143 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 mForcedAppOrientation = req;
3147 //send a message to Policy indicating orientation change to take
3148 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003149 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003150 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3151 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3152 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 }
3154 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003155
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003156 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003157 } finally {
3158 Binder.restoreCallingIdentity(ident);
3159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 }
Romain Guy06882f82009-06-10 13:36:04 -07003161
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003162 int computeForcedAppOrientationLocked() {
3163 int req = getOrientationFromWindowsLocked();
3164 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3165 req = getOrientationFromAppTokensLocked();
3166 }
3167 return req;
3168 }
Romain Guy06882f82009-06-10 13:36:04 -07003169
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003170 public void setNewConfiguration(Configuration config) {
3171 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3172 "setNewConfiguration()")) {
3173 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3174 }
3175
3176 synchronized(mWindowMap) {
3177 mCurConfiguration = new Configuration(config);
3178 mWaitingForConfig = false;
3179 performLayoutAndPlaceSurfacesLocked();
3180 }
3181 }
3182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3184 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3185 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003186 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 }
Romain Guy06882f82009-06-10 13:36:04 -07003188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 synchronized(mWindowMap) {
3190 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3191 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003192 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 return;
3194 }
Romain Guy06882f82009-06-10 13:36:04 -07003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 wtoken.requestedOrientation = requestedOrientation;
3197 }
3198 }
Romain Guy06882f82009-06-10 13:36:04 -07003199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 public int getAppOrientation(IApplicationToken token) {
3201 synchronized(mWindowMap) {
3202 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3203 if (wtoken == null) {
3204 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3205 }
Romain Guy06882f82009-06-10 13:36:04 -07003206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 return wtoken.requestedOrientation;
3208 }
3209 }
Romain Guy06882f82009-06-10 13:36:04 -07003210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3212 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3213 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003214 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 }
3216
3217 synchronized(mWindowMap) {
3218 boolean changed = false;
3219 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003220 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 changed = mFocusedApp != null;
3222 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003223 if (changed) {
3224 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 } else {
3227 AppWindowToken newFocus = findAppWindowToken(token);
3228 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003229 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 return;
3231 }
3232 changed = mFocusedApp != newFocus;
3233 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003234 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003235 if (changed) {
3236 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 }
3239
3240 if (moveFocusNow && changed) {
3241 final long origId = Binder.clearCallingIdentity();
3242 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3243 Binder.restoreCallingIdentity(origId);
3244 }
3245 }
3246 }
3247
3248 public void prepareAppTransition(int transit) {
3249 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3250 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003251 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 }
Romain Guy06882f82009-06-10 13:36:04 -07003253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003255 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 TAG, "Prepare app transition: transit=" + transit
3257 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003258 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003259 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3260 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003262 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3263 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3264 // Opening a new task always supersedes a close for the anim.
3265 mNextAppTransition = transit;
3266 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3267 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3268 // Opening a new activity always supersedes a close for the anim.
3269 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 }
3271 mAppTransitionReady = false;
3272 mAppTransitionTimeout = false;
3273 mStartingIconInTransition = false;
3274 mSkipAppTransitionAnimation = false;
3275 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3276 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3277 5000);
3278 }
3279 }
3280 }
3281
3282 public int getPendingAppTransition() {
3283 return mNextAppTransition;
3284 }
Romain Guy06882f82009-06-10 13:36:04 -07003285
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003286 public void overridePendingAppTransition(String packageName,
3287 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003288 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003289 mNextAppTransitionPackage = packageName;
3290 mNextAppTransitionEnter = enterAnim;
3291 mNextAppTransitionExit = exitAnim;
3292 }
3293 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 public void executeAppTransition() {
3296 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3297 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003298 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 }
Romain Guy06882f82009-06-10 13:36:04 -07003300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003302 if (DEBUG_APP_TRANSITIONS) {
3303 RuntimeException e = new RuntimeException("here");
3304 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003305 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003306 + mNextAppTransition, e);
3307 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003308 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 mAppTransitionReady = true;
3310 final long origId = Binder.clearCallingIdentity();
3311 performLayoutAndPlaceSurfacesLocked();
3312 Binder.restoreCallingIdentity(origId);
3313 }
3314 }
3315 }
3316
3317 public void setAppStartingWindow(IBinder token, String pkg,
3318 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3319 IBinder transferFrom, boolean createIfNeeded) {
3320 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3321 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003322 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 }
3324
3325 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003326 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3328 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 AppWindowToken wtoken = findAppWindowToken(token);
3331 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003332 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003333 return;
3334 }
3335
3336 // If the display is frozen, we won't do anything until the
3337 // actual window is displayed so there is no reason to put in
3338 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003339 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 return;
3341 }
Romain Guy06882f82009-06-10 13:36:04 -07003342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 if (wtoken.startingData != null) {
3344 return;
3345 }
Romain Guy06882f82009-06-10 13:36:04 -07003346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 if (transferFrom != null) {
3348 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3349 if (ttoken != null) {
3350 WindowState startingWindow = ttoken.startingWindow;
3351 if (startingWindow != null) {
3352 if (mStartingIconInTransition) {
3353 // In this case, the starting icon has already
3354 // been displayed, so start letting windows get
3355 // shown immediately without any more transitions.
3356 mSkipAppTransitionAnimation = true;
3357 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003358 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 "Moving existing starting from " + ttoken
3360 + " to " + wtoken);
3361 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 // Transfer the starting window over to the new
3364 // token.
3365 wtoken.startingData = ttoken.startingData;
3366 wtoken.startingView = ttoken.startingView;
3367 wtoken.startingWindow = startingWindow;
3368 ttoken.startingData = null;
3369 ttoken.startingView = null;
3370 ttoken.startingWindow = null;
3371 ttoken.startingMoved = true;
3372 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003373 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003375 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003376 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003378 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 ttoken.windows.remove(startingWindow);
3380 ttoken.allAppWindows.remove(startingWindow);
3381 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 // Propagate other interesting state between the
3384 // tokens. If the old token is displayed, we should
3385 // immediately force the new one to be displayed. If
3386 // it is animating, we need to move that animation to
3387 // the new one.
3388 if (ttoken.allDrawn) {
3389 wtoken.allDrawn = true;
3390 }
3391 if (ttoken.firstWindowDrawn) {
3392 wtoken.firstWindowDrawn = true;
3393 }
3394 if (!ttoken.hidden) {
3395 wtoken.hidden = false;
3396 wtoken.hiddenRequested = false;
3397 wtoken.willBeHidden = false;
3398 }
3399 if (wtoken.clientHidden != ttoken.clientHidden) {
3400 wtoken.clientHidden = ttoken.clientHidden;
3401 wtoken.sendAppVisibilityToClients();
3402 }
3403 if (ttoken.animation != null) {
3404 wtoken.animation = ttoken.animation;
3405 wtoken.animating = ttoken.animating;
3406 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3407 ttoken.animation = null;
3408 ttoken.animLayerAdjustment = 0;
3409 wtoken.updateLayers();
3410 ttoken.updateLayers();
3411 }
Romain Guy06882f82009-06-10 13:36:04 -07003412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 mLayoutNeeded = true;
3415 performLayoutAndPlaceSurfacesLocked();
3416 Binder.restoreCallingIdentity(origId);
3417 return;
3418 } else if (ttoken.startingData != null) {
3419 // The previous app was getting ready to show a
3420 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003421 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 "Moving pending starting from " + ttoken
3423 + " to " + wtoken);
3424 wtoken.startingData = ttoken.startingData;
3425 ttoken.startingData = null;
3426 ttoken.startingMoved = true;
3427 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3428 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3429 // want to process the message ASAP, before any other queued
3430 // messages.
3431 mH.sendMessageAtFrontOfQueue(m);
3432 return;
3433 }
3434 }
3435 }
3436
3437 // There is no existing starting window, and the caller doesn't
3438 // want us to create one, so that's it!
3439 if (!createIfNeeded) {
3440 return;
3441 }
Romain Guy06882f82009-06-10 13:36:04 -07003442
Dianne Hackborn284ac932009-08-28 10:34:25 -07003443 // If this is a translucent or wallpaper window, then don't
3444 // show a starting window -- the current effect (a full-screen
3445 // opaque starting window that fades away to the real contents
3446 // when it is ready) does not work for this.
3447 if (theme != 0) {
3448 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3449 com.android.internal.R.styleable.Window);
3450 if (ent.array.getBoolean(
3451 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3452 return;
3453 }
3454 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003455 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3456 return;
3457 }
3458 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003459 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3460 return;
3461 }
3462 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 mStartingIconInTransition = true;
3465 wtoken.startingData = new StartingData(
3466 pkg, theme, nonLocalizedLabel,
3467 labelRes, icon);
3468 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3469 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3470 // want to process the message ASAP, before any other queued
3471 // messages.
3472 mH.sendMessageAtFrontOfQueue(m);
3473 }
3474 }
3475
3476 public void setAppWillBeHidden(IBinder token) {
3477 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3478 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003479 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 }
3481
3482 AppWindowToken wtoken;
3483
3484 synchronized(mWindowMap) {
3485 wtoken = findAppWindowToken(token);
3486 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003487 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 -08003488 return;
3489 }
3490 wtoken.willBeHidden = true;
3491 }
3492 }
Romain Guy06882f82009-06-10 13:36:04 -07003493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003494 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3495 boolean visible, int transit, boolean performLayout) {
3496 boolean delayed = false;
3497
3498 if (wtoken.clientHidden == visible) {
3499 wtoken.clientHidden = !visible;
3500 wtoken.sendAppVisibilityToClients();
3501 }
Romain Guy06882f82009-06-10 13:36:04 -07003502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 wtoken.willBeHidden = false;
3504 if (wtoken.hidden == visible) {
3505 final int N = wtoken.allAppWindows.size();
3506 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003507 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3509 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003512
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003513 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 if (wtoken.animation == sDummyAnimation) {
3515 wtoken.animation = null;
3516 }
3517 applyAnimationLocked(wtoken, lp, transit, visible);
3518 changed = true;
3519 if (wtoken.animation != null) {
3520 delayed = runningAppAnimation = true;
3521 }
3522 }
Romain Guy06882f82009-06-10 13:36:04 -07003523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 for (int i=0; i<N; i++) {
3525 WindowState win = wtoken.allAppWindows.get(i);
3526 if (win == wtoken.startingWindow) {
3527 continue;
3528 }
3529
3530 if (win.isAnimating()) {
3531 delayed = true;
3532 }
Romain Guy06882f82009-06-10 13:36:04 -07003533
Joe Onorato8a9b2202010-02-26 18:56:32 -08003534 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 //win.dump(" ");
3536 if (visible) {
3537 if (!win.isVisibleNow()) {
3538 if (!runningAppAnimation) {
3539 applyAnimationLocked(win,
3540 WindowManagerPolicy.TRANSIT_ENTER, true);
3541 }
3542 changed = true;
3543 }
3544 } else if (win.isVisibleNow()) {
3545 if (!runningAppAnimation) {
3546 applyAnimationLocked(win,
3547 WindowManagerPolicy.TRANSIT_EXIT, false);
3548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003549 changed = true;
3550 }
3551 }
3552
3553 wtoken.hidden = wtoken.hiddenRequested = !visible;
3554 if (!visible) {
3555 unsetAppFreezingScreenLocked(wtoken, true, true);
3556 } else {
3557 // If we are being set visible, and the starting window is
3558 // not yet displayed, then make sure it doesn't get displayed.
3559 WindowState swin = wtoken.startingWindow;
3560 if (swin != null && (swin.mDrawPending
3561 || swin.mCommitDrawPending)) {
3562 swin.mPolicyVisibility = false;
3563 swin.mPolicyVisibilityAfterAnim = false;
3564 }
3565 }
Romain Guy06882f82009-06-10 13:36:04 -07003566
Joe Onorato8a9b2202010-02-26 18:56:32 -08003567 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003568 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3569 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003570
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003571 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003573 if (performLayout) {
3574 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3575 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003576 } else {
3577 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 }
3580 }
3581
3582 if (wtoken.animation != null) {
3583 delayed = true;
3584 }
Romain Guy06882f82009-06-10 13:36:04 -07003585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 return delayed;
3587 }
3588
3589 public void setAppVisibility(IBinder token, boolean visible) {
3590 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3591 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003592 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 }
3594
3595 AppWindowToken wtoken;
3596
3597 synchronized(mWindowMap) {
3598 wtoken = findAppWindowToken(token);
3599 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003600 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 return;
3602 }
3603
3604 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003605 RuntimeException e = null;
3606 if (!HIDE_STACK_CRAWLS) {
3607 e = new RuntimeException();
3608 e.fillInStackTrace();
3609 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003610 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 + "): mNextAppTransition=" + mNextAppTransition
3612 + " hidden=" + wtoken.hidden
3613 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3614 }
Romain Guy06882f82009-06-10 13:36:04 -07003615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 // If we are preparing an app transition, then delay changing
3617 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003618 if (!mDisplayFrozen && mPolicy.isScreenOn()
3619 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 // Already in requested state, don't do anything more.
3621 if (wtoken.hiddenRequested != visible) {
3622 return;
3623 }
3624 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003625
Joe Onorato8a9b2202010-02-26 18:56:32 -08003626 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 TAG, "Setting dummy animation on: " + wtoken);
3628 wtoken.setDummyAnimation();
3629 mOpeningApps.remove(wtoken);
3630 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003631 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 wtoken.inPendingTransaction = true;
3633 if (visible) {
3634 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 wtoken.startingDisplayed = false;
3636 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003637
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003638 // If the token is currently hidden (should be the
3639 // common case), then we need to set up to wait for
3640 // its windows to be ready.
3641 if (wtoken.hidden) {
3642 wtoken.allDrawn = false;
3643 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003644
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003645 if (wtoken.clientHidden) {
3646 // In the case where we are making an app visible
3647 // but holding off for a transition, we still need
3648 // to tell the client to make its windows visible so
3649 // they get drawn. Otherwise, we will wait on
3650 // performing the transition until all windows have
3651 // been drawn, they never will be, and we are sad.
3652 wtoken.clientHidden = false;
3653 wtoken.sendAppVisibilityToClients();
3654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 }
3656 } else {
3657 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003658
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003659 // If the token is currently visible (should be the
3660 // common case), then set up to wait for it to be hidden.
3661 if (!wtoken.hidden) {
3662 wtoken.waitingToHide = true;
3663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 }
3665 return;
3666 }
Romain Guy06882f82009-06-10 13:36:04 -07003667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003669 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 wtoken.updateReportedVisibilityLocked();
3671 Binder.restoreCallingIdentity(origId);
3672 }
3673 }
3674
3675 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3676 boolean unfreezeSurfaceNow, boolean force) {
3677 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003678 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 + " force=" + force);
3680 final int N = wtoken.allAppWindows.size();
3681 boolean unfrozeWindows = false;
3682 for (int i=0; i<N; i++) {
3683 WindowState w = wtoken.allAppWindows.get(i);
3684 if (w.mAppFreezing) {
3685 w.mAppFreezing = false;
3686 if (w.mSurface != null && !w.mOrientationChanging) {
3687 w.mOrientationChanging = true;
3688 }
3689 unfrozeWindows = true;
3690 }
3691 }
3692 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003693 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 wtoken.freezingScreen = false;
3695 mAppsFreezingScreen--;
3696 }
3697 if (unfreezeSurfaceNow) {
3698 if (unfrozeWindows) {
3699 mLayoutNeeded = true;
3700 performLayoutAndPlaceSurfacesLocked();
3701 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003702 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 }
3704 }
3705 }
Romain Guy06882f82009-06-10 13:36:04 -07003706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3708 int configChanges) {
3709 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003710 RuntimeException e = null;
3711 if (!HIDE_STACK_CRAWLS) {
3712 e = new RuntimeException();
3713 e.fillInStackTrace();
3714 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003715 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003716 + ": hidden=" + wtoken.hidden + " freezing="
3717 + wtoken.freezingScreen, e);
3718 }
3719 if (!wtoken.hiddenRequested) {
3720 if (!wtoken.freezingScreen) {
3721 wtoken.freezingScreen = true;
3722 mAppsFreezingScreen++;
3723 if (mAppsFreezingScreen == 1) {
3724 startFreezingDisplayLocked();
3725 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3726 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3727 5000);
3728 }
3729 }
3730 final int N = wtoken.allAppWindows.size();
3731 for (int i=0; i<N; i++) {
3732 WindowState w = wtoken.allAppWindows.get(i);
3733 w.mAppFreezing = true;
3734 }
3735 }
3736 }
Romain Guy06882f82009-06-10 13:36:04 -07003737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738 public void startAppFreezingScreen(IBinder token, int configChanges) {
3739 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3740 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003741 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 }
3743
3744 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003745 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003746 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 return;
3748 }
Romain Guy06882f82009-06-10 13:36:04 -07003749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 AppWindowToken wtoken = findAppWindowToken(token);
3751 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003752 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 return;
3754 }
3755 final long origId = Binder.clearCallingIdentity();
3756 startAppFreezingScreenLocked(wtoken, configChanges);
3757 Binder.restoreCallingIdentity(origId);
3758 }
3759 }
Romain Guy06882f82009-06-10 13:36:04 -07003760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 public void stopAppFreezingScreen(IBinder token, boolean force) {
3762 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3763 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003764 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765 }
3766
3767 synchronized(mWindowMap) {
3768 AppWindowToken wtoken = findAppWindowToken(token);
3769 if (wtoken == null || wtoken.appToken == null) {
3770 return;
3771 }
3772 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003773 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3775 unsetAppFreezingScreenLocked(wtoken, true, force);
3776 Binder.restoreCallingIdentity(origId);
3777 }
3778 }
Romain Guy06882f82009-06-10 13:36:04 -07003779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 public void removeAppToken(IBinder token) {
3781 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3782 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003783 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784 }
3785
3786 AppWindowToken wtoken = null;
3787 AppWindowToken startingToken = null;
3788 boolean delayed = false;
3789
3790 final long origId = Binder.clearCallingIdentity();
3791 synchronized(mWindowMap) {
3792 WindowToken basewtoken = mTokenMap.remove(token);
3793 mTokenList.remove(basewtoken);
3794 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003795 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003796 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 wtoken.inPendingTransaction = false;
3798 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003799 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 if (mClosingApps.contains(wtoken)) {
3801 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003802 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003804 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 delayed = true;
3806 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003807 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 TAG, "Removing app " + wtoken + " delayed=" + delayed
3809 + " animation=" + wtoken.animation
3810 + " animating=" + wtoken.animating);
3811 if (delayed) {
3812 // set the token aside because it has an active animation to be finished
3813 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003814 } else {
3815 // Make sure there is no animation running on this token,
3816 // so any windows associated with it will be removed as
3817 // soon as their animations are complete
3818 wtoken.animation = null;
3819 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 }
3821 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003822 if (mLastEnterAnimToken == wtoken) {
3823 mLastEnterAnimToken = null;
3824 mLastEnterAnimParams = null;
3825 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 wtoken.removed = true;
3827 if (wtoken.startingData != null) {
3828 startingToken = wtoken;
3829 }
3830 unsetAppFreezingScreenLocked(wtoken, true, true);
3831 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003832 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 mFocusedApp = null;
3834 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003835 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 }
3837 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003838 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 }
Romain Guy06882f82009-06-10 13:36:04 -07003840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 if (!delayed && wtoken != null) {
3842 wtoken.updateReportedVisibilityLocked();
3843 }
3844 }
3845 Binder.restoreCallingIdentity(origId);
3846
3847 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003848 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003849 + startingToken + ": app token removed");
3850 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3851 mH.sendMessage(m);
3852 }
3853 }
3854
3855 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3856 final int NW = token.windows.size();
3857 for (int i=0; i<NW; i++) {
3858 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003859 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003861 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 int j = win.mChildWindows.size();
3863 while (j > 0) {
3864 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003865 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003866 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003867 "Tmp removing child window " + cwin);
3868 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 }
3870 }
3871 return NW > 0;
3872 }
3873
3874 void dumpAppTokensLocked() {
3875 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003876 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003877 }
3878 }
Romain Guy06882f82009-06-10 13:36:04 -07003879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 void dumpWindowsLocked() {
3881 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003882 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 }
3884 }
Romain Guy06882f82009-06-10 13:36:04 -07003885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 private int findWindowOffsetLocked(int tokenPos) {
3887 final int NW = mWindows.size();
3888
3889 if (tokenPos >= mAppTokens.size()) {
3890 int i = NW;
3891 while (i > 0) {
3892 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003893 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003894 if (win.getAppToken() != null) {
3895 return i+1;
3896 }
3897 }
3898 }
3899
3900 while (tokenPos > 0) {
3901 // Find the first app token below the new position that has
3902 // a window displayed.
3903 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003904 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003905 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003906 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003907 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003908 "Skipping token -- currently sending to bottom");
3909 tokenPos--;
3910 continue;
3911 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003912 int i = wtoken.windows.size();
3913 while (i > 0) {
3914 i--;
3915 WindowState win = wtoken.windows.get(i);
3916 int j = win.mChildWindows.size();
3917 while (j > 0) {
3918 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003919 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003920 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 for (int pos=NW-1; pos>=0; pos--) {
3922 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003923 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003924 "Found child win @" + (pos+1));
3925 return pos+1;
3926 }
3927 }
3928 }
3929 }
3930 for (int pos=NW-1; pos>=0; pos--) {
3931 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003932 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 return pos+1;
3934 }
3935 }
3936 }
3937 tokenPos--;
3938 }
3939
3940 return 0;
3941 }
3942
3943 private final int reAddWindowLocked(int index, WindowState win) {
3944 final int NCW = win.mChildWindows.size();
3945 boolean added = false;
3946 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003947 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003949 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003950 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003951 mWindows.add(index, win);
3952 index++;
3953 added = true;
3954 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003955 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003956 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 mWindows.add(index, cwin);
3958 index++;
3959 }
3960 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003961 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003962 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003963 mWindows.add(index, win);
3964 index++;
3965 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003966 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 return index;
3968 }
Romain Guy06882f82009-06-10 13:36:04 -07003969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3971 final int NW = token.windows.size();
3972 for (int i=0; i<NW; i++) {
3973 index = reAddWindowLocked(index, token.windows.get(i));
3974 }
3975 return index;
3976 }
3977
3978 public void moveAppToken(int index, IBinder token) {
3979 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3980 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003981 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003982 }
3983
3984 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003985 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 if (DEBUG_REORDER) dumpAppTokensLocked();
3987 final AppWindowToken wtoken = findAppWindowToken(token);
3988 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003989 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003990 + token + " (" + wtoken + ")");
3991 return;
3992 }
3993 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003994 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003998 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 if (DEBUG_REORDER) dumpWindowsLocked();
4000 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004001 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 if (DEBUG_REORDER) dumpWindowsLocked();
4003 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 if (DEBUG_REORDER) dumpWindowsLocked();
4006 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007 mLayoutNeeded = true;
4008 performLayoutAndPlaceSurfacesLocked();
4009 }
4010 Binder.restoreCallingIdentity(origId);
4011 }
4012 }
4013
4014 private void removeAppTokensLocked(List<IBinder> tokens) {
4015 // XXX This should be done more efficiently!
4016 // (take advantage of the fact that both lists should be
4017 // ordered in the same way.)
4018 int N = tokens.size();
4019 for (int i=0; i<N; i++) {
4020 IBinder token = tokens.get(i);
4021 final AppWindowToken wtoken = findAppWindowToken(token);
4022 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004023 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004024 + token + " (" + wtoken + ")");
4025 i--;
4026 N--;
4027 }
4028 }
4029 }
4030
Dianne Hackborna8f60182009-09-01 19:01:50 -07004031 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4032 boolean updateFocusAndLayout) {
4033 // First remove all of the windows from the list.
4034 tmpRemoveAppWindowsLocked(wtoken);
4035
4036 // Where to start adding?
4037 int pos = findWindowOffsetLocked(tokenPos);
4038
4039 // And now add them back at the correct place.
4040 pos = reAddAppWindowsLocked(pos, wtoken);
4041
4042 if (updateFocusAndLayout) {
4043 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4044 assignLayersLocked();
4045 }
4046 mLayoutNeeded = true;
4047 performLayoutAndPlaceSurfacesLocked();
4048 }
4049 }
4050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004051 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4052 // First remove all of the windows from the list.
4053 final int N = tokens.size();
4054 int i;
4055 for (i=0; i<N; i++) {
4056 WindowToken token = mTokenMap.get(tokens.get(i));
4057 if (token != null) {
4058 tmpRemoveAppWindowsLocked(token);
4059 }
4060 }
4061
4062 // Where to start adding?
4063 int pos = findWindowOffsetLocked(tokenPos);
4064
4065 // And now add them back at the correct place.
4066 for (i=0; i<N; i++) {
4067 WindowToken token = mTokenMap.get(tokens.get(i));
4068 if (token != null) {
4069 pos = reAddAppWindowsLocked(pos, token);
4070 }
4071 }
4072
Dianne Hackborna8f60182009-09-01 19:01:50 -07004073 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4074 assignLayersLocked();
4075 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 mLayoutNeeded = true;
4077 performLayoutAndPlaceSurfacesLocked();
4078
4079 //dump();
4080 }
4081
4082 public void moveAppTokensToTop(List<IBinder> tokens) {
4083 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4084 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004085 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 }
4087
4088 final long origId = Binder.clearCallingIdentity();
4089 synchronized(mWindowMap) {
4090 removeAppTokensLocked(tokens);
4091 final int N = tokens.size();
4092 for (int i=0; i<N; i++) {
4093 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4094 if (wt != null) {
4095 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004096 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004097 mToTopApps.remove(wt);
4098 mToBottomApps.remove(wt);
4099 mToTopApps.add(wt);
4100 wt.sendingToBottom = false;
4101 wt.sendingToTop = true;
4102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 }
4104 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004105
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004106 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004107 moveAppWindowsLocked(tokens, mAppTokens.size());
4108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004109 }
4110 Binder.restoreCallingIdentity(origId);
4111 }
4112
4113 public void moveAppTokensToBottom(List<IBinder> tokens) {
4114 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4115 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004116 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 }
4118
4119 final long origId = Binder.clearCallingIdentity();
4120 synchronized(mWindowMap) {
4121 removeAppTokensLocked(tokens);
4122 final int N = tokens.size();
4123 int pos = 0;
4124 for (int i=0; i<N; i++) {
4125 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4126 if (wt != null) {
4127 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004128 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004129 mToTopApps.remove(wt);
4130 mToBottomApps.remove(wt);
4131 mToBottomApps.add(i, wt);
4132 wt.sendingToTop = false;
4133 wt.sendingToBottom = true;
4134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 pos++;
4136 }
4137 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004138
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004139 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004140 moveAppWindowsLocked(tokens, 0);
4141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142 }
4143 Binder.restoreCallingIdentity(origId);
4144 }
4145
4146 // -------------------------------------------------------------
4147 // Misc IWindowSession methods
4148 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004149
Jim Miller284b62e2010-06-08 14:27:42 -07004150 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004151 {
Jim Miller284b62e2010-06-08 14:27:42 -07004152 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4153 // called before DevicePolicyManagerService has started.
4154 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4155 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4156 Context.DEVICE_POLICY_SERVICE);
4157 if (dpm != null) {
4158 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4159 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4160 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4161 }
Jim Millerd6b57052010-06-07 17:52:42 -07004162 }
Jim Miller284b62e2010-06-08 14:27:42 -07004163 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004164 }
4165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004167 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 != PackageManager.PERMISSION_GRANTED) {
4169 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4170 }
Jim Millerd6b57052010-06-07 17:52:42 -07004171
Jim Miller284b62e2010-06-08 14:27:42 -07004172 synchronized (mKeyguardTokenWatcher) {
4173 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 }
4176
4177 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004178 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004179 != PackageManager.PERMISSION_GRANTED) {
4180 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182
Jim Miller284b62e2010-06-08 14:27:42 -07004183 synchronized (mKeyguardTokenWatcher) {
4184 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004185
Jim Miller284b62e2010-06-08 14:27:42 -07004186 if (!mKeyguardTokenWatcher.isAcquired()) {
4187 // If we are the last one to reenable the keyguard wait until
4188 // we have actually finished reenabling until returning.
4189 // It is possible that reenableKeyguard() can be called before
4190 // the previous disableKeyguard() is handled, in which case
4191 // neither mKeyguardTokenWatcher.acquired() or released() would
4192 // be called. In that case mKeyguardDisabled will be false here
4193 // and we have nothing to wait for.
4194 while (mKeyguardDisabled) {
4195 try {
4196 mKeyguardTokenWatcher.wait();
4197 } catch (InterruptedException e) {
4198 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004199 }
4200 }
4201 }
4202 }
4203 }
4204
4205 /**
4206 * @see android.app.KeyguardManager#exitKeyguardSecurely
4207 */
4208 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004209 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 != PackageManager.PERMISSION_GRANTED) {
4211 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4212 }
4213 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4214 public void onKeyguardExitResult(boolean success) {
4215 try {
4216 callback.onKeyguardExitResult(success);
4217 } catch (RemoteException e) {
4218 // Client has died, we don't care.
4219 }
4220 }
4221 });
4222 }
4223
4224 public boolean inKeyguardRestrictedInputMode() {
4225 return mPolicy.inKeyguardRestrictedKeyInputMode();
4226 }
Romain Guy06882f82009-06-10 13:36:04 -07004227
Dianne Hackbornffa42482009-09-23 22:20:11 -07004228 public void closeSystemDialogs(String reason) {
4229 synchronized(mWindowMap) {
4230 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004231 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004232 if (w.mSurface != null) {
4233 try {
4234 w.mClient.closeSystemDialogs(reason);
4235 } catch (RemoteException e) {
4236 }
4237 }
4238 }
4239 }
4240 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004242 static float fixScale(float scale) {
4243 if (scale < 0) scale = 0;
4244 else if (scale > 20) scale = 20;
4245 return Math.abs(scale);
4246 }
Romain Guy06882f82009-06-10 13:36:04 -07004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 public void setAnimationScale(int which, float scale) {
4249 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4250 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004251 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 }
4253
4254 if (scale < 0) scale = 0;
4255 else if (scale > 20) scale = 20;
4256 scale = Math.abs(scale);
4257 switch (which) {
4258 case 0: mWindowAnimationScale = fixScale(scale); break;
4259 case 1: mTransitionAnimationScale = fixScale(scale); break;
4260 }
Romain Guy06882f82009-06-10 13:36:04 -07004261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 // Persist setting
4263 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4264 }
Romain Guy06882f82009-06-10 13:36:04 -07004265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 public void setAnimationScales(float[] scales) {
4267 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4268 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004269 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004270 }
4271
4272 if (scales != null) {
4273 if (scales.length >= 1) {
4274 mWindowAnimationScale = fixScale(scales[0]);
4275 }
4276 if (scales.length >= 2) {
4277 mTransitionAnimationScale = fixScale(scales[1]);
4278 }
4279 }
Romain Guy06882f82009-06-10 13:36:04 -07004280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004281 // Persist setting
4282 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4283 }
Romain Guy06882f82009-06-10 13:36:04 -07004284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 public float getAnimationScale(int which) {
4286 switch (which) {
4287 case 0: return mWindowAnimationScale;
4288 case 1: return mTransitionAnimationScale;
4289 }
4290 return 0;
4291 }
Romain Guy06882f82009-06-10 13:36:04 -07004292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 public float[] getAnimationScales() {
4294 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4295 }
Romain Guy06882f82009-06-10 13:36:04 -07004296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 public int getSwitchState(int sw) {
4298 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4299 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004300 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004302 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 }
Romain Guy06882f82009-06-10 13:36:04 -07004304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004305 public int getSwitchStateForDevice(int devid, int sw) {
4306 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4307 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004308 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004310 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 }
Romain Guy06882f82009-06-10 13:36:04 -07004312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 public int getScancodeState(int sw) {
4314 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4315 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004316 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004318 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 }
Romain Guy06882f82009-06-10 13:36:04 -07004320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 public int getScancodeStateForDevice(int devid, int sw) {
4322 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4323 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004324 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004326 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 }
Romain Guy06882f82009-06-10 13:36:04 -07004328
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004329 public int getTrackballScancodeState(int sw) {
4330 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4331 "getTrackballScancodeState()")) {
4332 throw new SecurityException("Requires READ_INPUT_STATE permission");
4333 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004334 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004335 }
4336
4337 public int getDPadScancodeState(int sw) {
4338 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4339 "getDPadScancodeState()")) {
4340 throw new SecurityException("Requires READ_INPUT_STATE permission");
4341 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004342 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004343 }
4344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 public int getKeycodeState(int sw) {
4346 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4347 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004348 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004350 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 }
Romain Guy06882f82009-06-10 13:36:04 -07004352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004353 public int getKeycodeStateForDevice(int devid, int sw) {
4354 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4355 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004356 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004358 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 }
Romain Guy06882f82009-06-10 13:36:04 -07004360
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004361 public int getTrackballKeycodeState(int sw) {
4362 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4363 "getTrackballKeycodeState()")) {
4364 throw new SecurityException("Requires READ_INPUT_STATE permission");
4365 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004366 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004367 }
4368
4369 public int getDPadKeycodeState(int sw) {
4370 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4371 "getDPadKeycodeState()")) {
4372 throw new SecurityException("Requires READ_INPUT_STATE permission");
4373 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004374 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004375 }
4376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004377 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004378 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379 }
Romain Guy06882f82009-06-10 13:36:04 -07004380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 public void enableScreenAfterBoot() {
4382 synchronized(mWindowMap) {
4383 if (mSystemBooted) {
4384 return;
4385 }
4386 mSystemBooted = true;
4387 }
Romain Guy06882f82009-06-10 13:36:04 -07004388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 performEnableScreen();
4390 }
Romain Guy06882f82009-06-10 13:36:04 -07004391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004392 public void enableScreenIfNeededLocked() {
4393 if (mDisplayEnabled) {
4394 return;
4395 }
4396 if (!mSystemBooted) {
4397 return;
4398 }
4399 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4400 }
Romain Guy06882f82009-06-10 13:36:04 -07004401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004402 public void performEnableScreen() {
4403 synchronized(mWindowMap) {
4404 if (mDisplayEnabled) {
4405 return;
4406 }
4407 if (!mSystemBooted) {
4408 return;
4409 }
Romain Guy06882f82009-06-10 13:36:04 -07004410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 // Don't enable the screen until all existing windows
4412 // have been drawn.
4413 final int N = mWindows.size();
4414 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004415 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004416 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 return;
4418 }
4419 }
Romain Guy06882f82009-06-10 13:36:04 -07004420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004421 mDisplayEnabled = true;
4422 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004423 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 StringWriter sw = new StringWriter();
4425 PrintWriter pw = new PrintWriter(sw);
4426 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004427 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 }
4429 try {
4430 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4431 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004432 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 Parcel data = Parcel.obtain();
4434 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4435 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4436 data, null, 0);
4437 data.recycle();
4438 }
4439 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004440 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 }
4442 }
Romain Guy06882f82009-06-10 13:36:04 -07004443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004447 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4448 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
Romain Guy06882f82009-06-10 13:36:04 -07004450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 public void setInTouchMode(boolean mode) {
4452 synchronized(mWindowMap) {
4453 mInTouchMode = mode;
4454 }
4455 }
4456
Romain Guy06882f82009-06-10 13:36:04 -07004457 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004458 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004460 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004461 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004462 }
4463
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004464 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004465 }
Romain Guy06882f82009-06-10 13:36:04 -07004466
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004467 public void setRotationUnchecked(int rotation,
4468 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004469 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 long origId = Binder.clearCallingIdentity();
4473 boolean changed;
4474 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004475 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 }
Romain Guy06882f82009-06-10 13:36:04 -07004477
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004478 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 sendNewConfiguration();
4480 }
Romain Guy06882f82009-06-10 13:36:04 -07004481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 Binder.restoreCallingIdentity(origId);
4483 }
Romain Guy06882f82009-06-10 13:36:04 -07004484
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004485 /**
4486 * Apply a new rotation to the screen, respecting the requests of
4487 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4488 * re-evaluate the desired rotation.
4489 *
4490 * Returns null if the rotation has been changed. In this case YOU
4491 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4492 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004493 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 boolean changed;
4495 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4496 rotation = mRequestedRotation;
4497 } else {
4498 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004499 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004500 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004501 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004502 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004504 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004508 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 "Rotation changed to " + rotation
4510 + " from " + mRotation
4511 + " (forceApp=" + mForcedAppOrientation
4512 + ", req=" + mRequestedRotation + ")");
4513 mRotation = rotation;
4514 mWindowsFreezingScreen = true;
4515 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4516 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4517 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004518 mWaitingForConfig = true;
4519 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004521 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004522 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004524 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 }
4526 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004527 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 if (w.mSurface != null) {
4529 w.mOrientationChanging = true;
4530 }
4531 }
4532 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4533 try {
4534 mRotationWatchers.get(i).onRotationChanged(rotation);
4535 } catch (RemoteException e) {
4536 }
4537 }
4538 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 return changed;
4541 }
Romain Guy06882f82009-06-10 13:36:04 -07004542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 public int getRotation() {
4544 return mRotation;
4545 }
4546
4547 public int watchRotation(IRotationWatcher watcher) {
4548 final IBinder watcherBinder = watcher.asBinder();
4549 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4550 public void binderDied() {
4551 synchronized (mWindowMap) {
4552 for (int i=0; i<mRotationWatchers.size(); i++) {
4553 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004554 IRotationWatcher removed = mRotationWatchers.remove(i);
4555 if (removed != null) {
4556 removed.asBinder().unlinkToDeath(this, 0);
4557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004558 i--;
4559 }
4560 }
4561 }
4562 }
4563 };
Romain Guy06882f82009-06-10 13:36:04 -07004564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 synchronized (mWindowMap) {
4566 try {
4567 watcher.asBinder().linkToDeath(dr, 0);
4568 mRotationWatchers.add(watcher);
4569 } catch (RemoteException e) {
4570 // Client died, no cleanup needed.
4571 }
Romain Guy06882f82009-06-10 13:36:04 -07004572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 return mRotation;
4574 }
4575 }
4576
4577 /**
4578 * Starts the view server on the specified port.
4579 *
4580 * @param port The port to listener to.
4581 *
4582 * @return True if the server was successfully started, false otherwise.
4583 *
4584 * @see com.android.server.ViewServer
4585 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4586 */
4587 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004588 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004589 return false;
4590 }
4591
4592 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4593 return false;
4594 }
4595
4596 if (port < 1024) {
4597 return false;
4598 }
4599
4600 if (mViewServer != null) {
4601 if (!mViewServer.isRunning()) {
4602 try {
4603 return mViewServer.start();
4604 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004605 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004606 }
4607 }
4608 return false;
4609 }
4610
4611 try {
4612 mViewServer = new ViewServer(this, port);
4613 return mViewServer.start();
4614 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004615 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004616 }
4617 return false;
4618 }
4619
Romain Guy06882f82009-06-10 13:36:04 -07004620 private boolean isSystemSecure() {
4621 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4622 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4623 }
4624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004625 /**
4626 * Stops the view server if it exists.
4627 *
4628 * @return True if the server stopped, false if it wasn't started or
4629 * couldn't be stopped.
4630 *
4631 * @see com.android.server.ViewServer
4632 */
4633 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004634 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 return false;
4636 }
4637
4638 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4639 return false;
4640 }
4641
4642 if (mViewServer != null) {
4643 return mViewServer.stop();
4644 }
4645 return false;
4646 }
4647
4648 /**
4649 * Indicates whether the view server is running.
4650 *
4651 * @return True if the server is running, false otherwise.
4652 *
4653 * @see com.android.server.ViewServer
4654 */
4655 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004656 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 return false;
4658 }
4659
4660 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4661 return false;
4662 }
4663
4664 return mViewServer != null && mViewServer.isRunning();
4665 }
4666
4667 /**
4668 * Lists all availble windows in the system. The listing is written in the
4669 * specified Socket's output stream with the following syntax:
4670 * windowHashCodeInHexadecimal windowName
4671 * Each line of the ouput represents a different window.
4672 *
4673 * @param client The remote client to send the listing to.
4674 * @return False if an error occured, true otherwise.
4675 */
4676 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004677 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 return false;
4679 }
4680
4681 boolean result = true;
4682
Jeff Browne33348b2010-07-15 23:54:05 -07004683 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004686 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004687 }
4688
4689 BufferedWriter out = null;
4690
4691 // Any uncaught exception will crash the system process
4692 try {
4693 OutputStream clientStream = client.getOutputStream();
4694 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4695
4696 final int count = windows.length;
4697 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004698 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 out.write(Integer.toHexString(System.identityHashCode(w)));
4700 out.write(' ');
4701 out.append(w.mAttrs.getTitle());
4702 out.write('\n');
4703 }
4704
4705 out.write("DONE.\n");
4706 out.flush();
4707 } catch (Exception e) {
4708 result = false;
4709 } finally {
4710 if (out != null) {
4711 try {
4712 out.close();
4713 } catch (IOException e) {
4714 result = false;
4715 }
4716 }
4717 }
4718
4719 return result;
4720 }
4721
4722 /**
4723 * Sends a command to a target window. The result of the command, if any, will be
4724 * written in the output stream of the specified socket.
4725 *
4726 * The parameters must follow this syntax:
4727 * windowHashcode extra
4728 *
4729 * Where XX is the length in characeters of the windowTitle.
4730 *
4731 * The first parameter is the target window. The window with the specified hashcode
4732 * will be the target. If no target can be found, nothing happens. The extra parameters
4733 * will be delivered to the target window and as parameters to the command itself.
4734 *
4735 * @param client The remote client to sent the result, if any, to.
4736 * @param command The command to execute.
4737 * @param parameters The command parameters.
4738 *
4739 * @return True if the command was successfully delivered, false otherwise. This does
4740 * not indicate whether the command itself was successful.
4741 */
4742 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004743 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004744 return false;
4745 }
4746
4747 boolean success = true;
4748 Parcel data = null;
4749 Parcel reply = null;
4750
4751 // Any uncaught exception will crash the system process
4752 try {
4753 // Find the hashcode of the window
4754 int index = parameters.indexOf(' ');
4755 if (index == -1) {
4756 index = parameters.length();
4757 }
4758 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004759 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004760
4761 // Extract the command's parameter after the window description
4762 if (index < parameters.length()) {
4763 parameters = parameters.substring(index + 1);
4764 } else {
4765 parameters = "";
4766 }
4767
4768 final WindowManagerService.WindowState window = findWindow(hashCode);
4769 if (window == null) {
4770 return false;
4771 }
4772
4773 data = Parcel.obtain();
4774 data.writeInterfaceToken("android.view.IWindow");
4775 data.writeString(command);
4776 data.writeString(parameters);
4777 data.writeInt(1);
4778 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4779
4780 reply = Parcel.obtain();
4781
4782 final IBinder binder = window.mClient.asBinder();
4783 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4784 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4785
4786 reply.readException();
4787
4788 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004789 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 success = false;
4791 } finally {
4792 if (data != null) {
4793 data.recycle();
4794 }
4795 if (reply != null) {
4796 reply.recycle();
4797 }
4798 }
4799
4800 return success;
4801 }
4802
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004803 public void addWindowChangeListener(WindowChangeListener listener) {
4804 synchronized(mWindowMap) {
4805 mWindowChangeListeners.add(listener);
4806 }
4807 }
4808
4809 public void removeWindowChangeListener(WindowChangeListener listener) {
4810 synchronized(mWindowMap) {
4811 mWindowChangeListeners.remove(listener);
4812 }
4813 }
4814
4815 private void notifyWindowsChanged() {
4816 WindowChangeListener[] windowChangeListeners;
4817 synchronized(mWindowMap) {
4818 if(mWindowChangeListeners.isEmpty()) {
4819 return;
4820 }
4821 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4822 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4823 }
4824 int N = windowChangeListeners.length;
4825 for(int i = 0; i < N; i++) {
4826 windowChangeListeners[i].windowsChanged();
4827 }
4828 }
4829
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004830 private void notifyFocusChanged() {
4831 WindowChangeListener[] windowChangeListeners;
4832 synchronized(mWindowMap) {
4833 if(mWindowChangeListeners.isEmpty()) {
4834 return;
4835 }
4836 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4837 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4838 }
4839 int N = windowChangeListeners.length;
4840 for(int i = 0; i < N; i++) {
4841 windowChangeListeners[i].focusChanged();
4842 }
4843 }
4844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004845 private WindowState findWindow(int hashCode) {
4846 if (hashCode == -1) {
4847 return getFocusedWindow();
4848 }
4849
4850 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004851 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004852 final int count = windows.size();
4853
4854 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004855 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 if (System.identityHashCode(w) == hashCode) {
4857 return w;
4858 }
4859 }
4860 }
4861
4862 return null;
4863 }
4864
4865 /*
4866 * Instruct the Activity Manager to fetch the current configuration and broadcast
4867 * that to config-changed listeners if appropriate.
4868 */
4869 void sendNewConfiguration() {
4870 try {
4871 mActivityManager.updateConfiguration(null);
4872 } catch (RemoteException e) {
4873 }
4874 }
Romain Guy06882f82009-06-10 13:36:04 -07004875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 public Configuration computeNewConfiguration() {
4877 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004878 return computeNewConfigurationLocked();
4879 }
4880 }
Romain Guy06882f82009-06-10 13:36:04 -07004881
Dianne Hackbornc485a602009-03-24 22:39:49 -07004882 Configuration computeNewConfigurationLocked() {
4883 Configuration config = new Configuration();
4884 if (!computeNewConfigurationLocked(config)) {
4885 return null;
4886 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004887 return config;
4888 }
Romain Guy06882f82009-06-10 13:36:04 -07004889
Dianne Hackbornc485a602009-03-24 22:39:49 -07004890 boolean computeNewConfigurationLocked(Configuration config) {
4891 if (mDisplay == null) {
4892 return false;
4893 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004894
4895 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004896
4897 // Use the effective "visual" dimensions based on current rotation
4898 final boolean rotated = (mRotation == Surface.ROTATION_90
4899 || mRotation == Surface.ROTATION_270);
4900 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4901 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4902
Dianne Hackbornc485a602009-03-24 22:39:49 -07004903 int orientation = Configuration.ORIENTATION_SQUARE;
4904 if (dw < dh) {
4905 orientation = Configuration.ORIENTATION_PORTRAIT;
4906 } else if (dw > dh) {
4907 orientation = Configuration.ORIENTATION_LANDSCAPE;
4908 }
4909 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004910
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004911 DisplayMetrics dm = new DisplayMetrics();
4912 mDisplay.getMetrics(dm);
4913 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4914
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004915 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004916 // Note we only do this once because at this point we don't
4917 // expect the screen to change in this way at runtime, and want
4918 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004919 int longSize = dw;
4920 int shortSize = dh;
4921 if (longSize < shortSize) {
4922 int tmp = longSize;
4923 longSize = shortSize;
4924 shortSize = tmp;
4925 }
4926 longSize = (int)(longSize/dm.density);
4927 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004928
Dianne Hackborn723738c2009-06-25 19:48:04 -07004929 // These semi-magic numbers define our compatibility modes for
4930 // applications with different screens. Don't change unless you
4931 // make sure to test lots and lots of apps!
4932 if (longSize < 470) {
4933 // This is shorter than an HVGA normal density screen (which
4934 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004935 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4936 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004937 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004938 // What size is this screen screen?
4939 if (longSize >= 800 && shortSize >= 600) {
4940 // SVGA or larger screens at medium density are the point
4941 // at which we consider it to be an extra large screen.
4942 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4943 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004944 // VGA or larger screens at medium density are the point
4945 // at which we consider it to be a large screen.
4946 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4947 } else {
4948 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004949
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004950 // If this screen is wider than normal HVGA, or taller
4951 // than FWVGA, then for old apps we want to run in size
4952 // compatibility mode.
4953 if (shortSize > 321 || longSize > 570) {
4954 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4955 }
4956 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004957
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004958 // Is this a long screen?
4959 if (((longSize*3)/5) >= (shortSize-1)) {
4960 // Anything wider than WVGA (5:3) is considering to be long.
4961 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4962 } else {
4963 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4964 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004965 }
4966 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004967 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004968
Dianne Hackbornc485a602009-03-24 22:39:49 -07004969 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4970 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4971 mPolicy.adjustConfigurationLw(config);
4972 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004973 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004975 // -------------------------------------------------------------
4976 // Input Events and Focus Management
4977 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07004978
Jeff Brown349703e2010-06-22 01:27:15 -07004979 InputMonitor mInputMonitor = new InputMonitor();
4980
4981 /* Tracks the progress of input dispatch and ensures that input dispatch state
4982 * is kept in sync with changes in window focus, visibility, registration, and
4983 * other relevant Window Manager state transitions. */
4984 final class InputMonitor {
4985 // Current window with input focus for keys and other non-touch events. May be null.
4986 private WindowState mInputFocus;
4987
4988 // When true, prevents input dispatch from proceeding until set to false again.
4989 private boolean mInputDispatchFrozen;
4990
4991 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
4992 private boolean mInputDispatchEnabled = true;
4993
4994 // Temporary list of windows information to provide to the input dispatcher.
4995 private InputWindowList mTempInputWindows = new InputWindowList();
4996
4997 // Temporary input application object to provide to the input dispatcher.
4998 private InputApplication mTempInputApplication = new InputApplication();
4999
5000 /* Notifies the window manager about a broken input channel.
5001 *
5002 * Called by the InputManager.
5003 */
5004 public void notifyInputChannelBroken(InputChannel inputChannel) {
5005 synchronized (mWindowMap) {
5006 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5007 if (windowState == null) {
5008 return; // irrelevant
5009 }
5010
5011 Slog.i(TAG, "WINDOW DIED " + windowState);
5012 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005013 }
5014 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005015
Jeff Brown349703e2010-06-22 01:27:15 -07005016 /* Notifies the window manager about an input channel that is not responding.
5017 * The method can either cause dispatching to be aborted by returning -2 or
5018 * return a new timeout in nanoseconds.
5019 *
5020 * Called by the InputManager.
5021 */
5022 public long notifyInputChannelANR(InputChannel inputChannel) {
5023 AppWindowToken token;
5024 synchronized (mWindowMap) {
5025 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5026 if (windowState == null) {
5027 return -2; // irrelevant, abort dispatching (-2)
5028 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005029
Jeff Brown349703e2010-06-22 01:27:15 -07005030 Slog.i(TAG, "Input event dispatching timed out sending to "
5031 + windowState.mAttrs.getTitle());
5032 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005033 }
5034
Jeff Brown349703e2010-06-22 01:27:15 -07005035 return notifyANRInternal(token);
5036 }
5037
5038 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5039 * by successfully delivering the event that originally timed out.
5040 *
5041 * Called by the InputManager.
5042 */
5043 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5044 // Nothing to do just now.
5045 // Just wait for the user to dismiss the ANR dialog.
5046 }
5047
5048 /* Notifies the window manager about an application that is not responding
5049 * in general rather than with respect to a particular input channel.
5050 * The method can either cause dispatching to be aborted by returning -2 or
5051 * return a new timeout in nanoseconds.
5052 *
5053 * Called by the InputManager.
5054 */
5055 public long notifyANR(Object token) {
5056 AppWindowToken appWindowToken = (AppWindowToken) token;
5057
5058 Slog.i(TAG, "Input event dispatching timed out sending to application "
5059 + appWindowToken.stringName);
5060 return notifyANRInternal(appWindowToken);
5061 }
5062
5063 private long notifyANRInternal(AppWindowToken token) {
5064 if (token != null && token.appToken != null) {
5065 try {
5066 // Notify the activity manager about the timeout and let it decide whether
5067 // to abort dispatching or keep waiting.
5068 boolean abort = token.appToken.keyDispatchingTimedOut();
5069 if (! abort) {
5070 // The activity manager declined to abort dispatching.
5071 // Wait a bit longer and timeout again later.
5072 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005073 }
Jeff Brown349703e2010-06-22 01:27:15 -07005074 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005075 }
5076 }
Jeff Brown349703e2010-06-22 01:27:15 -07005077 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005078 }
5079
Jeff Brown349703e2010-06-22 01:27:15 -07005080 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5081 synchronized (mWindowMap) {
5082 return getWindowStateForInputChannelLocked(inputChannel);
5083 }
5084 }
5085
5086 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5087 int windowCount = mWindows.size();
5088 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005089 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005090 if (windowState.mInputChannel == inputChannel) {
5091 return windowState;
5092 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005093 }
5094
Jeff Brown349703e2010-06-22 01:27:15 -07005095 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005096 }
5097
Jeff Brown349703e2010-06-22 01:27:15 -07005098 /* Updates the cached window information provided to the input dispatcher. */
5099 public void updateInputWindowsLw() {
5100 // Populate the input window list with information about all of the windows that
5101 // could potentially receive input.
5102 // As an optimization, we could try to prune the list of windows but this turns
5103 // out to be difficult because only the native code knows for sure which window
5104 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005105 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005106 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005107 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005108 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005109 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005110 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005111 continue;
5112 }
5113
Jeff Brown349703e2010-06-22 01:27:15 -07005114 final int flags = child.mAttrs.flags;
5115 final int type = child.mAttrs.type;
5116
5117 final boolean hasFocus = (child == mInputFocus);
5118 final boolean isVisible = child.isVisibleLw();
5119 final boolean hasWallpaper = (child == mWallpaperTarget)
5120 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5121
5122 // Add a window to our list of input windows.
5123 final InputWindow inputWindow = mTempInputWindows.add();
5124 inputWindow.inputChannel = child.mInputChannel;
5125 inputWindow.layoutParamsFlags = flags;
5126 inputWindow.layoutParamsType = type;
5127 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5128 inputWindow.visible = isVisible;
5129 inputWindow.hasFocus = hasFocus;
5130 inputWindow.hasWallpaper = hasWallpaper;
5131 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5132 inputWindow.ownerPid = child.mSession.mPid;
5133 inputWindow.ownerUid = child.mSession.mUid;
5134
5135 final Rect frame = child.mFrame;
5136 inputWindow.frameLeft = frame.left;
5137 inputWindow.frameTop = frame.top;
5138
5139 switch (child.mTouchableInsets) {
5140 default:
5141 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5142 inputWindow.touchableAreaLeft = frame.left;
5143 inputWindow.touchableAreaTop = frame.top;
5144 inputWindow.touchableAreaRight = frame.right;
5145 inputWindow.touchableAreaBottom = frame.bottom;
5146 break;
5147
5148 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5149 Rect inset = child.mGivenContentInsets;
5150 inputWindow.touchableAreaLeft = frame.left + inset.left;
5151 inputWindow.touchableAreaTop = frame.top + inset.top;
5152 inputWindow.touchableAreaRight = frame.right - inset.right;
5153 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5154 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005155 }
Jeff Brown349703e2010-06-22 01:27:15 -07005156
5157 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5158 Rect inset = child.mGivenVisibleInsets;
5159 inputWindow.touchableAreaLeft = frame.left + inset.left;
5160 inputWindow.touchableAreaTop = frame.top + inset.top;
5161 inputWindow.touchableAreaRight = frame.right - inset.right;
5162 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005163 break;
5164 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005165 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005166 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005167
Jeff Brown349703e2010-06-22 01:27:15 -07005168 // Send windows to native code.
5169 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005170
Jeff Brown349703e2010-06-22 01:27:15 -07005171 // Clear the list in preparation for the next round.
5172 // Also avoids keeping InputChannel objects referenced unnecessarily.
5173 mTempInputWindows.clear();
5174 }
5175
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005176 /* Provides feedback for a virtual key down. */
5177 public void virtualKeyDownFeedback() {
5178 synchronized (mWindowMap) {
5179 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5180 }
5181 }
5182
Jeff Brown349703e2010-06-22 01:27:15 -07005183 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5184 * This essentially starts a .5 second timeout for the application to process
5185 * subsequent input events while waiting for the app switch to occur. If it takes longer
5186 * than this, the pending events will be dropped.
5187 */
5188 public void notifyAppSwitchComing() {
5189 // TODO Not implemented yet. Should go in the native side.
5190 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005191
5192 /* Notifies that the lid switch changed state. */
5193 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5194 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5195 }
5196
Jeff Brown349703e2010-06-22 01:27:15 -07005197 /* Provides an opportunity for the window manager policy to intercept early key
5198 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005199 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5200 int policyFlags, boolean isScreenOn) {
5201 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5202 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005203 }
5204
5205 /* Provides an opportunity for the window manager policy to process a key before
5206 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005207 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5208 int action, int flags, int keyCode, int metaState, int repeatCount,
5209 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005210 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005211 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5212 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005213 }
5214
5215 /* Called when the current input focus changes.
5216 * Layer assignment is assumed to be complete by the time this is called.
5217 */
5218 public void setInputFocusLw(WindowState newWindow) {
5219 if (DEBUG_INPUT) {
5220 Slog.d(TAG, "Input focus has changed to " + newWindow);
5221 }
5222
5223 if (newWindow != mInputFocus) {
5224 if (newWindow != null && newWindow.canReceiveKeys()) {
5225 // If the new input focus is an error window or appears above the current
5226 // input focus, preempt any pending synchronous dispatch so that we can
5227 // start delivering events to the new input focus as soon as possible.
5228 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5229 if (DEBUG_INPUT) {
5230 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005231 }
Jeff Brown349703e2010-06-22 01:27:15 -07005232 preemptInputDispatchLw();
5233 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5234 if (DEBUG_INPUT) {
5235 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5236 + "old win layer=" + mInputFocus.mLayer
5237 + ", new win layer=" + newWindow.mLayer);
5238 }
5239 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005240 }
Jeff Brown349703e2010-06-22 01:27:15 -07005241
5242 // Displaying a window implicitly causes dispatching to be unpaused.
5243 // This is to protect against bugs if someone pauses dispatching but
5244 // forgets to resume.
5245 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005246 }
Jeff Brown349703e2010-06-22 01:27:15 -07005247
5248 mInputFocus = newWindow;
5249 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005250 }
5251 }
5252
Jeff Brown349703e2010-06-22 01:27:15 -07005253 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5254 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5255 * can begin.
5256 */
5257 private void preemptInputDispatchLw() {
5258 mInputManager.preemptInputDispatch();
5259 }
5260
5261 public void setFocusedAppLw(AppWindowToken newApp) {
5262 // Focused app has changed.
5263 if (newApp == null) {
5264 mInputManager.setFocusedApplication(null);
5265 } else {
5266 mTempInputApplication.name = newApp.toString();
5267 mTempInputApplication.dispatchingTimeoutNanos =
5268 newApp.inputDispatchingTimeoutNanos;
5269 mTempInputApplication.token = newApp;
5270
5271 mInputManager.setFocusedApplication(mTempInputApplication);
5272 }
5273 }
5274
Jeff Brown349703e2010-06-22 01:27:15 -07005275 public void pauseDispatchingLw(WindowToken window) {
5276 if (! window.paused) {
5277 if (DEBUG_INPUT) {
5278 Slog.v(TAG, "Pausing WindowToken " + window);
5279 }
5280
5281 window.paused = true;
5282 updateInputWindowsLw();
5283 }
5284 }
5285
5286 public void resumeDispatchingLw(WindowToken window) {
5287 if (window.paused) {
5288 if (DEBUG_INPUT) {
5289 Slog.v(TAG, "Resuming WindowToken " + window);
5290 }
5291
5292 window.paused = false;
5293 updateInputWindowsLw();
5294 }
5295 }
5296
5297 public void freezeInputDispatchingLw() {
5298 if (! mInputDispatchFrozen) {
5299 if (DEBUG_INPUT) {
5300 Slog.v(TAG, "Freezing input dispatching");
5301 }
5302
5303 mInputDispatchFrozen = true;
5304 updateInputDispatchModeLw();
5305 }
5306 }
5307
5308 public void thawInputDispatchingLw() {
5309 if (mInputDispatchFrozen) {
5310 if (DEBUG_INPUT) {
5311 Slog.v(TAG, "Thawing input dispatching");
5312 }
5313
5314 mInputDispatchFrozen = false;
5315 updateInputDispatchModeLw();
5316 }
5317 }
5318
5319 public void setEventDispatchingLw(boolean enabled) {
5320 if (mInputDispatchEnabled != enabled) {
5321 if (DEBUG_INPUT) {
5322 Slog.v(TAG, "Setting event dispatching to " + enabled);
5323 }
5324
5325 mInputDispatchEnabled = enabled;
5326 updateInputDispatchModeLw();
5327 }
5328 }
5329
5330 private void updateInputDispatchModeLw() {
5331 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5332 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005335 public void pauseKeyDispatching(IBinder _token) {
5336 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5337 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005338 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005339 }
5340
5341 synchronized (mWindowMap) {
5342 WindowToken token = mTokenMap.get(_token);
5343 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005344 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345 }
5346 }
5347 }
5348
5349 public void resumeKeyDispatching(IBinder _token) {
5350 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5351 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005352 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005353 }
5354
5355 synchronized (mWindowMap) {
5356 WindowToken token = mTokenMap.get(_token);
5357 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005358 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005359 }
5360 }
5361 }
5362
5363 public void setEventDispatching(boolean enabled) {
5364 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5365 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005366 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005367 }
5368
5369 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005370 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005371 }
5372 }
Romain Guy06882f82009-06-10 13:36:04 -07005373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374 /**
5375 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005376 * Even when sync is false, this method may block while waiting for current
5377 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005378 *
5379 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005380 * {@link SystemClock#uptimeMillis()} as the timebase.)
5381 * @param sync If true, wait for the event to be completed before returning to the caller.
5382 * @return Returns true if event was dispatched, false if it was dropped for any reason
5383 */
5384 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5385 long downTime = ev.getDownTime();
5386 long eventTime = ev.getEventTime();
5387
5388 int action = ev.getAction();
5389 int code = ev.getKeyCode();
5390 int repeatCount = ev.getRepeatCount();
5391 int metaState = ev.getMetaState();
5392 int deviceId = ev.getDeviceId();
5393 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005394 int source = ev.getSource();
5395
5396 if (source == InputDevice.SOURCE_UNKNOWN) {
5397 source = InputDevice.SOURCE_KEYBOARD;
5398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005399
5400 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5401 if (downTime == 0) downTime = eventTime;
5402
5403 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005404 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005405
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005406 final int pid = Binder.getCallingPid();
5407 final int uid = Binder.getCallingUid();
5408 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005409
Jeff Brownbbda99d2010-07-28 15:48:59 -07005410 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5411 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5412 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5413 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005414
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005415 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005416 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005417 }
5418
5419 /**
5420 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005421 * Even when sync is false, this method may block while waiting for current
5422 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005423 *
5424 * @param ev A motion event describing the pointer (touch) action. (As noted in
5425 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005426 * {@link SystemClock#uptimeMillis()} as the timebase.)
5427 * @param sync If true, wait for the event to be completed before returning to the caller.
5428 * @return Returns true if event was dispatched, false if it was dropped for any reason
5429 */
5430 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005431 final int pid = Binder.getCallingPid();
5432 final int uid = Binder.getCallingUid();
5433 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005434
Jeff Brownc5ed5912010-07-14 18:48:53 -07005435 MotionEvent newEvent = MotionEvent.obtain(ev);
5436 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5437 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5438 }
5439
Jeff Brownbbda99d2010-07-28 15:48:59 -07005440 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5441 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5442 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5443 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005444
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005445 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005446 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005447 }
Romain Guy06882f82009-06-10 13:36:04 -07005448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005449 /**
5450 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005451 * Even when sync is false, this method may block while waiting for current
5452 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005453 *
5454 * @param ev A motion event describing the trackball action. (As noted in
5455 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005456 * {@link SystemClock#uptimeMillis()} as the timebase.)
5457 * @param sync If true, wait for the event to be completed before returning to the caller.
5458 * @return Returns true if event was dispatched, false if it was dropped for any reason
5459 */
5460 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005461 final int pid = Binder.getCallingPid();
5462 final int uid = Binder.getCallingUid();
5463 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005464
Jeff Brownc5ed5912010-07-14 18:48:53 -07005465 MotionEvent newEvent = MotionEvent.obtain(ev);
5466 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5467 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5468 }
5469
Jeff Brownbbda99d2010-07-28 15:48:59 -07005470 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5471 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5472 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5473 INJECTION_TIMEOUT_MILLIS);
5474
5475 Binder.restoreCallingIdentity(ident);
5476 return reportInjectionResult(result);
5477 }
5478
5479 /**
5480 * Inject an input event into the UI without waiting for dispatch to commence.
5481 * This variant is useful for fire-and-forget input event injection. It does not
5482 * block any longer than it takes to enqueue the input event.
5483 *
5484 * @param ev An input event. (Be sure to set the input source correctly.)
5485 * @return Returns true if event was dispatched, false if it was dropped for any reason
5486 */
5487 public boolean injectInputEventNoWait(InputEvent ev) {
5488 final int pid = Binder.getCallingPid();
5489 final int uid = Binder.getCallingUid();
5490 final long ident = Binder.clearCallingIdentity();
5491
5492 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5493 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5494 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005495
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005496 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005497 return reportInjectionResult(result);
5498 }
5499
5500 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005501 switch (result) {
5502 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5503 Slog.w(TAG, "Input event injection permission denied.");
5504 throw new SecurityException(
5505 "Injecting to another application requires INJECT_EVENTS permission");
5506 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005507 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005508 return true;
5509 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5510 Slog.w(TAG, "Input event injection timed out.");
5511 return false;
5512 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5513 default:
5514 Slog.w(TAG, "Input event injection failed.");
5515 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005516 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005517 }
Romain Guy06882f82009-06-10 13:36:04 -07005518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005519 private WindowState getFocusedWindow() {
5520 synchronized (mWindowMap) {
5521 return getFocusedWindowLocked();
5522 }
5523 }
5524
5525 private WindowState getFocusedWindowLocked() {
5526 return mCurrentFocus;
5527 }
Romain Guy06882f82009-06-10 13:36:04 -07005528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005529 public boolean detectSafeMode() {
5530 mSafeMode = mPolicy.detectSafeMode();
5531 return mSafeMode;
5532 }
Romain Guy06882f82009-06-10 13:36:04 -07005533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005534 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005535 synchronized(mWindowMap) {
5536 if (mDisplay != null) {
5537 throw new IllegalStateException("Display already initialized");
5538 }
5539 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5540 mDisplay = wm.getDefaultDisplay();
5541 mInitialDisplayWidth = mDisplay.getWidth();
5542 mInitialDisplayHeight = mDisplay.getHeight();
5543 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
5544 }
5545
5546 try {
5547 mActivityManager.updateConfiguration(null);
5548 } catch (RemoteException e) {
5549 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005550
5551 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005552 }
5553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005554 // -------------------------------------------------------------
5555 // Client Session State
5556 // -------------------------------------------------------------
5557
5558 private final class Session extends IWindowSession.Stub
5559 implements IBinder.DeathRecipient {
5560 final IInputMethodClient mClient;
5561 final IInputContext mInputContext;
5562 final int mUid;
5563 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005564 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005565 SurfaceSession mSurfaceSession;
5566 int mNumWindow = 0;
5567 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005569 public Session(IInputMethodClient client, IInputContext inputContext) {
5570 mClient = client;
5571 mInputContext = inputContext;
5572 mUid = Binder.getCallingUid();
5573 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005574 StringBuilder sb = new StringBuilder();
5575 sb.append("Session{");
5576 sb.append(Integer.toHexString(System.identityHashCode(this)));
5577 sb.append(" uid ");
5578 sb.append(mUid);
5579 sb.append("}");
5580 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005582 synchronized (mWindowMap) {
5583 if (mInputMethodManager == null && mHaveInputMethods) {
5584 IBinder b = ServiceManager.getService(
5585 Context.INPUT_METHOD_SERVICE);
5586 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5587 }
5588 }
5589 long ident = Binder.clearCallingIdentity();
5590 try {
5591 // Note: it is safe to call in to the input method manager
5592 // here because we are not holding our lock.
5593 if (mInputMethodManager != null) {
5594 mInputMethodManager.addClient(client, inputContext,
5595 mUid, mPid);
5596 } else {
5597 client.setUsingInputMethod(false);
5598 }
5599 client.asBinder().linkToDeath(this, 0);
5600 } catch (RemoteException e) {
5601 // The caller has died, so we can just forget about this.
5602 try {
5603 if (mInputMethodManager != null) {
5604 mInputMethodManager.removeClient(client);
5605 }
5606 } catch (RemoteException ee) {
5607 }
5608 } finally {
5609 Binder.restoreCallingIdentity(ident);
5610 }
5611 }
Romain Guy06882f82009-06-10 13:36:04 -07005612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005613 @Override
5614 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5615 throws RemoteException {
5616 try {
5617 return super.onTransact(code, data, reply, flags);
5618 } catch (RuntimeException e) {
5619 // Log all 'real' exceptions thrown to the caller
5620 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005621 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005622 }
5623 throw e;
5624 }
5625 }
5626
5627 public void binderDied() {
5628 // Note: it is safe to call in to the input method manager
5629 // here because we are not holding our lock.
5630 try {
5631 if (mInputMethodManager != null) {
5632 mInputMethodManager.removeClient(mClient);
5633 }
5634 } catch (RemoteException e) {
5635 }
5636 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005637 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005638 mClientDead = true;
5639 killSessionLocked();
5640 }
5641 }
5642
5643 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005644 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5645 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5646 outInputChannel);
5647 }
5648
5649 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005650 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005651 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005652 }
Romain Guy06882f82009-06-10 13:36:04 -07005653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005654 public void remove(IWindow window) {
5655 removeWindow(this, window);
5656 }
Romain Guy06882f82009-06-10 13:36:04 -07005657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005658 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5659 int requestedWidth, int requestedHeight, int viewFlags,
5660 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005661 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005662 return relayoutWindow(this, window, attrs,
5663 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005664 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005665 }
Romain Guy06882f82009-06-10 13:36:04 -07005666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005667 public void setTransparentRegion(IWindow window, Region region) {
5668 setTransparentRegionWindow(this, window, region);
5669 }
Romain Guy06882f82009-06-10 13:36:04 -07005670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 public void setInsets(IWindow window, int touchableInsets,
5672 Rect contentInsets, Rect visibleInsets) {
5673 setInsetsWindow(this, window, touchableInsets, contentInsets,
5674 visibleInsets);
5675 }
Romain Guy06882f82009-06-10 13:36:04 -07005676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005677 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5678 getWindowDisplayFrame(this, window, outDisplayFrame);
5679 }
Romain Guy06882f82009-06-10 13:36:04 -07005680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005681 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005682 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005683 TAG, "IWindow finishDrawing called for " + window);
5684 finishDrawingWindow(this, window);
5685 }
5686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005687 public void setInTouchMode(boolean mode) {
5688 synchronized(mWindowMap) {
5689 mInTouchMode = mode;
5690 }
5691 }
5692
5693 public boolean getInTouchMode() {
5694 synchronized(mWindowMap) {
5695 return mInTouchMode;
5696 }
5697 }
5698
5699 public boolean performHapticFeedback(IWindow window, int effectId,
5700 boolean always) {
5701 synchronized(mWindowMap) {
5702 long ident = Binder.clearCallingIdentity();
5703 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005704 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005705 windowForClientLocked(this, window, true),
5706 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005707 } finally {
5708 Binder.restoreCallingIdentity(ident);
5709 }
5710 }
5711 }
Romain Guy06882f82009-06-10 13:36:04 -07005712
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005713 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005714 synchronized(mWindowMap) {
5715 long ident = Binder.clearCallingIdentity();
5716 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005717 setWindowWallpaperPositionLocked(
5718 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005719 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005720 } finally {
5721 Binder.restoreCallingIdentity(ident);
5722 }
5723 }
5724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005725
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005726 public void wallpaperOffsetsComplete(IBinder window) {
5727 WindowManagerService.this.wallpaperOffsetsComplete(window);
5728 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005729
Dianne Hackborn75804932009-10-20 20:15:20 -07005730 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5731 int z, Bundle extras, boolean sync) {
5732 synchronized(mWindowMap) {
5733 long ident = Binder.clearCallingIdentity();
5734 try {
5735 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005736 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005737 action, x, y, z, extras, sync);
5738 } finally {
5739 Binder.restoreCallingIdentity(ident);
5740 }
5741 }
5742 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005743
Dianne Hackborn75804932009-10-20 20:15:20 -07005744 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5745 WindowManagerService.this.wallpaperCommandComplete(window, result);
5746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005748 void windowAddedLocked() {
5749 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005750 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005751 TAG, "First window added to " + this + ", creating SurfaceSession");
5752 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005753 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005754 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005755 mSessions.add(this);
5756 }
5757 mNumWindow++;
5758 }
5759
5760 void windowRemovedLocked() {
5761 mNumWindow--;
5762 killSessionLocked();
5763 }
Romain Guy06882f82009-06-10 13:36:04 -07005764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005765 void killSessionLocked() {
5766 if (mNumWindow <= 0 && mClientDead) {
5767 mSessions.remove(this);
5768 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005769 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005770 TAG, "Last window removed from " + this
5771 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005772 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005773 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005774 try {
5775 mSurfaceSession.kill();
5776 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005777 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005778 + mSurfaceSession + " in session " + this
5779 + ": " + e.toString());
5780 }
5781 mSurfaceSession = null;
5782 }
5783 }
5784 }
Romain Guy06882f82009-06-10 13:36:04 -07005785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005786 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005787 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5788 pw.print(" mClientDead="); pw.print(mClientDead);
5789 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005790 }
5791
5792 @Override
5793 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005794 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005795 }
5796 }
5797
5798 // -------------------------------------------------------------
5799 // Client Window State
5800 // -------------------------------------------------------------
5801
5802 private final class WindowState implements WindowManagerPolicy.WindowState {
5803 final Session mSession;
5804 final IWindow mClient;
5805 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005806 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005807 AppWindowToken mAppToken;
5808 AppWindowToken mTargetAppToken;
5809 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5810 final DeathRecipient mDeathRecipient;
5811 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005812 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005813 final int mBaseLayer;
5814 final int mSubLayer;
5815 final boolean mLayoutAttached;
5816 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005817 final boolean mIsWallpaper;
5818 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005819 int mViewVisibility;
5820 boolean mPolicyVisibility = true;
5821 boolean mPolicyVisibilityAfterAnim = true;
5822 boolean mAppFreezing;
5823 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005824 boolean mReportDestroySurface;
5825 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005826 boolean mAttachedHidden; // is our parent window hidden?
5827 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005828 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005829 int mRequestedWidth;
5830 int mRequestedHeight;
5831 int mLastRequestedWidth;
5832 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005833 int mLayer;
5834 int mAnimLayer;
5835 int mLastLayer;
5836 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005837 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005838 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005839
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005840 int mLayoutSeq = -1;
5841
5842 Configuration mConfiguration = null;
5843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 // Actual frame shown on-screen (may be modified by animation)
5845 final Rect mShownFrame = new Rect();
5846 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005848 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005849 * Set when we have changed the size of the surface, to know that
5850 * we must tell them application to resize (and thus redraw itself).
5851 */
5852 boolean mSurfaceResized;
5853
5854 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005855 * Insets that determine the actually visible area
5856 */
5857 final Rect mVisibleInsets = new Rect();
5858 final Rect mLastVisibleInsets = new Rect();
5859 boolean mVisibleInsetsChanged;
5860
5861 /**
5862 * Insets that are covered by system windows
5863 */
5864 final Rect mContentInsets = new Rect();
5865 final Rect mLastContentInsets = new Rect();
5866 boolean mContentInsetsChanged;
5867
5868 /**
5869 * Set to true if we are waiting for this window to receive its
5870 * given internal insets before laying out other windows based on it.
5871 */
5872 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005874 /**
5875 * These are the content insets that were given during layout for
5876 * this window, to be applied to windows behind it.
5877 */
5878 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 /**
5881 * These are the visible insets that were given during layout for
5882 * this window, to be applied to windows behind it.
5883 */
5884 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 /**
5887 * Flag indicating whether the touchable region should be adjusted by
5888 * the visible insets; if false the area outside the visible insets is
5889 * NOT touchable, so we must use those to adjust the frame during hit
5890 * tests.
5891 */
5892 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005894 // Current transformation being applied.
5895 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5896 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5897 float mHScale=1, mVScale=1;
5898 float mLastHScale=1, mLastVScale=1;
5899 final Matrix mTmpMatrix = new Matrix();
5900
5901 // "Real" frame that the application sees.
5902 final Rect mFrame = new Rect();
5903 final Rect mLastFrame = new Rect();
5904
5905 final Rect mContainingFrame = new Rect();
5906 final Rect mDisplayFrame = new Rect();
5907 final Rect mContentFrame = new Rect();
5908 final Rect mVisibleFrame = new Rect();
5909
5910 float mShownAlpha = 1;
5911 float mAlpha = 1;
5912 float mLastAlpha = 1;
5913
5914 // Set to true if, when the window gets displayed, it should perform
5915 // an enter animation.
5916 boolean mEnterAnimationPending;
5917
5918 // Currently running animation.
5919 boolean mAnimating;
5920 boolean mLocalAnimating;
5921 Animation mAnimation;
5922 boolean mAnimationIsEntrance;
5923 boolean mHasTransformation;
5924 boolean mHasLocalTransformation;
5925 final Transformation mTransformation = new Transformation();
5926
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005927 // If a window showing a wallpaper: the requested offset for the
5928 // wallpaper; if a wallpaper window: the currently applied offset.
5929 float mWallpaperX = -1;
5930 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005931
5932 // If a window showing a wallpaper: what fraction of the offset
5933 // range corresponds to a full virtual screen.
5934 float mWallpaperXStep = -1;
5935 float mWallpaperYStep = -1;
5936
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005937 // Wallpaper windows: pixels offset based on above variables.
5938 int mXOffset;
5939 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 // This is set after IWindowSession.relayout() has been called at
5942 // least once for the window. It allows us to detect the situation
5943 // where we don't yet have a surface, but should have one soon, so
5944 // we can give the window focus before waiting for the relayout.
5945 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005947 // This is set after the Surface has been created but before the
5948 // window has been drawn. During this time the surface is hidden.
5949 boolean mDrawPending;
5950
5951 // This is set after the window has finished drawing for the first
5952 // time but before its surface is shown. The surface will be
5953 // displayed when the next layout is run.
5954 boolean mCommitDrawPending;
5955
5956 // This is set during the time after the window's drawing has been
5957 // committed, and before its surface is actually shown. It is used
5958 // to delay showing the surface until all windows in a token are ready
5959 // to be shown.
5960 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005962 // Set when the window has been shown in the screen the first time.
5963 boolean mHasDrawn;
5964
5965 // Currently running an exit animation?
5966 boolean mExiting;
5967
5968 // Currently on the mDestroySurface list?
5969 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 // Completely remove from window manager after exit animation?
5972 boolean mRemoveOnExit;
5973
5974 // Set when the orientation is changing and this window has not yet
5975 // been updated for the new orientation.
5976 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005978 // Is this window now (or just being) removed?
5979 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005980
Dianne Hackborn16064f92010-03-25 00:47:24 -07005981 // For debugging, this is the last information given to the surface flinger.
5982 boolean mSurfaceShown;
5983 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5984 int mSurfaceLayer;
5985 float mSurfaceAlpha;
5986
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005987 // Input channel
5988 InputChannel mInputChannel;
5989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005990 WindowState(Session s, IWindow c, WindowToken token,
5991 WindowState attachedWindow, WindowManager.LayoutParams a,
5992 int viewVisibility) {
5993 mSession = s;
5994 mClient = c;
5995 mToken = token;
5996 mAttrs.copyFrom(a);
5997 mViewVisibility = viewVisibility;
5998 DeathRecipient deathRecipient = new DeathRecipient();
5999 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006000 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 TAG, "Window " + this + " client=" + c.asBinder()
6002 + " token=" + token + " (" + mAttrs.token + ")");
6003 try {
6004 c.asBinder().linkToDeath(deathRecipient, 0);
6005 } catch (RemoteException e) {
6006 mDeathRecipient = null;
6007 mAttachedWindow = null;
6008 mLayoutAttached = false;
6009 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006010 mIsWallpaper = false;
6011 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006012 mBaseLayer = 0;
6013 mSubLayer = 0;
6014 return;
6015 }
6016 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006018 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6019 mAttrs.type <= LAST_SUB_WINDOW)) {
6020 // The multiplier here is to reserve space for multiple
6021 // windows in the same type layer.
6022 mBaseLayer = mPolicy.windowTypeToLayerLw(
6023 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6024 + TYPE_LAYER_OFFSET;
6025 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6026 mAttachedWindow = attachedWindow;
6027 mAttachedWindow.mChildWindows.add(this);
6028 mLayoutAttached = mAttrs.type !=
6029 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6030 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6031 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006032 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6033 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006034 } else {
6035 // The multiplier here is to reserve space for multiple
6036 // windows in the same type layer.
6037 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6038 * TYPE_LAYER_MULTIPLIER
6039 + TYPE_LAYER_OFFSET;
6040 mSubLayer = 0;
6041 mAttachedWindow = null;
6042 mLayoutAttached = false;
6043 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6044 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006045 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6046 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006047 }
6048
6049 WindowState appWin = this;
6050 while (appWin.mAttachedWindow != null) {
6051 appWin = mAttachedWindow;
6052 }
6053 WindowToken appToken = appWin.mToken;
6054 while (appToken.appWindowToken == null) {
6055 WindowToken parent = mTokenMap.get(appToken.token);
6056 if (parent == null || appToken == parent) {
6057 break;
6058 }
6059 appToken = parent;
6060 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006061 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006062 mAppToken = appToken.appWindowToken;
6063
6064 mSurface = null;
6065 mRequestedWidth = 0;
6066 mRequestedHeight = 0;
6067 mLastRequestedWidth = 0;
6068 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006069 mXOffset = 0;
6070 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071 mLayer = 0;
6072 mAnimLayer = 0;
6073 mLastLayer = 0;
6074 }
6075
6076 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006077 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 TAG, "Attaching " + this + " token=" + mToken
6079 + ", list=" + mToken.windows);
6080 mSession.windowAddedLocked();
6081 }
6082
6083 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6084 mHaveFrame = true;
6085
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006086 final Rect container = mContainingFrame;
6087 container.set(pf);
6088
6089 final Rect display = mDisplayFrame;
6090 display.set(df);
6091
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006092 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006093 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006094 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6095 display.intersect(mCompatibleScreenFrame);
6096 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006097 }
6098
6099 final int pw = container.right - container.left;
6100 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101
6102 int w,h;
6103 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6104 w = mAttrs.width < 0 ? pw : mAttrs.width;
6105 h = mAttrs.height< 0 ? ph : mAttrs.height;
6106 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006107 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6108 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006109 }
Romain Guy06882f82009-06-10 13:36:04 -07006110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006111 final Rect content = mContentFrame;
6112 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006114 final Rect visible = mVisibleFrame;
6115 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006117 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006118 final int fw = frame.width();
6119 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006121 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6122 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6123
6124 Gravity.apply(mAttrs.gravity, w, h, container,
6125 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6126 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6127
6128 //System.out.println("Out: " + mFrame);
6129
6130 // Now make sure the window fits in the overall display.
6131 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006133 // Make sure the content and visible frames are inside of the
6134 // final window frame.
6135 if (content.left < frame.left) content.left = frame.left;
6136 if (content.top < frame.top) content.top = frame.top;
6137 if (content.right > frame.right) content.right = frame.right;
6138 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6139 if (visible.left < frame.left) visible.left = frame.left;
6140 if (visible.top < frame.top) visible.top = frame.top;
6141 if (visible.right > frame.right) visible.right = frame.right;
6142 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 final Rect contentInsets = mContentInsets;
6145 contentInsets.left = content.left-frame.left;
6146 contentInsets.top = content.top-frame.top;
6147 contentInsets.right = frame.right-content.right;
6148 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006150 final Rect visibleInsets = mVisibleInsets;
6151 visibleInsets.left = visible.left-frame.left;
6152 visibleInsets.top = visible.top-frame.top;
6153 visibleInsets.right = frame.right-visible.right;
6154 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006155
Dianne Hackborn284ac932009-08-28 10:34:25 -07006156 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6157 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006158 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006159 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006161 if (localLOGV) {
6162 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6163 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006164 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006165 + mRequestedWidth + ", mRequestedheight="
6166 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6167 + "): frame=" + mFrame.toShortString()
6168 + " ci=" + contentInsets.toShortString()
6169 + " vi=" + visibleInsets.toShortString());
6170 //}
6171 }
6172 }
Romain Guy06882f82009-06-10 13:36:04 -07006173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 public Rect getFrameLw() {
6175 return mFrame;
6176 }
6177
6178 public Rect getShownFrameLw() {
6179 return mShownFrame;
6180 }
6181
6182 public Rect getDisplayFrameLw() {
6183 return mDisplayFrame;
6184 }
6185
6186 public Rect getContentFrameLw() {
6187 return mContentFrame;
6188 }
6189
6190 public Rect getVisibleFrameLw() {
6191 return mVisibleFrame;
6192 }
6193
6194 public boolean getGivenInsetsPendingLw() {
6195 return mGivenInsetsPending;
6196 }
6197
6198 public Rect getGivenContentInsetsLw() {
6199 return mGivenContentInsets;
6200 }
Romain Guy06882f82009-06-10 13:36:04 -07006201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006202 public Rect getGivenVisibleInsetsLw() {
6203 return mGivenVisibleInsets;
6204 }
Romain Guy06882f82009-06-10 13:36:04 -07006205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006206 public WindowManager.LayoutParams getAttrs() {
6207 return mAttrs;
6208 }
6209
6210 public int getSurfaceLayer() {
6211 return mLayer;
6212 }
Romain Guy06882f82009-06-10 13:36:04 -07006213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006214 public IApplicationToken getAppToken() {
6215 return mAppToken != null ? mAppToken.appToken : null;
6216 }
Jeff Brown349703e2010-06-22 01:27:15 -07006217
6218 public long getInputDispatchingTimeoutNanos() {
6219 return mAppToken != null
6220 ? mAppToken.inputDispatchingTimeoutNanos
6221 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006223
6224 public boolean hasAppShownWindows() {
6225 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6226 }
6227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006229 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006230 TAG, "Setting animation in " + this + ": " + anim);
6231 mAnimating = false;
6232 mLocalAnimating = false;
6233 mAnimation = anim;
6234 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6235 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6236 }
6237
6238 public void clearAnimation() {
6239 if (mAnimation != null) {
6240 mAnimating = true;
6241 mLocalAnimating = false;
6242 mAnimation = null;
6243 }
6244 }
Romain Guy06882f82009-06-10 13:36:04 -07006245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006246 Surface createSurfaceLocked() {
6247 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006248 mReportDestroySurface = false;
6249 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006250 mDrawPending = true;
6251 mCommitDrawPending = false;
6252 mReadyToShow = false;
6253 if (mAppToken != null) {
6254 mAppToken.allDrawn = false;
6255 }
6256
6257 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006258 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006259 flags |= Surface.PUSH_BUFFERS;
6260 }
6261
6262 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6263 flags |= Surface.SECURE;
6264 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006265 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 TAG, "Creating surface in session "
6267 + mSession.mSurfaceSession + " window " + this
6268 + " w=" + mFrame.width()
6269 + " h=" + mFrame.height() + " format="
6270 + mAttrs.format + " flags=" + flags);
6271
6272 int w = mFrame.width();
6273 int h = mFrame.height();
6274 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6275 // for a scaled surface, we always want the requested
6276 // size.
6277 w = mRequestedWidth;
6278 h = mRequestedHeight;
6279 }
6280
Romain Guy9825ec62009-10-01 00:58:09 -07006281 // Something is wrong and SurfaceFlinger will not like this,
6282 // try to revert to sane values
6283 if (w <= 0) w = 1;
6284 if (h <= 0) h = 1;
6285
Dianne Hackborn16064f92010-03-25 00:47:24 -07006286 mSurfaceShown = false;
6287 mSurfaceLayer = 0;
6288 mSurfaceAlpha = 1;
6289 mSurfaceX = 0;
6290 mSurfaceY = 0;
6291 mSurfaceW = w;
6292 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006293 try {
6294 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006295 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006296 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006297 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006298 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006299 + mSurface + " IN SESSION "
6300 + mSession.mSurfaceSession
6301 + ": pid=" + mSession.mPid + " format="
6302 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006303 + Integer.toHexString(flags)
6304 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006306 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 reclaimSomeSurfaceMemoryLocked(this, "create");
6308 return null;
6309 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006310 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311 return null;
6312 }
Romain Guy06882f82009-06-10 13:36:04 -07006313
Joe Onorato8a9b2202010-02-26 18:56:32 -08006314 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006315 TAG, "Got surface: " + mSurface
6316 + ", set left=" + mFrame.left + " top=" + mFrame.top
6317 + ", animLayer=" + mAnimLayer);
6318 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006319 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006320 if (SHOW_TRANSACTIONS) logSurface(this,
6321 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6322 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6323 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006324 }
6325 Surface.openTransaction();
6326 try {
6327 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006328 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006329 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006330 mSurface.setPosition(mSurfaceX, mSurfaceY);
6331 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006332 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006333 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006334 mSurface.hide();
6335 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006336 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006337 mSurface.setFlags(Surface.SURFACE_DITHER,
6338 Surface.SURFACE_DITHER);
6339 }
6340 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006341 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006342 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6343 }
6344 mLastHidden = true;
6345 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006346 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006347 Surface.closeTransaction();
6348 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006349 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 TAG, "Created surface " + this);
6351 }
6352 return mSurface;
6353 }
Romain Guy06882f82009-06-10 13:36:04 -07006354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006355 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006356 if (mAppToken != null && this == mAppToken.startingWindow) {
6357 mAppToken.startingDisplayed = false;
6358 }
Romain Guy06882f82009-06-10 13:36:04 -07006359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006361 mDrawPending = false;
6362 mCommitDrawPending = false;
6363 mReadyToShow = false;
6364
6365 int i = mChildWindows.size();
6366 while (i > 0) {
6367 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006368 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006369 c.mAttachedHidden = true;
6370 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006371
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006372 if (mReportDestroySurface) {
6373 mReportDestroySurface = false;
6374 mSurfacePendingDestroy = true;
6375 try {
6376 mClient.dispatchGetNewSurface();
6377 // We'll really destroy on the next time around.
6378 return;
6379 } catch (RemoteException e) {
6380 }
6381 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006383 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006384 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006385 RuntimeException e = null;
6386 if (!HIDE_STACK_CRAWLS) {
6387 e = new RuntimeException();
6388 e.fillInStackTrace();
6389 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006390 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006391 + mSurface + ", session " + mSession, e);
6392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006393 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006394 RuntimeException e = null;
6395 if (!HIDE_STACK_CRAWLS) {
6396 e = new RuntimeException();
6397 e.fillInStackTrace();
6398 }
6399 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006400 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006401 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006403 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006404 + " surface " + mSurface + " session " + mSession
6405 + ": " + e.toString());
6406 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006407
Dianne Hackborn16064f92010-03-25 00:47:24 -07006408 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 }
6411 }
6412
6413 boolean finishDrawingLocked() {
6414 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006415 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006416 TAG, "finishDrawingLocked: " + mSurface);
6417 mCommitDrawPending = true;
6418 mDrawPending = false;
6419 return true;
6420 }
6421 return false;
6422 }
6423
6424 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006425 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006426 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006428 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 }
6430 mCommitDrawPending = false;
6431 mReadyToShow = true;
6432 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6433 final AppWindowToken atoken = mAppToken;
6434 if (atoken == null || atoken.allDrawn || starting) {
6435 performShowLocked();
6436 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006437 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 }
6439
6440 // This must be called while inside a transaction.
6441 boolean performShowLocked() {
6442 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006443 RuntimeException e = null;
6444 if (!HIDE_STACK_CRAWLS) {
6445 e = new RuntimeException();
6446 e.fillInStackTrace();
6447 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006448 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006449 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6450 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6451 }
6452 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006453 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6454 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006455 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 + " during animation: policyVis=" + mPolicyVisibility
6457 + " attHidden=" + mAttachedHidden
6458 + " tok.hiddenRequested="
6459 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006460 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006461 + (mAppToken != null ? mAppToken.hidden : false)
6462 + " animating=" + mAnimating
6463 + " tok animating="
6464 + (mAppToken != null ? mAppToken.animating : false));
6465 if (!showSurfaceRobustlyLocked(this)) {
6466 return false;
6467 }
6468 mLastAlpha = -1;
6469 mHasDrawn = true;
6470 mLastHidden = false;
6471 mReadyToShow = false;
6472 enableScreenIfNeededLocked();
6473
6474 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 int i = mChildWindows.size();
6477 while (i > 0) {
6478 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006479 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006480 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006482 if (c.mSurface != null) {
6483 c.performShowLocked();
6484 // It hadn't been shown, which means layout not
6485 // performed on it, so now we want to make sure to
6486 // do a layout. If called from within the transaction
6487 // loop, this will cause it to restart with a new
6488 // layout.
6489 mLayoutNeeded = true;
6490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006491 }
6492 }
Romain Guy06882f82009-06-10 13:36:04 -07006493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006494 if (mAttrs.type != TYPE_APPLICATION_STARTING
6495 && mAppToken != null) {
6496 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006497
Dianne Hackborn248b1882009-09-16 16:46:44 -07006498 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006499 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006500 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006501 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006502 // If this initial window is animating, stop it -- we
6503 // will do an animation to reveal it from behind the
6504 // starting window, so there is no need for it to also
6505 // be doing its own stuff.
6506 if (mAnimation != null) {
6507 mAnimation = null;
6508 // Make sure we clean up the animation.
6509 mAnimating = true;
6510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 mFinishedStarting.add(mAppToken);
6512 mH.sendEmptyMessage(H.FINISHED_STARTING);
6513 }
6514 mAppToken.updateReportedVisibilityLocked();
6515 }
6516 }
6517 return true;
6518 }
Romain Guy06882f82009-06-10 13:36:04 -07006519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520 // This must be called while inside a transaction. Returns true if
6521 // there is more animation to run.
6522 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006523 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006524 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006526 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6527 mHasTransformation = true;
6528 mHasLocalTransformation = true;
6529 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006530 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 TAG, "Starting animation in " + this +
6532 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6533 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6534 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6535 mAnimation.setStartTime(currentTime);
6536 mLocalAnimating = true;
6537 mAnimating = true;
6538 }
6539 mTransformation.clear();
6540 final boolean more = mAnimation.getTransformation(
6541 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006542 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006543 TAG, "Stepped animation in " + this +
6544 ": more=" + more + ", xform=" + mTransformation);
6545 if (more) {
6546 // we're not done!
6547 return true;
6548 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006549 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006550 TAG, "Finished animation in " + this +
6551 " @ " + currentTime);
6552 mAnimation = null;
6553 //WindowManagerService.this.dump();
6554 }
6555 mHasLocalTransformation = false;
6556 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006557 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 // When our app token is animating, we kind-of pretend like
6559 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6560 // part of this check means that we will only do this if
6561 // our window is not currently exiting, or it is not
6562 // locally animating itself. The idea being that one that
6563 // is exiting and doing a local animation should be removed
6564 // once that animation is done.
6565 mAnimating = true;
6566 mHasTransformation = true;
6567 mTransformation.clear();
6568 return false;
6569 } else if (mHasTransformation) {
6570 // Little trick to get through the path below to act like
6571 // we have finished an animation.
6572 mAnimating = true;
6573 } else if (isAnimating()) {
6574 mAnimating = true;
6575 }
6576 } else if (mAnimation != null) {
6577 // If the display is frozen, and there is a pending animation,
6578 // clear it and make sure we run the cleanup code.
6579 mAnimating = true;
6580 mLocalAnimating = true;
6581 mAnimation = null;
6582 }
Romain Guy06882f82009-06-10 13:36:04 -07006583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006584 if (!mAnimating && !mLocalAnimating) {
6585 return false;
6586 }
6587
Joe Onorato8a9b2202010-02-26 18:56:32 -08006588 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006589 TAG, "Animation done in " + this + ": exiting=" + mExiting
6590 + ", reportedVisible="
6591 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 mAnimating = false;
6594 mLocalAnimating = false;
6595 mAnimation = null;
6596 mAnimLayer = mLayer;
6597 if (mIsImWindow) {
6598 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006599 } else if (mIsWallpaper) {
6600 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006601 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006602 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 + " anim layer: " + mAnimLayer);
6604 mHasTransformation = false;
6605 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006606 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6607 if (DEBUG_VISIBILITY) {
6608 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6609 + mPolicyVisibilityAfterAnim);
6610 }
6611 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6612 if (!mPolicyVisibility) {
6613 if (mCurrentFocus == this) {
6614 mFocusMayChange = true;
6615 }
6616 // Window is no longer visible -- make sure if we were waiting
6617 // for it to be displayed before enabling the display, that
6618 // we allow the display to be enabled now.
6619 enableScreenIfNeededLocked();
6620 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006622 mTransformation.clear();
6623 if (mHasDrawn
6624 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6625 && mAppToken != null
6626 && mAppToken.firstWindowDrawn
6627 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006628 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006629 + mToken + ": first real window done animating");
6630 mFinishedStarting.add(mAppToken);
6631 mH.sendEmptyMessage(H.FINISHED_STARTING);
6632 }
Romain Guy06882f82009-06-10 13:36:04 -07006633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006634 finishExit();
6635
6636 if (mAppToken != null) {
6637 mAppToken.updateReportedVisibilityLocked();
6638 }
6639
6640 return false;
6641 }
6642
6643 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006644 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006645 TAG, "finishExit in " + this
6646 + ": exiting=" + mExiting
6647 + " remove=" + mRemoveOnExit
6648 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006650 final int N = mChildWindows.size();
6651 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006652 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006653 }
Romain Guy06882f82009-06-10 13:36:04 -07006654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 if (!mExiting) {
6656 return;
6657 }
Romain Guy06882f82009-06-10 13:36:04 -07006658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006659 if (isWindowAnimating()) {
6660 return;
6661 }
6662
Joe Onorato8a9b2202010-02-26 18:56:32 -08006663 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006664 TAG, "Exit animation finished in " + this
6665 + ": remove=" + mRemoveOnExit);
6666 if (mSurface != null) {
6667 mDestroySurface.add(this);
6668 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006669 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006670 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 try {
6672 mSurface.hide();
6673 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006674 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006675 }
6676 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006677 }
6678 mExiting = false;
6679 if (mRemoveOnExit) {
6680 mPendingRemove.add(this);
6681 mRemoveOnExit = false;
6682 }
6683 }
Romain Guy06882f82009-06-10 13:36:04 -07006684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6686 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6687 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6688 if (dtdx < -.000001f || dtdx > .000001f) return false;
6689 if (dsdy < -.000001f || dsdy > .000001f) return false;
6690 return true;
6691 }
Romain Guy06882f82009-06-10 13:36:04 -07006692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006693 void computeShownFrameLocked() {
6694 final boolean selfTransformation = mHasLocalTransformation;
6695 Transformation attachedTransformation =
6696 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6697 ? mAttachedWindow.mTransformation : null;
6698 Transformation appTransformation =
6699 (mAppToken != null && mAppToken.hasTransformation)
6700 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006701
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006702 // Wallpapers are animated based on the "real" window they
6703 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006704 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006705 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006706 if (mWallpaperTarget.mHasLocalTransformation &&
6707 mWallpaperTarget.mAnimation != null &&
6708 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006709 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006710 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006711 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006712 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006713 }
6714 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006715 mWallpaperTarget.mAppToken.hasTransformation &&
6716 mWallpaperTarget.mAppToken.animation != null &&
6717 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006718 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006719 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006720 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006721 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006722 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 if (selfTransformation || attachedTransformation != null
6726 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006727 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 final Rect frame = mFrame;
6729 final float tmpFloats[] = mTmpFloats;
6730 final Matrix tmpMatrix = mTmpMatrix;
6731
6732 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006733 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006735 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006736 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006737 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006738 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006739 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006740 }
6741 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006742 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 }
6744
6745 // "convert" it into SurfaceFlinger's format
6746 // (a 2x2 matrix + an offset)
6747 // Here we must not transform the position of the surface
6748 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006749 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006751 tmpMatrix.getValues(tmpFloats);
6752 mDsDx = tmpFloats[Matrix.MSCALE_X];
6753 mDtDx = tmpFloats[Matrix.MSKEW_X];
6754 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6755 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006756 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6757 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006758 int w = frame.width();
6759 int h = frame.height();
6760 mShownFrame.set(x, y, x+w, y+h);
6761
6762 // Now set the alpha... but because our current hardware
6763 // can't do alpha transformation on a non-opaque surface,
6764 // turn it off if we are running an animation that is also
6765 // transforming since it is more important to have that
6766 // animation be smooth.
6767 mShownAlpha = mAlpha;
6768 if (!mLimitedAlphaCompositing
6769 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6770 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6771 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006772 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 if (selfTransformation) {
6774 mShownAlpha *= mTransformation.getAlpha();
6775 }
6776 if (attachedTransformation != null) {
6777 mShownAlpha *= attachedTransformation.getAlpha();
6778 }
6779 if (appTransformation != null) {
6780 mShownAlpha *= appTransformation.getAlpha();
6781 }
6782 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006783 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006784 }
Romain Guy06882f82009-06-10 13:36:04 -07006785
Joe Onorato8a9b2202010-02-26 18:56:32 -08006786 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006787 TAG, "Continuing animation in " + this +
6788 ": " + mShownFrame +
6789 ", alpha=" + mTransformation.getAlpha());
6790 return;
6791 }
Romain Guy06882f82009-06-10 13:36:04 -07006792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006793 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006794 if (mXOffset != 0 || mYOffset != 0) {
6795 mShownFrame.offset(mXOffset, mYOffset);
6796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 mShownAlpha = mAlpha;
6798 mDsDx = 1;
6799 mDtDx = 0;
6800 mDsDy = 0;
6801 mDtDy = 1;
6802 }
Romain Guy06882f82009-06-10 13:36:04 -07006803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006804 /**
6805 * Is this window visible? It is not visible if there is no
6806 * surface, or we are in the process of running an exit animation
6807 * that will remove the surface, or its app token has been hidden.
6808 */
6809 public boolean isVisibleLw() {
6810 final AppWindowToken atoken = mAppToken;
6811 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6812 && (atoken == null || !atoken.hiddenRequested)
6813 && !mExiting && !mDestroying;
6814 }
6815
6816 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006817 * Like {@link #isVisibleLw}, but also counts a window that is currently
6818 * "hidden" behind the keyguard as visible. This allows us to apply
6819 * things like window flags that impact the keyguard.
6820 * XXX I am starting to think we need to have ANOTHER visibility flag
6821 * for this "hidden behind keyguard" state rather than overloading
6822 * mPolicyVisibility. Ungh.
6823 */
6824 public boolean isVisibleOrBehindKeyguardLw() {
6825 final AppWindowToken atoken = mAppToken;
6826 return mSurface != null && !mAttachedHidden
6827 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006828 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006829 && !mExiting && !mDestroying;
6830 }
6831
6832 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006833 * Is this window visible, ignoring its app token? It is not visible
6834 * if there is no surface, or we are in the process of running an exit animation
6835 * that will remove the surface.
6836 */
6837 public boolean isWinVisibleLw() {
6838 final AppWindowToken atoken = mAppToken;
6839 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6840 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6841 && !mExiting && !mDestroying;
6842 }
6843
6844 /**
6845 * The same as isVisible(), but follows the current hidden state of
6846 * the associated app token, not the pending requested hidden state.
6847 */
6848 boolean isVisibleNow() {
6849 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006850 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 }
6852
6853 /**
6854 * Same as isVisible(), but we also count it as visible between the
6855 * call to IWindowSession.add() and the first relayout().
6856 */
6857 boolean isVisibleOrAdding() {
6858 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006859 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006860 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6861 && mPolicyVisibility && !mAttachedHidden
6862 && (atoken == null || !atoken.hiddenRequested)
6863 && !mExiting && !mDestroying;
6864 }
6865
6866 /**
6867 * Is this window currently on-screen? It is on-screen either if it
6868 * is visible or it is currently running an animation before no longer
6869 * being visible.
6870 */
6871 boolean isOnScreen() {
6872 final AppWindowToken atoken = mAppToken;
6873 if (atoken != null) {
6874 return mSurface != null && mPolicyVisibility && !mDestroying
6875 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006876 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 } else {
6878 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006879 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006880 }
6881 }
Romain Guy06882f82009-06-10 13:36:04 -07006882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 /**
6884 * Like isOnScreen(), but we don't return true if the window is part
6885 * of a transition that has not yet been started.
6886 */
6887 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006888 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006889 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006890 return false;
6891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006892 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006893 final boolean animating = atoken != null
6894 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006895 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006896 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6897 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006898 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006899 }
6900
6901 /** Is the window or its container currently animating? */
6902 boolean isAnimating() {
6903 final WindowState attached = mAttachedWindow;
6904 final AppWindowToken atoken = mAppToken;
6905 return mAnimation != null
6906 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006907 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006908 (atoken.animation != null
6909 || atoken.inPendingTransaction));
6910 }
6911
6912 /** Is this window currently animating? */
6913 boolean isWindowAnimating() {
6914 return mAnimation != null;
6915 }
6916
6917 /**
6918 * Like isOnScreen, but returns false if the surface hasn't yet
6919 * been drawn.
6920 */
6921 public boolean isDisplayedLw() {
6922 final AppWindowToken atoken = mAppToken;
6923 return mSurface != null && mPolicyVisibility && !mDestroying
6924 && !mDrawPending && !mCommitDrawPending
6925 && ((!mAttachedHidden &&
6926 (atoken == null || !atoken.hiddenRequested))
6927 || mAnimating);
6928 }
6929
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006930 /**
6931 * Returns true if the window has a surface that it has drawn a
6932 * complete UI in to.
6933 */
6934 public boolean isDrawnLw() {
6935 final AppWindowToken atoken = mAppToken;
6936 return mSurface != null && !mDestroying
6937 && !mDrawPending && !mCommitDrawPending;
6938 }
6939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006940 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6941 boolean shownFrame, boolean onlyOpaque) {
6942 if (mSurface == null) {
6943 return false;
6944 }
6945 if (mAppToken != null && !mAppToken.appFullscreen) {
6946 return false;
6947 }
6948 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6949 return false;
6950 }
6951 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006952
6953 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6954 return frame.left <= mCompatibleScreenFrame.left &&
6955 frame.top <= mCompatibleScreenFrame.top &&
6956 frame.right >= mCompatibleScreenFrame.right &&
6957 frame.bottom >= mCompatibleScreenFrame.bottom;
6958 } else {
6959 return frame.left <= 0 && frame.top <= 0
6960 && frame.right >= screenWidth
6961 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006963 }
Romain Guy06882f82009-06-10 13:36:04 -07006964
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006965 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006966 * Return true if the window is opaque and fully drawn. This indicates
6967 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006968 */
6969 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006970 return (mAttrs.format == PixelFormat.OPAQUE
6971 || mAttrs.type == TYPE_WALLPAPER)
6972 && mSurface != null && mAnimation == null
6973 && (mAppToken == null || mAppToken.animation == null)
6974 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006975 }
6976
6977 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6978 return
6979 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006980 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6981 // only if it's visible
6982 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006983 // and only if the application fills the compatible screen
6984 mFrame.left <= mCompatibleScreenFrame.left &&
6985 mFrame.top <= mCompatibleScreenFrame.top &&
6986 mFrame.right >= mCompatibleScreenFrame.right &&
6987 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006988 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006989 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006990 }
6991
6992 boolean isFullscreen(int screenWidth, int screenHeight) {
6993 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006994 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006995 }
6996
6997 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07006998 disposeInputChannel();
6999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007000 if (mAttachedWindow != null) {
7001 mAttachedWindow.mChildWindows.remove(this);
7002 }
7003 destroySurfaceLocked();
7004 mSession.windowRemovedLocked();
7005 try {
7006 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7007 } catch (RuntimeException e) {
7008 // Ignore if it has already been removed (usually because
7009 // we are doing this as part of processing a death note.)
7010 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007011 }
7012
7013 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007014 if (mInputChannel != null) {
7015 mInputManager.unregisterInputChannel(mInputChannel);
7016
7017 mInputChannel.dispose();
7018 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007019 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007020 }
7021
7022 private class DeathRecipient implements IBinder.DeathRecipient {
7023 public void binderDied() {
7024 try {
7025 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007026 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007027 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007028 if (win != null) {
7029 removeWindowLocked(mSession, win);
7030 }
7031 }
7032 } catch (IllegalArgumentException ex) {
7033 // This will happen if the window has already been
7034 // removed.
7035 }
7036 }
7037 }
7038
7039 /** Returns true if this window desires key events. */
7040 public final boolean canReceiveKeys() {
7041 return isVisibleOrAdding()
7042 && (mViewVisibility == View.VISIBLE)
7043 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7044 }
7045
7046 public boolean hasDrawnLw() {
7047 return mHasDrawn;
7048 }
7049
7050 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007051 return showLw(doAnimation, true);
7052 }
7053
7054 boolean showLw(boolean doAnimation, boolean requestAnim) {
7055 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7056 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007057 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007058 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007059 if (doAnimation) {
7060 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7061 + mPolicyVisibility + " mAnimation=" + mAnimation);
7062 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7063 doAnimation = false;
7064 } else if (mPolicyVisibility && mAnimation == null) {
7065 // Check for the case where we are currently visible and
7066 // not animating; we do not want to do animation at such a
7067 // point to become visible when we already are.
7068 doAnimation = false;
7069 }
7070 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007071 mPolicyVisibility = true;
7072 mPolicyVisibilityAfterAnim = true;
7073 if (doAnimation) {
7074 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7075 }
7076 if (requestAnim) {
7077 requestAnimationLocked(0);
7078 }
7079 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007080 }
7081
7082 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007083 return hideLw(doAnimation, true);
7084 }
7085
7086 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007087 if (doAnimation) {
7088 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7089 doAnimation = false;
7090 }
7091 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007092 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7093 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007094 if (!current) {
7095 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007096 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007097 if (doAnimation) {
7098 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7099 if (mAnimation == null) {
7100 doAnimation = false;
7101 }
7102 }
7103 if (doAnimation) {
7104 mPolicyVisibilityAfterAnim = false;
7105 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007106 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007107 mPolicyVisibilityAfterAnim = false;
7108 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007109 // Window is no longer visible -- make sure if we were waiting
7110 // for it to be displayed before enabling the display, that
7111 // we allow the display to be enabled now.
7112 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007113 if (mCurrentFocus == this) {
7114 mFocusMayChange = true;
7115 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007116 }
7117 if (requestAnim) {
7118 requestAnimationLocked(0);
7119 }
7120 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007121 }
7122
7123 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007124 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7125 pw.print(" mClient="); pw.println(mClient.asBinder());
7126 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7127 if (mAttachedWindow != null || mLayoutAttached) {
7128 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7129 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7130 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007131 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7132 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7133 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007134 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7135 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007136 }
7137 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7138 pw.print(" mSubLayer="); pw.print(mSubLayer);
7139 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7140 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7141 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7142 pw.print("="); pw.print(mAnimLayer);
7143 pw.print(" mLastLayer="); pw.println(mLastLayer);
7144 if (mSurface != null) {
7145 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007146 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7147 pw.print(" layer="); pw.print(mSurfaceLayer);
7148 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7149 pw.print(" rect=("); pw.print(mSurfaceX);
7150 pw.print(","); pw.print(mSurfaceY);
7151 pw.print(") "); pw.print(mSurfaceW);
7152 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007153 }
7154 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7155 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7156 if (mAppToken != null) {
7157 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7158 }
7159 if (mTargetAppToken != null) {
7160 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7161 }
7162 pw.print(prefix); pw.print("mViewVisibility=0x");
7163 pw.print(Integer.toHexString(mViewVisibility));
7164 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007165 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7166 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007167 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7168 pw.print(prefix); pw.print("mPolicyVisibility=");
7169 pw.print(mPolicyVisibility);
7170 pw.print(" mPolicyVisibilityAfterAnim=");
7171 pw.print(mPolicyVisibilityAfterAnim);
7172 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7173 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007174 if (!mRelayoutCalled) {
7175 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7176 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007177 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007178 pw.print(" h="); pw.print(mRequestedHeight);
7179 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007180 if (mXOffset != 0 || mYOffset != 0) {
7181 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7182 pw.print(" y="); pw.println(mYOffset);
7183 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007184 pw.print(prefix); pw.print("mGivenContentInsets=");
7185 mGivenContentInsets.printShortString(pw);
7186 pw.print(" mGivenVisibleInsets=");
7187 mGivenVisibleInsets.printShortString(pw);
7188 pw.println();
7189 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7190 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7191 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7192 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007193 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007194 pw.print(prefix); pw.print("mShownFrame=");
7195 mShownFrame.printShortString(pw);
7196 pw.print(" last="); mLastShownFrame.printShortString(pw);
7197 pw.println();
7198 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7199 pw.print(" last="); mLastFrame.printShortString(pw);
7200 pw.println();
7201 pw.print(prefix); pw.print("mContainingFrame=");
7202 mContainingFrame.printShortString(pw);
7203 pw.print(" mDisplayFrame=");
7204 mDisplayFrame.printShortString(pw);
7205 pw.println();
7206 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7207 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7208 pw.println();
7209 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7210 pw.print(" last="); mLastContentInsets.printShortString(pw);
7211 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7212 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7213 pw.println();
7214 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7215 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7216 pw.print(" mAlpha="); pw.print(mAlpha);
7217 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7218 }
7219 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7220 || mAnimation != null) {
7221 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7222 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7223 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7224 pw.print(" mAnimation="); pw.println(mAnimation);
7225 }
7226 if (mHasTransformation || mHasLocalTransformation) {
7227 pw.print(prefix); pw.print("XForm: has=");
7228 pw.print(mHasTransformation);
7229 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7230 pw.print(" "); mTransformation.printShortString(pw);
7231 pw.println();
7232 }
7233 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7234 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7235 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7236 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7237 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7238 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7239 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7240 pw.print(" mDestroying="); pw.print(mDestroying);
7241 pw.print(" mRemoved="); pw.println(mRemoved);
7242 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007243 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007244 pw.print(prefix); pw.print("mOrientationChanging=");
7245 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007246 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7247 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007248 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007249 if (mHScale != 1 || mVScale != 1) {
7250 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7251 pw.print(" mVScale="); pw.println(mVScale);
7252 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007253 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007254 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7255 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7256 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007257 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7258 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7259 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007261 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007262
7263 String makeInputChannelName() {
7264 return Integer.toHexString(System.identityHashCode(this))
7265 + " " + mAttrs.getTitle();
7266 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007267
7268 @Override
7269 public String toString() {
7270 return "Window{"
7271 + Integer.toHexString(System.identityHashCode(this))
7272 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7273 }
7274 }
Romain Guy06882f82009-06-10 13:36:04 -07007275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007276 // -------------------------------------------------------------
7277 // Window Token State
7278 // -------------------------------------------------------------
7279
7280 class WindowToken {
7281 // The actual token.
7282 final IBinder token;
7283
7284 // The type of window this token is for, as per WindowManager.LayoutParams.
7285 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007287 // Set if this token was explicitly added by a client, so should
7288 // not be removed when all windows are removed.
7289 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007290
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007291 // For printing.
7292 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007294 // If this is an AppWindowToken, this is non-null.
7295 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007297 // All of the windows associated with this token.
7298 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7299
7300 // Is key dispatching paused for this token?
7301 boolean paused = false;
7302
7303 // Should this token's windows be hidden?
7304 boolean hidden;
7305
7306 // Temporary for finding which tokens no longer have visible windows.
7307 boolean hasVisible;
7308
Dianne Hackborna8f60182009-09-01 19:01:50 -07007309 // Set to true when this token is in a pending transaction where it
7310 // will be shown.
7311 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007312
Dianne Hackborna8f60182009-09-01 19:01:50 -07007313 // Set to true when this token is in a pending transaction where it
7314 // will be hidden.
7315 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007316
Dianne Hackborna8f60182009-09-01 19:01:50 -07007317 // Set to true when this token is in a pending transaction where its
7318 // windows will be put to the bottom of the list.
7319 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007320
Dianne Hackborna8f60182009-09-01 19:01:50 -07007321 // Set to true when this token is in a pending transaction where its
7322 // windows will be put to the top of the list.
7323 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 WindowToken(IBinder _token, int type, boolean _explicit) {
7326 token = _token;
7327 windowType = type;
7328 explicit = _explicit;
7329 }
7330
7331 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007332 pw.print(prefix); pw.print("token="); pw.println(token);
7333 pw.print(prefix); pw.print("windows="); pw.println(windows);
7334 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7335 pw.print(" hidden="); pw.print(hidden);
7336 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007337 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7338 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7339 pw.print(" waitingToHide="); pw.print(waitingToHide);
7340 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7341 pw.print(" sendingToTop="); pw.println(sendingToTop);
7342 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 }
7344
7345 @Override
7346 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007347 if (stringName == null) {
7348 StringBuilder sb = new StringBuilder();
7349 sb.append("WindowToken{");
7350 sb.append(Integer.toHexString(System.identityHashCode(this)));
7351 sb.append(" token="); sb.append(token); sb.append('}');
7352 stringName = sb.toString();
7353 }
7354 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007355 }
7356 };
7357
7358 class AppWindowToken extends WindowToken {
7359 // Non-null only for application tokens.
7360 final IApplicationToken appToken;
7361
7362 // All of the windows and child windows that are included in this
7363 // application token. Note this list is NOT sorted!
7364 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7365
7366 int groupId = -1;
7367 boolean appFullscreen;
7368 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007369
7370 // The input dispatching timeout for this application token in nanoseconds.
7371 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007373 // These are used for determining when all windows associated with
7374 // an activity have been drawn, so they can be made visible together
7375 // at the same time.
7376 int lastTransactionSequence = mTransactionSequence-1;
7377 int numInterestingWindows;
7378 int numDrawnWindows;
7379 boolean inPendingTransaction;
7380 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 // Is this token going to be hidden in a little while? If so, it
7383 // won't be taken into account for setting the screen orientation.
7384 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007386 // Is this window's surface needed? This is almost like hidden, except
7387 // it will sometimes be true a little earlier: when the token has
7388 // been shown, but is still waiting for its app transition to execute
7389 // before making its windows shown.
7390 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 // Have we told the window clients to hide themselves?
7393 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007395 // Last visibility state we reported to the app token.
7396 boolean reportedVisible;
7397
7398 // Set to true when the token has been removed from the window mgr.
7399 boolean removed;
7400
7401 // Have we been asked to have this token keep the screen frozen?
7402 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 boolean animating;
7405 Animation animation;
7406 boolean hasTransformation;
7407 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 // Offset to the window of all layers in the token, for use by
7410 // AppWindowToken animations.
7411 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007413 // Information about an application starting window if displayed.
7414 StartingData startingData;
7415 WindowState startingWindow;
7416 View startingView;
7417 boolean startingDisplayed;
7418 boolean startingMoved;
7419 boolean firstWindowDrawn;
7420
7421 AppWindowToken(IApplicationToken _token) {
7422 super(_token.asBinder(),
7423 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7424 appWindowToken = this;
7425 appToken = _token;
7426 }
Romain Guy06882f82009-06-10 13:36:04 -07007427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007428 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007429 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 TAG, "Setting animation in " + this + ": " + anim);
7431 animation = anim;
7432 animating = false;
7433 anim.restrictDuration(MAX_ANIMATION_DURATION);
7434 anim.scaleCurrentDuration(mTransitionAnimationScale);
7435 int zorder = anim.getZAdjustment();
7436 int adj = 0;
7437 if (zorder == Animation.ZORDER_TOP) {
7438 adj = TYPE_LAYER_OFFSET;
7439 } else if (zorder == Animation.ZORDER_BOTTOM) {
7440 adj = -TYPE_LAYER_OFFSET;
7441 }
Romain Guy06882f82009-06-10 13:36:04 -07007442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007443 if (animLayerAdjustment != adj) {
7444 animLayerAdjustment = adj;
7445 updateLayers();
7446 }
7447 }
Romain Guy06882f82009-06-10 13:36:04 -07007448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 public void setDummyAnimation() {
7450 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007451 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 TAG, "Setting dummy animation in " + this);
7453 animation = sDummyAnimation;
7454 }
7455 }
7456
7457 public void clearAnimation() {
7458 if (animation != null) {
7459 animation = null;
7460 animating = true;
7461 }
7462 }
Romain Guy06882f82009-06-10 13:36:04 -07007463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 void updateLayers() {
7465 final int N = allAppWindows.size();
7466 final int adj = animLayerAdjustment;
7467 for (int i=0; i<N; i++) {
7468 WindowState w = allAppWindows.get(i);
7469 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007470 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007471 + w.mAnimLayer);
7472 if (w == mInputMethodTarget) {
7473 setInputMethodAnimLayerAdjustment(adj);
7474 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007475 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007476 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007477 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007478 }
7479 }
Romain Guy06882f82009-06-10 13:36:04 -07007480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 void sendAppVisibilityToClients() {
7482 final int N = allAppWindows.size();
7483 for (int i=0; i<N; i++) {
7484 WindowState win = allAppWindows.get(i);
7485 if (win == startingWindow && clientHidden) {
7486 // Don't hide the starting window.
7487 continue;
7488 }
7489 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007490 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 "Setting visibility of " + win + ": " + (!clientHidden));
7492 win.mClient.dispatchAppVisibility(!clientHidden);
7493 } catch (RemoteException e) {
7494 }
7495 }
7496 }
Romain Guy06882f82009-06-10 13:36:04 -07007497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007498 void showAllWindowsLocked() {
7499 final int NW = allAppWindows.size();
7500 for (int i=0; i<NW; i++) {
7501 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007502 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 "performing show on: " + w);
7504 w.performShowLocked();
7505 }
7506 }
Romain Guy06882f82009-06-10 13:36:04 -07007507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 // This must be called while inside a transaction.
7509 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007510 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007511 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007513 if (animation == sDummyAnimation) {
7514 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007515 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007516 // when it is really time to animate, this will be set to
7517 // a real animation and the next call will execute normally.
7518 return false;
7519 }
Romain Guy06882f82009-06-10 13:36:04 -07007520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007521 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7522 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007523 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 TAG, "Starting animation in " + this +
7525 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7526 + " scale=" + mTransitionAnimationScale
7527 + " allDrawn=" + allDrawn + " animating=" + animating);
7528 animation.initialize(dw, dh, dw, dh);
7529 animation.setStartTime(currentTime);
7530 animating = true;
7531 }
7532 transformation.clear();
7533 final boolean more = animation.getTransformation(
7534 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007535 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007536 TAG, "Stepped animation in " + this +
7537 ": more=" + more + ", xform=" + transformation);
7538 if (more) {
7539 // we're done!
7540 hasTransformation = true;
7541 return true;
7542 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007543 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007544 TAG, "Finished animation in " + this +
7545 " @ " + currentTime);
7546 animation = null;
7547 }
7548 } else if (animation != null) {
7549 // If the display is frozen, and there is a pending animation,
7550 // clear it and make sure we run the cleanup code.
7551 animating = true;
7552 animation = null;
7553 }
7554
7555 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007557 if (!animating) {
7558 return false;
7559 }
7560
7561 clearAnimation();
7562 animating = false;
7563 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7564 moveInputMethodWindowsIfNeededLocked(true);
7565 }
Romain Guy06882f82009-06-10 13:36:04 -07007566
Joe Onorato8a9b2202010-02-26 18:56:32 -08007567 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007568 TAG, "Animation done in " + this
7569 + ": reportedVisible=" + reportedVisible);
7570
7571 transformation.clear();
7572 if (animLayerAdjustment != 0) {
7573 animLayerAdjustment = 0;
7574 updateLayers();
7575 }
Romain Guy06882f82009-06-10 13:36:04 -07007576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007577 final int N = windows.size();
7578 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007579 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 }
7581 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007583 return false;
7584 }
7585
7586 void updateReportedVisibilityLocked() {
7587 if (appToken == null) {
7588 return;
7589 }
Romain Guy06882f82009-06-10 13:36:04 -07007590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007591 int numInteresting = 0;
7592 int numVisible = 0;
7593 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007594
Joe Onorato8a9b2202010-02-26 18:56:32 -08007595 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 final int N = allAppWindows.size();
7597 for (int i=0; i<N; i++) {
7598 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007599 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007600 || win.mViewVisibility != View.VISIBLE
7601 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007602 continue;
7603 }
7604 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007605 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007606 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007607 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007608 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007609 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007610 + " pv=" + win.mPolicyVisibility
7611 + " dp=" + win.mDrawPending
7612 + " cdp=" + win.mCommitDrawPending
7613 + " ah=" + win.mAttachedHidden
7614 + " th="
7615 + (win.mAppToken != null
7616 ? win.mAppToken.hiddenRequested : false)
7617 + " a=" + win.mAnimating);
7618 }
7619 }
7620 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007621 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007622 if (!win.isAnimating()) {
7623 numVisible++;
7624 }
7625 nowGone = false;
7626 } else if (win.isAnimating()) {
7627 nowGone = false;
7628 }
7629 }
Romain Guy06882f82009-06-10 13:36:04 -07007630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007631 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007632 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 + numInteresting + " visible=" + numVisible);
7634 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007635 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007636 TAG, "Visibility changed in " + this
7637 + ": vis=" + nowVisible);
7638 reportedVisible = nowVisible;
7639 Message m = mH.obtainMessage(
7640 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7641 nowVisible ? 1 : 0,
7642 nowGone ? 1 : 0,
7643 this);
7644 mH.sendMessage(m);
7645 }
7646 }
Romain Guy06882f82009-06-10 13:36:04 -07007647
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007648 WindowState findMainWindow() {
7649 int j = windows.size();
7650 while (j > 0) {
7651 j--;
7652 WindowState win = windows.get(j);
7653 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7654 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7655 return win;
7656 }
7657 }
7658 return null;
7659 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007661 void dump(PrintWriter pw, String prefix) {
7662 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007663 if (appToken != null) {
7664 pw.print(prefix); pw.println("app=true");
7665 }
7666 if (allAppWindows.size() > 0) {
7667 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7668 }
7669 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007670 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007671 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7672 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7673 pw.print(" clientHidden="); pw.print(clientHidden);
7674 pw.print(" willBeHidden="); pw.print(willBeHidden);
7675 pw.print(" reportedVisible="); pw.println(reportedVisible);
7676 if (paused || freezingScreen) {
7677 pw.print(prefix); pw.print("paused="); pw.print(paused);
7678 pw.print(" freezingScreen="); pw.println(freezingScreen);
7679 }
7680 if (numInterestingWindows != 0 || numDrawnWindows != 0
7681 || inPendingTransaction || allDrawn) {
7682 pw.print(prefix); pw.print("numInterestingWindows=");
7683 pw.print(numInterestingWindows);
7684 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7685 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7686 pw.print(" allDrawn="); pw.println(allDrawn);
7687 }
7688 if (animating || animation != null) {
7689 pw.print(prefix); pw.print("animating="); pw.print(animating);
7690 pw.print(" animation="); pw.println(animation);
7691 }
7692 if (animLayerAdjustment != 0) {
7693 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7694 }
7695 if (hasTransformation) {
7696 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7697 pw.print(" transformation="); transformation.printShortString(pw);
7698 pw.println();
7699 }
7700 if (startingData != null || removed || firstWindowDrawn) {
7701 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7702 pw.print(" removed="); pw.print(removed);
7703 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7704 }
7705 if (startingWindow != null || startingView != null
7706 || startingDisplayed || startingMoved) {
7707 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7708 pw.print(" startingView="); pw.print(startingView);
7709 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7710 pw.print(" startingMoved"); pw.println(startingMoved);
7711 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007712 }
7713
7714 @Override
7715 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007716 if (stringName == null) {
7717 StringBuilder sb = new StringBuilder();
7718 sb.append("AppWindowToken{");
7719 sb.append(Integer.toHexString(System.identityHashCode(this)));
7720 sb.append(" token="); sb.append(token); sb.append('}');
7721 stringName = sb.toString();
7722 }
7723 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007724 }
7725 }
Romain Guy06882f82009-06-10 13:36:04 -07007726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007727 // -------------------------------------------------------------
7728 // DummyAnimation
7729 // -------------------------------------------------------------
7730
7731 // This is an animation that does nothing: it just immediately finishes
7732 // itself every time it is called. It is used as a stub animation in cases
7733 // where we want to synchronize multiple things that may be animating.
7734 static final class DummyAnimation extends Animation {
7735 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7736 return false;
7737 }
7738 }
7739 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007741 // -------------------------------------------------------------
7742 // Async Handler
7743 // -------------------------------------------------------------
7744
7745 static final class StartingData {
7746 final String pkg;
7747 final int theme;
7748 final CharSequence nonLocalizedLabel;
7749 final int labelRes;
7750 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007752 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7753 int _labelRes, int _icon) {
7754 pkg = _pkg;
7755 theme = _theme;
7756 nonLocalizedLabel = _nonLocalizedLabel;
7757 labelRes = _labelRes;
7758 icon = _icon;
7759 }
7760 }
7761
7762 private final class H extends Handler {
7763 public static final int REPORT_FOCUS_CHANGE = 2;
7764 public static final int REPORT_LOSING_FOCUS = 3;
7765 public static final int ANIMATE = 4;
7766 public static final int ADD_STARTING = 5;
7767 public static final int REMOVE_STARTING = 6;
7768 public static final int FINISHED_STARTING = 7;
7769 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7771 public static final int HOLD_SCREEN_CHANGED = 12;
7772 public static final int APP_TRANSITION_TIMEOUT = 13;
7773 public static final int PERSIST_ANIMATION_SCALE = 14;
7774 public static final int FORCE_GC = 15;
7775 public static final int ENABLE_SCREEN = 16;
7776 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007777 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007778 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007780 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007782 public H() {
7783 }
Romain Guy06882f82009-06-10 13:36:04 -07007784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007785 @Override
7786 public void handleMessage(Message msg) {
7787 switch (msg.what) {
7788 case REPORT_FOCUS_CHANGE: {
7789 WindowState lastFocus;
7790 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792 synchronized(mWindowMap) {
7793 lastFocus = mLastFocus;
7794 newFocus = mCurrentFocus;
7795 if (lastFocus == newFocus) {
7796 // Focus is not changing, so nothing to do.
7797 return;
7798 }
7799 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007800 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007801 // + " to " + newFocus);
7802 if (newFocus != null && lastFocus != null
7803 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007804 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007805 mLosingFocus.add(lastFocus);
7806 lastFocus = null;
7807 }
7808 }
7809
7810 if (lastFocus != newFocus) {
7811 //System.out.println("Changing focus from " + lastFocus
7812 // + " to " + newFocus);
7813 if (newFocus != null) {
7814 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007815 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007816 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7817 } catch (RemoteException e) {
7818 // Ignore if process has died.
7819 }
7820 }
7821
7822 if (lastFocus != null) {
7823 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007824 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007825 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7826 } catch (RemoteException e) {
7827 // Ignore if process has died.
7828 }
7829 }
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007830 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007831 }
7832 } break;
7833
7834 case REPORT_LOSING_FOCUS: {
7835 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007837 synchronized(mWindowMap) {
7838 losers = mLosingFocus;
7839 mLosingFocus = new ArrayList<WindowState>();
7840 }
7841
7842 final int N = losers.size();
7843 for (int i=0; i<N; i++) {
7844 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007845 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007846 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7847 } catch (RemoteException e) {
7848 // Ignore if process has died.
7849 }
7850 }
7851 } break;
7852
7853 case ANIMATE: {
7854 synchronized(mWindowMap) {
7855 mAnimationPending = false;
7856 performLayoutAndPlaceSurfacesLocked();
7857 }
7858 } break;
7859
7860 case ADD_STARTING: {
7861 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7862 final StartingData sd = wtoken.startingData;
7863
7864 if (sd == null) {
7865 // Animation has been canceled... do nothing.
7866 return;
7867 }
Romain Guy06882f82009-06-10 13:36:04 -07007868
Joe Onorato8a9b2202010-02-26 18:56:32 -08007869 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007870 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007872 View view = null;
7873 try {
7874 view = mPolicy.addStartingWindow(
7875 wtoken.token, sd.pkg,
7876 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7877 sd.icon);
7878 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007879 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 }
7881
7882 if (view != null) {
7883 boolean abort = false;
7884
7885 synchronized(mWindowMap) {
7886 if (wtoken.removed || wtoken.startingData == null) {
7887 // If the window was successfully added, then
7888 // we need to remove it.
7889 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007890 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 "Aborted starting " + wtoken
7892 + ": removed=" + wtoken.removed
7893 + " startingData=" + wtoken.startingData);
7894 wtoken.startingWindow = null;
7895 wtoken.startingData = null;
7896 abort = true;
7897 }
7898 } else {
7899 wtoken.startingView = view;
7900 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007901 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007902 "Added starting " + wtoken
7903 + ": startingWindow="
7904 + wtoken.startingWindow + " startingView="
7905 + wtoken.startingView);
7906 }
7907
7908 if (abort) {
7909 try {
7910 mPolicy.removeStartingWindow(wtoken.token, view);
7911 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007912 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007913 }
7914 }
7915 }
7916 } break;
7917
7918 case REMOVE_STARTING: {
7919 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7920 IBinder token = null;
7921 View view = null;
7922 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007923 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007924 + wtoken + ": startingWindow="
7925 + wtoken.startingWindow + " startingView="
7926 + wtoken.startingView);
7927 if (wtoken.startingWindow != null) {
7928 view = wtoken.startingView;
7929 token = wtoken.token;
7930 wtoken.startingData = null;
7931 wtoken.startingView = null;
7932 wtoken.startingWindow = null;
7933 }
7934 }
7935 if (view != null) {
7936 try {
7937 mPolicy.removeStartingWindow(token, view);
7938 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007939 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007940 }
7941 }
7942 } break;
7943
7944 case FINISHED_STARTING: {
7945 IBinder token = null;
7946 View view = null;
7947 while (true) {
7948 synchronized (mWindowMap) {
7949 final int N = mFinishedStarting.size();
7950 if (N <= 0) {
7951 break;
7952 }
7953 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7954
Joe Onorato8a9b2202010-02-26 18:56:32 -08007955 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007956 "Finished starting " + wtoken
7957 + ": startingWindow=" + wtoken.startingWindow
7958 + " startingView=" + wtoken.startingView);
7959
7960 if (wtoken.startingWindow == null) {
7961 continue;
7962 }
7963
7964 view = wtoken.startingView;
7965 token = wtoken.token;
7966 wtoken.startingData = null;
7967 wtoken.startingView = null;
7968 wtoken.startingWindow = null;
7969 }
7970
7971 try {
7972 mPolicy.removeStartingWindow(token, view);
7973 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007974 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007975 }
7976 }
7977 } break;
7978
7979 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7980 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7981
7982 boolean nowVisible = msg.arg1 != 0;
7983 boolean nowGone = msg.arg2 != 0;
7984
7985 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007986 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007987 TAG, "Reporting visible in " + wtoken
7988 + " visible=" + nowVisible
7989 + " gone=" + nowGone);
7990 if (nowVisible) {
7991 wtoken.appToken.windowsVisible();
7992 } else {
7993 wtoken.appToken.windowsGone();
7994 }
7995 } catch (RemoteException ex) {
7996 }
7997 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007999 case WINDOW_FREEZE_TIMEOUT: {
8000 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008001 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008002 int i = mWindows.size();
8003 while (i > 0) {
8004 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008005 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 if (w.mOrientationChanging) {
8007 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008008 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008009 }
8010 }
8011 performLayoutAndPlaceSurfacesLocked();
8012 }
8013 break;
8014 }
Romain Guy06882f82009-06-10 13:36:04 -07008015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 case HOLD_SCREEN_CHANGED: {
8017 Session oldHold;
8018 Session newHold;
8019 synchronized (mWindowMap) {
8020 oldHold = mLastReportedHold;
8021 newHold = (Session)msg.obj;
8022 mLastReportedHold = newHold;
8023 }
Romain Guy06882f82009-06-10 13:36:04 -07008024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 if (oldHold != newHold) {
8026 try {
8027 if (oldHold != null) {
8028 mBatteryStats.noteStopWakelock(oldHold.mUid,
8029 "window",
8030 BatteryStats.WAKE_TYPE_WINDOW);
8031 }
8032 if (newHold != null) {
8033 mBatteryStats.noteStartWakelock(newHold.mUid,
8034 "window",
8035 BatteryStats.WAKE_TYPE_WINDOW);
8036 }
8037 } catch (RemoteException e) {
8038 }
8039 }
8040 break;
8041 }
Romain Guy06882f82009-06-10 13:36:04 -07008042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 case APP_TRANSITION_TIMEOUT: {
8044 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008045 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008046 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 "*** APP TRANSITION TIMEOUT");
8048 mAppTransitionReady = true;
8049 mAppTransitionTimeout = true;
8050 performLayoutAndPlaceSurfacesLocked();
8051 }
8052 }
8053 break;
8054 }
Romain Guy06882f82009-06-10 13:36:04 -07008055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008056 case PERSIST_ANIMATION_SCALE: {
8057 Settings.System.putFloat(mContext.getContentResolver(),
8058 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8059 Settings.System.putFloat(mContext.getContentResolver(),
8060 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8061 break;
8062 }
Romain Guy06882f82009-06-10 13:36:04 -07008063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008064 case FORCE_GC: {
8065 synchronized(mWindowMap) {
8066 if (mAnimationPending) {
8067 // If we are animating, don't do the gc now but
8068 // delay a bit so we don't interrupt the animation.
8069 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8070 2000);
8071 return;
8072 }
8073 // If we are currently rotating the display, it will
8074 // schedule a new message when done.
8075 if (mDisplayFrozen) {
8076 return;
8077 }
8078 mFreezeGcPending = 0;
8079 }
8080 Runtime.getRuntime().gc();
8081 break;
8082 }
Romain Guy06882f82009-06-10 13:36:04 -07008083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008084 case ENABLE_SCREEN: {
8085 performEnableScreen();
8086 break;
8087 }
Romain Guy06882f82009-06-10 13:36:04 -07008088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 case APP_FREEZE_TIMEOUT: {
8090 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008091 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008092 int i = mAppTokens.size();
8093 while (i > 0) {
8094 i--;
8095 AppWindowToken tok = mAppTokens.get(i);
8096 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008097 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 unsetAppFreezingScreenLocked(tok, true, true);
8099 }
8100 }
8101 }
8102 break;
8103 }
Romain Guy06882f82009-06-10 13:36:04 -07008104
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008105 case SEND_NEW_CONFIGURATION: {
8106 removeMessages(SEND_NEW_CONFIGURATION);
8107 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008108 break;
8109 }
Romain Guy06882f82009-06-10 13:36:04 -07008110
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008111 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008112 if (mWindowsChanged) {
8113 synchronized (mWindowMap) {
8114 mWindowsChanged = false;
8115 }
8116 notifyWindowsChanged();
8117 }
8118 break;
8119 }
8120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 }
8122 }
8123 }
8124
8125 // -------------------------------------------------------------
8126 // IWindowManager API
8127 // -------------------------------------------------------------
8128
8129 public IWindowSession openSession(IInputMethodClient client,
8130 IInputContext inputContext) {
8131 if (client == null) throw new IllegalArgumentException("null client");
8132 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008133 Session session = new Session(client, inputContext);
8134 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008135 }
8136
8137 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8138 synchronized (mWindowMap) {
8139 // The focus for the client is the window immediately below
8140 // where we would place the input method window.
8141 int idx = findDesiredInputMethodWindowIndexLocked(false);
8142 WindowState imFocus;
8143 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008144 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 if (imFocus != null) {
8146 if (imFocus.mSession.mClient != null &&
8147 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8148 return true;
8149 }
8150 }
8151 }
8152 }
8153 return false;
8154 }
Romain Guy06882f82009-06-10 13:36:04 -07008155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008156 // -------------------------------------------------------------
8157 // Internals
8158 // -------------------------------------------------------------
8159
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008160 final WindowState windowForClientLocked(Session session, IWindow client,
8161 boolean throwOnError) {
8162 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008163 }
Romain Guy06882f82009-06-10 13:36:04 -07008164
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008165 final WindowState windowForClientLocked(Session session, IBinder client,
8166 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008167 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008168 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008169 TAG, "Looking up client " + client + ": " + win);
8170 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008171 RuntimeException ex = new IllegalArgumentException(
8172 "Requested window " + client + " does not exist");
8173 if (throwOnError) {
8174 throw ex;
8175 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008176 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008177 return null;
8178 }
8179 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008180 RuntimeException ex = new IllegalArgumentException(
8181 "Requested window " + client + " is in session " +
8182 win.mSession + ", not " + session);
8183 if (throwOnError) {
8184 throw ex;
8185 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008186 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008187 return null;
8188 }
8189
8190 return win;
8191 }
8192
Dianne Hackborna8f60182009-09-01 19:01:50 -07008193 final void rebuildAppWindowListLocked() {
8194 int NW = mWindows.size();
8195 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008196 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008197 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008198
Dianne Hackborna8f60182009-09-01 19:01:50 -07008199 // First remove all existing app windows.
8200 i=0;
8201 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008202 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008203 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008204 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008205 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008206 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008207 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008208 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008209 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008210 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008211 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8212 && lastWallpaper == i-1) {
8213 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008214 }
8215 i++;
8216 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008217
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008218 // The wallpaper window(s) typically live at the bottom of the stack,
8219 // so skip them before adding app tokens.
8220 lastWallpaper++;
8221 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008222
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008223 // First add all of the exiting app tokens... these are no longer
8224 // in the main app list, but still have windows shown. We put them
8225 // in the back because now that the animation is over we no longer
8226 // will care about them.
8227 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008228 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008229 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8230 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008231
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008232 // And add in the still active app tokens in Z order.
8233 NT = mAppTokens.size();
8234 for (int j=0; j<NT; j++) {
8235 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008237
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008238 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008239 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008240 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008241 + " windows but added " + i);
8242 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008243 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008245 private final void assignLayersLocked() {
8246 int N = mWindows.size();
8247 int curBaseLayer = 0;
8248 int curLayer = 0;
8249 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008252 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008253 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8254 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008255 curLayer += WINDOW_LAYER_MULTIPLIER;
8256 w.mLayer = curLayer;
8257 } else {
8258 curBaseLayer = curLayer = w.mBaseLayer;
8259 w.mLayer = curLayer;
8260 }
8261 if (w.mTargetAppToken != null) {
8262 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8263 } else if (w.mAppToken != null) {
8264 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8265 } else {
8266 w.mAnimLayer = w.mLayer;
8267 }
8268 if (w.mIsImWindow) {
8269 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008270 } else if (w.mIsWallpaper) {
8271 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008272 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008273 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008274 + w.mAnimLayer);
8275 //System.out.println(
8276 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8277 }
8278 }
8279
8280 private boolean mInLayout = false;
8281 private final void performLayoutAndPlaceSurfacesLocked() {
8282 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008283 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008284 throw new RuntimeException("Recursive call!");
8285 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008286 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008287 return;
8288 }
8289
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008290 if (mWaitingForConfig) {
8291 // Our configuration has changed (most likely rotation), but we
8292 // don't yet have the complete configuration to report to
8293 // applications. Don't do any window layout until we have it.
8294 return;
8295 }
8296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008297 boolean recoveringMemory = false;
8298 if (mForceRemoves != null) {
8299 recoveringMemory = true;
8300 // Wait a little it for things to settle down, and off we go.
8301 for (int i=0; i<mForceRemoves.size(); i++) {
8302 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008303 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008304 removeWindowInnerLocked(ws.mSession, ws);
8305 }
8306 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008307 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008308 Object tmp = new Object();
8309 synchronized (tmp) {
8310 try {
8311 tmp.wait(250);
8312 } catch (InterruptedException e) {
8313 }
8314 }
8315 }
Romain Guy06882f82009-06-10 13:36:04 -07008316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008317 mInLayout = true;
8318 try {
8319 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008321 int i = mPendingRemove.size()-1;
8322 if (i >= 0) {
8323 while (i >= 0) {
8324 WindowState w = mPendingRemove.get(i);
8325 removeWindowInnerLocked(w.mSession, w);
8326 i--;
8327 }
8328 mPendingRemove.clear();
8329
8330 mInLayout = false;
8331 assignLayersLocked();
8332 mLayoutNeeded = true;
8333 performLayoutAndPlaceSurfacesLocked();
8334
8335 } else {
8336 mInLayout = false;
8337 if (mLayoutNeeded) {
8338 requestAnimationLocked(0);
8339 }
8340 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008341 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008342 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8343 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008344 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008345 } catch (RuntimeException e) {
8346 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008347 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008348 }
8349 }
8350
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008351 private final int performLayoutLockedInner() {
8352 if (!mLayoutNeeded) {
8353 return 0;
8354 }
8355
8356 mLayoutNeeded = false;
8357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008358 final int dw = mDisplay.getWidth();
8359 final int dh = mDisplay.getHeight();
8360
8361 final int N = mWindows.size();
8362 int i;
8363
Joe Onorato8a9b2202010-02-26 18:56:32 -08008364 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008365 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8366
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008367 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008368
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008369 int seq = mLayoutSeq+1;
8370 if (seq < 0) seq = 0;
8371 mLayoutSeq = seq;
8372
8373 // First perform layout of any root windows (not attached
8374 // to another window).
8375 int topAttached = -1;
8376 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008377 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008378
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008379 // Don't do layout of a window if it is not visible, or
8380 // soon won't be visible, to avoid wasting time and funky
8381 // changes while a window is animating away.
8382 final AppWindowToken atoken = win.mAppToken;
8383 final boolean gone = win.mViewVisibility == View.GONE
8384 || !win.mRelayoutCalled
8385 || win.mRootToken.hidden
8386 || (atoken != null && atoken.hiddenRequested)
8387 || win.mAttachedHidden
8388 || win.mExiting || win.mDestroying;
8389
8390 if (!win.mLayoutAttached) {
8391 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8392 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8393 + " mLayoutAttached=" + win.mLayoutAttached);
8394 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8395 + win.mViewVisibility + " mRelayoutCalled="
8396 + win.mRelayoutCalled + " hidden="
8397 + win.mRootToken.hidden + " hiddenRequested="
8398 + (atoken != null && atoken.hiddenRequested)
8399 + " mAttachedHidden=" + win.mAttachedHidden);
8400 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008401
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008402 // If this view is GONE, then skip it -- keep the current
8403 // frame, and let the caller know so they can ignore it
8404 // if they want. (We do the normal layout for INVISIBLE
8405 // windows, since that means "perform layout as normal,
8406 // just don't display").
8407 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008408 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008409 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8410 win.mLayoutSeq = seq;
8411 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8412 + win.mFrame + " mContainingFrame="
8413 + win.mContainingFrame + " mDisplayFrame="
8414 + win.mDisplayFrame);
8415 } else {
8416 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008417 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008418 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008419 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008420
8421 // Now perform layout of attached windows, which usually
8422 // depend on the position of the window they are attached to.
8423 // XXX does not deal with windows that are attached to windows
8424 // that are themselves attached.
8425 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008426 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008427
8428 // If this view is GONE, then skip it -- keep the current
8429 // frame, and let the caller know so they can ignore it
8430 // if they want. (We do the normal layout for INVISIBLE
8431 // windows, since that means "perform layout as normal,
8432 // just don't display").
8433 if (win.mLayoutAttached) {
8434 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8435 + " mHaveFrame=" + win.mHaveFrame
8436 + " mViewVisibility=" + win.mViewVisibility
8437 + " mRelayoutCalled=" + win.mRelayoutCalled);
8438 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8439 || !win.mHaveFrame) {
8440 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8441 win.mLayoutSeq = seq;
8442 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8443 + win.mFrame + " mContainingFrame="
8444 + win.mContainingFrame + " mDisplayFrame="
8445 + win.mDisplayFrame);
8446 }
8447 }
8448 }
Jeff Brown349703e2010-06-22 01:27:15 -07008449
8450 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008451 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008452
8453 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008454 }
Romain Guy06882f82009-06-10 13:36:04 -07008455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008456 private final void performLayoutAndPlaceSurfacesLockedInner(
8457 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008458 if (mDisplay == null) {
8459 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8460 return;
8461 }
8462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008463 final long currentTime = SystemClock.uptimeMillis();
8464 final int dw = mDisplay.getWidth();
8465 final int dh = mDisplay.getHeight();
8466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 int i;
8468
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008469 if (mFocusMayChange) {
8470 mFocusMayChange = false;
8471 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8472 }
8473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008474 if (mFxSession == null) {
8475 mFxSession = new SurfaceSession();
8476 }
Romain Guy06882f82009-06-10 13:36:04 -07008477
Joe Onorato8a9b2202010-02-26 18:56:32 -08008478 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479
8480 // Initialize state of exiting tokens.
8481 for (i=mExitingTokens.size()-1; i>=0; i--) {
8482 mExitingTokens.get(i).hasVisible = false;
8483 }
8484
8485 // Initialize state of exiting applications.
8486 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8487 mExitingAppTokens.get(i).hasVisible = false;
8488 }
8489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008490 boolean orientationChangeComplete = true;
8491 Session holdScreen = null;
8492 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008493 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 boolean focusDisplayed = false;
8495 boolean animating = false;
8496
8497 Surface.openTransaction();
8498 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008499 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008500 int repeats = 0;
8501 int changes = 0;
8502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008503 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008504 repeats++;
8505 if (repeats > 6) {
8506 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8507 mLayoutNeeded = false;
8508 break;
8509 }
8510
8511 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8512 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8513 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8514 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8515 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8516 assignLayersLocked();
8517 mLayoutNeeded = true;
8518 }
8519 }
8520 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8521 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8522 if (updateOrientationFromAppTokensLocked()) {
8523 mLayoutNeeded = true;
8524 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8525 }
8526 }
8527 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8528 mLayoutNeeded = true;
8529 }
8530 }
8531
8532 // FIRST LOOP: Perform a layout, if needed.
8533 if (repeats < 4) {
8534 changes = performLayoutLockedInner();
8535 if (changes != 0) {
8536 continue;
8537 }
8538 } else {
8539 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8540 changes = 0;
8541 }
8542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008543 final int transactionSequence = ++mTransactionSequence;
8544
8545 // Update animations of all applications, including those
8546 // associated with exiting/removed apps
8547 boolean tokensAnimating = false;
8548 final int NAT = mAppTokens.size();
8549 for (i=0; i<NAT; i++) {
8550 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8551 tokensAnimating = true;
8552 }
8553 }
8554 final int NEAT = mExitingAppTokens.size();
8555 for (i=0; i<NEAT; i++) {
8556 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8557 tokensAnimating = true;
8558 }
8559 }
8560
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008561 // SECOND LOOP: Execute animations and update visibility of windows.
8562
Joe Onorato8a9b2202010-02-26 18:56:32 -08008563 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008564 + transactionSequence + " tokensAnimating="
8565 + tokensAnimating);
8566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008567 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568
8569 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008570 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008571 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008572
8573 mPolicy.beginAnimationLw(dw, dh);
8574
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008575 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008577 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008578 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008579
8580 final WindowManager.LayoutParams attrs = w.mAttrs;
8581
8582 if (w.mSurface != null) {
8583 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008584 if (w.commitFinishDrawingLocked(currentTime)) {
8585 if ((w.mAttrs.flags
8586 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008587 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008588 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008589 wallpaperMayChange = true;
8590 }
8591 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008592
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008593 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008594 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8595 animating = true;
8596 //w.dump(" ");
8597 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008598 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8599 wallpaperMayChange = true;
8600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008601
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008602 if (mPolicy.doesForceHide(w, attrs)) {
8603 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008604 if (DEBUG_VISIBILITY) Slog.v(TAG,
8605 "Animation done that could impact force hide: "
8606 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008607 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008608 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008609 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8610 forceHiding = true;
8611 }
8612 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8613 boolean changed;
8614 if (forceHiding) {
8615 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008616 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8617 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008618 } else {
8619 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008620 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8621 "Now policy shown: " + w);
8622 if (changed) {
8623 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008624 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008625 // Assume we will need to animate. If
8626 // we don't (because the wallpaper will
8627 // stay with the lock screen), then we will
8628 // clean up later.
8629 Animation a = mPolicy.createForceHideEnterAnimation();
8630 if (a != null) {
8631 w.setAnimation(a);
8632 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008633 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008634 if (mCurrentFocus == null ||
8635 mCurrentFocus.mLayer < w.mLayer) {
8636 // We are showing on to of the current
8637 // focus, so re-evaluate focus to make
8638 // sure it is correct.
8639 mFocusMayChange = true;
8640 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008641 }
8642 }
8643 if (changed && (attrs.flags
8644 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8645 wallpaperMayChange = true;
8646 }
8647 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008649 mPolicy.animatingWindowLw(w, attrs);
8650 }
8651
8652 final AppWindowToken atoken = w.mAppToken;
8653 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8654 if (atoken.lastTransactionSequence != transactionSequence) {
8655 atoken.lastTransactionSequence = transactionSequence;
8656 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8657 atoken.startingDisplayed = false;
8658 }
8659 if ((w.isOnScreen() || w.mAttrs.type
8660 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8661 && !w.mExiting && !w.mDestroying) {
8662 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008663 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008664 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008665 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008666 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008667 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008668 + " pv=" + w.mPolicyVisibility
8669 + " dp=" + w.mDrawPending
8670 + " cdp=" + w.mCommitDrawPending
8671 + " ah=" + w.mAttachedHidden
8672 + " th=" + atoken.hiddenRequested
8673 + " a=" + w.mAnimating);
8674 }
8675 }
8676 if (w != atoken.startingWindow) {
8677 if (!atoken.freezingScreen || !w.mAppFreezing) {
8678 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008679 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008681 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008682 "tokenMayBeDrawn: " + atoken
8683 + " freezingScreen=" + atoken.freezingScreen
8684 + " mAppFreezing=" + w.mAppFreezing);
8685 tokenMayBeDrawn = true;
8686 }
8687 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008688 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008689 atoken.startingDisplayed = true;
8690 }
8691 }
8692 } else if (w.mReadyToShow) {
8693 w.performShowLocked();
8694 }
8695 }
8696
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008697 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008698
8699 if (tokenMayBeDrawn) {
8700 // See if any windows have been drawn, so they (and others
8701 // associated with them) can now be shown.
8702 final int NT = mTokenList.size();
8703 for (i=0; i<NT; i++) {
8704 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8705 if (wtoken == null) {
8706 continue;
8707 }
8708 if (wtoken.freezingScreen) {
8709 int numInteresting = wtoken.numInterestingWindows;
8710 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008711 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008712 "allDrawn: " + wtoken
8713 + " interesting=" + numInteresting
8714 + " drawn=" + wtoken.numDrawnWindows);
8715 wtoken.showAllWindowsLocked();
8716 unsetAppFreezingScreenLocked(wtoken, false, true);
8717 orientationChangeComplete = true;
8718 }
8719 } else if (!wtoken.allDrawn) {
8720 int numInteresting = wtoken.numInterestingWindows;
8721 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008722 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008723 "allDrawn: " + wtoken
8724 + " interesting=" + numInteresting
8725 + " drawn=" + wtoken.numDrawnWindows);
8726 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008727 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728
8729 // We can now show all of the drawn windows!
8730 if (!mOpeningApps.contains(wtoken)) {
8731 wtoken.showAllWindowsLocked();
8732 }
8733 }
8734 }
8735 }
8736 }
8737
8738 // If we are ready to perform an app transition, check through
8739 // all of the app tokens to be shown and see if they are ready
8740 // to go.
8741 if (mAppTransitionReady) {
8742 int NN = mOpeningApps.size();
8743 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008744 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008745 "Checking " + NN + " opening apps (frozen="
8746 + mDisplayFrozen + " timeout="
8747 + mAppTransitionTimeout + ")...");
8748 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8749 // If the display isn't frozen, wait to do anything until
8750 // all of the apps are ready. Otherwise just go because
8751 // we'll unfreeze the display when everyone is ready.
8752 for (i=0; i<NN && goodToGo; i++) {
8753 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008754 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008755 "Check opening app" + wtoken + ": allDrawn="
8756 + wtoken.allDrawn + " startingDisplayed="
8757 + wtoken.startingDisplayed);
8758 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8759 && !wtoken.startingMoved) {
8760 goodToGo = false;
8761 }
8762 }
8763 }
8764 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008765 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008766 int transit = mNextAppTransition;
8767 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008768 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008769 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008770 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008771 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008772 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008773 mAppTransitionTimeout = false;
8774 mStartingIconInTransition = false;
8775 mSkipAppTransitionAnimation = false;
8776
8777 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8778
Dianne Hackborna8f60182009-09-01 19:01:50 -07008779 // If there are applications waiting to come to the
8780 // top of the stack, now is the time to move their windows.
8781 // (Note that we don't do apps going to the bottom
8782 // here -- we want to keep their windows in the old
8783 // Z-order until the animation completes.)
8784 if (mToTopApps.size() > 0) {
8785 NN = mAppTokens.size();
8786 for (i=0; i<NN; i++) {
8787 AppWindowToken wtoken = mAppTokens.get(i);
8788 if (wtoken.sendingToTop) {
8789 wtoken.sendingToTop = false;
8790 moveAppWindowsLocked(wtoken, NN, false);
8791 }
8792 }
8793 mToTopApps.clear();
8794 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008795
Dianne Hackborn25994b42009-09-04 14:21:19 -07008796 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008797
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008798 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008799 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008800
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008801 // The top-most window will supply the layout params,
8802 // and we will determine it below.
8803 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008804 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008805 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008806
Joe Onorato8a9b2202010-02-26 18:56:32 -08008807 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008808 "New wallpaper target=" + mWallpaperTarget
8809 + ", lower target=" + mLowerWallpaperTarget
8810 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008811 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008812 // Do a first pass through the tokens for two
8813 // things:
8814 // (1) Determine if both the closing and opening
8815 // app token sets are wallpaper targets, in which
8816 // case special animations are needed
8817 // (since the wallpaper needs to stay static
8818 // behind them).
8819 // (2) Find the layout params of the top-most
8820 // application window in the tokens, which is
8821 // what will control the animation theme.
8822 final int NC = mClosingApps.size();
8823 NN = NC + mOpeningApps.size();
8824 for (i=0; i<NN; i++) {
8825 AppWindowToken wtoken;
8826 int mode;
8827 if (i < NC) {
8828 wtoken = mClosingApps.get(i);
8829 mode = 1;
8830 } else {
8831 wtoken = mOpeningApps.get(i-NC);
8832 mode = 2;
8833 }
8834 if (mLowerWallpaperTarget != null) {
8835 if (mLowerWallpaperTarget.mAppToken == wtoken
8836 || mUpperWallpaperTarget.mAppToken == wtoken) {
8837 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008838 }
8839 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008840 if (wtoken.appFullscreen) {
8841 WindowState ws = wtoken.findMainWindow();
8842 if (ws != null) {
8843 // If this is a compatibility mode
8844 // window, we will always use its anim.
8845 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8846 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008847 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008848 bestAnimLayer = Integer.MAX_VALUE;
8849 } else if (ws.mLayer > bestAnimLayer) {
8850 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008851 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008852 bestAnimLayer = ws.mLayer;
8853 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008854 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008855 }
8856 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008857
Dianne Hackborn25994b42009-09-04 14:21:19 -07008858 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008859 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008860 "Wallpaper animation!");
8861 switch (transit) {
8862 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8863 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8864 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8865 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8866 break;
8867 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8868 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8869 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8870 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8871 break;
8872 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008873 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008874 "New transit: " + transit);
8875 } else if (oldWallpaper != null) {
8876 // We are transitioning from an activity with
8877 // a wallpaper to one without.
8878 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008879 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008880 "New transit away from wallpaper: " + transit);
8881 } else if (mWallpaperTarget != null) {
8882 // We are transitioning from an activity without
8883 // a wallpaper to now showing the wallpaper
8884 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008885 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008886 "New transit into wallpaper: " + transit);
8887 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008888
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008889 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8890 mLastEnterAnimToken = animToken;
8891 mLastEnterAnimParams = animLp;
8892 } else if (mLastEnterAnimParams != null) {
8893 animLp = mLastEnterAnimParams;
8894 mLastEnterAnimToken = null;
8895 mLastEnterAnimParams = null;
8896 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008897
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008898 // If all closing windows are obscured, then there is
8899 // no need to do an animation. This is the case, for
8900 // example, when this transition is being done behind
8901 // the lock screen.
8902 if (!mPolicy.allowAppAnimationsLw()) {
8903 animLp = null;
8904 }
8905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008906 NN = mOpeningApps.size();
8907 for (i=0; i<NN; i++) {
8908 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008909 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 "Now opening app" + wtoken);
8911 wtoken.reportedVisible = false;
8912 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008913 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008914 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008915 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008916 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008917 wtoken.showAllWindowsLocked();
8918 }
8919 NN = mClosingApps.size();
8920 for (i=0; i<NN; i++) {
8921 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008922 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008923 "Now closing app" + wtoken);
8924 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008925 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008926 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008927 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008928 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008929 // Force the allDrawn flag, because we want to start
8930 // this guy's animations regardless of whether it's
8931 // gotten drawn.
8932 wtoken.allDrawn = true;
8933 }
8934
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008935 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008937 mOpeningApps.clear();
8938 mClosingApps.clear();
8939
8940 // This has changed the visibility of windows, so perform
8941 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008942 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008943 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008944 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8945 assignLayersLocked();
8946 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008947 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008948 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008949 }
8950 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008951
Dianne Hackborn16064f92010-03-25 00:47:24 -07008952 int adjResult = 0;
8953
Dianne Hackborna8f60182009-09-01 19:01:50 -07008954 if (!animating && mAppTransitionRunning) {
8955 // We have finished the animation of an app transition. To do
8956 // this, we have delayed a lot of operations like showing and
8957 // hiding apps, moving apps in Z-order, etc. The app token list
8958 // reflects the correct Z-order, but the window list may now
8959 // be out of sync with it. So here we will just rebuild the
8960 // entire app window list. Fun!
8961 mAppTransitionRunning = false;
8962 // Clear information about apps that were moving.
8963 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008964
Dianne Hackborna8f60182009-09-01 19:01:50 -07008965 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008966 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008967 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008968 moveInputMethodWindowsIfNeededLocked(false);
8969 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008970 // Since the window list has been rebuilt, focus might
8971 // have to be recomputed since the actual order of windows
8972 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008973 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008974 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008975
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008976 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008977 // At this point, there was a window with a wallpaper that
8978 // was force hiding other windows behind it, but now it
8979 // is going away. This may be simple -- just animate
8980 // away the wallpaper and its window -- or it may be
8981 // hard -- the wallpaper now needs to be shown behind
8982 // something that was hidden.
8983 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008984 if (mLowerWallpaperTarget != null
8985 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008986 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008987 "wallpaperForceHiding changed with lower="
8988 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008989 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008990 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8991 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8992 if (mLowerWallpaperTarget.mAppToken.hidden) {
8993 // The lower target has become hidden before we
8994 // actually started the animation... let's completely
8995 // re-evaluate everything.
8996 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008997 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008998 }
8999 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009000 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009001 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009002 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009003 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009004 + " NEW: " + mWallpaperTarget
9005 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009006 if (mLowerWallpaperTarget == null) {
9007 // Whoops, we don't need a special wallpaper animation.
9008 // Clear them out.
9009 forceHiding = false;
9010 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009011 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009012 if (w.mSurface != null) {
9013 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009014 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009015 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009016 forceHiding = true;
9017 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9018 if (!w.mAnimating) {
9019 // We set the animation above so it
9020 // is not yet running.
9021 w.clearAnimation();
9022 }
9023 }
9024 }
9025 }
9026 }
9027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009028
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009029 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009030 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009031 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009032 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009033 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009034
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009035 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009036 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009037 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009038 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009039 assignLayersLocked();
9040 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009041 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009042 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009043 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009045
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009046 if (mFocusMayChange) {
9047 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009048 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009049 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009050 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009051 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009052 }
9053
9054 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009055 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009056 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009057
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009058 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9059 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009060
Jeff Browne33348b2010-07-15 23:54:05 -07009061 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009062 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009063
9064 // THIRD LOOP: Update the surfaces of all windows.
9065
9066 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9067
9068 boolean obscured = false;
9069 boolean blurring = false;
9070 boolean dimming = false;
9071 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009072 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009073 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009074
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009075 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009077 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009078 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009079
9080 boolean displayed = false;
9081 final WindowManager.LayoutParams attrs = w.mAttrs;
9082 final int attrFlags = attrs.flags;
9083
9084 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009085 // XXX NOTE: The logic here could be improved. We have
9086 // the decision about whether to resize a window separated
9087 // from whether to hide the surface. This can cause us to
9088 // resize a surface even if we are going to hide it. You
9089 // can see this by (1) holding device in landscape mode on
9090 // home screen; (2) tapping browser icon (device will rotate
9091 // to landscape; (3) tap home. The wallpaper will be resized
9092 // in step 2 but then immediately hidden, causing us to
9093 // have to resize and then redraw it again in step 3. It
9094 // would be nice to figure out how to avoid this, but it is
9095 // difficult because we do need to resize surfaces in some
9096 // cases while they are hidden such as when first showing a
9097 // window.
9098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009099 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009100 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009101 TAG, "Placing surface #" + i + " " + w.mSurface
9102 + ": new=" + w.mShownFrame + ", old="
9103 + w.mLastShownFrame);
9104
9105 boolean resize;
9106 int width, height;
9107 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9108 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9109 w.mLastRequestedHeight != w.mRequestedHeight;
9110 // for a scaled surface, we just want to use
9111 // the requested size.
9112 width = w.mRequestedWidth;
9113 height = w.mRequestedHeight;
9114 w.mLastRequestedWidth = width;
9115 w.mLastRequestedHeight = height;
9116 w.mLastShownFrame.set(w.mShownFrame);
9117 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009118 if (SHOW_TRANSACTIONS) logSurface(w,
9119 "POS " + w.mShownFrame.left
9120 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009121 w.mSurfaceX = w.mShownFrame.left;
9122 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9124 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009125 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126 if (!recoveringMemory) {
9127 reclaimSomeSurfaceMemoryLocked(w, "position");
9128 }
9129 }
9130 } else {
9131 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9132 width = w.mShownFrame.width();
9133 height = w.mShownFrame.height();
9134 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009135 }
9136
9137 if (resize) {
9138 if (width < 1) width = 1;
9139 if (height < 1) height = 1;
9140 if (w.mSurface != null) {
9141 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009142 if (SHOW_TRANSACTIONS) logSurface(w,
9143 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009144 + w.mShownFrame.top + " SIZE "
9145 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009146 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009147 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009148 w.mSurfaceW = width;
9149 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009151 w.mSurfaceX = w.mShownFrame.left;
9152 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009153 w.mSurface.setPosition(w.mShownFrame.left,
9154 w.mShownFrame.top);
9155 } catch (RuntimeException e) {
9156 // If something goes wrong with the surface (such
9157 // as running out of memory), don't take down the
9158 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009159 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009160 + "size=(" + width + "x" + height
9161 + "), pos=(" + w.mShownFrame.left
9162 + "," + w.mShownFrame.top + ")", e);
9163 if (!recoveringMemory) {
9164 reclaimSomeSurfaceMemoryLocked(w, "size");
9165 }
9166 }
9167 }
9168 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009169 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009170 w.mContentInsetsChanged =
9171 !w.mLastContentInsets.equals(w.mContentInsets);
9172 w.mVisibleInsetsChanged =
9173 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009174 boolean configChanged =
9175 w.mConfiguration != mCurConfiguration
9176 && (w.mConfiguration == null
9177 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009178 if (DEBUG_CONFIGURATION && configChanged) {
9179 Slog.v(TAG, "Win " + w + " config changed: "
9180 + mCurConfiguration);
9181 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009182 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009183 + ": configChanged=" + configChanged
9184 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009185 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009186 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009187 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009188 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009189 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009190 w.mLastFrame.set(w.mFrame);
9191 w.mLastContentInsets.set(w.mContentInsets);
9192 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009193 // If the screen is currently frozen, then keep
9194 // it frozen until this window draws at its new
9195 // orientation.
9196 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009197 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009198 "Resizing while display frozen: " + w);
9199 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009200 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009201 mWindowsFreezingScreen = true;
9202 // XXX should probably keep timeout from
9203 // when we first froze the display.
9204 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9205 mH.sendMessageDelayed(mH.obtainMessage(
9206 H.WINDOW_FREEZE_TIMEOUT), 2000);
9207 }
9208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009209 // If the orientation is changing, then we need to
9210 // hold off on unfreezing the display until this
9211 // window has been redrawn; to do that, we need
9212 // to go through the process of getting informed
9213 // by the application when it has finished drawing.
9214 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009215 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009216 "Orientation start waiting for draw in "
9217 + w + ", surface " + w.mSurface);
9218 w.mDrawPending = true;
9219 w.mCommitDrawPending = false;
9220 w.mReadyToShow = false;
9221 if (w.mAppToken != null) {
9222 w.mAppToken.allDrawn = false;
9223 }
9224 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009225 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009226 "Resizing window " + w + " to " + w.mFrame);
9227 mResizingWindows.add(w);
9228 } else if (w.mOrientationChanging) {
9229 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009230 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009231 "Orientation not waiting for draw in "
9232 + w + ", surface " + w.mSurface);
9233 w.mOrientationChanging = false;
9234 }
9235 }
9236 }
9237
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009238 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009239 if (!w.mLastHidden) {
9240 //dump();
9241 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009242 if (SHOW_TRANSACTIONS) logSurface(w,
9243 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009244 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009245 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009246 try {
9247 w.mSurface.hide();
9248 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009249 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009250 }
9251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009252 }
9253 // If we are waiting for this window to handle an
9254 // orientation change, well, it is hidden, so
9255 // doesn't really matter. Note that this does
9256 // introduce a potential glitch if the window
9257 // becomes unhidden before it has drawn for the
9258 // new orientation.
9259 if (w.mOrientationChanging) {
9260 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009261 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 "Orientation change skips hidden " + w);
9263 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009264 } else if (w.mLastLayer != w.mAnimLayer
9265 || w.mLastAlpha != w.mShownAlpha
9266 || w.mLastDsDx != w.mDsDx
9267 || w.mLastDtDx != w.mDtDx
9268 || w.mLastDsDy != w.mDsDy
9269 || w.mLastDtDy != w.mDtDy
9270 || w.mLastHScale != w.mHScale
9271 || w.mLastVScale != w.mVScale
9272 || w.mLastHidden) {
9273 displayed = true;
9274 w.mLastAlpha = w.mShownAlpha;
9275 w.mLastLayer = w.mAnimLayer;
9276 w.mLastDsDx = w.mDsDx;
9277 w.mLastDtDx = w.mDtDx;
9278 w.mLastDsDy = w.mDsDy;
9279 w.mLastDtDy = w.mDtDy;
9280 w.mLastHScale = w.mHScale;
9281 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009282 if (SHOW_TRANSACTIONS) logSurface(w,
9283 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009284 + " matrix=[" + (w.mDsDx*w.mHScale)
9285 + "," + (w.mDtDx*w.mVScale)
9286 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009287 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009288 if (w.mSurface != null) {
9289 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009290 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009291 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009292 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009293 w.mSurface.setLayer(w.mAnimLayer);
9294 w.mSurface.setMatrix(
9295 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9296 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9297 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009298 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009299 if (!recoveringMemory) {
9300 reclaimSomeSurfaceMemoryLocked(w, "update");
9301 }
9302 }
9303 }
9304
9305 if (w.mLastHidden && !w.mDrawPending
9306 && !w.mCommitDrawPending
9307 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009308 if (SHOW_TRANSACTIONS) logSurface(w,
9309 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009310 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 + " during relayout");
9312 if (showSurfaceRobustlyLocked(w)) {
9313 w.mHasDrawn = true;
9314 w.mLastHidden = false;
9315 } else {
9316 w.mOrientationChanging = false;
9317 }
9318 }
9319 if (w.mSurface != null) {
9320 w.mToken.hasVisible = true;
9321 }
9322 } else {
9323 displayed = true;
9324 }
9325
9326 if (displayed) {
9327 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009328 if (attrs.width == LayoutParams.MATCH_PARENT
9329 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009330 covered = true;
9331 }
9332 }
9333 if (w.mOrientationChanging) {
9334 if (w.mDrawPending || w.mCommitDrawPending) {
9335 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009336 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009337 "Orientation continue waiting for draw in " + w);
9338 } else {
9339 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009340 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009341 "Orientation change complete in " + w);
9342 }
9343 }
9344 w.mToken.hasVisible = true;
9345 }
9346 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009347 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009348 "Orientation change skips hidden " + w);
9349 w.mOrientationChanging = false;
9350 }
9351
9352 final boolean canBeSeen = w.isDisplayedLw();
9353
9354 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9355 focusDisplayed = true;
9356 }
9357
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009358 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009360 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009361 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009362 if (w.mSurface != null) {
9363 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9364 holdScreen = w.mSession;
9365 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009366 if (!syswin && w.mAttrs.screenBrightness >= 0
9367 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009368 screenBrightness = w.mAttrs.screenBrightness;
9369 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009370 if (!syswin && w.mAttrs.buttonBrightness >= 0
9371 && buttonBrightness < 0) {
9372 buttonBrightness = w.mAttrs.buttonBrightness;
9373 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009374 if (canBeSeen
9375 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9376 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9377 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009378 syswin = true;
9379 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009380 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009381
Dianne Hackborn25994b42009-09-04 14:21:19 -07009382 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9383 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009384 // This window completely covers everything behind it,
9385 // so we want to leave all of them as unblurred (for
9386 // performance reasons).
9387 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009388 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009389 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009390 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009391 obscured = true;
9392 if (mBackgroundFillerSurface == null) {
9393 try {
9394 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009395 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009396 0, dw, dh,
9397 PixelFormat.OPAQUE,
9398 Surface.FX_SURFACE_NORMAL);
9399 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009400 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009401 }
9402 }
9403 try {
9404 mBackgroundFillerSurface.setPosition(0, 0);
9405 mBackgroundFillerSurface.setSize(dw, dh);
9406 // Using the same layer as Dim because they will never be shown at the
9407 // same time.
9408 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9409 mBackgroundFillerSurface.show();
9410 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009411 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009412 }
9413 backgroundFillerShown = true;
9414 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009415 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009416 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009417 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009418 + ": blurring=" + blurring
9419 + " obscured=" + obscured
9420 + " displayed=" + displayed);
9421 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9422 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009423 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009424 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009425 if (mDimAnimator == null) {
9426 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009428 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009429 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009430 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009431 }
9432 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9433 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009434 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009435 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009436 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009437 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009438 + mBlurSurface + ": CREATE");
9439 try {
Romain Guy06882f82009-06-10 13:36:04 -07009440 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009441 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009442 -1, 16, 16,
9443 PixelFormat.OPAQUE,
9444 Surface.FX_SURFACE_BLUR);
9445 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009446 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447 }
9448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009449 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009450 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9451 + mBlurSurface + ": pos=(0,0) (" +
9452 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009453 mBlurSurface.setPosition(0, 0);
9454 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009455 mBlurSurface.setLayer(w.mAnimLayer-2);
9456 if (!mBlurShown) {
9457 try {
9458 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9459 + mBlurSurface + ": SHOW");
9460 mBlurSurface.show();
9461 } catch (RuntimeException e) {
9462 Slog.w(TAG, "Failure showing blur surface", e);
9463 }
9464 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009465 }
9466 }
9467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468 }
9469 }
9470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009471
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009472 if (obscuredChanged && mWallpaperTarget == w) {
9473 // This is the wallpaper target and its obscured state
9474 // changed... make sure the current wallaper's visibility
9475 // has been updated accordingly.
9476 updateWallpaperVisibilityLocked();
9477 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009478 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009479
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009480 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9481 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009482 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009483 try {
9484 mBackgroundFillerSurface.hide();
9485 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009486 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009487 }
9488 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009489
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009490 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009491 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9492 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009493 }
Romain Guy06882f82009-06-10 13:36:04 -07009494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009495 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009496 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 + ": HIDE");
9498 try {
9499 mBlurSurface.hide();
9500 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009501 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009502 }
9503 mBlurShown = false;
9504 }
9505
Joe Onorato8a9b2202010-02-26 18:56:32 -08009506 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009507 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009508 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 }
9510
Jeff Browne33348b2010-07-15 23:54:05 -07009511 mInputMonitor.updateInputWindowsLw();
9512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009513 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009514
Joe Onorato8a9b2202010-02-26 18:56:32 -08009515 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 "With display frozen, orientationChangeComplete="
9517 + orientationChangeComplete);
9518 if (orientationChangeComplete) {
9519 if (mWindowsFreezingScreen) {
9520 mWindowsFreezingScreen = false;
9521 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9522 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009523 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009524 }
Romain Guy06882f82009-06-10 13:36:04 -07009525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009526 i = mResizingWindows.size();
9527 if (i > 0) {
9528 do {
9529 i--;
9530 WindowState win = mResizingWindows.get(i);
9531 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009532 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9533 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009534 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009535 boolean configChanged =
9536 win.mConfiguration != mCurConfiguration
9537 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009538 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9539 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9540 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009541 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009542 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009543 + " / " + mCurConfiguration + " / 0x"
9544 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009545 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009546 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009547 win.mClient.resized(win.mFrame.width(),
9548 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009549 win.mLastVisibleInsets, win.mDrawPending,
9550 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 win.mContentInsetsChanged = false;
9552 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009553 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009554 } catch (RemoteException e) {
9555 win.mOrientationChanging = false;
9556 }
9557 } while (i > 0);
9558 mResizingWindows.clear();
9559 }
Romain Guy06882f82009-06-10 13:36:04 -07009560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009561 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009562 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009563 i = mDestroySurface.size();
9564 if (i > 0) {
9565 do {
9566 i--;
9567 WindowState win = mDestroySurface.get(i);
9568 win.mDestroying = false;
9569 if (mInputMethodWindow == win) {
9570 mInputMethodWindow = null;
9571 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009572 if (win == mWallpaperTarget) {
9573 wallpaperDestroyed = true;
9574 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009575 win.destroySurfaceLocked();
9576 } while (i > 0);
9577 mDestroySurface.clear();
9578 }
9579
9580 // Time to remove any exiting tokens?
9581 for (i=mExitingTokens.size()-1; i>=0; i--) {
9582 WindowToken token = mExitingTokens.get(i);
9583 if (!token.hasVisible) {
9584 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009585 if (token.windowType == TYPE_WALLPAPER) {
9586 mWallpaperTokens.remove(token);
9587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009588 }
9589 }
9590
9591 // Time to remove any exiting applications?
9592 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9593 AppWindowToken token = mExitingAppTokens.get(i);
9594 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009595 // Make sure there is no animation running on this token,
9596 // so any windows associated with it will be removed as
9597 // soon as their animations are complete
9598 token.animation = null;
9599 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009600 mAppTokens.remove(token);
9601 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009602 if (mLastEnterAnimToken == token) {
9603 mLastEnterAnimToken = null;
9604 mLastEnterAnimParams = null;
9605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009606 }
9607 }
9608
Dianne Hackborna8f60182009-09-01 19:01:50 -07009609 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009610
Dianne Hackborna8f60182009-09-01 19:01:50 -07009611 if (!animating && mAppTransitionRunning) {
9612 // We have finished the animation of an app transition. To do
9613 // this, we have delayed a lot of operations like showing and
9614 // hiding apps, moving apps in Z-order, etc. The app token list
9615 // reflects the correct Z-order, but the window list may now
9616 // be out of sync with it. So here we will just rebuild the
9617 // entire app window list. Fun!
9618 mAppTransitionRunning = false;
9619 needRelayout = true;
9620 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009621 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009622 // Clear information about apps that were moving.
9623 mToBottomApps.clear();
9624 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009626 if (focusDisplayed) {
9627 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9628 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009629 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009630 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009631 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009632 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009633 requestAnimationLocked(0);
9634 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009635 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9636 }
Jeff Browneb857f12010-07-16 10:06:33 -07009637
Jeff Browne33348b2010-07-15 23:54:05 -07009638 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009639
Jeff Brown8e03b752010-06-13 19:16:55 -07009640 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009641 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9642 mPowerManager.setScreenBrightnessOverride(-1);
9643 } else {
9644 mPowerManager.setScreenBrightnessOverride((int)
9645 (screenBrightness * Power.BRIGHTNESS_ON));
9646 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009647 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9648 mPowerManager.setButtonBrightnessOverride(-1);
9649 } else {
9650 mPowerManager.setButtonBrightnessOverride((int)
9651 (buttonBrightness * Power.BRIGHTNESS_ON));
9652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009653 if (holdScreen != mHoldingScreenOn) {
9654 mHoldingScreenOn = holdScreen;
9655 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9656 mH.sendMessage(m);
9657 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009658
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009659 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009660 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009661 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9662 LocalPowerManager.BUTTON_EVENT, true);
9663 mTurnOnScreen = false;
9664 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009665
9666 // Check to see if we are now in a state where the screen should
9667 // be enabled, because the window obscured flags have changed.
9668 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009669 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009670
9671 /**
9672 * Must be called with the main window manager lock held.
9673 */
9674 void setHoldScreenLocked(boolean holding) {
9675 boolean state = mHoldingScreenWakeLock.isHeld();
9676 if (holding != state) {
9677 if (holding) {
9678 mHoldingScreenWakeLock.acquire();
9679 } else {
9680 mPolicy.screenOnStoppedLw();
9681 mHoldingScreenWakeLock.release();
9682 }
9683 }
9684 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009685
9686 void requestAnimationLocked(long delay) {
9687 if (!mAnimationPending) {
9688 mAnimationPending = true;
9689 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9690 }
9691 }
Romain Guy06882f82009-06-10 13:36:04 -07009692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009693 /**
9694 * Have the surface flinger show a surface, robustly dealing with
9695 * error conditions. In particular, if there is not enough memory
9696 * to show the surface, then we will try to get rid of other surfaces
9697 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009698 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009699 * @return Returns true if the surface was successfully shown.
9700 */
9701 boolean showSurfaceRobustlyLocked(WindowState win) {
9702 try {
9703 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009704 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009705 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009706 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009707 if (DEBUG_VISIBILITY) Slog.v(TAG,
9708 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009709 win.mTurnOnScreen = false;
9710 mTurnOnScreen = true;
9711 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009712 }
9713 return true;
9714 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009715 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009716 }
Romain Guy06882f82009-06-10 13:36:04 -07009717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009718 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009720 return false;
9721 }
Romain Guy06882f82009-06-10 13:36:04 -07009722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009723 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9724 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009725
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009726 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009727 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009729 if (mForceRemoves == null) {
9730 mForceRemoves = new ArrayList<WindowState>();
9731 }
Romain Guy06882f82009-06-10 13:36:04 -07009732
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009733 long callingIdentity = Binder.clearCallingIdentity();
9734 try {
9735 // There was some problem... first, do a sanity check of the
9736 // window list to make sure we haven't left any dangling surfaces
9737 // around.
9738 int N = mWindows.size();
9739 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009740 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009741 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009742 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009743 if (ws.mSurface != null) {
9744 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009745 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 + ws + " surface=" + ws.mSurface
9747 + " token=" + win.mToken
9748 + " pid=" + ws.mSession.mPid
9749 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009750 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009751 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009752 ws.mSurface = null;
9753 mForceRemoves.add(ws);
9754 i--;
9755 N--;
9756 leakedSurface = true;
9757 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009758 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009759 + ws + " surface=" + ws.mSurface
9760 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009761 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009762 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009763 ws.mSurface = null;
9764 leakedSurface = true;
9765 }
9766 }
9767 }
Romain Guy06882f82009-06-10 13:36:04 -07009768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 boolean killedApps = false;
9770 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009771 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 SparseIntArray pidCandidates = new SparseIntArray();
9773 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009774 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 if (ws.mSurface != null) {
9776 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9777 }
9778 }
9779 if (pidCandidates.size() > 0) {
9780 int[] pids = new int[pidCandidates.size()];
9781 for (int i=0; i<pids.length; i++) {
9782 pids[i] = pidCandidates.keyAt(i);
9783 }
9784 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009785 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009786 killedApps = true;
9787 }
9788 } catch (RemoteException e) {
9789 }
9790 }
9791 }
Romain Guy06882f82009-06-10 13:36:04 -07009792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009793 if (leakedSurface || killedApps) {
9794 // We managed to reclaim some memory, so get rid of the trouble
9795 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009796 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009797 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009798 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009799 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 win.mSurface = null;
9801 }
Romain Guy06882f82009-06-10 13:36:04 -07009802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009803 try {
9804 win.mClient.dispatchGetNewSurface();
9805 } catch (RemoteException e) {
9806 }
9807 }
9808 } finally {
9809 Binder.restoreCallingIdentity(callingIdentity);
9810 }
9811 }
Romain Guy06882f82009-06-10 13:36:04 -07009812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 private boolean updateFocusedWindowLocked(int mode) {
9814 WindowState newFocus = computeFocusedWindowLocked();
9815 if (mCurrentFocus != newFocus) {
9816 // This check makes sure that we don't already have the focus
9817 // change message pending.
9818 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9819 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009820 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009821 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9822 final WindowState oldFocus = mCurrentFocus;
9823 mCurrentFocus = newFocus;
9824 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 final WindowState imWindow = mInputMethodWindow;
9827 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009828 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009830 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9831 mLayoutNeeded = true;
9832 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009833 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9834 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009835 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9836 // Client will do the layout, but we need to assign layers
9837 // for handleNewWindowLocked() below.
9838 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 }
9840 }
Jeff Brown349703e2010-06-22 01:27:15 -07009841
9842 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9843 // If we defer assigning layers, then the caller is responsible for
9844 // doing this part.
9845 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009847 return true;
9848 }
9849 return false;
9850 }
Jeff Brown349703e2010-06-22 01:27:15 -07009851
9852 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009853 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855
9856 private WindowState computeFocusedWindowLocked() {
9857 WindowState result = null;
9858 WindowState win;
9859
9860 int i = mWindows.size() - 1;
9861 int nextAppIndex = mAppTokens.size()-1;
9862 WindowToken nextApp = nextAppIndex >= 0
9863 ? mAppTokens.get(nextAppIndex) : null;
9864
9865 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009866 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867
Joe Onorato8a9b2202010-02-26 18:56:32 -08009868 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009869 TAG, "Looking for focus: " + i
9870 + " = " + win
9871 + ", flags=" + win.mAttrs.flags
9872 + ", canReceive=" + win.canReceiveKeys());
9873
9874 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009875
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009876 // If this window's application has been removed, just skip it.
9877 if (thisApp != null && thisApp.removed) {
9878 i--;
9879 continue;
9880 }
Romain Guy06882f82009-06-10 13:36:04 -07009881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 // If there is a focused app, don't allow focus to go to any
9883 // windows below it. If this is an application window, step
9884 // through the app tokens until we find its app.
9885 if (thisApp != null && nextApp != null && thisApp != nextApp
9886 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9887 int origAppIndex = nextAppIndex;
9888 while (nextAppIndex > 0) {
9889 if (nextApp == mFocusedApp) {
9890 // Whoops, we are below the focused app... no focus
9891 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009892 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 TAG, "Reached focused app: " + mFocusedApp);
9894 return null;
9895 }
9896 nextAppIndex--;
9897 nextApp = mAppTokens.get(nextAppIndex);
9898 if (nextApp == thisApp) {
9899 break;
9900 }
9901 }
9902 if (thisApp != nextApp) {
9903 // Uh oh, the app token doesn't exist! This shouldn't
9904 // happen, but if it does we can get totally hosed...
9905 // so restart at the original app.
9906 nextAppIndex = origAppIndex;
9907 nextApp = mAppTokens.get(nextAppIndex);
9908 }
9909 }
9910
9911 // Dispatch to this window if it is wants key events.
9912 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009913 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009914 TAG, "Found focus @ " + i + " = " + win);
9915 result = win;
9916 break;
9917 }
9918
9919 i--;
9920 }
9921
9922 return result;
9923 }
9924
9925 private void startFreezingDisplayLocked() {
9926 if (mDisplayFrozen) {
9927 return;
9928 }
Romain Guy06882f82009-06-10 13:36:04 -07009929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009930 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009932 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009933 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009934 if (mFreezeGcPending != 0) {
9935 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009936 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937 mH.removeMessages(H.FORCE_GC);
9938 Runtime.getRuntime().gc();
9939 mFreezeGcPending = now;
9940 }
9941 } else {
9942 mFreezeGcPending = now;
9943 }
Romain Guy06882f82009-06-10 13:36:04 -07009944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009945 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009946
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009947 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009948
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009949 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9950 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009951 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009952 mAppTransitionReady = true;
9953 }
Romain Guy06882f82009-06-10 13:36:04 -07009954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955 if (PROFILE_ORIENTATION) {
9956 File file = new File("/data/system/frozen");
9957 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9958 }
9959 Surface.freezeDisplay(0);
9960 }
Romain Guy06882f82009-06-10 13:36:04 -07009961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009962 private void stopFreezingDisplayLocked() {
9963 if (!mDisplayFrozen) {
9964 return;
9965 }
Romain Guy06882f82009-06-10 13:36:04 -07009966
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009967 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9968 return;
9969 }
9970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009971 mDisplayFrozen = false;
9972 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9973 if (PROFILE_ORIENTATION) {
9974 Debug.stopMethodTracing();
9975 }
9976 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009977
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009978 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009979
Christopher Tateb696aee2010-04-02 19:08:30 -07009980 // While the display is frozen we don't re-compute the orientation
9981 // to avoid inconsistent states. However, something interesting
9982 // could have actually changed during that time so re-evaluate it
9983 // now to catch that.
9984 if (updateOrientationFromAppTokensLocked()) {
9985 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9986 }
9987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009988 // A little kludge: a lot could have happened while the
9989 // display was frozen, so now that we are coming back we
9990 // do a gc so that any remote references the system
9991 // processes holds on others can be released if they are
9992 // no longer needed.
9993 mH.removeMessages(H.FORCE_GC);
9994 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9995 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009997 mScreenFrozenLock.release();
9998 }
Romain Guy06882f82009-06-10 13:36:04 -07009999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 @Override
10001 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10002 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10003 != PackageManager.PERMISSION_GRANTED) {
10004 pw.println("Permission Denial: can't dump WindowManager from from pid="
10005 + Binder.getCallingPid()
10006 + ", uid=" + Binder.getCallingUid());
10007 return;
10008 }
Romain Guy06882f82009-06-10 13:36:04 -070010009
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010010 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010011 pw.println(" ");
10012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010013 synchronized(mWindowMap) {
10014 pw.println("Current Window Manager state:");
10015 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010016 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010017 pw.print(" Window #"); pw.print(i); pw.print(' ');
10018 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010019 w.dump(pw, " ");
10020 }
10021 if (mInputMethodDialogs.size() > 0) {
10022 pw.println(" ");
10023 pw.println(" Input method dialogs:");
10024 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10025 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010026 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010027 }
10028 }
10029 if (mPendingRemove.size() > 0) {
10030 pw.println(" ");
10031 pw.println(" Remove pending for:");
10032 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10033 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010034 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10035 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010036 w.dump(pw, " ");
10037 }
10038 }
10039 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10040 pw.println(" ");
10041 pw.println(" Windows force removing:");
10042 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10043 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010044 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10045 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 w.dump(pw, " ");
10047 }
10048 }
10049 if (mDestroySurface.size() > 0) {
10050 pw.println(" ");
10051 pw.println(" Windows waiting to destroy their surface:");
10052 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10053 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010054 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10055 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010056 w.dump(pw, " ");
10057 }
10058 }
10059 if (mLosingFocus.size() > 0) {
10060 pw.println(" ");
10061 pw.println(" Windows losing focus:");
10062 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10063 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010064 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10065 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010066 w.dump(pw, " ");
10067 }
10068 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010069 if (mResizingWindows.size() > 0) {
10070 pw.println(" ");
10071 pw.println(" Windows waiting to resize:");
10072 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10073 WindowState w = mResizingWindows.get(i);
10074 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10075 pw.print(w); pw.println(":");
10076 w.dump(pw, " ");
10077 }
10078 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010079 if (mSessions.size() > 0) {
10080 pw.println(" ");
10081 pw.println(" All active sessions:");
10082 Iterator<Session> it = mSessions.iterator();
10083 while (it.hasNext()) {
10084 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010085 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010086 s.dump(pw, " ");
10087 }
10088 }
10089 if (mTokenMap.size() > 0) {
10090 pw.println(" ");
10091 pw.println(" All tokens:");
10092 Iterator<WindowToken> it = mTokenMap.values().iterator();
10093 while (it.hasNext()) {
10094 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010095 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010096 token.dump(pw, " ");
10097 }
10098 }
10099 if (mTokenList.size() > 0) {
10100 pw.println(" ");
10101 pw.println(" Window token list:");
10102 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010103 pw.print(" #"); pw.print(i); pw.print(": ");
10104 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010105 }
10106 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010107 if (mWallpaperTokens.size() > 0) {
10108 pw.println(" ");
10109 pw.println(" Wallpaper tokens:");
10110 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10111 WindowToken token = mWallpaperTokens.get(i);
10112 pw.print(" Wallpaper #"); pw.print(i);
10113 pw.print(' '); pw.print(token); pw.println(':');
10114 token.dump(pw, " ");
10115 }
10116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010117 if (mAppTokens.size() > 0) {
10118 pw.println(" ");
10119 pw.println(" Application tokens in Z order:");
10120 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010121 pw.print(" App #"); pw.print(i); pw.print(": ");
10122 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 }
10124 }
10125 if (mFinishedStarting.size() > 0) {
10126 pw.println(" ");
10127 pw.println(" Finishing start of application tokens:");
10128 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10129 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010130 pw.print(" Finished Starting #"); pw.print(i);
10131 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010132 token.dump(pw, " ");
10133 }
10134 }
10135 if (mExitingTokens.size() > 0) {
10136 pw.println(" ");
10137 pw.println(" Exiting tokens:");
10138 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10139 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010140 pw.print(" Exiting #"); pw.print(i);
10141 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010142 token.dump(pw, " ");
10143 }
10144 }
10145 if (mExitingAppTokens.size() > 0) {
10146 pw.println(" ");
10147 pw.println(" Exiting application tokens:");
10148 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10149 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010150 pw.print(" Exiting App #"); pw.print(i);
10151 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010152 token.dump(pw, " ");
10153 }
10154 }
10155 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010156 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10157 pw.print(" mLastFocus="); pw.println(mLastFocus);
10158 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10159 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10160 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010161 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010162 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10163 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10164 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10165 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010166 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10167 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10168 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010169 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10170 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10171 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10172 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010173 if (mDimAnimator != null) {
10174 mDimAnimator.printTo(pw);
10175 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010176 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010177 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010178 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010179 pw.print(mInputMethodAnimLayerAdjustment);
10180 pw.print(" mWallpaperAnimLayerAdjustment=");
10181 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010182 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10183 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010184 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10185 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010186 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10187 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010188 pw.print(" mRotation="); pw.print(mRotation);
10189 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10190 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10191 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10192 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10193 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10194 pw.print(" mNextAppTransition=0x");
10195 pw.print(Integer.toHexString(mNextAppTransition));
10196 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010197 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010198 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010199 if (mNextAppTransitionPackage != null) {
10200 pw.print(" mNextAppTransitionPackage=");
10201 pw.print(mNextAppTransitionPackage);
10202 pw.print(", mNextAppTransitionEnter=0x");
10203 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10204 pw.print(", mNextAppTransitionExit=0x");
10205 pw.print(Integer.toHexString(mNextAppTransitionExit));
10206 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010207 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10208 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010209 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10210 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10211 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10212 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010213 if (mOpeningApps.size() > 0) {
10214 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10215 }
10216 if (mClosingApps.size() > 0) {
10217 pw.print(" mClosingApps="); pw.println(mClosingApps);
10218 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010219 if (mToTopApps.size() > 0) {
10220 pw.print(" mToTopApps="); pw.println(mToTopApps);
10221 }
10222 if (mToBottomApps.size() > 0) {
10223 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10224 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010225 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10226 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010227 }
10228 }
10229
Jeff Brown349703e2010-06-22 01:27:15 -070010230 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010231 public void monitor() {
10232 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010233 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010234 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010235
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010236 /**
10237 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010238 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010239 */
10240 private static class DimAnimator {
10241 Surface mDimSurface;
10242 boolean mDimShown = false;
10243 float mDimCurrentAlpha;
10244 float mDimTargetAlpha;
10245 float mDimDeltaPerMs;
10246 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010247
10248 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010249
10250 DimAnimator (SurfaceSession session) {
10251 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010252 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010253 + mDimSurface + ": CREATE");
10254 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010255 mDimSurface = new Surface(session, 0,
10256 "DimSurface",
10257 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010258 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010259 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010260 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010261 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010262 }
10263 }
10264 }
10265
10266 /**
10267 * Show the dim surface.
10268 */
10269 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010270 if (!mDimShown) {
10271 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10272 dw + "x" + dh + ")");
10273 mDimShown = true;
10274 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010275 mLastDimWidth = dw;
10276 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010277 mDimSurface.setPosition(0, 0);
10278 mDimSurface.setSize(dw, dh);
10279 mDimSurface.show();
10280 } catch (RuntimeException e) {
10281 Slog.w(TAG, "Failure showing dim surface", e);
10282 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010283 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10284 mLastDimWidth = dw;
10285 mLastDimHeight = dh;
10286 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010287 }
10288 }
10289
10290 /**
10291 * Set's the dim surface's layer and update dim parameters that will be used in
10292 * {@link updateSurface} after all windows are examined.
10293 */
10294 void updateParameters(WindowState w, long currentTime) {
10295 mDimSurface.setLayer(w.mAnimLayer-1);
10296
10297 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010298 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010299 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010300 if (mDimTargetAlpha != target) {
10301 // If the desired dim level has changed, then
10302 // start an animation to it.
10303 mLastDimAnimTime = currentTime;
10304 long duration = (w.mAnimating && w.mAnimation != null)
10305 ? w.mAnimation.computeDurationHint()
10306 : DEFAULT_DIM_DURATION;
10307 if (target > mDimTargetAlpha) {
10308 // This is happening behind the activity UI,
10309 // so we can make it run a little longer to
10310 // give a stronger impression without disrupting
10311 // the user.
10312 duration *= DIM_DURATION_MULTIPLIER;
10313 }
10314 if (duration < 1) {
10315 // Don't divide by zero
10316 duration = 1;
10317 }
10318 mDimTargetAlpha = target;
10319 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10320 }
10321 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010322
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010323 /**
10324 * Updating the surface's alpha. Returns true if the animation continues, or returns
10325 * false when the animation is finished and the dim surface is hidden.
10326 */
10327 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10328 if (!dimming) {
10329 if (mDimTargetAlpha != 0) {
10330 mLastDimAnimTime = currentTime;
10331 mDimTargetAlpha = 0;
10332 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10333 }
10334 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010335
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010336 boolean animating = false;
10337 if (mLastDimAnimTime != 0) {
10338 mDimCurrentAlpha += mDimDeltaPerMs
10339 * (currentTime-mLastDimAnimTime);
10340 boolean more = true;
10341 if (displayFrozen) {
10342 // If the display is frozen, there is no reason to animate.
10343 more = false;
10344 } else if (mDimDeltaPerMs > 0) {
10345 if (mDimCurrentAlpha > mDimTargetAlpha) {
10346 more = false;
10347 }
10348 } else if (mDimDeltaPerMs < 0) {
10349 if (mDimCurrentAlpha < mDimTargetAlpha) {
10350 more = false;
10351 }
10352 } else {
10353 more = false;
10354 }
10355
10356 // Do we need to continue animating?
10357 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010358 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010359 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10360 mLastDimAnimTime = currentTime;
10361 mDimSurface.setAlpha(mDimCurrentAlpha);
10362 animating = true;
10363 } else {
10364 mDimCurrentAlpha = mDimTargetAlpha;
10365 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010366 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010367 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10368 mDimSurface.setAlpha(mDimCurrentAlpha);
10369 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010370 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010371 + ": HIDE");
10372 try {
10373 mDimSurface.hide();
10374 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010375 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010376 }
10377 mDimShown = false;
10378 }
10379 }
10380 }
10381 return animating;
10382 }
10383
10384 public void printTo(PrintWriter pw) {
10385 pw.print(" mDimShown="); pw.print(mDimShown);
10386 pw.print(" current="); pw.print(mDimCurrentAlpha);
10387 pw.print(" target="); pw.print(mDimTargetAlpha);
10388 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10389 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10390 }
10391 }
10392
10393 /**
10394 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10395 * This is used for opening/closing transition for apps in compatible mode.
10396 */
10397 private static class FadeInOutAnimation extends Animation {
10398 int mWidth;
10399 boolean mFadeIn;
10400
10401 public FadeInOutAnimation(boolean fadeIn) {
10402 setInterpolator(new AccelerateInterpolator());
10403 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10404 mFadeIn = fadeIn;
10405 }
10406
10407 @Override
10408 protected void applyTransformation(float interpolatedTime, Transformation t) {
10409 float x = interpolatedTime;
10410 if (!mFadeIn) {
10411 x = 1.0f - x; // reverse the interpolation for fade out
10412 }
10413 if (x < 0.5) {
10414 // move the window out of the screen.
10415 t.getMatrix().setTranslate(mWidth, 0);
10416 } else {
10417 t.getMatrix().setTranslate(0, 0);// show
10418 t.setAlpha((x - 0.5f) * 2);
10419 }
10420 }
10421
10422 @Override
10423 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10424 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10425 mWidth = width;
10426 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010427
10428 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010429 public int getZAdjustment() {
10430 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010431 }
10432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010433}