blob: 37a2a588fa2e778294cdfb2051a518ab9f08608a [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 Brown46b9ac02010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700106import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107import android.view.KeyEvent;
108import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109import android.view.Surface;
110import android.view.SurfaceSession;
111import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700112import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.ViewTreeObserver;
114import android.view.WindowManager;
115import android.view.WindowManagerImpl;
116import android.view.WindowManagerPolicy;
117import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700118import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119import android.view.animation.Animation;
120import android.view.animation.AnimationUtils;
121import android.view.animation.Transformation;
122
123import java.io.BufferedWriter;
124import java.io.File;
125import java.io.FileDescriptor;
126import java.io.IOException;
127import java.io.OutputStream;
128import java.io.OutputStreamWriter;
129import java.io.PrintWriter;
130import java.io.StringWriter;
131import java.net.Socket;
132import java.util.ArrayList;
133import java.util.HashMap;
134import java.util.HashSet;
135import java.util.Iterator;
136import java.util.List;
137
138/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700139public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700140 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
143 static final boolean DEBUG_FOCUS = false;
144 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800145 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800146 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 static final boolean DEBUG_LAYERS = false;
148 static final boolean DEBUG_INPUT = false;
149 static final boolean DEBUG_INPUT_METHOD = false;
150 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700151 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700153 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 static final boolean DEBUG_APP_TRANSITIONS = false;
155 static final boolean DEBUG_STARTING_WINDOW = false;
156 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700157 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700158 static final boolean DEBUG_FREEZE = 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 */
335 final ArrayList mWindows = new ArrayList();
336
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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown00fa7bd2010-07-02 15:37:36 -0700633 mInputManager = new InputManager(context, this, pmc, mPowerManager);
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
668 private void placeWindowAfter(Object pos, WindowState window) {
669 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
677 private void placeWindowBefore(Object pos, WindowState window) {
678 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
690 ArrayList localmWindows = mWindows;
691 int jmax = localmWindows.size();
692 if(jmax == 0) {
693 return -1;
694 }
695 for(int j = (jmax-1); j >= 0; j--) {
696 WindowState wentry = (WindowState)localmWindows.get(j);
697 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;
707 final ArrayList 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();
752 Object pos = null;
753 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.
Romain Guy06882f82009-06-10 13:36:04 -0700772 WindowToken atoken =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 mTokenMap.get(((WindowState)pos).mClient.asBinder());
774 if (atoken != null) {
775 final int NC = atoken.windows.size();
776 if (NC > 0) {
777 WindowState bottom = atoken.windows.get(0);
778 if (bottom.mSubLayer < 0) {
779 pos = bottom;
780 }
781 }
782 }
783 placeWindowBefore(pos, win);
784 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700785 // Continue looking down until we find the first
786 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 while (i >= 0) {
788 AppWindowToken t = mAppTokens.get(i);
789 final int NW = t.windows.size();
790 if (NW > 0) {
791 pos = t.windows.get(NW-1);
792 break;
793 }
794 i--;
795 }
796 if (pos != null) {
797 // Move in front of any windows attached to this
798 // one.
799 WindowToken atoken =
800 mTokenMap.get(((WindowState)pos).mClient.asBinder());
801 if (atoken != null) {
802 final int NC = atoken.windows.size();
803 if (NC > 0) {
804 WindowState top = atoken.windows.get(NC-1);
805 if (top.mSubLayer >= 0) {
806 pos = top;
807 }
808 }
809 }
810 placeWindowAfter(pos, win);
811 } else {
812 // Just search for the start of this layer.
813 final int myLayer = win.mBaseLayer;
814 for (i=0; i<N; i++) {
815 WindowState w = (WindowState)localmWindows.get(i);
816 if (w.mBaseLayer > myLayer) {
817 break;
818 }
819 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800820 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700821 TAG, "Adding window " + win + " at "
822 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700824 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 }
826 }
827 }
828 } else {
829 // Figure out where window should go, based on layer.
830 final int myLayer = win.mBaseLayer;
831 for (i=N-1; i>=0; i--) {
832 if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) {
833 i++;
834 break;
835 }
836 }
837 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800838 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700839 TAG, "Adding window " + win + " at "
840 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700842 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 }
844 if (addToToken) {
845 token.windows.add(tokenWindowsPos, win);
846 }
847
848 } else {
849 // Figure out this window's ordering relative to the window
850 // it is attached to.
851 final int NA = token.windows.size();
852 final int sublayer = win.mSubLayer;
853 int largestSublayer = Integer.MIN_VALUE;
854 WindowState windowWithLargestSublayer = null;
855 for (i=0; i<NA; i++) {
856 WindowState w = token.windows.get(i);
857 final int wSublayer = w.mSubLayer;
858 if (wSublayer >= largestSublayer) {
859 largestSublayer = wSublayer;
860 windowWithLargestSublayer = w;
861 }
862 if (sublayer < 0) {
863 // For negative sublayers, we go below all windows
864 // in the same sublayer.
865 if (wSublayer >= sublayer) {
866 if (addToToken) {
867 token.windows.add(i, win);
868 }
869 placeWindowBefore(
870 wSublayer >= 0 ? attached : w, win);
871 break;
872 }
873 } else {
874 // For positive sublayers, we go above all windows
875 // in the same sublayer.
876 if (wSublayer > sublayer) {
877 if (addToToken) {
878 token.windows.add(i, win);
879 }
880 placeWindowBefore(w, win);
881 break;
882 }
883 }
884 }
885 if (i >= NA) {
886 if (addToToken) {
887 token.windows.add(win);
888 }
889 if (sublayer < 0) {
890 placeWindowBefore(attached, win);
891 } else {
892 placeWindowAfter(largestSublayer >= 0
893 ? windowWithLargestSublayer
894 : attached,
895 win);
896 }
897 }
898 }
Romain Guy06882f82009-06-10 13:36:04 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 if (win.mAppToken != null && addToToken) {
901 win.mAppToken.allAppWindows.add(win);
902 }
903 }
Romain Guy06882f82009-06-10 13:36:04 -0700904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 static boolean canBeImeTarget(WindowState w) {
906 final int fl = w.mAttrs.flags
907 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
908 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
909 return w.isVisibleOrAdding();
910 }
911 return false;
912 }
Romain Guy06882f82009-06-10 13:36:04 -0700913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
915 final ArrayList localmWindows = mWindows;
916 final int N = localmWindows.size();
917 WindowState w = null;
918 int i = N;
919 while (i > 0) {
920 i--;
921 w = (WindowState)localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700922
Joe Onorato8a9b2202010-02-26 18:56:32 -0800923 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 // + Integer.toHexString(w.mAttrs.flags));
925 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800926 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 // Yet more tricksyness! If this window is a "starting"
929 // window, we do actually want to be on top of it, but
930 // it is not -really- where input will go. So if the caller
931 // is not actually looking to move the IME, look down below
932 // for a real window to target...
933 if (!willMove
934 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
935 && i > 0) {
936 WindowState wb = (WindowState)localmWindows.get(i-1);
937 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
938 i--;
939 w = wb;
940 }
941 }
942 break;
943 }
944 }
Romain Guy06882f82009-06-10 13:36:04 -0700945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700947
Joe Onorato8a9b2202010-02-26 18:56:32 -0800948 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 if (willMove && w != null) {
952 final WindowState curTarget = mInputMethodTarget;
953 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 // Now some fun for dealing with window animations that
956 // modify the Z order. We need to look at all windows below
957 // the current target that are in this app, finding the highest
958 // visible one in layering.
959 AppWindowToken token = curTarget.mAppToken;
960 WindowState highestTarget = null;
961 int highestPos = 0;
962 if (token.animating || token.animation != null) {
963 int pos = 0;
964 pos = localmWindows.indexOf(curTarget);
965 while (pos >= 0) {
966 WindowState win = (WindowState)localmWindows.get(pos);
967 if (win.mAppToken != token) {
968 break;
969 }
970 if (!win.mRemoved) {
971 if (highestTarget == null || win.mAnimLayer >
972 highestTarget.mAnimLayer) {
973 highestTarget = win;
974 highestPos = pos;
975 }
976 }
977 pos--;
978 }
979 }
Romain Guy06882f82009-06-10 13:36:04 -0700980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800982 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 + mNextAppTransition + " " + highestTarget
984 + " animating=" + highestTarget.isAnimating()
985 + " layer=" + highestTarget.mAnimLayer
986 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700987
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700988 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 // If we are currently setting up for an animation,
990 // hold everything until we can find out what will happen.
991 mInputMethodTargetWaitingAnim = true;
992 mInputMethodTarget = highestTarget;
993 return highestPos + 1;
994 } else if (highestTarget.isAnimating() &&
995 highestTarget.mAnimLayer > w.mAnimLayer) {
996 // If the window we are currently targeting is involved
997 // with an animation, and it is on top of the next target
998 // we will be over, then hold off on moving until
999 // that is done.
1000 mInputMethodTarget = highestTarget;
1001 return highestPos + 1;
1002 }
1003 }
1004 }
1005 }
Romain Guy06882f82009-06-10 13:36:04 -07001006
Joe Onorato8a9b2202010-02-26 18:56:32 -08001007 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 if (w != null) {
1009 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001010 if (DEBUG_INPUT_METHOD) {
1011 RuntimeException e = null;
1012 if (!HIDE_STACK_CRAWLS) {
1013 e = new RuntimeException();
1014 e.fillInStackTrace();
1015 }
1016 Slog.w(TAG, "Moving IM target from "
1017 + mInputMethodTarget + " to " + w, e);
1018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 mInputMethodTarget = w;
1020 if (w.mAppToken != null) {
1021 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1022 } else {
1023 setInputMethodAnimLayerAdjustment(0);
1024 }
1025 }
1026 return i+1;
1027 }
1028 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001029 if (DEBUG_INPUT_METHOD) {
1030 RuntimeException e = null;
1031 if (!HIDE_STACK_CRAWLS) {
1032 e = new RuntimeException();
1033 e.fillInStackTrace();
1034 }
1035 Slog.w(TAG, "Moving IM target from "
1036 + mInputMethodTarget + " to null", e);
1037 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 mInputMethodTarget = null;
1039 setInputMethodAnimLayerAdjustment(0);
1040 }
1041 return -1;
1042 }
Romain Guy06882f82009-06-10 13:36:04 -07001043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 void addInputMethodWindowToListLocked(WindowState win) {
1045 int pos = findDesiredInputMethodWindowIndexLocked(true);
1046 if (pos >= 0) {
1047 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001048 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001049 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001051 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 moveInputMethodDialogsLocked(pos+1);
1053 return;
1054 }
1055 win.mTargetAppToken = null;
1056 addWindowToListInOrderLocked(win, true);
1057 moveInputMethodDialogsLocked(pos);
1058 }
Romain Guy06882f82009-06-10 13:36:04 -07001059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001061 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 mInputMethodAnimLayerAdjustment = adj;
1063 WindowState imw = mInputMethodWindow;
1064 if (imw != null) {
1065 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 + " anim layer: " + imw.mAnimLayer);
1068 int wi = imw.mChildWindows.size();
1069 while (wi > 0) {
1070 wi--;
1071 WindowState cw = (WindowState)imw.mChildWindows.get(wi);
1072 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001073 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 + " anim layer: " + cw.mAnimLayer);
1075 }
1076 }
1077 int di = mInputMethodDialogs.size();
1078 while (di > 0) {
1079 di --;
1080 imw = mInputMethodDialogs.get(di);
1081 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001082 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 + " anim layer: " + imw.mAnimLayer);
1084 }
1085 }
Romain Guy06882f82009-06-10 13:36:04 -07001086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1088 int wpos = mWindows.indexOf(win);
1089 if (wpos >= 0) {
1090 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001091 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001093 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 int NC = win.mChildWindows.size();
1095 while (NC > 0) {
1096 NC--;
1097 WindowState cw = (WindowState)win.mChildWindows.get(NC);
1098 int cpos = mWindows.indexOf(cw);
1099 if (cpos >= 0) {
1100 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001101 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001102 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 mWindows.remove(cpos);
1104 }
1105 }
1106 }
1107 return interestingPos;
1108 }
Romain Guy06882f82009-06-10 13:36:04 -07001109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 private void reAddWindowToListInOrderLocked(WindowState win) {
1111 addWindowToListInOrderLocked(win, false);
1112 // This is a hack to get all of the child windows added as well
1113 // at the right position. Child windows should be rare and
1114 // this case should be rare, so it shouldn't be that big a deal.
1115 int wpos = mWindows.indexOf(win);
1116 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001117 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001118 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001120 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 reAddWindowLocked(wpos, win);
1122 }
1123 }
Romain Guy06882f82009-06-10 13:36:04 -07001124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 void logWindowList(String prefix) {
1126 int N = mWindows.size();
1127 while (N > 0) {
1128 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001129 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 }
1131 }
Romain Guy06882f82009-06-10 13:36:04 -07001132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 void moveInputMethodDialogsLocked(int pos) {
1134 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001137 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 for (int i=0; i<N; i++) {
1139 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1140 }
1141 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001142 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 logWindowList(" ");
1144 }
Romain Guy06882f82009-06-10 13:36:04 -07001145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 if (pos >= 0) {
1147 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1148 if (pos < mWindows.size()) {
1149 WindowState wp = (WindowState)mWindows.get(pos);
1150 if (wp == mInputMethodWindow) {
1151 pos++;
1152 }
1153 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001154 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 for (int i=0; i<N; i++) {
1156 WindowState win = dialogs.get(i);
1157 win.mTargetAppToken = targetAppToken;
1158 pos = reAddWindowLocked(pos, win);
1159 }
1160 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001161 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 logWindowList(" ");
1163 }
1164 return;
1165 }
1166 for (int i=0; i<N; i++) {
1167 WindowState win = dialogs.get(i);
1168 win.mTargetAppToken = null;
1169 reAddWindowToListInOrderLocked(win);
1170 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001171 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 logWindowList(" ");
1173 }
1174 }
1175 }
Romain Guy06882f82009-06-10 13:36:04 -07001176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1178 final WindowState imWin = mInputMethodWindow;
1179 final int DN = mInputMethodDialogs.size();
1180 if (imWin == null && DN == 0) {
1181 return false;
1182 }
Romain Guy06882f82009-06-10 13:36:04 -07001183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1185 if (imPos >= 0) {
1186 // In this case, the input method windows are to be placed
1187 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 // First check to see if the input method windows are already
1190 // located here, and contiguous.
1191 final int N = mWindows.size();
1192 WindowState firstImWin = imPos < N
1193 ? (WindowState)mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 // Figure out the actual input method window that should be
1196 // at the bottom of their stack.
1197 WindowState baseImWin = imWin != null
1198 ? imWin : mInputMethodDialogs.get(0);
1199 if (baseImWin.mChildWindows.size() > 0) {
1200 WindowState cw = (WindowState)baseImWin.mChildWindows.get(0);
1201 if (cw.mSubLayer < 0) baseImWin = cw;
1202 }
Romain Guy06882f82009-06-10 13:36:04 -07001203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001204 if (firstImWin == baseImWin) {
1205 // The windows haven't moved... but are they still contiguous?
1206 // First find the top IM window.
1207 int pos = imPos+1;
1208 while (pos < N) {
1209 if (!((WindowState)mWindows.get(pos)).mIsImWindow) {
1210 break;
1211 }
1212 pos++;
1213 }
1214 pos++;
1215 // Now there should be no more input method windows above.
1216 while (pos < N) {
1217 if (((WindowState)mWindows.get(pos)).mIsImWindow) {
1218 break;
1219 }
1220 pos++;
1221 }
1222 if (pos >= N) {
1223 // All is good!
1224 return false;
1225 }
1226 }
Romain Guy06882f82009-06-10 13:36:04 -07001227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 if (imWin != null) {
1229 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001230 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 logWindowList(" ");
1232 }
1233 imPos = tmpRemoveWindowLocked(imPos, imWin);
1234 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001235 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 logWindowList(" ");
1237 }
1238 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1239 reAddWindowLocked(imPos, imWin);
1240 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001241 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 logWindowList(" ");
1243 }
1244 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1245 } else {
1246 moveInputMethodDialogsLocked(imPos);
1247 }
Romain Guy06882f82009-06-10 13:36:04 -07001248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 } else {
1250 // In this case, the input method windows go in a fixed layer,
1251 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001254 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 tmpRemoveWindowLocked(0, imWin);
1256 imWin.mTargetAppToken = null;
1257 reAddWindowToListInOrderLocked(imWin);
1258 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001259 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 logWindowList(" ");
1261 }
1262 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1263 } else {
1264 moveInputMethodDialogsLocked(-1);;
1265 }
Romain Guy06882f82009-06-10 13:36:04 -07001266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 }
Romain Guy06882f82009-06-10 13:36:04 -07001268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 if (needAssignLayers) {
1270 assignLayersLocked();
1271 }
Romain Guy06882f82009-06-10 13:36:04 -07001272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 return true;
1274 }
Romain Guy06882f82009-06-10 13:36:04 -07001275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 void adjustInputMethodDialogsLocked() {
1277 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1278 }
Romain Guy06882f82009-06-10 13:36:04 -07001279
Dianne Hackborn25994b42009-09-04 14:21:19 -07001280 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001281 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001282 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1283 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1284 ? wallpaperTarget.mAppToken.animation : null)
1285 + " upper=" + mUpperWallpaperTarget
1286 + " lower=" + mLowerWallpaperTarget);
1287 return (wallpaperTarget != null
1288 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1289 && wallpaperTarget.mAppToken.animation != null)))
1290 || mUpperWallpaperTarget != null
1291 || mLowerWallpaperTarget != null;
1292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001293
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001294 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1295 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001296
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001297 int adjustWallpaperWindowsLocked() {
1298 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001299
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001300 final int dw = mDisplay.getWidth();
1301 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001302
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001303 // First find top-most window that has asked to be on top of the
1304 // wallpaper; all wallpapers go behind it.
1305 final ArrayList localmWindows = mWindows;
1306 int N = localmWindows.size();
1307 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001308 WindowState foundW = null;
1309 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001310 WindowState topCurW = null;
1311 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001312 int i = N;
1313 while (i > 0) {
1314 i--;
1315 w = (WindowState)localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001316 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1317 if (topCurW == null) {
1318 topCurW = w;
1319 topCurI = i;
1320 }
1321 continue;
1322 }
1323 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001324 if (w.mAppToken != null) {
1325 // If this window's app token is hidden and not animating,
1326 // it is of no interest to us.
1327 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001328 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001329 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001330 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001331 continue;
1332 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001333 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001334 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001335 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1336 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001337 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001338 && (mWallpaperTarget == w
1339 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001340 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001341 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001342 foundW = w;
1343 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001344 if (w == mWallpaperTarget && ((w.mAppToken != null
1345 && w.mAppToken.animation != null)
1346 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001347 // The current wallpaper target is animating, so we'll
1348 // look behind it for another possible target and figure
1349 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001350 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001351 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001352 continue;
1353 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001354 break;
1355 }
1356 }
1357
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001358 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001359 // If we are currently waiting for an app transition, and either
1360 // the current target or the next target are involved with it,
1361 // then hold off on doing anything with the wallpaper.
1362 // Note that we are checking here for just whether the target
1363 // is part of an app token... which is potentially overly aggressive
1364 // (the app token may not be involved in the transition), but good
1365 // enough (we'll just wait until whatever transition is pending
1366 // executes).
1367 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001368 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001369 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001370 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001371 }
1372 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001373 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001374 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001375 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001376 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001377 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001378
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001379 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001380 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001381 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001382 + " oldTarget: " + mWallpaperTarget);
1383 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001384
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001385 mLowerWallpaperTarget = null;
1386 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001387
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001388 WindowState oldW = mWallpaperTarget;
1389 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001390
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001391 // Now what is happening... if the current and new targets are
1392 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001393 if (foundW != null && oldW != null) {
1394 boolean oldAnim = oldW.mAnimation != null
1395 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1396 boolean foundAnim = foundW.mAnimation != null
1397 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001398 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001399 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001400 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001402 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001403 int oldI = localmWindows.indexOf(oldW);
1404 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001406 }
1407 if (oldI >= 0) {
1408 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001409 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001410 + "=" + oldW + "; new#" + foundI
1411 + "=" + foundW);
1412 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001413
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001414 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001415 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001416 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001417 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001418 }
1419 mWallpaperTarget = oldW;
1420 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001421
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001422 // Now set the upper and lower wallpaper targets
1423 // correctly, and make sure that we are positioning
1424 // the wallpaper below the lower.
1425 if (foundI > oldI) {
1426 // The new target is on top of the old one.
1427 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001428 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001429 }
1430 mUpperWallpaperTarget = foundW;
1431 mLowerWallpaperTarget = oldW;
1432 foundW = oldW;
1433 foundI = oldI;
1434 } else {
1435 // The new target is below the old one.
1436 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001437 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001438 }
1439 mUpperWallpaperTarget = oldW;
1440 mLowerWallpaperTarget = foundW;
1441 }
1442 }
1443 }
1444 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001445
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001446 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001447 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001448 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1449 || (mLowerWallpaperTarget.mAppToken != null
1450 && mLowerWallpaperTarget.mAppToken.animation != null);
1451 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1452 || (mUpperWallpaperTarget.mAppToken != null
1453 && mUpperWallpaperTarget.mAppToken.animation != null);
1454 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001455 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001456 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001457 }
1458 mLowerWallpaperTarget = null;
1459 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001460 }
1461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001462
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001463 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001464 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001465 // The window is visible to the compositor... but is it visible
1466 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001467 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001468 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001469
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001470 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001471 // its layer adjustment. Only do this if we are not transfering
1472 // between two wallpaper targets.
1473 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001474 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001475 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001476
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001477 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1478 * TYPE_LAYER_MULTIPLIER
1479 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001480
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001481 // Now w is the window we are supposed to be behind... but we
1482 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001483 // AND any starting window associated with it, AND below the
1484 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001485 while (foundI > 0) {
1486 WindowState wb = (WindowState)localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001487 if (wb.mBaseLayer < maxLayer &&
1488 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001489 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001490 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001491 // This window is not related to the previous one in any
1492 // interesting way, so stop here.
1493 break;
1494 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001495 foundW = wb;
1496 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001497 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001498 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001499 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001500 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001501
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001502 if (foundW == null && topCurW != null) {
1503 // There is no wallpaper target, so it goes at the bottom.
1504 // We will assume it is the same place as last time, if known.
1505 foundW = topCurW;
1506 foundI = topCurI+1;
1507 } else {
1508 // Okay i is the position immediately above the wallpaper. Look at
1509 // what is below it for later.
1510 foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
1511 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001512
Dianne Hackborn284ac932009-08-28 10:34:25 -07001513 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001514 if (mWallpaperTarget.mWallpaperX >= 0) {
1515 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001516 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001517 }
1518 if (mWallpaperTarget.mWallpaperY >= 0) {
1519 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001520 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001521 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001523
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001524 // Start stepping backwards from here, ensuring that our wallpaper windows
1525 // are correctly placed.
1526 int curTokenIndex = mWallpaperTokens.size();
1527 while (curTokenIndex > 0) {
1528 curTokenIndex--;
1529 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001530 if (token.hidden == visible) {
1531 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1532 token.hidden = !visible;
1533 // Need to do a layout to ensure the wallpaper now has the
1534 // correct size.
1535 mLayoutNeeded = true;
1536 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001537
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001538 int curWallpaperIndex = token.windows.size();
1539 while (curWallpaperIndex > 0) {
1540 curWallpaperIndex--;
1541 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001543 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001544 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001545 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001546
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001547 // First, make sure the client has the current visibility
1548 // state.
1549 if (wallpaper.mWallpaperVisible != visible) {
1550 wallpaper.mWallpaperVisible = visible;
1551 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001552 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001553 "Setting visibility of wallpaper " + wallpaper
1554 + ": " + visible);
1555 wallpaper.mClient.dispatchAppVisibility(visible);
1556 } catch (RemoteException e) {
1557 }
1558 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001559
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001560 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001561 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001562 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001563
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001564 // First, if this window is at the current index, then all
1565 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001566 if (wallpaper == foundW) {
1567 foundI--;
1568 foundW = foundI > 0
1569 ? (WindowState)localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001570 continue;
1571 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001572
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001573 // The window didn't match... the current wallpaper window,
1574 // wherever it is, is in the wrong place, so make sure it is
1575 // not in the list.
1576 int oldIndex = localmWindows.indexOf(wallpaper);
1577 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001578 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001579 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001580 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001581 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001582 if (oldIndex < foundI) {
1583 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001584 }
1585 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001586
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001587 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001588 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001589 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001590 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001591
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001592 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001593 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001594 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001595 }
1596 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001597
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001598 return changed;
1599 }
1600
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001601 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001602 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001603 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001604 mWallpaperAnimLayerAdjustment = adj;
1605 int curTokenIndex = mWallpaperTokens.size();
1606 while (curTokenIndex > 0) {
1607 curTokenIndex--;
1608 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1609 int curWallpaperIndex = token.windows.size();
1610 while (curWallpaperIndex > 0) {
1611 curWallpaperIndex--;
1612 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1613 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001614 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001615 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001616 }
1617 }
1618 }
1619
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001620 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1621 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001622 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001623 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001624 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001625 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001626 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1627 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1628 changed = wallpaperWin.mXOffset != offset;
1629 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001630 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001631 + wallpaperWin + " x: " + offset);
1632 wallpaperWin.mXOffset = offset;
1633 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001634 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001635 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001636 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001637 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001638 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001639
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001640 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001641 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001642 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1643 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1644 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001645 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001646 + wallpaperWin + " y: " + offset);
1647 changed = true;
1648 wallpaperWin.mYOffset = offset;
1649 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001650 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001651 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001652 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001653 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001654 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001655
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001656 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001657 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001658 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001659 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1660 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001661 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001662 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001663 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001664 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001665 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1666 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001667 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001668 if (mWaitingOnWallpaper != null) {
1669 long start = SystemClock.uptimeMillis();
1670 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1671 < start) {
1672 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001673 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001674 "Waiting for offset complete...");
1675 mWindowMap.wait(WALLPAPER_TIMEOUT);
1676 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001677 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001679 if ((start+WALLPAPER_TIMEOUT)
1680 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001681 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001682 + wallpaperWin);
1683 mLastWallpaperTimeoutTime = start;
1684 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001685 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001686 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001687 }
1688 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001689 } catch (RemoteException e) {
1690 }
1691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001692
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001693 return changed;
1694 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001695
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001696 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001697 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001698 if (mWaitingOnWallpaper != null &&
1699 mWaitingOnWallpaper.mClient.asBinder() == window) {
1700 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001701 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001702 }
1703 }
1704 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001706 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001707 final int dw = mDisplay.getWidth();
1708 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001709
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001710 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001711
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001712 WindowState target = mWallpaperTarget;
1713 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001714 if (target.mWallpaperX >= 0) {
1715 mLastWallpaperX = target.mWallpaperX;
1716 } else if (changingTarget.mWallpaperX >= 0) {
1717 mLastWallpaperX = changingTarget.mWallpaperX;
1718 }
1719 if (target.mWallpaperY >= 0) {
1720 mLastWallpaperY = target.mWallpaperY;
1721 } else if (changingTarget.mWallpaperY >= 0) {
1722 mLastWallpaperY = changingTarget.mWallpaperY;
1723 }
1724 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001725
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001726 int curTokenIndex = mWallpaperTokens.size();
1727 while (curTokenIndex > 0) {
1728 curTokenIndex--;
1729 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1730 int curWallpaperIndex = token.windows.size();
1731 while (curWallpaperIndex > 0) {
1732 curWallpaperIndex--;
1733 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1734 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1735 wallpaper.computeShownFrameLocked();
1736 changed = true;
1737 // We only want to be synchronous with one wallpaper.
1738 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001739 }
1740 }
1741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001742
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001743 return changed;
1744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001746 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001747 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001748 final int dw = mDisplay.getWidth();
1749 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001751 int curTokenIndex = mWallpaperTokens.size();
1752 while (curTokenIndex > 0) {
1753 curTokenIndex--;
1754 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001755 if (token.hidden == visible) {
1756 token.hidden = !visible;
1757 // Need to do a layout to ensure the wallpaper now has the
1758 // correct size.
1759 mLayoutNeeded = true;
1760 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001761
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001762 int curWallpaperIndex = token.windows.size();
1763 while (curWallpaperIndex > 0) {
1764 curWallpaperIndex--;
1765 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1766 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001767 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001768 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001769
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001770 if (wallpaper.mWallpaperVisible != visible) {
1771 wallpaper.mWallpaperVisible = visible;
1772 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001773 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001774 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001775 + ": " + visible);
1776 wallpaper.mClient.dispatchAppVisibility(visible);
1777 } catch (RemoteException e) {
1778 }
1779 }
1780 }
1781 }
1782 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001784 public int addWindow(Session session, IWindow client,
1785 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001786 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 int res = mPolicy.checkAddPermission(attrs);
1788 if (res != WindowManagerImpl.ADD_OKAY) {
1789 return res;
1790 }
Romain Guy06882f82009-06-10 13:36:04 -07001791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 boolean reportNewConfig = false;
1793 WindowState attachedWindow = null;
1794 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 synchronized(mWindowMap) {
1797 // Instantiating a Display requires talking with the simulator,
1798 // so don't do it until we know the system is mostly up and
1799 // running.
1800 if (mDisplay == null) {
1801 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1802 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001803 mInitialDisplayWidth = mDisplay.getWidth();
1804 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001805 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 reportNewConfig = true;
1807 }
Romain Guy06882f82009-06-10 13:36:04 -07001808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001810 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1812 }
1813
1814 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001815 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001817 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 + attrs.token + ". Aborting.");
1819 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1820 }
1821 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1822 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001823 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 + attrs.token + ". Aborting.");
1825 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1826 }
1827 }
1828
1829 boolean addToken = false;
1830 WindowToken token = mTokenMap.get(attrs.token);
1831 if (token == null) {
1832 if (attrs.type >= FIRST_APPLICATION_WINDOW
1833 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001834 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001835 + attrs.token + ". Aborting.");
1836 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1837 }
1838 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001839 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 + attrs.token + ". Aborting.");
1841 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1842 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001843 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001844 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001845 + attrs.token + ". Aborting.");
1846 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1847 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 token = new WindowToken(attrs.token, -1, false);
1849 addToken = true;
1850 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1851 && attrs.type <= LAST_APPLICATION_WINDOW) {
1852 AppWindowToken atoken = token.appWindowToken;
1853 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001854 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 + token + ". Aborting.");
1856 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1857 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001858 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001859 + token + ". Aborting.");
1860 return WindowManagerImpl.ADD_APP_EXITING;
1861 }
1862 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1863 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1866 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1867 }
1868 } else if (attrs.type == TYPE_INPUT_METHOD) {
1869 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001870 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 + attrs.token + ". Aborting.");
1872 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1873 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001874 } else if (attrs.type == TYPE_WALLPAPER) {
1875 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001876 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001877 + attrs.token + ". Aborting.");
1878 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 }
1881
1882 win = new WindowState(session, client, token,
1883 attachedWindow, attrs, viewVisibility);
1884 if (win.mDeathRecipient == null) {
1885 // Client has apparently died, so there is no reason to
1886 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001887 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 + " that is dead, aborting.");
1889 return WindowManagerImpl.ADD_APP_EXITING;
1890 }
1891
1892 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 res = mPolicy.prepareAddWindowLw(win, attrs);
1895 if (res != WindowManagerImpl.ADD_OKAY) {
1896 return res;
1897 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001898
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001899 if (outInputChannel != null) {
1900 String name = win.makeInputChannelName();
1901 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1902 win.mInputChannel = inputChannels[0];
1903 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1904
1905 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001906 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001907
1908 // From now on, no exceptions or errors allowed!
1909
1910 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001914 if (addToken) {
1915 mTokenMap.put(attrs.token, token);
1916 mTokenList.add(token);
1917 }
1918 win.attach();
1919 mWindowMap.put(client.asBinder(), win);
1920
1921 if (attrs.type == TYPE_APPLICATION_STARTING &&
1922 token.appWindowToken != null) {
1923 token.appWindowToken.startingWindow = win;
1924 }
1925
1926 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 if (attrs.type == TYPE_INPUT_METHOD) {
1929 mInputMethodWindow = win;
1930 addInputMethodWindowToListLocked(win);
1931 imMayMove = false;
1932 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1933 mInputMethodDialogs.add(win);
1934 addWindowToListInOrderLocked(win, true);
1935 adjustInputMethodDialogsLocked();
1936 imMayMove = false;
1937 } else {
1938 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001939 if (attrs.type == TYPE_WALLPAPER) {
1940 mLastWallpaperTimeoutTime = 0;
1941 adjustWallpaperWindowsLocked();
1942 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001943 adjustWallpaperWindowsLocked();
1944 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 }
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 if (mInTouchMode) {
1952 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1953 }
1954 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1955 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1956 }
Romain Guy06882f82009-06-10 13:36:04 -07001957
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001958 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001960 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1961 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001962 imMayMove = false;
1963 }
1964 }
Romain Guy06882f82009-06-10 13:36:04 -07001965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001967 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 }
Romain Guy06882f82009-06-10 13:36:04 -07001969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 assignLayersLocked();
1971 // Don't do layout here, the window must call
1972 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 //dump();
1975
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001976 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001977 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001978 }
Jeff Brown349703e2010-06-22 01:27:15 -07001979
Joe Onorato8a9b2202010-02-26 18:56:32 -08001980 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 TAG, "New client " + client.asBinder()
1982 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001983
1984 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1985 reportNewConfig = true;
1986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 }
1988
1989 // sendNewConfiguration() checks caller permissions so we must call it with
1990 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1991 // identity anyway, so it's safe to just clear & restore around this whole
1992 // block.
1993 final long origId = Binder.clearCallingIdentity();
1994 if (reportNewConfig) {
1995 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 }
1997 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 return res;
2000 }
Romain Guy06882f82009-06-10 13:36:04 -07002001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 public void removeWindow(Session session, IWindow client) {
2003 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002004 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 if (win == null) {
2006 return;
2007 }
2008 removeWindowLocked(session, win);
2009 }
2010 }
Romain Guy06882f82009-06-10 13:36:04 -07002011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 public void removeWindowLocked(Session session, WindowState win) {
2013
Joe Onorato8a9b2202010-02-26 18:56:32 -08002014 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015 TAG, "Remove " + win + " client="
2016 + Integer.toHexString(System.identityHashCode(
2017 win.mClient.asBinder()))
2018 + ", surface=" + win.mSurface);
2019
2020 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002021
2022 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002023
Joe Onorato8a9b2202010-02-26 18:56:32 -08002024 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2026 + " mExiting=" + win.mExiting
2027 + " isAnimating=" + win.isAnimating()
2028 + " app-animation="
2029 + (win.mAppToken != null ? win.mAppToken.animation : null)
2030 + " inPendingTransaction="
2031 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2032 + " mDisplayFrozen=" + mDisplayFrozen);
2033 // Visibility of the removed window. Will be used later to update orientation later on.
2034 boolean wasVisible = false;
2035 // First, see if we need to run an animation. If we do, we have
2036 // to hold off on removing the window until the animation is done.
2037 // If the display is frozen, just remove immediately, since the
2038 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002039 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040 // If we are not currently running the exit animation, we
2041 // need to see about starting one.
2042 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2045 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2046 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2047 }
2048 // Try starting an animation.
2049 if (applyAnimationLocked(win, transit, false)) {
2050 win.mExiting = true;
2051 }
2052 }
2053 if (win.mExiting || win.isAnimating()) {
2054 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002055 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 win.mExiting = true;
2057 win.mRemoveOnExit = true;
2058 mLayoutNeeded = true;
2059 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2060 performLayoutAndPlaceSurfacesLocked();
2061 if (win.mAppToken != null) {
2062 win.mAppToken.updateReportedVisibilityLocked();
2063 }
2064 //dump();
2065 Binder.restoreCallingIdentity(origId);
2066 return;
2067 }
2068 }
2069
2070 removeWindowInnerLocked(session, win);
2071 // Removing a visible window will effect the computed orientation
2072 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002073 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002074 != mForcedAppOrientation
2075 && updateOrientationFromAppTokensLocked()) {
2076 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002077 }
2078 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2079 Binder.restoreCallingIdentity(origId);
2080 }
Romain Guy06882f82009-06-10 13:36:04 -07002081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002085 if (mInputMethodTarget == win) {
2086 moveInputMethodWindowsIfNeededLocked(false);
2087 }
Romain Guy06882f82009-06-10 13:36:04 -07002088
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002089 if (false) {
2090 RuntimeException e = new RuntimeException("here");
2091 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002092 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002093 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 mPolicy.removeWindowLw(win);
2096 win.removeLocked();
2097
2098 mWindowMap.remove(win.mClient.asBinder());
2099 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002100 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002101 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102
2103 if (mInputMethodWindow == win) {
2104 mInputMethodWindow = null;
2105 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2106 mInputMethodDialogs.remove(win);
2107 }
Romain Guy06882f82009-06-10 13:36:04 -07002108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 final WindowToken token = win.mToken;
2110 final AppWindowToken atoken = win.mAppToken;
2111 token.windows.remove(win);
2112 if (atoken != null) {
2113 atoken.allAppWindows.remove(win);
2114 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002115 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002116 TAG, "**** Removing window " + win + ": count="
2117 + token.windows.size());
2118 if (token.windows.size() == 0) {
2119 if (!token.explicit) {
2120 mTokenMap.remove(token.token);
2121 mTokenList.remove(token);
2122 } else if (atoken != null) {
2123 atoken.firstWindowDrawn = false;
2124 }
2125 }
2126
2127 if (atoken != null) {
2128 if (atoken.startingWindow == win) {
2129 atoken.startingWindow = null;
2130 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2131 // If this is the last window and we had requested a starting
2132 // transition window, well there is no point now.
2133 atoken.startingData = null;
2134 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2135 // If this is the last window except for a starting transition
2136 // window, we need to get rid of the starting transition.
2137 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002138 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 + ": no more real windows");
2140 }
2141 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2142 mH.sendMessage(m);
2143 }
2144 }
Romain Guy06882f82009-06-10 13:36:04 -07002145
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002146 if (win.mAttrs.type == TYPE_WALLPAPER) {
2147 mLastWallpaperTimeoutTime = 0;
2148 adjustWallpaperWindowsLocked();
2149 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002150 adjustWallpaperWindowsLocked();
2151 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 if (!mInLayout) {
2154 assignLayersLocked();
2155 mLayoutNeeded = true;
2156 performLayoutAndPlaceSurfacesLocked();
2157 if (win.mAppToken != null) {
2158 win.mAppToken.updateReportedVisibilityLocked();
2159 }
2160 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002161
2162 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002163 }
2164
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002165 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2166 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2167 + ": " + msg + " / " + w.mAttrs.getTitle();
2168 if (where != null) {
2169 Slog.i(TAG, str, where);
2170 } else {
2171 Slog.i(TAG, str);
2172 }
2173 }
2174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2176 long origId = Binder.clearCallingIdentity();
2177 try {
2178 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002179 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002181 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 Surface.openTransaction();
2183 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002184 if (SHOW_TRANSACTIONS) logSurface(w,
2185 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 w.mSurface.setTransparentRegionHint(region);
2187 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002188 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 Surface.closeTransaction();
2190 }
2191 }
2192 }
2193 } finally {
2194 Binder.restoreCallingIdentity(origId);
2195 }
2196 }
2197
2198 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002199 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002200 Rect visibleInsets) {
2201 long origId = Binder.clearCallingIdentity();
2202 try {
2203 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002204 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 if (w != null) {
2206 w.mGivenInsetsPending = false;
2207 w.mGivenContentInsets.set(contentInsets);
2208 w.mGivenVisibleInsets.set(visibleInsets);
2209 w.mTouchableInsets = touchableInsets;
2210 mLayoutNeeded = true;
2211 performLayoutAndPlaceSurfacesLocked();
2212 }
2213 }
2214 } finally {
2215 Binder.restoreCallingIdentity(origId);
2216 }
2217 }
Romain Guy06882f82009-06-10 13:36:04 -07002218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 public void getWindowDisplayFrame(Session session, IWindow client,
2220 Rect outDisplayFrame) {
2221 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002222 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 if (win == null) {
2224 outDisplayFrame.setEmpty();
2225 return;
2226 }
2227 outDisplayFrame.set(win.mDisplayFrame);
2228 }
2229 }
2230
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002231 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2232 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002233 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2234 window.mWallpaperX = x;
2235 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002236 window.mWallpaperXStep = xStep;
2237 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002238 if (updateWallpaperOffsetLocked(window, true)) {
2239 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002240 }
2241 }
2242 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002243
Dianne Hackborn75804932009-10-20 20:15:20 -07002244 void wallpaperCommandComplete(IBinder window, Bundle result) {
2245 synchronized (mWindowMap) {
2246 if (mWaitingOnWallpaper != null &&
2247 mWaitingOnWallpaper.mClient.asBinder() == window) {
2248 mWaitingOnWallpaper = null;
2249 mWindowMap.notifyAll();
2250 }
2251 }
2252 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002253
Dianne Hackborn75804932009-10-20 20:15:20 -07002254 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2255 String action, int x, int y, int z, Bundle extras, boolean sync) {
2256 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2257 || window == mUpperWallpaperTarget) {
2258 boolean doWait = sync;
2259 int curTokenIndex = mWallpaperTokens.size();
2260 while (curTokenIndex > 0) {
2261 curTokenIndex--;
2262 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2263 int curWallpaperIndex = token.windows.size();
2264 while (curWallpaperIndex > 0) {
2265 curWallpaperIndex--;
2266 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2267 try {
2268 wallpaper.mClient.dispatchWallpaperCommand(action,
2269 x, y, z, extras, sync);
2270 // We only want to be synchronous with one wallpaper.
2271 sync = false;
2272 } catch (RemoteException e) {
2273 }
2274 }
2275 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002276
Dianne Hackborn75804932009-10-20 20:15:20 -07002277 if (doWait) {
2278 // XXX Need to wait for result.
2279 }
2280 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002281
Dianne Hackborn75804932009-10-20 20:15:20 -07002282 return null;
2283 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 public int relayoutWindow(Session session, IWindow client,
2286 WindowManager.LayoutParams attrs, int requestedWidth,
2287 int requestedHeight, int viewVisibility, boolean insetsPending,
2288 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002289 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 boolean displayed = false;
2291 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002292 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002296 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 if (win == null) {
2298 return 0;
2299 }
2300 win.mRequestedWidth = requestedWidth;
2301 win.mRequestedHeight = requestedHeight;
2302
2303 if (attrs != null) {
2304 mPolicy.adjustWindowParamsLw(attrs);
2305 }
Romain Guy06882f82009-06-10 13:36:04 -07002306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 int attrChanges = 0;
2308 int flagChanges = 0;
2309 if (attrs != null) {
2310 flagChanges = win.mAttrs.flags ^= attrs.flags;
2311 attrChanges = win.mAttrs.copyFrom(attrs);
2312 }
2313
Joe Onorato8a9b2202010-02-26 18:56:32 -08002314 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315
2316 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2317 win.mAlpha = attrs.alpha;
2318 }
2319
2320 final boolean scaledWindow =
2321 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2322
2323 if (scaledWindow) {
2324 // requested{Width|Height} Surface's physical size
2325 // attrs.{width|height} Size on screen
2326 win.mHScale = (attrs.width != requestedWidth) ?
2327 (attrs.width / (float)requestedWidth) : 1.0f;
2328 win.mVScale = (attrs.height != requestedHeight) ?
2329 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002330 } else {
2331 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 }
2333
2334 boolean imMayMove = (flagChanges&(
2335 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2336 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 boolean focusMayChange = win.mViewVisibility != viewVisibility
2339 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2340 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002341
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002342 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2343 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 win.mRelayoutCalled = true;
2346 final int oldVisibility = win.mViewVisibility;
2347 win.mViewVisibility = viewVisibility;
2348 if (viewVisibility == View.VISIBLE &&
2349 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2350 displayed = !win.isVisibleLw();
2351 if (win.mExiting) {
2352 win.mExiting = false;
2353 win.mAnimation = null;
2354 }
2355 if (win.mDestroying) {
2356 win.mDestroying = false;
2357 mDestroySurface.remove(win);
2358 }
2359 if (oldVisibility == View.GONE) {
2360 win.mEnterAnimationPending = true;
2361 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002362 if (displayed) {
2363 if (win.mSurface != null && !win.mDrawPending
2364 && !win.mCommitDrawPending && !mDisplayFrozen
2365 && mPolicy.isScreenOn()) {
2366 applyEnterAnimationLocked(win);
2367 }
2368 if ((win.mAttrs.flags
2369 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2370 if (DEBUG_VISIBILITY) Slog.v(TAG,
2371 "Relayout window turning screen on: " + win);
2372 win.mTurnOnScreen = true;
2373 }
2374 int diff = 0;
2375 if (win.mConfiguration != mCurConfiguration
2376 && (win.mConfiguration == null
2377 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2378 win.mConfiguration = mCurConfiguration;
2379 if (DEBUG_CONFIGURATION) {
2380 Slog.i(TAG, "Window " + win + " visible with new config: "
2381 + win.mConfiguration + " / 0x"
2382 + Integer.toHexString(diff));
2383 }
2384 outConfig.setTo(mCurConfiguration);
2385 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002386 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2388 // To change the format, we need to re-build the surface.
2389 win.destroySurfaceLocked();
2390 displayed = true;
2391 }
2392 try {
2393 Surface surface = win.createSurfaceLocked();
2394 if (surface != null) {
2395 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002396 win.mReportDestroySurface = false;
2397 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002398 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002399 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002401 // For some reason there isn't a surface. Clear the
2402 // caller's object so they see the same state.
2403 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 }
2405 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002406 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002407 + client + " (" + win.mAttrs.getTitle() + ")",
2408 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 Binder.restoreCallingIdentity(origId);
2410 return 0;
2411 }
2412 if (displayed) {
2413 focusMayChange = true;
2414 }
2415 if (win.mAttrs.type == TYPE_INPUT_METHOD
2416 && mInputMethodWindow == null) {
2417 mInputMethodWindow = win;
2418 imMayMove = true;
2419 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002420 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2421 && win.mAppToken != null
2422 && win.mAppToken.startingWindow != null) {
2423 // Special handling of starting window over the base
2424 // window of the app: propagate lock screen flags to it,
2425 // to provide the correct semantics while starting.
2426 final int mask =
2427 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002428 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2429 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002430 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2431 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 } else {
2434 win.mEnterAnimationPending = false;
2435 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002436 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002437 + ": mExiting=" + win.mExiting
2438 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 // If we are not currently running the exit animation, we
2440 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002441 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 // Try starting an animation; if there isn't one, we
2443 // can destroy the surface right away.
2444 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2445 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2446 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2447 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002448 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002450 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 win.mExiting = true;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002452 mInputMonitor.windowIsBecomingInvisibleLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 } else if (win.isAnimating()) {
2454 // Currently in a hide animation... turn this into
2455 // an exit.
2456 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002457 } else if (win == mWallpaperTarget) {
2458 // If the wallpaper is currently behind this
2459 // window, we need to change both of them inside
2460 // of a transaction to avoid artifacts.
2461 win.mExiting = true;
2462 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 } else {
2464 if (mInputMethodWindow == win) {
2465 mInputMethodWindow = null;
2466 }
2467 win.destroySurfaceLocked();
2468 }
2469 }
2470 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002471
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002472 if (win.mSurface == null || (win.getAttrs().flags
2473 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2474 || win.mSurfacePendingDestroy) {
2475 // We are being called from a local process, which
2476 // means outSurface holds its current surface. Ensure the
2477 // surface object is cleared, but we don't want it actually
2478 // destroyed at this point.
2479 win.mSurfacePendingDestroy = false;
2480 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002481 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002482 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002483 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002484 "Keeping surface, will report destroy: " + win);
2485 win.mReportDestroySurface = true;
2486 outSurface.copyFrom(win.mSurface);
2487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 }
2489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 if (focusMayChange) {
2491 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2492 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 imMayMove = false;
2494 }
2495 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2496 }
Romain Guy06882f82009-06-10 13:36:04 -07002497
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002498 // updateFocusedWindowLocked() already assigned layers so we only need to
2499 // reassign them at this point if the IM window state gets shuffled
2500 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002503 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2504 // Little hack here -- we -should- be able to rely on the
2505 // function to return true if the IME has moved and needs
2506 // its layer recomputed. However, if the IME was hidden
2507 // and isn't actually moved in the list, its layer may be
2508 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 assignLayers = true;
2510 }
2511 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002512 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002513 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002514 assignLayers = true;
2515 }
2516 }
Romain Guy06882f82009-06-10 13:36:04 -07002517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 mLayoutNeeded = true;
2519 win.mGivenInsetsPending = insetsPending;
2520 if (assignLayers) {
2521 assignLayersLocked();
2522 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002523 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002525 if (displayed && win.mIsWallpaper) {
2526 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002527 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 if (win.mAppToken != null) {
2530 win.mAppToken.updateReportedVisibilityLocked();
2531 }
2532 outFrame.set(win.mFrame);
2533 outContentInsets.set(win.mContentInsets);
2534 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002535 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002537 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 + ", requestedHeight=" + requestedHeight
2539 + ", viewVisibility=" + viewVisibility
2540 + "\nRelayout returning frame=" + outFrame
2541 + ", surface=" + outSurface);
2542
Joe Onorato8a9b2202010-02-26 18:56:32 -08002543 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2545
2546 inTouchMode = mInTouchMode;
2547 }
2548
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002549 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 sendNewConfiguration();
2551 }
Romain Guy06882f82009-06-10 13:36:04 -07002552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2556 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2557 }
2558
2559 public void finishDrawingWindow(Session session, IWindow client) {
2560 final long origId = Binder.clearCallingIdentity();
2561 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002562 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002564 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2565 adjustWallpaperWindowsLocked();
2566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 mLayoutNeeded = true;
2568 performLayoutAndPlaceSurfacesLocked();
2569 }
2570 }
2571 Binder.restoreCallingIdentity(origId);
2572 }
2573
2574 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002575 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 + (lp != null ? lp.packageName : null)
2577 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2578 if (lp != null && lp.windowAnimations != 0) {
2579 // If this is a system resource, don't try to load it from the
2580 // application resources. It is nice to avoid loading application
2581 // resources if we can.
2582 String packageName = lp.packageName != null ? lp.packageName : "android";
2583 int resId = lp.windowAnimations;
2584 if ((resId&0xFF000000) == 0x01000000) {
2585 packageName = "android";
2586 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002587 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 + packageName);
2589 return AttributeCache.instance().get(packageName, resId,
2590 com.android.internal.R.styleable.WindowAnimation);
2591 }
2592 return null;
2593 }
Romain Guy06882f82009-06-10 13:36:04 -07002594
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002595 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002596 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002597 + packageName + " resId=0x" + Integer.toHexString(resId));
2598 if (packageName != null) {
2599 if ((resId&0xFF000000) == 0x01000000) {
2600 packageName = "android";
2601 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002602 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002603 + packageName);
2604 return AttributeCache.instance().get(packageName, resId,
2605 com.android.internal.R.styleable.WindowAnimation);
2606 }
2607 return null;
2608 }
2609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 private void applyEnterAnimationLocked(WindowState win) {
2611 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2612 if (win.mEnterAnimationPending) {
2613 win.mEnterAnimationPending = false;
2614 transit = WindowManagerPolicy.TRANSIT_ENTER;
2615 }
2616
2617 applyAnimationLocked(win, transit, true);
2618 }
2619
2620 private boolean applyAnimationLocked(WindowState win,
2621 int transit, boolean isEntrance) {
2622 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2623 // If we are trying to apply an animation, but already running
2624 // an animation of the same type, then just leave that one alone.
2625 return true;
2626 }
Romain Guy06882f82009-06-10 13:36:04 -07002627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 // Only apply an animation if the display isn't frozen. If it is
2629 // frozen, there is no reason to animate and it can cause strange
2630 // artifacts when we unfreeze the display if some different animation
2631 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002632 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 int anim = mPolicy.selectAnimationLw(win, transit);
2634 int attr = -1;
2635 Animation a = null;
2636 if (anim != 0) {
2637 a = AnimationUtils.loadAnimation(mContext, anim);
2638 } else {
2639 switch (transit) {
2640 case WindowManagerPolicy.TRANSIT_ENTER:
2641 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2642 break;
2643 case WindowManagerPolicy.TRANSIT_EXIT:
2644 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2645 break;
2646 case WindowManagerPolicy.TRANSIT_SHOW:
2647 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2648 break;
2649 case WindowManagerPolicy.TRANSIT_HIDE:
2650 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2651 break;
2652 }
2653 if (attr >= 0) {
2654 a = loadAnimation(win.mAttrs, attr);
2655 }
2656 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002657 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2659 + " mAnimation=" + win.mAnimation
2660 + " isEntrance=" + isEntrance);
2661 if (a != null) {
2662 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002663 RuntimeException e = null;
2664 if (!HIDE_STACK_CRAWLS) {
2665 e = new RuntimeException();
2666 e.fillInStackTrace();
2667 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002668 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 }
2670 win.setAnimation(a);
2671 win.mAnimationIsEntrance = isEntrance;
2672 }
2673 } else {
2674 win.clearAnimation();
2675 }
2676
2677 return win.mAnimation != null;
2678 }
2679
2680 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2681 int anim = 0;
2682 Context context = mContext;
2683 if (animAttr >= 0) {
2684 AttributeCache.Entry ent = getCachedAnimations(lp);
2685 if (ent != null) {
2686 context = ent.context;
2687 anim = ent.array.getResourceId(animAttr, 0);
2688 }
2689 }
2690 if (anim != 0) {
2691 return AnimationUtils.loadAnimation(context, anim);
2692 }
2693 return null;
2694 }
Romain Guy06882f82009-06-10 13:36:04 -07002695
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002696 private Animation loadAnimation(String packageName, int resId) {
2697 int anim = 0;
2698 Context context = mContext;
2699 if (resId >= 0) {
2700 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2701 if (ent != null) {
2702 context = ent.context;
2703 anim = resId;
2704 }
2705 }
2706 if (anim != 0) {
2707 return AnimationUtils.loadAnimation(context, anim);
2708 }
2709 return null;
2710 }
2711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 private boolean applyAnimationLocked(AppWindowToken wtoken,
2713 WindowManager.LayoutParams lp, int transit, boolean enter) {
2714 // Only apply an animation if the display isn't frozen. If it is
2715 // frozen, there is no reason to animate and it can cause strange
2716 // artifacts when we unfreeze the display if some different animation
2717 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002718 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002719 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002720 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002721 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002722 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002723 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002724 } else if (mNextAppTransitionPackage != null) {
2725 a = loadAnimation(mNextAppTransitionPackage, enter ?
2726 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002727 } else {
2728 int animAttr = 0;
2729 switch (transit) {
2730 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2731 animAttr = enter
2732 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2733 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2734 break;
2735 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2736 animAttr = enter
2737 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2738 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2739 break;
2740 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2741 animAttr = enter
2742 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2743 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2744 break;
2745 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2746 animAttr = enter
2747 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2748 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2749 break;
2750 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2751 animAttr = enter
2752 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2753 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2754 break;
2755 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2756 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002757 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002758 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2759 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002760 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002761 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002762 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2763 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002764 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002765 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002766 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002767 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2768 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2769 break;
2770 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2771 animAttr = enter
2772 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2773 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2774 break;
2775 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2776 animAttr = enter
2777 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2778 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002779 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002780 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002781 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002782 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002783 + " anim=" + a
2784 + " animAttr=0x" + Integer.toHexString(animAttr)
2785 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 if (a != null) {
2788 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002789 RuntimeException e = null;
2790 if (!HIDE_STACK_CRAWLS) {
2791 e = new RuntimeException();
2792 e.fillInStackTrace();
2793 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002794 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 }
2796 wtoken.setAnimation(a);
2797 }
2798 } else {
2799 wtoken.clearAnimation();
2800 }
2801
2802 return wtoken.animation != null;
2803 }
2804
2805 // -------------------------------------------------------------
2806 // Application Window Tokens
2807 // -------------------------------------------------------------
2808
2809 public void validateAppTokens(List tokens) {
2810 int v = tokens.size()-1;
2811 int m = mAppTokens.size()-1;
2812 while (v >= 0 && m >= 0) {
2813 AppWindowToken wtoken = mAppTokens.get(m);
2814 if (wtoken.removed) {
2815 m--;
2816 continue;
2817 }
2818 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002819 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2821 }
2822 v--;
2823 m--;
2824 }
2825 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002826 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 v--;
2828 }
2829 while (m >= 0) {
2830 AppWindowToken wtoken = mAppTokens.get(m);
2831 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002832 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 }
2834 m--;
2835 }
2836 }
2837
2838 boolean checkCallingPermission(String permission, String func) {
2839 // Quick check: if the calling permission is me, it's all okay.
2840 if (Binder.getCallingPid() == Process.myPid()) {
2841 return true;
2842 }
Romain Guy06882f82009-06-10 13:36:04 -07002843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 if (mContext.checkCallingPermission(permission)
2845 == PackageManager.PERMISSION_GRANTED) {
2846 return true;
2847 }
2848 String msg = "Permission Denial: " + func + " from pid="
2849 + Binder.getCallingPid()
2850 + ", uid=" + Binder.getCallingUid()
2851 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002852 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 return false;
2854 }
Romain Guy06882f82009-06-10 13:36:04 -07002855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 AppWindowToken findAppWindowToken(IBinder token) {
2857 WindowToken wtoken = mTokenMap.get(token);
2858 if (wtoken == null) {
2859 return null;
2860 }
2861 return wtoken.appWindowToken;
2862 }
Romain Guy06882f82009-06-10 13:36:04 -07002863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 public void addWindowToken(IBinder token, int type) {
2865 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2866 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002867 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 }
Romain Guy06882f82009-06-10 13:36:04 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 synchronized(mWindowMap) {
2871 WindowToken wtoken = mTokenMap.get(token);
2872 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002873 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 return;
2875 }
2876 wtoken = new WindowToken(token, type, true);
2877 mTokenMap.put(token, wtoken);
2878 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002879 if (type == TYPE_WALLPAPER) {
2880 mWallpaperTokens.add(wtoken);
2881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 }
2883 }
Romain Guy06882f82009-06-10 13:36:04 -07002884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 public void removeWindowToken(IBinder token) {
2886 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2887 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002888 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 }
2890
2891 final long origId = Binder.clearCallingIdentity();
2892 synchronized(mWindowMap) {
2893 WindowToken wtoken = mTokenMap.remove(token);
2894 mTokenList.remove(wtoken);
2895 if (wtoken != null) {
2896 boolean delayed = false;
2897 if (!wtoken.hidden) {
2898 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 final int N = wtoken.windows.size();
2901 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903 for (int i=0; i<N; i++) {
2904 WindowState win = wtoken.windows.get(i);
2905
2906 if (win.isAnimating()) {
2907 delayed = true;
2908 }
Romain Guy06882f82009-06-10 13:36:04 -07002909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 if (win.isVisibleNow()) {
2911 applyAnimationLocked(win,
2912 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 changed = true;
2914 }
2915 }
2916
2917 if (changed) {
2918 mLayoutNeeded = true;
2919 performLayoutAndPlaceSurfacesLocked();
2920 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2921 }
Romain Guy06882f82009-06-10 13:36:04 -07002922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 if (delayed) {
2924 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002925 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2926 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 }
2928 }
Romain Guy06882f82009-06-10 13:36:04 -07002929
Jeff Brownc5ed5912010-07-14 18:48:53 -07002930 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002932 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 }
2934 }
2935 Binder.restoreCallingIdentity(origId);
2936 }
2937
2938 public void addAppToken(int addPos, IApplicationToken token,
2939 int groupId, int requestedOrientation, boolean fullscreen) {
2940 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2941 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002942 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 }
Jeff Brown349703e2010-06-22 01:27:15 -07002944
2945 // Get the dispatching timeout here while we are not holding any locks so that it
2946 // can be cached by the AppWindowToken. The timeout value is used later by the
2947 // input dispatcher in code that does hold locks. If we did not cache the value
2948 // here we would run the chance of introducing a deadlock between the window manager
2949 // (which holds locks while updating the input dispatcher state) and the activity manager
2950 // (which holds locks while querying the application token).
2951 long inputDispatchingTimeoutNanos;
2952 try {
2953 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2954 } catch (RemoteException ex) {
2955 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2956 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2957 }
Romain Guy06882f82009-06-10 13:36:04 -07002958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 synchronized(mWindowMap) {
2960 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2961 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002962 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 return;
2964 }
2965 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002966 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 wtoken.groupId = groupId;
2968 wtoken.appFullscreen = fullscreen;
2969 wtoken.requestedOrientation = requestedOrientation;
2970 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 mTokenMap.put(token.asBinder(), wtoken);
2973 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 // Application tokens start out hidden.
2976 wtoken.hidden = true;
2977 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 //dump();
2980 }
2981 }
Romain Guy06882f82009-06-10 13:36:04 -07002982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 public void setAppGroupId(IBinder token, int groupId) {
2984 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2985 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002986 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 }
2988
2989 synchronized(mWindowMap) {
2990 AppWindowToken wtoken = findAppWindowToken(token);
2991 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002992 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002993 return;
2994 }
2995 wtoken.groupId = groupId;
2996 }
2997 }
Romain Guy06882f82009-06-10 13:36:04 -07002998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 public int getOrientationFromWindowsLocked() {
3000 int pos = mWindows.size() - 1;
3001 while (pos >= 0) {
3002 WindowState wtoken = (WindowState) mWindows.get(pos);
3003 pos--;
3004 if (wtoken.mAppToken != null) {
3005 // We hit an application window. so the orientation will be determined by the
3006 // app window. No point in continuing further.
3007 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3008 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003009 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 continue;
3011 }
3012 int req = wtoken.mAttrs.screenOrientation;
3013 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3014 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3015 continue;
3016 } else {
3017 return req;
3018 }
3019 }
3020 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3021 }
Romain Guy06882f82009-06-10 13:36:04 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003024 int pos = mAppTokens.size() - 1;
3025 int curGroup = 0;
3026 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3027 boolean findingBehind = false;
3028 boolean haveGroup = false;
3029 boolean lastFullscreen = false;
3030 while (pos >= 0) {
3031 AppWindowToken wtoken = mAppTokens.get(pos);
3032 pos--;
3033 // if we're about to tear down this window and not seek for
3034 // the behind activity, don't use it for orientation
3035 if (!findingBehind
3036 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3037 continue;
3038 }
3039
3040 if (!haveGroup) {
3041 // We ignore any hidden applications on the top.
3042 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003043 continue;
3044 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003045 haveGroup = true;
3046 curGroup = wtoken.groupId;
3047 lastOrientation = wtoken.requestedOrientation;
3048 } else if (curGroup != wtoken.groupId) {
3049 // If we have hit a new application group, and the bottom
3050 // of the previous group didn't explicitly say to use
3051 // the orientation behind it, and the last app was
3052 // full screen, then we'll stick with the
3053 // user's orientation.
3054 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3055 && lastFullscreen) {
3056 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003058 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003059 int or = wtoken.requestedOrientation;
3060 // If this application is fullscreen, and didn't explicitly say
3061 // to use the orientation behind it, then just take whatever
3062 // orientation it has and ignores whatever is under it.
3063 lastFullscreen = wtoken.appFullscreen;
3064 if (lastFullscreen
3065 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3066 return or;
3067 }
3068 // If this application has requested an explicit orientation,
3069 // then use it.
3070 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3072 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3074 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3075 return or;
3076 }
3077 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3078 }
3079 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
Romain Guy06882f82009-06-10 13:36:04 -07003081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003083 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003084 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3085 "updateOrientationFromAppTokens()")) {
3086 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003088
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003089 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003091
3092 synchronized(mWindowMap) {
3093 if (updateOrientationFromAppTokensLocked()) {
3094 if (freezeThisOneIfNeeded != null) {
3095 AppWindowToken wtoken = findAppWindowToken(
3096 freezeThisOneIfNeeded);
3097 if (wtoken != null) {
3098 startAppFreezingScreenLocked(wtoken,
3099 ActivityInfo.CONFIG_ORIENTATION);
3100 }
3101 }
3102 config = computeNewConfigurationLocked();
3103
3104 } else if (currentConfig != null) {
3105 // No obvious action we need to take, but if our current
3106 // state mismatches the activity maanager's, update it
3107 mTempConfiguration.setToDefaults();
3108 if (computeNewConfigurationLocked(mTempConfiguration)) {
3109 if (currentConfig.diff(mTempConfiguration) != 0) {
3110 mWaitingForConfig = true;
3111 mLayoutNeeded = true;
3112 startFreezingDisplayLocked();
3113 config = new Configuration(mTempConfiguration);
3114 }
3115 }
3116 }
3117 }
3118
Dianne Hackborncfaef692009-06-15 14:24:44 -07003119 Binder.restoreCallingIdentity(ident);
3120 return config;
3121 }
3122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003124 * Determine the new desired orientation of the display, returning
3125 * a non-null new Configuration if it has changed from the current
3126 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3127 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3128 * SCREEN. This will typically be done for you if you call
3129 * sendNewConfiguration().
3130 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 * The orientation is computed from non-application windows first. If none of
3132 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003133 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3135 * android.os.IBinder)
3136 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003137 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003138 if (mDisplayFrozen) {
3139 // If the display is frozen, some activities may be in the middle
3140 // of restarting, and thus have removed their old window. If the
3141 // window has the flag to hide the lock screen, then the lock screen
3142 // can re-appear and inflict its own orientation on us. Keep the
3143 // orientation stable until this all settles down.
3144 return false;
3145 }
3146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 long ident = Binder.clearCallingIdentity();
3149 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003150 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 mForcedAppOrientation = req;
3154 //send a message to Policy indicating orientation change to take
3155 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003156 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003157 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3158 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3159 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 }
3161 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003162
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003163 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 } finally {
3165 Binder.restoreCallingIdentity(ident);
3166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 }
Romain Guy06882f82009-06-10 13:36:04 -07003168
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003169 int computeForcedAppOrientationLocked() {
3170 int req = getOrientationFromWindowsLocked();
3171 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3172 req = getOrientationFromAppTokensLocked();
3173 }
3174 return req;
3175 }
Romain Guy06882f82009-06-10 13:36:04 -07003176
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003177 public void setNewConfiguration(Configuration config) {
3178 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3179 "setNewConfiguration()")) {
3180 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3181 }
3182
3183 synchronized(mWindowMap) {
3184 mCurConfiguration = new Configuration(config);
3185 mWaitingForConfig = false;
3186 performLayoutAndPlaceSurfacesLocked();
3187 }
3188 }
3189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3191 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3192 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003193 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 }
Romain Guy06882f82009-06-10 13:36:04 -07003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 synchronized(mWindowMap) {
3197 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3198 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003199 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 return;
3201 }
Romain Guy06882f82009-06-10 13:36:04 -07003202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003203 wtoken.requestedOrientation = requestedOrientation;
3204 }
3205 }
Romain Guy06882f82009-06-10 13:36:04 -07003206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 public int getAppOrientation(IApplicationToken token) {
3208 synchronized(mWindowMap) {
3209 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3210 if (wtoken == null) {
3211 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3212 }
Romain Guy06882f82009-06-10 13:36:04 -07003213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 return wtoken.requestedOrientation;
3215 }
3216 }
Romain Guy06882f82009-06-10 13:36:04 -07003217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3219 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3220 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003221 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 }
3223
3224 synchronized(mWindowMap) {
3225 boolean changed = false;
3226 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003227 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 changed = mFocusedApp != null;
3229 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003230 if (changed) {
3231 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 } else {
3234 AppWindowToken newFocus = findAppWindowToken(token);
3235 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003236 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 return;
3238 }
3239 changed = mFocusedApp != newFocus;
3240 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003241 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003242 if (changed) {
3243 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 }
3246
3247 if (moveFocusNow && changed) {
3248 final long origId = Binder.clearCallingIdentity();
3249 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3250 Binder.restoreCallingIdentity(origId);
3251 }
3252 }
3253 }
3254
3255 public void prepareAppTransition(int transit) {
3256 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3257 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003258 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 }
Romain Guy06882f82009-06-10 13:36:04 -07003260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003262 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 TAG, "Prepare app transition: transit=" + transit
3264 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003265 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003266 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3267 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003269 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3270 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3271 // Opening a new task always supersedes a close for the anim.
3272 mNextAppTransition = transit;
3273 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3274 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3275 // Opening a new activity always supersedes a close for the anim.
3276 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 }
3278 mAppTransitionReady = false;
3279 mAppTransitionTimeout = false;
3280 mStartingIconInTransition = false;
3281 mSkipAppTransitionAnimation = false;
3282 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3283 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3284 5000);
3285 }
3286 }
3287 }
3288
3289 public int getPendingAppTransition() {
3290 return mNextAppTransition;
3291 }
Romain Guy06882f82009-06-10 13:36:04 -07003292
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003293 public void overridePendingAppTransition(String packageName,
3294 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003295 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003296 mNextAppTransitionPackage = packageName;
3297 mNextAppTransitionEnter = enterAnim;
3298 mNextAppTransitionExit = exitAnim;
3299 }
3300 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 public void executeAppTransition() {
3303 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3304 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003305 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003309 if (DEBUG_APP_TRANSITIONS) {
3310 RuntimeException e = new RuntimeException("here");
3311 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003312 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003313 + mNextAppTransition, e);
3314 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003315 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 mAppTransitionReady = true;
3317 final long origId = Binder.clearCallingIdentity();
3318 performLayoutAndPlaceSurfacesLocked();
3319 Binder.restoreCallingIdentity(origId);
3320 }
3321 }
3322 }
3323
3324 public void setAppStartingWindow(IBinder token, String pkg,
3325 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3326 IBinder transferFrom, boolean createIfNeeded) {
3327 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3328 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003329 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 }
3331
3332 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003333 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3335 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 AppWindowToken wtoken = findAppWindowToken(token);
3338 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003339 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 return;
3341 }
3342
3343 // If the display is frozen, we won't do anything until the
3344 // actual window is displayed so there is no reason to put in
3345 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003346 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 return;
3348 }
Romain Guy06882f82009-06-10 13:36:04 -07003349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 if (wtoken.startingData != null) {
3351 return;
3352 }
Romain Guy06882f82009-06-10 13:36:04 -07003353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 if (transferFrom != null) {
3355 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3356 if (ttoken != null) {
3357 WindowState startingWindow = ttoken.startingWindow;
3358 if (startingWindow != null) {
3359 if (mStartingIconInTransition) {
3360 // In this case, the starting icon has already
3361 // been displayed, so start letting windows get
3362 // shown immediately without any more transitions.
3363 mSkipAppTransitionAnimation = true;
3364 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003365 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 "Moving existing starting from " + ttoken
3367 + " to " + wtoken);
3368 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 // Transfer the starting window over to the new
3371 // token.
3372 wtoken.startingData = ttoken.startingData;
3373 wtoken.startingView = ttoken.startingView;
3374 wtoken.startingWindow = startingWindow;
3375 ttoken.startingData = null;
3376 ttoken.startingView = null;
3377 ttoken.startingWindow = null;
3378 ttoken.startingMoved = true;
3379 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003380 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003382 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003383 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003385 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 ttoken.windows.remove(startingWindow);
3387 ttoken.allAppWindows.remove(startingWindow);
3388 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 // Propagate other interesting state between the
3391 // tokens. If the old token is displayed, we should
3392 // immediately force the new one to be displayed. If
3393 // it is animating, we need to move that animation to
3394 // the new one.
3395 if (ttoken.allDrawn) {
3396 wtoken.allDrawn = true;
3397 }
3398 if (ttoken.firstWindowDrawn) {
3399 wtoken.firstWindowDrawn = true;
3400 }
3401 if (!ttoken.hidden) {
3402 wtoken.hidden = false;
3403 wtoken.hiddenRequested = false;
3404 wtoken.willBeHidden = false;
3405 }
3406 if (wtoken.clientHidden != ttoken.clientHidden) {
3407 wtoken.clientHidden = ttoken.clientHidden;
3408 wtoken.sendAppVisibilityToClients();
3409 }
3410 if (ttoken.animation != null) {
3411 wtoken.animation = ttoken.animation;
3412 wtoken.animating = ttoken.animating;
3413 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3414 ttoken.animation = null;
3415 ttoken.animLayerAdjustment = 0;
3416 wtoken.updateLayers();
3417 ttoken.updateLayers();
3418 }
Romain Guy06882f82009-06-10 13:36:04 -07003419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 mLayoutNeeded = true;
3422 performLayoutAndPlaceSurfacesLocked();
3423 Binder.restoreCallingIdentity(origId);
3424 return;
3425 } else if (ttoken.startingData != null) {
3426 // The previous app was getting ready to show a
3427 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003428 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 "Moving pending starting from " + ttoken
3430 + " to " + wtoken);
3431 wtoken.startingData = ttoken.startingData;
3432 ttoken.startingData = null;
3433 ttoken.startingMoved = true;
3434 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3435 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3436 // want to process the message ASAP, before any other queued
3437 // messages.
3438 mH.sendMessageAtFrontOfQueue(m);
3439 return;
3440 }
3441 }
3442 }
3443
3444 // There is no existing starting window, and the caller doesn't
3445 // want us to create one, so that's it!
3446 if (!createIfNeeded) {
3447 return;
3448 }
Romain Guy06882f82009-06-10 13:36:04 -07003449
Dianne Hackborn284ac932009-08-28 10:34:25 -07003450 // If this is a translucent or wallpaper window, then don't
3451 // show a starting window -- the current effect (a full-screen
3452 // opaque starting window that fades away to the real contents
3453 // when it is ready) does not work for this.
3454 if (theme != 0) {
3455 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3456 com.android.internal.R.styleable.Window);
3457 if (ent.array.getBoolean(
3458 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3459 return;
3460 }
3461 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003462 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3463 return;
3464 }
3465 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003466 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3467 return;
3468 }
3469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003471 mStartingIconInTransition = true;
3472 wtoken.startingData = new StartingData(
3473 pkg, theme, nonLocalizedLabel,
3474 labelRes, icon);
3475 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3476 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3477 // want to process the message ASAP, before any other queued
3478 // messages.
3479 mH.sendMessageAtFrontOfQueue(m);
3480 }
3481 }
3482
3483 public void setAppWillBeHidden(IBinder token) {
3484 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3485 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003486 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 }
3488
3489 AppWindowToken wtoken;
3490
3491 synchronized(mWindowMap) {
3492 wtoken = findAppWindowToken(token);
3493 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003494 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 -08003495 return;
3496 }
3497 wtoken.willBeHidden = true;
3498 }
3499 }
Romain Guy06882f82009-06-10 13:36:04 -07003500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3502 boolean visible, int transit, boolean performLayout) {
3503 boolean delayed = false;
3504
3505 if (wtoken.clientHidden == visible) {
3506 wtoken.clientHidden = !visible;
3507 wtoken.sendAppVisibilityToClients();
3508 }
Romain Guy06882f82009-06-10 13:36:04 -07003509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 wtoken.willBeHidden = false;
3511 if (wtoken.hidden == visible) {
3512 final int N = wtoken.allAppWindows.size();
3513 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003514 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3516 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003519
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003520 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 if (wtoken.animation == sDummyAnimation) {
3522 wtoken.animation = null;
3523 }
3524 applyAnimationLocked(wtoken, lp, transit, visible);
3525 changed = true;
3526 if (wtoken.animation != null) {
3527 delayed = runningAppAnimation = true;
3528 }
3529 }
Romain Guy06882f82009-06-10 13:36:04 -07003530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 for (int i=0; i<N; i++) {
3532 WindowState win = wtoken.allAppWindows.get(i);
3533 if (win == wtoken.startingWindow) {
3534 continue;
3535 }
3536
3537 if (win.isAnimating()) {
3538 delayed = true;
3539 }
Romain Guy06882f82009-06-10 13:36:04 -07003540
Joe Onorato8a9b2202010-02-26 18:56:32 -08003541 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 //win.dump(" ");
3543 if (visible) {
3544 if (!win.isVisibleNow()) {
3545 if (!runningAppAnimation) {
3546 applyAnimationLocked(win,
3547 WindowManagerPolicy.TRANSIT_ENTER, true);
3548 }
3549 changed = true;
3550 }
3551 } else if (win.isVisibleNow()) {
3552 if (!runningAppAnimation) {
3553 applyAnimationLocked(win,
3554 WindowManagerPolicy.TRANSIT_EXIT, false);
3555 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003556 mInputMonitor.windowIsBecomingInvisibleLw(win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 changed = true;
3558 }
3559 }
3560
3561 wtoken.hidden = wtoken.hiddenRequested = !visible;
3562 if (!visible) {
3563 unsetAppFreezingScreenLocked(wtoken, true, true);
3564 } else {
3565 // If we are being set visible, and the starting window is
3566 // not yet displayed, then make sure it doesn't get displayed.
3567 WindowState swin = wtoken.startingWindow;
3568 if (swin != null && (swin.mDrawPending
3569 || swin.mCommitDrawPending)) {
3570 swin.mPolicyVisibility = false;
3571 swin.mPolicyVisibilityAfterAnim = false;
3572 }
3573 }
Romain Guy06882f82009-06-10 13:36:04 -07003574
Joe Onorato8a9b2202010-02-26 18:56:32 -08003575 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003576 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3577 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003578
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003579 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003580 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003581 if (performLayout) {
3582 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3583 performLayoutAndPlaceSurfacesLocked();
3584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 }
3586 }
3587
3588 if (wtoken.animation != null) {
3589 delayed = true;
3590 }
Romain Guy06882f82009-06-10 13:36:04 -07003591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 return delayed;
3593 }
3594
3595 public void setAppVisibility(IBinder token, boolean visible) {
3596 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3597 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003598 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 }
3600
3601 AppWindowToken wtoken;
3602
3603 synchronized(mWindowMap) {
3604 wtoken = findAppWindowToken(token);
3605 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003606 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 return;
3608 }
3609
3610 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003611 RuntimeException e = null;
3612 if (!HIDE_STACK_CRAWLS) {
3613 e = new RuntimeException();
3614 e.fillInStackTrace();
3615 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003616 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 + "): mNextAppTransition=" + mNextAppTransition
3618 + " hidden=" + wtoken.hidden
3619 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3620 }
Romain Guy06882f82009-06-10 13:36:04 -07003621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 // If we are preparing an app transition, then delay changing
3623 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003624 if (!mDisplayFrozen && mPolicy.isScreenOn()
3625 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 // Already in requested state, don't do anything more.
3627 if (wtoken.hiddenRequested != visible) {
3628 return;
3629 }
3630 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003631
Joe Onorato8a9b2202010-02-26 18:56:32 -08003632 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 TAG, "Setting dummy animation on: " + wtoken);
3634 wtoken.setDummyAnimation();
3635 mOpeningApps.remove(wtoken);
3636 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003637 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 wtoken.inPendingTransaction = true;
3639 if (visible) {
3640 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 wtoken.startingDisplayed = false;
3642 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003643
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003644 // If the token is currently hidden (should be the
3645 // common case), then we need to set up to wait for
3646 // its windows to be ready.
3647 if (wtoken.hidden) {
3648 wtoken.allDrawn = false;
3649 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003650
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003651 if (wtoken.clientHidden) {
3652 // In the case where we are making an app visible
3653 // but holding off for a transition, we still need
3654 // to tell the client to make its windows visible so
3655 // they get drawn. Otherwise, we will wait on
3656 // performing the transition until all windows have
3657 // been drawn, they never will be, and we are sad.
3658 wtoken.clientHidden = false;
3659 wtoken.sendAppVisibilityToClients();
3660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003661 }
3662 } else {
3663 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003664
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003665 // If the token is currently visible (should be the
3666 // common case), then set up to wait for it to be hidden.
3667 if (!wtoken.hidden) {
3668 wtoken.waitingToHide = true;
3669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 }
3671 return;
3672 }
Romain Guy06882f82009-06-10 13:36:04 -07003673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003675 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 wtoken.updateReportedVisibilityLocked();
3677 Binder.restoreCallingIdentity(origId);
3678 }
3679 }
3680
3681 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3682 boolean unfreezeSurfaceNow, boolean force) {
3683 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003684 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 + " force=" + force);
3686 final int N = wtoken.allAppWindows.size();
3687 boolean unfrozeWindows = false;
3688 for (int i=0; i<N; i++) {
3689 WindowState w = wtoken.allAppWindows.get(i);
3690 if (w.mAppFreezing) {
3691 w.mAppFreezing = false;
3692 if (w.mSurface != null && !w.mOrientationChanging) {
3693 w.mOrientationChanging = true;
3694 }
3695 unfrozeWindows = true;
3696 }
3697 }
3698 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003699 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003700 wtoken.freezingScreen = false;
3701 mAppsFreezingScreen--;
3702 }
3703 if (unfreezeSurfaceNow) {
3704 if (unfrozeWindows) {
3705 mLayoutNeeded = true;
3706 performLayoutAndPlaceSurfacesLocked();
3707 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003708 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 }
3710 }
3711 }
Romain Guy06882f82009-06-10 13:36:04 -07003712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3714 int configChanges) {
3715 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003716 RuntimeException e = null;
3717 if (!HIDE_STACK_CRAWLS) {
3718 e = new RuntimeException();
3719 e.fillInStackTrace();
3720 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003721 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 + ": hidden=" + wtoken.hidden + " freezing="
3723 + wtoken.freezingScreen, e);
3724 }
3725 if (!wtoken.hiddenRequested) {
3726 if (!wtoken.freezingScreen) {
3727 wtoken.freezingScreen = true;
3728 mAppsFreezingScreen++;
3729 if (mAppsFreezingScreen == 1) {
3730 startFreezingDisplayLocked();
3731 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3732 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3733 5000);
3734 }
3735 }
3736 final int N = wtoken.allAppWindows.size();
3737 for (int i=0; i<N; i++) {
3738 WindowState w = wtoken.allAppWindows.get(i);
3739 w.mAppFreezing = true;
3740 }
3741 }
3742 }
Romain Guy06882f82009-06-10 13:36:04 -07003743
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 public void startAppFreezingScreen(IBinder token, int configChanges) {
3745 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3746 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003747 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 }
3749
3750 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003751 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003752 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753 return;
3754 }
Romain Guy06882f82009-06-10 13:36:04 -07003755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 AppWindowToken wtoken = findAppWindowToken(token);
3757 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003758 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 return;
3760 }
3761 final long origId = Binder.clearCallingIdentity();
3762 startAppFreezingScreenLocked(wtoken, configChanges);
3763 Binder.restoreCallingIdentity(origId);
3764 }
3765 }
Romain Guy06882f82009-06-10 13:36:04 -07003766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 public void stopAppFreezingScreen(IBinder token, boolean force) {
3768 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3769 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003770 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 }
3772
3773 synchronized(mWindowMap) {
3774 AppWindowToken wtoken = findAppWindowToken(token);
3775 if (wtoken == null || wtoken.appToken == null) {
3776 return;
3777 }
3778 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003779 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003780 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3781 unsetAppFreezingScreenLocked(wtoken, true, force);
3782 Binder.restoreCallingIdentity(origId);
3783 }
3784 }
Romain Guy06882f82009-06-10 13:36:04 -07003785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 public void removeAppToken(IBinder token) {
3787 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3788 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003789 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 }
3791
3792 AppWindowToken wtoken = null;
3793 AppWindowToken startingToken = null;
3794 boolean delayed = false;
3795
3796 final long origId = Binder.clearCallingIdentity();
3797 synchronized(mWindowMap) {
3798 WindowToken basewtoken = mTokenMap.remove(token);
3799 mTokenList.remove(basewtoken);
3800 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003801 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003802 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 wtoken.inPendingTransaction = false;
3804 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003805 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 if (mClosingApps.contains(wtoken)) {
3807 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003808 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003810 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 delayed = true;
3812 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003813 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 TAG, "Removing app " + wtoken + " delayed=" + delayed
3815 + " animation=" + wtoken.animation
3816 + " animating=" + wtoken.animating);
3817 if (delayed) {
3818 // set the token aside because it has an active animation to be finished
3819 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003820 } else {
3821 // Make sure there is no animation running on this token,
3822 // so any windows associated with it will be removed as
3823 // soon as their animations are complete
3824 wtoken.animation = null;
3825 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 }
3827 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003828 if (mLastEnterAnimToken == wtoken) {
3829 mLastEnterAnimToken = null;
3830 mLastEnterAnimParams = null;
3831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 wtoken.removed = true;
3833 if (wtoken.startingData != null) {
3834 startingToken = wtoken;
3835 }
3836 unsetAppFreezingScreenLocked(wtoken, true, true);
3837 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003838 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 mFocusedApp = null;
3840 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003841 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 }
3843 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003844 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 }
Romain Guy06882f82009-06-10 13:36:04 -07003846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 if (!delayed && wtoken != null) {
3848 wtoken.updateReportedVisibilityLocked();
3849 }
3850 }
3851 Binder.restoreCallingIdentity(origId);
3852
3853 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003854 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 + startingToken + ": app token removed");
3856 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3857 mH.sendMessage(m);
3858 }
3859 }
3860
3861 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3862 final int NW = token.windows.size();
3863 for (int i=0; i<NW; i++) {
3864 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003865 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003866 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003867 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 int j = win.mChildWindows.size();
3869 while (j > 0) {
3870 j--;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003871 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003872 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003873 "Tmp removing child window " + cwin);
3874 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 }
3876 }
3877 return NW > 0;
3878 }
3879
3880 void dumpAppTokensLocked() {
3881 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003882 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
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 void dumpWindowsLocked() {
3887 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003888 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 }
3890 }
Romain Guy06882f82009-06-10 13:36:04 -07003891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003892 private int findWindowOffsetLocked(int tokenPos) {
3893 final int NW = mWindows.size();
3894
3895 if (tokenPos >= mAppTokens.size()) {
3896 int i = NW;
3897 while (i > 0) {
3898 i--;
3899 WindowState win = (WindowState)mWindows.get(i);
3900 if (win.getAppToken() != null) {
3901 return i+1;
3902 }
3903 }
3904 }
3905
3906 while (tokenPos > 0) {
3907 // Find the first app token below the new position that has
3908 // a window displayed.
3909 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003910 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003912 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003913 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003914 "Skipping token -- currently sending to bottom");
3915 tokenPos--;
3916 continue;
3917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 int i = wtoken.windows.size();
3919 while (i > 0) {
3920 i--;
3921 WindowState win = wtoken.windows.get(i);
3922 int j = win.mChildWindows.size();
3923 while (j > 0) {
3924 j--;
3925 WindowState cwin = (WindowState)win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003926 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 for (int pos=NW-1; pos>=0; pos--) {
3928 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003929 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 "Found child win @" + (pos+1));
3931 return pos+1;
3932 }
3933 }
3934 }
3935 }
3936 for (int pos=NW-1; pos>=0; pos--) {
3937 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003938 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 return pos+1;
3940 }
3941 }
3942 }
3943 tokenPos--;
3944 }
3945
3946 return 0;
3947 }
3948
3949 private final int reAddWindowLocked(int index, WindowState win) {
3950 final int NCW = win.mChildWindows.size();
3951 boolean added = false;
3952 for (int j=0; j<NCW; j++) {
3953 WindowState cwin = (WindowState)win.mChildWindows.get(j);
3954 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003955 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child 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, win);
3958 index++;
3959 added = true;
3960 }
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 + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003963 mWindows.add(index, cwin);
3964 index++;
3965 }
3966 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003967 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003968 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003969 mWindows.add(index, win);
3970 index++;
3971 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003972 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 return index;
3974 }
Romain Guy06882f82009-06-10 13:36:04 -07003975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3977 final int NW = token.windows.size();
3978 for (int i=0; i<NW; i++) {
3979 index = reAddWindowLocked(index, token.windows.get(i));
3980 }
3981 return index;
3982 }
3983
3984 public void moveAppToken(int index, IBinder token) {
3985 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3986 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003987 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 }
3989
3990 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003991 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 if (DEBUG_REORDER) dumpAppTokensLocked();
3993 final AppWindowToken wtoken = findAppWindowToken(token);
3994 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003995 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 + token + " (" + wtoken + ")");
3997 return;
3998 }
3999 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004000 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004001 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004004 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 if (DEBUG_REORDER) dumpWindowsLocked();
4006 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004007 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 if (DEBUG_REORDER) dumpWindowsLocked();
4009 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 if (DEBUG_REORDER) dumpWindowsLocked();
4012 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 mLayoutNeeded = true;
4014 performLayoutAndPlaceSurfacesLocked();
4015 }
4016 Binder.restoreCallingIdentity(origId);
4017 }
4018 }
4019
4020 private void removeAppTokensLocked(List<IBinder> tokens) {
4021 // XXX This should be done more efficiently!
4022 // (take advantage of the fact that both lists should be
4023 // ordered in the same way.)
4024 int N = tokens.size();
4025 for (int i=0; i<N; i++) {
4026 IBinder token = tokens.get(i);
4027 final AppWindowToken wtoken = findAppWindowToken(token);
4028 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004029 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 + token + " (" + wtoken + ")");
4031 i--;
4032 N--;
4033 }
4034 }
4035 }
4036
Dianne Hackborna8f60182009-09-01 19:01:50 -07004037 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4038 boolean updateFocusAndLayout) {
4039 // First remove all of the windows from the list.
4040 tmpRemoveAppWindowsLocked(wtoken);
4041
4042 // Where to start adding?
4043 int pos = findWindowOffsetLocked(tokenPos);
4044
4045 // And now add them back at the correct place.
4046 pos = reAddAppWindowsLocked(pos, wtoken);
4047
4048 if (updateFocusAndLayout) {
4049 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4050 assignLayersLocked();
4051 }
4052 mLayoutNeeded = true;
4053 performLayoutAndPlaceSurfacesLocked();
4054 }
4055 }
4056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004057 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4058 // First remove all of the windows from the list.
4059 final int N = tokens.size();
4060 int i;
4061 for (i=0; i<N; i++) {
4062 WindowToken token = mTokenMap.get(tokens.get(i));
4063 if (token != null) {
4064 tmpRemoveAppWindowsLocked(token);
4065 }
4066 }
4067
4068 // Where to start adding?
4069 int pos = findWindowOffsetLocked(tokenPos);
4070
4071 // And now add them back at the correct place.
4072 for (i=0; i<N; i++) {
4073 WindowToken token = mTokenMap.get(tokens.get(i));
4074 if (token != null) {
4075 pos = reAddAppWindowsLocked(pos, token);
4076 }
4077 }
4078
Dianne Hackborna8f60182009-09-01 19:01:50 -07004079 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4080 assignLayersLocked();
4081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 mLayoutNeeded = true;
4083 performLayoutAndPlaceSurfacesLocked();
4084
4085 //dump();
4086 }
4087
4088 public void moveAppTokensToTop(List<IBinder> tokens) {
4089 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4090 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004091 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 }
4093
4094 final long origId = Binder.clearCallingIdentity();
4095 synchronized(mWindowMap) {
4096 removeAppTokensLocked(tokens);
4097 final int N = tokens.size();
4098 for (int i=0; i<N; i++) {
4099 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4100 if (wt != null) {
4101 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004102 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004103 mToTopApps.remove(wt);
4104 mToBottomApps.remove(wt);
4105 mToTopApps.add(wt);
4106 wt.sendingToBottom = false;
4107 wt.sendingToTop = true;
4108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004109 }
4110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004111
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004112 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004113 moveAppWindowsLocked(tokens, mAppTokens.size());
4114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 }
4116 Binder.restoreCallingIdentity(origId);
4117 }
4118
4119 public void moveAppTokensToBottom(List<IBinder> tokens) {
4120 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4121 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004122 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004123 }
4124
4125 final long origId = Binder.clearCallingIdentity();
4126 synchronized(mWindowMap) {
4127 removeAppTokensLocked(tokens);
4128 final int N = tokens.size();
4129 int pos = 0;
4130 for (int i=0; i<N; i++) {
4131 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4132 if (wt != null) {
4133 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004134 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004135 mToTopApps.remove(wt);
4136 mToBottomApps.remove(wt);
4137 mToBottomApps.add(i, wt);
4138 wt.sendingToTop = false;
4139 wt.sendingToBottom = true;
4140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 pos++;
4142 }
4143 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004144
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004145 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004146 moveAppWindowsLocked(tokens, 0);
4147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004148 }
4149 Binder.restoreCallingIdentity(origId);
4150 }
4151
4152 // -------------------------------------------------------------
4153 // Misc IWindowSession methods
4154 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004155
Jim Miller284b62e2010-06-08 14:27:42 -07004156 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004157 {
Jim Miller284b62e2010-06-08 14:27:42 -07004158 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4159 // called before DevicePolicyManagerService has started.
4160 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4161 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4162 Context.DEVICE_POLICY_SERVICE);
4163 if (dpm != null) {
4164 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4165 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4166 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4167 }
Jim Millerd6b57052010-06-07 17:52:42 -07004168 }
Jim Miller284b62e2010-06-08 14:27:42 -07004169 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004170 }
4171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004173 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174 != PackageManager.PERMISSION_GRANTED) {
4175 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4176 }
Jim Millerd6b57052010-06-07 17:52:42 -07004177
Jim Miller284b62e2010-06-08 14:27:42 -07004178 synchronized (mKeyguardTokenWatcher) {
4179 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 }
4182
4183 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004184 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 != PackageManager.PERMISSION_GRANTED) {
4186 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4187 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188
Jim Miller284b62e2010-06-08 14:27:42 -07004189 synchronized (mKeyguardTokenWatcher) {
4190 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004191
Jim Miller284b62e2010-06-08 14:27:42 -07004192 if (!mKeyguardTokenWatcher.isAcquired()) {
4193 // If we are the last one to reenable the keyguard wait until
4194 // we have actually finished reenabling until returning.
4195 // It is possible that reenableKeyguard() can be called before
4196 // the previous disableKeyguard() is handled, in which case
4197 // neither mKeyguardTokenWatcher.acquired() or released() would
4198 // be called. In that case mKeyguardDisabled will be false here
4199 // and we have nothing to wait for.
4200 while (mKeyguardDisabled) {
4201 try {
4202 mKeyguardTokenWatcher.wait();
4203 } catch (InterruptedException e) {
4204 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 }
4206 }
4207 }
4208 }
4209 }
4210
4211 /**
4212 * @see android.app.KeyguardManager#exitKeyguardSecurely
4213 */
4214 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004215 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004216 != PackageManager.PERMISSION_GRANTED) {
4217 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4218 }
4219 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4220 public void onKeyguardExitResult(boolean success) {
4221 try {
4222 callback.onKeyguardExitResult(success);
4223 } catch (RemoteException e) {
4224 // Client has died, we don't care.
4225 }
4226 }
4227 });
4228 }
4229
4230 public boolean inKeyguardRestrictedInputMode() {
4231 return mPolicy.inKeyguardRestrictedKeyInputMode();
4232 }
Romain Guy06882f82009-06-10 13:36:04 -07004233
Dianne Hackbornffa42482009-09-23 22:20:11 -07004234 public void closeSystemDialogs(String reason) {
4235 synchronized(mWindowMap) {
4236 for (int i=mWindows.size()-1; i>=0; i--) {
4237 WindowState w = (WindowState)mWindows.get(i);
4238 if (w.mSurface != null) {
4239 try {
4240 w.mClient.closeSystemDialogs(reason);
4241 } catch (RemoteException e) {
4242 }
4243 }
4244 }
4245 }
4246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 static float fixScale(float scale) {
4249 if (scale < 0) scale = 0;
4250 else if (scale > 20) scale = 20;
4251 return Math.abs(scale);
4252 }
Romain Guy06882f82009-06-10 13:36:04 -07004253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004254 public void setAnimationScale(int which, float scale) {
4255 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4256 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004257 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 }
4259
4260 if (scale < 0) scale = 0;
4261 else if (scale > 20) scale = 20;
4262 scale = Math.abs(scale);
4263 switch (which) {
4264 case 0: mWindowAnimationScale = fixScale(scale); break;
4265 case 1: mTransitionAnimationScale = fixScale(scale); break;
4266 }
Romain Guy06882f82009-06-10 13:36:04 -07004267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 // Persist setting
4269 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4270 }
Romain Guy06882f82009-06-10 13:36:04 -07004271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 public void setAnimationScales(float[] scales) {
4273 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4274 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004275 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276 }
4277
4278 if (scales != null) {
4279 if (scales.length >= 1) {
4280 mWindowAnimationScale = fixScale(scales[0]);
4281 }
4282 if (scales.length >= 2) {
4283 mTransitionAnimationScale = fixScale(scales[1]);
4284 }
4285 }
Romain Guy06882f82009-06-10 13:36:04 -07004286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 // Persist setting
4288 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 public float getAnimationScale(int which) {
4292 switch (which) {
4293 case 0: return mWindowAnimationScale;
4294 case 1: return mTransitionAnimationScale;
4295 }
4296 return 0;
4297 }
Romain Guy06882f82009-06-10 13:36:04 -07004298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 public float[] getAnimationScales() {
4300 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public int getSwitchState(int sw) {
4304 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4305 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004306 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004308 return mInputManager.getSwitchState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
Romain Guy06882f82009-06-10 13:36:04 -07004310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 public int getSwitchStateForDevice(int devid, int sw) {
4312 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4313 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004314 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004316 return mInputManager.getSwitchState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Romain Guy06882f82009-06-10 13:36:04 -07004318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 public int getScancodeState(int sw) {
4320 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4321 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004322 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004324 return mInputManager.getScancodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Romain Guy06882f82009-06-10 13:36:04 -07004326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 public int getScancodeStateForDevice(int devid, int sw) {
4328 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4329 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004330 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004332 return mInputManager.getScancodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
Romain Guy06882f82009-06-10 13:36:04 -07004334
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004335 public int getTrackballScancodeState(int sw) {
4336 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4337 "getTrackballScancodeState()")) {
4338 throw new SecurityException("Requires READ_INPUT_STATE permission");
4339 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004340 return mInputManager.getTrackballScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004341 }
4342
4343 public int getDPadScancodeState(int sw) {
4344 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4345 "getDPadScancodeState()")) {
4346 throw new SecurityException("Requires READ_INPUT_STATE permission");
4347 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004348 return mInputManager.getDPadScancodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004349 }
4350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 public int getKeycodeState(int sw) {
4352 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4353 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004354 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004356 return mInputManager.getKeycodeState(sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Romain Guy06882f82009-06-10 13:36:04 -07004358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 public int getKeycodeStateForDevice(int devid, int sw) {
4360 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4361 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004362 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004364 return mInputManager.getKeycodeState(devid, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
Romain Guy06882f82009-06-10 13:36:04 -07004366
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004367 public int getTrackballKeycodeState(int sw) {
4368 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4369 "getTrackballKeycodeState()")) {
4370 throw new SecurityException("Requires READ_INPUT_STATE permission");
4371 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004372 return mInputManager.getTrackballKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004373 }
4374
4375 public int getDPadKeycodeState(int sw) {
4376 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4377 "getDPadKeycodeState()")) {
4378 throw new SecurityException("Requires READ_INPUT_STATE permission");
4379 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004380 return mInputManager.getDPadKeycodeState(sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004381 }
4382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004384 return mInputManager.hasKeys(keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 }
Romain Guy06882f82009-06-10 13:36:04 -07004386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 public void enableScreenAfterBoot() {
4388 synchronized(mWindowMap) {
4389 if (mSystemBooted) {
4390 return;
4391 }
4392 mSystemBooted = true;
4393 }
Romain Guy06882f82009-06-10 13:36:04 -07004394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 performEnableScreen();
4396 }
Romain Guy06882f82009-06-10 13:36:04 -07004397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 public void enableScreenIfNeededLocked() {
4399 if (mDisplayEnabled) {
4400 return;
4401 }
4402 if (!mSystemBooted) {
4403 return;
4404 }
4405 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4406 }
Romain Guy06882f82009-06-10 13:36:04 -07004407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 public void performEnableScreen() {
4409 synchronized(mWindowMap) {
4410 if (mDisplayEnabled) {
4411 return;
4412 }
4413 if (!mSystemBooted) {
4414 return;
4415 }
Romain Guy06882f82009-06-10 13:36:04 -07004416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 // Don't enable the screen until all existing windows
4418 // have been drawn.
4419 final int N = mWindows.size();
4420 for (int i=0; i<N; i++) {
4421 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004422 if (w.isVisibleLw() && !w.mObscured
4423 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 return;
4425 }
4426 }
Romain Guy06882f82009-06-10 13:36:04 -07004427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004428 mDisplayEnabled = true;
4429 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004430 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 StringWriter sw = new StringWriter();
4432 PrintWriter pw = new PrintWriter(sw);
4433 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004434 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 }
4436 try {
4437 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4438 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004439 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 Parcel data = Parcel.obtain();
4441 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4442 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4443 data, null, 0);
4444 data.recycle();
4445 }
4446 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 }
4449 }
Romain Guy06882f82009-06-10 13:36:04 -07004450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004454 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4455 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
Romain Guy06882f82009-06-10 13:36:04 -07004457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 public void setInTouchMode(boolean mode) {
4459 synchronized(mWindowMap) {
4460 mInTouchMode = mode;
4461 }
4462 }
4463
Romain Guy06882f82009-06-10 13:36:04 -07004464 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004465 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004467 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004468 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 }
4470
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004471 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
Romain Guy06882f82009-06-10 13:36:04 -07004473
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004474 public void setRotationUnchecked(int rotation,
4475 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004476 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 long origId = Binder.clearCallingIdentity();
4480 boolean changed;
4481 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 }
Romain Guy06882f82009-06-10 13:36:04 -07004484
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004485 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 sendNewConfiguration();
4487 }
Romain Guy06882f82009-06-10 13:36:04 -07004488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 Binder.restoreCallingIdentity(origId);
4490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004492 /**
4493 * Apply a new rotation to the screen, respecting the requests of
4494 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4495 * re-evaluate the desired rotation.
4496 *
4497 * Returns null if the rotation has been changed. In this case YOU
4498 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4499 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004500 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 boolean changed;
4502 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4503 rotation = mRequestedRotation;
4504 } else {
4505 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004506 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004508 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004509 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004511 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004515 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 "Rotation changed to " + rotation
4517 + " from " + mRotation
4518 + " (forceApp=" + mForcedAppOrientation
4519 + ", req=" + mRequestedRotation + ")");
4520 mRotation = rotation;
4521 mWindowsFreezingScreen = true;
4522 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4523 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4524 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004525 mWaitingForConfig = true;
4526 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004528 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004529 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004531 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 }
4533 for (int i=mWindows.size()-1; i>=0; i--) {
4534 WindowState w = (WindowState)mWindows.get(i);
4535 if (w.mSurface != null) {
4536 w.mOrientationChanging = true;
4537 }
4538 }
4539 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4540 try {
4541 mRotationWatchers.get(i).onRotationChanged(rotation);
4542 } catch (RemoteException e) {
4543 }
4544 }
4545 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 return changed;
4548 }
Romain Guy06882f82009-06-10 13:36:04 -07004549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 public int getRotation() {
4551 return mRotation;
4552 }
4553
4554 public int watchRotation(IRotationWatcher watcher) {
4555 final IBinder watcherBinder = watcher.asBinder();
4556 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4557 public void binderDied() {
4558 synchronized (mWindowMap) {
4559 for (int i=0; i<mRotationWatchers.size(); i++) {
4560 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004561 IRotationWatcher removed = mRotationWatchers.remove(i);
4562 if (removed != null) {
4563 removed.asBinder().unlinkToDeath(this, 0);
4564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 i--;
4566 }
4567 }
4568 }
4569 }
4570 };
Romain Guy06882f82009-06-10 13:36:04 -07004571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004572 synchronized (mWindowMap) {
4573 try {
4574 watcher.asBinder().linkToDeath(dr, 0);
4575 mRotationWatchers.add(watcher);
4576 } catch (RemoteException e) {
4577 // Client died, no cleanup needed.
4578 }
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 return mRotation;
4581 }
4582 }
4583
4584 /**
4585 * Starts the view server on the specified port.
4586 *
4587 * @param port The port to listener to.
4588 *
4589 * @return True if the server was successfully started, false otherwise.
4590 *
4591 * @see com.android.server.ViewServer
4592 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4593 */
4594 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004595 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004596 return false;
4597 }
4598
4599 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4600 return false;
4601 }
4602
4603 if (port < 1024) {
4604 return false;
4605 }
4606
4607 if (mViewServer != null) {
4608 if (!mViewServer.isRunning()) {
4609 try {
4610 return mViewServer.start();
4611 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004612 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 }
4614 }
4615 return false;
4616 }
4617
4618 try {
4619 mViewServer = new ViewServer(this, port);
4620 return mViewServer.start();
4621 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004622 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 }
4624 return false;
4625 }
4626
Romain Guy06882f82009-06-10 13:36:04 -07004627 private boolean isSystemSecure() {
4628 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4629 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4630 }
4631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632 /**
4633 * Stops the view server if it exists.
4634 *
4635 * @return True if the server stopped, false if it wasn't started or
4636 * couldn't be stopped.
4637 *
4638 * @see com.android.server.ViewServer
4639 */
4640 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004641 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 return false;
4643 }
4644
4645 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4646 return false;
4647 }
4648
4649 if (mViewServer != null) {
4650 return mViewServer.stop();
4651 }
4652 return false;
4653 }
4654
4655 /**
4656 * Indicates whether the view server is running.
4657 *
4658 * @return True if the server is running, false otherwise.
4659 *
4660 * @see com.android.server.ViewServer
4661 */
4662 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004663 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004664 return false;
4665 }
4666
4667 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4668 return false;
4669 }
4670
4671 return mViewServer != null && mViewServer.isRunning();
4672 }
4673
4674 /**
4675 * Lists all availble windows in the system. The listing is written in the
4676 * specified Socket's output stream with the following syntax:
4677 * windowHashCodeInHexadecimal windowName
4678 * Each line of the ouput represents a different window.
4679 *
4680 * @param client The remote client to send the listing to.
4681 * @return False if an error occured, true otherwise.
4682 */
4683 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004684 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 return false;
4686 }
4687
4688 boolean result = true;
4689
4690 Object[] windows;
4691 synchronized (mWindowMap) {
4692 windows = new Object[mWindows.size()];
4693 //noinspection unchecked
4694 windows = mWindows.toArray(windows);
4695 }
4696
4697 BufferedWriter out = null;
4698
4699 // Any uncaught exception will crash the system process
4700 try {
4701 OutputStream clientStream = client.getOutputStream();
4702 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4703
4704 final int count = windows.length;
4705 for (int i = 0; i < count; i++) {
4706 final WindowState w = (WindowState) windows[i];
4707 out.write(Integer.toHexString(System.identityHashCode(w)));
4708 out.write(' ');
4709 out.append(w.mAttrs.getTitle());
4710 out.write('\n');
4711 }
4712
4713 out.write("DONE.\n");
4714 out.flush();
4715 } catch (Exception e) {
4716 result = false;
4717 } finally {
4718 if (out != null) {
4719 try {
4720 out.close();
4721 } catch (IOException e) {
4722 result = false;
4723 }
4724 }
4725 }
4726
4727 return result;
4728 }
4729
4730 /**
4731 * Sends a command to a target window. The result of the command, if any, will be
4732 * written in the output stream of the specified socket.
4733 *
4734 * The parameters must follow this syntax:
4735 * windowHashcode extra
4736 *
4737 * Where XX is the length in characeters of the windowTitle.
4738 *
4739 * The first parameter is the target window. The window with the specified hashcode
4740 * will be the target. If no target can be found, nothing happens. The extra parameters
4741 * will be delivered to the target window and as parameters to the command itself.
4742 *
4743 * @param client The remote client to sent the result, if any, to.
4744 * @param command The command to execute.
4745 * @param parameters The command parameters.
4746 *
4747 * @return True if the command was successfully delivered, false otherwise. This does
4748 * not indicate whether the command itself was successful.
4749 */
4750 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004751 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004752 return false;
4753 }
4754
4755 boolean success = true;
4756 Parcel data = null;
4757 Parcel reply = null;
4758
4759 // Any uncaught exception will crash the system process
4760 try {
4761 // Find the hashcode of the window
4762 int index = parameters.indexOf(' ');
4763 if (index == -1) {
4764 index = parameters.length();
4765 }
4766 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004767 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004768
4769 // Extract the command's parameter after the window description
4770 if (index < parameters.length()) {
4771 parameters = parameters.substring(index + 1);
4772 } else {
4773 parameters = "";
4774 }
4775
4776 final WindowManagerService.WindowState window = findWindow(hashCode);
4777 if (window == null) {
4778 return false;
4779 }
4780
4781 data = Parcel.obtain();
4782 data.writeInterfaceToken("android.view.IWindow");
4783 data.writeString(command);
4784 data.writeString(parameters);
4785 data.writeInt(1);
4786 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4787
4788 reply = Parcel.obtain();
4789
4790 final IBinder binder = window.mClient.asBinder();
4791 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4792 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4793
4794 reply.readException();
4795
4796 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004797 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004798 success = false;
4799 } finally {
4800 if (data != null) {
4801 data.recycle();
4802 }
4803 if (reply != null) {
4804 reply.recycle();
4805 }
4806 }
4807
4808 return success;
4809 }
4810
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004811 public void addWindowChangeListener(WindowChangeListener listener) {
4812 synchronized(mWindowMap) {
4813 mWindowChangeListeners.add(listener);
4814 }
4815 }
4816
4817 public void removeWindowChangeListener(WindowChangeListener listener) {
4818 synchronized(mWindowMap) {
4819 mWindowChangeListeners.remove(listener);
4820 }
4821 }
4822
4823 private void notifyWindowsChanged() {
4824 WindowChangeListener[] windowChangeListeners;
4825 synchronized(mWindowMap) {
4826 if(mWindowChangeListeners.isEmpty()) {
4827 return;
4828 }
4829 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4830 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4831 }
4832 int N = windowChangeListeners.length;
4833 for(int i = 0; i < N; i++) {
4834 windowChangeListeners[i].windowsChanged();
4835 }
4836 }
4837
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004838 private void notifyFocusChanged() {
4839 WindowChangeListener[] windowChangeListeners;
4840 synchronized(mWindowMap) {
4841 if(mWindowChangeListeners.isEmpty()) {
4842 return;
4843 }
4844 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4845 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4846 }
4847 int N = windowChangeListeners.length;
4848 for(int i = 0; i < N; i++) {
4849 windowChangeListeners[i].focusChanged();
4850 }
4851 }
4852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 private WindowState findWindow(int hashCode) {
4854 if (hashCode == -1) {
4855 return getFocusedWindow();
4856 }
4857
4858 synchronized (mWindowMap) {
4859 final ArrayList windows = mWindows;
4860 final int count = windows.size();
4861
4862 for (int i = 0; i < count; i++) {
4863 WindowState w = (WindowState) windows.get(i);
4864 if (System.identityHashCode(w) == hashCode) {
4865 return w;
4866 }
4867 }
4868 }
4869
4870 return null;
4871 }
4872
4873 /*
4874 * Instruct the Activity Manager to fetch the current configuration and broadcast
4875 * that to config-changed listeners if appropriate.
4876 */
4877 void sendNewConfiguration() {
4878 try {
4879 mActivityManager.updateConfiguration(null);
4880 } catch (RemoteException e) {
4881 }
4882 }
Romain Guy06882f82009-06-10 13:36:04 -07004883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004884 public Configuration computeNewConfiguration() {
4885 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004886 return computeNewConfigurationLocked();
4887 }
4888 }
Romain Guy06882f82009-06-10 13:36:04 -07004889
Dianne Hackbornc485a602009-03-24 22:39:49 -07004890 Configuration computeNewConfigurationLocked() {
4891 Configuration config = new Configuration();
4892 if (!computeNewConfigurationLocked(config)) {
4893 return null;
4894 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004895 return config;
4896 }
Romain Guy06882f82009-06-10 13:36:04 -07004897
Dianne Hackbornc485a602009-03-24 22:39:49 -07004898 boolean computeNewConfigurationLocked(Configuration config) {
4899 if (mDisplay == null) {
4900 return false;
4901 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004902
4903 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004904
4905 // Use the effective "visual" dimensions based on current rotation
4906 final boolean rotated = (mRotation == Surface.ROTATION_90
4907 || mRotation == Surface.ROTATION_270);
4908 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4909 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4910
Dianne Hackbornc485a602009-03-24 22:39:49 -07004911 int orientation = Configuration.ORIENTATION_SQUARE;
4912 if (dw < dh) {
4913 orientation = Configuration.ORIENTATION_PORTRAIT;
4914 } else if (dw > dh) {
4915 orientation = Configuration.ORIENTATION_LANDSCAPE;
4916 }
4917 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004918
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004919 DisplayMetrics dm = new DisplayMetrics();
4920 mDisplay.getMetrics(dm);
4921 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4922
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004923 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004924 // Note we only do this once because at this point we don't
4925 // expect the screen to change in this way at runtime, and want
4926 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004927 int longSize = dw;
4928 int shortSize = dh;
4929 if (longSize < shortSize) {
4930 int tmp = longSize;
4931 longSize = shortSize;
4932 shortSize = tmp;
4933 }
4934 longSize = (int)(longSize/dm.density);
4935 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004936
Dianne Hackborn723738c2009-06-25 19:48:04 -07004937 // These semi-magic numbers define our compatibility modes for
4938 // applications with different screens. Don't change unless you
4939 // make sure to test lots and lots of apps!
4940 if (longSize < 470) {
4941 // This is shorter than an HVGA normal density screen (which
4942 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004943 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4944 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004945 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004946 // What size is this screen screen?
4947 if (longSize >= 800 && shortSize >= 600) {
4948 // SVGA or larger screens at medium density are the point
4949 // at which we consider it to be an extra large screen.
4950 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4951 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004952 // VGA or larger screens at medium density are the point
4953 // at which we consider it to be a large screen.
4954 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4955 } else {
4956 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004957
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004958 // If this screen is wider than normal HVGA, or taller
4959 // than FWVGA, then for old apps we want to run in size
4960 // compatibility mode.
4961 if (shortSize > 321 || longSize > 570) {
4962 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4963 }
4964 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004965
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004966 // Is this a long screen?
4967 if (((longSize*3)/5) >= (shortSize-1)) {
4968 // Anything wider than WVGA (5:3) is considering to be long.
4969 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4970 } else {
4971 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4972 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004973 }
4974 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004975 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004976
Dianne Hackbornc485a602009-03-24 22:39:49 -07004977 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4978 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4979 mPolicy.adjustConfigurationLw(config);
4980 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 // -------------------------------------------------------------
4984 // Input Events and Focus Management
4985 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07004986
Jeff Brown349703e2010-06-22 01:27:15 -07004987 InputMonitor mInputMonitor = new InputMonitor();
4988
4989 /* Tracks the progress of input dispatch and ensures that input dispatch state
4990 * is kept in sync with changes in window focus, visibility, registration, and
4991 * other relevant Window Manager state transitions. */
4992 final class InputMonitor {
4993 // Current window with input focus for keys and other non-touch events. May be null.
4994 private WindowState mInputFocus;
4995
4996 // When true, prevents input dispatch from proceeding until set to false again.
4997 private boolean mInputDispatchFrozen;
4998
4999 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5000 private boolean mInputDispatchEnabled = true;
5001
5002 // Temporary list of windows information to provide to the input dispatcher.
5003 private InputWindowList mTempInputWindows = new InputWindowList();
5004
5005 // Temporary input application object to provide to the input dispatcher.
5006 private InputApplication mTempInputApplication = new InputApplication();
5007
5008 /* Notifies the window manager about a broken input channel.
5009 *
5010 * Called by the InputManager.
5011 */
5012 public void notifyInputChannelBroken(InputChannel inputChannel) {
5013 synchronized (mWindowMap) {
5014 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5015 if (windowState == null) {
5016 return; // irrelevant
5017 }
5018
5019 Slog.i(TAG, "WINDOW DIED " + windowState);
5020 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005021 }
5022 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005023
Jeff Brown349703e2010-06-22 01:27:15 -07005024 /* Notifies the window manager about an input channel that is not responding.
5025 * The method can either cause dispatching to be aborted by returning -2 or
5026 * return a new timeout in nanoseconds.
5027 *
5028 * Called by the InputManager.
5029 */
5030 public long notifyInputChannelANR(InputChannel inputChannel) {
5031 AppWindowToken token;
5032 synchronized (mWindowMap) {
5033 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5034 if (windowState == null) {
5035 return -2; // irrelevant, abort dispatching (-2)
5036 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005037
Jeff Brown349703e2010-06-22 01:27:15 -07005038 Slog.i(TAG, "Input event dispatching timed out sending to "
5039 + windowState.mAttrs.getTitle());
5040 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005041 }
5042
Jeff Brown349703e2010-06-22 01:27:15 -07005043 return notifyANRInternal(token);
5044 }
5045
5046 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5047 * by successfully delivering the event that originally timed out.
5048 *
5049 * Called by the InputManager.
5050 */
5051 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5052 // Nothing to do just now.
5053 // Just wait for the user to dismiss the ANR dialog.
5054 }
5055
5056 /* Notifies the window manager about an application that is not responding
5057 * in general rather than with respect to a particular input channel.
5058 * The method can either cause dispatching to be aborted by returning -2 or
5059 * return a new timeout in nanoseconds.
5060 *
5061 * Called by the InputManager.
5062 */
5063 public long notifyANR(Object token) {
5064 AppWindowToken appWindowToken = (AppWindowToken) token;
5065
5066 Slog.i(TAG, "Input event dispatching timed out sending to application "
5067 + appWindowToken.stringName);
5068 return notifyANRInternal(appWindowToken);
5069 }
5070
5071 private long notifyANRInternal(AppWindowToken token) {
5072 if (token != null && token.appToken != null) {
5073 try {
5074 // Notify the activity manager about the timeout and let it decide whether
5075 // to abort dispatching or keep waiting.
5076 boolean abort = token.appToken.keyDispatchingTimedOut();
5077 if (! abort) {
5078 // The activity manager declined to abort dispatching.
5079 // Wait a bit longer and timeout again later.
5080 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005081 }
Jeff Brown349703e2010-06-22 01:27:15 -07005082 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005083 }
5084 }
Jeff Brown349703e2010-06-22 01:27:15 -07005085 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005086 }
5087
Jeff Brown349703e2010-06-22 01:27:15 -07005088 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5089 synchronized (mWindowMap) {
5090 return getWindowStateForInputChannelLocked(inputChannel);
5091 }
5092 }
5093
5094 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5095 int windowCount = mWindows.size();
5096 for (int i = 0; i < windowCount; i++) {
5097 WindowState windowState = (WindowState) mWindows.get(i);
5098 if (windowState.mInputChannel == inputChannel) {
5099 return windowState;
5100 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005101 }
5102
Jeff Brown349703e2010-06-22 01:27:15 -07005103 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005104 }
5105
Jeff Brown349703e2010-06-22 01:27:15 -07005106 /* Updates the cached window information provided to the input dispatcher. */
5107 public void updateInputWindowsLw() {
5108 // Populate the input window list with information about all of the windows that
5109 // could potentially receive input.
5110 // As an optimization, we could try to prune the list of windows but this turns
5111 // out to be difficult because only the native code knows for sure which window
5112 // currently has touch focus.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005113 final ArrayList windows = mWindows;
5114 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005115 for (int i = N - 1; i >= 0; i--) {
5116 final WindowState child = (WindowState) windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005117 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005118 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005119 continue;
5120 }
5121
Jeff Brown349703e2010-06-22 01:27:15 -07005122 final int flags = child.mAttrs.flags;
5123 final int type = child.mAttrs.type;
5124
5125 final boolean hasFocus = (child == mInputFocus);
5126 final boolean isVisible = child.isVisibleLw();
5127 final boolean hasWallpaper = (child == mWallpaperTarget)
5128 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5129
5130 // Add a window to our list of input windows.
5131 final InputWindow inputWindow = mTempInputWindows.add();
5132 inputWindow.inputChannel = child.mInputChannel;
5133 inputWindow.layoutParamsFlags = flags;
5134 inputWindow.layoutParamsType = type;
5135 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5136 inputWindow.visible = isVisible;
5137 inputWindow.hasFocus = hasFocus;
5138 inputWindow.hasWallpaper = hasWallpaper;
5139 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5140 inputWindow.ownerPid = child.mSession.mPid;
5141 inputWindow.ownerUid = child.mSession.mUid;
5142
5143 final Rect frame = child.mFrame;
5144 inputWindow.frameLeft = frame.left;
5145 inputWindow.frameTop = frame.top;
5146
5147 switch (child.mTouchableInsets) {
5148 default:
5149 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5150 inputWindow.touchableAreaLeft = frame.left;
5151 inputWindow.touchableAreaTop = frame.top;
5152 inputWindow.touchableAreaRight = frame.right;
5153 inputWindow.touchableAreaBottom = frame.bottom;
5154 break;
5155
5156 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5157 Rect inset = child.mGivenContentInsets;
5158 inputWindow.touchableAreaLeft = frame.left + inset.left;
5159 inputWindow.touchableAreaTop = frame.top + inset.top;
5160 inputWindow.touchableAreaRight = frame.right - inset.right;
5161 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5162 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005163 }
Jeff Brown349703e2010-06-22 01:27:15 -07005164
5165 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5166 Rect inset = child.mGivenVisibleInsets;
5167 inputWindow.touchableAreaLeft = frame.left + inset.left;
5168 inputWindow.touchableAreaTop = frame.top + inset.top;
5169 inputWindow.touchableAreaRight = frame.right - inset.right;
5170 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005171 break;
5172 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005173 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005174 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005175
Jeff Brown349703e2010-06-22 01:27:15 -07005176 // Send windows to native code.
5177 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005178
Jeff Brown349703e2010-06-22 01:27:15 -07005179 // Clear the list in preparation for the next round.
5180 // Also avoids keeping InputChannel objects referenced unnecessarily.
5181 mTempInputWindows.clear();
5182 }
5183
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005184 /* Provides feedback for a virtual key down. */
5185 public void virtualKeyDownFeedback() {
5186 synchronized (mWindowMap) {
5187 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5188 }
5189 }
5190
Jeff Brown349703e2010-06-22 01:27:15 -07005191 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5192 * This essentially starts a .5 second timeout for the application to process
5193 * subsequent input events while waiting for the app switch to occur. If it takes longer
5194 * than this, the pending events will be dropped.
5195 */
5196 public void notifyAppSwitchComing() {
5197 // TODO Not implemented yet. Should go in the native side.
5198 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005199
5200 /* Notifies that the lid switch changed state. */
5201 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5202 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5203 }
5204
Jeff Brown349703e2010-06-22 01:27:15 -07005205 /* Provides an opportunity for the window manager policy to intercept early key
5206 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005207 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5208 int policyFlags, boolean isScreenOn) {
5209 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5210 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005211 }
5212
5213 /* Provides an opportunity for the window manager policy to process a key before
5214 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005215 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5216 int action, int flags, int keyCode, int metaState, int repeatCount,
5217 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005218 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005219 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5220 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005221 }
5222
5223 /* Called when the current input focus changes.
5224 * Layer assignment is assumed to be complete by the time this is called.
5225 */
5226 public void setInputFocusLw(WindowState newWindow) {
5227 if (DEBUG_INPUT) {
5228 Slog.d(TAG, "Input focus has changed to " + newWindow);
5229 }
5230
5231 if (newWindow != mInputFocus) {
5232 if (newWindow != null && newWindow.canReceiveKeys()) {
5233 // If the new input focus is an error window or appears above the current
5234 // input focus, preempt any pending synchronous dispatch so that we can
5235 // start delivering events to the new input focus as soon as possible.
5236 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5237 if (DEBUG_INPUT) {
5238 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac02010-04-22 18:58:52 -07005239 }
Jeff Brown349703e2010-06-22 01:27:15 -07005240 preemptInputDispatchLw();
5241 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5242 if (DEBUG_INPUT) {
5243 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5244 + "old win layer=" + mInputFocus.mLayer
5245 + ", new win layer=" + newWindow.mLayer);
5246 }
5247 preemptInputDispatchLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005248 }
Jeff Brown349703e2010-06-22 01:27:15 -07005249
5250 // Displaying a window implicitly causes dispatching to be unpaused.
5251 // This is to protect against bugs if someone pauses dispatching but
5252 // forgets to resume.
5253 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005254 }
Jeff Brown349703e2010-06-22 01:27:15 -07005255
5256 mInputFocus = newWindow;
5257 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005258 }
5259 }
5260
Jeff Brown349703e2010-06-22 01:27:15 -07005261 public void windowIsBecomingInvisibleLw(WindowState window) {
5262 // The window is becoming invisible. Preempt input dispatch in progress
5263 // so that the next window below can receive focus.
5264 if (window == mInputFocus) {
5265 mInputFocus = null;
5266 preemptInputDispatchLw();
5267 }
5268
5269 updateInputWindowsLw();
5270 }
5271
5272 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5273 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5274 * can begin.
5275 */
5276 private void preemptInputDispatchLw() {
5277 mInputManager.preemptInputDispatch();
5278 }
5279
5280 public void setFocusedAppLw(AppWindowToken newApp) {
5281 // Focused app has changed.
5282 if (newApp == null) {
5283 mInputManager.setFocusedApplication(null);
5284 } else {
5285 mTempInputApplication.name = newApp.toString();
5286 mTempInputApplication.dispatchingTimeoutNanos =
5287 newApp.inputDispatchingTimeoutNanos;
5288 mTempInputApplication.token = newApp;
5289
5290 mInputManager.setFocusedApplication(mTempInputApplication);
5291 }
5292 }
5293
Jeff Brown349703e2010-06-22 01:27:15 -07005294 public void pauseDispatchingLw(WindowToken window) {
5295 if (! window.paused) {
5296 if (DEBUG_INPUT) {
5297 Slog.v(TAG, "Pausing WindowToken " + window);
5298 }
5299
5300 window.paused = true;
5301 updateInputWindowsLw();
5302 }
5303 }
5304
5305 public void resumeDispatchingLw(WindowToken window) {
5306 if (window.paused) {
5307 if (DEBUG_INPUT) {
5308 Slog.v(TAG, "Resuming WindowToken " + window);
5309 }
5310
5311 window.paused = false;
5312 updateInputWindowsLw();
5313 }
5314 }
5315
5316 public void freezeInputDispatchingLw() {
5317 if (! mInputDispatchFrozen) {
5318 if (DEBUG_INPUT) {
5319 Slog.v(TAG, "Freezing input dispatching");
5320 }
5321
5322 mInputDispatchFrozen = true;
5323 updateInputDispatchModeLw();
5324 }
5325 }
5326
5327 public void thawInputDispatchingLw() {
5328 if (mInputDispatchFrozen) {
5329 if (DEBUG_INPUT) {
5330 Slog.v(TAG, "Thawing input dispatching");
5331 }
5332
5333 mInputDispatchFrozen = false;
5334 updateInputDispatchModeLw();
5335 }
5336 }
5337
5338 public void setEventDispatchingLw(boolean enabled) {
5339 if (mInputDispatchEnabled != enabled) {
5340 if (DEBUG_INPUT) {
5341 Slog.v(TAG, "Setting event dispatching to " + enabled);
5342 }
5343
5344 mInputDispatchEnabled = enabled;
5345 updateInputDispatchModeLw();
5346 }
5347 }
5348
5349 private void updateInputDispatchModeLw() {
5350 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5351 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 public void pauseKeyDispatching(IBinder _token) {
5355 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5356 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005357 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005358 }
5359
5360 synchronized (mWindowMap) {
5361 WindowToken token = mTokenMap.get(_token);
5362 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005363 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005364 }
5365 }
5366 }
5367
5368 public void resumeKeyDispatching(IBinder _token) {
5369 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5370 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005371 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005372 }
5373
5374 synchronized (mWindowMap) {
5375 WindowToken token = mTokenMap.get(_token);
5376 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005377 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005378 }
5379 }
5380 }
5381
5382 public void setEventDispatching(boolean enabled) {
5383 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5384 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005385 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005386 }
5387
5388 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005389 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005390 }
5391 }
Romain Guy06882f82009-06-10 13:36:04 -07005392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 /**
5394 * Injects a keystroke event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005395 *
5396 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005397 * {@link SystemClock#uptimeMillis()} as the timebase.)
5398 * @param sync If true, wait for the event to be completed before returning to the caller.
5399 * @return Returns true if event was dispatched, false if it was dropped for any reason
5400 */
5401 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5402 long downTime = ev.getDownTime();
5403 long eventTime = ev.getEventTime();
5404
5405 int action = ev.getAction();
5406 int code = ev.getKeyCode();
5407 int repeatCount = ev.getRepeatCount();
5408 int metaState = ev.getMetaState();
5409 int deviceId = ev.getDeviceId();
5410 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005411 int source = ev.getSource();
5412
5413 if (source == InputDevice.SOURCE_UNKNOWN) {
5414 source = InputDevice.SOURCE_KEYBOARD;
5415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005416
5417 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5418 if (downTime == 0) downTime = eventTime;
5419
5420 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005421 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005423 final int pid = Binder.getCallingPid();
5424 final int uid = Binder.getCallingUid();
5425 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005426
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005427 final int result = mInputManager.injectKeyEvent(newEvent,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005428 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005429
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005430 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005431 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005432 }
5433
5434 /**
5435 * Inject a pointer (touch) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005436 *
5437 * @param ev A motion event describing the pointer (touch) action. (As noted in
5438 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005439 * {@link SystemClock#uptimeMillis()} as the timebase.)
5440 * @param sync If true, wait for the event to be completed before returning to the caller.
5441 * @return Returns true if event was dispatched, false if it was dropped for any reason
5442 */
5443 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005444 final int pid = Binder.getCallingPid();
5445 final int uid = Binder.getCallingUid();
5446 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005447
Jeff Brownc5ed5912010-07-14 18:48:53 -07005448 MotionEvent newEvent = MotionEvent.obtain(ev);
5449 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5450 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5451 }
5452
5453 final int result = mInputManager.injectMotionEvent(newEvent,
5454 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005455
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005456 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005457 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005458 }
Romain Guy06882f82009-06-10 13:36:04 -07005459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005460 /**
5461 * Inject a trackball (navigation device) event into the UI.
Romain Guy06882f82009-06-10 13:36:04 -07005462 *
5463 * @param ev A motion event describing the trackball action. (As noted in
5464 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005465 * {@link SystemClock#uptimeMillis()} as the timebase.)
5466 * @param sync If true, wait for the event to be completed before returning to the caller.
5467 * @return Returns true if event was dispatched, false if it was dropped for any reason
5468 */
5469 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005470 final int pid = Binder.getCallingPid();
5471 final int uid = Binder.getCallingUid();
5472 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005473
Jeff Brownc5ed5912010-07-14 18:48:53 -07005474 MotionEvent newEvent = MotionEvent.obtain(ev);
5475 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5476 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5477 }
5478
5479 final int result = mInputManager.injectMotionEvent(newEvent,
5480 pid, uid, sync, INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005481
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005482 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005483 return reportInjectionResult(result);
5484 }
5485
5486 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005487 switch (result) {
5488 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5489 Slog.w(TAG, "Input event injection permission denied.");
5490 throw new SecurityException(
5491 "Injecting to another application requires INJECT_EVENTS permission");
5492 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
5493 Slog.v(TAG, "Input event injection succeeded.");
5494 return true;
5495 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5496 Slog.w(TAG, "Input event injection timed out.");
5497 return false;
5498 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5499 default:
5500 Slog.w(TAG, "Input event injection failed.");
5501 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005503 }
Romain Guy06882f82009-06-10 13:36:04 -07005504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005505 private WindowState getFocusedWindow() {
5506 synchronized (mWindowMap) {
5507 return getFocusedWindowLocked();
5508 }
5509 }
5510
5511 private WindowState getFocusedWindowLocked() {
5512 return mCurrentFocus;
5513 }
Romain Guy06882f82009-06-10 13:36:04 -07005514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005515 public boolean detectSafeMode() {
5516 mSafeMode = mPolicy.detectSafeMode();
5517 return mSafeMode;
5518 }
Romain Guy06882f82009-06-10 13:36:04 -07005519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005520 public void systemReady() {
5521 mPolicy.systemReady();
5522 }
Romain Guy06882f82009-06-10 13:36:04 -07005523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005524 // -------------------------------------------------------------
5525 // Client Session State
5526 // -------------------------------------------------------------
5527
5528 private final class Session extends IWindowSession.Stub
5529 implements IBinder.DeathRecipient {
5530 final IInputMethodClient mClient;
5531 final IInputContext mInputContext;
5532 final int mUid;
5533 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005534 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005535 SurfaceSession mSurfaceSession;
5536 int mNumWindow = 0;
5537 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 public Session(IInputMethodClient client, IInputContext inputContext) {
5540 mClient = client;
5541 mInputContext = inputContext;
5542 mUid = Binder.getCallingUid();
5543 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005544 StringBuilder sb = new StringBuilder();
5545 sb.append("Session{");
5546 sb.append(Integer.toHexString(System.identityHashCode(this)));
5547 sb.append(" uid ");
5548 sb.append(mUid);
5549 sb.append("}");
5550 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005552 synchronized (mWindowMap) {
5553 if (mInputMethodManager == null && mHaveInputMethods) {
5554 IBinder b = ServiceManager.getService(
5555 Context.INPUT_METHOD_SERVICE);
5556 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5557 }
5558 }
5559 long ident = Binder.clearCallingIdentity();
5560 try {
5561 // Note: it is safe to call in to the input method manager
5562 // here because we are not holding our lock.
5563 if (mInputMethodManager != null) {
5564 mInputMethodManager.addClient(client, inputContext,
5565 mUid, mPid);
5566 } else {
5567 client.setUsingInputMethod(false);
5568 }
5569 client.asBinder().linkToDeath(this, 0);
5570 } catch (RemoteException e) {
5571 // The caller has died, so we can just forget about this.
5572 try {
5573 if (mInputMethodManager != null) {
5574 mInputMethodManager.removeClient(client);
5575 }
5576 } catch (RemoteException ee) {
5577 }
5578 } finally {
5579 Binder.restoreCallingIdentity(ident);
5580 }
5581 }
Romain Guy06882f82009-06-10 13:36:04 -07005582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005583 @Override
5584 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5585 throws RemoteException {
5586 try {
5587 return super.onTransact(code, data, reply, flags);
5588 } catch (RuntimeException e) {
5589 // Log all 'real' exceptions thrown to the caller
5590 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005591 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005592 }
5593 throw e;
5594 }
5595 }
5596
5597 public void binderDied() {
5598 // Note: it is safe to call in to the input method manager
5599 // here because we are not holding our lock.
5600 try {
5601 if (mInputMethodManager != null) {
5602 mInputMethodManager.removeClient(mClient);
5603 }
5604 } catch (RemoteException e) {
5605 }
5606 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005607 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005608 mClientDead = true;
5609 killSessionLocked();
5610 }
5611 }
5612
5613 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07005614 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5615 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5616 outInputChannel);
5617 }
5618
5619 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005620 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07005621 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005622 }
Romain Guy06882f82009-06-10 13:36:04 -07005623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005624 public void remove(IWindow window) {
5625 removeWindow(this, window);
5626 }
Romain Guy06882f82009-06-10 13:36:04 -07005627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005628 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5629 int requestedWidth, int requestedHeight, int viewFlags,
5630 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005631 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005632 return relayoutWindow(this, window, attrs,
5633 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005634 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005635 }
Romain Guy06882f82009-06-10 13:36:04 -07005636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005637 public void setTransparentRegion(IWindow window, Region region) {
5638 setTransparentRegionWindow(this, window, region);
5639 }
Romain Guy06882f82009-06-10 13:36:04 -07005640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005641 public void setInsets(IWindow window, int touchableInsets,
5642 Rect contentInsets, Rect visibleInsets) {
5643 setInsetsWindow(this, window, touchableInsets, contentInsets,
5644 visibleInsets);
5645 }
Romain Guy06882f82009-06-10 13:36:04 -07005646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005647 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5648 getWindowDisplayFrame(this, window, outDisplayFrame);
5649 }
Romain Guy06882f82009-06-10 13:36:04 -07005650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005651 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005652 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005653 TAG, "IWindow finishDrawing called for " + window);
5654 finishDrawingWindow(this, window);
5655 }
5656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 public void setInTouchMode(boolean mode) {
5658 synchronized(mWindowMap) {
5659 mInTouchMode = mode;
5660 }
5661 }
5662
5663 public boolean getInTouchMode() {
5664 synchronized(mWindowMap) {
5665 return mInTouchMode;
5666 }
5667 }
5668
5669 public boolean performHapticFeedback(IWindow window, int effectId,
5670 boolean always) {
5671 synchronized(mWindowMap) {
5672 long ident = Binder.clearCallingIdentity();
5673 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005674 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005675 windowForClientLocked(this, window, true),
5676 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005677 } finally {
5678 Binder.restoreCallingIdentity(ident);
5679 }
5680 }
5681 }
Romain Guy06882f82009-06-10 13:36:04 -07005682
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005683 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005684 synchronized(mWindowMap) {
5685 long ident = Binder.clearCallingIdentity();
5686 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005687 setWindowWallpaperPositionLocked(
5688 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005689 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005690 } finally {
5691 Binder.restoreCallingIdentity(ident);
5692 }
5693 }
5694 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005695
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005696 public void wallpaperOffsetsComplete(IBinder window) {
5697 WindowManagerService.this.wallpaperOffsetsComplete(window);
5698 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005699
Dianne Hackborn75804932009-10-20 20:15:20 -07005700 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5701 int z, Bundle extras, boolean sync) {
5702 synchronized(mWindowMap) {
5703 long ident = Binder.clearCallingIdentity();
5704 try {
5705 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005706 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005707 action, x, y, z, extras, sync);
5708 } finally {
5709 Binder.restoreCallingIdentity(ident);
5710 }
5711 }
5712 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005713
Dianne Hackborn75804932009-10-20 20:15:20 -07005714 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5715 WindowManagerService.this.wallpaperCommandComplete(window, result);
5716 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005718 void windowAddedLocked() {
5719 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005720 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005721 TAG, "First window added to " + this + ", creating SurfaceSession");
5722 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005723 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005724 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 mSessions.add(this);
5726 }
5727 mNumWindow++;
5728 }
5729
5730 void windowRemovedLocked() {
5731 mNumWindow--;
5732 killSessionLocked();
5733 }
Romain Guy06882f82009-06-10 13:36:04 -07005734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005735 void killSessionLocked() {
5736 if (mNumWindow <= 0 && mClientDead) {
5737 mSessions.remove(this);
5738 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005739 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005740 TAG, "Last window removed from " + this
5741 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005742 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005743 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005744 try {
5745 mSurfaceSession.kill();
5746 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005747 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005748 + mSurfaceSession + " in session " + this
5749 + ": " + e.toString());
5750 }
5751 mSurfaceSession = null;
5752 }
5753 }
5754 }
Romain Guy06882f82009-06-10 13:36:04 -07005755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005756 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005757 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5758 pw.print(" mClientDead="); pw.print(mClientDead);
5759 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005760 }
5761
5762 @Override
5763 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005764 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005765 }
5766 }
5767
5768 // -------------------------------------------------------------
5769 // Client Window State
5770 // -------------------------------------------------------------
5771
5772 private final class WindowState implements WindowManagerPolicy.WindowState {
5773 final Session mSession;
5774 final IWindow mClient;
5775 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005776 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005777 AppWindowToken mAppToken;
5778 AppWindowToken mTargetAppToken;
5779 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5780 final DeathRecipient mDeathRecipient;
5781 final WindowState mAttachedWindow;
5782 final ArrayList mChildWindows = new ArrayList();
5783 final int mBaseLayer;
5784 final int mSubLayer;
5785 final boolean mLayoutAttached;
5786 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005787 final boolean mIsWallpaper;
5788 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005789 int mViewVisibility;
5790 boolean mPolicyVisibility = true;
5791 boolean mPolicyVisibilityAfterAnim = true;
5792 boolean mAppFreezing;
5793 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005794 boolean mReportDestroySurface;
5795 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005796 boolean mAttachedHidden; // is our parent window hidden?
5797 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005798 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005799 int mRequestedWidth;
5800 int mRequestedHeight;
5801 int mLastRequestedWidth;
5802 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005803 int mLayer;
5804 int mAnimLayer;
5805 int mLastLayer;
5806 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005807 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005808 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005809
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005810 int mLayoutSeq = -1;
5811
5812 Configuration mConfiguration = null;
5813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005814 // Actual frame shown on-screen (may be modified by animation)
5815 final Rect mShownFrame = new Rect();
5816 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005818 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005819 * Set when we have changed the size of the surface, to know that
5820 * we must tell them application to resize (and thus redraw itself).
5821 */
5822 boolean mSurfaceResized;
5823
5824 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 * Insets that determine the actually visible area
5826 */
5827 final Rect mVisibleInsets = new Rect();
5828 final Rect mLastVisibleInsets = new Rect();
5829 boolean mVisibleInsetsChanged;
5830
5831 /**
5832 * Insets that are covered by system windows
5833 */
5834 final Rect mContentInsets = new Rect();
5835 final Rect mLastContentInsets = new Rect();
5836 boolean mContentInsetsChanged;
5837
5838 /**
5839 * Set to true if we are waiting for this window to receive its
5840 * given internal insets before laying out other windows based on it.
5841 */
5842 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 /**
5845 * These are the content insets that were given during layout for
5846 * this window, to be applied to windows behind it.
5847 */
5848 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 /**
5851 * These are the visible insets that were given during layout for
5852 * this window, to be applied to windows behind it.
5853 */
5854 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005856 /**
5857 * Flag indicating whether the touchable region should be adjusted by
5858 * the visible insets; if false the area outside the visible insets is
5859 * NOT touchable, so we must use those to adjust the frame during hit
5860 * tests.
5861 */
5862 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005864 // Current transformation being applied.
5865 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5866 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5867 float mHScale=1, mVScale=1;
5868 float mLastHScale=1, mLastVScale=1;
5869 final Matrix mTmpMatrix = new Matrix();
5870
5871 // "Real" frame that the application sees.
5872 final Rect mFrame = new Rect();
5873 final Rect mLastFrame = new Rect();
5874
5875 final Rect mContainingFrame = new Rect();
5876 final Rect mDisplayFrame = new Rect();
5877 final Rect mContentFrame = new Rect();
5878 final Rect mVisibleFrame = new Rect();
5879
5880 float mShownAlpha = 1;
5881 float mAlpha = 1;
5882 float mLastAlpha = 1;
5883
5884 // Set to true if, when the window gets displayed, it should perform
5885 // an enter animation.
5886 boolean mEnterAnimationPending;
5887
5888 // Currently running animation.
5889 boolean mAnimating;
5890 boolean mLocalAnimating;
5891 Animation mAnimation;
5892 boolean mAnimationIsEntrance;
5893 boolean mHasTransformation;
5894 boolean mHasLocalTransformation;
5895 final Transformation mTransformation = new Transformation();
5896
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005897 // If a window showing a wallpaper: the requested offset for the
5898 // wallpaper; if a wallpaper window: the currently applied offset.
5899 float mWallpaperX = -1;
5900 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005901
5902 // If a window showing a wallpaper: what fraction of the offset
5903 // range corresponds to a full virtual screen.
5904 float mWallpaperXStep = -1;
5905 float mWallpaperYStep = -1;
5906
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005907 // Wallpaper windows: pixels offset based on above variables.
5908 int mXOffset;
5909 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 // This is set after IWindowSession.relayout() has been called at
5912 // least once for the window. It allows us to detect the situation
5913 // where we don't yet have a surface, but should have one soon, so
5914 // we can give the window focus before waiting for the relayout.
5915 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005917 // This is set after the Surface has been created but before the
5918 // window has been drawn. During this time the surface is hidden.
5919 boolean mDrawPending;
5920
5921 // This is set after the window has finished drawing for the first
5922 // time but before its surface is shown. The surface will be
5923 // displayed when the next layout is run.
5924 boolean mCommitDrawPending;
5925
5926 // This is set during the time after the window's drawing has been
5927 // committed, and before its surface is actually shown. It is used
5928 // to delay showing the surface until all windows in a token are ready
5929 // to be shown.
5930 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005932 // Set when the window has been shown in the screen the first time.
5933 boolean mHasDrawn;
5934
5935 // Currently running an exit animation?
5936 boolean mExiting;
5937
5938 // Currently on the mDestroySurface list?
5939 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 // Completely remove from window manager after exit animation?
5942 boolean mRemoveOnExit;
5943
5944 // Set when the orientation is changing and this window has not yet
5945 // been updated for the new orientation.
5946 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005948 // Is this window now (or just being) removed?
5949 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005950
Dianne Hackborn16064f92010-03-25 00:47:24 -07005951 // For debugging, this is the last information given to the surface flinger.
5952 boolean mSurfaceShown;
5953 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5954 int mSurfaceLayer;
5955 float mSurfaceAlpha;
5956
Jeff Brown46b9ac02010-04-22 18:58:52 -07005957 // Input channel
5958 InputChannel mInputChannel;
5959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005960 WindowState(Session s, IWindow c, WindowToken token,
5961 WindowState attachedWindow, WindowManager.LayoutParams a,
5962 int viewVisibility) {
5963 mSession = s;
5964 mClient = c;
5965 mToken = token;
5966 mAttrs.copyFrom(a);
5967 mViewVisibility = viewVisibility;
5968 DeathRecipient deathRecipient = new DeathRecipient();
5969 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005970 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 TAG, "Window " + this + " client=" + c.asBinder()
5972 + " token=" + token + " (" + mAttrs.token + ")");
5973 try {
5974 c.asBinder().linkToDeath(deathRecipient, 0);
5975 } catch (RemoteException e) {
5976 mDeathRecipient = null;
5977 mAttachedWindow = null;
5978 mLayoutAttached = false;
5979 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005980 mIsWallpaper = false;
5981 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005982 mBaseLayer = 0;
5983 mSubLayer = 0;
5984 return;
5985 }
5986 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07005987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005988 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
5989 mAttrs.type <= LAST_SUB_WINDOW)) {
5990 // The multiplier here is to reserve space for multiple
5991 // windows in the same type layer.
5992 mBaseLayer = mPolicy.windowTypeToLayerLw(
5993 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
5994 + TYPE_LAYER_OFFSET;
5995 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
5996 mAttachedWindow = attachedWindow;
5997 mAttachedWindow.mChildWindows.add(this);
5998 mLayoutAttached = mAttrs.type !=
5999 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6000 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6001 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006002 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6003 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006004 } else {
6005 // The multiplier here is to reserve space for multiple
6006 // windows in the same type layer.
6007 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6008 * TYPE_LAYER_MULTIPLIER
6009 + TYPE_LAYER_OFFSET;
6010 mSubLayer = 0;
6011 mAttachedWindow = null;
6012 mLayoutAttached = false;
6013 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6014 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006015 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6016 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006017 }
6018
6019 WindowState appWin = this;
6020 while (appWin.mAttachedWindow != null) {
6021 appWin = mAttachedWindow;
6022 }
6023 WindowToken appToken = appWin.mToken;
6024 while (appToken.appWindowToken == null) {
6025 WindowToken parent = mTokenMap.get(appToken.token);
6026 if (parent == null || appToken == parent) {
6027 break;
6028 }
6029 appToken = parent;
6030 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006031 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006032 mAppToken = appToken.appWindowToken;
6033
6034 mSurface = null;
6035 mRequestedWidth = 0;
6036 mRequestedHeight = 0;
6037 mLastRequestedWidth = 0;
6038 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006039 mXOffset = 0;
6040 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006041 mLayer = 0;
6042 mAnimLayer = 0;
6043 mLastLayer = 0;
6044 }
6045
6046 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006047 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006048 TAG, "Attaching " + this + " token=" + mToken
6049 + ", list=" + mToken.windows);
6050 mSession.windowAddedLocked();
6051 }
6052
6053 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6054 mHaveFrame = true;
6055
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006056 final Rect container = mContainingFrame;
6057 container.set(pf);
6058
6059 final Rect display = mDisplayFrame;
6060 display.set(df);
6061
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006062 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006063 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006064 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6065 display.intersect(mCompatibleScreenFrame);
6066 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006067 }
6068
6069 final int pw = container.right - container.left;
6070 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071
6072 int w,h;
6073 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6074 w = mAttrs.width < 0 ? pw : mAttrs.width;
6075 h = mAttrs.height< 0 ? ph : mAttrs.height;
6076 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006077 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6078 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006079 }
Romain Guy06882f82009-06-10 13:36:04 -07006080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006081 final Rect content = mContentFrame;
6082 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006084 final Rect visible = mVisibleFrame;
6085 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006086
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006087 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006088 final int fw = frame.width();
6089 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006091 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6092 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6093
6094 Gravity.apply(mAttrs.gravity, w, h, container,
6095 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6096 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6097
6098 //System.out.println("Out: " + mFrame);
6099
6100 // Now make sure the window fits in the overall display.
6101 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006103 // Make sure the content and visible frames are inside of the
6104 // final window frame.
6105 if (content.left < frame.left) content.left = frame.left;
6106 if (content.top < frame.top) content.top = frame.top;
6107 if (content.right > frame.right) content.right = frame.right;
6108 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6109 if (visible.left < frame.left) visible.left = frame.left;
6110 if (visible.top < frame.top) visible.top = frame.top;
6111 if (visible.right > frame.right) visible.right = frame.right;
6112 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006114 final Rect contentInsets = mContentInsets;
6115 contentInsets.left = content.left-frame.left;
6116 contentInsets.top = content.top-frame.top;
6117 contentInsets.right = frame.right-content.right;
6118 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006120 final Rect visibleInsets = mVisibleInsets;
6121 visibleInsets.left = visible.left-frame.left;
6122 visibleInsets.top = visible.top-frame.top;
6123 visibleInsets.right = frame.right-visible.right;
6124 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006125
Dianne Hackborn284ac932009-08-28 10:34:25 -07006126 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6127 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006128 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006129 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006131 if (localLOGV) {
6132 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6133 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006134 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006135 + mRequestedWidth + ", mRequestedheight="
6136 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6137 + "): frame=" + mFrame.toShortString()
6138 + " ci=" + contentInsets.toShortString()
6139 + " vi=" + visibleInsets.toShortString());
6140 //}
6141 }
6142 }
Romain Guy06882f82009-06-10 13:36:04 -07006143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 public Rect getFrameLw() {
6145 return mFrame;
6146 }
6147
6148 public Rect getShownFrameLw() {
6149 return mShownFrame;
6150 }
6151
6152 public Rect getDisplayFrameLw() {
6153 return mDisplayFrame;
6154 }
6155
6156 public Rect getContentFrameLw() {
6157 return mContentFrame;
6158 }
6159
6160 public Rect getVisibleFrameLw() {
6161 return mVisibleFrame;
6162 }
6163
6164 public boolean getGivenInsetsPendingLw() {
6165 return mGivenInsetsPending;
6166 }
6167
6168 public Rect getGivenContentInsetsLw() {
6169 return mGivenContentInsets;
6170 }
Romain Guy06882f82009-06-10 13:36:04 -07006171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006172 public Rect getGivenVisibleInsetsLw() {
6173 return mGivenVisibleInsets;
6174 }
Romain Guy06882f82009-06-10 13:36:04 -07006175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006176 public WindowManager.LayoutParams getAttrs() {
6177 return mAttrs;
6178 }
6179
6180 public int getSurfaceLayer() {
6181 return mLayer;
6182 }
Romain Guy06882f82009-06-10 13:36:04 -07006183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006184 public IApplicationToken getAppToken() {
6185 return mAppToken != null ? mAppToken.appToken : null;
6186 }
Jeff Brown349703e2010-06-22 01:27:15 -07006187
6188 public long getInputDispatchingTimeoutNanos() {
6189 return mAppToken != null
6190 ? mAppToken.inputDispatchingTimeoutNanos
6191 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6192 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193
6194 public boolean hasAppShownWindows() {
6195 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6196 }
6197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006198 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006199 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 TAG, "Setting animation in " + this + ": " + anim);
6201 mAnimating = false;
6202 mLocalAnimating = false;
6203 mAnimation = anim;
6204 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6205 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6206 }
6207
6208 public void clearAnimation() {
6209 if (mAnimation != null) {
6210 mAnimating = true;
6211 mLocalAnimating = false;
6212 mAnimation = null;
6213 }
6214 }
Romain Guy06882f82009-06-10 13:36:04 -07006215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006216 Surface createSurfaceLocked() {
6217 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006218 mReportDestroySurface = false;
6219 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006220 mDrawPending = true;
6221 mCommitDrawPending = false;
6222 mReadyToShow = false;
6223 if (mAppToken != null) {
6224 mAppToken.allDrawn = false;
6225 }
6226
6227 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006228 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006229 flags |= Surface.PUSH_BUFFERS;
6230 }
6231
6232 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6233 flags |= Surface.SECURE;
6234 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006235 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006236 TAG, "Creating surface in session "
6237 + mSession.mSurfaceSession + " window " + this
6238 + " w=" + mFrame.width()
6239 + " h=" + mFrame.height() + " format="
6240 + mAttrs.format + " flags=" + flags);
6241
6242 int w = mFrame.width();
6243 int h = mFrame.height();
6244 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6245 // for a scaled surface, we always want the requested
6246 // size.
6247 w = mRequestedWidth;
6248 h = mRequestedHeight;
6249 }
6250
Romain Guy9825ec62009-10-01 00:58:09 -07006251 // Something is wrong and SurfaceFlinger will not like this,
6252 // try to revert to sane values
6253 if (w <= 0) w = 1;
6254 if (h <= 0) h = 1;
6255
Dianne Hackborn16064f92010-03-25 00:47:24 -07006256 mSurfaceShown = false;
6257 mSurfaceLayer = 0;
6258 mSurfaceAlpha = 1;
6259 mSurfaceX = 0;
6260 mSurfaceY = 0;
6261 mSurfaceW = w;
6262 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006263 try {
6264 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006265 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006266 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006267 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006268 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006269 + mSurface + " IN SESSION "
6270 + mSession.mSurfaceSession
6271 + ": pid=" + mSession.mPid + " format="
6272 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006273 + Integer.toHexString(flags)
6274 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006275 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006276 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277 reclaimSomeSurfaceMemoryLocked(this, "create");
6278 return null;
6279 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006280 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006281 return null;
6282 }
Romain Guy06882f82009-06-10 13:36:04 -07006283
Joe Onorato8a9b2202010-02-26 18:56:32 -08006284 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006285 TAG, "Got surface: " + mSurface
6286 + ", set left=" + mFrame.left + " top=" + mFrame.top
6287 + ", animLayer=" + mAnimLayer);
6288 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006289 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006290 if (SHOW_TRANSACTIONS) logSurface(this,
6291 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6292 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6293 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006294 }
6295 Surface.openTransaction();
6296 try {
6297 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006298 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006299 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006300 mSurface.setPosition(mSurfaceX, mSurfaceY);
6301 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006302 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006303 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 mSurface.hide();
6305 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006306 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006307 mSurface.setFlags(Surface.SURFACE_DITHER,
6308 Surface.SURFACE_DITHER);
6309 }
6310 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006311 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006312 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6313 }
6314 mLastHidden = true;
6315 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006316 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006317 Surface.closeTransaction();
6318 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006319 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006320 TAG, "Created surface " + this);
6321 }
6322 return mSurface;
6323 }
Romain Guy06882f82009-06-10 13:36:04 -07006324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006325 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326 if (mAppToken != null && this == mAppToken.startingWindow) {
6327 mAppToken.startingDisplayed = false;
6328 }
Romain Guy06882f82009-06-10 13:36:04 -07006329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006330 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006331 mDrawPending = false;
6332 mCommitDrawPending = false;
6333 mReadyToShow = false;
6334
6335 int i = mChildWindows.size();
6336 while (i > 0) {
6337 i--;
6338 WindowState c = (WindowState)mChildWindows.get(i);
6339 c.mAttachedHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006340
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006341 mInputMonitor.windowIsBecomingInvisibleLw(c);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006342 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006343
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006344 if (mReportDestroySurface) {
6345 mReportDestroySurface = false;
6346 mSurfacePendingDestroy = true;
6347 try {
6348 mClient.dispatchGetNewSurface();
6349 // We'll really destroy on the next time around.
6350 return;
6351 } catch (RemoteException e) {
6352 }
6353 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006355 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006356 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006357 RuntimeException e = null;
6358 if (!HIDE_STACK_CRAWLS) {
6359 e = new RuntimeException();
6360 e.fillInStackTrace();
6361 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006362 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006363 + mSurface + ", session " + mSession, e);
6364 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006366 RuntimeException e = null;
6367 if (!HIDE_STACK_CRAWLS) {
6368 e = new RuntimeException();
6369 e.fillInStackTrace();
6370 }
6371 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006372 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006373 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006375 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006376 + " surface " + mSurface + " session " + mSession
6377 + ": " + e.toString());
6378 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006379
Dianne Hackborn16064f92010-03-25 00:47:24 -07006380 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006381 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006382 }
6383 }
6384
6385 boolean finishDrawingLocked() {
6386 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006387 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006388 TAG, "finishDrawingLocked: " + mSurface);
6389 mCommitDrawPending = true;
6390 mDrawPending = false;
6391 return true;
6392 }
6393 return false;
6394 }
6395
6396 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006397 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006398 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006399 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006400 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 }
6402 mCommitDrawPending = false;
6403 mReadyToShow = true;
6404 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6405 final AppWindowToken atoken = mAppToken;
6406 if (atoken == null || atoken.allDrawn || starting) {
6407 performShowLocked();
6408 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006409 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 }
6411
6412 // This must be called while inside a transaction.
6413 boolean performShowLocked() {
6414 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006415 RuntimeException e = null;
6416 if (!HIDE_STACK_CRAWLS) {
6417 e = new RuntimeException();
6418 e.fillInStackTrace();
6419 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006420 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6422 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6423 }
6424 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006425 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6426 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006427 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006428 + " during animation: policyVis=" + mPolicyVisibility
6429 + " attHidden=" + mAttachedHidden
6430 + " tok.hiddenRequested="
6431 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006432 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006433 + (mAppToken != null ? mAppToken.hidden : false)
6434 + " animating=" + mAnimating
6435 + " tok animating="
6436 + (mAppToken != null ? mAppToken.animating : false));
6437 if (!showSurfaceRobustlyLocked(this)) {
6438 return false;
6439 }
6440 mLastAlpha = -1;
6441 mHasDrawn = true;
6442 mLastHidden = false;
6443 mReadyToShow = false;
6444 enableScreenIfNeededLocked();
6445
6446 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006448 int i = mChildWindows.size();
6449 while (i > 0) {
6450 i--;
6451 WindowState c = (WindowState)mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006452 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006454 if (c.mSurface != null) {
6455 c.performShowLocked();
6456 // It hadn't been shown, which means layout not
6457 // performed on it, so now we want to make sure to
6458 // do a layout. If called from within the transaction
6459 // loop, this will cause it to restart with a new
6460 // layout.
6461 mLayoutNeeded = true;
6462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006463 }
6464 }
Romain Guy06882f82009-06-10 13:36:04 -07006465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006466 if (mAttrs.type != TYPE_APPLICATION_STARTING
6467 && mAppToken != null) {
6468 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006469
Dianne Hackborn248b1882009-09-16 16:46:44 -07006470 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006471 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006472 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006473 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006474 // If this initial window is animating, stop it -- we
6475 // will do an animation to reveal it from behind the
6476 // starting window, so there is no need for it to also
6477 // be doing its own stuff.
6478 if (mAnimation != null) {
6479 mAnimation = null;
6480 // Make sure we clean up the animation.
6481 mAnimating = true;
6482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 mFinishedStarting.add(mAppToken);
6484 mH.sendEmptyMessage(H.FINISHED_STARTING);
6485 }
6486 mAppToken.updateReportedVisibilityLocked();
6487 }
6488 }
6489 return true;
6490 }
Romain Guy06882f82009-06-10 13:36:04 -07006491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 // This must be called while inside a transaction. Returns true if
6493 // there is more animation to run.
6494 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006495 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006496 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6499 mHasTransformation = true;
6500 mHasLocalTransformation = true;
6501 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006502 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 TAG, "Starting animation in " + this +
6504 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6505 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6506 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6507 mAnimation.setStartTime(currentTime);
6508 mLocalAnimating = true;
6509 mAnimating = true;
6510 }
6511 mTransformation.clear();
6512 final boolean more = mAnimation.getTransformation(
6513 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006514 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 TAG, "Stepped animation in " + this +
6516 ": more=" + more + ", xform=" + mTransformation);
6517 if (more) {
6518 // we're not done!
6519 return true;
6520 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006521 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006522 TAG, "Finished animation in " + this +
6523 " @ " + currentTime);
6524 mAnimation = null;
6525 //WindowManagerService.this.dump();
6526 }
6527 mHasLocalTransformation = false;
6528 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006529 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006530 // When our app token is animating, we kind-of pretend like
6531 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6532 // part of this check means that we will only do this if
6533 // our window is not currently exiting, or it is not
6534 // locally animating itself. The idea being that one that
6535 // is exiting and doing a local animation should be removed
6536 // once that animation is done.
6537 mAnimating = true;
6538 mHasTransformation = true;
6539 mTransformation.clear();
6540 return false;
6541 } else if (mHasTransformation) {
6542 // Little trick to get through the path below to act like
6543 // we have finished an animation.
6544 mAnimating = true;
6545 } else if (isAnimating()) {
6546 mAnimating = true;
6547 }
6548 } else if (mAnimation != null) {
6549 // If the display is frozen, and there is a pending animation,
6550 // clear it and make sure we run the cleanup code.
6551 mAnimating = true;
6552 mLocalAnimating = true;
6553 mAnimation = null;
6554 }
Romain Guy06882f82009-06-10 13:36:04 -07006555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006556 if (!mAnimating && !mLocalAnimating) {
6557 return false;
6558 }
6559
Joe Onorato8a9b2202010-02-26 18:56:32 -08006560 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 TAG, "Animation done in " + this + ": exiting=" + mExiting
6562 + ", reportedVisible="
6563 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 mAnimating = false;
6566 mLocalAnimating = false;
6567 mAnimation = null;
6568 mAnimLayer = mLayer;
6569 if (mIsImWindow) {
6570 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006571 } else if (mIsWallpaper) {
6572 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006574 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006575 + " anim layer: " + mAnimLayer);
6576 mHasTransformation = false;
6577 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006578 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6579 if (DEBUG_VISIBILITY) {
6580 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6581 + mPolicyVisibilityAfterAnim);
6582 }
6583 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6584 if (!mPolicyVisibility) {
6585 if (mCurrentFocus == this) {
6586 mFocusMayChange = true;
6587 }
6588 // Window is no longer visible -- make sure if we were waiting
6589 // for it to be displayed before enabling the display, that
6590 // we allow the display to be enabled now.
6591 enableScreenIfNeededLocked();
6592 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006594 mTransformation.clear();
6595 if (mHasDrawn
6596 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6597 && mAppToken != null
6598 && mAppToken.firstWindowDrawn
6599 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006600 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006601 + mToken + ": first real window done animating");
6602 mFinishedStarting.add(mAppToken);
6603 mH.sendEmptyMessage(H.FINISHED_STARTING);
6604 }
Romain Guy06882f82009-06-10 13:36:04 -07006605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 finishExit();
6607
6608 if (mAppToken != null) {
6609 mAppToken.updateReportedVisibilityLocked();
6610 }
6611
6612 return false;
6613 }
6614
6615 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006616 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006617 TAG, "finishExit in " + this
6618 + ": exiting=" + mExiting
6619 + " remove=" + mRemoveOnExit
6620 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006622 final int N = mChildWindows.size();
6623 for (int i=0; i<N; i++) {
6624 ((WindowState)mChildWindows.get(i)).finishExit();
6625 }
Romain Guy06882f82009-06-10 13:36:04 -07006626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006627 if (!mExiting) {
6628 return;
6629 }
Romain Guy06882f82009-06-10 13:36:04 -07006630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006631 if (isWindowAnimating()) {
6632 return;
6633 }
6634
Joe Onorato8a9b2202010-02-26 18:56:32 -08006635 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006636 TAG, "Exit animation finished in " + this
6637 + ": remove=" + mRemoveOnExit);
6638 if (mSurface != null) {
6639 mDestroySurface.add(this);
6640 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006641 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006642 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006643 try {
6644 mSurface.hide();
6645 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006646 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006647 }
6648 mLastHidden = true;
Jeff Brown349703e2010-06-22 01:27:15 -07006649
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006650 for (int i=0; i<N; i++) {
6651 mInputMonitor.windowIsBecomingInvisibleLw((WindowState)mChildWindows.get(i));
Jeff Brown349703e2010-06-22 01:27:15 -07006652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006653 }
6654 mExiting = false;
6655 if (mRemoveOnExit) {
6656 mPendingRemove.add(this);
6657 mRemoveOnExit = false;
6658 }
6659 }
Romain Guy06882f82009-06-10 13:36:04 -07006660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6662 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6663 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6664 if (dtdx < -.000001f || dtdx > .000001f) return false;
6665 if (dsdy < -.000001f || dsdy > .000001f) return false;
6666 return true;
6667 }
Romain Guy06882f82009-06-10 13:36:04 -07006668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006669 void computeShownFrameLocked() {
6670 final boolean selfTransformation = mHasLocalTransformation;
6671 Transformation attachedTransformation =
6672 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6673 ? mAttachedWindow.mTransformation : null;
6674 Transformation appTransformation =
6675 (mAppToken != null && mAppToken.hasTransformation)
6676 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006677
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006678 // Wallpapers are animated based on the "real" window they
6679 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006680 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006681 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006682 if (mWallpaperTarget.mHasLocalTransformation &&
6683 mWallpaperTarget.mAnimation != null &&
6684 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006685 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006686 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006687 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006688 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006689 }
6690 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006691 mWallpaperTarget.mAppToken.hasTransformation &&
6692 mWallpaperTarget.mAppToken.animation != null &&
6693 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006694 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006695 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006696 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006697 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006698 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006699 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006701 if (selfTransformation || attachedTransformation != null
6702 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006703 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006704 final Rect frame = mFrame;
6705 final float tmpFloats[] = mTmpFloats;
6706 final Matrix tmpMatrix = mTmpMatrix;
6707
6708 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006709 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006711 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006712 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006713 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006714 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006715 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 }
6717 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006718 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006719 }
6720
6721 // "convert" it into SurfaceFlinger's format
6722 // (a 2x2 matrix + an offset)
6723 // Here we must not transform the position of the surface
6724 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006725 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 tmpMatrix.getValues(tmpFloats);
6728 mDsDx = tmpFloats[Matrix.MSCALE_X];
6729 mDtDx = tmpFloats[Matrix.MSKEW_X];
6730 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6731 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006732 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6733 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 int w = frame.width();
6735 int h = frame.height();
6736 mShownFrame.set(x, y, x+w, y+h);
6737
6738 // Now set the alpha... but because our current hardware
6739 // can't do alpha transformation on a non-opaque surface,
6740 // turn it off if we are running an animation that is also
6741 // transforming since it is more important to have that
6742 // animation be smooth.
6743 mShownAlpha = mAlpha;
6744 if (!mLimitedAlphaCompositing
6745 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6746 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6747 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006748 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006749 if (selfTransformation) {
6750 mShownAlpha *= mTransformation.getAlpha();
6751 }
6752 if (attachedTransformation != null) {
6753 mShownAlpha *= attachedTransformation.getAlpha();
6754 }
6755 if (appTransformation != null) {
6756 mShownAlpha *= appTransformation.getAlpha();
6757 }
6758 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006759 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006760 }
Romain Guy06882f82009-06-10 13:36:04 -07006761
Joe Onorato8a9b2202010-02-26 18:56:32 -08006762 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006763 TAG, "Continuing animation in " + this +
6764 ": " + mShownFrame +
6765 ", alpha=" + mTransformation.getAlpha());
6766 return;
6767 }
Romain Guy06882f82009-06-10 13:36:04 -07006768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006770 if (mXOffset != 0 || mYOffset != 0) {
6771 mShownFrame.offset(mXOffset, mYOffset);
6772 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006773 mShownAlpha = mAlpha;
6774 mDsDx = 1;
6775 mDtDx = 0;
6776 mDsDy = 0;
6777 mDtDy = 1;
6778 }
Romain Guy06882f82009-06-10 13:36:04 -07006779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006780 /**
6781 * Is this window visible? It is not visible if there is no
6782 * surface, or we are in the process of running an exit animation
6783 * that will remove the surface, or its app token has been hidden.
6784 */
6785 public boolean isVisibleLw() {
6786 final AppWindowToken atoken = mAppToken;
6787 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6788 && (atoken == null || !atoken.hiddenRequested)
6789 && !mExiting && !mDestroying;
6790 }
6791
6792 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006793 * Like {@link #isVisibleLw}, but also counts a window that is currently
6794 * "hidden" behind the keyguard as visible. This allows us to apply
6795 * things like window flags that impact the keyguard.
6796 * XXX I am starting to think we need to have ANOTHER visibility flag
6797 * for this "hidden behind keyguard" state rather than overloading
6798 * mPolicyVisibility. Ungh.
6799 */
6800 public boolean isVisibleOrBehindKeyguardLw() {
6801 final AppWindowToken atoken = mAppToken;
6802 return mSurface != null && !mAttachedHidden
6803 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006804 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006805 && !mExiting && !mDestroying;
6806 }
6807
6808 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006809 * Is this window visible, ignoring its app token? It is not visible
6810 * if there is no surface, or we are in the process of running an exit animation
6811 * that will remove the surface.
6812 */
6813 public boolean isWinVisibleLw() {
6814 final AppWindowToken atoken = mAppToken;
6815 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6816 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6817 && !mExiting && !mDestroying;
6818 }
6819
6820 /**
6821 * The same as isVisible(), but follows the current hidden state of
6822 * the associated app token, not the pending requested hidden state.
6823 */
6824 boolean isVisibleNow() {
6825 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006826 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 }
6828
6829 /**
6830 * Same as isVisible(), but we also count it as visible between the
6831 * call to IWindowSession.add() and the first relayout().
6832 */
6833 boolean isVisibleOrAdding() {
6834 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006835 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006836 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6837 && mPolicyVisibility && !mAttachedHidden
6838 && (atoken == null || !atoken.hiddenRequested)
6839 && !mExiting && !mDestroying;
6840 }
6841
6842 /**
6843 * Is this window currently on-screen? It is on-screen either if it
6844 * is visible or it is currently running an animation before no longer
6845 * being visible.
6846 */
6847 boolean isOnScreen() {
6848 final AppWindowToken atoken = mAppToken;
6849 if (atoken != null) {
6850 return mSurface != null && mPolicyVisibility && !mDestroying
6851 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006852 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 } else {
6854 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006855 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 }
6857 }
Romain Guy06882f82009-06-10 13:36:04 -07006858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006859 /**
6860 * Like isOnScreen(), but we don't return true if the window is part
6861 * of a transition that has not yet been started.
6862 */
6863 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006864 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006865 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006866 return false;
6867 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006868 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006869 final boolean animating = atoken != null
6870 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006872 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6873 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006874 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 }
6876
6877 /** Is the window or its container currently animating? */
6878 boolean isAnimating() {
6879 final WindowState attached = mAttachedWindow;
6880 final AppWindowToken atoken = mAppToken;
6881 return mAnimation != null
6882 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006883 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006884 (atoken.animation != null
6885 || atoken.inPendingTransaction));
6886 }
6887
6888 /** Is this window currently animating? */
6889 boolean isWindowAnimating() {
6890 return mAnimation != null;
6891 }
6892
6893 /**
6894 * Like isOnScreen, but returns false if the surface hasn't yet
6895 * been drawn.
6896 */
6897 public boolean isDisplayedLw() {
6898 final AppWindowToken atoken = mAppToken;
6899 return mSurface != null && mPolicyVisibility && !mDestroying
6900 && !mDrawPending && !mCommitDrawPending
6901 && ((!mAttachedHidden &&
6902 (atoken == null || !atoken.hiddenRequested))
6903 || mAnimating);
6904 }
6905
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006906 /**
6907 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006908 * complete UI in to. Note that this returns true if the orientation
6909 * is changing even if the window hasn't redrawn because we don't want
6910 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006911 */
6912 public boolean isDrawnLw() {
6913 final AppWindowToken atoken = mAppToken;
6914 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006915 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006916 }
6917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006918 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6919 boolean shownFrame, boolean onlyOpaque) {
6920 if (mSurface == null) {
6921 return false;
6922 }
6923 if (mAppToken != null && !mAppToken.appFullscreen) {
6924 return false;
6925 }
6926 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6927 return false;
6928 }
6929 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006930
6931 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6932 return frame.left <= mCompatibleScreenFrame.left &&
6933 frame.top <= mCompatibleScreenFrame.top &&
6934 frame.right >= mCompatibleScreenFrame.right &&
6935 frame.bottom >= mCompatibleScreenFrame.bottom;
6936 } else {
6937 return frame.left <= 0 && frame.top <= 0
6938 && frame.right >= screenWidth
6939 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006940 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 }
Romain Guy06882f82009-06-10 13:36:04 -07006942
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006943 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006944 * Return true if the window is opaque and fully drawn. This indicates
6945 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006946 */
6947 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006948 return (mAttrs.format == PixelFormat.OPAQUE
6949 || mAttrs.type == TYPE_WALLPAPER)
6950 && mSurface != null && mAnimation == null
6951 && (mAppToken == null || mAppToken.animation == null)
6952 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006953 }
6954
6955 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6956 return
6957 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006958 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6959 // only if it's visible
6960 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006961 // and only if the application fills the compatible screen
6962 mFrame.left <= mCompatibleScreenFrame.left &&
6963 mFrame.top <= mCompatibleScreenFrame.top &&
6964 mFrame.right >= mCompatibleScreenFrame.right &&
6965 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006966 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006967 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006968 }
6969
6970 boolean isFullscreen(int screenWidth, int screenHeight) {
6971 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006972 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006973 }
6974
6975 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07006976 disposeInputChannel();
6977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006978 if (mAttachedWindow != null) {
6979 mAttachedWindow.mChildWindows.remove(this);
6980 }
6981 destroySurfaceLocked();
6982 mSession.windowRemovedLocked();
6983 try {
6984 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
6985 } catch (RuntimeException e) {
6986 // Ignore if it has already been removed (usually because
6987 // we are doing this as part of processing a death note.)
6988 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07006989 }
6990
6991 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006992 if (mInputChannel != null) {
6993 mInputManager.unregisterInputChannel(mInputChannel);
6994
6995 mInputChannel.dispose();
6996 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07006997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006998 }
6999
7000 private class DeathRecipient implements IBinder.DeathRecipient {
7001 public void binderDied() {
7002 try {
7003 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007004 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007005 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007006 if (win != null) {
7007 removeWindowLocked(mSession, win);
7008 }
7009 }
7010 } catch (IllegalArgumentException ex) {
7011 // This will happen if the window has already been
7012 // removed.
7013 }
7014 }
7015 }
7016
7017 /** Returns true if this window desires key events. */
7018 public final boolean canReceiveKeys() {
7019 return isVisibleOrAdding()
7020 && (mViewVisibility == View.VISIBLE)
7021 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7022 }
7023
7024 public boolean hasDrawnLw() {
7025 return mHasDrawn;
7026 }
7027
7028 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007029 return showLw(doAnimation, true);
7030 }
7031
7032 boolean showLw(boolean doAnimation, boolean requestAnim) {
7033 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7034 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007036 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007037 if (doAnimation) {
7038 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7039 + mPolicyVisibility + " mAnimation=" + mAnimation);
7040 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7041 doAnimation = false;
7042 } else if (mPolicyVisibility && mAnimation == null) {
7043 // Check for the case where we are currently visible and
7044 // not animating; we do not want to do animation at such a
7045 // point to become visible when we already are.
7046 doAnimation = false;
7047 }
7048 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007049 mPolicyVisibility = true;
7050 mPolicyVisibilityAfterAnim = true;
7051 if (doAnimation) {
7052 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7053 }
7054 if (requestAnim) {
7055 requestAnimationLocked(0);
7056 }
7057 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007058 }
7059
7060 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007061 return hideLw(doAnimation, true);
7062 }
7063
7064 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007065 if (doAnimation) {
7066 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7067 doAnimation = false;
7068 }
7069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007070 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7071 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007072 if (!current) {
7073 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007074 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007075 if (doAnimation) {
7076 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7077 if (mAnimation == null) {
7078 doAnimation = false;
7079 }
7080 }
7081 if (doAnimation) {
7082 mPolicyVisibilityAfterAnim = false;
7083 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007084 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007085 mPolicyVisibilityAfterAnim = false;
7086 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007087 // Window is no longer visible -- make sure if we were waiting
7088 // for it to be displayed before enabling the display, that
7089 // we allow the display to be enabled now.
7090 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007091 if (mCurrentFocus == this) {
7092 mFocusMayChange = true;
7093 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007094 }
7095 if (requestAnim) {
7096 requestAnimationLocked(0);
7097 }
7098 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 }
7100
7101 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007102 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7103 pw.print(" mClient="); pw.println(mClient.asBinder());
7104 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7105 if (mAttachedWindow != null || mLayoutAttached) {
7106 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7107 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7108 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007109 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7110 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7111 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007112 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7113 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007114 }
7115 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7116 pw.print(" mSubLayer="); pw.print(mSubLayer);
7117 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7118 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7119 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7120 pw.print("="); pw.print(mAnimLayer);
7121 pw.print(" mLastLayer="); pw.println(mLastLayer);
7122 if (mSurface != null) {
7123 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007124 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7125 pw.print(" layer="); pw.print(mSurfaceLayer);
7126 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7127 pw.print(" rect=("); pw.print(mSurfaceX);
7128 pw.print(","); pw.print(mSurfaceY);
7129 pw.print(") "); pw.print(mSurfaceW);
7130 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007131 }
7132 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7133 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7134 if (mAppToken != null) {
7135 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7136 }
7137 if (mTargetAppToken != null) {
7138 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7139 }
7140 pw.print(prefix); pw.print("mViewVisibility=0x");
7141 pw.print(Integer.toHexString(mViewVisibility));
7142 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007143 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7144 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007145 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7146 pw.print(prefix); pw.print("mPolicyVisibility=");
7147 pw.print(mPolicyVisibility);
7148 pw.print(" mPolicyVisibilityAfterAnim=");
7149 pw.print(mPolicyVisibilityAfterAnim);
7150 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7151 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007152 if (!mRelayoutCalled) {
7153 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7154 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007155 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007156 pw.print(" h="); pw.print(mRequestedHeight);
7157 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007158 if (mXOffset != 0 || mYOffset != 0) {
7159 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7160 pw.print(" y="); pw.println(mYOffset);
7161 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007162 pw.print(prefix); pw.print("mGivenContentInsets=");
7163 mGivenContentInsets.printShortString(pw);
7164 pw.print(" mGivenVisibleInsets=");
7165 mGivenVisibleInsets.printShortString(pw);
7166 pw.println();
7167 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7168 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7169 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7170 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007171 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007172 pw.print(prefix); pw.print("mShownFrame=");
7173 mShownFrame.printShortString(pw);
7174 pw.print(" last="); mLastShownFrame.printShortString(pw);
7175 pw.println();
7176 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7177 pw.print(" last="); mLastFrame.printShortString(pw);
7178 pw.println();
7179 pw.print(prefix); pw.print("mContainingFrame=");
7180 mContainingFrame.printShortString(pw);
7181 pw.print(" mDisplayFrame=");
7182 mDisplayFrame.printShortString(pw);
7183 pw.println();
7184 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7185 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7186 pw.println();
7187 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7188 pw.print(" last="); mLastContentInsets.printShortString(pw);
7189 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7190 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7191 pw.println();
7192 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7193 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7194 pw.print(" mAlpha="); pw.print(mAlpha);
7195 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7196 }
7197 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7198 || mAnimation != null) {
7199 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7200 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7201 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7202 pw.print(" mAnimation="); pw.println(mAnimation);
7203 }
7204 if (mHasTransformation || mHasLocalTransformation) {
7205 pw.print(prefix); pw.print("XForm: has=");
7206 pw.print(mHasTransformation);
7207 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7208 pw.print(" "); mTransformation.printShortString(pw);
7209 pw.println();
7210 }
7211 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7212 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7213 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7214 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7215 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7216 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7217 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7218 pw.print(" mDestroying="); pw.print(mDestroying);
7219 pw.print(" mRemoved="); pw.println(mRemoved);
7220 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007221 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007222 pw.print(prefix); pw.print("mOrientationChanging=");
7223 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007224 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7225 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007226 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007227 if (mHScale != 1 || mVScale != 1) {
7228 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7229 pw.print(" mVScale="); pw.println(mVScale);
7230 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007231 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007232 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7233 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7234 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007235 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7236 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7237 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007239 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007240
7241 String makeInputChannelName() {
7242 return Integer.toHexString(System.identityHashCode(this))
7243 + " " + mAttrs.getTitle();
7244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007245
7246 @Override
7247 public String toString() {
7248 return "Window{"
7249 + Integer.toHexString(System.identityHashCode(this))
7250 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7251 }
7252 }
Romain Guy06882f82009-06-10 13:36:04 -07007253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007254 // -------------------------------------------------------------
7255 // Window Token State
7256 // -------------------------------------------------------------
7257
7258 class WindowToken {
7259 // The actual token.
7260 final IBinder token;
7261
7262 // The type of window this token is for, as per WindowManager.LayoutParams.
7263 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007265 // Set if this token was explicitly added by a client, so should
7266 // not be removed when all windows are removed.
7267 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007268
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007269 // For printing.
7270 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007272 // If this is an AppWindowToken, this is non-null.
7273 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 // All of the windows associated with this token.
7276 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7277
7278 // Is key dispatching paused for this token?
7279 boolean paused = false;
7280
7281 // Should this token's windows be hidden?
7282 boolean hidden;
7283
7284 // Temporary for finding which tokens no longer have visible windows.
7285 boolean hasVisible;
7286
Dianne Hackborna8f60182009-09-01 19:01:50 -07007287 // Set to true when this token is in a pending transaction where it
7288 // will be shown.
7289 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007290
Dianne Hackborna8f60182009-09-01 19:01:50 -07007291 // Set to true when this token is in a pending transaction where it
7292 // will be hidden.
7293 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007294
Dianne Hackborna8f60182009-09-01 19:01:50 -07007295 // Set to true when this token is in a pending transaction where its
7296 // windows will be put to the bottom of the list.
7297 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007298
Dianne Hackborna8f60182009-09-01 19:01:50 -07007299 // Set to true when this token is in a pending transaction where its
7300 // windows will be put to the top of the list.
7301 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007303 WindowToken(IBinder _token, int type, boolean _explicit) {
7304 token = _token;
7305 windowType = type;
7306 explicit = _explicit;
7307 }
7308
7309 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007310 pw.print(prefix); pw.print("token="); pw.println(token);
7311 pw.print(prefix); pw.print("windows="); pw.println(windows);
7312 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7313 pw.print(" hidden="); pw.print(hidden);
7314 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007315 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7316 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7317 pw.print(" waitingToHide="); pw.print(waitingToHide);
7318 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7319 pw.print(" sendingToTop="); pw.println(sendingToTop);
7320 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 }
7322
7323 @Override
7324 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007325 if (stringName == null) {
7326 StringBuilder sb = new StringBuilder();
7327 sb.append("WindowToken{");
7328 sb.append(Integer.toHexString(System.identityHashCode(this)));
7329 sb.append(" token="); sb.append(token); sb.append('}');
7330 stringName = sb.toString();
7331 }
7332 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007333 }
7334 };
7335
7336 class AppWindowToken extends WindowToken {
7337 // Non-null only for application tokens.
7338 final IApplicationToken appToken;
7339
7340 // All of the windows and child windows that are included in this
7341 // application token. Note this list is NOT sorted!
7342 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7343
7344 int groupId = -1;
7345 boolean appFullscreen;
7346 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007347
7348 // The input dispatching timeout for this application token in nanoseconds.
7349 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 // These are used for determining when all windows associated with
7352 // an activity have been drawn, so they can be made visible together
7353 // at the same time.
7354 int lastTransactionSequence = mTransactionSequence-1;
7355 int numInterestingWindows;
7356 int numDrawnWindows;
7357 boolean inPendingTransaction;
7358 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007360 // Is this token going to be hidden in a little while? If so, it
7361 // won't be taken into account for setting the screen orientation.
7362 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007364 // Is this window's surface needed? This is almost like hidden, except
7365 // it will sometimes be true a little earlier: when the token has
7366 // been shown, but is still waiting for its app transition to execute
7367 // before making its windows shown.
7368 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007370 // Have we told the window clients to hide themselves?
7371 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007373 // Last visibility state we reported to the app token.
7374 boolean reportedVisible;
7375
7376 // Set to true when the token has been removed from the window mgr.
7377 boolean removed;
7378
7379 // Have we been asked to have this token keep the screen frozen?
7380 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 boolean animating;
7383 Animation animation;
7384 boolean hasTransformation;
7385 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007387 // Offset to the window of all layers in the token, for use by
7388 // AppWindowToken animations.
7389 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007391 // Information about an application starting window if displayed.
7392 StartingData startingData;
7393 WindowState startingWindow;
7394 View startingView;
7395 boolean startingDisplayed;
7396 boolean startingMoved;
7397 boolean firstWindowDrawn;
7398
7399 AppWindowToken(IApplicationToken _token) {
7400 super(_token.asBinder(),
7401 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7402 appWindowToken = this;
7403 appToken = _token;
7404 }
Romain Guy06882f82009-06-10 13:36:04 -07007405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007406 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007407 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007408 TAG, "Setting animation in " + this + ": " + anim);
7409 animation = anim;
7410 animating = false;
7411 anim.restrictDuration(MAX_ANIMATION_DURATION);
7412 anim.scaleCurrentDuration(mTransitionAnimationScale);
7413 int zorder = anim.getZAdjustment();
7414 int adj = 0;
7415 if (zorder == Animation.ZORDER_TOP) {
7416 adj = TYPE_LAYER_OFFSET;
7417 } else if (zorder == Animation.ZORDER_BOTTOM) {
7418 adj = -TYPE_LAYER_OFFSET;
7419 }
Romain Guy06882f82009-06-10 13:36:04 -07007420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007421 if (animLayerAdjustment != adj) {
7422 animLayerAdjustment = adj;
7423 updateLayers();
7424 }
7425 }
Romain Guy06882f82009-06-10 13:36:04 -07007426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 public void setDummyAnimation() {
7428 if (animation == null) {
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 dummy animation in " + this);
7431 animation = sDummyAnimation;
7432 }
7433 }
7434
7435 public void clearAnimation() {
7436 if (animation != null) {
7437 animation = null;
7438 animating = true;
7439 }
7440 }
Romain Guy06882f82009-06-10 13:36:04 -07007441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 void updateLayers() {
7443 final int N = allAppWindows.size();
7444 final int adj = animLayerAdjustment;
7445 for (int i=0; i<N; i++) {
7446 WindowState w = allAppWindows.get(i);
7447 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007448 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 + w.mAnimLayer);
7450 if (w == mInputMethodTarget) {
7451 setInputMethodAnimLayerAdjustment(adj);
7452 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007453 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007454 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007455 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007456 }
7457 }
Romain Guy06882f82009-06-10 13:36:04 -07007458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007459 void sendAppVisibilityToClients() {
7460 final int N = allAppWindows.size();
7461 for (int i=0; i<N; i++) {
7462 WindowState win = allAppWindows.get(i);
7463 if (win == startingWindow && clientHidden) {
7464 // Don't hide the starting window.
7465 continue;
7466 }
7467 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007468 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 "Setting visibility of " + win + ": " + (!clientHidden));
7470 win.mClient.dispatchAppVisibility(!clientHidden);
7471 } catch (RemoteException e) {
7472 }
7473 }
7474 }
Romain Guy06882f82009-06-10 13:36:04 -07007475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007476 void showAllWindowsLocked() {
7477 final int NW = allAppWindows.size();
7478 for (int i=0; i<NW; i++) {
7479 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007480 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007481 "performing show on: " + w);
7482 w.performShowLocked();
7483 }
7484 }
Romain Guy06882f82009-06-10 13:36:04 -07007485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 // This must be called while inside a transaction.
7487 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007488 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007489 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 if (animation == sDummyAnimation) {
7492 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007493 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 // when it is really time to animate, this will be set to
7495 // a real animation and the next call will execute normally.
7496 return false;
7497 }
Romain Guy06882f82009-06-10 13:36:04 -07007498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7500 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007501 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007502 TAG, "Starting animation in " + this +
7503 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7504 + " scale=" + mTransitionAnimationScale
7505 + " allDrawn=" + allDrawn + " animating=" + animating);
7506 animation.initialize(dw, dh, dw, dh);
7507 animation.setStartTime(currentTime);
7508 animating = true;
7509 }
7510 transformation.clear();
7511 final boolean more = animation.getTransformation(
7512 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007513 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007514 TAG, "Stepped animation in " + this +
7515 ": more=" + more + ", xform=" + transformation);
7516 if (more) {
7517 // we're done!
7518 hasTransformation = true;
7519 return true;
7520 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007521 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007522 TAG, "Finished animation in " + this +
7523 " @ " + currentTime);
7524 animation = null;
7525 }
7526 } else if (animation != null) {
7527 // If the display is frozen, and there is a pending animation,
7528 // clear it and make sure we run the cleanup code.
7529 animating = true;
7530 animation = null;
7531 }
7532
7533 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007535 if (!animating) {
7536 return false;
7537 }
7538
7539 clearAnimation();
7540 animating = false;
7541 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7542 moveInputMethodWindowsIfNeededLocked(true);
7543 }
Romain Guy06882f82009-06-10 13:36:04 -07007544
Joe Onorato8a9b2202010-02-26 18:56:32 -08007545 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 TAG, "Animation done in " + this
7547 + ": reportedVisible=" + reportedVisible);
7548
7549 transformation.clear();
7550 if (animLayerAdjustment != 0) {
7551 animLayerAdjustment = 0;
7552 updateLayers();
7553 }
Romain Guy06882f82009-06-10 13:36:04 -07007554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007555 final int N = windows.size();
7556 for (int i=0; i<N; i++) {
7557 ((WindowState)windows.get(i)).finishExit();
7558 }
7559 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007561 return false;
7562 }
7563
7564 void updateReportedVisibilityLocked() {
7565 if (appToken == null) {
7566 return;
7567 }
Romain Guy06882f82009-06-10 13:36:04 -07007568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 int numInteresting = 0;
7570 int numVisible = 0;
7571 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007572
Joe Onorato8a9b2202010-02-26 18:56:32 -08007573 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007574 final int N = allAppWindows.size();
7575 for (int i=0; i<N; i++) {
7576 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007577 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007578 || win.mViewVisibility != View.VISIBLE
7579 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 continue;
7581 }
7582 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007583 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007584 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007586 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007587 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007588 + " pv=" + win.mPolicyVisibility
7589 + " dp=" + win.mDrawPending
7590 + " cdp=" + win.mCommitDrawPending
7591 + " ah=" + win.mAttachedHidden
7592 + " th="
7593 + (win.mAppToken != null
7594 ? win.mAppToken.hiddenRequested : false)
7595 + " a=" + win.mAnimating);
7596 }
7597 }
7598 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007599 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007600 if (!win.isAnimating()) {
7601 numVisible++;
7602 }
7603 nowGone = false;
7604 } else if (win.isAnimating()) {
7605 nowGone = false;
7606 }
7607 }
Romain Guy06882f82009-06-10 13:36:04 -07007608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007609 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007610 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007611 + numInteresting + " visible=" + numVisible);
7612 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007613 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007614 TAG, "Visibility changed in " + this
7615 + ": vis=" + nowVisible);
7616 reportedVisible = nowVisible;
7617 Message m = mH.obtainMessage(
7618 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7619 nowVisible ? 1 : 0,
7620 nowGone ? 1 : 0,
7621 this);
7622 mH.sendMessage(m);
7623 }
7624 }
Romain Guy06882f82009-06-10 13:36:04 -07007625
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007626 WindowState findMainWindow() {
7627 int j = windows.size();
7628 while (j > 0) {
7629 j--;
7630 WindowState win = windows.get(j);
7631 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7632 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7633 return win;
7634 }
7635 }
7636 return null;
7637 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 void dump(PrintWriter pw, String prefix) {
7640 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007641 if (appToken != null) {
7642 pw.print(prefix); pw.println("app=true");
7643 }
7644 if (allAppWindows.size() > 0) {
7645 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7646 }
7647 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007648 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007649 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7650 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7651 pw.print(" clientHidden="); pw.print(clientHidden);
7652 pw.print(" willBeHidden="); pw.print(willBeHidden);
7653 pw.print(" reportedVisible="); pw.println(reportedVisible);
7654 if (paused || freezingScreen) {
7655 pw.print(prefix); pw.print("paused="); pw.print(paused);
7656 pw.print(" freezingScreen="); pw.println(freezingScreen);
7657 }
7658 if (numInterestingWindows != 0 || numDrawnWindows != 0
7659 || inPendingTransaction || allDrawn) {
7660 pw.print(prefix); pw.print("numInterestingWindows=");
7661 pw.print(numInterestingWindows);
7662 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7663 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7664 pw.print(" allDrawn="); pw.println(allDrawn);
7665 }
7666 if (animating || animation != null) {
7667 pw.print(prefix); pw.print("animating="); pw.print(animating);
7668 pw.print(" animation="); pw.println(animation);
7669 }
7670 if (animLayerAdjustment != 0) {
7671 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7672 }
7673 if (hasTransformation) {
7674 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7675 pw.print(" transformation="); transformation.printShortString(pw);
7676 pw.println();
7677 }
7678 if (startingData != null || removed || firstWindowDrawn) {
7679 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7680 pw.print(" removed="); pw.print(removed);
7681 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7682 }
7683 if (startingWindow != null || startingView != null
7684 || startingDisplayed || startingMoved) {
7685 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7686 pw.print(" startingView="); pw.print(startingView);
7687 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7688 pw.print(" startingMoved"); pw.println(startingMoved);
7689 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007690 }
7691
7692 @Override
7693 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007694 if (stringName == null) {
7695 StringBuilder sb = new StringBuilder();
7696 sb.append("AppWindowToken{");
7697 sb.append(Integer.toHexString(System.identityHashCode(this)));
7698 sb.append(" token="); sb.append(token); sb.append('}');
7699 stringName = sb.toString();
7700 }
7701 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007702 }
7703 }
Romain Guy06882f82009-06-10 13:36:04 -07007704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007705 // -------------------------------------------------------------
7706 // DummyAnimation
7707 // -------------------------------------------------------------
7708
7709 // This is an animation that does nothing: it just immediately finishes
7710 // itself every time it is called. It is used as a stub animation in cases
7711 // where we want to synchronize multiple things that may be animating.
7712 static final class DummyAnimation extends Animation {
7713 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7714 return false;
7715 }
7716 }
7717 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007719 // -------------------------------------------------------------
7720 // Async Handler
7721 // -------------------------------------------------------------
7722
7723 static final class StartingData {
7724 final String pkg;
7725 final int theme;
7726 final CharSequence nonLocalizedLabel;
7727 final int labelRes;
7728 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007730 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7731 int _labelRes, int _icon) {
7732 pkg = _pkg;
7733 theme = _theme;
7734 nonLocalizedLabel = _nonLocalizedLabel;
7735 labelRes = _labelRes;
7736 icon = _icon;
7737 }
7738 }
7739
7740 private final class H extends Handler {
7741 public static final int REPORT_FOCUS_CHANGE = 2;
7742 public static final int REPORT_LOSING_FOCUS = 3;
7743 public static final int ANIMATE = 4;
7744 public static final int ADD_STARTING = 5;
7745 public static final int REMOVE_STARTING = 6;
7746 public static final int FINISHED_STARTING = 7;
7747 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7749 public static final int HOLD_SCREEN_CHANGED = 12;
7750 public static final int APP_TRANSITION_TIMEOUT = 13;
7751 public static final int PERSIST_ANIMATION_SCALE = 14;
7752 public static final int FORCE_GC = 15;
7753 public static final int ENABLE_SCREEN = 16;
7754 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007755 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007756 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007758 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007760 public H() {
7761 }
Romain Guy06882f82009-06-10 13:36:04 -07007762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007763 @Override
7764 public void handleMessage(Message msg) {
7765 switch (msg.what) {
7766 case REPORT_FOCUS_CHANGE: {
7767 WindowState lastFocus;
7768 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007770 synchronized(mWindowMap) {
7771 lastFocus = mLastFocus;
7772 newFocus = mCurrentFocus;
7773 if (lastFocus == newFocus) {
7774 // Focus is not changing, so nothing to do.
7775 return;
7776 }
7777 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007778 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007779 // + " to " + newFocus);
7780 if (newFocus != null && lastFocus != null
7781 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007782 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 mLosingFocus.add(lastFocus);
7784 lastFocus = null;
7785 }
7786 }
7787
7788 if (lastFocus != newFocus) {
7789 //System.out.println("Changing focus from " + lastFocus
7790 // + " to " + newFocus);
7791 if (newFocus != null) {
7792 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007793 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007794 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7795 } catch (RemoteException e) {
7796 // Ignore if process has died.
7797 }
7798 }
7799
7800 if (lastFocus != null) {
7801 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007802 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007803 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7804 } catch (RemoteException e) {
7805 // Ignore if process has died.
7806 }
7807 }
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007808 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007809 }
7810 } break;
7811
7812 case REPORT_LOSING_FOCUS: {
7813 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007815 synchronized(mWindowMap) {
7816 losers = mLosingFocus;
7817 mLosingFocus = new ArrayList<WindowState>();
7818 }
7819
7820 final int N = losers.size();
7821 for (int i=0; i<N; i++) {
7822 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007823 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007824 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7825 } catch (RemoteException e) {
7826 // Ignore if process has died.
7827 }
7828 }
7829 } break;
7830
7831 case ANIMATE: {
7832 synchronized(mWindowMap) {
7833 mAnimationPending = false;
7834 performLayoutAndPlaceSurfacesLocked();
7835 }
7836 } break;
7837
7838 case ADD_STARTING: {
7839 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7840 final StartingData sd = wtoken.startingData;
7841
7842 if (sd == null) {
7843 // Animation has been canceled... do nothing.
7844 return;
7845 }
Romain Guy06882f82009-06-10 13:36:04 -07007846
Joe Onorato8a9b2202010-02-26 18:56:32 -08007847 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007848 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850 View view = null;
7851 try {
7852 view = mPolicy.addStartingWindow(
7853 wtoken.token, sd.pkg,
7854 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7855 sd.icon);
7856 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007857 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007858 }
7859
7860 if (view != null) {
7861 boolean abort = false;
7862
7863 synchronized(mWindowMap) {
7864 if (wtoken.removed || wtoken.startingData == null) {
7865 // If the window was successfully added, then
7866 // we need to remove it.
7867 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007868 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007869 "Aborted starting " + wtoken
7870 + ": removed=" + wtoken.removed
7871 + " startingData=" + wtoken.startingData);
7872 wtoken.startingWindow = null;
7873 wtoken.startingData = null;
7874 abort = true;
7875 }
7876 } else {
7877 wtoken.startingView = view;
7878 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007879 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 "Added starting " + wtoken
7881 + ": startingWindow="
7882 + wtoken.startingWindow + " startingView="
7883 + wtoken.startingView);
7884 }
7885
7886 if (abort) {
7887 try {
7888 mPolicy.removeStartingWindow(wtoken.token, view);
7889 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007890 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007891 }
7892 }
7893 }
7894 } break;
7895
7896 case REMOVE_STARTING: {
7897 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7898 IBinder token = null;
7899 View view = null;
7900 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007901 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007902 + wtoken + ": startingWindow="
7903 + wtoken.startingWindow + " startingView="
7904 + wtoken.startingView);
7905 if (wtoken.startingWindow != null) {
7906 view = wtoken.startingView;
7907 token = wtoken.token;
7908 wtoken.startingData = null;
7909 wtoken.startingView = null;
7910 wtoken.startingWindow = null;
7911 }
7912 }
7913 if (view != null) {
7914 try {
7915 mPolicy.removeStartingWindow(token, view);
7916 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007917 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007918 }
7919 }
7920 } break;
7921
7922 case FINISHED_STARTING: {
7923 IBinder token = null;
7924 View view = null;
7925 while (true) {
7926 synchronized (mWindowMap) {
7927 final int N = mFinishedStarting.size();
7928 if (N <= 0) {
7929 break;
7930 }
7931 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7932
Joe Onorato8a9b2202010-02-26 18:56:32 -08007933 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007934 "Finished starting " + wtoken
7935 + ": startingWindow=" + wtoken.startingWindow
7936 + " startingView=" + wtoken.startingView);
7937
7938 if (wtoken.startingWindow == null) {
7939 continue;
7940 }
7941
7942 view = wtoken.startingView;
7943 token = wtoken.token;
7944 wtoken.startingData = null;
7945 wtoken.startingView = null;
7946 wtoken.startingWindow = null;
7947 }
7948
7949 try {
7950 mPolicy.removeStartingWindow(token, view);
7951 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007952 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 }
7954 }
7955 } break;
7956
7957 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7958 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7959
7960 boolean nowVisible = msg.arg1 != 0;
7961 boolean nowGone = msg.arg2 != 0;
7962
7963 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007964 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007965 TAG, "Reporting visible in " + wtoken
7966 + " visible=" + nowVisible
7967 + " gone=" + nowGone);
7968 if (nowVisible) {
7969 wtoken.appToken.windowsVisible();
7970 } else {
7971 wtoken.appToken.windowsGone();
7972 }
7973 } catch (RemoteException ex) {
7974 }
7975 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 case WINDOW_FREEZE_TIMEOUT: {
7978 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007979 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 int i = mWindows.size();
7981 while (i > 0) {
7982 i--;
7983 WindowState w = (WindowState)mWindows.get(i);
7984 if (w.mOrientationChanging) {
7985 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007986 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007987 }
7988 }
7989 performLayoutAndPlaceSurfacesLocked();
7990 }
7991 break;
7992 }
Romain Guy06882f82009-06-10 13:36:04 -07007993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007994 case HOLD_SCREEN_CHANGED: {
7995 Session oldHold;
7996 Session newHold;
7997 synchronized (mWindowMap) {
7998 oldHold = mLastReportedHold;
7999 newHold = (Session)msg.obj;
8000 mLastReportedHold = newHold;
8001 }
Romain Guy06882f82009-06-10 13:36:04 -07008002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 if (oldHold != newHold) {
8004 try {
8005 if (oldHold != null) {
8006 mBatteryStats.noteStopWakelock(oldHold.mUid,
8007 "window",
8008 BatteryStats.WAKE_TYPE_WINDOW);
8009 }
8010 if (newHold != null) {
8011 mBatteryStats.noteStartWakelock(newHold.mUid,
8012 "window",
8013 BatteryStats.WAKE_TYPE_WINDOW);
8014 }
8015 } catch (RemoteException e) {
8016 }
8017 }
8018 break;
8019 }
Romain Guy06882f82009-06-10 13:36:04 -07008020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 case APP_TRANSITION_TIMEOUT: {
8022 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008023 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008024 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008025 "*** APP TRANSITION TIMEOUT");
8026 mAppTransitionReady = true;
8027 mAppTransitionTimeout = true;
8028 performLayoutAndPlaceSurfacesLocked();
8029 }
8030 }
8031 break;
8032 }
Romain Guy06882f82009-06-10 13:36:04 -07008033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008034 case PERSIST_ANIMATION_SCALE: {
8035 Settings.System.putFloat(mContext.getContentResolver(),
8036 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8037 Settings.System.putFloat(mContext.getContentResolver(),
8038 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8039 break;
8040 }
Romain Guy06882f82009-06-10 13:36:04 -07008041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008042 case FORCE_GC: {
8043 synchronized(mWindowMap) {
8044 if (mAnimationPending) {
8045 // If we are animating, don't do the gc now but
8046 // delay a bit so we don't interrupt the animation.
8047 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8048 2000);
8049 return;
8050 }
8051 // If we are currently rotating the display, it will
8052 // schedule a new message when done.
8053 if (mDisplayFrozen) {
8054 return;
8055 }
8056 mFreezeGcPending = 0;
8057 }
8058 Runtime.getRuntime().gc();
8059 break;
8060 }
Romain Guy06882f82009-06-10 13:36:04 -07008061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 case ENABLE_SCREEN: {
8063 performEnableScreen();
8064 break;
8065 }
Romain Guy06882f82009-06-10 13:36:04 -07008066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008067 case APP_FREEZE_TIMEOUT: {
8068 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008069 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008070 int i = mAppTokens.size();
8071 while (i > 0) {
8072 i--;
8073 AppWindowToken tok = mAppTokens.get(i);
8074 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008075 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 unsetAppFreezingScreenLocked(tok, true, true);
8077 }
8078 }
8079 }
8080 break;
8081 }
Romain Guy06882f82009-06-10 13:36:04 -07008082
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008083 case SEND_NEW_CONFIGURATION: {
8084 removeMessages(SEND_NEW_CONFIGURATION);
8085 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008086 break;
8087 }
Romain Guy06882f82009-06-10 13:36:04 -07008088
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008089 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008090 if (mWindowsChanged) {
8091 synchronized (mWindowMap) {
8092 mWindowsChanged = false;
8093 }
8094 notifyWindowsChanged();
8095 }
8096 break;
8097 }
8098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 }
8100 }
8101 }
8102
8103 // -------------------------------------------------------------
8104 // IWindowManager API
8105 // -------------------------------------------------------------
8106
8107 public IWindowSession openSession(IInputMethodClient client,
8108 IInputContext inputContext) {
8109 if (client == null) throw new IllegalArgumentException("null client");
8110 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008111 Session session = new Session(client, inputContext);
8112 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008113 }
8114
8115 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8116 synchronized (mWindowMap) {
8117 // The focus for the client is the window immediately below
8118 // where we would place the input method window.
8119 int idx = findDesiredInputMethodWindowIndexLocked(false);
8120 WindowState imFocus;
8121 if (idx > 0) {
8122 imFocus = (WindowState)mWindows.get(idx-1);
8123 if (imFocus != null) {
8124 if (imFocus.mSession.mClient != null &&
8125 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8126 return true;
8127 }
8128 }
8129 }
8130 }
8131 return false;
8132 }
Romain Guy06882f82009-06-10 13:36:04 -07008133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008134 // -------------------------------------------------------------
8135 // Internals
8136 // -------------------------------------------------------------
8137
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008138 final WindowState windowForClientLocked(Session session, IWindow client,
8139 boolean throwOnError) {
8140 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008141 }
Romain Guy06882f82009-06-10 13:36:04 -07008142
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008143 final WindowState windowForClientLocked(Session session, IBinder client,
8144 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008146 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008147 TAG, "Looking up client " + client + ": " + win);
8148 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008149 RuntimeException ex = new IllegalArgumentException(
8150 "Requested window " + client + " does not exist");
8151 if (throwOnError) {
8152 throw ex;
8153 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008154 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008155 return null;
8156 }
8157 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008158 RuntimeException ex = new IllegalArgumentException(
8159 "Requested window " + client + " is in session " +
8160 win.mSession + ", not " + session);
8161 if (throwOnError) {
8162 throw ex;
8163 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008164 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008165 return null;
8166 }
8167
8168 return win;
8169 }
8170
Dianne Hackborna8f60182009-09-01 19:01:50 -07008171 final void rebuildAppWindowListLocked() {
8172 int NW = mWindows.size();
8173 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008174 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008175 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008176
Dianne Hackborna8f60182009-09-01 19:01:50 -07008177 // First remove all existing app windows.
8178 i=0;
8179 while (i < NW) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008180 WindowState w = (WindowState)mWindows.get(i);
8181 if (w.mAppToken != null) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008182 WindowState win = (WindowState)mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008183 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008184 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008185 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008186 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008187 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008188 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008189 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8190 && lastWallpaper == i-1) {
8191 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008192 }
8193 i++;
8194 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008195
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008196 // The wallpaper window(s) typically live at the bottom of the stack,
8197 // so skip them before adding app tokens.
8198 lastWallpaper++;
8199 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008200
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008201 // First add all of the exiting app tokens... these are no longer
8202 // in the main app list, but still have windows shown. We put them
8203 // in the back because now that the animation is over we no longer
8204 // will care about them.
8205 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008206 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008207 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8208 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008209
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008210 // And add in the still active app tokens in Z order.
8211 NT = mAppTokens.size();
8212 for (int j=0; j<NT; j++) {
8213 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008214 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008215
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008216 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008217 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008218 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008219 + " windows but added " + i);
8220 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008221 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008223 private final void assignLayersLocked() {
8224 int N = mWindows.size();
8225 int curBaseLayer = 0;
8226 int curLayer = 0;
8227 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008229 for (i=0; i<N; i++) {
8230 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008231 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8232 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008233 curLayer += WINDOW_LAYER_MULTIPLIER;
8234 w.mLayer = curLayer;
8235 } else {
8236 curBaseLayer = curLayer = w.mBaseLayer;
8237 w.mLayer = curLayer;
8238 }
8239 if (w.mTargetAppToken != null) {
8240 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8241 } else if (w.mAppToken != null) {
8242 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8243 } else {
8244 w.mAnimLayer = w.mLayer;
8245 }
8246 if (w.mIsImWindow) {
8247 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008248 } else if (w.mIsWallpaper) {
8249 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008251 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008252 + w.mAnimLayer);
8253 //System.out.println(
8254 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8255 }
8256 }
8257
8258 private boolean mInLayout = false;
8259 private final void performLayoutAndPlaceSurfacesLocked() {
8260 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008261 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008262 throw new RuntimeException("Recursive call!");
8263 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008264 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008265 return;
8266 }
8267
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008268 if (mWaitingForConfig) {
8269 // Our configuration has changed (most likely rotation), but we
8270 // don't yet have the complete configuration to report to
8271 // applications. Don't do any window layout until we have it.
8272 return;
8273 }
8274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008275 boolean recoveringMemory = false;
8276 if (mForceRemoves != null) {
8277 recoveringMemory = true;
8278 // Wait a little it for things to settle down, and off we go.
8279 for (int i=0; i<mForceRemoves.size(); i++) {
8280 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008281 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008282 removeWindowInnerLocked(ws.mSession, ws);
8283 }
8284 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008285 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008286 Object tmp = new Object();
8287 synchronized (tmp) {
8288 try {
8289 tmp.wait(250);
8290 } catch (InterruptedException e) {
8291 }
8292 }
8293 }
Romain Guy06882f82009-06-10 13:36:04 -07008294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008295 mInLayout = true;
8296 try {
8297 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008299 int i = mPendingRemove.size()-1;
8300 if (i >= 0) {
8301 while (i >= 0) {
8302 WindowState w = mPendingRemove.get(i);
8303 removeWindowInnerLocked(w.mSession, w);
8304 i--;
8305 }
8306 mPendingRemove.clear();
8307
8308 mInLayout = false;
8309 assignLayersLocked();
8310 mLayoutNeeded = true;
8311 performLayoutAndPlaceSurfacesLocked();
8312
8313 } else {
8314 mInLayout = false;
8315 if (mLayoutNeeded) {
8316 requestAnimationLocked(0);
8317 }
8318 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008319 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008320 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8321 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008322 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008323 } catch (RuntimeException e) {
8324 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008325 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008326 }
8327 }
8328
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008329 private final int performLayoutLockedInner() {
8330 if (!mLayoutNeeded) {
8331 return 0;
8332 }
8333
8334 mLayoutNeeded = false;
8335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008336 final int dw = mDisplay.getWidth();
8337 final int dh = mDisplay.getHeight();
8338
8339 final int N = mWindows.size();
8340 int i;
8341
Joe Onorato8a9b2202010-02-26 18:56:32 -08008342 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008343 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8344
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008345 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008346
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008347 int seq = mLayoutSeq+1;
8348 if (seq < 0) seq = 0;
8349 mLayoutSeq = seq;
8350
8351 // First perform layout of any root windows (not attached
8352 // to another window).
8353 int topAttached = -1;
8354 for (i = N-1; i >= 0; i--) {
8355 WindowState win = (WindowState) mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008357 // Don't do layout of a window if it is not visible, or
8358 // soon won't be visible, to avoid wasting time and funky
8359 // changes while a window is animating away.
8360 final AppWindowToken atoken = win.mAppToken;
8361 final boolean gone = win.mViewVisibility == View.GONE
8362 || !win.mRelayoutCalled
8363 || win.mRootToken.hidden
8364 || (atoken != null && atoken.hiddenRequested)
8365 || win.mAttachedHidden
8366 || win.mExiting || win.mDestroying;
8367
8368 if (!win.mLayoutAttached) {
8369 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8370 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8371 + " mLayoutAttached=" + win.mLayoutAttached);
8372 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8373 + win.mViewVisibility + " mRelayoutCalled="
8374 + win.mRelayoutCalled + " hidden="
8375 + win.mRootToken.hidden + " hiddenRequested="
8376 + (atoken != null && atoken.hiddenRequested)
8377 + " mAttachedHidden=" + win.mAttachedHidden);
8378 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008379
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008380 // If this view is GONE, then skip it -- keep the current
8381 // frame, and let the caller know so they can ignore it
8382 // if they want. (We do the normal layout for INVISIBLE
8383 // windows, since that means "perform layout as normal,
8384 // just don't display").
8385 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008386 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008387 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8388 win.mLayoutSeq = seq;
8389 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8390 + win.mFrame + " mContainingFrame="
8391 + win.mContainingFrame + " mDisplayFrame="
8392 + win.mDisplayFrame);
8393 } else {
8394 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008395 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008398
8399 // Now perform layout of attached windows, which usually
8400 // depend on the position of the window they are attached to.
8401 // XXX does not deal with windows that are attached to windows
8402 // that are themselves attached.
8403 for (i = topAttached; i >= 0; i--) {
8404 WindowState win = (WindowState) mWindows.get(i);
8405
8406 // If this view is GONE, then skip it -- keep the current
8407 // frame, and let the caller know so they can ignore it
8408 // if they want. (We do the normal layout for INVISIBLE
8409 // windows, since that means "perform layout as normal,
8410 // just don't display").
8411 if (win.mLayoutAttached) {
8412 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8413 + " mHaveFrame=" + win.mHaveFrame
8414 + " mViewVisibility=" + win.mViewVisibility
8415 + " mRelayoutCalled=" + win.mRelayoutCalled);
8416 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8417 || !win.mHaveFrame) {
8418 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8419 win.mLayoutSeq = seq;
8420 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8421 + win.mFrame + " mContainingFrame="
8422 + win.mContainingFrame + " mDisplayFrame="
8423 + win.mDisplayFrame);
8424 }
8425 }
8426 }
Jeff Brown349703e2010-06-22 01:27:15 -07008427
8428 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008429 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008430
8431 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008432 }
Romain Guy06882f82009-06-10 13:36:04 -07008433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008434 private final void performLayoutAndPlaceSurfacesLockedInner(
8435 boolean recoveringMemory) {
8436 final long currentTime = SystemClock.uptimeMillis();
8437 final int dw = mDisplay.getWidth();
8438 final int dh = mDisplay.getHeight();
8439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 int i;
8441
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008442 if (mFocusMayChange) {
8443 mFocusMayChange = false;
8444 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8445 }
8446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008447 if (mFxSession == null) {
8448 mFxSession = new SurfaceSession();
8449 }
Romain Guy06882f82009-06-10 13:36:04 -07008450
Joe Onorato8a9b2202010-02-26 18:56:32 -08008451 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452
8453 // Initialize state of exiting tokens.
8454 for (i=mExitingTokens.size()-1; i>=0; i--) {
8455 mExitingTokens.get(i).hasVisible = false;
8456 }
8457
8458 // Initialize state of exiting applications.
8459 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8460 mExitingAppTokens.get(i).hasVisible = false;
8461 }
8462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008463 boolean orientationChangeComplete = true;
8464 Session holdScreen = null;
8465 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008466 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 boolean focusDisplayed = false;
8468 boolean animating = false;
8469
8470 Surface.openTransaction();
8471 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008472 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008473 int repeats = 0;
8474 int changes = 0;
8475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008476 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008477 repeats++;
8478 if (repeats > 6) {
8479 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8480 mLayoutNeeded = false;
8481 break;
8482 }
8483
8484 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8485 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8486 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8487 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8488 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8489 assignLayersLocked();
8490 mLayoutNeeded = true;
8491 }
8492 }
8493 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8494 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8495 if (updateOrientationFromAppTokensLocked()) {
8496 mLayoutNeeded = true;
8497 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8498 }
8499 }
8500 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8501 mLayoutNeeded = true;
8502 }
8503 }
8504
8505 // FIRST LOOP: Perform a layout, if needed.
8506 if (repeats < 4) {
8507 changes = performLayoutLockedInner();
8508 if (changes != 0) {
8509 continue;
8510 }
8511 } else {
8512 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8513 changes = 0;
8514 }
8515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 final int transactionSequence = ++mTransactionSequence;
8517
8518 // Update animations of all applications, including those
8519 // associated with exiting/removed apps
8520 boolean tokensAnimating = false;
8521 final int NAT = mAppTokens.size();
8522 for (i=0; i<NAT; i++) {
8523 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8524 tokensAnimating = true;
8525 }
8526 }
8527 final int NEAT = mExitingAppTokens.size();
8528 for (i=0; i<NEAT; i++) {
8529 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8530 tokensAnimating = true;
8531 }
8532 }
8533
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008534 // SECOND LOOP: Execute animations and update visibility of windows.
8535
Joe Onorato8a9b2202010-02-26 18:56:32 -08008536 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008537 + transactionSequence + " tokensAnimating="
8538 + tokensAnimating);
8539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008540 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008541
8542 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008543 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008544 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545
8546 mPolicy.beginAnimationLw(dw, dh);
8547
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008548 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008550 for (i=N-1; i>=0; i--) {
8551 WindowState w = (WindowState)mWindows.get(i);
8552
8553 final WindowManager.LayoutParams attrs = w.mAttrs;
8554
8555 if (w.mSurface != null) {
8556 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008557 if (w.commitFinishDrawingLocked(currentTime)) {
8558 if ((w.mAttrs.flags
8559 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008560 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008561 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008562 wallpaperMayChange = true;
8563 }
8564 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008565
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008566 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008567 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8568 animating = true;
8569 //w.dump(" ");
8570 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008571 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8572 wallpaperMayChange = true;
8573 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008574
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008575 if (mPolicy.doesForceHide(w, attrs)) {
8576 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008577 if (DEBUG_VISIBILITY) Slog.v(TAG,
8578 "Animation done that could impact force hide: "
8579 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008580 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008581 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008582 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8583 forceHiding = true;
8584 }
8585 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8586 boolean changed;
8587 if (forceHiding) {
8588 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008589 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8590 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008591 } else {
8592 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008593 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8594 "Now policy shown: " + w);
8595 if (changed) {
8596 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008597 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008598 // Assume we will need to animate. If
8599 // we don't (because the wallpaper will
8600 // stay with the lock screen), then we will
8601 // clean up later.
8602 Animation a = mPolicy.createForceHideEnterAnimation();
8603 if (a != null) {
8604 w.setAnimation(a);
8605 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008606 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008607 if (mCurrentFocus == null ||
8608 mCurrentFocus.mLayer < w.mLayer) {
8609 // We are showing on to of the current
8610 // focus, so re-evaluate focus to make
8611 // sure it is correct.
8612 mFocusMayChange = true;
8613 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008614 }
8615 }
8616 if (changed && (attrs.flags
8617 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8618 wallpaperMayChange = true;
8619 }
8620 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008622 mPolicy.animatingWindowLw(w, attrs);
8623 }
8624
8625 final AppWindowToken atoken = w.mAppToken;
8626 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8627 if (atoken.lastTransactionSequence != transactionSequence) {
8628 atoken.lastTransactionSequence = transactionSequence;
8629 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8630 atoken.startingDisplayed = false;
8631 }
8632 if ((w.isOnScreen() || w.mAttrs.type
8633 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8634 && !w.mExiting && !w.mDestroying) {
8635 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008636 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008637 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008639 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008640 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008641 + " pv=" + w.mPolicyVisibility
8642 + " dp=" + w.mDrawPending
8643 + " cdp=" + w.mCommitDrawPending
8644 + " ah=" + w.mAttachedHidden
8645 + " th=" + atoken.hiddenRequested
8646 + " a=" + w.mAnimating);
8647 }
8648 }
8649 if (w != atoken.startingWindow) {
8650 if (!atoken.freezingScreen || !w.mAppFreezing) {
8651 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008652 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008653 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008654 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 "tokenMayBeDrawn: " + atoken
8656 + " freezingScreen=" + atoken.freezingScreen
8657 + " mAppFreezing=" + w.mAppFreezing);
8658 tokenMayBeDrawn = true;
8659 }
8660 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008661 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008662 atoken.startingDisplayed = true;
8663 }
8664 }
8665 } else if (w.mReadyToShow) {
8666 w.performShowLocked();
8667 }
8668 }
8669
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008670 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671
8672 if (tokenMayBeDrawn) {
8673 // See if any windows have been drawn, so they (and others
8674 // associated with them) can now be shown.
8675 final int NT = mTokenList.size();
8676 for (i=0; i<NT; i++) {
8677 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8678 if (wtoken == null) {
8679 continue;
8680 }
8681 if (wtoken.freezingScreen) {
8682 int numInteresting = wtoken.numInterestingWindows;
8683 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008684 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008685 "allDrawn: " + wtoken
8686 + " interesting=" + numInteresting
8687 + " drawn=" + wtoken.numDrawnWindows);
8688 wtoken.showAllWindowsLocked();
8689 unsetAppFreezingScreenLocked(wtoken, false, true);
8690 orientationChangeComplete = true;
8691 }
8692 } else if (!wtoken.allDrawn) {
8693 int numInteresting = wtoken.numInterestingWindows;
8694 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008695 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008696 "allDrawn: " + wtoken
8697 + " interesting=" + numInteresting
8698 + " drawn=" + wtoken.numDrawnWindows);
8699 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008700 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008701
8702 // We can now show all of the drawn windows!
8703 if (!mOpeningApps.contains(wtoken)) {
8704 wtoken.showAllWindowsLocked();
8705 }
8706 }
8707 }
8708 }
8709 }
8710
8711 // If we are ready to perform an app transition, check through
8712 // all of the app tokens to be shown and see if they are ready
8713 // to go.
8714 if (mAppTransitionReady) {
8715 int NN = mOpeningApps.size();
8716 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008717 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008718 "Checking " + NN + " opening apps (frozen="
8719 + mDisplayFrozen + " timeout="
8720 + mAppTransitionTimeout + ")...");
8721 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8722 // If the display isn't frozen, wait to do anything until
8723 // all of the apps are ready. Otherwise just go because
8724 // we'll unfreeze the display when everyone is ready.
8725 for (i=0; i<NN && goodToGo; i++) {
8726 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008727 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 "Check opening app" + wtoken + ": allDrawn="
8729 + wtoken.allDrawn + " startingDisplayed="
8730 + wtoken.startingDisplayed);
8731 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8732 && !wtoken.startingMoved) {
8733 goodToGo = false;
8734 }
8735 }
8736 }
8737 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008738 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008739 int transit = mNextAppTransition;
8740 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008741 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008742 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008743 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008744 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008745 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 mAppTransitionTimeout = false;
8747 mStartingIconInTransition = false;
8748 mSkipAppTransitionAnimation = false;
8749
8750 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8751
Dianne Hackborna8f60182009-09-01 19:01:50 -07008752 // If there are applications waiting to come to the
8753 // top of the stack, now is the time to move their windows.
8754 // (Note that we don't do apps going to the bottom
8755 // here -- we want to keep their windows in the old
8756 // Z-order until the animation completes.)
8757 if (mToTopApps.size() > 0) {
8758 NN = mAppTokens.size();
8759 for (i=0; i<NN; i++) {
8760 AppWindowToken wtoken = mAppTokens.get(i);
8761 if (wtoken.sendingToTop) {
8762 wtoken.sendingToTop = false;
8763 moveAppWindowsLocked(wtoken, NN, false);
8764 }
8765 }
8766 mToTopApps.clear();
8767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008768
Dianne Hackborn25994b42009-09-04 14:21:19 -07008769 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008770
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008771 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008772 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008773
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008774 // The top-most window will supply the layout params,
8775 // and we will determine it below.
8776 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008777 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008778 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008779
Joe Onorato8a9b2202010-02-26 18:56:32 -08008780 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008781 "New wallpaper target=" + mWallpaperTarget
8782 + ", lower target=" + mLowerWallpaperTarget
8783 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008784 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008785 // Do a first pass through the tokens for two
8786 // things:
8787 // (1) Determine if both the closing and opening
8788 // app token sets are wallpaper targets, in which
8789 // case special animations are needed
8790 // (since the wallpaper needs to stay static
8791 // behind them).
8792 // (2) Find the layout params of the top-most
8793 // application window in the tokens, which is
8794 // what will control the animation theme.
8795 final int NC = mClosingApps.size();
8796 NN = NC + mOpeningApps.size();
8797 for (i=0; i<NN; i++) {
8798 AppWindowToken wtoken;
8799 int mode;
8800 if (i < NC) {
8801 wtoken = mClosingApps.get(i);
8802 mode = 1;
8803 } else {
8804 wtoken = mOpeningApps.get(i-NC);
8805 mode = 2;
8806 }
8807 if (mLowerWallpaperTarget != null) {
8808 if (mLowerWallpaperTarget.mAppToken == wtoken
8809 || mUpperWallpaperTarget.mAppToken == wtoken) {
8810 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008811 }
8812 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008813 if (wtoken.appFullscreen) {
8814 WindowState ws = wtoken.findMainWindow();
8815 if (ws != null) {
8816 // If this is a compatibility mode
8817 // window, we will always use its anim.
8818 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8819 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008820 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008821 bestAnimLayer = Integer.MAX_VALUE;
8822 } else if (ws.mLayer > bestAnimLayer) {
8823 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008824 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008825 bestAnimLayer = ws.mLayer;
8826 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008827 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008828 }
8829 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008830
Dianne Hackborn25994b42009-09-04 14:21:19 -07008831 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008832 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008833 "Wallpaper animation!");
8834 switch (transit) {
8835 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8836 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8837 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8838 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8839 break;
8840 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8841 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8842 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8843 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8844 break;
8845 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008846 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008847 "New transit: " + transit);
8848 } else if (oldWallpaper != null) {
8849 // We are transitioning from an activity with
8850 // a wallpaper to one without.
8851 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008852 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008853 "New transit away from wallpaper: " + transit);
8854 } else if (mWallpaperTarget != null) {
8855 // We are transitioning from an activity without
8856 // a wallpaper to now showing the wallpaper
8857 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008858 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008859 "New transit into wallpaper: " + transit);
8860 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008861
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008862 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8863 mLastEnterAnimToken = animToken;
8864 mLastEnterAnimParams = animLp;
8865 } else if (mLastEnterAnimParams != null) {
8866 animLp = mLastEnterAnimParams;
8867 mLastEnterAnimToken = null;
8868 mLastEnterAnimParams = null;
8869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008870
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008871 // If all closing windows are obscured, then there is
8872 // no need to do an animation. This is the case, for
8873 // example, when this transition is being done behind
8874 // the lock screen.
8875 if (!mPolicy.allowAppAnimationsLw()) {
8876 animLp = null;
8877 }
8878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008879 NN = mOpeningApps.size();
8880 for (i=0; i<NN; i++) {
8881 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008882 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008883 "Now opening app" + wtoken);
8884 wtoken.reportedVisible = false;
8885 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008886 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008887 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008888 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008889 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008890 wtoken.showAllWindowsLocked();
8891 }
8892 NN = mClosingApps.size();
8893 for (i=0; i<NN; i++) {
8894 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008895 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008896 "Now closing app" + wtoken);
8897 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008898 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008899 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008900 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008901 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008902 // Force the allDrawn flag, because we want to start
8903 // this guy's animations regardless of whether it's
8904 // gotten drawn.
8905 wtoken.allDrawn = true;
8906 }
8907
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008908 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008910 mOpeningApps.clear();
8911 mClosingApps.clear();
8912
8913 // This has changed the visibility of windows, so perform
8914 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008915 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008916 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008917 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8918 assignLayersLocked();
8919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008920 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008921 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008922 }
8923 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008924
Dianne Hackborn16064f92010-03-25 00:47:24 -07008925 int adjResult = 0;
8926
Dianne Hackborna8f60182009-09-01 19:01:50 -07008927 if (!animating && mAppTransitionRunning) {
8928 // We have finished the animation of an app transition. To do
8929 // this, we have delayed a lot of operations like showing and
8930 // hiding apps, moving apps in Z-order, etc. The app token list
8931 // reflects the correct Z-order, but the window list may now
8932 // be out of sync with it. So here we will just rebuild the
8933 // entire app window list. Fun!
8934 mAppTransitionRunning = false;
8935 // Clear information about apps that were moving.
8936 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008937
Dianne Hackborna8f60182009-09-01 19:01:50 -07008938 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008939 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008940 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008941 moveInputMethodWindowsIfNeededLocked(false);
8942 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008943 // Since the window list has been rebuilt, focus might
8944 // have to be recomputed since the actual order of windows
8945 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008946 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008948
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008949 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008950 // At this point, there was a window with a wallpaper that
8951 // was force hiding other windows behind it, but now it
8952 // is going away. This may be simple -- just animate
8953 // away the wallpaper and its window -- or it may be
8954 // hard -- the wallpaper now needs to be shown behind
8955 // something that was hidden.
8956 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008957 if (mLowerWallpaperTarget != null
8958 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008959 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008960 "wallpaperForceHiding changed with lower="
8961 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008962 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008963 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8964 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8965 if (mLowerWallpaperTarget.mAppToken.hidden) {
8966 // The lower target has become hidden before we
8967 // actually started the animation... let's completely
8968 // re-evaluate everything.
8969 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008970 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008971 }
8972 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07008973 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008974 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008975 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008976 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008977 + " NEW: " + mWallpaperTarget
8978 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008979 if (mLowerWallpaperTarget == null) {
8980 // Whoops, we don't need a special wallpaper animation.
8981 // Clear them out.
8982 forceHiding = false;
8983 for (i=N-1; i>=0; i--) {
8984 WindowState w = (WindowState)mWindows.get(i);
8985 if (w.mSurface != null) {
8986 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07008987 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008988 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008989 forceHiding = true;
8990 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8991 if (!w.mAnimating) {
8992 // We set the animation above so it
8993 // is not yet running.
8994 w.clearAnimation();
8995 }
8996 }
8997 }
8998 }
8999 }
9000 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009001
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009002 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009003 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009004 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009005 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009006 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009007
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009008 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009009 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009010 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009011 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009012 assignLayersLocked();
9013 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009014 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009015 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009016 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009017 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009018
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009019 if (mFocusMayChange) {
9020 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009021 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009022 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009023 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009024 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009025 }
9026
9027 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009028 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009029 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009030
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009031 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9032 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009033
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009034 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035
9036 // THIRD LOOP: Update the surfaces of all windows.
9037
9038 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9039
9040 boolean obscured = false;
9041 boolean blurring = false;
9042 boolean dimming = false;
9043 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009044 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009045 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009046
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009047 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009049 for (i=N-1; i>=0; i--) {
9050 WindowState w = (WindowState)mWindows.get(i);
9051
9052 boolean displayed = false;
9053 final WindowManager.LayoutParams attrs = w.mAttrs;
9054 final int attrFlags = attrs.flags;
9055
9056 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009057 // XXX NOTE: The logic here could be improved. We have
9058 // the decision about whether to resize a window separated
9059 // from whether to hide the surface. This can cause us to
9060 // resize a surface even if we are going to hide it. You
9061 // can see this by (1) holding device in landscape mode on
9062 // home screen; (2) tapping browser icon (device will rotate
9063 // to landscape; (3) tap home. The wallpaper will be resized
9064 // in step 2 but then immediately hidden, causing us to
9065 // have to resize and then redraw it again in step 3. It
9066 // would be nice to figure out how to avoid this, but it is
9067 // difficult because we do need to resize surfaces in some
9068 // cases while they are hidden such as when first showing a
9069 // window.
9070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009071 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009072 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009073 TAG, "Placing surface #" + i + " " + w.mSurface
9074 + ": new=" + w.mShownFrame + ", old="
9075 + w.mLastShownFrame);
9076
9077 boolean resize;
9078 int width, height;
9079 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9080 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9081 w.mLastRequestedHeight != w.mRequestedHeight;
9082 // for a scaled surface, we just want to use
9083 // the requested size.
9084 width = w.mRequestedWidth;
9085 height = w.mRequestedHeight;
9086 w.mLastRequestedWidth = width;
9087 w.mLastRequestedHeight = height;
9088 w.mLastShownFrame.set(w.mShownFrame);
9089 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009090 if (SHOW_TRANSACTIONS) logSurface(w,
9091 "POS " + w.mShownFrame.left
9092 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009093 w.mSurfaceX = w.mShownFrame.left;
9094 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009095 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9096 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009097 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009098 if (!recoveringMemory) {
9099 reclaimSomeSurfaceMemoryLocked(w, "position");
9100 }
9101 }
9102 } else {
9103 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9104 width = w.mShownFrame.width();
9105 height = w.mShownFrame.height();
9106 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009107 }
9108
9109 if (resize) {
9110 if (width < 1) width = 1;
9111 if (height < 1) height = 1;
9112 if (w.mSurface != null) {
9113 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009114 if (SHOW_TRANSACTIONS) logSurface(w,
9115 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009116 + w.mShownFrame.top + " SIZE "
9117 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009118 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009119 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009120 w.mSurfaceW = width;
9121 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009122 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009123 w.mSurfaceX = w.mShownFrame.left;
9124 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009125 w.mSurface.setPosition(w.mShownFrame.left,
9126 w.mShownFrame.top);
9127 } catch (RuntimeException e) {
9128 // If something goes wrong with the surface (such
9129 // as running out of memory), don't take down the
9130 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009131 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009132 + "size=(" + width + "x" + height
9133 + "), pos=(" + w.mShownFrame.left
9134 + "," + w.mShownFrame.top + ")", e);
9135 if (!recoveringMemory) {
9136 reclaimSomeSurfaceMemoryLocked(w, "size");
9137 }
9138 }
9139 }
9140 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009141 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009142 w.mContentInsetsChanged =
9143 !w.mLastContentInsets.equals(w.mContentInsets);
9144 w.mVisibleInsetsChanged =
9145 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009146 boolean configChanged =
9147 w.mConfiguration != mCurConfiguration
9148 && (w.mConfiguration == null
9149 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009150 if (DEBUG_CONFIGURATION && configChanged) {
9151 Slog.v(TAG, "Win " + w + " config changed: "
9152 + mCurConfiguration);
9153 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009154 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009155 + ": configChanged=" + configChanged
9156 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009157 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009158 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009159 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009160 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009161 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 w.mLastFrame.set(w.mFrame);
9163 w.mLastContentInsets.set(w.mContentInsets);
9164 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009165 // If the screen is currently frozen, then keep
9166 // it frozen until this window draws at its new
9167 // orientation.
9168 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009169 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009170 "Resizing while display frozen: " + w);
9171 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009172 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009173 mWindowsFreezingScreen = true;
9174 // XXX should probably keep timeout from
9175 // when we first froze the display.
9176 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9177 mH.sendMessageDelayed(mH.obtainMessage(
9178 H.WINDOW_FREEZE_TIMEOUT), 2000);
9179 }
9180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 // If the orientation is changing, then we need to
9182 // hold off on unfreezing the display until this
9183 // window has been redrawn; to do that, we need
9184 // to go through the process of getting informed
9185 // by the application when it has finished drawing.
9186 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009187 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009188 "Orientation start waiting for draw in "
9189 + w + ", surface " + w.mSurface);
9190 w.mDrawPending = true;
9191 w.mCommitDrawPending = false;
9192 w.mReadyToShow = false;
9193 if (w.mAppToken != null) {
9194 w.mAppToken.allDrawn = false;
9195 }
9196 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009197 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009198 "Resizing window " + w + " to " + w.mFrame);
9199 mResizingWindows.add(w);
9200 } else if (w.mOrientationChanging) {
9201 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009202 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009203 "Orientation not waiting for draw in "
9204 + w + ", surface " + w.mSurface);
9205 w.mOrientationChanging = false;
9206 }
9207 }
9208 }
9209
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009210 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 if (!w.mLastHidden) {
9212 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009213 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9214 + w.mRootToken.waitingToShow + " polvis="
9215 + w.mPolicyVisibility + " atthid="
9216 + w.mAttachedHidden + " tokhid="
9217 + w.mRootToken.hidden + " vis="
9218 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009219 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009220 if (SHOW_TRANSACTIONS) logSurface(w,
9221 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009223 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224 try {
9225 w.mSurface.hide();
9226 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009227 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009228 }
9229 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009230 mInputMonitor.windowIsBecomingInvisibleLw(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009231 }
9232 // If we are waiting for this window to handle an
9233 // orientation change, well, it is hidden, so
9234 // doesn't really matter. Note that this does
9235 // introduce a potential glitch if the window
9236 // becomes unhidden before it has drawn for the
9237 // new orientation.
9238 if (w.mOrientationChanging) {
9239 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009240 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009241 "Orientation change skips hidden " + w);
9242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243 } else if (w.mLastLayer != w.mAnimLayer
9244 || w.mLastAlpha != w.mShownAlpha
9245 || w.mLastDsDx != w.mDsDx
9246 || w.mLastDtDx != w.mDtDx
9247 || w.mLastDsDy != w.mDsDy
9248 || w.mLastDtDy != w.mDtDy
9249 || w.mLastHScale != w.mHScale
9250 || w.mLastVScale != w.mVScale
9251 || w.mLastHidden) {
9252 displayed = true;
9253 w.mLastAlpha = w.mShownAlpha;
9254 w.mLastLayer = w.mAnimLayer;
9255 w.mLastDsDx = w.mDsDx;
9256 w.mLastDtDx = w.mDtDx;
9257 w.mLastDsDy = w.mDsDy;
9258 w.mLastDtDy = w.mDtDy;
9259 w.mLastHScale = w.mHScale;
9260 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009261 if (SHOW_TRANSACTIONS) logSurface(w,
9262 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009263 + " matrix=[" + (w.mDsDx*w.mHScale)
9264 + "," + (w.mDtDx*w.mVScale)
9265 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009266 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009267 if (w.mSurface != null) {
9268 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009269 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009271 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009272 w.mSurface.setLayer(w.mAnimLayer);
9273 w.mSurface.setMatrix(
9274 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9275 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9276 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009277 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009278 if (!recoveringMemory) {
9279 reclaimSomeSurfaceMemoryLocked(w, "update");
9280 }
9281 }
9282 }
9283
9284 if (w.mLastHidden && !w.mDrawPending
9285 && !w.mCommitDrawPending
9286 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009287 if (SHOW_TRANSACTIONS) logSurface(w,
9288 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009289 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009290 + " during relayout");
9291 if (showSurfaceRobustlyLocked(w)) {
9292 w.mHasDrawn = true;
9293 w.mLastHidden = false;
9294 } else {
9295 w.mOrientationChanging = false;
9296 }
9297 }
9298 if (w.mSurface != null) {
9299 w.mToken.hasVisible = true;
9300 }
9301 } else {
9302 displayed = true;
9303 }
9304
9305 if (displayed) {
9306 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009307 if (attrs.width == LayoutParams.MATCH_PARENT
9308 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009309 covered = true;
9310 }
9311 }
9312 if (w.mOrientationChanging) {
9313 if (w.mDrawPending || w.mCommitDrawPending) {
9314 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009315 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009316 "Orientation continue waiting for draw in " + w);
9317 } else {
9318 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009319 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 "Orientation change complete in " + w);
9321 }
9322 }
9323 w.mToken.hasVisible = true;
9324 }
9325 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009326 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 "Orientation change skips hidden " + w);
9328 w.mOrientationChanging = false;
9329 }
9330
9331 final boolean canBeSeen = w.isDisplayedLw();
9332
9333 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9334 focusDisplayed = true;
9335 }
9336
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009337 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009339 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009340 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009341 if (w.mSurface != null) {
9342 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9343 holdScreen = w.mSession;
9344 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009345 if (!syswin && w.mAttrs.screenBrightness >= 0
9346 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009347 screenBrightness = w.mAttrs.screenBrightness;
9348 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009349 if (!syswin && w.mAttrs.buttonBrightness >= 0
9350 && buttonBrightness < 0) {
9351 buttonBrightness = w.mAttrs.buttonBrightness;
9352 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009353 if (canBeSeen
9354 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9355 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9356 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009357 syswin = true;
9358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009359 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009360
Dianne Hackborn25994b42009-09-04 14:21:19 -07009361 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9362 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009363 // This window completely covers everything behind it,
9364 // so we want to leave all of them as unblurred (for
9365 // performance reasons).
9366 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009367 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009368 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009369 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009370 obscured = true;
9371 if (mBackgroundFillerSurface == null) {
9372 try {
9373 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009374 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009375 0, dw, dh,
9376 PixelFormat.OPAQUE,
9377 Surface.FX_SURFACE_NORMAL);
9378 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009379 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009380 }
9381 }
9382 try {
9383 mBackgroundFillerSurface.setPosition(0, 0);
9384 mBackgroundFillerSurface.setSize(dw, dh);
9385 // Using the same layer as Dim because they will never be shown at the
9386 // same time.
9387 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9388 mBackgroundFillerSurface.show();
9389 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009390 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009391 }
9392 backgroundFillerShown = true;
9393 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009394 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009395 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009396 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009397 + ": blurring=" + blurring
9398 + " obscured=" + obscured
9399 + " displayed=" + displayed);
9400 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9401 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009402 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009404 if (mDimAnimator == null) {
9405 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009406 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009407 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009408 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009409 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009410 }
9411 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9412 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009413 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009414 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009416 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009417 + mBlurSurface + ": CREATE");
9418 try {
Romain Guy06882f82009-06-10 13:36:04 -07009419 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009420 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009421 -1, 16, 16,
9422 PixelFormat.OPAQUE,
9423 Surface.FX_SURFACE_BLUR);
9424 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009425 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009426 }
9427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009428 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009429 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9430 + mBlurSurface + ": pos=(0,0) (" +
9431 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009432 mBlurSurface.setPosition(0, 0);
9433 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009434 mBlurSurface.setLayer(w.mAnimLayer-2);
9435 if (!mBlurShown) {
9436 try {
9437 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9438 + mBlurSurface + ": SHOW");
9439 mBlurSurface.show();
9440 } catch (RuntimeException e) {
9441 Slog.w(TAG, "Failure showing blur surface", e);
9442 }
9443 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009444 }
9445 }
9446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447 }
9448 }
9449 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009450
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009451 if (obscuredChanged && mWallpaperTarget == w) {
9452 // This is the wallpaper target and its obscured state
9453 // changed... make sure the current wallaper's visibility
9454 // has been updated accordingly.
9455 updateWallpaperVisibilityLocked();
9456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009457 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009458
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009459 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9460 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009461 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009462 try {
9463 mBackgroundFillerSurface.hide();
9464 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009465 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009466 }
9467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009468
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009469 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009470 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9471 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 }
Romain Guy06882f82009-06-10 13:36:04 -07009473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009474 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009475 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 + ": HIDE");
9477 try {
9478 mBlurSurface.hide();
9479 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009480 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009481 }
9482 mBlurShown = false;
9483 }
9484
Joe Onorato8a9b2202010-02-26 18:56:32 -08009485 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009487 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009488 }
9489
9490 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009491
Joe Onorato8a9b2202010-02-26 18:56:32 -08009492 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009493 "With display frozen, orientationChangeComplete="
9494 + orientationChangeComplete);
9495 if (orientationChangeComplete) {
9496 if (mWindowsFreezingScreen) {
9497 mWindowsFreezingScreen = false;
9498 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9499 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009500 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009501 }
Romain Guy06882f82009-06-10 13:36:04 -07009502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 i = mResizingWindows.size();
9504 if (i > 0) {
9505 do {
9506 i--;
9507 WindowState win = mResizingWindows.get(i);
9508 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009509 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9510 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009511 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009512 boolean configChanged =
9513 win.mConfiguration != mCurConfiguration
9514 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009515 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9516 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9517 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009518 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009519 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009520 + " / " + mCurConfiguration + " / 0x"
9521 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009522 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009523 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009524 win.mClient.resized(win.mFrame.width(),
9525 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009526 win.mLastVisibleInsets, win.mDrawPending,
9527 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009528 win.mContentInsetsChanged = false;
9529 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009530 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009531 } catch (RemoteException e) {
9532 win.mOrientationChanging = false;
9533 }
9534 } while (i > 0);
9535 mResizingWindows.clear();
9536 }
Romain Guy06882f82009-06-10 13:36:04 -07009537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009538 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009539 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009540 i = mDestroySurface.size();
9541 if (i > 0) {
9542 do {
9543 i--;
9544 WindowState win = mDestroySurface.get(i);
9545 win.mDestroying = false;
9546 if (mInputMethodWindow == win) {
9547 mInputMethodWindow = null;
9548 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009549 if (win == mWallpaperTarget) {
9550 wallpaperDestroyed = true;
9551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009552 win.destroySurfaceLocked();
9553 } while (i > 0);
9554 mDestroySurface.clear();
9555 }
9556
9557 // Time to remove any exiting tokens?
9558 for (i=mExitingTokens.size()-1; i>=0; i--) {
9559 WindowToken token = mExitingTokens.get(i);
9560 if (!token.hasVisible) {
9561 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009562 if (token.windowType == TYPE_WALLPAPER) {
9563 mWallpaperTokens.remove(token);
9564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 }
9566 }
9567
9568 // Time to remove any exiting applications?
9569 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9570 AppWindowToken token = mExitingAppTokens.get(i);
9571 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009572 // Make sure there is no animation running on this token,
9573 // so any windows associated with it will be removed as
9574 // soon as their animations are complete
9575 token.animation = null;
9576 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009577 mAppTokens.remove(token);
9578 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009579 if (mLastEnterAnimToken == token) {
9580 mLastEnterAnimToken = null;
9581 mLastEnterAnimParams = null;
9582 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009583 }
9584 }
9585
Dianne Hackborna8f60182009-09-01 19:01:50 -07009586 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009587
Dianne Hackborna8f60182009-09-01 19:01:50 -07009588 if (!animating && mAppTransitionRunning) {
9589 // We have finished the animation of an app transition. To do
9590 // this, we have delayed a lot of operations like showing and
9591 // hiding apps, moving apps in Z-order, etc. The app token list
9592 // reflects the correct Z-order, but the window list may now
9593 // be out of sync with it. So here we will just rebuild the
9594 // entire app window list. Fun!
9595 mAppTransitionRunning = false;
9596 needRelayout = true;
9597 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009598 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009599 // Clear information about apps that were moving.
9600 mToBottomApps.clear();
9601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 if (focusDisplayed) {
9604 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9605 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009606 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009607 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009608 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009609 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009610 requestAnimationLocked(0);
9611 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009612 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9613 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009614
9615 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9616 + " holdScreen=" + holdScreen);
9617 if (!mDisplayFrozen) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07009618 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009619 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9620 mPowerManager.setScreenBrightnessOverride(-1);
9621 } else {
9622 mPowerManager.setScreenBrightnessOverride((int)
9623 (screenBrightness * Power.BRIGHTNESS_ON));
9624 }
9625 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9626 mPowerManager.setButtonBrightnessOverride(-1);
9627 } else {
9628 mPowerManager.setButtonBrightnessOverride((int)
9629 (buttonBrightness * Power.BRIGHTNESS_ON));
9630 }
9631 if (holdScreen != mHoldingScreenOn) {
9632 mHoldingScreenOn = holdScreen;
9633 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9634 mH.sendMessage(m);
9635 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009636 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009637
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009638 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009639 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009640 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9641 LocalPowerManager.BUTTON_EVENT, true);
9642 mTurnOnScreen = false;
9643 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009644
9645 // Check to see if we are now in a state where the screen should
9646 // be enabled, because the window obscured flags have changed.
9647 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009648 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07009649
9650 /**
9651 * Must be called with the main window manager lock held.
9652 */
9653 void setHoldScreenLocked(boolean holding) {
9654 boolean state = mHoldingScreenWakeLock.isHeld();
9655 if (holding != state) {
9656 if (holding) {
9657 mHoldingScreenWakeLock.acquire();
9658 } else {
9659 mPolicy.screenOnStoppedLw();
9660 mHoldingScreenWakeLock.release();
9661 }
9662 }
9663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009664
9665 void requestAnimationLocked(long delay) {
9666 if (!mAnimationPending) {
9667 mAnimationPending = true;
9668 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9669 }
9670 }
Romain Guy06882f82009-06-10 13:36:04 -07009671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009672 /**
9673 * Have the surface flinger show a surface, robustly dealing with
9674 * error conditions. In particular, if there is not enough memory
9675 * to show the surface, then we will try to get rid of other surfaces
9676 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009677 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009678 * @return Returns true if the surface was successfully shown.
9679 */
9680 boolean showSurfaceRobustlyLocked(WindowState win) {
9681 try {
9682 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009683 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009685 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009686 if (DEBUG_VISIBILITY) Slog.v(TAG,
9687 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009688 win.mTurnOnScreen = false;
9689 mTurnOnScreen = true;
9690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 }
9692 return true;
9693 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009694 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009695 }
Romain Guy06882f82009-06-10 13:36:04 -07009696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009697 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009699 return false;
9700 }
Romain Guy06882f82009-06-10 13:36:04 -07009701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9703 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009704
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009705 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009706 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009708 if (mForceRemoves == null) {
9709 mForceRemoves = new ArrayList<WindowState>();
9710 }
Romain Guy06882f82009-06-10 13:36:04 -07009711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009712 long callingIdentity = Binder.clearCallingIdentity();
9713 try {
9714 // There was some problem... first, do a sanity check of the
9715 // window list to make sure we haven't left any dangling surfaces
9716 // around.
9717 int N = mWindows.size();
9718 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009719 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009720 for (int i=0; i<N; i++) {
9721 WindowState ws = (WindowState)mWindows.get(i);
9722 if (ws.mSurface != null) {
9723 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009724 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009725 + ws + " surface=" + ws.mSurface
9726 + " token=" + win.mToken
9727 + " pid=" + ws.mSession.mPid
9728 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009729 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009730 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009731 ws.mSurface = null;
9732 mForceRemoves.add(ws);
9733 i--;
9734 N--;
9735 leakedSurface = true;
9736 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009737 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009738 + ws + " surface=" + ws.mSurface
9739 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009740 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009741 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742 ws.mSurface = null;
9743 leakedSurface = true;
9744 }
9745 }
9746 }
Romain Guy06882f82009-06-10 13:36:04 -07009747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009748 boolean killedApps = false;
9749 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009750 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009751 SparseIntArray pidCandidates = new SparseIntArray();
9752 for (int i=0; i<N; i++) {
9753 WindowState ws = (WindowState)mWindows.get(i);
9754 if (ws.mSurface != null) {
9755 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9756 }
9757 }
9758 if (pidCandidates.size() > 0) {
9759 int[] pids = new int[pidCandidates.size()];
9760 for (int i=0; i<pids.length; i++) {
9761 pids[i] = pidCandidates.keyAt(i);
9762 }
9763 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009764 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 killedApps = true;
9766 }
9767 } catch (RemoteException e) {
9768 }
9769 }
9770 }
Romain Guy06882f82009-06-10 13:36:04 -07009771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 if (leakedSurface || killedApps) {
9773 // We managed to reclaim some memory, so get rid of the trouble
9774 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009775 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009776 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009777 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009778 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009779 win.mSurface = null;
9780 }
Romain Guy06882f82009-06-10 13:36:04 -07009781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 try {
9783 win.mClient.dispatchGetNewSurface();
9784 } catch (RemoteException e) {
9785 }
9786 }
9787 } finally {
9788 Binder.restoreCallingIdentity(callingIdentity);
9789 }
9790 }
Romain Guy06882f82009-06-10 13:36:04 -07009791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009792 private boolean updateFocusedWindowLocked(int mode) {
9793 WindowState newFocus = computeFocusedWindowLocked();
9794 if (mCurrentFocus != newFocus) {
9795 // This check makes sure that we don't already have the focus
9796 // change message pending.
9797 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9798 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009799 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9801 final WindowState oldFocus = mCurrentFocus;
9802 mCurrentFocus = newFocus;
9803 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009805 final WindowState imWindow = mInputMethodWindow;
9806 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009807 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009809 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9810 mLayoutNeeded = true;
9811 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9813 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009814 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9815 // Client will do the layout, but we need to assign layers
9816 // for handleNewWindowLocked() below.
9817 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 }
9819 }
Jeff Brown349703e2010-06-22 01:27:15 -07009820
9821 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9822 // If we defer assigning layers, then the caller is responsible for
9823 // doing this part.
9824 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009825 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009826 return true;
9827 }
9828 return false;
9829 }
Jeff Brown349703e2010-06-22 01:27:15 -07009830
9831 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009832 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009834
9835 private WindowState computeFocusedWindowLocked() {
9836 WindowState result = null;
9837 WindowState win;
9838
9839 int i = mWindows.size() - 1;
9840 int nextAppIndex = mAppTokens.size()-1;
9841 WindowToken nextApp = nextAppIndex >= 0
9842 ? mAppTokens.get(nextAppIndex) : null;
9843
9844 while (i >= 0) {
9845 win = (WindowState)mWindows.get(i);
9846
Joe Onorato8a9b2202010-02-26 18:56:32 -08009847 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 TAG, "Looking for focus: " + i
9849 + " = " + win
9850 + ", flags=" + win.mAttrs.flags
9851 + ", canReceive=" + win.canReceiveKeys());
9852
9853 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855 // If this window's application has been removed, just skip it.
9856 if (thisApp != null && thisApp.removed) {
9857 i--;
9858 continue;
9859 }
Romain Guy06882f82009-06-10 13:36:04 -07009860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009861 // If there is a focused app, don't allow focus to go to any
9862 // windows below it. If this is an application window, step
9863 // through the app tokens until we find its app.
9864 if (thisApp != null && nextApp != null && thisApp != nextApp
9865 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9866 int origAppIndex = nextAppIndex;
9867 while (nextAppIndex > 0) {
9868 if (nextApp == mFocusedApp) {
9869 // Whoops, we are below the focused app... no focus
9870 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009871 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009872 TAG, "Reached focused app: " + mFocusedApp);
9873 return null;
9874 }
9875 nextAppIndex--;
9876 nextApp = mAppTokens.get(nextAppIndex);
9877 if (nextApp == thisApp) {
9878 break;
9879 }
9880 }
9881 if (thisApp != nextApp) {
9882 // Uh oh, the app token doesn't exist! This shouldn't
9883 // happen, but if it does we can get totally hosed...
9884 // so restart at the original app.
9885 nextAppIndex = origAppIndex;
9886 nextApp = mAppTokens.get(nextAppIndex);
9887 }
9888 }
9889
9890 // Dispatch to this window if it is wants key events.
9891 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009892 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 TAG, "Found focus @ " + i + " = " + win);
9894 result = win;
9895 break;
9896 }
9897
9898 i--;
9899 }
9900
9901 return result;
9902 }
9903
9904 private void startFreezingDisplayLocked() {
9905 if (mDisplayFrozen) {
9906 return;
9907 }
Romain Guy06882f82009-06-10 13:36:04 -07009908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009911 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009912 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009913 if (mFreezeGcPending != 0) {
9914 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009915 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009916 mH.removeMessages(H.FORCE_GC);
9917 Runtime.getRuntime().gc();
9918 mFreezeGcPending = now;
9919 }
9920 } else {
9921 mFreezeGcPending = now;
9922 }
Romain Guy06882f82009-06-10 13:36:04 -07009923
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009924 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
9925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009927
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009928 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009929
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009930 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9931 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009932 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 mAppTransitionReady = true;
9934 }
Romain Guy06882f82009-06-10 13:36:04 -07009935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 if (PROFILE_ORIENTATION) {
9937 File file = new File("/data/system/frozen");
9938 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9939 }
9940 Surface.freezeDisplay(0);
9941 }
Romain Guy06882f82009-06-10 13:36:04 -07009942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009943 private void stopFreezingDisplayLocked() {
9944 if (!mDisplayFrozen) {
9945 return;
9946 }
Romain Guy06882f82009-06-10 13:36:04 -07009947
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009948 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9949 return;
9950 }
9951
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009952 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
9953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009954 mDisplayFrozen = false;
9955 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9956 if (PROFILE_ORIENTATION) {
9957 Debug.stopMethodTracing();
9958 }
9959 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009960
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009961 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009962
Christopher Tateb696aee2010-04-02 19:08:30 -07009963 // While the display is frozen we don't re-compute the orientation
9964 // to avoid inconsistent states. However, something interesting
9965 // could have actually changed during that time so re-evaluate it
9966 // now to catch that.
9967 if (updateOrientationFromAppTokensLocked()) {
9968 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9969 }
9970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009971 // A little kludge: a lot could have happened while the
9972 // display was frozen, so now that we are coming back we
9973 // do a gc so that any remote references the system
9974 // processes holds on others can be released if they are
9975 // no longer needed.
9976 mH.removeMessages(H.FORCE_GC);
9977 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
9978 2000);
Romain Guy06882f82009-06-10 13:36:04 -07009979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 mScreenFrozenLock.release();
9981 }
Romain Guy06882f82009-06-10 13:36:04 -07009982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 @Override
9984 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
9985 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
9986 != PackageManager.PERMISSION_GRANTED) {
9987 pw.println("Permission Denial: can't dump WindowManager from from pid="
9988 + Binder.getCallingPid()
9989 + ", uid=" + Binder.getCallingUid());
9990 return;
9991 }
Romain Guy06882f82009-06-10 13:36:04 -07009992
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009993 pw.println("Input Dispatcher State:");
9994 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -08009995 pw.println(" ");
9996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009997 synchronized(mWindowMap) {
9998 pw.println("Current Window Manager state:");
9999 for (int i=mWindows.size()-1; i>=0; i--) {
10000 WindowState w = (WindowState)mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010001 pw.print(" Window #"); pw.print(i); pw.print(' ');
10002 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 w.dump(pw, " ");
10004 }
10005 if (mInputMethodDialogs.size() > 0) {
10006 pw.println(" ");
10007 pw.println(" Input method dialogs:");
10008 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10009 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010010 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010011 }
10012 }
10013 if (mPendingRemove.size() > 0) {
10014 pw.println(" ");
10015 pw.println(" Remove pending for:");
10016 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10017 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010018 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10019 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010020 w.dump(pw, " ");
10021 }
10022 }
10023 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10024 pw.println(" ");
10025 pw.println(" Windows force removing:");
10026 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10027 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010028 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10029 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 w.dump(pw, " ");
10031 }
10032 }
10033 if (mDestroySurface.size() > 0) {
10034 pw.println(" ");
10035 pw.println(" Windows waiting to destroy their surface:");
10036 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10037 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010038 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10039 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010040 w.dump(pw, " ");
10041 }
10042 }
10043 if (mLosingFocus.size() > 0) {
10044 pw.println(" ");
10045 pw.println(" Windows losing focus:");
10046 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10047 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010048 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10049 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010050 w.dump(pw, " ");
10051 }
10052 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010053 if (mResizingWindows.size() > 0) {
10054 pw.println(" ");
10055 pw.println(" Windows waiting to resize:");
10056 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10057 WindowState w = mResizingWindows.get(i);
10058 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10059 pw.print(w); pw.println(":");
10060 w.dump(pw, " ");
10061 }
10062 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 if (mSessions.size() > 0) {
10064 pw.println(" ");
10065 pw.println(" All active sessions:");
10066 Iterator<Session> it = mSessions.iterator();
10067 while (it.hasNext()) {
10068 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010069 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010070 s.dump(pw, " ");
10071 }
10072 }
10073 if (mTokenMap.size() > 0) {
10074 pw.println(" ");
10075 pw.println(" All tokens:");
10076 Iterator<WindowToken> it = mTokenMap.values().iterator();
10077 while (it.hasNext()) {
10078 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010079 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010080 token.dump(pw, " ");
10081 }
10082 }
10083 if (mTokenList.size() > 0) {
10084 pw.println(" ");
10085 pw.println(" Window token list:");
10086 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010087 pw.print(" #"); pw.print(i); pw.print(": ");
10088 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010089 }
10090 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010091 if (mWallpaperTokens.size() > 0) {
10092 pw.println(" ");
10093 pw.println(" Wallpaper tokens:");
10094 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10095 WindowToken token = mWallpaperTokens.get(i);
10096 pw.print(" Wallpaper #"); pw.print(i);
10097 pw.print(' '); pw.print(token); pw.println(':');
10098 token.dump(pw, " ");
10099 }
10100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010101 if (mAppTokens.size() > 0) {
10102 pw.println(" ");
10103 pw.println(" Application tokens in Z order:");
10104 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010105 pw.print(" App #"); pw.print(i); pw.print(": ");
10106 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 }
10108 }
10109 if (mFinishedStarting.size() > 0) {
10110 pw.println(" ");
10111 pw.println(" Finishing start of application tokens:");
10112 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10113 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010114 pw.print(" Finished Starting #"); pw.print(i);
10115 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010116 token.dump(pw, " ");
10117 }
10118 }
10119 if (mExitingTokens.size() > 0) {
10120 pw.println(" ");
10121 pw.println(" Exiting tokens:");
10122 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10123 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010124 pw.print(" Exiting #"); pw.print(i);
10125 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010126 token.dump(pw, " ");
10127 }
10128 }
10129 if (mExitingAppTokens.size() > 0) {
10130 pw.println(" ");
10131 pw.println(" Exiting application tokens:");
10132 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10133 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010134 pw.print(" Exiting App #"); pw.print(i);
10135 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010136 token.dump(pw, " ");
10137 }
10138 }
10139 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010140 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10141 pw.print(" mLastFocus="); pw.println(mLastFocus);
10142 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10143 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10144 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010145 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010146 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10147 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10148 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10149 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010150 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10151 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10152 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010153 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10154 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10155 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10156 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010157 if (mDimAnimator != null) {
10158 mDimAnimator.printTo(pw);
10159 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010160 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010161 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010162 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010163 pw.print(mInputMethodAnimLayerAdjustment);
10164 pw.print(" mWallpaperAnimLayerAdjustment=");
10165 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010166 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10167 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010168 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10169 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010170 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10171 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010172 pw.print(" mRotation="); pw.print(mRotation);
10173 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10174 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10175 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10176 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10177 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10178 pw.print(" mNextAppTransition=0x");
10179 pw.print(Integer.toHexString(mNextAppTransition));
10180 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010181 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010182 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010183 if (mNextAppTransitionPackage != null) {
10184 pw.print(" mNextAppTransitionPackage=");
10185 pw.print(mNextAppTransitionPackage);
10186 pw.print(", mNextAppTransitionEnter=0x");
10187 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10188 pw.print(", mNextAppTransitionExit=0x");
10189 pw.print(Integer.toHexString(mNextAppTransitionExit));
10190 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010191 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10192 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010193 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10194 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10195 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10196 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010197 if (mOpeningApps.size() > 0) {
10198 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10199 }
10200 if (mClosingApps.size() > 0) {
10201 pw.print(" mClosingApps="); pw.println(mClosingApps);
10202 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010203 if (mToTopApps.size() > 0) {
10204 pw.print(" mToTopApps="); pw.println(mToTopApps);
10205 }
10206 if (mToBottomApps.size() > 0) {
10207 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10208 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010209 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10210 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010211 }
10212 }
10213
Jeff Brown349703e2010-06-22 01:27:15 -070010214 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010215 public void monitor() {
10216 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010217 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010218 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010219
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010220 /**
10221 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010222 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010223 */
10224 private static class DimAnimator {
10225 Surface mDimSurface;
10226 boolean mDimShown = false;
10227 float mDimCurrentAlpha;
10228 float mDimTargetAlpha;
10229 float mDimDeltaPerMs;
10230 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010231
10232 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010233
10234 DimAnimator (SurfaceSession session) {
10235 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010236 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010237 + mDimSurface + ": CREATE");
10238 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010239 mDimSurface = new Surface(session, 0,
10240 "DimSurface",
10241 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010242 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010243 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010244 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010245 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010246 }
10247 }
10248 }
10249
10250 /**
10251 * Show the dim surface.
10252 */
10253 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010254 if (!mDimShown) {
10255 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10256 dw + "x" + dh + ")");
10257 mDimShown = true;
10258 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010259 mLastDimWidth = dw;
10260 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010261 mDimSurface.setPosition(0, 0);
10262 mDimSurface.setSize(dw, dh);
10263 mDimSurface.show();
10264 } catch (RuntimeException e) {
10265 Slog.w(TAG, "Failure showing dim surface", e);
10266 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010267 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10268 mLastDimWidth = dw;
10269 mLastDimHeight = dh;
10270 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010271 }
10272 }
10273
10274 /**
10275 * Set's the dim surface's layer and update dim parameters that will be used in
10276 * {@link updateSurface} after all windows are examined.
10277 */
10278 void updateParameters(WindowState w, long currentTime) {
10279 mDimSurface.setLayer(w.mAnimLayer-1);
10280
10281 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010282 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010283 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010284 if (mDimTargetAlpha != target) {
10285 // If the desired dim level has changed, then
10286 // start an animation to it.
10287 mLastDimAnimTime = currentTime;
10288 long duration = (w.mAnimating && w.mAnimation != null)
10289 ? w.mAnimation.computeDurationHint()
10290 : DEFAULT_DIM_DURATION;
10291 if (target > mDimTargetAlpha) {
10292 // This is happening behind the activity UI,
10293 // so we can make it run a little longer to
10294 // give a stronger impression without disrupting
10295 // the user.
10296 duration *= DIM_DURATION_MULTIPLIER;
10297 }
10298 if (duration < 1) {
10299 // Don't divide by zero
10300 duration = 1;
10301 }
10302 mDimTargetAlpha = target;
10303 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10304 }
10305 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010306
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010307 /**
10308 * Updating the surface's alpha. Returns true if the animation continues, or returns
10309 * false when the animation is finished and the dim surface is hidden.
10310 */
10311 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10312 if (!dimming) {
10313 if (mDimTargetAlpha != 0) {
10314 mLastDimAnimTime = currentTime;
10315 mDimTargetAlpha = 0;
10316 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10317 }
10318 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010319
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010320 boolean animating = false;
10321 if (mLastDimAnimTime != 0) {
10322 mDimCurrentAlpha += mDimDeltaPerMs
10323 * (currentTime-mLastDimAnimTime);
10324 boolean more = true;
10325 if (displayFrozen) {
10326 // If the display is frozen, there is no reason to animate.
10327 more = false;
10328 } else if (mDimDeltaPerMs > 0) {
10329 if (mDimCurrentAlpha > mDimTargetAlpha) {
10330 more = false;
10331 }
10332 } else if (mDimDeltaPerMs < 0) {
10333 if (mDimCurrentAlpha < mDimTargetAlpha) {
10334 more = false;
10335 }
10336 } else {
10337 more = false;
10338 }
10339
10340 // Do we need to continue animating?
10341 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010342 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010343 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10344 mLastDimAnimTime = currentTime;
10345 mDimSurface.setAlpha(mDimCurrentAlpha);
10346 animating = true;
10347 } else {
10348 mDimCurrentAlpha = mDimTargetAlpha;
10349 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010350 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010351 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10352 mDimSurface.setAlpha(mDimCurrentAlpha);
10353 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010354 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010355 + ": HIDE");
10356 try {
10357 mDimSurface.hide();
10358 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010359 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010360 }
10361 mDimShown = false;
10362 }
10363 }
10364 }
10365 return animating;
10366 }
10367
10368 public void printTo(PrintWriter pw) {
10369 pw.print(" mDimShown="); pw.print(mDimShown);
10370 pw.print(" current="); pw.print(mDimCurrentAlpha);
10371 pw.print(" target="); pw.print(mDimTargetAlpha);
10372 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10373 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10374 }
10375 }
10376
10377 /**
10378 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10379 * This is used for opening/closing transition for apps in compatible mode.
10380 */
10381 private static class FadeInOutAnimation extends Animation {
10382 int mWidth;
10383 boolean mFadeIn;
10384
10385 public FadeInOutAnimation(boolean fadeIn) {
10386 setInterpolator(new AccelerateInterpolator());
10387 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10388 mFadeIn = fadeIn;
10389 }
10390
10391 @Override
10392 protected void applyTransformation(float interpolatedTime, Transformation t) {
10393 float x = interpolatedTime;
10394 if (!mFadeIn) {
10395 x = 1.0f - x; // reverse the interpolation for fade out
10396 }
10397 if (x < 0.5) {
10398 // move the window out of the screen.
10399 t.getMatrix().setTranslate(mWidth, 0);
10400 } else {
10401 t.getMatrix().setTranslate(0, 0);// show
10402 t.setAlpha((x - 0.5f) * 2);
10403 }
10404 }
10405
10406 @Override
10407 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10408 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10409 mWidth = width;
10410 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010411
10412 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010413 public int getZAdjustment() {
10414 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010415 }
10416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010417}