blob: cd687da1eac031083957d11bb6b31d46b3c49ba7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import static android.os.LocalPowerManager.CHEEK_EVENT;
20import static android.os.LocalPowerManager.OTHER_EVENT;
21import static android.os.LocalPowerManager.TOUCH_EVENT;
Joe Onoratoe68ffcb2009-03-24 19:11:13 -070022import static android.os.LocalPowerManager.LONG_TOUCH_EVENT;
23import static android.os.LocalPowerManager.TOUCH_UP_EVENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
25import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
26import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070027import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
29import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070030import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
32import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
36import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
38import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
39import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
40import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
41import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070042import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import com.android.internal.app.IBatteryStats;
45import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080046import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import com.android.internal.view.IInputContext;
48import com.android.internal.view.IInputMethodClient;
49import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080050import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import com.android.server.am.BatteryStatsService;
52
53import android.Manifest;
54import android.app.ActivityManagerNative;
55import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070056import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070057import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070059import android.content.Intent;
60import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.ActivityInfo;
62import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.content.res.Configuration;
65import android.graphics.Matrix;
66import android.graphics.PixelFormat;
67import android.graphics.Rect;
68import android.graphics.Region;
69import android.os.BatteryStats;
70import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070071import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.Debug;
73import android.os.Handler;
74import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070075import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.LocalPowerManager;
77import android.os.Looper;
78import android.os.Message;
79import android.os.Parcel;
80import android.os.ParcelFileDescriptor;
81import android.os.Power;
82import android.os.PowerManager;
83import android.os.Process;
84import android.os.RemoteException;
85import android.os.ServiceManager;
86import android.os.SystemClock;
87import android.os.SystemProperties;
88import android.os.TokenWatcher;
89import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070090import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070092import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080093import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.util.SparseIntArray;
95import android.view.Display;
96import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070097import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IApplicationToken;
99import android.view.IOnKeyguardExitResult;
100import android.view.IRotationWatcher;
101import android.view.IWindow;
102import android.view.IWindowManager;
103import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700104import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -0700106import android.view.InputEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700107import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.KeyEvent;
109import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110import android.view.Surface;
111import android.view.SurfaceSession;
112import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700113import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114import android.view.ViewTreeObserver;
115import android.view.WindowManager;
116import android.view.WindowManagerImpl;
117import android.view.WindowManagerPolicy;
118import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700119import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120import android.view.animation.Animation;
121import android.view.animation.AnimationUtils;
122import android.view.animation.Transformation;
123
124import java.io.BufferedWriter;
125import java.io.File;
126import java.io.FileDescriptor;
127import java.io.IOException;
128import java.io.OutputStream;
129import java.io.OutputStreamWriter;
130import java.io.PrintWriter;
131import java.io.StringWriter;
132import java.net.Socket;
133import java.util.ArrayList;
134import java.util.HashMap;
135import java.util.HashSet;
136import java.util.Iterator;
137import java.util.List;
138
139/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700140public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700141 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 static final String TAG = "WindowManager";
143 static final boolean DEBUG = false;
144 static final boolean DEBUG_FOCUS = false;
145 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800146 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800147 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 static final boolean DEBUG_LAYERS = false;
149 static final boolean DEBUG_INPUT = false;
150 static final boolean DEBUG_INPUT_METHOD = false;
151 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700152 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700154 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_APP_TRANSITIONS = false;
156 static final boolean DEBUG_STARTING_WINDOW = false;
157 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700158 static final boolean DEBUG_WALLPAPER = false;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700159 static final boolean DEBUG_FREEZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700161 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700162 static final boolean MEASURE_LATENCY = false;
163 static private LatencyTimer lt;
164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean PROFILE_ORIENTATION = false;
166 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700167 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /** How much to multiply the policy's type layer, to reserve room
170 * for multiple windows of the same type and Z-ordering adjustment
171 * with TYPE_LAYER_OFFSET. */
172 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
175 * or below others in the same layer. */
176 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /** How much to increment the layer for each window, to reserve room
179 * for effect surfaces between them.
180 */
181 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** The maximum length we will accept for a loaded animation duration:
184 * this is 10 seconds.
185 */
186 static final int MAX_ANIMATION_DURATION = 10*1000;
187
188 /** Amount of time (in milliseconds) to animate the dim surface from one
189 * value to another, when no window animation is driving it.
190 */
191 static final int DEFAULT_DIM_DURATION = 200;
192
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700193 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
194 * compatible windows.
195 */
196 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 /** Adjustment to time to perform a dim, to make it more dramatic.
199 */
200 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700201
202 // Maximum number of milliseconds to wait for input event injection.
203 // FIXME is this value reasonable?
204 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700205
206 // Default input dispatching timeout in nanoseconds.
207 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 static final int UPDATE_FOCUS_NORMAL = 0;
210 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
211 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
212 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700215 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
217 /**
218 * Condition waited on by {@link #reenableKeyguard} to know the call to
219 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500220 * This is set to true only if mKeyguardTokenWatcher.acquired() has
221 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500223 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224
Jim Miller284b62e2010-06-08 14:27:42 -0700225 private static final int ALLOW_DISABLE_YES = 1;
226 private static final int ALLOW_DISABLE_NO = 0;
227 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
228 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
229
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
231 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700233 if (shouldAllowDisableKeyguard()) {
234 mPolicy.enableKeyguard(false);
235 mKeyguardDisabled = true;
236 } else {
237 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 }
240 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700241 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500242 synchronized (mKeyguardTokenWatcher) {
243 mKeyguardDisabled = false;
244 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 }
246 }
247 };
248
Jim Miller284b62e2010-06-08 14:27:42 -0700249 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
250 @Override
251 public void onReceive(Context context, Intent intent) {
252 mPolicy.enableKeyguard(true);
253 synchronized(mKeyguardTokenWatcher) {
254 // lazily evaluate this next time we're asked to disable keyguard
255 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
256 mKeyguardDisabled = false;
257 }
258 }
259 };
260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 final Context mContext;
262
263 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
268
269 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 /**
274 * All currently active sessions with clients.
275 */
276 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * Mapping from an IWindow IBinder to the server's Window object.
280 * This is also used as the lock for all of our state.
281 */
282 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
283
284 /**
285 * Mapping from a token IBinder to a WindowToken object.
286 */
287 final HashMap<IBinder, WindowToken> mTokenMap =
288 new HashMap<IBinder, WindowToken>();
289
290 /**
291 * The same tokens as mTokenMap, stored in a list for efficient iteration
292 * over them.
293 */
294 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 /**
297 * Window tokens that are in the process of exiting, but still
298 * on screen for animations.
299 */
300 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
301
302 /**
303 * Z-ordered (bottom-most first) list of all application tokens, for
304 * controlling the ordering of windows in different applications. This
305 * contains WindowToken objects.
306 */
307 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
308
309 /**
310 * Application tokens that are in the process of exiting, but still
311 * on screen for animations.
312 */
313 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
314
315 /**
316 * List of window tokens that have finished starting their application,
317 * and now need to have the policy remove their windows.
318 */
319 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
320
321 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700322 * This was the app token that was used to retrieve the last enter
323 * animation. It will be used for the next exit animation.
324 */
325 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800326
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700327 /**
328 * These were the layout params used to retrieve the last enter animation.
329 * They will be used for the next exit animation.
330 */
331 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800332
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700333 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 * Z-ordered (bottom-most first) list of all Window objects.
335 */
Jeff Browne33348b2010-07-15 23:54:05 -0700336 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337
338 /**
339 * Windows that are being resized. Used so we can tell the client about
340 * the resize after closing the transaction in which we resized the
341 * underlying surface.
342 */
343 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
344
345 /**
346 * Windows whose animations have ended and now must be removed.
347 */
348 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
349
350 /**
351 * Windows whose surface should be destroyed.
352 */
353 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
354
355 /**
356 * Windows that have lost input focus and are waiting for the new
357 * focus window to be displayed before they are told about this.
358 */
359 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
360
361 /**
362 * This is set when we have run out of memory, and will either be an empty
363 * list or contain windows that need to be force removed.
364 */
365 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700370 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 Surface mBlurSurface;
372 boolean mBlurShown;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 final float[] mTmpFloats = new float[9];
377
378 boolean mSafeMode;
379 boolean mDisplayEnabled = false;
380 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700381 int mInitialDisplayWidth = 0;
382 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 int mRotation = 0;
384 int mRequestedRotation = 0;
385 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700386 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 ArrayList<IRotationWatcher> mRotationWatchers
388 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 boolean mLayoutNeeded = true;
391 boolean mAnimationPending = false;
392 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800393 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 boolean mWindowsFreezingScreen = false;
395 long mFreezeGcPending = 0;
396 int mAppsFreezingScreen = 0;
397
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800398 int mLayoutSeq = 0;
399
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800400 // State while inside of layoutAndPlaceSurfacesLocked().
401 boolean mFocusMayChange;
402
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800403 Configuration mCurConfiguration = new Configuration();
404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 // This is held as long as we have the screen frozen, to give us time to
406 // perform a rotation animation when turning off shows the lock screen which
407 // changes the orientation.
408 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 // State management of app transitions. When we are preparing for a
411 // transition, mNextAppTransition will be the kind of transition to
412 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
413 // mOpeningApps and mClosingApps are the lists of tokens that will be
414 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700415 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700416 String mNextAppTransitionPackage;
417 int mNextAppTransitionEnter;
418 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700420 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 boolean mAppTransitionTimeout = false;
422 boolean mStartingIconInTransition = false;
423 boolean mSkipAppTransitionAnimation = false;
424 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
425 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700426 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
427 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 H mH = new H();
432
433 WindowState mCurrentFocus = null;
434 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 // This just indicates the window the input method is on top of, not
437 // necessarily the window its input is going to.
438 WindowState mInputMethodTarget = null;
439 WindowState mUpcomingInputMethodTarget = null;
440 boolean mInputMethodTargetWaitingAnim;
441 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 WindowState mInputMethodWindow = null;
444 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
445
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700446 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800447
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700448 // If non-null, this is the currently visible window that is associated
449 // with the wallpaper.
450 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700451 // If non-null, we are in the middle of animating from one wallpaper target
452 // to another, and this is the lower one in Z-order.
453 WindowState mLowerWallpaperTarget = null;
454 // If non-null, we are in the middle of animating from one wallpaper target
455 // to another, and this is the higher one in Z-order.
456 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700458 float mLastWallpaperX = -1;
459 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800460 float mLastWallpaperXStep = -1;
461 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700462 // This is set when we are waiting for a wallpaper to tell us it is done
463 // changing its scroll position.
464 WindowState mWaitingOnWallpaper;
465 // The last time we had a timeout when waiting for a wallpaper.
466 long mLastWallpaperTimeoutTime;
467 // We give a wallpaper up to 150ms to finish scrolling.
468 static final long WALLPAPER_TIMEOUT = 150;
469 // Time we wait after a timeout before trying to wait again.
470 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 AppWindowToken mFocusedApp = null;
473
474 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 float mWindowAnimationScale = 1.0f;
477 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700478
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700479 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480
481 // Who is holding the screen on.
482 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700483 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700484
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700485 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 /**
488 * Whether the UI is currently running in touch mode (not showing
489 * navigational focus because the user is directly pressing the screen).
490 */
491 boolean mInTouchMode = false;
492
493 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700494 private ArrayList<WindowChangeListener> mWindowChangeListeners =
495 new ArrayList<WindowChangeListener>();
496 private boolean mWindowsChanged = false;
497
498 public interface WindowChangeListener {
499 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700500 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502
Dianne Hackbornc485a602009-03-24 22:39:49 -0700503 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700504 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700505
506 // The frame use to limit the size of the app running in compatibility mode.
507 Rect mCompatibleScreenFrame = new Rect();
508 // The surface used to fill the outer rim of the app running in compatibility mode.
509 Surface mBackgroundFillerSurface = null;
510 boolean mBackgroundFillerShown = false;
511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 public static WindowManagerService main(Context context,
513 PowerManagerService pm, boolean haveInputMethods) {
514 WMThread thr = new WMThread(context, pm, haveInputMethods);
515 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 synchronized (thr) {
518 while (thr.mService == null) {
519 try {
520 thr.wait();
521 } catch (InterruptedException e) {
522 }
523 }
524 }
Romain Guy06882f82009-06-10 13:36:04 -0700525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 return thr.mService;
527 }
Romain Guy06882f82009-06-10 13:36:04 -0700528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 static class WMThread extends Thread {
530 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 private final Context mContext;
533 private final PowerManagerService mPM;
534 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 public WMThread(Context context, PowerManagerService pm,
537 boolean haveInputMethods) {
538 super("WindowManager");
539 mContext = context;
540 mPM = pm;
541 mHaveInputMethods = haveInputMethods;
542 }
Romain Guy06882f82009-06-10 13:36:04 -0700543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 public void run() {
545 Looper.prepare();
546 WindowManagerService s = new WindowManagerService(mContext, mPM,
547 mHaveInputMethods);
548 android.os.Process.setThreadPriority(
549 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700550 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 synchronized (this) {
553 mService = s;
554 notifyAll();
555 }
Romain Guy06882f82009-06-10 13:36:04 -0700556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 Looper.loop();
558 }
559 }
560
561 static class PolicyThread extends Thread {
562 private final WindowManagerPolicy mPolicy;
563 private final WindowManagerService mService;
564 private final Context mContext;
565 private final PowerManagerService mPM;
566 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 public PolicyThread(WindowManagerPolicy policy,
569 WindowManagerService service, Context context,
570 PowerManagerService pm) {
571 super("WindowManagerPolicy");
572 mPolicy = policy;
573 mService = service;
574 mContext = context;
575 mPM = pm;
576 }
Romain Guy06882f82009-06-10 13:36:04 -0700577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 public void run() {
579 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800580 WindowManagerPolicyThread.set(this, Looper.myLooper());
581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800583 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 android.os.Process.setThreadPriority(
585 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700586 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 synchronized (this) {
590 mRunning = true;
591 notifyAll();
592 }
Romain Guy06882f82009-06-10 13:36:04 -0700593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 Looper.loop();
595 }
596 }
597
598 private WindowManagerService(Context context, PowerManagerService pm,
599 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700600 if (MEASURE_LATENCY) {
601 lt = new LatencyTimer(100, 1000);
602 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 mContext = context;
605 mHaveInputMethods = haveInputMethods;
606 mLimitedAlphaCompositing = context.getResources().getBoolean(
607 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 mPowerManager = pm;
610 mPowerManager.setPolicy(mPolicy);
611 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
612 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
613 "SCREEN_FROZEN");
614 mScreenFrozenLock.setReferenceCounted(false);
615
616 mActivityManager = ActivityManagerNative.getDefault();
617 mBatteryStats = BatteryStatsService.getService();
618
619 // Get persisted window scale setting
620 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
621 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
622 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
623 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700624
Jim Miller284b62e2010-06-08 14:27:42 -0700625 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
626 IntentFilter filter = new IntentFilter();
627 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
628 mContext.registerReceiver(mBroadcastReceiver, filter);
629
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700630 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
631 "KEEP_SCREEN_ON_FLAG");
632 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633
Jeff Browne33348b2010-07-15 23:54:05 -0700634 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
637 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 synchronized (thr) {
640 while (!thr.mRunning) {
641 try {
642 thr.wait();
643 } catch (InterruptedException e) {
644 }
645 }
646 }
Romain Guy06882f82009-06-10 13:36:04 -0700647
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700648 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 // Add ourself to the Watchdog monitors.
651 Watchdog.getInstance().addMonitor(this);
652 }
653
654 @Override
655 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
656 throws RemoteException {
657 try {
658 return super.onTransact(code, data, reply, flags);
659 } catch (RuntimeException e) {
660 // The window manager only throws security exceptions, so let's
661 // log all others.
662 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800663 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 }
665 throw e;
666 }
667 }
668
Jeff Browne33348b2010-07-15 23:54:05 -0700669 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 TAG, "Adding window " + window + " at "
673 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
674 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700675 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 }
677
Jeff Browne33348b2010-07-15 23:54:05 -0700678 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800680 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 TAG, "Adding window " + window + " at "
682 + i + " of " + mWindows.size() + " (before " + pos + ")");
683 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700684 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 }
686
687 //This method finds out the index of a window that has the same app token as
688 //win. used for z ordering the windows in mWindows
689 private int findIdxBasedOnAppTokens(WindowState win) {
690 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700691 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 int jmax = localmWindows.size();
693 if(jmax == 0) {
694 return -1;
695 }
696 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700697 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 if(wentry.mAppToken == win.mAppToken) {
699 return j;
700 }
701 }
702 return -1;
703 }
Romain Guy06882f82009-06-10 13:36:04 -0700704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
706 final IWindow client = win.mClient;
707 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700708 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 final int N = localmWindows.size();
711 final WindowState attached = win.mAttachedWindow;
712 int i;
713 if (attached == null) {
714 int tokenWindowsPos = token.windows.size();
715 if (token.appWindowToken != null) {
716 int index = tokenWindowsPos-1;
717 if (index >= 0) {
718 // If this application has existing windows, we
719 // simply place the new window on top of them... but
720 // keep the starting window on top.
721 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
722 // Base windows go behind everything else.
723 placeWindowBefore(token.windows.get(0), win);
724 tokenWindowsPos = 0;
725 } else {
726 AppWindowToken atoken = win.mAppToken;
727 if (atoken != null &&
728 token.windows.get(index) == atoken.startingWindow) {
729 placeWindowBefore(token.windows.get(index), win);
730 tokenWindowsPos--;
731 } else {
732 int newIdx = findIdxBasedOnAppTokens(win);
733 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700734 //there is a window above this one associated with the same
735 //apptoken note that the window could be a floating window
736 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800738 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700739 TAG, "Adding window " + win + " at "
740 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700742 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 }
745 }
746 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800747 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 TAG, "Figuring out where to add app window "
749 + client.asBinder() + " (token=" + token + ")");
750 // Figure out where the window should go, based on the
751 // order of applications.
752 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700753 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 for (i=NA-1; i>=0; i--) {
755 AppWindowToken t = mAppTokens.get(i);
756 if (t == token) {
757 i--;
758 break;
759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800760
Dianne Hackborna8f60182009-09-01 19:01:50 -0700761 // We haven't reached the token yet; if this token
762 // is not going to the bottom and has windows, we can
763 // use it as an anchor for when we do reach the token.
764 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 pos = t.windows.get(0);
766 }
767 }
768 // We now know the index into the apps. If we found
769 // an app window above, that gives us the position; else
770 // we need to look some more.
771 if (pos != null) {
772 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700773 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 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.
Jeff Browne33348b2010-07-15 23:54:05 -0700799 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 if (atoken != null) {
801 final int NC = atoken.windows.size();
802 if (NC > 0) {
803 WindowState top = atoken.windows.get(NC-1);
804 if (top.mSubLayer >= 0) {
805 pos = top;
806 }
807 }
808 }
809 placeWindowAfter(pos, win);
810 } else {
811 // Just search for the start of this layer.
812 final int myLayer = win.mBaseLayer;
813 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700814 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 if (w.mBaseLayer > myLayer) {
816 break;
817 }
818 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800819 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700820 TAG, "Adding window " + win + " at "
821 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700823 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 }
825 }
826 }
827 } else {
828 // Figure out where window should go, based on layer.
829 final int myLayer = win.mBaseLayer;
830 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700831 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 i++;
833 break;
834 }
835 }
836 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800837 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700838 TAG, "Adding window " + win + " at "
839 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700841 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 }
843 if (addToToken) {
844 token.windows.add(tokenWindowsPos, win);
845 }
846
847 } else {
848 // Figure out this window's ordering relative to the window
849 // it is attached to.
850 final int NA = token.windows.size();
851 final int sublayer = win.mSubLayer;
852 int largestSublayer = Integer.MIN_VALUE;
853 WindowState windowWithLargestSublayer = null;
854 for (i=0; i<NA; i++) {
855 WindowState w = token.windows.get(i);
856 final int wSublayer = w.mSubLayer;
857 if (wSublayer >= largestSublayer) {
858 largestSublayer = wSublayer;
859 windowWithLargestSublayer = w;
860 }
861 if (sublayer < 0) {
862 // For negative sublayers, we go below all windows
863 // in the same sublayer.
864 if (wSublayer >= sublayer) {
865 if (addToToken) {
866 token.windows.add(i, win);
867 }
868 placeWindowBefore(
869 wSublayer >= 0 ? attached : w, win);
870 break;
871 }
872 } else {
873 // For positive sublayers, we go above all windows
874 // in the same sublayer.
875 if (wSublayer > sublayer) {
876 if (addToToken) {
877 token.windows.add(i, win);
878 }
879 placeWindowBefore(w, win);
880 break;
881 }
882 }
883 }
884 if (i >= NA) {
885 if (addToToken) {
886 token.windows.add(win);
887 }
888 if (sublayer < 0) {
889 placeWindowBefore(attached, win);
890 } else {
891 placeWindowAfter(largestSublayer >= 0
892 ? windowWithLargestSublayer
893 : attached,
894 win);
895 }
896 }
897 }
Romain Guy06882f82009-06-10 13:36:04 -0700898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 if (win.mAppToken != null && addToToken) {
900 win.mAppToken.allAppWindows.add(win);
901 }
902 }
Romain Guy06882f82009-06-10 13:36:04 -0700903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 static boolean canBeImeTarget(WindowState w) {
905 final int fl = w.mAttrs.flags
906 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
907 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
908 return w.isVisibleOrAdding();
909 }
910 return false;
911 }
Romain Guy06882f82009-06-10 13:36:04 -0700912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700914 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 final int N = localmWindows.size();
916 WindowState w = null;
917 int i = N;
918 while (i > 0) {
919 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700920 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700921
Joe Onorato8a9b2202010-02-26 18:56:32 -0800922 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 // + Integer.toHexString(w.mAttrs.flags));
924 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800925 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 // Yet more tricksyness! If this window is a "starting"
928 // window, we do actually want to be on top of it, but
929 // it is not -really- where input will go. So if the caller
930 // is not actually looking to move the IME, look down below
931 // for a real window to target...
932 if (!willMove
933 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
934 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700935 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
937 i--;
938 w = wb;
939 }
940 }
941 break;
942 }
943 }
Romain Guy06882f82009-06-10 13:36:04 -0700944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700946
Joe Onorato8a9b2202010-02-26 18:56:32 -0800947 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 if (willMove && w != null) {
951 final WindowState curTarget = mInputMethodTarget;
952 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 // Now some fun for dealing with window animations that
955 // modify the Z order. We need to look at all windows below
956 // the current target that are in this app, finding the highest
957 // visible one in layering.
958 AppWindowToken token = curTarget.mAppToken;
959 WindowState highestTarget = null;
960 int highestPos = 0;
961 if (token.animating || token.animation != null) {
962 int pos = 0;
963 pos = localmWindows.indexOf(curTarget);
964 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700965 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 if (win.mAppToken != token) {
967 break;
968 }
969 if (!win.mRemoved) {
970 if (highestTarget == null || win.mAnimLayer >
971 highestTarget.mAnimLayer) {
972 highestTarget = win;
973 highestPos = pos;
974 }
975 }
976 pos--;
977 }
978 }
Romain Guy06882f82009-06-10 13:36:04 -0700979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800981 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 + mNextAppTransition + " " + highestTarget
983 + " animating=" + highestTarget.isAnimating()
984 + " layer=" + highestTarget.mAnimLayer
985 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700986
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700987 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 // If we are currently setting up for an animation,
989 // hold everything until we can find out what will happen.
990 mInputMethodTargetWaitingAnim = true;
991 mInputMethodTarget = highestTarget;
992 return highestPos + 1;
993 } else if (highestTarget.isAnimating() &&
994 highestTarget.mAnimLayer > w.mAnimLayer) {
995 // If the window we are currently targeting is involved
996 // with an animation, and it is on top of the next target
997 // we will be over, then hold off on moving until
998 // that is done.
999 mInputMethodTarget = highestTarget;
1000 return highestPos + 1;
1001 }
1002 }
1003 }
1004 }
Romain Guy06882f82009-06-10 13:36:04 -07001005
Joe Onorato8a9b2202010-02-26 18:56:32 -08001006 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 if (w != null) {
1008 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001009 if (DEBUG_INPUT_METHOD) {
1010 RuntimeException e = null;
1011 if (!HIDE_STACK_CRAWLS) {
1012 e = new RuntimeException();
1013 e.fillInStackTrace();
1014 }
1015 Slog.w(TAG, "Moving IM target from "
1016 + mInputMethodTarget + " to " + w, e);
1017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 mInputMethodTarget = w;
1019 if (w.mAppToken != null) {
1020 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1021 } else {
1022 setInputMethodAnimLayerAdjustment(0);
1023 }
1024 }
1025 return i+1;
1026 }
1027 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001028 if (DEBUG_INPUT_METHOD) {
1029 RuntimeException e = null;
1030 if (!HIDE_STACK_CRAWLS) {
1031 e = new RuntimeException();
1032 e.fillInStackTrace();
1033 }
1034 Slog.w(TAG, "Moving IM target from "
1035 + mInputMethodTarget + " to null", e);
1036 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 mInputMethodTarget = null;
1038 setInputMethodAnimLayerAdjustment(0);
1039 }
1040 return -1;
1041 }
Romain Guy06882f82009-06-10 13:36:04 -07001042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 void addInputMethodWindowToListLocked(WindowState win) {
1044 int pos = findDesiredInputMethodWindowIndexLocked(true);
1045 if (pos >= 0) {
1046 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001047 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001048 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001050 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 moveInputMethodDialogsLocked(pos+1);
1052 return;
1053 }
1054 win.mTargetAppToken = null;
1055 addWindowToListInOrderLocked(win, true);
1056 moveInputMethodDialogsLocked(pos);
1057 }
Romain Guy06882f82009-06-10 13:36:04 -07001058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001060 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 mInputMethodAnimLayerAdjustment = adj;
1062 WindowState imw = mInputMethodWindow;
1063 if (imw != null) {
1064 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001065 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 + " anim layer: " + imw.mAnimLayer);
1067 int wi = imw.mChildWindows.size();
1068 while (wi > 0) {
1069 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001070 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 + " anim layer: " + cw.mAnimLayer);
1074 }
1075 }
1076 int di = mInputMethodDialogs.size();
1077 while (di > 0) {
1078 di --;
1079 imw = mInputMethodDialogs.get(di);
1080 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001081 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 + " anim layer: " + imw.mAnimLayer);
1083 }
1084 }
Romain Guy06882f82009-06-10 13:36:04 -07001085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1087 int wpos = mWindows.indexOf(win);
1088 if (wpos >= 0) {
1089 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001090 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001092 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 int NC = win.mChildWindows.size();
1094 while (NC > 0) {
1095 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001096 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 int cpos = mWindows.indexOf(cw);
1098 if (cpos >= 0) {
1099 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001101 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 mWindows.remove(cpos);
1103 }
1104 }
1105 }
1106 return interestingPos;
1107 }
Romain Guy06882f82009-06-10 13:36:04 -07001108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 private void reAddWindowToListInOrderLocked(WindowState win) {
1110 addWindowToListInOrderLocked(win, false);
1111 // This is a hack to get all of the child windows added as well
1112 // at the right position. Child windows should be rare and
1113 // this case should be rare, so it shouldn't be that big a deal.
1114 int wpos = mWindows.indexOf(win);
1115 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001116 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001117 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001119 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 reAddWindowLocked(wpos, win);
1121 }
1122 }
Romain Guy06882f82009-06-10 13:36:04 -07001123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 void logWindowList(String prefix) {
1125 int N = mWindows.size();
1126 while (N > 0) {
1127 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001128 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 }
1130 }
Romain Guy06882f82009-06-10 13:36:04 -07001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 void moveInputMethodDialogsLocked(int pos) {
1133 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001136 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 for (int i=0; i<N; i++) {
1138 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1139 }
1140 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001141 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 logWindowList(" ");
1143 }
Romain Guy06882f82009-06-10 13:36:04 -07001144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (pos >= 0) {
1146 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1147 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001148 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 if (wp == mInputMethodWindow) {
1150 pos++;
1151 }
1152 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001153 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 for (int i=0; i<N; i++) {
1155 WindowState win = dialogs.get(i);
1156 win.mTargetAppToken = targetAppToken;
1157 pos = reAddWindowLocked(pos, win);
1158 }
1159 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001160 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 logWindowList(" ");
1162 }
1163 return;
1164 }
1165 for (int i=0; i<N; i++) {
1166 WindowState win = dialogs.get(i);
1167 win.mTargetAppToken = null;
1168 reAddWindowToListInOrderLocked(win);
1169 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001170 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 logWindowList(" ");
1172 }
1173 }
1174 }
Romain Guy06882f82009-06-10 13:36:04 -07001175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1177 final WindowState imWin = mInputMethodWindow;
1178 final int DN = mInputMethodDialogs.size();
1179 if (imWin == null && DN == 0) {
1180 return false;
1181 }
Romain Guy06882f82009-06-10 13:36:04 -07001182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1184 if (imPos >= 0) {
1185 // In this case, the input method windows are to be placed
1186 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 // First check to see if the input method windows are already
1189 // located here, and contiguous.
1190 final int N = mWindows.size();
1191 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001192 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 // Figure out the actual input method window that should be
1195 // at the bottom of their stack.
1196 WindowState baseImWin = imWin != null
1197 ? imWin : mInputMethodDialogs.get(0);
1198 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001199 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 if (cw.mSubLayer < 0) baseImWin = cw;
1201 }
Romain Guy06882f82009-06-10 13:36:04 -07001202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 if (firstImWin == baseImWin) {
1204 // The windows haven't moved... but are they still contiguous?
1205 // First find the top IM window.
1206 int pos = imPos+1;
1207 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001208 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 break;
1210 }
1211 pos++;
1212 }
1213 pos++;
1214 // Now there should be no more input method windows above.
1215 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001216 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 break;
1218 }
1219 pos++;
1220 }
1221 if (pos >= N) {
1222 // All is good!
1223 return false;
1224 }
1225 }
Romain Guy06882f82009-06-10 13:36:04 -07001226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 if (imWin != null) {
1228 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001229 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 logWindowList(" ");
1231 }
1232 imPos = tmpRemoveWindowLocked(imPos, imWin);
1233 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001234 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 logWindowList(" ");
1236 }
1237 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1238 reAddWindowLocked(imPos, imWin);
1239 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001240 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 logWindowList(" ");
1242 }
1243 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1244 } else {
1245 moveInputMethodDialogsLocked(imPos);
1246 }
Romain Guy06882f82009-06-10 13:36:04 -07001247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 } else {
1249 // In this case, the input method windows go in a fixed layer,
1250 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001253 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 tmpRemoveWindowLocked(0, imWin);
1255 imWin.mTargetAppToken = null;
1256 reAddWindowToListInOrderLocked(imWin);
1257 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001258 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 logWindowList(" ");
1260 }
1261 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1262 } else {
1263 moveInputMethodDialogsLocked(-1);;
1264 }
Romain Guy06882f82009-06-10 13:36:04 -07001265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 }
Romain Guy06882f82009-06-10 13:36:04 -07001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 if (needAssignLayers) {
1269 assignLayersLocked();
1270 }
Romain Guy06882f82009-06-10 13:36:04 -07001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 return true;
1273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 void adjustInputMethodDialogsLocked() {
1276 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1277 }
Romain Guy06882f82009-06-10 13:36:04 -07001278
Dianne Hackborn25994b42009-09-04 14:21:19 -07001279 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001280 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001281 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1282 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1283 ? wallpaperTarget.mAppToken.animation : null)
1284 + " upper=" + mUpperWallpaperTarget
1285 + " lower=" + mLowerWallpaperTarget);
1286 return (wallpaperTarget != null
1287 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1288 && wallpaperTarget.mAppToken.animation != null)))
1289 || mUpperWallpaperTarget != null
1290 || mLowerWallpaperTarget != null;
1291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001292
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001293 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1294 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001295
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001296 int adjustWallpaperWindowsLocked() {
1297 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001298
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001299 final int dw = mDisplay.getWidth();
1300 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001301
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001302 // First find top-most window that has asked to be on top of the
1303 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001304 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001305 int N = localmWindows.size();
1306 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001307 WindowState foundW = null;
1308 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001309 WindowState topCurW = null;
1310 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001311 int i = N;
1312 while (i > 0) {
1313 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001314 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001315 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1316 if (topCurW == null) {
1317 topCurW = w;
1318 topCurI = i;
1319 }
1320 continue;
1321 }
1322 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001323 if (w.mAppToken != null) {
1324 // If this window's app token is hidden and not animating,
1325 // it is of no interest to us.
1326 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001327 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001328 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001329 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001330 continue;
1331 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001332 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001334 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1335 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001336 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001337 && (mWallpaperTarget == w
1338 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001339 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001340 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001341 foundW = w;
1342 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001343 if (w == mWallpaperTarget && ((w.mAppToken != null
1344 && w.mAppToken.animation != null)
1345 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001346 // The current wallpaper target is animating, so we'll
1347 // look behind it for another possible target and figure
1348 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001349 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001350 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001351 continue;
1352 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001353 break;
1354 }
1355 }
1356
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001357 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001358 // If we are currently waiting for an app transition, and either
1359 // the current target or the next target are involved with it,
1360 // then hold off on doing anything with the wallpaper.
1361 // Note that we are checking here for just whether the target
1362 // is part of an app token... which is potentially overly aggressive
1363 // (the app token may not be involved in the transition), but good
1364 // enough (we'll just wait until whatever transition is pending
1365 // executes).
1366 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001367 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001368 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001369 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001370 }
1371 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001372 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001373 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001374 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001375 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001376 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001377
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001378 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001379 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001380 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001381 + " oldTarget: " + mWallpaperTarget);
1382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001383
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001384 mLowerWallpaperTarget = null;
1385 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001386
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001387 WindowState oldW = mWallpaperTarget;
1388 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001389
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001390 // Now what is happening... if the current and new targets are
1391 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001392 if (foundW != null && oldW != null) {
1393 boolean oldAnim = oldW.mAnimation != null
1394 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1395 boolean foundAnim = foundW.mAnimation != null
1396 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001398 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001399 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001400 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001401 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001402 int oldI = localmWindows.indexOf(oldW);
1403 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001404 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 }
1406 if (oldI >= 0) {
1407 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001408 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001409 + "=" + oldW + "; new#" + foundI
1410 + "=" + foundW);
1411 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001412
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001413 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001414 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001415 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001416 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001417 }
1418 mWallpaperTarget = oldW;
1419 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001420
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 // Now set the upper and lower wallpaper targets
1422 // correctly, and make sure that we are positioning
1423 // the wallpaper below the lower.
1424 if (foundI > oldI) {
1425 // The new target is on top of the old one.
1426 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001427 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001428 }
1429 mUpperWallpaperTarget = foundW;
1430 mLowerWallpaperTarget = oldW;
1431 foundW = oldW;
1432 foundI = oldI;
1433 } else {
1434 // The new target is below the old one.
1435 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001436 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001437 }
1438 mUpperWallpaperTarget = oldW;
1439 mLowerWallpaperTarget = foundW;
1440 }
1441 }
1442 }
1443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001444
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001445 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001446 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001447 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1448 || (mLowerWallpaperTarget.mAppToken != null
1449 && mLowerWallpaperTarget.mAppToken.animation != null);
1450 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1451 || (mUpperWallpaperTarget.mAppToken != null
1452 && mUpperWallpaperTarget.mAppToken.animation != null);
1453 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001454 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001455 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001456 }
1457 mLowerWallpaperTarget = null;
1458 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001459 }
1460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001461
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001462 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001463 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001464 // The window is visible to the compositor... but is it visible
1465 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001466 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001467 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001468
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001469 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001470 // its layer adjustment. Only do this if we are not transfering
1471 // between two wallpaper targets.
1472 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001473 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001474 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001475
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001476 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1477 * TYPE_LAYER_MULTIPLIER
1478 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001479
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001480 // Now w is the window we are supposed to be behind... but we
1481 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001482 // AND any starting window associated with it, AND below the
1483 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001484 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001485 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001486 if (wb.mBaseLayer < maxLayer &&
1487 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001488 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001489 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001490 // This window is not related to the previous one in any
1491 // interesting way, so stop here.
1492 break;
1493 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001494 foundW = wb;
1495 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001496 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001497 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001498 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001499 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001500
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001501 if (foundW == null && topCurW != null) {
1502 // There is no wallpaper target, so it goes at the bottom.
1503 // We will assume it is the same place as last time, if known.
1504 foundW = topCurW;
1505 foundI = topCurI+1;
1506 } else {
1507 // Okay i is the position immediately above the wallpaper. Look at
1508 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001509 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001510 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001511
Dianne Hackborn284ac932009-08-28 10:34:25 -07001512 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001513 if (mWallpaperTarget.mWallpaperX >= 0) {
1514 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001515 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001516 }
1517 if (mWallpaperTarget.mWallpaperY >= 0) {
1518 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001519 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001520 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001521 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001522
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001523 // Start stepping backwards from here, ensuring that our wallpaper windows
1524 // are correctly placed.
1525 int curTokenIndex = mWallpaperTokens.size();
1526 while (curTokenIndex > 0) {
1527 curTokenIndex--;
1528 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001529 if (token.hidden == visible) {
1530 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1531 token.hidden = !visible;
1532 // Need to do a layout to ensure the wallpaper now has the
1533 // correct size.
1534 mLayoutNeeded = true;
1535 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001536
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001537 int curWallpaperIndex = token.windows.size();
1538 while (curWallpaperIndex > 0) {
1539 curWallpaperIndex--;
1540 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001541
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001542 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001543 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001544 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001545
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001546 // First, make sure the client has the current visibility
1547 // state.
1548 if (wallpaper.mWallpaperVisible != visible) {
1549 wallpaper.mWallpaperVisible = visible;
1550 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001551 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001552 "Setting visibility of wallpaper " + wallpaper
1553 + ": " + visible);
1554 wallpaper.mClient.dispatchAppVisibility(visible);
1555 } catch (RemoteException e) {
1556 }
1557 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001558
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001559 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001561 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001562
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001563 // First, if this window is at the current index, then all
1564 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001565 if (wallpaper == foundW) {
1566 foundI--;
1567 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001568 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 continue;
1570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001571
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001572 // The window didn't match... the current wallpaper window,
1573 // wherever it is, is in the wrong place, so make sure it is
1574 // not in the list.
1575 int oldIndex = localmWindows.indexOf(wallpaper);
1576 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001577 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001578 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001580 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001581 if (oldIndex < foundI) {
1582 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001583 }
1584 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001585
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001586 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001587 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001588 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001589 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001590
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001591 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001592 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001593 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001594 }
1595 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001597 return changed;
1598 }
1599
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001600 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001601 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001602 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001603 mWallpaperAnimLayerAdjustment = adj;
1604 int curTokenIndex = mWallpaperTokens.size();
1605 while (curTokenIndex > 0) {
1606 curTokenIndex--;
1607 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1608 int curWallpaperIndex = token.windows.size();
1609 while (curWallpaperIndex > 0) {
1610 curWallpaperIndex--;
1611 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1612 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001614 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001615 }
1616 }
1617 }
1618
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001619 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1620 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001621 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001622 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001623 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001624 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001625 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1626 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1627 changed = wallpaperWin.mXOffset != offset;
1628 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001629 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001630 + wallpaperWin + " x: " + offset);
1631 wallpaperWin.mXOffset = offset;
1632 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001633 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001634 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001635 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001637 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001638
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001639 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001640 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001641 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1642 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1643 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001644 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001645 + wallpaperWin + " y: " + offset);
1646 changed = true;
1647 wallpaperWin.mYOffset = offset;
1648 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001649 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001650 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001651 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001652 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001653 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001654
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001655 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001656 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001657 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001658 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1659 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001660 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001661 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001662 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001663 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001664 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1665 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 if (mWaitingOnWallpaper != null) {
1668 long start = SystemClock.uptimeMillis();
1669 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1670 < start) {
1671 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001672 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001673 "Waiting for offset complete...");
1674 mWindowMap.wait(WALLPAPER_TIMEOUT);
1675 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001676 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 if ((start+WALLPAPER_TIMEOUT)
1679 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001680 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001681 + wallpaperWin);
1682 mLastWallpaperTimeoutTime = start;
1683 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001684 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001685 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001686 }
1687 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001688 } catch (RemoteException e) {
1689 }
1690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001692 return changed;
1693 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001694
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001695 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001696 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001697 if (mWaitingOnWallpaper != null &&
1698 mWaitingOnWallpaper.mClient.asBinder() == window) {
1699 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001700 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001701 }
1702 }
1703 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001704
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001705 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001706 final int dw = mDisplay.getWidth();
1707 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001709 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001710
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001711 WindowState target = mWallpaperTarget;
1712 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001713 if (target.mWallpaperX >= 0) {
1714 mLastWallpaperX = target.mWallpaperX;
1715 } else if (changingTarget.mWallpaperX >= 0) {
1716 mLastWallpaperX = changingTarget.mWallpaperX;
1717 }
1718 if (target.mWallpaperY >= 0) {
1719 mLastWallpaperY = target.mWallpaperY;
1720 } else if (changingTarget.mWallpaperY >= 0) {
1721 mLastWallpaperY = changingTarget.mWallpaperY;
1722 }
1723 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001724
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001725 int curTokenIndex = mWallpaperTokens.size();
1726 while (curTokenIndex > 0) {
1727 curTokenIndex--;
1728 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1729 int curWallpaperIndex = token.windows.size();
1730 while (curWallpaperIndex > 0) {
1731 curWallpaperIndex--;
1732 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1733 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1734 wallpaper.computeShownFrameLocked();
1735 changed = true;
1736 // We only want to be synchronous with one wallpaper.
1737 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001738 }
1739 }
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001742 return changed;
1743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001744
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001745 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001746 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 final int dw = mDisplay.getWidth();
1748 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001749
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001750 int curTokenIndex = mWallpaperTokens.size();
1751 while (curTokenIndex > 0) {
1752 curTokenIndex--;
1753 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001754 if (token.hidden == visible) {
1755 token.hidden = !visible;
1756 // Need to do a layout to ensure the wallpaper now has the
1757 // correct size.
1758 mLayoutNeeded = true;
1759 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001760
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001761 int curWallpaperIndex = token.windows.size();
1762 while (curWallpaperIndex > 0) {
1763 curWallpaperIndex--;
1764 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1765 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001766 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001768
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001769 if (wallpaper.mWallpaperVisible != visible) {
1770 wallpaper.mWallpaperVisible = visible;
1771 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001772 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001773 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001774 + ": " + visible);
1775 wallpaper.mClient.dispatchAppVisibility(visible);
1776 } catch (RemoteException e) {
1777 }
1778 }
1779 }
1780 }
1781 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 public int addWindow(Session session, IWindow client,
1784 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001785 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 int res = mPolicy.checkAddPermission(attrs);
1787 if (res != WindowManagerImpl.ADD_OKAY) {
1788 return res;
1789 }
Romain Guy06882f82009-06-10 13:36:04 -07001790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 boolean reportNewConfig = false;
1792 WindowState attachedWindow = null;
1793 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 synchronized(mWindowMap) {
1796 // Instantiating a Display requires talking with the simulator,
1797 // so don't do it until we know the system is mostly up and
1798 // running.
1799 if (mDisplay == null) {
1800 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1801 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001802 mInitialDisplayWidth = mDisplay.getWidth();
1803 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001804 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 reportNewConfig = true;
1806 }
Romain Guy06882f82009-06-10 13:36:04 -07001807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001809 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1811 }
1812
1813 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001814 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001816 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 + attrs.token + ". Aborting.");
1818 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1819 }
1820 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1821 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001822 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001823 + attrs.token + ". Aborting.");
1824 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1825 }
1826 }
1827
1828 boolean addToken = false;
1829 WindowToken token = mTokenMap.get(attrs.token);
1830 if (token == null) {
1831 if (attrs.type >= FIRST_APPLICATION_WINDOW
1832 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 + attrs.token + ". Aborting.");
1835 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1836 }
1837 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001838 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 + attrs.token + ". Aborting.");
1840 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1841 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001842 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001843 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001844 + attrs.token + ". Aborting.");
1845 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 token = new WindowToken(attrs.token, -1, false);
1848 addToken = true;
1849 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1850 && attrs.type <= LAST_APPLICATION_WINDOW) {
1851 AppWindowToken atoken = token.appWindowToken;
1852 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 + token + ". Aborting.");
1855 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1856 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001857 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 + token + ". Aborting.");
1859 return WindowManagerImpl.ADD_APP_EXITING;
1860 }
1861 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1862 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001863 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1865 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1866 }
1867 } else if (attrs.type == TYPE_INPUT_METHOD) {
1868 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001869 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 + attrs.token + ". Aborting.");
1871 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1872 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001873 } else if (attrs.type == TYPE_WALLPAPER) {
1874 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001875 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001876 + attrs.token + ". Aborting.");
1877 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 }
1880
1881 win = new WindowState(session, client, token,
1882 attachedWindow, attrs, viewVisibility);
1883 if (win.mDeathRecipient == null) {
1884 // Client has apparently died, so there is no reason to
1885 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001886 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 + " that is dead, aborting.");
1888 return WindowManagerImpl.ADD_APP_EXITING;
1889 }
1890
1891 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 res = mPolicy.prepareAddWindowLw(win, attrs);
1894 if (res != WindowManagerImpl.ADD_OKAY) {
1895 return res;
1896 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001897
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001898 if (outInputChannel != null) {
1899 String name = win.makeInputChannelName();
1900 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1901 win.mInputChannel = inputChannels[0];
1902 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1903
1904 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906
1907 // From now on, no exceptions or errors allowed!
1908
1909 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 if (addToken) {
1914 mTokenMap.put(attrs.token, token);
1915 mTokenList.add(token);
1916 }
1917 win.attach();
1918 mWindowMap.put(client.asBinder(), win);
1919
1920 if (attrs.type == TYPE_APPLICATION_STARTING &&
1921 token.appWindowToken != null) {
1922 token.appWindowToken.startingWindow = win;
1923 }
1924
1925 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 if (attrs.type == TYPE_INPUT_METHOD) {
1928 mInputMethodWindow = win;
1929 addInputMethodWindowToListLocked(win);
1930 imMayMove = false;
1931 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1932 mInputMethodDialogs.add(win);
1933 addWindowToListInOrderLocked(win, true);
1934 adjustInputMethodDialogsLocked();
1935 imMayMove = false;
1936 } else {
1937 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001938 if (attrs.type == TYPE_WALLPAPER) {
1939 mLastWallpaperTimeoutTime = 0;
1940 adjustWallpaperWindowsLocked();
1941 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001942 adjustWallpaperWindowsLocked();
1943 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 }
Romain Guy06882f82009-06-10 13:36:04 -07001945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 if (mInTouchMode) {
1951 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1952 }
1953 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1954 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1955 }
Romain Guy06882f82009-06-10 13:36:04 -07001956
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001957 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001959 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1960 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 imMayMove = false;
1962 }
1963 }
Romain Guy06882f82009-06-10 13:36:04 -07001964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001966 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 }
Romain Guy06882f82009-06-10 13:36:04 -07001968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 assignLayersLocked();
1970 // Don't do layout here, the window must call
1971 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 //dump();
1974
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001975 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001976 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001977 }
Jeff Brown349703e2010-06-22 01:27:15 -07001978
Joe Onorato8a9b2202010-02-26 18:56:32 -08001979 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 TAG, "New client " + client.asBinder()
1981 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001982
1983 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1984 reportNewConfig = true;
1985 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 }
1987
1988 // sendNewConfiguration() checks caller permissions so we must call it with
1989 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1990 // identity anyway, so it's safe to just clear & restore around this whole
1991 // block.
1992 final long origId = Binder.clearCallingIdentity();
1993 if (reportNewConfig) {
1994 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 }
1996 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 return res;
1999 }
Romain Guy06882f82009-06-10 13:36:04 -07002000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 public void removeWindow(Session session, IWindow client) {
2002 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002003 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 if (win == null) {
2005 return;
2006 }
2007 removeWindowLocked(session, win);
2008 }
2009 }
Romain Guy06882f82009-06-10 13:36:04 -07002010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 public void removeWindowLocked(Session session, WindowState win) {
2012
Joe Onorato8a9b2202010-02-26 18:56:32 -08002013 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 TAG, "Remove " + win + " client="
2015 + Integer.toHexString(System.identityHashCode(
2016 win.mClient.asBinder()))
2017 + ", surface=" + win.mSurface);
2018
2019 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002020
2021 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002022
Joe Onorato8a9b2202010-02-26 18:56:32 -08002023 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2025 + " mExiting=" + win.mExiting
2026 + " isAnimating=" + win.isAnimating()
2027 + " app-animation="
2028 + (win.mAppToken != null ? win.mAppToken.animation : null)
2029 + " inPendingTransaction="
2030 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2031 + " mDisplayFrozen=" + mDisplayFrozen);
2032 // Visibility of the removed window. Will be used later to update orientation later on.
2033 boolean wasVisible = false;
2034 // First, see if we need to run an animation. If we do, we have
2035 // to hold off on removing the window until the animation is done.
2036 // If the display is frozen, just remove immediately, since the
2037 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002038 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 // If we are not currently running the exit animation, we
2040 // need to see about starting one.
2041 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2044 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2045 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2046 }
2047 // Try starting an animation.
2048 if (applyAnimationLocked(win, transit, false)) {
2049 win.mExiting = true;
2050 }
2051 }
2052 if (win.mExiting || win.isAnimating()) {
2053 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002055 win.mExiting = true;
2056 win.mRemoveOnExit = true;
2057 mLayoutNeeded = true;
2058 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2059 performLayoutAndPlaceSurfacesLocked();
2060 if (win.mAppToken != null) {
2061 win.mAppToken.updateReportedVisibilityLocked();
2062 }
2063 //dump();
2064 Binder.restoreCallingIdentity(origId);
2065 return;
2066 }
2067 }
2068
2069 removeWindowInnerLocked(session, win);
2070 // Removing a visible window will effect the computed orientation
2071 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002072 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002073 != mForcedAppOrientation
2074 && updateOrientationFromAppTokensLocked()) {
2075 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 }
2077 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2078 Binder.restoreCallingIdentity(origId);
2079 }
Romain Guy06882f82009-06-10 13:36:04 -07002080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 if (mInputMethodTarget == win) {
2085 moveInputMethodWindowsIfNeededLocked(false);
2086 }
Romain Guy06882f82009-06-10 13:36:04 -07002087
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002088 if (false) {
2089 RuntimeException e = new RuntimeException("here");
2090 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002091 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 mPolicy.removeWindowLw(win);
2095 win.removeLocked();
2096
2097 mWindowMap.remove(win.mClient.asBinder());
2098 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002099 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002100 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101
2102 if (mInputMethodWindow == win) {
2103 mInputMethodWindow = null;
2104 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2105 mInputMethodDialogs.remove(win);
2106 }
Romain Guy06882f82009-06-10 13:36:04 -07002107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108 final WindowToken token = win.mToken;
2109 final AppWindowToken atoken = win.mAppToken;
2110 token.windows.remove(win);
2111 if (atoken != null) {
2112 atoken.allAppWindows.remove(win);
2113 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002114 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 TAG, "**** Removing window " + win + ": count="
2116 + token.windows.size());
2117 if (token.windows.size() == 0) {
2118 if (!token.explicit) {
2119 mTokenMap.remove(token.token);
2120 mTokenList.remove(token);
2121 } else if (atoken != null) {
2122 atoken.firstWindowDrawn = false;
2123 }
2124 }
2125
2126 if (atoken != null) {
2127 if (atoken.startingWindow == win) {
2128 atoken.startingWindow = null;
2129 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2130 // If this is the last window and we had requested a starting
2131 // transition window, well there is no point now.
2132 atoken.startingData = null;
2133 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2134 // If this is the last window except for a starting transition
2135 // window, we need to get rid of the starting transition.
2136 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002137 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 + ": no more real windows");
2139 }
2140 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2141 mH.sendMessage(m);
2142 }
2143 }
Romain Guy06882f82009-06-10 13:36:04 -07002144
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002145 if (win.mAttrs.type == TYPE_WALLPAPER) {
2146 mLastWallpaperTimeoutTime = 0;
2147 adjustWallpaperWindowsLocked();
2148 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002149 adjustWallpaperWindowsLocked();
2150 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 if (!mInLayout) {
2153 assignLayersLocked();
2154 mLayoutNeeded = true;
2155 performLayoutAndPlaceSurfacesLocked();
2156 if (win.mAppToken != null) {
2157 win.mAppToken.updateReportedVisibilityLocked();
2158 }
2159 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002160
2161 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 }
2163
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002164 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2165 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2166 + ": " + msg + " / " + w.mAttrs.getTitle();
2167 if (where != null) {
2168 Slog.i(TAG, str, where);
2169 } else {
2170 Slog.i(TAG, str);
2171 }
2172 }
2173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2175 long origId = Binder.clearCallingIdentity();
2176 try {
2177 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002178 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002180 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 Surface.openTransaction();
2182 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002183 if (SHOW_TRANSACTIONS) logSurface(w,
2184 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 w.mSurface.setTransparentRegionHint(region);
2186 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002187 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 Surface.closeTransaction();
2189 }
2190 }
2191 }
2192 } finally {
2193 Binder.restoreCallingIdentity(origId);
2194 }
2195 }
2196
2197 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002198 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 Rect visibleInsets) {
2200 long origId = Binder.clearCallingIdentity();
2201 try {
2202 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002203 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 if (w != null) {
2205 w.mGivenInsetsPending = false;
2206 w.mGivenContentInsets.set(contentInsets);
2207 w.mGivenVisibleInsets.set(visibleInsets);
2208 w.mTouchableInsets = touchableInsets;
2209 mLayoutNeeded = true;
2210 performLayoutAndPlaceSurfacesLocked();
2211 }
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(origId);
2215 }
2216 }
Romain Guy06882f82009-06-10 13:36:04 -07002217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 public void getWindowDisplayFrame(Session session, IWindow client,
2219 Rect outDisplayFrame) {
2220 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002221 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 if (win == null) {
2223 outDisplayFrame.setEmpty();
2224 return;
2225 }
2226 outDisplayFrame.set(win.mDisplayFrame);
2227 }
2228 }
2229
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002230 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2231 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002232 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2233 window.mWallpaperX = x;
2234 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002235 window.mWallpaperXStep = xStep;
2236 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002237 if (updateWallpaperOffsetLocked(window, true)) {
2238 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002239 }
2240 }
2241 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002242
Dianne Hackborn75804932009-10-20 20:15:20 -07002243 void wallpaperCommandComplete(IBinder window, Bundle result) {
2244 synchronized (mWindowMap) {
2245 if (mWaitingOnWallpaper != null &&
2246 mWaitingOnWallpaper.mClient.asBinder() == window) {
2247 mWaitingOnWallpaper = null;
2248 mWindowMap.notifyAll();
2249 }
2250 }
2251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002252
Dianne Hackborn75804932009-10-20 20:15:20 -07002253 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2254 String action, int x, int y, int z, Bundle extras, boolean sync) {
2255 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2256 || window == mUpperWallpaperTarget) {
2257 boolean doWait = sync;
2258 int curTokenIndex = mWallpaperTokens.size();
2259 while (curTokenIndex > 0) {
2260 curTokenIndex--;
2261 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2262 int curWallpaperIndex = token.windows.size();
2263 while (curWallpaperIndex > 0) {
2264 curWallpaperIndex--;
2265 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2266 try {
2267 wallpaper.mClient.dispatchWallpaperCommand(action,
2268 x, y, z, extras, sync);
2269 // We only want to be synchronous with one wallpaper.
2270 sync = false;
2271 } catch (RemoteException e) {
2272 }
2273 }
2274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002275
Dianne Hackborn75804932009-10-20 20:15:20 -07002276 if (doWait) {
2277 // XXX Need to wait for result.
2278 }
2279 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002280
Dianne Hackborn75804932009-10-20 20:15:20 -07002281 return null;
2282 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 public int relayoutWindow(Session session, IWindow client,
2285 WindowManager.LayoutParams attrs, int requestedWidth,
2286 int requestedHeight, int viewVisibility, boolean insetsPending,
2287 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002288 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 boolean displayed = false;
2290 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002291 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002295 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 if (win == null) {
2297 return 0;
2298 }
2299 win.mRequestedWidth = requestedWidth;
2300 win.mRequestedHeight = requestedHeight;
2301
2302 if (attrs != null) {
2303 mPolicy.adjustWindowParamsLw(attrs);
2304 }
Romain Guy06882f82009-06-10 13:36:04 -07002305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 int attrChanges = 0;
2307 int flagChanges = 0;
2308 if (attrs != null) {
2309 flagChanges = win.mAttrs.flags ^= attrs.flags;
2310 attrChanges = win.mAttrs.copyFrom(attrs);
2311 }
2312
Joe Onorato8a9b2202010-02-26 18:56:32 -08002313 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314
2315 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2316 win.mAlpha = attrs.alpha;
2317 }
2318
2319 final boolean scaledWindow =
2320 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2321
2322 if (scaledWindow) {
2323 // requested{Width|Height} Surface's physical size
2324 // attrs.{width|height} Size on screen
2325 win.mHScale = (attrs.width != requestedWidth) ?
2326 (attrs.width / (float)requestedWidth) : 1.0f;
2327 win.mVScale = (attrs.height != requestedHeight) ?
2328 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002329 } else {
2330 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 }
2332
2333 boolean imMayMove = (flagChanges&(
2334 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2335 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 boolean focusMayChange = win.mViewVisibility != viewVisibility
2338 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2339 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002340
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002341 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2342 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 win.mRelayoutCalled = true;
2345 final int oldVisibility = win.mViewVisibility;
2346 win.mViewVisibility = viewVisibility;
2347 if (viewVisibility == View.VISIBLE &&
2348 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2349 displayed = !win.isVisibleLw();
2350 if (win.mExiting) {
2351 win.mExiting = false;
2352 win.mAnimation = null;
2353 }
2354 if (win.mDestroying) {
2355 win.mDestroying = false;
2356 mDestroySurface.remove(win);
2357 }
2358 if (oldVisibility == View.GONE) {
2359 win.mEnterAnimationPending = true;
2360 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002361 if (displayed) {
2362 if (win.mSurface != null && !win.mDrawPending
2363 && !win.mCommitDrawPending && !mDisplayFrozen
2364 && mPolicy.isScreenOn()) {
2365 applyEnterAnimationLocked(win);
2366 }
2367 if ((win.mAttrs.flags
2368 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2369 if (DEBUG_VISIBILITY) Slog.v(TAG,
2370 "Relayout window turning screen on: " + win);
2371 win.mTurnOnScreen = true;
2372 }
2373 int diff = 0;
2374 if (win.mConfiguration != mCurConfiguration
2375 && (win.mConfiguration == null
2376 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2377 win.mConfiguration = mCurConfiguration;
2378 if (DEBUG_CONFIGURATION) {
2379 Slog.i(TAG, "Window " + win + " visible with new config: "
2380 + win.mConfiguration + " / 0x"
2381 + Integer.toHexString(diff));
2382 }
2383 outConfig.setTo(mCurConfiguration);
2384 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2387 // To change the format, we need to re-build the surface.
2388 win.destroySurfaceLocked();
2389 displayed = true;
2390 }
2391 try {
2392 Surface surface = win.createSurfaceLocked();
2393 if (surface != null) {
2394 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002395 win.mReportDestroySurface = false;
2396 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002397 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002398 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002400 // For some reason there isn't a surface. Clear the
2401 // caller's object so they see the same state.
2402 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 }
2404 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002405 mInputMonitor.updateInputWindowsLw();
2406
Joe Onorato8a9b2202010-02-26 18:56:32 -08002407 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002408 + client + " (" + win.mAttrs.getTitle() + ")",
2409 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 Binder.restoreCallingIdentity(origId);
2411 return 0;
2412 }
2413 if (displayed) {
2414 focusMayChange = true;
2415 }
2416 if (win.mAttrs.type == TYPE_INPUT_METHOD
2417 && mInputMethodWindow == null) {
2418 mInputMethodWindow = win;
2419 imMayMove = true;
2420 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002421 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2422 && win.mAppToken != null
2423 && win.mAppToken.startingWindow != null) {
2424 // Special handling of starting window over the base
2425 // window of the app: propagate lock screen flags to it,
2426 // to provide the correct semantics while starting.
2427 final int mask =
2428 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002429 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2430 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002431 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2432 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002434 } else {
2435 win.mEnterAnimationPending = false;
2436 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002437 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002438 + ": mExiting=" + win.mExiting
2439 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 // If we are not currently running the exit animation, we
2441 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002442 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 // Try starting an animation; if there isn't one, we
2444 // can destroy the surface right away.
2445 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2446 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2447 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2448 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002449 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002451 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 win.mExiting = true;
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;
Jeff Browne33348b2010-07-15 23:54:05 -07002547
2548 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 }
2550
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002551 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 sendNewConfiguration();
2553 }
Romain Guy06882f82009-06-10 13:36:04 -07002554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2558 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2559 }
2560
2561 public void finishDrawingWindow(Session session, IWindow client) {
2562 final long origId = Binder.clearCallingIdentity();
2563 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002564 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002566 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2567 adjustWallpaperWindowsLocked();
2568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 mLayoutNeeded = true;
2570 performLayoutAndPlaceSurfacesLocked();
2571 }
2572 }
2573 Binder.restoreCallingIdentity(origId);
2574 }
2575
2576 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002577 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 + (lp != null ? lp.packageName : null)
2579 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2580 if (lp != null && lp.windowAnimations != 0) {
2581 // If this is a system resource, don't try to load it from the
2582 // application resources. It is nice to avoid loading application
2583 // resources if we can.
2584 String packageName = lp.packageName != null ? lp.packageName : "android";
2585 int resId = lp.windowAnimations;
2586 if ((resId&0xFF000000) == 0x01000000) {
2587 packageName = "android";
2588 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002589 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002590 + packageName);
2591 return AttributeCache.instance().get(packageName, resId,
2592 com.android.internal.R.styleable.WindowAnimation);
2593 }
2594 return null;
2595 }
Romain Guy06882f82009-06-10 13:36:04 -07002596
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002597 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002598 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002599 + packageName + " resId=0x" + Integer.toHexString(resId));
2600 if (packageName != null) {
2601 if ((resId&0xFF000000) == 0x01000000) {
2602 packageName = "android";
2603 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002604 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002605 + packageName);
2606 return AttributeCache.instance().get(packageName, resId,
2607 com.android.internal.R.styleable.WindowAnimation);
2608 }
2609 return null;
2610 }
2611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 private void applyEnterAnimationLocked(WindowState win) {
2613 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2614 if (win.mEnterAnimationPending) {
2615 win.mEnterAnimationPending = false;
2616 transit = WindowManagerPolicy.TRANSIT_ENTER;
2617 }
2618
2619 applyAnimationLocked(win, transit, true);
2620 }
2621
2622 private boolean applyAnimationLocked(WindowState win,
2623 int transit, boolean isEntrance) {
2624 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2625 // If we are trying to apply an animation, but already running
2626 // an animation of the same type, then just leave that one alone.
2627 return true;
2628 }
Romain Guy06882f82009-06-10 13:36:04 -07002629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 // Only apply an animation if the display isn't frozen. If it is
2631 // frozen, there is no reason to animate and it can cause strange
2632 // artifacts when we unfreeze the display if some different animation
2633 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002634 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 int anim = mPolicy.selectAnimationLw(win, transit);
2636 int attr = -1;
2637 Animation a = null;
2638 if (anim != 0) {
2639 a = AnimationUtils.loadAnimation(mContext, anim);
2640 } else {
2641 switch (transit) {
2642 case WindowManagerPolicy.TRANSIT_ENTER:
2643 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2644 break;
2645 case WindowManagerPolicy.TRANSIT_EXIT:
2646 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2647 break;
2648 case WindowManagerPolicy.TRANSIT_SHOW:
2649 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2650 break;
2651 case WindowManagerPolicy.TRANSIT_HIDE:
2652 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2653 break;
2654 }
2655 if (attr >= 0) {
2656 a = loadAnimation(win.mAttrs, attr);
2657 }
2658 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002659 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2661 + " mAnimation=" + win.mAnimation
2662 + " isEntrance=" + isEntrance);
2663 if (a != null) {
2664 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002665 RuntimeException e = null;
2666 if (!HIDE_STACK_CRAWLS) {
2667 e = new RuntimeException();
2668 e.fillInStackTrace();
2669 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002670 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 }
2672 win.setAnimation(a);
2673 win.mAnimationIsEntrance = isEntrance;
2674 }
2675 } else {
2676 win.clearAnimation();
2677 }
2678
2679 return win.mAnimation != null;
2680 }
2681
2682 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2683 int anim = 0;
2684 Context context = mContext;
2685 if (animAttr >= 0) {
2686 AttributeCache.Entry ent = getCachedAnimations(lp);
2687 if (ent != null) {
2688 context = ent.context;
2689 anim = ent.array.getResourceId(animAttr, 0);
2690 }
2691 }
2692 if (anim != 0) {
2693 return AnimationUtils.loadAnimation(context, anim);
2694 }
2695 return null;
2696 }
Romain Guy06882f82009-06-10 13:36:04 -07002697
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002698 private Animation loadAnimation(String packageName, int resId) {
2699 int anim = 0;
2700 Context context = mContext;
2701 if (resId >= 0) {
2702 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2703 if (ent != null) {
2704 context = ent.context;
2705 anim = resId;
2706 }
2707 }
2708 if (anim != 0) {
2709 return AnimationUtils.loadAnimation(context, anim);
2710 }
2711 return null;
2712 }
2713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 private boolean applyAnimationLocked(AppWindowToken wtoken,
2715 WindowManager.LayoutParams lp, int transit, boolean enter) {
2716 // Only apply an animation if the display isn't frozen. If it is
2717 // frozen, there is no reason to animate and it can cause strange
2718 // artifacts when we unfreeze the display if some different animation
2719 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002720 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002721 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002722 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002723 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002724 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002725 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002726 } else if (mNextAppTransitionPackage != null) {
2727 a = loadAnimation(mNextAppTransitionPackage, enter ?
2728 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002729 } else {
2730 int animAttr = 0;
2731 switch (transit) {
2732 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2733 animAttr = enter
2734 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2735 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2736 break;
2737 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2738 animAttr = enter
2739 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2740 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2741 break;
2742 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2743 animAttr = enter
2744 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2745 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2746 break;
2747 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2748 animAttr = enter
2749 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2750 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2751 break;
2752 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2753 animAttr = enter
2754 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2755 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2756 break;
2757 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2758 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002759 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002760 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2761 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002762 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002763 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002764 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2765 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002766 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002767 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002768 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002769 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2770 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2771 break;
2772 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2773 animAttr = enter
2774 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2775 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2776 break;
2777 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2778 animAttr = enter
2779 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2780 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002781 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002782 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002783 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002784 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002785 + " anim=" + a
2786 + " animAttr=0x" + Integer.toHexString(animAttr)
2787 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 if (a != null) {
2790 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002791 RuntimeException e = null;
2792 if (!HIDE_STACK_CRAWLS) {
2793 e = new RuntimeException();
2794 e.fillInStackTrace();
2795 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002796 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 }
2798 wtoken.setAnimation(a);
2799 }
2800 } else {
2801 wtoken.clearAnimation();
2802 }
2803
2804 return wtoken.animation != null;
2805 }
2806
2807 // -------------------------------------------------------------
2808 // Application Window Tokens
2809 // -------------------------------------------------------------
2810
2811 public void validateAppTokens(List tokens) {
2812 int v = tokens.size()-1;
2813 int m = mAppTokens.size()-1;
2814 while (v >= 0 && m >= 0) {
2815 AppWindowToken wtoken = mAppTokens.get(m);
2816 if (wtoken.removed) {
2817 m--;
2818 continue;
2819 }
2820 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002821 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2823 }
2824 v--;
2825 m--;
2826 }
2827 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002828 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 v--;
2830 }
2831 while (m >= 0) {
2832 AppWindowToken wtoken = mAppTokens.get(m);
2833 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002834 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 }
2836 m--;
2837 }
2838 }
2839
2840 boolean checkCallingPermission(String permission, String func) {
2841 // Quick check: if the calling permission is me, it's all okay.
2842 if (Binder.getCallingPid() == Process.myPid()) {
2843 return true;
2844 }
Romain Guy06882f82009-06-10 13:36:04 -07002845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 if (mContext.checkCallingPermission(permission)
2847 == PackageManager.PERMISSION_GRANTED) {
2848 return true;
2849 }
2850 String msg = "Permission Denial: " + func + " from pid="
2851 + Binder.getCallingPid()
2852 + ", uid=" + Binder.getCallingUid()
2853 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002854 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 return false;
2856 }
Romain Guy06882f82009-06-10 13:36:04 -07002857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 AppWindowToken findAppWindowToken(IBinder token) {
2859 WindowToken wtoken = mTokenMap.get(token);
2860 if (wtoken == null) {
2861 return null;
2862 }
2863 return wtoken.appWindowToken;
2864 }
Romain Guy06882f82009-06-10 13:36:04 -07002865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 public void addWindowToken(IBinder token, int type) {
2867 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2868 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002869 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 }
Romain Guy06882f82009-06-10 13:36:04 -07002871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 synchronized(mWindowMap) {
2873 WindowToken wtoken = mTokenMap.get(token);
2874 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002875 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 return;
2877 }
2878 wtoken = new WindowToken(token, type, true);
2879 mTokenMap.put(token, wtoken);
2880 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002881 if (type == TYPE_WALLPAPER) {
2882 mWallpaperTokens.add(wtoken);
2883 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 }
2885 }
Romain Guy06882f82009-06-10 13:36:04 -07002886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 public void removeWindowToken(IBinder token) {
2888 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2889 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002890 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 }
2892
2893 final long origId = Binder.clearCallingIdentity();
2894 synchronized(mWindowMap) {
2895 WindowToken wtoken = mTokenMap.remove(token);
2896 mTokenList.remove(wtoken);
2897 if (wtoken != null) {
2898 boolean delayed = false;
2899 if (!wtoken.hidden) {
2900 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 final int N = wtoken.windows.size();
2903 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 for (int i=0; i<N; i++) {
2906 WindowState win = wtoken.windows.get(i);
2907
2908 if (win.isAnimating()) {
2909 delayed = true;
2910 }
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 if (win.isVisibleNow()) {
2913 applyAnimationLocked(win,
2914 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 changed = true;
2916 }
2917 }
2918
2919 if (changed) {
2920 mLayoutNeeded = true;
2921 performLayoutAndPlaceSurfacesLocked();
2922 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2923 }
Romain Guy06882f82009-06-10 13:36:04 -07002924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 if (delayed) {
2926 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002927 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2928 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 }
2930 }
Romain Guy06882f82009-06-10 13:36:04 -07002931
Jeff Brownc5ed5912010-07-14 18:48:53 -07002932 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002934 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 }
2936 }
2937 Binder.restoreCallingIdentity(origId);
2938 }
2939
2940 public void addAppToken(int addPos, IApplicationToken token,
2941 int groupId, int requestedOrientation, boolean fullscreen) {
2942 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2943 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002944 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 }
Jeff Brown349703e2010-06-22 01:27:15 -07002946
2947 // Get the dispatching timeout here while we are not holding any locks so that it
2948 // can be cached by the AppWindowToken. The timeout value is used later by the
2949 // input dispatcher in code that does hold locks. If we did not cache the value
2950 // here we would run the chance of introducing a deadlock between the window manager
2951 // (which holds locks while updating the input dispatcher state) and the activity manager
2952 // (which holds locks while querying the application token).
2953 long inputDispatchingTimeoutNanos;
2954 try {
2955 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2956 } catch (RemoteException ex) {
2957 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2958 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2959 }
Romain Guy06882f82009-06-10 13:36:04 -07002960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 synchronized(mWindowMap) {
2962 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2963 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002964 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 return;
2966 }
2967 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002968 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 wtoken.groupId = groupId;
2970 wtoken.appFullscreen = fullscreen;
2971 wtoken.requestedOrientation = requestedOrientation;
2972 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002973 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 mTokenMap.put(token.asBinder(), wtoken);
2975 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 // Application tokens start out hidden.
2978 wtoken.hidden = true;
2979 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 //dump();
2982 }
2983 }
Romain Guy06882f82009-06-10 13:36:04 -07002984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 public void setAppGroupId(IBinder token, int groupId) {
2986 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2987 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002988 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002989 }
2990
2991 synchronized(mWindowMap) {
2992 AppWindowToken wtoken = findAppWindowToken(token);
2993 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002994 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 return;
2996 }
2997 wtoken.groupId = groupId;
2998 }
2999 }
Romain Guy06882f82009-06-10 13:36:04 -07003000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 public int getOrientationFromWindowsLocked() {
3002 int pos = mWindows.size() - 1;
3003 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003004 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 pos--;
3006 if (wtoken.mAppToken != null) {
3007 // We hit an application window. so the orientation will be determined by the
3008 // app window. No point in continuing further.
3009 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3010 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003011 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 continue;
3013 }
3014 int req = wtoken.mAttrs.screenOrientation;
3015 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3016 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3017 continue;
3018 } else {
3019 return req;
3020 }
3021 }
3022 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3023 }
Romain Guy06882f82009-06-10 13:36:04 -07003024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003025 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003026 int pos = mAppTokens.size() - 1;
3027 int curGroup = 0;
3028 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3029 boolean findingBehind = false;
3030 boolean haveGroup = false;
3031 boolean lastFullscreen = false;
3032 while (pos >= 0) {
3033 AppWindowToken wtoken = mAppTokens.get(pos);
3034 pos--;
3035 // if we're about to tear down this window and not seek for
3036 // the behind activity, don't use it for orientation
3037 if (!findingBehind
3038 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3039 continue;
3040 }
3041
3042 if (!haveGroup) {
3043 // We ignore any hidden applications on the top.
3044 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003045 continue;
3046 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003047 haveGroup = true;
3048 curGroup = wtoken.groupId;
3049 lastOrientation = wtoken.requestedOrientation;
3050 } else if (curGroup != wtoken.groupId) {
3051 // If we have hit a new application group, and the bottom
3052 // of the previous group didn't explicitly say to use
3053 // the orientation behind it, and the last app was
3054 // full screen, then we'll stick with the
3055 // user's orientation.
3056 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3057 && lastFullscreen) {
3058 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003061 int or = wtoken.requestedOrientation;
3062 // If this application is fullscreen, and didn't explicitly say
3063 // to use the orientation behind it, then just take whatever
3064 // orientation it has and ignores whatever is under it.
3065 lastFullscreen = wtoken.appFullscreen;
3066 if (lastFullscreen
3067 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3068 return or;
3069 }
3070 // If this application has requested an explicit orientation,
3071 // then use it.
3072 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3073 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3074 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3075 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3076 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3077 return or;
3078 }
3079 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3080 }
3081 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 }
Romain Guy06882f82009-06-10 13:36:04 -07003083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003085 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003086 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3087 "updateOrientationFromAppTokens()")) {
3088 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3089 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003090
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003091 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003092 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003093
3094 synchronized(mWindowMap) {
3095 if (updateOrientationFromAppTokensLocked()) {
3096 if (freezeThisOneIfNeeded != null) {
3097 AppWindowToken wtoken = findAppWindowToken(
3098 freezeThisOneIfNeeded);
3099 if (wtoken != null) {
3100 startAppFreezingScreenLocked(wtoken,
3101 ActivityInfo.CONFIG_ORIENTATION);
3102 }
3103 }
3104 config = computeNewConfigurationLocked();
3105
3106 } else if (currentConfig != null) {
3107 // No obvious action we need to take, but if our current
3108 // state mismatches the activity maanager's, update it
3109 mTempConfiguration.setToDefaults();
3110 if (computeNewConfigurationLocked(mTempConfiguration)) {
3111 if (currentConfig.diff(mTempConfiguration) != 0) {
3112 mWaitingForConfig = true;
3113 mLayoutNeeded = true;
3114 startFreezingDisplayLocked();
3115 config = new Configuration(mTempConfiguration);
3116 }
3117 }
3118 }
3119 }
3120
Dianne Hackborncfaef692009-06-15 14:24:44 -07003121 Binder.restoreCallingIdentity(ident);
3122 return config;
3123 }
3124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003126 * Determine the new desired orientation of the display, returning
3127 * a non-null new Configuration if it has changed from the current
3128 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3129 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3130 * SCREEN. This will typically be done for you if you call
3131 * sendNewConfiguration().
3132 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 * The orientation is computed from non-application windows first. If none of
3134 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003135 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3137 * android.os.IBinder)
3138 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003139 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003140 if (mDisplayFrozen) {
3141 // If the display is frozen, some activities may be in the middle
3142 // of restarting, and thus have removed their old window. If the
3143 // window has the flag to hide the lock screen, then the lock screen
3144 // can re-appear and inflict its own orientation on us. Keep the
3145 // orientation stable until this all settles down.
3146 return false;
3147 }
3148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 long ident = Binder.clearCallingIdentity();
3151 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003152 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003154 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 mForcedAppOrientation = req;
3156 //send a message to Policy indicating orientation change to take
3157 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003158 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003159 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3160 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3161 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 }
3163 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003164
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003165 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 } finally {
3167 Binder.restoreCallingIdentity(ident);
3168 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 }
Romain Guy06882f82009-06-10 13:36:04 -07003170
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003171 int computeForcedAppOrientationLocked() {
3172 int req = getOrientationFromWindowsLocked();
3173 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3174 req = getOrientationFromAppTokensLocked();
3175 }
3176 return req;
3177 }
Romain Guy06882f82009-06-10 13:36:04 -07003178
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003179 public void setNewConfiguration(Configuration config) {
3180 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3181 "setNewConfiguration()")) {
3182 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3183 }
3184
3185 synchronized(mWindowMap) {
3186 mCurConfiguration = new Configuration(config);
3187 mWaitingForConfig = false;
3188 performLayoutAndPlaceSurfacesLocked();
3189 }
3190 }
3191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3193 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3194 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003195 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 synchronized(mWindowMap) {
3199 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3200 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003201 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 return;
3203 }
Romain Guy06882f82009-06-10 13:36:04 -07003204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 wtoken.requestedOrientation = requestedOrientation;
3206 }
3207 }
Romain Guy06882f82009-06-10 13:36:04 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 public int getAppOrientation(IApplicationToken token) {
3210 synchronized(mWindowMap) {
3211 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3212 if (wtoken == null) {
3213 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3214 }
Romain Guy06882f82009-06-10 13:36:04 -07003215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216 return wtoken.requestedOrientation;
3217 }
3218 }
Romain Guy06882f82009-06-10 13:36:04 -07003219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3221 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3222 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003223 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 }
3225
3226 synchronized(mWindowMap) {
3227 boolean changed = false;
3228 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003229 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 changed = mFocusedApp != null;
3231 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003232 if (changed) {
3233 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 } else {
3236 AppWindowToken newFocus = findAppWindowToken(token);
3237 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003238 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 return;
3240 }
3241 changed = mFocusedApp != newFocus;
3242 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003243 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003244 if (changed) {
3245 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003246 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247 }
3248
3249 if (moveFocusNow && changed) {
3250 final long origId = Binder.clearCallingIdentity();
3251 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3252 Binder.restoreCallingIdentity(origId);
3253 }
3254 }
3255 }
3256
3257 public void prepareAppTransition(int transit) {
3258 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3259 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003260 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 }
Romain Guy06882f82009-06-10 13:36:04 -07003262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003264 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 TAG, "Prepare app transition: transit=" + transit
3266 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003267 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003268 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3269 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003271 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3272 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3273 // Opening a new task always supersedes a close for the anim.
3274 mNextAppTransition = transit;
3275 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3276 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3277 // Opening a new activity always supersedes a close for the anim.
3278 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 }
3280 mAppTransitionReady = false;
3281 mAppTransitionTimeout = false;
3282 mStartingIconInTransition = false;
3283 mSkipAppTransitionAnimation = false;
3284 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3285 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3286 5000);
3287 }
3288 }
3289 }
3290
3291 public int getPendingAppTransition() {
3292 return mNextAppTransition;
3293 }
Romain Guy06882f82009-06-10 13:36:04 -07003294
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003295 public void overridePendingAppTransition(String packageName,
3296 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003297 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003298 mNextAppTransitionPackage = packageName;
3299 mNextAppTransitionEnter = enterAnim;
3300 mNextAppTransitionExit = exitAnim;
3301 }
3302 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 public void executeAppTransition() {
3305 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3306 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003307 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 }
Romain Guy06882f82009-06-10 13:36:04 -07003309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003311 if (DEBUG_APP_TRANSITIONS) {
3312 RuntimeException e = new RuntimeException("here");
3313 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003314 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003315 + mNextAppTransition, e);
3316 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003317 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 mAppTransitionReady = true;
3319 final long origId = Binder.clearCallingIdentity();
3320 performLayoutAndPlaceSurfacesLocked();
3321 Binder.restoreCallingIdentity(origId);
3322 }
3323 }
3324 }
3325
3326 public void setAppStartingWindow(IBinder token, String pkg,
3327 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3328 IBinder transferFrom, boolean createIfNeeded) {
3329 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3330 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003331 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 }
3333
3334 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003335 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3337 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 AppWindowToken wtoken = findAppWindowToken(token);
3340 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003341 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 return;
3343 }
3344
3345 // If the display is frozen, we won't do anything until the
3346 // actual window is displayed so there is no reason to put in
3347 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003348 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 return;
3350 }
Romain Guy06882f82009-06-10 13:36:04 -07003351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 if (wtoken.startingData != null) {
3353 return;
3354 }
Romain Guy06882f82009-06-10 13:36:04 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 if (transferFrom != null) {
3357 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3358 if (ttoken != null) {
3359 WindowState startingWindow = ttoken.startingWindow;
3360 if (startingWindow != null) {
3361 if (mStartingIconInTransition) {
3362 // In this case, the starting icon has already
3363 // been displayed, so start letting windows get
3364 // shown immediately without any more transitions.
3365 mSkipAppTransitionAnimation = true;
3366 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003367 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 "Moving existing starting from " + ttoken
3369 + " to " + wtoken);
3370 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 // Transfer the starting window over to the new
3373 // token.
3374 wtoken.startingData = ttoken.startingData;
3375 wtoken.startingView = ttoken.startingView;
3376 wtoken.startingWindow = startingWindow;
3377 ttoken.startingData = null;
3378 ttoken.startingView = null;
3379 ttoken.startingWindow = null;
3380 ttoken.startingMoved = true;
3381 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003382 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003384 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003385 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003387 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003388 ttoken.windows.remove(startingWindow);
3389 ttoken.allAppWindows.remove(startingWindow);
3390 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 // Propagate other interesting state between the
3393 // tokens. If the old token is displayed, we should
3394 // immediately force the new one to be displayed. If
3395 // it is animating, we need to move that animation to
3396 // the new one.
3397 if (ttoken.allDrawn) {
3398 wtoken.allDrawn = true;
3399 }
3400 if (ttoken.firstWindowDrawn) {
3401 wtoken.firstWindowDrawn = true;
3402 }
3403 if (!ttoken.hidden) {
3404 wtoken.hidden = false;
3405 wtoken.hiddenRequested = false;
3406 wtoken.willBeHidden = false;
3407 }
3408 if (wtoken.clientHidden != ttoken.clientHidden) {
3409 wtoken.clientHidden = ttoken.clientHidden;
3410 wtoken.sendAppVisibilityToClients();
3411 }
3412 if (ttoken.animation != null) {
3413 wtoken.animation = ttoken.animation;
3414 wtoken.animating = ttoken.animating;
3415 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3416 ttoken.animation = null;
3417 ttoken.animLayerAdjustment = 0;
3418 wtoken.updateLayers();
3419 ttoken.updateLayers();
3420 }
Romain Guy06882f82009-06-10 13:36:04 -07003421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003423 mLayoutNeeded = true;
3424 performLayoutAndPlaceSurfacesLocked();
3425 Binder.restoreCallingIdentity(origId);
3426 return;
3427 } else if (ttoken.startingData != null) {
3428 // The previous app was getting ready to show a
3429 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003430 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 "Moving pending starting from " + ttoken
3432 + " to " + wtoken);
3433 wtoken.startingData = ttoken.startingData;
3434 ttoken.startingData = null;
3435 ttoken.startingMoved = true;
3436 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3437 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3438 // want to process the message ASAP, before any other queued
3439 // messages.
3440 mH.sendMessageAtFrontOfQueue(m);
3441 return;
3442 }
3443 }
3444 }
3445
3446 // There is no existing starting window, and the caller doesn't
3447 // want us to create one, so that's it!
3448 if (!createIfNeeded) {
3449 return;
3450 }
Romain Guy06882f82009-06-10 13:36:04 -07003451
Dianne Hackborn284ac932009-08-28 10:34:25 -07003452 // If this is a translucent or wallpaper window, then don't
3453 // show a starting window -- the current effect (a full-screen
3454 // opaque starting window that fades away to the real contents
3455 // when it is ready) does not work for this.
3456 if (theme != 0) {
3457 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3458 com.android.internal.R.styleable.Window);
3459 if (ent.array.getBoolean(
3460 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3461 return;
3462 }
3463 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003464 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3465 return;
3466 }
3467 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003468 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3469 return;
3470 }
3471 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 mStartingIconInTransition = true;
3474 wtoken.startingData = new StartingData(
3475 pkg, theme, nonLocalizedLabel,
3476 labelRes, icon);
3477 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3478 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3479 // want to process the message ASAP, before any other queued
3480 // messages.
3481 mH.sendMessageAtFrontOfQueue(m);
3482 }
3483 }
3484
3485 public void setAppWillBeHidden(IBinder token) {
3486 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3487 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003488 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489 }
3490
3491 AppWindowToken wtoken;
3492
3493 synchronized(mWindowMap) {
3494 wtoken = findAppWindowToken(token);
3495 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003496 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 -08003497 return;
3498 }
3499 wtoken.willBeHidden = true;
3500 }
3501 }
Romain Guy06882f82009-06-10 13:36:04 -07003502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3504 boolean visible, int transit, boolean performLayout) {
3505 boolean delayed = false;
3506
3507 if (wtoken.clientHidden == visible) {
3508 wtoken.clientHidden = !visible;
3509 wtoken.sendAppVisibilityToClients();
3510 }
Romain Guy06882f82009-06-10 13:36:04 -07003511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 wtoken.willBeHidden = false;
3513 if (wtoken.hidden == visible) {
3514 final int N = wtoken.allAppWindows.size();
3515 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003516 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3518 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003521
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003522 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003523 if (wtoken.animation == sDummyAnimation) {
3524 wtoken.animation = null;
3525 }
3526 applyAnimationLocked(wtoken, lp, transit, visible);
3527 changed = true;
3528 if (wtoken.animation != null) {
3529 delayed = runningAppAnimation = true;
3530 }
3531 }
Romain Guy06882f82009-06-10 13:36:04 -07003532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 for (int i=0; i<N; i++) {
3534 WindowState win = wtoken.allAppWindows.get(i);
3535 if (win == wtoken.startingWindow) {
3536 continue;
3537 }
3538
3539 if (win.isAnimating()) {
3540 delayed = true;
3541 }
Romain Guy06882f82009-06-10 13:36:04 -07003542
Joe Onorato8a9b2202010-02-26 18:56:32 -08003543 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 //win.dump(" ");
3545 if (visible) {
3546 if (!win.isVisibleNow()) {
3547 if (!runningAppAnimation) {
3548 applyAnimationLocked(win,
3549 WindowManagerPolicy.TRANSIT_ENTER, true);
3550 }
3551 changed = true;
3552 }
3553 } else if (win.isVisibleNow()) {
3554 if (!runningAppAnimation) {
3555 applyAnimationLocked(win,
3556 WindowManagerPolicy.TRANSIT_EXIT, false);
3557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 changed = true;
3559 }
3560 }
3561
3562 wtoken.hidden = wtoken.hiddenRequested = !visible;
3563 if (!visible) {
3564 unsetAppFreezingScreenLocked(wtoken, true, true);
3565 } else {
3566 // If we are being set visible, and the starting window is
3567 // not yet displayed, then make sure it doesn't get displayed.
3568 WindowState swin = wtoken.startingWindow;
3569 if (swin != null && (swin.mDrawPending
3570 || swin.mCommitDrawPending)) {
3571 swin.mPolicyVisibility = false;
3572 swin.mPolicyVisibilityAfterAnim = false;
3573 }
3574 }
Romain Guy06882f82009-06-10 13:36:04 -07003575
Joe Onorato8a9b2202010-02-26 18:56:32 -08003576 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3578 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003579
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003580 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003582 if (performLayout) {
3583 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3584 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003585 } else {
3586 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003587 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 }
3589 }
3590
3591 if (wtoken.animation != null) {
3592 delayed = true;
3593 }
Romain Guy06882f82009-06-10 13:36:04 -07003594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 return delayed;
3596 }
3597
3598 public void setAppVisibility(IBinder token, boolean visible) {
3599 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3600 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003601 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 }
3603
3604 AppWindowToken wtoken;
3605
3606 synchronized(mWindowMap) {
3607 wtoken = findAppWindowToken(token);
3608 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003609 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 return;
3611 }
3612
3613 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003614 RuntimeException e = null;
3615 if (!HIDE_STACK_CRAWLS) {
3616 e = new RuntimeException();
3617 e.fillInStackTrace();
3618 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003619 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 + "): mNextAppTransition=" + mNextAppTransition
3621 + " hidden=" + wtoken.hidden
3622 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3623 }
Romain Guy06882f82009-06-10 13:36:04 -07003624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 // If we are preparing an app transition, then delay changing
3626 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003627 if (!mDisplayFrozen && mPolicy.isScreenOn()
3628 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003629 // Already in requested state, don't do anything more.
3630 if (wtoken.hiddenRequested != visible) {
3631 return;
3632 }
3633 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003634
Joe Onorato8a9b2202010-02-26 18:56:32 -08003635 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 TAG, "Setting dummy animation on: " + wtoken);
3637 wtoken.setDummyAnimation();
3638 mOpeningApps.remove(wtoken);
3639 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003640 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 wtoken.inPendingTransaction = true;
3642 if (visible) {
3643 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 wtoken.startingDisplayed = false;
3645 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003646
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003647 // If the token is currently hidden (should be the
3648 // common case), then we need to set up to wait for
3649 // its windows to be ready.
3650 if (wtoken.hidden) {
3651 wtoken.allDrawn = false;
3652 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003653
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003654 if (wtoken.clientHidden) {
3655 // In the case where we are making an app visible
3656 // but holding off for a transition, we still need
3657 // to tell the client to make its windows visible so
3658 // they get drawn. Otherwise, we will wait on
3659 // performing the transition until all windows have
3660 // been drawn, they never will be, and we are sad.
3661 wtoken.clientHidden = false;
3662 wtoken.sendAppVisibilityToClients();
3663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 }
3665 } else {
3666 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003667
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003668 // If the token is currently visible (should be the
3669 // common case), then set up to wait for it to be hidden.
3670 if (!wtoken.hidden) {
3671 wtoken.waitingToHide = true;
3672 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 }
3674 return;
3675 }
Romain Guy06882f82009-06-10 13:36:04 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003678 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 wtoken.updateReportedVisibilityLocked();
3680 Binder.restoreCallingIdentity(origId);
3681 }
3682 }
3683
3684 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3685 boolean unfreezeSurfaceNow, boolean force) {
3686 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003687 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 + " force=" + force);
3689 final int N = wtoken.allAppWindows.size();
3690 boolean unfrozeWindows = false;
3691 for (int i=0; i<N; i++) {
3692 WindowState w = wtoken.allAppWindows.get(i);
3693 if (w.mAppFreezing) {
3694 w.mAppFreezing = false;
3695 if (w.mSurface != null && !w.mOrientationChanging) {
3696 w.mOrientationChanging = true;
3697 }
3698 unfrozeWindows = true;
3699 }
3700 }
3701 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003702 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 wtoken.freezingScreen = false;
3704 mAppsFreezingScreen--;
3705 }
3706 if (unfreezeSurfaceNow) {
3707 if (unfrozeWindows) {
3708 mLayoutNeeded = true;
3709 performLayoutAndPlaceSurfacesLocked();
3710 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003711 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003712 }
3713 }
3714 }
Romain Guy06882f82009-06-10 13:36:04 -07003715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003716 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3717 int configChanges) {
3718 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003719 RuntimeException e = null;
3720 if (!HIDE_STACK_CRAWLS) {
3721 e = new RuntimeException();
3722 e.fillInStackTrace();
3723 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003724 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 + ": hidden=" + wtoken.hidden + " freezing="
3726 + wtoken.freezingScreen, e);
3727 }
3728 if (!wtoken.hiddenRequested) {
3729 if (!wtoken.freezingScreen) {
3730 wtoken.freezingScreen = true;
3731 mAppsFreezingScreen++;
3732 if (mAppsFreezingScreen == 1) {
3733 startFreezingDisplayLocked();
3734 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3735 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3736 5000);
3737 }
3738 }
3739 final int N = wtoken.allAppWindows.size();
3740 for (int i=0; i<N; i++) {
3741 WindowState w = wtoken.allAppWindows.get(i);
3742 w.mAppFreezing = true;
3743 }
3744 }
3745 }
Romain Guy06882f82009-06-10 13:36:04 -07003746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 public void startAppFreezingScreen(IBinder token, int configChanges) {
3748 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3749 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003750 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 }
3752
3753 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003754 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003755 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003756 return;
3757 }
Romain Guy06882f82009-06-10 13:36:04 -07003758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 AppWindowToken wtoken = findAppWindowToken(token);
3760 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003761 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 return;
3763 }
3764 final long origId = Binder.clearCallingIdentity();
3765 startAppFreezingScreenLocked(wtoken, configChanges);
3766 Binder.restoreCallingIdentity(origId);
3767 }
3768 }
Romain Guy06882f82009-06-10 13:36:04 -07003769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 public void stopAppFreezingScreen(IBinder token, boolean force) {
3771 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3772 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003773 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 }
3775
3776 synchronized(mWindowMap) {
3777 AppWindowToken wtoken = findAppWindowToken(token);
3778 if (wtoken == null || wtoken.appToken == null) {
3779 return;
3780 }
3781 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003782 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3784 unsetAppFreezingScreenLocked(wtoken, true, force);
3785 Binder.restoreCallingIdentity(origId);
3786 }
3787 }
Romain Guy06882f82009-06-10 13:36:04 -07003788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003789 public void removeAppToken(IBinder token) {
3790 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3791 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003792 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793 }
3794
3795 AppWindowToken wtoken = null;
3796 AppWindowToken startingToken = null;
3797 boolean delayed = false;
3798
3799 final long origId = Binder.clearCallingIdentity();
3800 synchronized(mWindowMap) {
3801 WindowToken basewtoken = mTokenMap.remove(token);
3802 mTokenList.remove(basewtoken);
3803 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003804 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003805 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 wtoken.inPendingTransaction = false;
3807 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003808 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 if (mClosingApps.contains(wtoken)) {
3810 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003811 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003813 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 delayed = true;
3815 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003816 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003817 TAG, "Removing app " + wtoken + " delayed=" + delayed
3818 + " animation=" + wtoken.animation
3819 + " animating=" + wtoken.animating);
3820 if (delayed) {
3821 // set the token aside because it has an active animation to be finished
3822 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003823 } else {
3824 // Make sure there is no animation running on this token,
3825 // so any windows associated with it will be removed as
3826 // soon as their animations are complete
3827 wtoken.animation = null;
3828 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003829 }
3830 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003831 if (mLastEnterAnimToken == wtoken) {
3832 mLastEnterAnimToken = null;
3833 mLastEnterAnimParams = null;
3834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 wtoken.removed = true;
3836 if (wtoken.startingData != null) {
3837 startingToken = wtoken;
3838 }
3839 unsetAppFreezingScreenLocked(wtoken, true, true);
3840 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003841 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 mFocusedApp = null;
3843 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003844 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 }
3846 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003847 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 }
Romain Guy06882f82009-06-10 13:36:04 -07003849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003850 if (!delayed && wtoken != null) {
3851 wtoken.updateReportedVisibilityLocked();
3852 }
3853 }
3854 Binder.restoreCallingIdentity(origId);
3855
3856 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003857 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 + startingToken + ": app token removed");
3859 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3860 mH.sendMessage(m);
3861 }
3862 }
3863
3864 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3865 final int NW = token.windows.size();
3866 for (int i=0; i<NW; i++) {
3867 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003868 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003870 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003871 int j = win.mChildWindows.size();
3872 while (j > 0) {
3873 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003874 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003875 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003876 "Tmp removing child window " + cwin);
3877 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 }
3879 }
3880 return NW > 0;
3881 }
3882
3883 void dumpAppTokensLocked() {
3884 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003885 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886 }
3887 }
Romain Guy06882f82009-06-10 13:36:04 -07003888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 void dumpWindowsLocked() {
3890 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003891 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003892 }
3893 }
Romain Guy06882f82009-06-10 13:36:04 -07003894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003895 private int findWindowOffsetLocked(int tokenPos) {
3896 final int NW = mWindows.size();
3897
3898 if (tokenPos >= mAppTokens.size()) {
3899 int i = NW;
3900 while (i > 0) {
3901 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003902 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 if (win.getAppToken() != null) {
3904 return i+1;
3905 }
3906 }
3907 }
3908
3909 while (tokenPos > 0) {
3910 // Find the first app token below the new position that has
3911 // a window displayed.
3912 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003913 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003914 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003915 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003916 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003917 "Skipping token -- currently sending to bottom");
3918 tokenPos--;
3919 continue;
3920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 int i = wtoken.windows.size();
3922 while (i > 0) {
3923 i--;
3924 WindowState win = wtoken.windows.get(i);
3925 int j = win.mChildWindows.size();
3926 while (j > 0) {
3927 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003928 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003929 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 for (int pos=NW-1; pos>=0; pos--) {
3931 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003932 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 "Found child win @" + (pos+1));
3934 return pos+1;
3935 }
3936 }
3937 }
3938 }
3939 for (int pos=NW-1; pos>=0; pos--) {
3940 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003941 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003942 return pos+1;
3943 }
3944 }
3945 }
3946 tokenPos--;
3947 }
3948
3949 return 0;
3950 }
3951
3952 private final int reAddWindowLocked(int index, WindowState win) {
3953 final int NCW = win.mChildWindows.size();
3954 boolean added = false;
3955 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003956 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003958 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003959 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003960 mWindows.add(index, win);
3961 index++;
3962 added = true;
3963 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003964 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003965 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966 mWindows.add(index, cwin);
3967 index++;
3968 }
3969 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003970 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003971 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003972 mWindows.add(index, win);
3973 index++;
3974 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003975 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003976 return index;
3977 }
Romain Guy06882f82009-06-10 13:36:04 -07003978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003979 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3980 final int NW = token.windows.size();
3981 for (int i=0; i<NW; i++) {
3982 index = reAddWindowLocked(index, token.windows.get(i));
3983 }
3984 return index;
3985 }
3986
3987 public void moveAppToken(int index, IBinder token) {
3988 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3989 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003990 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003991 }
3992
3993 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003994 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 if (DEBUG_REORDER) dumpAppTokensLocked();
3996 final AppWindowToken wtoken = findAppWindowToken(token);
3997 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003998 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003999 + token + " (" + wtoken + ")");
4000 return;
4001 }
4002 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004003 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004007 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004008 if (DEBUG_REORDER) dumpWindowsLocked();
4009 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 if (DEBUG_REORDER) dumpWindowsLocked();
4012 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004013 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 if (DEBUG_REORDER) dumpWindowsLocked();
4015 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 mLayoutNeeded = true;
4017 performLayoutAndPlaceSurfacesLocked();
4018 }
4019 Binder.restoreCallingIdentity(origId);
4020 }
4021 }
4022
4023 private void removeAppTokensLocked(List<IBinder> tokens) {
4024 // XXX This should be done more efficiently!
4025 // (take advantage of the fact that both lists should be
4026 // ordered in the same way.)
4027 int N = tokens.size();
4028 for (int i=0; i<N; i++) {
4029 IBinder token = tokens.get(i);
4030 final AppWindowToken wtoken = findAppWindowToken(token);
4031 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004032 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004033 + token + " (" + wtoken + ")");
4034 i--;
4035 N--;
4036 }
4037 }
4038 }
4039
Dianne Hackborna8f60182009-09-01 19:01:50 -07004040 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4041 boolean updateFocusAndLayout) {
4042 // First remove all of the windows from the list.
4043 tmpRemoveAppWindowsLocked(wtoken);
4044
4045 // Where to start adding?
4046 int pos = findWindowOffsetLocked(tokenPos);
4047
4048 // And now add them back at the correct place.
4049 pos = reAddAppWindowsLocked(pos, wtoken);
4050
4051 if (updateFocusAndLayout) {
4052 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4053 assignLayersLocked();
4054 }
4055 mLayoutNeeded = true;
4056 performLayoutAndPlaceSurfacesLocked();
4057 }
4058 }
4059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004060 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4061 // First remove all of the windows from the list.
4062 final int N = tokens.size();
4063 int i;
4064 for (i=0; i<N; i++) {
4065 WindowToken token = mTokenMap.get(tokens.get(i));
4066 if (token != null) {
4067 tmpRemoveAppWindowsLocked(token);
4068 }
4069 }
4070
4071 // Where to start adding?
4072 int pos = findWindowOffsetLocked(tokenPos);
4073
4074 // And now add them back at the correct place.
4075 for (i=0; i<N; i++) {
4076 WindowToken token = mTokenMap.get(tokens.get(i));
4077 if (token != null) {
4078 pos = reAddAppWindowsLocked(pos, token);
4079 }
4080 }
4081
Dianne Hackborna8f60182009-09-01 19:01:50 -07004082 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4083 assignLayersLocked();
4084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 mLayoutNeeded = true;
4086 performLayoutAndPlaceSurfacesLocked();
4087
4088 //dump();
4089 }
4090
4091 public void moveAppTokensToTop(List<IBinder> tokens) {
4092 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4093 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004094 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004095 }
4096
4097 final long origId = Binder.clearCallingIdentity();
4098 synchronized(mWindowMap) {
4099 removeAppTokensLocked(tokens);
4100 final int N = tokens.size();
4101 for (int i=0; i<N; i++) {
4102 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4103 if (wt != null) {
4104 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004105 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004106 mToTopApps.remove(wt);
4107 mToBottomApps.remove(wt);
4108 mToTopApps.add(wt);
4109 wt.sendingToBottom = false;
4110 wt.sendingToTop = true;
4111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 }
4113 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004114
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004115 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004116 moveAppWindowsLocked(tokens, mAppTokens.size());
4117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004118 }
4119 Binder.restoreCallingIdentity(origId);
4120 }
4121
4122 public void moveAppTokensToBottom(List<IBinder> tokens) {
4123 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4124 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004125 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126 }
4127
4128 final long origId = Binder.clearCallingIdentity();
4129 synchronized(mWindowMap) {
4130 removeAppTokensLocked(tokens);
4131 final int N = tokens.size();
4132 int pos = 0;
4133 for (int i=0; i<N; i++) {
4134 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4135 if (wt != null) {
4136 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004137 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004138 mToTopApps.remove(wt);
4139 mToBottomApps.remove(wt);
4140 mToBottomApps.add(i, wt);
4141 wt.sendingToTop = false;
4142 wt.sendingToBottom = true;
4143 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004144 pos++;
4145 }
4146 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004147
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004148 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004149 moveAppWindowsLocked(tokens, 0);
4150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 }
4152 Binder.restoreCallingIdentity(origId);
4153 }
4154
4155 // -------------------------------------------------------------
4156 // Misc IWindowSession methods
4157 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004158
Jim Miller284b62e2010-06-08 14:27:42 -07004159 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004160 {
Jim Miller284b62e2010-06-08 14:27:42 -07004161 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4162 // called before DevicePolicyManagerService has started.
4163 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4164 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4165 Context.DEVICE_POLICY_SERVICE);
4166 if (dpm != null) {
4167 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4168 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4169 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4170 }
Jim Millerd6b57052010-06-07 17:52:42 -07004171 }
Jim Miller284b62e2010-06-08 14:27:42 -07004172 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004173 }
4174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004176 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 != PackageManager.PERMISSION_GRANTED) {
4178 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4179 }
Jim Millerd6b57052010-06-07 17:52:42 -07004180
Jim Miller284b62e2010-06-08 14:27:42 -07004181 synchronized (mKeyguardTokenWatcher) {
4182 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 }
4185
4186 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004187 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004188 != PackageManager.PERMISSION_GRANTED) {
4189 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191
Jim Miller284b62e2010-06-08 14:27:42 -07004192 synchronized (mKeyguardTokenWatcher) {
4193 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004194
Jim Miller284b62e2010-06-08 14:27:42 -07004195 if (!mKeyguardTokenWatcher.isAcquired()) {
4196 // If we are the last one to reenable the keyguard wait until
4197 // we have actually finished reenabling until returning.
4198 // It is possible that reenableKeyguard() can be called before
4199 // the previous disableKeyguard() is handled, in which case
4200 // neither mKeyguardTokenWatcher.acquired() or released() would
4201 // be called. In that case mKeyguardDisabled will be false here
4202 // and we have nothing to wait for.
4203 while (mKeyguardDisabled) {
4204 try {
4205 mKeyguardTokenWatcher.wait();
4206 } catch (InterruptedException e) {
4207 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 }
4209 }
4210 }
4211 }
4212 }
4213
4214 /**
4215 * @see android.app.KeyguardManager#exitKeyguardSecurely
4216 */
4217 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004218 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 != PackageManager.PERMISSION_GRANTED) {
4220 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4221 }
4222 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4223 public void onKeyguardExitResult(boolean success) {
4224 try {
4225 callback.onKeyguardExitResult(success);
4226 } catch (RemoteException e) {
4227 // Client has died, we don't care.
4228 }
4229 }
4230 });
4231 }
4232
4233 public boolean inKeyguardRestrictedInputMode() {
4234 return mPolicy.inKeyguardRestrictedKeyInputMode();
4235 }
Romain Guy06882f82009-06-10 13:36:04 -07004236
Dianne Hackbornffa42482009-09-23 22:20:11 -07004237 public void closeSystemDialogs(String reason) {
4238 synchronized(mWindowMap) {
4239 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004240 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004241 if (w.mSurface != null) {
4242 try {
4243 w.mClient.closeSystemDialogs(reason);
4244 } catch (RemoteException e) {
4245 }
4246 }
4247 }
4248 }
4249 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 static float fixScale(float scale) {
4252 if (scale < 0) scale = 0;
4253 else if (scale > 20) scale = 20;
4254 return Math.abs(scale);
4255 }
Romain Guy06882f82009-06-10 13:36:04 -07004256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 public void setAnimationScale(int which, float scale) {
4258 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4259 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004260 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004261 }
4262
4263 if (scale < 0) scale = 0;
4264 else if (scale > 20) scale = 20;
4265 scale = Math.abs(scale);
4266 switch (which) {
4267 case 0: mWindowAnimationScale = fixScale(scale); break;
4268 case 1: mTransitionAnimationScale = fixScale(scale); break;
4269 }
Romain Guy06882f82009-06-10 13:36:04 -07004270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004271 // Persist setting
4272 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4273 }
Romain Guy06882f82009-06-10 13:36:04 -07004274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004275 public void setAnimationScales(float[] scales) {
4276 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4277 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004278 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 }
4280
4281 if (scales != null) {
4282 if (scales.length >= 1) {
4283 mWindowAnimationScale = fixScale(scales[0]);
4284 }
4285 if (scales.length >= 2) {
4286 mTransitionAnimationScale = fixScale(scales[1]);
4287 }
4288 }
Romain Guy06882f82009-06-10 13:36:04 -07004289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290 // Persist setting
4291 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4292 }
Romain Guy06882f82009-06-10 13:36:04 -07004293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004294 public float getAnimationScale(int which) {
4295 switch (which) {
4296 case 0: return mWindowAnimationScale;
4297 case 1: return mTransitionAnimationScale;
4298 }
4299 return 0;
4300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 public float[] getAnimationScales() {
4303 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4304 }
Romain Guy06882f82009-06-10 13:36:04 -07004305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 public int getSwitchState(int sw) {
4307 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4308 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004309 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004311 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 }
Romain Guy06882f82009-06-10 13:36:04 -07004313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 public int getSwitchStateForDevice(int devid, int sw) {
4315 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4316 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004317 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004319 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 }
Romain Guy06882f82009-06-10 13:36:04 -07004321
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 public int getScancodeState(int sw) {
4323 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4324 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004325 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004327 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 }
Romain Guy06882f82009-06-10 13:36:04 -07004329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004330 public int getScancodeStateForDevice(int devid, int sw) {
4331 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4332 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004333 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004335 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004336 }
Romain Guy06882f82009-06-10 13:36:04 -07004337
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004338 public int getTrackballScancodeState(int sw) {
4339 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4340 "getTrackballScancodeState()")) {
4341 throw new SecurityException("Requires READ_INPUT_STATE permission");
4342 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004343 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004344 }
4345
4346 public int getDPadScancodeState(int sw) {
4347 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4348 "getDPadScancodeState()")) {
4349 throw new SecurityException("Requires READ_INPUT_STATE permission");
4350 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004351 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004352 }
4353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004354 public int getKeycodeState(int sw) {
4355 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4356 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004357 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004359 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 }
Romain Guy06882f82009-06-10 13:36:04 -07004361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362 public int getKeycodeStateForDevice(int devid, int sw) {
4363 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4364 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004365 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004367 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 }
Romain Guy06882f82009-06-10 13:36:04 -07004369
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004370 public int getTrackballKeycodeState(int sw) {
4371 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4372 "getTrackballKeycodeState()")) {
4373 throw new SecurityException("Requires READ_INPUT_STATE permission");
4374 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004375 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004376 }
4377
4378 public int getDPadKeycodeState(int sw) {
4379 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4380 "getDPadKeycodeState()")) {
4381 throw new SecurityException("Requires READ_INPUT_STATE permission");
4382 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004383 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004384 }
4385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004387 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004388 }
Romain Guy06882f82009-06-10 13:36:04 -07004389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004390 public void enableScreenAfterBoot() {
4391 synchronized(mWindowMap) {
4392 if (mSystemBooted) {
4393 return;
4394 }
4395 mSystemBooted = true;
4396 }
Romain Guy06882f82009-06-10 13:36:04 -07004397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 performEnableScreen();
4399 }
Romain Guy06882f82009-06-10 13:36:04 -07004400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 public void enableScreenIfNeededLocked() {
4402 if (mDisplayEnabled) {
4403 return;
4404 }
4405 if (!mSystemBooted) {
4406 return;
4407 }
4408 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4409 }
Romain Guy06882f82009-06-10 13:36:04 -07004410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004411 public void performEnableScreen() {
4412 synchronized(mWindowMap) {
4413 if (mDisplayEnabled) {
4414 return;
4415 }
4416 if (!mSystemBooted) {
4417 return;
4418 }
Romain Guy06882f82009-06-10 13:36:04 -07004419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 // Don't enable the screen until all existing windows
4421 // have been drawn.
4422 final int N = mWindows.size();
4423 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004424 WindowState w = mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004425 if (w.isVisibleLw() && !w.mObscured
4426 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004427 return;
4428 }
4429 }
Romain Guy06882f82009-06-10 13:36:04 -07004430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 mDisplayEnabled = true;
4432 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004433 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004434 StringWriter sw = new StringWriter();
4435 PrintWriter pw = new PrintWriter(sw);
4436 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004437 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 }
4439 try {
4440 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4441 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 Parcel data = Parcel.obtain();
4444 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4445 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4446 data, null, 0);
4447 data.recycle();
4448 }
4449 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004450 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 }
4452 }
Romain Guy06882f82009-06-10 13:36:04 -07004453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004457 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4458 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 }
Romain Guy06882f82009-06-10 13:36:04 -07004460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 public void setInTouchMode(boolean mode) {
4462 synchronized(mWindowMap) {
4463 mInTouchMode = mode;
4464 }
4465 }
4466
Romain Guy06882f82009-06-10 13:36:04 -07004467 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004468 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004470 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004471 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 }
4473
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004474 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 }
Romain Guy06882f82009-06-10 13:36:04 -07004476
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004477 public void setRotationUnchecked(int rotation,
4478 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004479 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 long origId = Binder.clearCallingIdentity();
4483 boolean changed;
4484 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004485 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 }
Romain Guy06882f82009-06-10 13:36:04 -07004487
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004488 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004489 sendNewConfiguration();
4490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004492 Binder.restoreCallingIdentity(origId);
4493 }
Romain Guy06882f82009-06-10 13:36:04 -07004494
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004495 /**
4496 * Apply a new rotation to the screen, respecting the requests of
4497 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4498 * re-evaluate the desired rotation.
4499 *
4500 * Returns null if the rotation has been changed. In this case YOU
4501 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4502 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004503 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 boolean changed;
4505 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4506 rotation = mRequestedRotation;
4507 } else {
4508 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004509 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004511 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004512 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004513 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004514 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004518 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 "Rotation changed to " + rotation
4520 + " from " + mRotation
4521 + " (forceApp=" + mForcedAppOrientation
4522 + ", req=" + mRequestedRotation + ")");
4523 mRotation = rotation;
4524 mWindowsFreezingScreen = true;
4525 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4526 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4527 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004528 mWaitingForConfig = true;
4529 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004531 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004532 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004534 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 }
4536 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004537 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 if (w.mSurface != null) {
4539 w.mOrientationChanging = true;
4540 }
4541 }
4542 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4543 try {
4544 mRotationWatchers.get(i).onRotationChanged(rotation);
4545 } catch (RemoteException e) {
4546 }
4547 }
4548 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 return changed;
4551 }
Romain Guy06882f82009-06-10 13:36:04 -07004552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004553 public int getRotation() {
4554 return mRotation;
4555 }
4556
4557 public int watchRotation(IRotationWatcher watcher) {
4558 final IBinder watcherBinder = watcher.asBinder();
4559 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4560 public void binderDied() {
4561 synchronized (mWindowMap) {
4562 for (int i=0; i<mRotationWatchers.size(); i++) {
4563 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004564 IRotationWatcher removed = mRotationWatchers.remove(i);
4565 if (removed != null) {
4566 removed.asBinder().unlinkToDeath(this, 0);
4567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004568 i--;
4569 }
4570 }
4571 }
4572 }
4573 };
Romain Guy06882f82009-06-10 13:36:04 -07004574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004575 synchronized (mWindowMap) {
4576 try {
4577 watcher.asBinder().linkToDeath(dr, 0);
4578 mRotationWatchers.add(watcher);
4579 } catch (RemoteException e) {
4580 // Client died, no cleanup needed.
4581 }
Romain Guy06882f82009-06-10 13:36:04 -07004582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004583 return mRotation;
4584 }
4585 }
4586
4587 /**
4588 * Starts the view server on the specified port.
4589 *
4590 * @param port The port to listener to.
4591 *
4592 * @return True if the server was successfully started, false otherwise.
4593 *
4594 * @see com.android.server.ViewServer
4595 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4596 */
4597 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004598 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004599 return false;
4600 }
4601
4602 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4603 return false;
4604 }
4605
4606 if (port < 1024) {
4607 return false;
4608 }
4609
4610 if (mViewServer != null) {
4611 if (!mViewServer.isRunning()) {
4612 try {
4613 return mViewServer.start();
4614 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004615 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004616 }
4617 }
4618 return false;
4619 }
4620
4621 try {
4622 mViewServer = new ViewServer(this, port);
4623 return mViewServer.start();
4624 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004625 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004626 }
4627 return false;
4628 }
4629
Romain Guy06882f82009-06-10 13:36:04 -07004630 private boolean isSystemSecure() {
4631 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4632 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4633 }
4634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 /**
4636 * Stops the view server if it exists.
4637 *
4638 * @return True if the server stopped, false if it wasn't started or
4639 * couldn't be stopped.
4640 *
4641 * @see com.android.server.ViewServer
4642 */
4643 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004644 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 return false;
4646 }
4647
4648 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4649 return false;
4650 }
4651
4652 if (mViewServer != null) {
4653 return mViewServer.stop();
4654 }
4655 return false;
4656 }
4657
4658 /**
4659 * Indicates whether the view server is running.
4660 *
4661 * @return True if the server is running, false otherwise.
4662 *
4663 * @see com.android.server.ViewServer
4664 */
4665 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004666 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004667 return false;
4668 }
4669
4670 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4671 return false;
4672 }
4673
4674 return mViewServer != null && mViewServer.isRunning();
4675 }
4676
4677 /**
4678 * Lists all availble windows in the system. The listing is written in the
4679 * specified Socket's output stream with the following syntax:
4680 * windowHashCodeInHexadecimal windowName
4681 * Each line of the ouput represents a different window.
4682 *
4683 * @param client The remote client to send the listing to.
4684 * @return False if an error occured, true otherwise.
4685 */
4686 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004687 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 return false;
4689 }
4690
4691 boolean result = true;
4692
Jeff Browne33348b2010-07-15 23:54:05 -07004693 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004695 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004696 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004697 }
4698
4699 BufferedWriter out = null;
4700
4701 // Any uncaught exception will crash the system process
4702 try {
4703 OutputStream clientStream = client.getOutputStream();
4704 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4705
4706 final int count = windows.length;
4707 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004708 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 out.write(Integer.toHexString(System.identityHashCode(w)));
4710 out.write(' ');
4711 out.append(w.mAttrs.getTitle());
4712 out.write('\n');
4713 }
4714
4715 out.write("DONE.\n");
4716 out.flush();
4717 } catch (Exception e) {
4718 result = false;
4719 } finally {
4720 if (out != null) {
4721 try {
4722 out.close();
4723 } catch (IOException e) {
4724 result = false;
4725 }
4726 }
4727 }
4728
4729 return result;
4730 }
4731
4732 /**
4733 * Sends a command to a target window. The result of the command, if any, will be
4734 * written in the output stream of the specified socket.
4735 *
4736 * The parameters must follow this syntax:
4737 * windowHashcode extra
4738 *
4739 * Where XX is the length in characeters of the windowTitle.
4740 *
4741 * The first parameter is the target window. The window with the specified hashcode
4742 * will be the target. If no target can be found, nothing happens. The extra parameters
4743 * will be delivered to the target window and as parameters to the command itself.
4744 *
4745 * @param client The remote client to sent the result, if any, to.
4746 * @param command The command to execute.
4747 * @param parameters The command parameters.
4748 *
4749 * @return True if the command was successfully delivered, false otherwise. This does
4750 * not indicate whether the command itself was successful.
4751 */
4752 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004753 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004754 return false;
4755 }
4756
4757 boolean success = true;
4758 Parcel data = null;
4759 Parcel reply = null;
4760
4761 // Any uncaught exception will crash the system process
4762 try {
4763 // Find the hashcode of the window
4764 int index = parameters.indexOf(' ');
4765 if (index == -1) {
4766 index = parameters.length();
4767 }
4768 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004769 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004770
4771 // Extract the command's parameter after the window description
4772 if (index < parameters.length()) {
4773 parameters = parameters.substring(index + 1);
4774 } else {
4775 parameters = "";
4776 }
4777
4778 final WindowManagerService.WindowState window = findWindow(hashCode);
4779 if (window == null) {
4780 return false;
4781 }
4782
4783 data = Parcel.obtain();
4784 data.writeInterfaceToken("android.view.IWindow");
4785 data.writeString(command);
4786 data.writeString(parameters);
4787 data.writeInt(1);
4788 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4789
4790 reply = Parcel.obtain();
4791
4792 final IBinder binder = window.mClient.asBinder();
4793 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4794 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4795
4796 reply.readException();
4797
4798 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004799 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004800 success = false;
4801 } finally {
4802 if (data != null) {
4803 data.recycle();
4804 }
4805 if (reply != null) {
4806 reply.recycle();
4807 }
4808 }
4809
4810 return success;
4811 }
4812
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004813 public void addWindowChangeListener(WindowChangeListener listener) {
4814 synchronized(mWindowMap) {
4815 mWindowChangeListeners.add(listener);
4816 }
4817 }
4818
4819 public void removeWindowChangeListener(WindowChangeListener listener) {
4820 synchronized(mWindowMap) {
4821 mWindowChangeListeners.remove(listener);
4822 }
4823 }
4824
4825 private void notifyWindowsChanged() {
4826 WindowChangeListener[] windowChangeListeners;
4827 synchronized(mWindowMap) {
4828 if(mWindowChangeListeners.isEmpty()) {
4829 return;
4830 }
4831 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4832 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4833 }
4834 int N = windowChangeListeners.length;
4835 for(int i = 0; i < N; i++) {
4836 windowChangeListeners[i].windowsChanged();
4837 }
4838 }
4839
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004840 private void notifyFocusChanged() {
4841 WindowChangeListener[] windowChangeListeners;
4842 synchronized(mWindowMap) {
4843 if(mWindowChangeListeners.isEmpty()) {
4844 return;
4845 }
4846 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4847 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4848 }
4849 int N = windowChangeListeners.length;
4850 for(int i = 0; i < N; i++) {
4851 windowChangeListeners[i].focusChanged();
4852 }
4853 }
4854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 private WindowState findWindow(int hashCode) {
4856 if (hashCode == -1) {
4857 return getFocusedWindow();
4858 }
4859
4860 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004861 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004862 final int count = windows.size();
4863
4864 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004865 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004866 if (System.identityHashCode(w) == hashCode) {
4867 return w;
4868 }
4869 }
4870 }
4871
4872 return null;
4873 }
4874
4875 /*
4876 * Instruct the Activity Manager to fetch the current configuration and broadcast
4877 * that to config-changed listeners if appropriate.
4878 */
4879 void sendNewConfiguration() {
4880 try {
4881 mActivityManager.updateConfiguration(null);
4882 } catch (RemoteException e) {
4883 }
4884 }
Romain Guy06882f82009-06-10 13:36:04 -07004885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886 public Configuration computeNewConfiguration() {
4887 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004888 return computeNewConfigurationLocked();
4889 }
4890 }
Romain Guy06882f82009-06-10 13:36:04 -07004891
Dianne Hackbornc485a602009-03-24 22:39:49 -07004892 Configuration computeNewConfigurationLocked() {
4893 Configuration config = new Configuration();
4894 if (!computeNewConfigurationLocked(config)) {
4895 return null;
4896 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004897 return config;
4898 }
Romain Guy06882f82009-06-10 13:36:04 -07004899
Dianne Hackbornc485a602009-03-24 22:39:49 -07004900 boolean computeNewConfigurationLocked(Configuration config) {
4901 if (mDisplay == null) {
4902 return false;
4903 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004904
4905 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004906
4907 // Use the effective "visual" dimensions based on current rotation
4908 final boolean rotated = (mRotation == Surface.ROTATION_90
4909 || mRotation == Surface.ROTATION_270);
4910 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4911 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4912
Dianne Hackbornc485a602009-03-24 22:39:49 -07004913 int orientation = Configuration.ORIENTATION_SQUARE;
4914 if (dw < dh) {
4915 orientation = Configuration.ORIENTATION_PORTRAIT;
4916 } else if (dw > dh) {
4917 orientation = Configuration.ORIENTATION_LANDSCAPE;
4918 }
4919 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004920
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004921 DisplayMetrics dm = new DisplayMetrics();
4922 mDisplay.getMetrics(dm);
4923 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4924
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004925 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004926 // Note we only do this once because at this point we don't
4927 // expect the screen to change in this way at runtime, and want
4928 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004929 int longSize = dw;
4930 int shortSize = dh;
4931 if (longSize < shortSize) {
4932 int tmp = longSize;
4933 longSize = shortSize;
4934 shortSize = tmp;
4935 }
4936 longSize = (int)(longSize/dm.density);
4937 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004938
Dianne Hackborn723738c2009-06-25 19:48:04 -07004939 // These semi-magic numbers define our compatibility modes for
4940 // applications with different screens. Don't change unless you
4941 // make sure to test lots and lots of apps!
4942 if (longSize < 470) {
4943 // This is shorter than an HVGA normal density screen (which
4944 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004945 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4946 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004947 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004948 // What size is this screen screen?
4949 if (longSize >= 800 && shortSize >= 600) {
4950 // SVGA or larger screens at medium density are the point
4951 // at which we consider it to be an extra large screen.
4952 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
4953 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004954 // VGA or larger screens at medium density are the point
4955 // at which we consider it to be a large screen.
4956 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
4957 } else {
4958 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004959
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004960 // If this screen is wider than normal HVGA, or taller
4961 // than FWVGA, then for old apps we want to run in size
4962 // compatibility mode.
4963 if (shortSize > 321 || longSize > 570) {
4964 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
4965 }
4966 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004967
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004968 // Is this a long screen?
4969 if (((longSize*3)/5) >= (shortSize-1)) {
4970 // Anything wider than WVGA (5:3) is considering to be long.
4971 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
4972 } else {
4973 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
4974 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07004975 }
4976 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004977 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004978
Dianne Hackbornc485a602009-03-24 22:39:49 -07004979 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
4980 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
4981 mPolicy.adjustConfigurationLw(config);
4982 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07004984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004985 // -------------------------------------------------------------
4986 // Input Events and Focus Management
4987 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07004988
Jeff Brown349703e2010-06-22 01:27:15 -07004989 InputMonitor mInputMonitor = new InputMonitor();
4990
4991 /* Tracks the progress of input dispatch and ensures that input dispatch state
4992 * is kept in sync with changes in window focus, visibility, registration, and
4993 * other relevant Window Manager state transitions. */
4994 final class InputMonitor {
4995 // Current window with input focus for keys and other non-touch events. May be null.
4996 private WindowState mInputFocus;
4997
4998 // When true, prevents input dispatch from proceeding until set to false again.
4999 private boolean mInputDispatchFrozen;
5000
5001 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5002 private boolean mInputDispatchEnabled = true;
5003
5004 // Temporary list of windows information to provide to the input dispatcher.
5005 private InputWindowList mTempInputWindows = new InputWindowList();
5006
5007 // Temporary input application object to provide to the input dispatcher.
5008 private InputApplication mTempInputApplication = new InputApplication();
5009
5010 /* Notifies the window manager about a broken input channel.
5011 *
5012 * Called by the InputManager.
5013 */
5014 public void notifyInputChannelBroken(InputChannel inputChannel) {
5015 synchronized (mWindowMap) {
5016 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5017 if (windowState == null) {
5018 return; // irrelevant
5019 }
5020
5021 Slog.i(TAG, "WINDOW DIED " + windowState);
5022 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005023 }
5024 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005025
Jeff Brown349703e2010-06-22 01:27:15 -07005026 /* Notifies the window manager about an input channel that is not responding.
5027 * The method can either cause dispatching to be aborted by returning -2 or
5028 * return a new timeout in nanoseconds.
5029 *
5030 * Called by the InputManager.
5031 */
5032 public long notifyInputChannelANR(InputChannel inputChannel) {
5033 AppWindowToken token;
5034 synchronized (mWindowMap) {
5035 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5036 if (windowState == null) {
5037 return -2; // irrelevant, abort dispatching (-2)
5038 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005039
Jeff Brown349703e2010-06-22 01:27:15 -07005040 Slog.i(TAG, "Input event dispatching timed out sending to "
5041 + windowState.mAttrs.getTitle());
5042 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005043 }
5044
Jeff Brown349703e2010-06-22 01:27:15 -07005045 return notifyANRInternal(token);
5046 }
5047
5048 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5049 * by successfully delivering the event that originally timed out.
5050 *
5051 * Called by the InputManager.
5052 */
5053 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5054 // Nothing to do just now.
5055 // Just wait for the user to dismiss the ANR dialog.
5056 }
5057
5058 /* Notifies the window manager about an application that is not responding
5059 * in general rather than with respect to a particular input channel.
5060 * The method can either cause dispatching to be aborted by returning -2 or
5061 * return a new timeout in nanoseconds.
5062 *
5063 * Called by the InputManager.
5064 */
5065 public long notifyANR(Object token) {
5066 AppWindowToken appWindowToken = (AppWindowToken) token;
5067
5068 Slog.i(TAG, "Input event dispatching timed out sending to application "
5069 + appWindowToken.stringName);
5070 return notifyANRInternal(appWindowToken);
5071 }
5072
5073 private long notifyANRInternal(AppWindowToken token) {
5074 if (token != null && token.appToken != null) {
5075 try {
5076 // Notify the activity manager about the timeout and let it decide whether
5077 // to abort dispatching or keep waiting.
5078 boolean abort = token.appToken.keyDispatchingTimedOut();
5079 if (! abort) {
5080 // The activity manager declined to abort dispatching.
5081 // Wait a bit longer and timeout again later.
5082 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005083 }
Jeff Brown349703e2010-06-22 01:27:15 -07005084 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005085 }
5086 }
Jeff Brown349703e2010-06-22 01:27:15 -07005087 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005088 }
5089
Jeff Brown349703e2010-06-22 01:27:15 -07005090 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5091 synchronized (mWindowMap) {
5092 return getWindowStateForInputChannelLocked(inputChannel);
5093 }
5094 }
5095
5096 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5097 int windowCount = mWindows.size();
5098 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005099 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005100 if (windowState.mInputChannel == inputChannel) {
5101 return windowState;
5102 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005103 }
5104
Jeff Brown349703e2010-06-22 01:27:15 -07005105 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005106 }
5107
Jeff Brown349703e2010-06-22 01:27:15 -07005108 /* Updates the cached window information provided to the input dispatcher. */
5109 public void updateInputWindowsLw() {
5110 // Populate the input window list with information about all of the windows that
5111 // could potentially receive input.
5112 // As an optimization, we could try to prune the list of windows but this turns
5113 // out to be difficult because only the native code knows for sure which window
5114 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005115 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005116 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005117 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005118 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005119 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005120 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005121 continue;
5122 }
5123
Jeff Brown349703e2010-06-22 01:27:15 -07005124 final int flags = child.mAttrs.flags;
5125 final int type = child.mAttrs.type;
5126
5127 final boolean hasFocus = (child == mInputFocus);
5128 final boolean isVisible = child.isVisibleLw();
5129 final boolean hasWallpaper = (child == mWallpaperTarget)
5130 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5131
5132 // Add a window to our list of input windows.
5133 final InputWindow inputWindow = mTempInputWindows.add();
5134 inputWindow.inputChannel = child.mInputChannel;
5135 inputWindow.layoutParamsFlags = flags;
5136 inputWindow.layoutParamsType = type;
5137 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5138 inputWindow.visible = isVisible;
5139 inputWindow.hasFocus = hasFocus;
5140 inputWindow.hasWallpaper = hasWallpaper;
5141 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5142 inputWindow.ownerPid = child.mSession.mPid;
5143 inputWindow.ownerUid = child.mSession.mUid;
5144
5145 final Rect frame = child.mFrame;
5146 inputWindow.frameLeft = frame.left;
5147 inputWindow.frameTop = frame.top;
5148
5149 switch (child.mTouchableInsets) {
5150 default:
5151 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5152 inputWindow.touchableAreaLeft = frame.left;
5153 inputWindow.touchableAreaTop = frame.top;
5154 inputWindow.touchableAreaRight = frame.right;
5155 inputWindow.touchableAreaBottom = frame.bottom;
5156 break;
5157
5158 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5159 Rect inset = child.mGivenContentInsets;
5160 inputWindow.touchableAreaLeft = frame.left + inset.left;
5161 inputWindow.touchableAreaTop = frame.top + inset.top;
5162 inputWindow.touchableAreaRight = frame.right - inset.right;
5163 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5164 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005165 }
Jeff Brown349703e2010-06-22 01:27:15 -07005166
5167 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5168 Rect inset = child.mGivenVisibleInsets;
5169 inputWindow.touchableAreaLeft = frame.left + inset.left;
5170 inputWindow.touchableAreaTop = frame.top + inset.top;
5171 inputWindow.touchableAreaRight = frame.right - inset.right;
5172 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005173 break;
5174 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005175 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005176 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005177
Jeff Brown349703e2010-06-22 01:27:15 -07005178 // Send windows to native code.
5179 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005180
Jeff Brown349703e2010-06-22 01:27:15 -07005181 // Clear the list in preparation for the next round.
5182 // Also avoids keeping InputChannel objects referenced unnecessarily.
5183 mTempInputWindows.clear();
5184 }
5185
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005186 /* Provides feedback for a virtual key down. */
5187 public void virtualKeyDownFeedback() {
5188 synchronized (mWindowMap) {
5189 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5190 }
5191 }
5192
Jeff Brown349703e2010-06-22 01:27:15 -07005193 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5194 * This essentially starts a .5 second timeout for the application to process
5195 * subsequent input events while waiting for the app switch to occur. If it takes longer
5196 * than this, the pending events will be dropped.
5197 */
5198 public void notifyAppSwitchComing() {
5199 // TODO Not implemented yet. Should go in the native side.
5200 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005201
5202 /* Notifies that the lid switch changed state. */
5203 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5204 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5205 }
5206
Jeff Brown349703e2010-06-22 01:27:15 -07005207 /* Provides an opportunity for the window manager policy to intercept early key
5208 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005209 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5210 int policyFlags, boolean isScreenOn) {
5211 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5212 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005213 }
5214
5215 /* Provides an opportunity for the window manager policy to process a key before
5216 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005217 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5218 int action, int flags, int keyCode, int metaState, int repeatCount,
5219 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005220 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005221 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5222 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005223 }
5224
5225 /* Called when the current input focus changes.
5226 * Layer assignment is assumed to be complete by the time this is called.
5227 */
5228 public void setInputFocusLw(WindowState newWindow) {
5229 if (DEBUG_INPUT) {
5230 Slog.d(TAG, "Input focus has changed to " + newWindow);
5231 }
5232
5233 if (newWindow != mInputFocus) {
5234 if (newWindow != null && newWindow.canReceiveKeys()) {
5235 // If the new input focus is an error window or appears above the current
5236 // input focus, preempt any pending synchronous dispatch so that we can
5237 // start delivering events to the new input focus as soon as possible.
5238 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5239 if (DEBUG_INPUT) {
5240 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005241 }
Jeff Brown349703e2010-06-22 01:27:15 -07005242 preemptInputDispatchLw();
5243 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5244 if (DEBUG_INPUT) {
5245 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5246 + "old win layer=" + mInputFocus.mLayer
5247 + ", new win layer=" + newWindow.mLayer);
5248 }
5249 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005250 }
Jeff Brown349703e2010-06-22 01:27:15 -07005251
5252 // Displaying a window implicitly causes dispatching to be unpaused.
5253 // This is to protect against bugs if someone pauses dispatching but
5254 // forgets to resume.
5255 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005256 }
Jeff Brown349703e2010-06-22 01:27:15 -07005257
5258 mInputFocus = newWindow;
5259 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005260 }
5261 }
5262
Jeff Brown349703e2010-06-22 01:27:15 -07005263 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5264 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5265 * can begin.
5266 */
5267 private void preemptInputDispatchLw() {
5268 mInputManager.preemptInputDispatch();
5269 }
5270
5271 public void setFocusedAppLw(AppWindowToken newApp) {
5272 // Focused app has changed.
5273 if (newApp == null) {
5274 mInputManager.setFocusedApplication(null);
5275 } else {
5276 mTempInputApplication.name = newApp.toString();
5277 mTempInputApplication.dispatchingTimeoutNanos =
5278 newApp.inputDispatchingTimeoutNanos;
5279 mTempInputApplication.token = newApp;
5280
5281 mInputManager.setFocusedApplication(mTempInputApplication);
5282 }
5283 }
5284
Jeff Brown349703e2010-06-22 01:27:15 -07005285 public void pauseDispatchingLw(WindowToken window) {
5286 if (! window.paused) {
5287 if (DEBUG_INPUT) {
5288 Slog.v(TAG, "Pausing WindowToken " + window);
5289 }
5290
5291 window.paused = true;
5292 updateInputWindowsLw();
5293 }
5294 }
5295
5296 public void resumeDispatchingLw(WindowToken window) {
5297 if (window.paused) {
5298 if (DEBUG_INPUT) {
5299 Slog.v(TAG, "Resuming WindowToken " + window);
5300 }
5301
5302 window.paused = false;
5303 updateInputWindowsLw();
5304 }
5305 }
5306
5307 public void freezeInputDispatchingLw() {
5308 if (! mInputDispatchFrozen) {
5309 if (DEBUG_INPUT) {
5310 Slog.v(TAG, "Freezing input dispatching");
5311 }
5312
5313 mInputDispatchFrozen = true;
5314 updateInputDispatchModeLw();
5315 }
5316 }
5317
5318 public void thawInputDispatchingLw() {
5319 if (mInputDispatchFrozen) {
5320 if (DEBUG_INPUT) {
5321 Slog.v(TAG, "Thawing input dispatching");
5322 }
5323
5324 mInputDispatchFrozen = false;
5325 updateInputDispatchModeLw();
5326 }
5327 }
5328
5329 public void setEventDispatchingLw(boolean enabled) {
5330 if (mInputDispatchEnabled != enabled) {
5331 if (DEBUG_INPUT) {
5332 Slog.v(TAG, "Setting event dispatching to " + enabled);
5333 }
5334
5335 mInputDispatchEnabled = enabled;
5336 updateInputDispatchModeLw();
5337 }
5338 }
5339
5340 private void updateInputDispatchModeLw() {
5341 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5342 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345 public void pauseKeyDispatching(IBinder _token) {
5346 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5347 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005348 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005349 }
5350
5351 synchronized (mWindowMap) {
5352 WindowToken token = mTokenMap.get(_token);
5353 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005354 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005355 }
5356 }
5357 }
5358
5359 public void resumeKeyDispatching(IBinder _token) {
5360 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5361 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005362 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005363 }
5364
5365 synchronized (mWindowMap) {
5366 WindowToken token = mTokenMap.get(_token);
5367 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005368 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005369 }
5370 }
5371 }
5372
5373 public void setEventDispatching(boolean enabled) {
5374 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5375 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005376 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005377 }
5378
5379 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005380 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005381 }
5382 }
Romain Guy06882f82009-06-10 13:36:04 -07005383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005384 /**
5385 * Injects a keystroke event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005386 * Even when sync is false, this method may block while waiting for current
5387 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005388 *
5389 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005390 * {@link SystemClock#uptimeMillis()} as the timebase.)
5391 * @param sync If true, wait for the event to be completed before returning to the caller.
5392 * @return Returns true if event was dispatched, false if it was dropped for any reason
5393 */
5394 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5395 long downTime = ev.getDownTime();
5396 long eventTime = ev.getEventTime();
5397
5398 int action = ev.getAction();
5399 int code = ev.getKeyCode();
5400 int repeatCount = ev.getRepeatCount();
5401 int metaState = ev.getMetaState();
5402 int deviceId = ev.getDeviceId();
5403 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005404 int source = ev.getSource();
5405
5406 if (source == InputDevice.SOURCE_UNKNOWN) {
5407 source = InputDevice.SOURCE_KEYBOARD;
5408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005409
5410 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5411 if (downTime == 0) downTime = eventTime;
5412
5413 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005414 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005415
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005416 final int pid = Binder.getCallingPid();
5417 final int uid = Binder.getCallingUid();
5418 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005419
Jeff Brown6ec402b2010-07-28 15:48:59 -07005420 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5421 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5422 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5423 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005424
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005425 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005426 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 }
5428
5429 /**
5430 * Inject a pointer (touch) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005431 * Even when sync is false, this method may block while waiting for current
5432 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005433 *
5434 * @param ev A motion event describing the pointer (touch) action. (As noted in
5435 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 * {@link SystemClock#uptimeMillis()} as the timebase.)
5437 * @param sync If true, wait for the event to be completed before returning to the caller.
5438 * @return Returns true if event was dispatched, false if it was dropped for any reason
5439 */
5440 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005441 final int pid = Binder.getCallingPid();
5442 final int uid = Binder.getCallingUid();
5443 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005444
Jeff Brownc5ed5912010-07-14 18:48:53 -07005445 MotionEvent newEvent = MotionEvent.obtain(ev);
5446 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5447 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5448 }
5449
Jeff Brown6ec402b2010-07-28 15:48:59 -07005450 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5451 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5452 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5453 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005454
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005455 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005456 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005457 }
Romain Guy06882f82009-06-10 13:36:04 -07005458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005459 /**
5460 * Inject a trackball (navigation device) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005461 * Even when sync is false, this method may block while waiting for current
5462 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005463 *
5464 * @param ev A motion event describing the trackball action. (As noted in
5465 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005466 * {@link SystemClock#uptimeMillis()} as the timebase.)
5467 * @param sync If true, wait for the event to be completed before returning to the caller.
5468 * @return Returns true if event was dispatched, false if it was dropped for any reason
5469 */
5470 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005471 final int pid = Binder.getCallingPid();
5472 final int uid = Binder.getCallingUid();
5473 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005474
Jeff Brownc5ed5912010-07-14 18:48:53 -07005475 MotionEvent newEvent = MotionEvent.obtain(ev);
5476 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5477 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5478 }
5479
Jeff Brown6ec402b2010-07-28 15:48:59 -07005480 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5481 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5482 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5483 INJECTION_TIMEOUT_MILLIS);
5484
5485 Binder.restoreCallingIdentity(ident);
5486 return reportInjectionResult(result);
5487 }
5488
5489 /**
5490 * Inject an input event into the UI without waiting for dispatch to commence.
5491 * This variant is useful for fire-and-forget input event injection. It does not
5492 * block any longer than it takes to enqueue the input event.
5493 *
5494 * @param ev An input event. (Be sure to set the input source correctly.)
5495 * @return Returns true if event was dispatched, false if it was dropped for any reason
5496 */
5497 public boolean injectInputEventNoWait(InputEvent ev) {
5498 final int pid = Binder.getCallingPid();
5499 final int uid = Binder.getCallingUid();
5500 final long ident = Binder.clearCallingIdentity();
5501
5502 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5503 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5504 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005505
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005506 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005507 return reportInjectionResult(result);
5508 }
5509
5510 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005511 switch (result) {
5512 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5513 Slog.w(TAG, "Input event injection permission denied.");
5514 throw new SecurityException(
5515 "Injecting to another application requires INJECT_EVENTS permission");
5516 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005517 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005518 return true;
5519 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5520 Slog.w(TAG, "Input event injection timed out.");
5521 return false;
5522 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5523 default:
5524 Slog.w(TAG, "Input event injection failed.");
5525 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005527 }
Romain Guy06882f82009-06-10 13:36:04 -07005528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005529 private WindowState getFocusedWindow() {
5530 synchronized (mWindowMap) {
5531 return getFocusedWindowLocked();
5532 }
5533 }
5534
5535 private WindowState getFocusedWindowLocked() {
5536 return mCurrentFocus;
5537 }
Romain Guy06882f82009-06-10 13:36:04 -07005538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 public boolean detectSafeMode() {
5540 mSafeMode = mPolicy.detectSafeMode();
5541 return mSafeMode;
5542 }
Romain Guy06882f82009-06-10 13:36:04 -07005543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005544 public void systemReady() {
5545 mPolicy.systemReady();
5546 }
Romain Guy06882f82009-06-10 13:36:04 -07005547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005548 // -------------------------------------------------------------
5549 // Client Session State
5550 // -------------------------------------------------------------
5551
5552 private final class Session extends IWindowSession.Stub
5553 implements IBinder.DeathRecipient {
5554 final IInputMethodClient mClient;
5555 final IInputContext mInputContext;
5556 final int mUid;
5557 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005558 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005559 SurfaceSession mSurfaceSession;
5560 int mNumWindow = 0;
5561 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005563 public Session(IInputMethodClient client, IInputContext inputContext) {
5564 mClient = client;
5565 mInputContext = inputContext;
5566 mUid = Binder.getCallingUid();
5567 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005568 StringBuilder sb = new StringBuilder();
5569 sb.append("Session{");
5570 sb.append(Integer.toHexString(System.identityHashCode(this)));
5571 sb.append(" uid ");
5572 sb.append(mUid);
5573 sb.append("}");
5574 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005576 synchronized (mWindowMap) {
5577 if (mInputMethodManager == null && mHaveInputMethods) {
5578 IBinder b = ServiceManager.getService(
5579 Context.INPUT_METHOD_SERVICE);
5580 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5581 }
5582 }
5583 long ident = Binder.clearCallingIdentity();
5584 try {
5585 // Note: it is safe to call in to the input method manager
5586 // here because we are not holding our lock.
5587 if (mInputMethodManager != null) {
5588 mInputMethodManager.addClient(client, inputContext,
5589 mUid, mPid);
5590 } else {
5591 client.setUsingInputMethod(false);
5592 }
5593 client.asBinder().linkToDeath(this, 0);
5594 } catch (RemoteException e) {
5595 // The caller has died, so we can just forget about this.
5596 try {
5597 if (mInputMethodManager != null) {
5598 mInputMethodManager.removeClient(client);
5599 }
5600 } catch (RemoteException ee) {
5601 }
5602 } finally {
5603 Binder.restoreCallingIdentity(ident);
5604 }
5605 }
Romain Guy06882f82009-06-10 13:36:04 -07005606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005607 @Override
5608 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5609 throws RemoteException {
5610 try {
5611 return super.onTransact(code, data, reply, flags);
5612 } catch (RuntimeException e) {
5613 // Log all 'real' exceptions thrown to the caller
5614 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005615 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 }
5617 throw e;
5618 }
5619 }
5620
5621 public void binderDied() {
5622 // Note: it is safe to call in to the input method manager
5623 // here because we are not holding our lock.
5624 try {
5625 if (mInputMethodManager != null) {
5626 mInputMethodManager.removeClient(mClient);
5627 }
5628 } catch (RemoteException e) {
5629 }
5630 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005631 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005632 mClientDead = true;
5633 killSessionLocked();
5634 }
5635 }
5636
5637 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005638 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5639 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5640 outInputChannel);
5641 }
5642
5643 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005644 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005645 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005646 }
Romain Guy06882f82009-06-10 13:36:04 -07005647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005648 public void remove(IWindow window) {
5649 removeWindow(this, window);
5650 }
Romain Guy06882f82009-06-10 13:36:04 -07005651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005652 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5653 int requestedWidth, int requestedHeight, int viewFlags,
5654 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005655 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005656 return relayoutWindow(this, window, attrs,
5657 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005658 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005659 }
Romain Guy06882f82009-06-10 13:36:04 -07005660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005661 public void setTransparentRegion(IWindow window, Region region) {
5662 setTransparentRegionWindow(this, window, region);
5663 }
Romain Guy06882f82009-06-10 13:36:04 -07005664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005665 public void setInsets(IWindow window, int touchableInsets,
5666 Rect contentInsets, Rect visibleInsets) {
5667 setInsetsWindow(this, window, touchableInsets, contentInsets,
5668 visibleInsets);
5669 }
Romain Guy06882f82009-06-10 13:36:04 -07005670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005671 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5672 getWindowDisplayFrame(this, window, outDisplayFrame);
5673 }
Romain Guy06882f82009-06-10 13:36:04 -07005674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005675 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005676 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005677 TAG, "IWindow finishDrawing called for " + window);
5678 finishDrawingWindow(this, window);
5679 }
5680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005681 public void setInTouchMode(boolean mode) {
5682 synchronized(mWindowMap) {
5683 mInTouchMode = mode;
5684 }
5685 }
5686
5687 public boolean getInTouchMode() {
5688 synchronized(mWindowMap) {
5689 return mInTouchMode;
5690 }
5691 }
5692
5693 public boolean performHapticFeedback(IWindow window, int effectId,
5694 boolean always) {
5695 synchronized(mWindowMap) {
5696 long ident = Binder.clearCallingIdentity();
5697 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005698 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005699 windowForClientLocked(this, window, true),
5700 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005701 } finally {
5702 Binder.restoreCallingIdentity(ident);
5703 }
5704 }
5705 }
Romain Guy06882f82009-06-10 13:36:04 -07005706
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005707 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005708 synchronized(mWindowMap) {
5709 long ident = Binder.clearCallingIdentity();
5710 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005711 setWindowWallpaperPositionLocked(
5712 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005713 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005714 } finally {
5715 Binder.restoreCallingIdentity(ident);
5716 }
5717 }
5718 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005719
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005720 public void wallpaperOffsetsComplete(IBinder window) {
5721 WindowManagerService.this.wallpaperOffsetsComplete(window);
5722 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005723
Dianne Hackborn75804932009-10-20 20:15:20 -07005724 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5725 int z, Bundle extras, boolean sync) {
5726 synchronized(mWindowMap) {
5727 long ident = Binder.clearCallingIdentity();
5728 try {
5729 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005730 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005731 action, x, y, z, extras, sync);
5732 } finally {
5733 Binder.restoreCallingIdentity(ident);
5734 }
5735 }
5736 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005737
Dianne Hackborn75804932009-10-20 20:15:20 -07005738 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5739 WindowManagerService.this.wallpaperCommandComplete(window, result);
5740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005742 void windowAddedLocked() {
5743 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005744 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005745 TAG, "First window added to " + this + ", creating SurfaceSession");
5746 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005747 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005748 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005749 mSessions.add(this);
5750 }
5751 mNumWindow++;
5752 }
5753
5754 void windowRemovedLocked() {
5755 mNumWindow--;
5756 killSessionLocked();
5757 }
Romain Guy06882f82009-06-10 13:36:04 -07005758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005759 void killSessionLocked() {
5760 if (mNumWindow <= 0 && mClientDead) {
5761 mSessions.remove(this);
5762 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005763 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005764 TAG, "Last window removed from " + this
5765 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005766 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005767 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005768 try {
5769 mSurfaceSession.kill();
5770 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005771 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005772 + mSurfaceSession + " in session " + this
5773 + ": " + e.toString());
5774 }
5775 mSurfaceSession = null;
5776 }
5777 }
5778 }
Romain Guy06882f82009-06-10 13:36:04 -07005779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005780 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005781 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5782 pw.print(" mClientDead="); pw.print(mClientDead);
5783 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005784 }
5785
5786 @Override
5787 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005788 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005789 }
5790 }
5791
5792 // -------------------------------------------------------------
5793 // Client Window State
5794 // -------------------------------------------------------------
5795
5796 private final class WindowState implements WindowManagerPolicy.WindowState {
5797 final Session mSession;
5798 final IWindow mClient;
5799 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005800 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005801 AppWindowToken mAppToken;
5802 AppWindowToken mTargetAppToken;
5803 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5804 final DeathRecipient mDeathRecipient;
5805 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005806 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005807 final int mBaseLayer;
5808 final int mSubLayer;
5809 final boolean mLayoutAttached;
5810 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005811 final boolean mIsWallpaper;
5812 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005813 int mViewVisibility;
5814 boolean mPolicyVisibility = true;
5815 boolean mPolicyVisibilityAfterAnim = true;
5816 boolean mAppFreezing;
5817 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005818 boolean mReportDestroySurface;
5819 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005820 boolean mAttachedHidden; // is our parent window hidden?
5821 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005822 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005823 int mRequestedWidth;
5824 int mRequestedHeight;
5825 int mLastRequestedWidth;
5826 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005827 int mLayer;
5828 int mAnimLayer;
5829 int mLastLayer;
5830 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005831 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005832 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005833
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005834 int mLayoutSeq = -1;
5835
5836 Configuration mConfiguration = null;
5837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 // Actual frame shown on-screen (may be modified by animation)
5839 final Rect mShownFrame = new Rect();
5840 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005842 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005843 * Set when we have changed the size of the surface, to know that
5844 * we must tell them application to resize (and thus redraw itself).
5845 */
5846 boolean mSurfaceResized;
5847
5848 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005849 * Insets that determine the actually visible area
5850 */
5851 final Rect mVisibleInsets = new Rect();
5852 final Rect mLastVisibleInsets = new Rect();
5853 boolean mVisibleInsetsChanged;
5854
5855 /**
5856 * Insets that are covered by system windows
5857 */
5858 final Rect mContentInsets = new Rect();
5859 final Rect mLastContentInsets = new Rect();
5860 boolean mContentInsetsChanged;
5861
5862 /**
5863 * Set to true if we are waiting for this window to receive its
5864 * given internal insets before laying out other windows based on it.
5865 */
5866 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005868 /**
5869 * These are the content insets that were given during layout for
5870 * this window, to be applied to windows behind it.
5871 */
5872 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005874 /**
5875 * These are the visible insets that were given during layout for
5876 * this window, to be applied to windows behind it.
5877 */
5878 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 /**
5881 * Flag indicating whether the touchable region should be adjusted by
5882 * the visible insets; if false the area outside the visible insets is
5883 * NOT touchable, so we must use those to adjust the frame during hit
5884 * tests.
5885 */
5886 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005888 // Current transformation being applied.
5889 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5890 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5891 float mHScale=1, mVScale=1;
5892 float mLastHScale=1, mLastVScale=1;
5893 final Matrix mTmpMatrix = new Matrix();
5894
5895 // "Real" frame that the application sees.
5896 final Rect mFrame = new Rect();
5897 final Rect mLastFrame = new Rect();
5898
5899 final Rect mContainingFrame = new Rect();
5900 final Rect mDisplayFrame = new Rect();
5901 final Rect mContentFrame = new Rect();
5902 final Rect mVisibleFrame = new Rect();
5903
5904 float mShownAlpha = 1;
5905 float mAlpha = 1;
5906 float mLastAlpha = 1;
5907
5908 // Set to true if, when the window gets displayed, it should perform
5909 // an enter animation.
5910 boolean mEnterAnimationPending;
5911
5912 // Currently running animation.
5913 boolean mAnimating;
5914 boolean mLocalAnimating;
5915 Animation mAnimation;
5916 boolean mAnimationIsEntrance;
5917 boolean mHasTransformation;
5918 boolean mHasLocalTransformation;
5919 final Transformation mTransformation = new Transformation();
5920
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005921 // If a window showing a wallpaper: the requested offset for the
5922 // wallpaper; if a wallpaper window: the currently applied offset.
5923 float mWallpaperX = -1;
5924 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005925
5926 // If a window showing a wallpaper: what fraction of the offset
5927 // range corresponds to a full virtual screen.
5928 float mWallpaperXStep = -1;
5929 float mWallpaperYStep = -1;
5930
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005931 // Wallpaper windows: pixels offset based on above variables.
5932 int mXOffset;
5933 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005935 // This is set after IWindowSession.relayout() has been called at
5936 // least once for the window. It allows us to detect the situation
5937 // where we don't yet have a surface, but should have one soon, so
5938 // we can give the window focus before waiting for the relayout.
5939 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07005940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005941 // This is set after the Surface has been created but before the
5942 // window has been drawn. During this time the surface is hidden.
5943 boolean mDrawPending;
5944
5945 // This is set after the window has finished drawing for the first
5946 // time but before its surface is shown. The surface will be
5947 // displayed when the next layout is run.
5948 boolean mCommitDrawPending;
5949
5950 // This is set during the time after the window's drawing has been
5951 // committed, and before its surface is actually shown. It is used
5952 // to delay showing the surface until all windows in a token are ready
5953 // to be shown.
5954 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07005955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005956 // Set when the window has been shown in the screen the first time.
5957 boolean mHasDrawn;
5958
5959 // Currently running an exit animation?
5960 boolean mExiting;
5961
5962 // Currently on the mDestroySurface list?
5963 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07005964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005965 // Completely remove from window manager after exit animation?
5966 boolean mRemoveOnExit;
5967
5968 // Set when the orientation is changing and this window has not yet
5969 // been updated for the new orientation.
5970 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07005971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005972 // Is this window now (or just being) removed?
5973 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07005974
Dianne Hackborn16064f92010-03-25 00:47:24 -07005975 // For debugging, this is the last information given to the surface flinger.
5976 boolean mSurfaceShown;
5977 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
5978 int mSurfaceLayer;
5979 float mSurfaceAlpha;
5980
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005981 // Input channel
5982 InputChannel mInputChannel;
5983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005984 WindowState(Session s, IWindow c, WindowToken token,
5985 WindowState attachedWindow, WindowManager.LayoutParams a,
5986 int viewVisibility) {
5987 mSession = s;
5988 mClient = c;
5989 mToken = token;
5990 mAttrs.copyFrom(a);
5991 mViewVisibility = viewVisibility;
5992 DeathRecipient deathRecipient = new DeathRecipient();
5993 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08005994 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005995 TAG, "Window " + this + " client=" + c.asBinder()
5996 + " token=" + token + " (" + mAttrs.token + ")");
5997 try {
5998 c.asBinder().linkToDeath(deathRecipient, 0);
5999 } catch (RemoteException e) {
6000 mDeathRecipient = null;
6001 mAttachedWindow = null;
6002 mLayoutAttached = false;
6003 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006004 mIsWallpaper = false;
6005 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006006 mBaseLayer = 0;
6007 mSubLayer = 0;
6008 return;
6009 }
6010 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006012 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6013 mAttrs.type <= LAST_SUB_WINDOW)) {
6014 // The multiplier here is to reserve space for multiple
6015 // windows in the same type layer.
6016 mBaseLayer = mPolicy.windowTypeToLayerLw(
6017 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6018 + TYPE_LAYER_OFFSET;
6019 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6020 mAttachedWindow = attachedWindow;
6021 mAttachedWindow.mChildWindows.add(this);
6022 mLayoutAttached = mAttrs.type !=
6023 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6024 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6025 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006026 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6027 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006028 } else {
6029 // The multiplier here is to reserve space for multiple
6030 // windows in the same type layer.
6031 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6032 * TYPE_LAYER_MULTIPLIER
6033 + TYPE_LAYER_OFFSET;
6034 mSubLayer = 0;
6035 mAttachedWindow = null;
6036 mLayoutAttached = false;
6037 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6038 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006039 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6040 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006041 }
6042
6043 WindowState appWin = this;
6044 while (appWin.mAttachedWindow != null) {
6045 appWin = mAttachedWindow;
6046 }
6047 WindowToken appToken = appWin.mToken;
6048 while (appToken.appWindowToken == null) {
6049 WindowToken parent = mTokenMap.get(appToken.token);
6050 if (parent == null || appToken == parent) {
6051 break;
6052 }
6053 appToken = parent;
6054 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006055 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006056 mAppToken = appToken.appWindowToken;
6057
6058 mSurface = null;
6059 mRequestedWidth = 0;
6060 mRequestedHeight = 0;
6061 mLastRequestedWidth = 0;
6062 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006063 mXOffset = 0;
6064 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006065 mLayer = 0;
6066 mAnimLayer = 0;
6067 mLastLayer = 0;
6068 }
6069
6070 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006071 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 TAG, "Attaching " + this + " token=" + mToken
6073 + ", list=" + mToken.windows);
6074 mSession.windowAddedLocked();
6075 }
6076
6077 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6078 mHaveFrame = true;
6079
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006080 final Rect container = mContainingFrame;
6081 container.set(pf);
6082
6083 final Rect display = mDisplayFrame;
6084 display.set(df);
6085
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006086 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006087 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006088 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6089 display.intersect(mCompatibleScreenFrame);
6090 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006091 }
6092
6093 final int pw = container.right - container.left;
6094 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006095
6096 int w,h;
6097 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6098 w = mAttrs.width < 0 ? pw : mAttrs.width;
6099 h = mAttrs.height< 0 ? ph : mAttrs.height;
6100 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006101 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6102 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006103 }
Romain Guy06882f82009-06-10 13:36:04 -07006104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006105 final Rect content = mContentFrame;
6106 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006108 final Rect visible = mVisibleFrame;
6109 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006111 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006112 final int fw = frame.width();
6113 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006115 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6116 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6117
6118 Gravity.apply(mAttrs.gravity, w, h, container,
6119 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6120 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6121
6122 //System.out.println("Out: " + mFrame);
6123
6124 // Now make sure the window fits in the overall display.
6125 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006127 // Make sure the content and visible frames are inside of the
6128 // final window frame.
6129 if (content.left < frame.left) content.left = frame.left;
6130 if (content.top < frame.top) content.top = frame.top;
6131 if (content.right > frame.right) content.right = frame.right;
6132 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6133 if (visible.left < frame.left) visible.left = frame.left;
6134 if (visible.top < frame.top) visible.top = frame.top;
6135 if (visible.right > frame.right) visible.right = frame.right;
6136 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 final Rect contentInsets = mContentInsets;
6139 contentInsets.left = content.left-frame.left;
6140 contentInsets.top = content.top-frame.top;
6141 contentInsets.right = frame.right-content.right;
6142 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 final Rect visibleInsets = mVisibleInsets;
6145 visibleInsets.left = visible.left-frame.left;
6146 visibleInsets.top = visible.top-frame.top;
6147 visibleInsets.right = frame.right-visible.right;
6148 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006149
Dianne Hackborn284ac932009-08-28 10:34:25 -07006150 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6151 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006152 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006153 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155 if (localLOGV) {
6156 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6157 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006158 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006159 + mRequestedWidth + ", mRequestedheight="
6160 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6161 + "): frame=" + mFrame.toShortString()
6162 + " ci=" + contentInsets.toShortString()
6163 + " vi=" + visibleInsets.toShortString());
6164 //}
6165 }
6166 }
Romain Guy06882f82009-06-10 13:36:04 -07006167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 public Rect getFrameLw() {
6169 return mFrame;
6170 }
6171
6172 public Rect getShownFrameLw() {
6173 return mShownFrame;
6174 }
6175
6176 public Rect getDisplayFrameLw() {
6177 return mDisplayFrame;
6178 }
6179
6180 public Rect getContentFrameLw() {
6181 return mContentFrame;
6182 }
6183
6184 public Rect getVisibleFrameLw() {
6185 return mVisibleFrame;
6186 }
6187
6188 public boolean getGivenInsetsPendingLw() {
6189 return mGivenInsetsPending;
6190 }
6191
6192 public Rect getGivenContentInsetsLw() {
6193 return mGivenContentInsets;
6194 }
Romain Guy06882f82009-06-10 13:36:04 -07006195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 public Rect getGivenVisibleInsetsLw() {
6197 return mGivenVisibleInsets;
6198 }
Romain Guy06882f82009-06-10 13:36:04 -07006199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006200 public WindowManager.LayoutParams getAttrs() {
6201 return mAttrs;
6202 }
6203
6204 public int getSurfaceLayer() {
6205 return mLayer;
6206 }
Romain Guy06882f82009-06-10 13:36:04 -07006207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006208 public IApplicationToken getAppToken() {
6209 return mAppToken != null ? mAppToken.appToken : null;
6210 }
Jeff Brown349703e2010-06-22 01:27:15 -07006211
6212 public long getInputDispatchingTimeoutNanos() {
6213 return mAppToken != null
6214 ? mAppToken.inputDispatchingTimeoutNanos
6215 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006217
6218 public boolean hasAppShownWindows() {
6219 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6220 }
6221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006222 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006223 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006224 TAG, "Setting animation in " + this + ": " + anim);
6225 mAnimating = false;
6226 mLocalAnimating = false;
6227 mAnimation = anim;
6228 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6229 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6230 }
6231
6232 public void clearAnimation() {
6233 if (mAnimation != null) {
6234 mAnimating = true;
6235 mLocalAnimating = false;
6236 mAnimation = null;
6237 }
6238 }
Romain Guy06882f82009-06-10 13:36:04 -07006239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006240 Surface createSurfaceLocked() {
6241 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006242 mReportDestroySurface = false;
6243 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006244 mDrawPending = true;
6245 mCommitDrawPending = false;
6246 mReadyToShow = false;
6247 if (mAppToken != null) {
6248 mAppToken.allDrawn = false;
6249 }
6250
6251 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006252 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006253 flags |= Surface.PUSH_BUFFERS;
6254 }
6255
6256 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6257 flags |= Surface.SECURE;
6258 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006259 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006260 TAG, "Creating surface in session "
6261 + mSession.mSurfaceSession + " window " + this
6262 + " w=" + mFrame.width()
6263 + " h=" + mFrame.height() + " format="
6264 + mAttrs.format + " flags=" + flags);
6265
6266 int w = mFrame.width();
6267 int h = mFrame.height();
6268 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6269 // for a scaled surface, we always want the requested
6270 // size.
6271 w = mRequestedWidth;
6272 h = mRequestedHeight;
6273 }
6274
Romain Guy9825ec62009-10-01 00:58:09 -07006275 // Something is wrong and SurfaceFlinger will not like this,
6276 // try to revert to sane values
6277 if (w <= 0) w = 1;
6278 if (h <= 0) h = 1;
6279
Dianne Hackborn16064f92010-03-25 00:47:24 -07006280 mSurfaceShown = false;
6281 mSurfaceLayer = 0;
6282 mSurfaceAlpha = 1;
6283 mSurfaceX = 0;
6284 mSurfaceY = 0;
6285 mSurfaceW = w;
6286 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006287 try {
6288 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006289 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006290 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006291 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006292 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006293 + mSurface + " IN SESSION "
6294 + mSession.mSurfaceSession
6295 + ": pid=" + mSession.mPid + " format="
6296 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006297 + Integer.toHexString(flags)
6298 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006299 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006300 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006301 reclaimSomeSurfaceMemoryLocked(this, "create");
6302 return null;
6303 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006304 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305 return null;
6306 }
Romain Guy06882f82009-06-10 13:36:04 -07006307
Joe Onorato8a9b2202010-02-26 18:56:32 -08006308 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006309 TAG, "Got surface: " + mSurface
6310 + ", set left=" + mFrame.left + " top=" + mFrame.top
6311 + ", animLayer=" + mAnimLayer);
6312 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006313 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006314 if (SHOW_TRANSACTIONS) logSurface(this,
6315 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6316 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6317 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006318 }
6319 Surface.openTransaction();
6320 try {
6321 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006322 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006323 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006324 mSurface.setPosition(mSurfaceX, mSurfaceY);
6325 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006327 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006328 mSurface.hide();
6329 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006330 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 mSurface.setFlags(Surface.SURFACE_DITHER,
6332 Surface.SURFACE_DITHER);
6333 }
6334 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006335 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6337 }
6338 mLastHidden = true;
6339 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006340 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006341 Surface.closeTransaction();
6342 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006343 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006344 TAG, "Created surface " + this);
6345 }
6346 return mSurface;
6347 }
Romain Guy06882f82009-06-10 13:36:04 -07006348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006349 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006350 if (mAppToken != null && this == mAppToken.startingWindow) {
6351 mAppToken.startingDisplayed = false;
6352 }
Romain Guy06882f82009-06-10 13:36:04 -07006353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006355 mDrawPending = false;
6356 mCommitDrawPending = false;
6357 mReadyToShow = false;
6358
6359 int i = mChildWindows.size();
6360 while (i > 0) {
6361 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006362 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006363 c.mAttachedHidden = true;
6364 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006365
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006366 if (mReportDestroySurface) {
6367 mReportDestroySurface = false;
6368 mSurfacePendingDestroy = true;
6369 try {
6370 mClient.dispatchGetNewSurface();
6371 // We'll really destroy on the next time around.
6372 return;
6373 } catch (RemoteException e) {
6374 }
6375 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006377 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006378 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006379 RuntimeException e = null;
6380 if (!HIDE_STACK_CRAWLS) {
6381 e = new RuntimeException();
6382 e.fillInStackTrace();
6383 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006384 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006385 + mSurface + ", session " + mSession, e);
6386 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006388 RuntimeException e = null;
6389 if (!HIDE_STACK_CRAWLS) {
6390 e = new RuntimeException();
6391 e.fillInStackTrace();
6392 }
6393 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006395 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006397 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006398 + " surface " + mSurface + " session " + mSession
6399 + ": " + e.toString());
6400 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006401
Dianne Hackborn16064f92010-03-25 00:47:24 -07006402 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006403 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006404 }
6405 }
6406
6407 boolean finishDrawingLocked() {
6408 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006409 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 TAG, "finishDrawingLocked: " + mSurface);
6411 mCommitDrawPending = true;
6412 mDrawPending = false;
6413 return true;
6414 }
6415 return false;
6416 }
6417
6418 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006419 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006420 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006422 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006423 }
6424 mCommitDrawPending = false;
6425 mReadyToShow = true;
6426 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6427 final AppWindowToken atoken = mAppToken;
6428 if (atoken == null || atoken.allDrawn || starting) {
6429 performShowLocked();
6430 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006431 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 }
6433
6434 // This must be called while inside a transaction.
6435 boolean performShowLocked() {
6436 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006437 RuntimeException e = null;
6438 if (!HIDE_STACK_CRAWLS) {
6439 e = new RuntimeException();
6440 e.fillInStackTrace();
6441 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006442 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6444 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6445 }
6446 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006447 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6448 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006449 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006450 + " during animation: policyVis=" + mPolicyVisibility
6451 + " attHidden=" + mAttachedHidden
6452 + " tok.hiddenRequested="
6453 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006454 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006455 + (mAppToken != null ? mAppToken.hidden : false)
6456 + " animating=" + mAnimating
6457 + " tok animating="
6458 + (mAppToken != null ? mAppToken.animating : false));
6459 if (!showSurfaceRobustlyLocked(this)) {
6460 return false;
6461 }
6462 mLastAlpha = -1;
6463 mHasDrawn = true;
6464 mLastHidden = false;
6465 mReadyToShow = false;
6466 enableScreenIfNeededLocked();
6467
6468 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006469
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 int i = mChildWindows.size();
6471 while (i > 0) {
6472 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006473 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006474 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006475 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006476 if (c.mSurface != null) {
6477 c.performShowLocked();
6478 // It hadn't been shown, which means layout not
6479 // performed on it, so now we want to make sure to
6480 // do a layout. If called from within the transaction
6481 // loop, this will cause it to restart with a new
6482 // layout.
6483 mLayoutNeeded = true;
6484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006485 }
6486 }
Romain Guy06882f82009-06-10 13:36:04 -07006487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 if (mAttrs.type != TYPE_APPLICATION_STARTING
6489 && mAppToken != null) {
6490 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006491
Dianne Hackborn248b1882009-09-16 16:46:44 -07006492 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006493 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006494 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006495 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006496 // If this initial window is animating, stop it -- we
6497 // will do an animation to reveal it from behind the
6498 // starting window, so there is no need for it to also
6499 // be doing its own stuff.
6500 if (mAnimation != null) {
6501 mAnimation = null;
6502 // Make sure we clean up the animation.
6503 mAnimating = true;
6504 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006505 mFinishedStarting.add(mAppToken);
6506 mH.sendEmptyMessage(H.FINISHED_STARTING);
6507 }
6508 mAppToken.updateReportedVisibilityLocked();
6509 }
6510 }
6511 return true;
6512 }
Romain Guy06882f82009-06-10 13:36:04 -07006513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006514 // This must be called while inside a transaction. Returns true if
6515 // there is more animation to run.
6516 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006517 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006518 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6521 mHasTransformation = true;
6522 mHasLocalTransformation = true;
6523 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006524 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006525 TAG, "Starting animation in " + this +
6526 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6527 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6528 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6529 mAnimation.setStartTime(currentTime);
6530 mLocalAnimating = true;
6531 mAnimating = true;
6532 }
6533 mTransformation.clear();
6534 final boolean more = mAnimation.getTransformation(
6535 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006536 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006537 TAG, "Stepped animation in " + this +
6538 ": more=" + more + ", xform=" + mTransformation);
6539 if (more) {
6540 // we're not done!
6541 return true;
6542 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006543 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006544 TAG, "Finished animation in " + this +
6545 " @ " + currentTime);
6546 mAnimation = null;
6547 //WindowManagerService.this.dump();
6548 }
6549 mHasLocalTransformation = false;
6550 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006551 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006552 // When our app token is animating, we kind-of pretend like
6553 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6554 // part of this check means that we will only do this if
6555 // our window is not currently exiting, or it is not
6556 // locally animating itself. The idea being that one that
6557 // is exiting and doing a local animation should be removed
6558 // once that animation is done.
6559 mAnimating = true;
6560 mHasTransformation = true;
6561 mTransformation.clear();
6562 return false;
6563 } else if (mHasTransformation) {
6564 // Little trick to get through the path below to act like
6565 // we have finished an animation.
6566 mAnimating = true;
6567 } else if (isAnimating()) {
6568 mAnimating = true;
6569 }
6570 } else if (mAnimation != null) {
6571 // If the display is frozen, and there is a pending animation,
6572 // clear it and make sure we run the cleanup code.
6573 mAnimating = true;
6574 mLocalAnimating = true;
6575 mAnimation = null;
6576 }
Romain Guy06882f82009-06-10 13:36:04 -07006577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006578 if (!mAnimating && !mLocalAnimating) {
6579 return false;
6580 }
6581
Joe Onorato8a9b2202010-02-26 18:56:32 -08006582 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 TAG, "Animation done in " + this + ": exiting=" + mExiting
6584 + ", reportedVisible="
6585 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006587 mAnimating = false;
6588 mLocalAnimating = false;
6589 mAnimation = null;
6590 mAnimLayer = mLayer;
6591 if (mIsImWindow) {
6592 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006593 } else if (mIsWallpaper) {
6594 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006595 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006596 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 + " anim layer: " + mAnimLayer);
6598 mHasTransformation = false;
6599 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006600 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6601 if (DEBUG_VISIBILITY) {
6602 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6603 + mPolicyVisibilityAfterAnim);
6604 }
6605 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6606 if (!mPolicyVisibility) {
6607 if (mCurrentFocus == this) {
6608 mFocusMayChange = true;
6609 }
6610 // Window is no longer visible -- make sure if we were waiting
6611 // for it to be displayed before enabling the display, that
6612 // we allow the display to be enabled now.
6613 enableScreenIfNeededLocked();
6614 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006616 mTransformation.clear();
6617 if (mHasDrawn
6618 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6619 && mAppToken != null
6620 && mAppToken.firstWindowDrawn
6621 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006622 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006623 + mToken + ": first real window done animating");
6624 mFinishedStarting.add(mAppToken);
6625 mH.sendEmptyMessage(H.FINISHED_STARTING);
6626 }
Romain Guy06882f82009-06-10 13:36:04 -07006627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006628 finishExit();
6629
6630 if (mAppToken != null) {
6631 mAppToken.updateReportedVisibilityLocked();
6632 }
6633
6634 return false;
6635 }
6636
6637 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006638 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006639 TAG, "finishExit in " + this
6640 + ": exiting=" + mExiting
6641 + " remove=" + mRemoveOnExit
6642 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006644 final int N = mChildWindows.size();
6645 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006646 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006647 }
Romain Guy06882f82009-06-10 13:36:04 -07006648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006649 if (!mExiting) {
6650 return;
6651 }
Romain Guy06882f82009-06-10 13:36:04 -07006652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006653 if (isWindowAnimating()) {
6654 return;
6655 }
6656
Joe Onorato8a9b2202010-02-26 18:56:32 -08006657 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006658 TAG, "Exit animation finished in " + this
6659 + ": remove=" + mRemoveOnExit);
6660 if (mSurface != null) {
6661 mDestroySurface.add(this);
6662 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006663 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006664 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006665 try {
6666 mSurface.hide();
6667 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006668 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006669 }
6670 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 }
6672 mExiting = false;
6673 if (mRemoveOnExit) {
6674 mPendingRemove.add(this);
6675 mRemoveOnExit = false;
6676 }
6677 }
Romain Guy06882f82009-06-10 13:36:04 -07006678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006679 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6680 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6681 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6682 if (dtdx < -.000001f || dtdx > .000001f) return false;
6683 if (dsdy < -.000001f || dsdy > .000001f) return false;
6684 return true;
6685 }
Romain Guy06882f82009-06-10 13:36:04 -07006686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006687 void computeShownFrameLocked() {
6688 final boolean selfTransformation = mHasLocalTransformation;
6689 Transformation attachedTransformation =
6690 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6691 ? mAttachedWindow.mTransformation : null;
6692 Transformation appTransformation =
6693 (mAppToken != null && mAppToken.hasTransformation)
6694 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006695
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006696 // Wallpapers are animated based on the "real" window they
6697 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006698 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006699 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006700 if (mWallpaperTarget.mHasLocalTransformation &&
6701 mWallpaperTarget.mAnimation != null &&
6702 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006703 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006704 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006705 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006706 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006707 }
6708 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006709 mWallpaperTarget.mAppToken.hasTransformation &&
6710 mWallpaperTarget.mAppToken.animation != null &&
6711 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006712 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006713 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006714 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006715 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006716 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006717 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006719 if (selfTransformation || attachedTransformation != null
6720 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006721 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006722 final Rect frame = mFrame;
6723 final float tmpFloats[] = mTmpFloats;
6724 final Matrix tmpMatrix = mTmpMatrix;
6725
6726 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006727 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006728 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006729 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006730 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006731 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006733 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006734 }
6735 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006736 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 }
6738
6739 // "convert" it into SurfaceFlinger's format
6740 // (a 2x2 matrix + an offset)
6741 // Here we must not transform the position of the surface
6742 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006743 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 tmpMatrix.getValues(tmpFloats);
6746 mDsDx = tmpFloats[Matrix.MSCALE_X];
6747 mDtDx = tmpFloats[Matrix.MSKEW_X];
6748 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6749 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006750 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6751 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006752 int w = frame.width();
6753 int h = frame.height();
6754 mShownFrame.set(x, y, x+w, y+h);
6755
6756 // Now set the alpha... but because our current hardware
6757 // can't do alpha transformation on a non-opaque surface,
6758 // turn it off if we are running an animation that is also
6759 // transforming since it is more important to have that
6760 // animation be smooth.
6761 mShownAlpha = mAlpha;
6762 if (!mLimitedAlphaCompositing
6763 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6764 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6765 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006766 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 if (selfTransformation) {
6768 mShownAlpha *= mTransformation.getAlpha();
6769 }
6770 if (attachedTransformation != null) {
6771 mShownAlpha *= attachedTransformation.getAlpha();
6772 }
6773 if (appTransformation != null) {
6774 mShownAlpha *= appTransformation.getAlpha();
6775 }
6776 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006777 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006778 }
Romain Guy06882f82009-06-10 13:36:04 -07006779
Joe Onorato8a9b2202010-02-26 18:56:32 -08006780 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006781 TAG, "Continuing animation in " + this +
6782 ": " + mShownFrame +
6783 ", alpha=" + mTransformation.getAlpha());
6784 return;
6785 }
Romain Guy06882f82009-06-10 13:36:04 -07006786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006787 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006788 if (mXOffset != 0 || mYOffset != 0) {
6789 mShownFrame.offset(mXOffset, mYOffset);
6790 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 mShownAlpha = mAlpha;
6792 mDsDx = 1;
6793 mDtDx = 0;
6794 mDsDy = 0;
6795 mDtDy = 1;
6796 }
Romain Guy06882f82009-06-10 13:36:04 -07006797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 /**
6799 * Is this window visible? It is not visible if there is no
6800 * surface, or we are in the process of running an exit animation
6801 * that will remove the surface, or its app token has been hidden.
6802 */
6803 public boolean isVisibleLw() {
6804 final AppWindowToken atoken = mAppToken;
6805 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6806 && (atoken == null || !atoken.hiddenRequested)
6807 && !mExiting && !mDestroying;
6808 }
6809
6810 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006811 * Like {@link #isVisibleLw}, but also counts a window that is currently
6812 * "hidden" behind the keyguard as visible. This allows us to apply
6813 * things like window flags that impact the keyguard.
6814 * XXX I am starting to think we need to have ANOTHER visibility flag
6815 * for this "hidden behind keyguard" state rather than overloading
6816 * mPolicyVisibility. Ungh.
6817 */
6818 public boolean isVisibleOrBehindKeyguardLw() {
6819 final AppWindowToken atoken = mAppToken;
6820 return mSurface != null && !mAttachedHidden
6821 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006822 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006823 && !mExiting && !mDestroying;
6824 }
6825
6826 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 * Is this window visible, ignoring its app token? It is not visible
6828 * if there is no surface, or we are in the process of running an exit animation
6829 * that will remove the surface.
6830 */
6831 public boolean isWinVisibleLw() {
6832 final AppWindowToken atoken = mAppToken;
6833 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6834 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6835 && !mExiting && !mDestroying;
6836 }
6837
6838 /**
6839 * The same as isVisible(), but follows the current hidden state of
6840 * the associated app token, not the pending requested hidden state.
6841 */
6842 boolean isVisibleNow() {
6843 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006844 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006845 }
6846
6847 /**
6848 * Same as isVisible(), but we also count it as visible between the
6849 * call to IWindowSession.add() and the first relayout().
6850 */
6851 boolean isVisibleOrAdding() {
6852 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006853 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006854 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6855 && mPolicyVisibility && !mAttachedHidden
6856 && (atoken == null || !atoken.hiddenRequested)
6857 && !mExiting && !mDestroying;
6858 }
6859
6860 /**
6861 * Is this window currently on-screen? It is on-screen either if it
6862 * is visible or it is currently running an animation before no longer
6863 * being visible.
6864 */
6865 boolean isOnScreen() {
6866 final AppWindowToken atoken = mAppToken;
6867 if (atoken != null) {
6868 return mSurface != null && mPolicyVisibility && !mDestroying
6869 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006870 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006871 } else {
6872 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006873 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006874 }
6875 }
Romain Guy06882f82009-06-10 13:36:04 -07006876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006877 /**
6878 * Like isOnScreen(), but we don't return true if the window is part
6879 * of a transition that has not yet been started.
6880 */
6881 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006882 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006883 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006884 return false;
6885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006886 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006887 final boolean animating = atoken != null
6888 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006889 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006890 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6891 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006892 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 }
6894
6895 /** Is the window or its container currently animating? */
6896 boolean isAnimating() {
6897 final WindowState attached = mAttachedWindow;
6898 final AppWindowToken atoken = mAppToken;
6899 return mAnimation != null
6900 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006901 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006902 (atoken.animation != null
6903 || atoken.inPendingTransaction));
6904 }
6905
6906 /** Is this window currently animating? */
6907 boolean isWindowAnimating() {
6908 return mAnimation != null;
6909 }
6910
6911 /**
6912 * Like isOnScreen, but returns false if the surface hasn't yet
6913 * been drawn.
6914 */
6915 public boolean isDisplayedLw() {
6916 final AppWindowToken atoken = mAppToken;
6917 return mSurface != null && mPolicyVisibility && !mDestroying
6918 && !mDrawPending && !mCommitDrawPending
6919 && ((!mAttachedHidden &&
6920 (atoken == null || !atoken.hiddenRequested))
6921 || mAnimating);
6922 }
6923
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006924 /**
6925 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006926 * complete UI in to. Note that this returns true if the orientation
6927 * is changing even if the window hasn't redrawn because we don't want
6928 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006929 */
6930 public boolean isDrawnLw() {
6931 final AppWindowToken atoken = mAppToken;
6932 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006933 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006934 }
6935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006936 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6937 boolean shownFrame, boolean onlyOpaque) {
6938 if (mSurface == null) {
6939 return false;
6940 }
6941 if (mAppToken != null && !mAppToken.appFullscreen) {
6942 return false;
6943 }
6944 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
6945 return false;
6946 }
6947 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006948
6949 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
6950 return frame.left <= mCompatibleScreenFrame.left &&
6951 frame.top <= mCompatibleScreenFrame.top &&
6952 frame.right >= mCompatibleScreenFrame.right &&
6953 frame.bottom >= mCompatibleScreenFrame.bottom;
6954 } else {
6955 return frame.left <= 0 && frame.top <= 0
6956 && frame.right >= screenWidth
6957 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006958 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 }
Romain Guy06882f82009-06-10 13:36:04 -07006960
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006961 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07006962 * Return true if the window is opaque and fully drawn. This indicates
6963 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006964 */
6965 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07006966 return (mAttrs.format == PixelFormat.OPAQUE
6967 || mAttrs.type == TYPE_WALLPAPER)
6968 && mSurface != null && mAnimation == null
6969 && (mAppToken == null || mAppToken.animation == null)
6970 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006971 }
6972
6973 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
6974 return
6975 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006976 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
6977 // only if it's visible
6978 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006979 // and only if the application fills the compatible screen
6980 mFrame.left <= mCompatibleScreenFrame.left &&
6981 mFrame.top <= mCompatibleScreenFrame.top &&
6982 mFrame.right >= mCompatibleScreenFrame.right &&
6983 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006984 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006985 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006986 }
6987
6988 boolean isFullscreen(int screenWidth, int screenHeight) {
6989 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006990 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006991 }
6992
6993 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07006994 disposeInputChannel();
6995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006996 if (mAttachedWindow != null) {
6997 mAttachedWindow.mChildWindows.remove(this);
6998 }
6999 destroySurfaceLocked();
7000 mSession.windowRemovedLocked();
7001 try {
7002 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7003 } catch (RuntimeException e) {
7004 // Ignore if it has already been removed (usually because
7005 // we are doing this as part of processing a death note.)
7006 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007007 }
7008
7009 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007010 if (mInputChannel != null) {
7011 mInputManager.unregisterInputChannel(mInputChannel);
7012
7013 mInputChannel.dispose();
7014 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007016 }
7017
7018 private class DeathRecipient implements IBinder.DeathRecipient {
7019 public void binderDied() {
7020 try {
7021 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007022 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007023 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007024 if (win != null) {
7025 removeWindowLocked(mSession, win);
7026 }
7027 }
7028 } catch (IllegalArgumentException ex) {
7029 // This will happen if the window has already been
7030 // removed.
7031 }
7032 }
7033 }
7034
7035 /** Returns true if this window desires key events. */
7036 public final boolean canReceiveKeys() {
7037 return isVisibleOrAdding()
7038 && (mViewVisibility == View.VISIBLE)
7039 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7040 }
7041
7042 public boolean hasDrawnLw() {
7043 return mHasDrawn;
7044 }
7045
7046 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007047 return showLw(doAnimation, true);
7048 }
7049
7050 boolean showLw(boolean doAnimation, boolean requestAnim) {
7051 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7052 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007053 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007054 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007055 if (doAnimation) {
7056 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7057 + mPolicyVisibility + " mAnimation=" + mAnimation);
7058 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7059 doAnimation = false;
7060 } else if (mPolicyVisibility && mAnimation == null) {
7061 // Check for the case where we are currently visible and
7062 // not animating; we do not want to do animation at such a
7063 // point to become visible when we already are.
7064 doAnimation = false;
7065 }
7066 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007067 mPolicyVisibility = true;
7068 mPolicyVisibilityAfterAnim = true;
7069 if (doAnimation) {
7070 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7071 }
7072 if (requestAnim) {
7073 requestAnimationLocked(0);
7074 }
7075 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007076 }
7077
7078 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007079 return hideLw(doAnimation, true);
7080 }
7081
7082 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007083 if (doAnimation) {
7084 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7085 doAnimation = false;
7086 }
7087 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007088 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7089 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007090 if (!current) {
7091 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007092 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007093 if (doAnimation) {
7094 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7095 if (mAnimation == null) {
7096 doAnimation = false;
7097 }
7098 }
7099 if (doAnimation) {
7100 mPolicyVisibilityAfterAnim = false;
7101 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007102 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007103 mPolicyVisibilityAfterAnim = false;
7104 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007105 // Window is no longer visible -- make sure if we were waiting
7106 // for it to be displayed before enabling the display, that
7107 // we allow the display to be enabled now.
7108 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007109 if (mCurrentFocus == this) {
7110 mFocusMayChange = true;
7111 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007112 }
7113 if (requestAnim) {
7114 requestAnimationLocked(0);
7115 }
7116 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007117 }
7118
7119 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007120 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7121 pw.print(" mClient="); pw.println(mClient.asBinder());
7122 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7123 if (mAttachedWindow != null || mLayoutAttached) {
7124 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7125 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7126 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007127 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7128 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7129 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007130 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7131 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007132 }
7133 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7134 pw.print(" mSubLayer="); pw.print(mSubLayer);
7135 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7136 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7137 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7138 pw.print("="); pw.print(mAnimLayer);
7139 pw.print(" mLastLayer="); pw.println(mLastLayer);
7140 if (mSurface != null) {
7141 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007142 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7143 pw.print(" layer="); pw.print(mSurfaceLayer);
7144 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7145 pw.print(" rect=("); pw.print(mSurfaceX);
7146 pw.print(","); pw.print(mSurfaceY);
7147 pw.print(") "); pw.print(mSurfaceW);
7148 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007149 }
7150 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7151 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7152 if (mAppToken != null) {
7153 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7154 }
7155 if (mTargetAppToken != null) {
7156 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7157 }
7158 pw.print(prefix); pw.print("mViewVisibility=0x");
7159 pw.print(Integer.toHexString(mViewVisibility));
7160 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007161 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7162 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007163 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7164 pw.print(prefix); pw.print("mPolicyVisibility=");
7165 pw.print(mPolicyVisibility);
7166 pw.print(" mPolicyVisibilityAfterAnim=");
7167 pw.print(mPolicyVisibilityAfterAnim);
7168 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7169 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007170 if (!mRelayoutCalled) {
7171 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7172 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007173 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007174 pw.print(" h="); pw.print(mRequestedHeight);
7175 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007176 if (mXOffset != 0 || mYOffset != 0) {
7177 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7178 pw.print(" y="); pw.println(mYOffset);
7179 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007180 pw.print(prefix); pw.print("mGivenContentInsets=");
7181 mGivenContentInsets.printShortString(pw);
7182 pw.print(" mGivenVisibleInsets=");
7183 mGivenVisibleInsets.printShortString(pw);
7184 pw.println();
7185 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7186 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7187 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7188 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007189 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007190 pw.print(prefix); pw.print("mShownFrame=");
7191 mShownFrame.printShortString(pw);
7192 pw.print(" last="); mLastShownFrame.printShortString(pw);
7193 pw.println();
7194 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7195 pw.print(" last="); mLastFrame.printShortString(pw);
7196 pw.println();
7197 pw.print(prefix); pw.print("mContainingFrame=");
7198 mContainingFrame.printShortString(pw);
7199 pw.print(" mDisplayFrame=");
7200 mDisplayFrame.printShortString(pw);
7201 pw.println();
7202 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7203 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7204 pw.println();
7205 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7206 pw.print(" last="); mLastContentInsets.printShortString(pw);
7207 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7208 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7209 pw.println();
7210 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7211 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7212 pw.print(" mAlpha="); pw.print(mAlpha);
7213 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7214 }
7215 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7216 || mAnimation != null) {
7217 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7218 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7219 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7220 pw.print(" mAnimation="); pw.println(mAnimation);
7221 }
7222 if (mHasTransformation || mHasLocalTransformation) {
7223 pw.print(prefix); pw.print("XForm: has=");
7224 pw.print(mHasTransformation);
7225 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7226 pw.print(" "); mTransformation.printShortString(pw);
7227 pw.println();
7228 }
7229 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7230 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7231 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7232 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7233 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7234 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7235 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7236 pw.print(" mDestroying="); pw.print(mDestroying);
7237 pw.print(" mRemoved="); pw.println(mRemoved);
7238 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007239 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007240 pw.print(prefix); pw.print("mOrientationChanging=");
7241 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007242 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7243 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007244 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007245 if (mHScale != 1 || mVScale != 1) {
7246 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7247 pw.print(" mVScale="); pw.println(mVScale);
7248 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007249 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007250 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7251 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7252 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007253 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7254 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7255 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007257 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007258
7259 String makeInputChannelName() {
7260 return Integer.toHexString(System.identityHashCode(this))
7261 + " " + mAttrs.getTitle();
7262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007263
7264 @Override
7265 public String toString() {
7266 return "Window{"
7267 + Integer.toHexString(System.identityHashCode(this))
7268 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7269 }
7270 }
Romain Guy06882f82009-06-10 13:36:04 -07007271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007272 // -------------------------------------------------------------
7273 // Window Token State
7274 // -------------------------------------------------------------
7275
7276 class WindowToken {
7277 // The actual token.
7278 final IBinder token;
7279
7280 // The type of window this token is for, as per WindowManager.LayoutParams.
7281 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007283 // Set if this token was explicitly added by a client, so should
7284 // not be removed when all windows are removed.
7285 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007286
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007287 // For printing.
7288 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007290 // If this is an AppWindowToken, this is non-null.
7291 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007293 // All of the windows associated with this token.
7294 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7295
7296 // Is key dispatching paused for this token?
7297 boolean paused = false;
7298
7299 // Should this token's windows be hidden?
7300 boolean hidden;
7301
7302 // Temporary for finding which tokens no longer have visible windows.
7303 boolean hasVisible;
7304
Dianne Hackborna8f60182009-09-01 19:01:50 -07007305 // Set to true when this token is in a pending transaction where it
7306 // will be shown.
7307 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007308
Dianne Hackborna8f60182009-09-01 19:01:50 -07007309 // Set to true when this token is in a pending transaction where it
7310 // will be hidden.
7311 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007312
Dianne Hackborna8f60182009-09-01 19:01:50 -07007313 // Set to true when this token is in a pending transaction where its
7314 // windows will be put to the bottom of the list.
7315 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007316
Dianne Hackborna8f60182009-09-01 19:01:50 -07007317 // Set to true when this token is in a pending transaction where its
7318 // windows will be put to the top of the list.
7319 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 WindowToken(IBinder _token, int type, boolean _explicit) {
7322 token = _token;
7323 windowType = type;
7324 explicit = _explicit;
7325 }
7326
7327 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007328 pw.print(prefix); pw.print("token="); pw.println(token);
7329 pw.print(prefix); pw.print("windows="); pw.println(windows);
7330 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7331 pw.print(" hidden="); pw.print(hidden);
7332 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007333 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7334 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7335 pw.print(" waitingToHide="); pw.print(waitingToHide);
7336 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7337 pw.print(" sendingToTop="); pw.println(sendingToTop);
7338 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007339 }
7340
7341 @Override
7342 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007343 if (stringName == null) {
7344 StringBuilder sb = new StringBuilder();
7345 sb.append("WindowToken{");
7346 sb.append(Integer.toHexString(System.identityHashCode(this)));
7347 sb.append(" token="); sb.append(token); sb.append('}');
7348 stringName = sb.toString();
7349 }
7350 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007351 }
7352 };
7353
7354 class AppWindowToken extends WindowToken {
7355 // Non-null only for application tokens.
7356 final IApplicationToken appToken;
7357
7358 // All of the windows and child windows that are included in this
7359 // application token. Note this list is NOT sorted!
7360 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7361
7362 int groupId = -1;
7363 boolean appFullscreen;
7364 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007365
7366 // The input dispatching timeout for this application token in nanoseconds.
7367 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 // These are used for determining when all windows associated with
7370 // an activity have been drawn, so they can be made visible together
7371 // at the same time.
7372 int lastTransactionSequence = mTransactionSequence-1;
7373 int numInterestingWindows;
7374 int numDrawnWindows;
7375 boolean inPendingTransaction;
7376 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007378 // Is this token going to be hidden in a little while? If so, it
7379 // won't be taken into account for setting the screen orientation.
7380 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007382 // Is this window's surface needed? This is almost like hidden, except
7383 // it will sometimes be true a little earlier: when the token has
7384 // been shown, but is still waiting for its app transition to execute
7385 // before making its windows shown.
7386 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007388 // Have we told the window clients to hide themselves?
7389 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007391 // Last visibility state we reported to the app token.
7392 boolean reportedVisible;
7393
7394 // Set to true when the token has been removed from the window mgr.
7395 boolean removed;
7396
7397 // Have we been asked to have this token keep the screen frozen?
7398 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007400 boolean animating;
7401 Animation animation;
7402 boolean hasTransformation;
7403 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007405 // Offset to the window of all layers in the token, for use by
7406 // AppWindowToken animations.
7407 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007409 // Information about an application starting window if displayed.
7410 StartingData startingData;
7411 WindowState startingWindow;
7412 View startingView;
7413 boolean startingDisplayed;
7414 boolean startingMoved;
7415 boolean firstWindowDrawn;
7416
7417 AppWindowToken(IApplicationToken _token) {
7418 super(_token.asBinder(),
7419 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7420 appWindowToken = this;
7421 appToken = _token;
7422 }
Romain Guy06882f82009-06-10 13:36:04 -07007423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007424 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007425 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007426 TAG, "Setting animation in " + this + ": " + anim);
7427 animation = anim;
7428 animating = false;
7429 anim.restrictDuration(MAX_ANIMATION_DURATION);
7430 anim.scaleCurrentDuration(mTransitionAnimationScale);
7431 int zorder = anim.getZAdjustment();
7432 int adj = 0;
7433 if (zorder == Animation.ZORDER_TOP) {
7434 adj = TYPE_LAYER_OFFSET;
7435 } else if (zorder == Animation.ZORDER_BOTTOM) {
7436 adj = -TYPE_LAYER_OFFSET;
7437 }
Romain Guy06882f82009-06-10 13:36:04 -07007438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007439 if (animLayerAdjustment != adj) {
7440 animLayerAdjustment = adj;
7441 updateLayers();
7442 }
7443 }
Romain Guy06882f82009-06-10 13:36:04 -07007444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 public void setDummyAnimation() {
7446 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007447 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 TAG, "Setting dummy animation in " + this);
7449 animation = sDummyAnimation;
7450 }
7451 }
7452
7453 public void clearAnimation() {
7454 if (animation != null) {
7455 animation = null;
7456 animating = true;
7457 }
7458 }
Romain Guy06882f82009-06-10 13:36:04 -07007459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 void updateLayers() {
7461 final int N = allAppWindows.size();
7462 final int adj = animLayerAdjustment;
7463 for (int i=0; i<N; i++) {
7464 WindowState w = allAppWindows.get(i);
7465 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007466 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007467 + w.mAnimLayer);
7468 if (w == mInputMethodTarget) {
7469 setInputMethodAnimLayerAdjustment(adj);
7470 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007471 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007472 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 }
7475 }
Romain Guy06882f82009-06-10 13:36:04 -07007476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 void sendAppVisibilityToClients() {
7478 final int N = allAppWindows.size();
7479 for (int i=0; i<N; i++) {
7480 WindowState win = allAppWindows.get(i);
7481 if (win == startingWindow && clientHidden) {
7482 // Don't hide the starting window.
7483 continue;
7484 }
7485 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007486 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007487 "Setting visibility of " + win + ": " + (!clientHidden));
7488 win.mClient.dispatchAppVisibility(!clientHidden);
7489 } catch (RemoteException e) {
7490 }
7491 }
7492 }
Romain Guy06882f82009-06-10 13:36:04 -07007493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007494 void showAllWindowsLocked() {
7495 final int NW = allAppWindows.size();
7496 for (int i=0; i<NW; i++) {
7497 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007498 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 "performing show on: " + w);
7500 w.performShowLocked();
7501 }
7502 }
Romain Guy06882f82009-06-10 13:36:04 -07007503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007504 // This must be called while inside a transaction.
7505 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007506 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007507 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007509 if (animation == sDummyAnimation) {
7510 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007511 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 // when it is really time to animate, this will be set to
7513 // a real animation and the next call will execute normally.
7514 return false;
7515 }
Romain Guy06882f82009-06-10 13:36:04 -07007516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007517 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7518 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007519 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 TAG, "Starting animation in " + this +
7521 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7522 + " scale=" + mTransitionAnimationScale
7523 + " allDrawn=" + allDrawn + " animating=" + animating);
7524 animation.initialize(dw, dh, dw, dh);
7525 animation.setStartTime(currentTime);
7526 animating = true;
7527 }
7528 transformation.clear();
7529 final boolean more = animation.getTransformation(
7530 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007531 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007532 TAG, "Stepped animation in " + this +
7533 ": more=" + more + ", xform=" + transformation);
7534 if (more) {
7535 // we're done!
7536 hasTransformation = true;
7537 return true;
7538 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007539 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007540 TAG, "Finished animation in " + this +
7541 " @ " + currentTime);
7542 animation = null;
7543 }
7544 } else if (animation != null) {
7545 // If the display is frozen, and there is a pending animation,
7546 // clear it and make sure we run the cleanup code.
7547 animating = true;
7548 animation = null;
7549 }
7550
7551 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 if (!animating) {
7554 return false;
7555 }
7556
7557 clearAnimation();
7558 animating = false;
7559 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7560 moveInputMethodWindowsIfNeededLocked(true);
7561 }
Romain Guy06882f82009-06-10 13:36:04 -07007562
Joe Onorato8a9b2202010-02-26 18:56:32 -08007563 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007564 TAG, "Animation done in " + this
7565 + ": reportedVisible=" + reportedVisible);
7566
7567 transformation.clear();
7568 if (animLayerAdjustment != 0) {
7569 animLayerAdjustment = 0;
7570 updateLayers();
7571 }
Romain Guy06882f82009-06-10 13:36:04 -07007572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 final int N = windows.size();
7574 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007575 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 }
7577 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007579 return false;
7580 }
7581
7582 void updateReportedVisibilityLocked() {
7583 if (appToken == null) {
7584 return;
7585 }
Romain Guy06882f82009-06-10 13:36:04 -07007586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007587 int numInteresting = 0;
7588 int numVisible = 0;
7589 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007590
Joe Onorato8a9b2202010-02-26 18:56:32 -08007591 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 final int N = allAppWindows.size();
7593 for (int i=0; i<N; i++) {
7594 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007595 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007596 || win.mViewVisibility != View.VISIBLE
7597 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598 continue;
7599 }
7600 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007601 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007602 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007603 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007604 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007605 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 + " pv=" + win.mPolicyVisibility
7607 + " dp=" + win.mDrawPending
7608 + " cdp=" + win.mCommitDrawPending
7609 + " ah=" + win.mAttachedHidden
7610 + " th="
7611 + (win.mAppToken != null
7612 ? win.mAppToken.hiddenRequested : false)
7613 + " a=" + win.mAnimating);
7614 }
7615 }
7616 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007617 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 if (!win.isAnimating()) {
7619 numVisible++;
7620 }
7621 nowGone = false;
7622 } else if (win.isAnimating()) {
7623 nowGone = false;
7624 }
7625 }
Romain Guy06882f82009-06-10 13:36:04 -07007626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007627 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007628 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007629 + numInteresting + " visible=" + numVisible);
7630 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007631 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007632 TAG, "Visibility changed in " + this
7633 + ": vis=" + nowVisible);
7634 reportedVisible = nowVisible;
7635 Message m = mH.obtainMessage(
7636 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7637 nowVisible ? 1 : 0,
7638 nowGone ? 1 : 0,
7639 this);
7640 mH.sendMessage(m);
7641 }
7642 }
Romain Guy06882f82009-06-10 13:36:04 -07007643
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007644 WindowState findMainWindow() {
7645 int j = windows.size();
7646 while (j > 0) {
7647 j--;
7648 WindowState win = windows.get(j);
7649 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7650 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7651 return win;
7652 }
7653 }
7654 return null;
7655 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007657 void dump(PrintWriter pw, String prefix) {
7658 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007659 if (appToken != null) {
7660 pw.print(prefix); pw.println("app=true");
7661 }
7662 if (allAppWindows.size() > 0) {
7663 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7664 }
7665 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007666 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007667 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7668 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7669 pw.print(" clientHidden="); pw.print(clientHidden);
7670 pw.print(" willBeHidden="); pw.print(willBeHidden);
7671 pw.print(" reportedVisible="); pw.println(reportedVisible);
7672 if (paused || freezingScreen) {
7673 pw.print(prefix); pw.print("paused="); pw.print(paused);
7674 pw.print(" freezingScreen="); pw.println(freezingScreen);
7675 }
7676 if (numInterestingWindows != 0 || numDrawnWindows != 0
7677 || inPendingTransaction || allDrawn) {
7678 pw.print(prefix); pw.print("numInterestingWindows=");
7679 pw.print(numInterestingWindows);
7680 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7681 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7682 pw.print(" allDrawn="); pw.println(allDrawn);
7683 }
7684 if (animating || animation != null) {
7685 pw.print(prefix); pw.print("animating="); pw.print(animating);
7686 pw.print(" animation="); pw.println(animation);
7687 }
7688 if (animLayerAdjustment != 0) {
7689 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7690 }
7691 if (hasTransformation) {
7692 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7693 pw.print(" transformation="); transformation.printShortString(pw);
7694 pw.println();
7695 }
7696 if (startingData != null || removed || firstWindowDrawn) {
7697 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7698 pw.print(" removed="); pw.print(removed);
7699 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7700 }
7701 if (startingWindow != null || startingView != null
7702 || startingDisplayed || startingMoved) {
7703 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7704 pw.print(" startingView="); pw.print(startingView);
7705 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7706 pw.print(" startingMoved"); pw.println(startingMoved);
7707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007708 }
7709
7710 @Override
7711 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007712 if (stringName == null) {
7713 StringBuilder sb = new StringBuilder();
7714 sb.append("AppWindowToken{");
7715 sb.append(Integer.toHexString(System.identityHashCode(this)));
7716 sb.append(" token="); sb.append(token); sb.append('}');
7717 stringName = sb.toString();
7718 }
7719 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007720 }
7721 }
Romain Guy06882f82009-06-10 13:36:04 -07007722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007723 // -------------------------------------------------------------
7724 // DummyAnimation
7725 // -------------------------------------------------------------
7726
7727 // This is an animation that does nothing: it just immediately finishes
7728 // itself every time it is called. It is used as a stub animation in cases
7729 // where we want to synchronize multiple things that may be animating.
7730 static final class DummyAnimation extends Animation {
7731 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7732 return false;
7733 }
7734 }
7735 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007737 // -------------------------------------------------------------
7738 // Async Handler
7739 // -------------------------------------------------------------
7740
7741 static final class StartingData {
7742 final String pkg;
7743 final int theme;
7744 final CharSequence nonLocalizedLabel;
7745 final int labelRes;
7746 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007748 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7749 int _labelRes, int _icon) {
7750 pkg = _pkg;
7751 theme = _theme;
7752 nonLocalizedLabel = _nonLocalizedLabel;
7753 labelRes = _labelRes;
7754 icon = _icon;
7755 }
7756 }
7757
7758 private final class H extends Handler {
7759 public static final int REPORT_FOCUS_CHANGE = 2;
7760 public static final int REPORT_LOSING_FOCUS = 3;
7761 public static final int ANIMATE = 4;
7762 public static final int ADD_STARTING = 5;
7763 public static final int REMOVE_STARTING = 6;
7764 public static final int FINISHED_STARTING = 7;
7765 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007766 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7767 public static final int HOLD_SCREEN_CHANGED = 12;
7768 public static final int APP_TRANSITION_TIMEOUT = 13;
7769 public static final int PERSIST_ANIMATION_SCALE = 14;
7770 public static final int FORCE_GC = 15;
7771 public static final int ENABLE_SCREEN = 16;
7772 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007773 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007774 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007776 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007778 public H() {
7779 }
Romain Guy06882f82009-06-10 13:36:04 -07007780
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007781 @Override
7782 public void handleMessage(Message msg) {
7783 switch (msg.what) {
7784 case REPORT_FOCUS_CHANGE: {
7785 WindowState lastFocus;
7786 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007788 synchronized(mWindowMap) {
7789 lastFocus = mLastFocus;
7790 newFocus = mCurrentFocus;
7791 if (lastFocus == newFocus) {
7792 // Focus is not changing, so nothing to do.
7793 return;
7794 }
7795 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007796 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797 // + " to " + newFocus);
7798 if (newFocus != null && lastFocus != null
7799 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007800 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007801 mLosingFocus.add(lastFocus);
7802 lastFocus = null;
7803 }
7804 }
7805
7806 if (lastFocus != newFocus) {
7807 //System.out.println("Changing focus from " + lastFocus
7808 // + " to " + newFocus);
7809 if (newFocus != null) {
7810 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007811 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007812 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7813 } catch (RemoteException e) {
7814 // Ignore if process has died.
7815 }
7816 }
7817
7818 if (lastFocus != null) {
7819 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007820 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007821 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7822 } catch (RemoteException e) {
7823 // Ignore if process has died.
7824 }
Konstantin Lopyrev321f7fa2010-08-02 20:01:01 -07007825 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 }
7827 }
7828 } break;
7829
7830 case REPORT_LOSING_FOCUS: {
7831 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007833 synchronized(mWindowMap) {
7834 losers = mLosingFocus;
7835 mLosingFocus = new ArrayList<WindowState>();
7836 }
7837
7838 final int N = losers.size();
7839 for (int i=0; i<N; i++) {
7840 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007841 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7843 } catch (RemoteException e) {
7844 // Ignore if process has died.
7845 }
7846 }
7847 } break;
7848
7849 case ANIMATE: {
7850 synchronized(mWindowMap) {
7851 mAnimationPending = false;
7852 performLayoutAndPlaceSurfacesLocked();
7853 }
7854 } break;
7855
7856 case ADD_STARTING: {
7857 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7858 final StartingData sd = wtoken.startingData;
7859
7860 if (sd == null) {
7861 // Animation has been canceled... do nothing.
7862 return;
7863 }
Romain Guy06882f82009-06-10 13:36:04 -07007864
Joe Onorato8a9b2202010-02-26 18:56:32 -08007865 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007866 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 View view = null;
7869 try {
7870 view = mPolicy.addStartingWindow(
7871 wtoken.token, sd.pkg,
7872 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7873 sd.icon);
7874 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007875 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 }
7877
7878 if (view != null) {
7879 boolean abort = false;
7880
7881 synchronized(mWindowMap) {
7882 if (wtoken.removed || wtoken.startingData == null) {
7883 // If the window was successfully added, then
7884 // we need to remove it.
7885 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007886 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007887 "Aborted starting " + wtoken
7888 + ": removed=" + wtoken.removed
7889 + " startingData=" + wtoken.startingData);
7890 wtoken.startingWindow = null;
7891 wtoken.startingData = null;
7892 abort = true;
7893 }
7894 } else {
7895 wtoken.startingView = view;
7896 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007897 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 "Added starting " + wtoken
7899 + ": startingWindow="
7900 + wtoken.startingWindow + " startingView="
7901 + wtoken.startingView);
7902 }
7903
7904 if (abort) {
7905 try {
7906 mPolicy.removeStartingWindow(wtoken.token, view);
7907 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007908 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007909 }
7910 }
7911 }
7912 } break;
7913
7914 case REMOVE_STARTING: {
7915 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7916 IBinder token = null;
7917 View view = null;
7918 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007919 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007920 + wtoken + ": startingWindow="
7921 + wtoken.startingWindow + " startingView="
7922 + wtoken.startingView);
7923 if (wtoken.startingWindow != null) {
7924 view = wtoken.startingView;
7925 token = wtoken.token;
7926 wtoken.startingData = null;
7927 wtoken.startingView = null;
7928 wtoken.startingWindow = null;
7929 }
7930 }
7931 if (view != null) {
7932 try {
7933 mPolicy.removeStartingWindow(token, view);
7934 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007935 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 }
7937 }
7938 } break;
7939
7940 case FINISHED_STARTING: {
7941 IBinder token = null;
7942 View view = null;
7943 while (true) {
7944 synchronized (mWindowMap) {
7945 final int N = mFinishedStarting.size();
7946 if (N <= 0) {
7947 break;
7948 }
7949 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
7950
Joe Onorato8a9b2202010-02-26 18:56:32 -08007951 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007952 "Finished starting " + wtoken
7953 + ": startingWindow=" + wtoken.startingWindow
7954 + " startingView=" + wtoken.startingView);
7955
7956 if (wtoken.startingWindow == null) {
7957 continue;
7958 }
7959
7960 view = wtoken.startingView;
7961 token = wtoken.token;
7962 wtoken.startingData = null;
7963 wtoken.startingView = null;
7964 wtoken.startingWindow = null;
7965 }
7966
7967 try {
7968 mPolicy.removeStartingWindow(token, view);
7969 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007970 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007971 }
7972 }
7973 } break;
7974
7975 case REPORT_APPLICATION_TOKEN_WINDOWS: {
7976 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7977
7978 boolean nowVisible = msg.arg1 != 0;
7979 boolean nowGone = msg.arg2 != 0;
7980
7981 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007982 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007983 TAG, "Reporting visible in " + wtoken
7984 + " visible=" + nowVisible
7985 + " gone=" + nowGone);
7986 if (nowVisible) {
7987 wtoken.appToken.windowsVisible();
7988 } else {
7989 wtoken.appToken.windowsGone();
7990 }
7991 } catch (RemoteException ex) {
7992 }
7993 } break;
Romain Guy06882f82009-06-10 13:36:04 -07007994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007995 case WINDOW_FREEZE_TIMEOUT: {
7996 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007997 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007998 int i = mWindows.size();
7999 while (i > 0) {
8000 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008001 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008002 if (w.mOrientationChanging) {
8003 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008004 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008005 }
8006 }
8007 performLayoutAndPlaceSurfacesLocked();
8008 }
8009 break;
8010 }
Romain Guy06882f82009-06-10 13:36:04 -07008011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008012 case HOLD_SCREEN_CHANGED: {
8013 Session oldHold;
8014 Session newHold;
8015 synchronized (mWindowMap) {
8016 oldHold = mLastReportedHold;
8017 newHold = (Session)msg.obj;
8018 mLastReportedHold = newHold;
8019 }
Romain Guy06882f82009-06-10 13:36:04 -07008020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008021 if (oldHold != newHold) {
8022 try {
8023 if (oldHold != null) {
8024 mBatteryStats.noteStopWakelock(oldHold.mUid,
8025 "window",
8026 BatteryStats.WAKE_TYPE_WINDOW);
8027 }
8028 if (newHold != null) {
8029 mBatteryStats.noteStartWakelock(newHold.mUid,
8030 "window",
8031 BatteryStats.WAKE_TYPE_WINDOW);
8032 }
8033 } catch (RemoteException e) {
8034 }
8035 }
8036 break;
8037 }
Romain Guy06882f82009-06-10 13:36:04 -07008038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008039 case APP_TRANSITION_TIMEOUT: {
8040 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008041 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008042 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 "*** APP TRANSITION TIMEOUT");
8044 mAppTransitionReady = true;
8045 mAppTransitionTimeout = true;
8046 performLayoutAndPlaceSurfacesLocked();
8047 }
8048 }
8049 break;
8050 }
Romain Guy06882f82009-06-10 13:36:04 -07008051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008052 case PERSIST_ANIMATION_SCALE: {
8053 Settings.System.putFloat(mContext.getContentResolver(),
8054 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8055 Settings.System.putFloat(mContext.getContentResolver(),
8056 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8057 break;
8058 }
Romain Guy06882f82009-06-10 13:36:04 -07008059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008060 case FORCE_GC: {
8061 synchronized(mWindowMap) {
8062 if (mAnimationPending) {
8063 // If we are animating, don't do the gc now but
8064 // delay a bit so we don't interrupt the animation.
8065 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8066 2000);
8067 return;
8068 }
8069 // If we are currently rotating the display, it will
8070 // schedule a new message when done.
8071 if (mDisplayFrozen) {
8072 return;
8073 }
8074 mFreezeGcPending = 0;
8075 }
8076 Runtime.getRuntime().gc();
8077 break;
8078 }
Romain Guy06882f82009-06-10 13:36:04 -07008079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008080 case ENABLE_SCREEN: {
8081 performEnableScreen();
8082 break;
8083 }
Romain Guy06882f82009-06-10 13:36:04 -07008084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 case APP_FREEZE_TIMEOUT: {
8086 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008087 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008088 int i = mAppTokens.size();
8089 while (i > 0) {
8090 i--;
8091 AppWindowToken tok = mAppTokens.get(i);
8092 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008093 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 unsetAppFreezingScreenLocked(tok, true, true);
8095 }
8096 }
8097 }
8098 break;
8099 }
Romain Guy06882f82009-06-10 13:36:04 -07008100
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008101 case SEND_NEW_CONFIGURATION: {
8102 removeMessages(SEND_NEW_CONFIGURATION);
8103 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008104 break;
8105 }
Romain Guy06882f82009-06-10 13:36:04 -07008106
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008107 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008108 if (mWindowsChanged) {
8109 synchronized (mWindowMap) {
8110 mWindowsChanged = false;
8111 }
8112 notifyWindowsChanged();
8113 }
8114 break;
8115 }
8116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008117 }
8118 }
8119 }
8120
8121 // -------------------------------------------------------------
8122 // IWindowManager API
8123 // -------------------------------------------------------------
8124
8125 public IWindowSession openSession(IInputMethodClient client,
8126 IInputContext inputContext) {
8127 if (client == null) throw new IllegalArgumentException("null client");
8128 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008129 Session session = new Session(client, inputContext);
8130 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008131 }
8132
8133 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8134 synchronized (mWindowMap) {
8135 // The focus for the client is the window immediately below
8136 // where we would place the input method window.
8137 int idx = findDesiredInputMethodWindowIndexLocked(false);
8138 WindowState imFocus;
8139 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008140 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008141 if (imFocus != null) {
8142 if (imFocus.mSession.mClient != null &&
8143 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8144 return true;
8145 }
8146 }
8147 }
8148 }
8149 return false;
8150 }
Romain Guy06882f82009-06-10 13:36:04 -07008151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008152 // -------------------------------------------------------------
8153 // Internals
8154 // -------------------------------------------------------------
8155
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008156 final WindowState windowForClientLocked(Session session, IWindow client,
8157 boolean throwOnError) {
8158 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 }
Romain Guy06882f82009-06-10 13:36:04 -07008160
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008161 final WindowState windowForClientLocked(Session session, IBinder client,
8162 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008163 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008164 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008165 TAG, "Looking up client " + client + ": " + win);
8166 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008167 RuntimeException ex = new IllegalArgumentException(
8168 "Requested window " + client + " does not exist");
8169 if (throwOnError) {
8170 throw ex;
8171 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008172 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008173 return null;
8174 }
8175 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008176 RuntimeException ex = new IllegalArgumentException(
8177 "Requested window " + client + " is in session " +
8178 win.mSession + ", not " + session);
8179 if (throwOnError) {
8180 throw ex;
8181 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008182 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008183 return null;
8184 }
8185
8186 return win;
8187 }
8188
Dianne Hackborna8f60182009-09-01 19:01:50 -07008189 final void rebuildAppWindowListLocked() {
8190 int NW = mWindows.size();
8191 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008192 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008193 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008194
Dianne Hackborna8f60182009-09-01 19:01:50 -07008195 // First remove all existing app windows.
8196 i=0;
8197 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008198 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008199 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008200 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008201 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008202 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008203 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008204 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008205 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008206 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008207 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8208 && lastWallpaper == i-1) {
8209 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008210 }
8211 i++;
8212 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008213
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008214 // The wallpaper window(s) typically live at the bottom of the stack,
8215 // so skip them before adding app tokens.
8216 lastWallpaper++;
8217 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008218
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008219 // First add all of the exiting app tokens... these are no longer
8220 // in the main app list, but still have windows shown. We put them
8221 // in the back because now that the animation is over we no longer
8222 // will care about them.
8223 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008224 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008225 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8226 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008227
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008228 // And add in the still active app tokens in Z order.
8229 NT = mAppTokens.size();
8230 for (int j=0; j<NT; j++) {
8231 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008232 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008233
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008234 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008235 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008236 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008237 + " windows but added " + i);
8238 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008241 private final void assignLayersLocked() {
8242 int N = mWindows.size();
8243 int curBaseLayer = 0;
8244 int curLayer = 0;
8245 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008247 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008248 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008249 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8250 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 curLayer += WINDOW_LAYER_MULTIPLIER;
8252 w.mLayer = curLayer;
8253 } else {
8254 curBaseLayer = curLayer = w.mBaseLayer;
8255 w.mLayer = curLayer;
8256 }
8257 if (w.mTargetAppToken != null) {
8258 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8259 } else if (w.mAppToken != null) {
8260 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8261 } else {
8262 w.mAnimLayer = w.mLayer;
8263 }
8264 if (w.mIsImWindow) {
8265 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008266 } else if (w.mIsWallpaper) {
8267 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008268 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008269 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008270 + w.mAnimLayer);
8271 //System.out.println(
8272 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8273 }
8274 }
8275
8276 private boolean mInLayout = false;
8277 private final void performLayoutAndPlaceSurfacesLocked() {
8278 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008279 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008280 throw new RuntimeException("Recursive call!");
8281 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008282 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008283 return;
8284 }
8285
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008286 if (mWaitingForConfig) {
8287 // Our configuration has changed (most likely rotation), but we
8288 // don't yet have the complete configuration to report to
8289 // applications. Don't do any window layout until we have it.
8290 return;
8291 }
8292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008293 boolean recoveringMemory = false;
8294 if (mForceRemoves != null) {
8295 recoveringMemory = true;
8296 // Wait a little it for things to settle down, and off we go.
8297 for (int i=0; i<mForceRemoves.size(); i++) {
8298 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008299 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008300 removeWindowInnerLocked(ws.mSession, ws);
8301 }
8302 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008303 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008304 Object tmp = new Object();
8305 synchronized (tmp) {
8306 try {
8307 tmp.wait(250);
8308 } catch (InterruptedException e) {
8309 }
8310 }
8311 }
Romain Guy06882f82009-06-10 13:36:04 -07008312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008313 mInLayout = true;
8314 try {
8315 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008317 int i = mPendingRemove.size()-1;
8318 if (i >= 0) {
8319 while (i >= 0) {
8320 WindowState w = mPendingRemove.get(i);
8321 removeWindowInnerLocked(w.mSession, w);
8322 i--;
8323 }
8324 mPendingRemove.clear();
8325
8326 mInLayout = false;
8327 assignLayersLocked();
8328 mLayoutNeeded = true;
8329 performLayoutAndPlaceSurfacesLocked();
8330
8331 } else {
8332 mInLayout = false;
8333 if (mLayoutNeeded) {
8334 requestAnimationLocked(0);
8335 }
8336 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008337 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008338 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8339 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008340 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008341 } catch (RuntimeException e) {
8342 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008343 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008344 }
8345 }
8346
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008347 private final int performLayoutLockedInner() {
8348 if (!mLayoutNeeded) {
8349 return 0;
8350 }
8351
8352 mLayoutNeeded = false;
8353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 final int dw = mDisplay.getWidth();
8355 final int dh = mDisplay.getHeight();
8356
8357 final int N = mWindows.size();
8358 int i;
8359
Joe Onorato8a9b2202010-02-26 18:56:32 -08008360 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008361 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8362
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008363 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008364
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008365 int seq = mLayoutSeq+1;
8366 if (seq < 0) seq = 0;
8367 mLayoutSeq = seq;
8368
8369 // First perform layout of any root windows (not attached
8370 // to another window).
8371 int topAttached = -1;
8372 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008373 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008374
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008375 // Don't do layout of a window if it is not visible, or
8376 // soon won't be visible, to avoid wasting time and funky
8377 // changes while a window is animating away.
8378 final AppWindowToken atoken = win.mAppToken;
8379 final boolean gone = win.mViewVisibility == View.GONE
8380 || !win.mRelayoutCalled
8381 || win.mRootToken.hidden
8382 || (atoken != null && atoken.hiddenRequested)
8383 || win.mAttachedHidden
8384 || win.mExiting || win.mDestroying;
8385
8386 if (!win.mLayoutAttached) {
8387 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8388 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8389 + " mLayoutAttached=" + win.mLayoutAttached);
8390 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8391 + win.mViewVisibility + " mRelayoutCalled="
8392 + win.mRelayoutCalled + " hidden="
8393 + win.mRootToken.hidden + " hiddenRequested="
8394 + (atoken != null && atoken.hiddenRequested)
8395 + " mAttachedHidden=" + win.mAttachedHidden);
8396 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008397
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008398 // If this view is GONE, then skip it -- keep the current
8399 // frame, and let the caller know so they can ignore it
8400 // if they want. (We do the normal layout for INVISIBLE
8401 // windows, since that means "perform layout as normal,
8402 // just don't display").
8403 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008404 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008405 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8406 win.mLayoutSeq = seq;
8407 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8408 + win.mFrame + " mContainingFrame="
8409 + win.mContainingFrame + " mDisplayFrame="
8410 + win.mDisplayFrame);
8411 } else {
8412 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008413 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008415 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008416
8417 // Now perform layout of attached windows, which usually
8418 // depend on the position of the window they are attached to.
8419 // XXX does not deal with windows that are attached to windows
8420 // that are themselves attached.
8421 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008422 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008423
8424 // If this view is GONE, then skip it -- keep the current
8425 // frame, and let the caller know so they can ignore it
8426 // if they want. (We do the normal layout for INVISIBLE
8427 // windows, since that means "perform layout as normal,
8428 // just don't display").
8429 if (win.mLayoutAttached) {
8430 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8431 + " mHaveFrame=" + win.mHaveFrame
8432 + " mViewVisibility=" + win.mViewVisibility
8433 + " mRelayoutCalled=" + win.mRelayoutCalled);
8434 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8435 || !win.mHaveFrame) {
8436 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8437 win.mLayoutSeq = seq;
8438 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8439 + win.mFrame + " mContainingFrame="
8440 + win.mContainingFrame + " mDisplayFrame="
8441 + win.mDisplayFrame);
8442 }
8443 }
8444 }
Jeff Brown349703e2010-06-22 01:27:15 -07008445
8446 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008447 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008448
8449 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008450 }
Romain Guy06882f82009-06-10 13:36:04 -07008451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008452 private final void performLayoutAndPlaceSurfacesLockedInner(
8453 boolean recoveringMemory) {
8454 final long currentTime = SystemClock.uptimeMillis();
8455 final int dw = mDisplay.getWidth();
8456 final int dh = mDisplay.getHeight();
8457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008458 int i;
8459
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008460 if (mFocusMayChange) {
8461 mFocusMayChange = false;
8462 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8463 }
8464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008465 if (mFxSession == null) {
8466 mFxSession = new SurfaceSession();
8467 }
Romain Guy06882f82009-06-10 13:36:04 -07008468
Joe Onorato8a9b2202010-02-26 18:56:32 -08008469 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008470
8471 // Initialize state of exiting tokens.
8472 for (i=mExitingTokens.size()-1; i>=0; i--) {
8473 mExitingTokens.get(i).hasVisible = false;
8474 }
8475
8476 // Initialize state of exiting applications.
8477 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8478 mExitingAppTokens.get(i).hasVisible = false;
8479 }
8480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008481 boolean orientationChangeComplete = true;
8482 Session holdScreen = null;
8483 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008484 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008485 boolean focusDisplayed = false;
8486 boolean animating = false;
8487
8488 Surface.openTransaction();
8489 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008490 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008491 int repeats = 0;
8492 int changes = 0;
8493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008494 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008495 repeats++;
8496 if (repeats > 6) {
8497 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8498 mLayoutNeeded = false;
8499 break;
8500 }
8501
8502 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8503 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8504 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8505 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8506 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8507 assignLayersLocked();
8508 mLayoutNeeded = true;
8509 }
8510 }
8511 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8512 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8513 if (updateOrientationFromAppTokensLocked()) {
8514 mLayoutNeeded = true;
8515 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8516 }
8517 }
8518 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8519 mLayoutNeeded = true;
8520 }
8521 }
8522
8523 // FIRST LOOP: Perform a layout, if needed.
8524 if (repeats < 4) {
8525 changes = performLayoutLockedInner();
8526 if (changes != 0) {
8527 continue;
8528 }
8529 } else {
8530 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8531 changes = 0;
8532 }
8533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 final int transactionSequence = ++mTransactionSequence;
8535
8536 // Update animations of all applications, including those
8537 // associated with exiting/removed apps
8538 boolean tokensAnimating = false;
8539 final int NAT = mAppTokens.size();
8540 for (i=0; i<NAT; i++) {
8541 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8542 tokensAnimating = true;
8543 }
8544 }
8545 final int NEAT = mExitingAppTokens.size();
8546 for (i=0; i<NEAT; i++) {
8547 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8548 tokensAnimating = true;
8549 }
8550 }
8551
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008552 // SECOND LOOP: Execute animations and update visibility of windows.
8553
Joe Onorato8a9b2202010-02-26 18:56:32 -08008554 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008555 + transactionSequence + " tokensAnimating="
8556 + tokensAnimating);
8557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559
8560 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008561 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008562 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008563
8564 mPolicy.beginAnimationLw(dw, dh);
8565
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008566 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008569 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570
8571 final WindowManager.LayoutParams attrs = w.mAttrs;
8572
8573 if (w.mSurface != null) {
8574 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008575 if (w.commitFinishDrawingLocked(currentTime)) {
8576 if ((w.mAttrs.flags
8577 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008578 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008579 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008580 wallpaperMayChange = true;
8581 }
8582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008583
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008584 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008585 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8586 animating = true;
8587 //w.dump(" ");
8588 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008589 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8590 wallpaperMayChange = true;
8591 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008592
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008593 if (mPolicy.doesForceHide(w, attrs)) {
8594 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008595 if (DEBUG_VISIBILITY) Slog.v(TAG,
8596 "Animation done that could impact force hide: "
8597 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008598 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008599 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008600 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8601 forceHiding = true;
8602 }
8603 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8604 boolean changed;
8605 if (forceHiding) {
8606 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008607 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8608 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008609 } else {
8610 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008611 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8612 "Now policy shown: " + w);
8613 if (changed) {
8614 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008615 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008616 // Assume we will need to animate. If
8617 // we don't (because the wallpaper will
8618 // stay with the lock screen), then we will
8619 // clean up later.
8620 Animation a = mPolicy.createForceHideEnterAnimation();
8621 if (a != null) {
8622 w.setAnimation(a);
8623 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008624 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008625 if (mCurrentFocus == null ||
8626 mCurrentFocus.mLayer < w.mLayer) {
8627 // We are showing on to of the current
8628 // focus, so re-evaluate focus to make
8629 // sure it is correct.
8630 mFocusMayChange = true;
8631 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008632 }
8633 }
8634 if (changed && (attrs.flags
8635 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8636 wallpaperMayChange = true;
8637 }
8638 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640 mPolicy.animatingWindowLw(w, attrs);
8641 }
8642
8643 final AppWindowToken atoken = w.mAppToken;
8644 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8645 if (atoken.lastTransactionSequence != transactionSequence) {
8646 atoken.lastTransactionSequence = transactionSequence;
8647 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8648 atoken.startingDisplayed = false;
8649 }
8650 if ((w.isOnScreen() || w.mAttrs.type
8651 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8652 && !w.mExiting && !w.mDestroying) {
8653 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008654 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008655 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008656 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008657 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008658 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 + " pv=" + w.mPolicyVisibility
8660 + " dp=" + w.mDrawPending
8661 + " cdp=" + w.mCommitDrawPending
8662 + " ah=" + w.mAttachedHidden
8663 + " th=" + atoken.hiddenRequested
8664 + " a=" + w.mAnimating);
8665 }
8666 }
8667 if (w != atoken.startingWindow) {
8668 if (!atoken.freezingScreen || !w.mAppFreezing) {
8669 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008670 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008672 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008673 "tokenMayBeDrawn: " + atoken
8674 + " freezingScreen=" + atoken.freezingScreen
8675 + " mAppFreezing=" + w.mAppFreezing);
8676 tokenMayBeDrawn = true;
8677 }
8678 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008679 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008680 atoken.startingDisplayed = true;
8681 }
8682 }
8683 } else if (w.mReadyToShow) {
8684 w.performShowLocked();
8685 }
8686 }
8687
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008688 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008689
8690 if (tokenMayBeDrawn) {
8691 // See if any windows have been drawn, so they (and others
8692 // associated with them) can now be shown.
8693 final int NT = mTokenList.size();
8694 for (i=0; i<NT; i++) {
8695 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8696 if (wtoken == null) {
8697 continue;
8698 }
8699 if (wtoken.freezingScreen) {
8700 int numInteresting = wtoken.numInterestingWindows;
8701 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008702 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008703 "allDrawn: " + wtoken
8704 + " interesting=" + numInteresting
8705 + " drawn=" + wtoken.numDrawnWindows);
8706 wtoken.showAllWindowsLocked();
8707 unsetAppFreezingScreenLocked(wtoken, false, true);
8708 orientationChangeComplete = true;
8709 }
8710 } else if (!wtoken.allDrawn) {
8711 int numInteresting = wtoken.numInterestingWindows;
8712 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008713 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008714 "allDrawn: " + wtoken
8715 + " interesting=" + numInteresting
8716 + " drawn=" + wtoken.numDrawnWindows);
8717 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008718 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719
8720 // We can now show all of the drawn windows!
8721 if (!mOpeningApps.contains(wtoken)) {
8722 wtoken.showAllWindowsLocked();
8723 }
8724 }
8725 }
8726 }
8727 }
8728
8729 // If we are ready to perform an app transition, check through
8730 // all of the app tokens to be shown and see if they are ready
8731 // to go.
8732 if (mAppTransitionReady) {
8733 int NN = mOpeningApps.size();
8734 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008735 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008736 "Checking " + NN + " opening apps (frozen="
8737 + mDisplayFrozen + " timeout="
8738 + mAppTransitionTimeout + ")...");
8739 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8740 // If the display isn't frozen, wait to do anything until
8741 // all of the apps are ready. Otherwise just go because
8742 // we'll unfreeze the display when everyone is ready.
8743 for (i=0; i<NN && goodToGo; i++) {
8744 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008745 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008746 "Check opening app" + wtoken + ": allDrawn="
8747 + wtoken.allDrawn + " startingDisplayed="
8748 + wtoken.startingDisplayed);
8749 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8750 && !wtoken.startingMoved) {
8751 goodToGo = false;
8752 }
8753 }
8754 }
8755 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008756 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008757 int transit = mNextAppTransition;
8758 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008759 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008760 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008761 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008762 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008763 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008764 mAppTransitionTimeout = false;
8765 mStartingIconInTransition = false;
8766 mSkipAppTransitionAnimation = false;
8767
8768 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8769
Dianne Hackborna8f60182009-09-01 19:01:50 -07008770 // If there are applications waiting to come to the
8771 // top of the stack, now is the time to move their windows.
8772 // (Note that we don't do apps going to the bottom
8773 // here -- we want to keep their windows in the old
8774 // Z-order until the animation completes.)
8775 if (mToTopApps.size() > 0) {
8776 NN = mAppTokens.size();
8777 for (i=0; i<NN; i++) {
8778 AppWindowToken wtoken = mAppTokens.get(i);
8779 if (wtoken.sendingToTop) {
8780 wtoken.sendingToTop = false;
8781 moveAppWindowsLocked(wtoken, NN, false);
8782 }
8783 }
8784 mToTopApps.clear();
8785 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008786
Dianne Hackborn25994b42009-09-04 14:21:19 -07008787 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008788
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008789 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008790 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008791
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008792 // The top-most window will supply the layout params,
8793 // and we will determine it below.
8794 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008795 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008796 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008797
Joe Onorato8a9b2202010-02-26 18:56:32 -08008798 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008799 "New wallpaper target=" + mWallpaperTarget
8800 + ", lower target=" + mLowerWallpaperTarget
8801 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008802 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008803 // Do a first pass through the tokens for two
8804 // things:
8805 // (1) Determine if both the closing and opening
8806 // app token sets are wallpaper targets, in which
8807 // case special animations are needed
8808 // (since the wallpaper needs to stay static
8809 // behind them).
8810 // (2) Find the layout params of the top-most
8811 // application window in the tokens, which is
8812 // what will control the animation theme.
8813 final int NC = mClosingApps.size();
8814 NN = NC + mOpeningApps.size();
8815 for (i=0; i<NN; i++) {
8816 AppWindowToken wtoken;
8817 int mode;
8818 if (i < NC) {
8819 wtoken = mClosingApps.get(i);
8820 mode = 1;
8821 } else {
8822 wtoken = mOpeningApps.get(i-NC);
8823 mode = 2;
8824 }
8825 if (mLowerWallpaperTarget != null) {
8826 if (mLowerWallpaperTarget.mAppToken == wtoken
8827 || mUpperWallpaperTarget.mAppToken == wtoken) {
8828 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008829 }
8830 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008831 if (wtoken.appFullscreen) {
8832 WindowState ws = wtoken.findMainWindow();
8833 if (ws != null) {
8834 // If this is a compatibility mode
8835 // window, we will always use its anim.
8836 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8837 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008838 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008839 bestAnimLayer = Integer.MAX_VALUE;
8840 } else if (ws.mLayer > bestAnimLayer) {
8841 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008842 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008843 bestAnimLayer = ws.mLayer;
8844 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008845 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008846 }
8847 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008848
Dianne Hackborn25994b42009-09-04 14:21:19 -07008849 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008850 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008851 "Wallpaper animation!");
8852 switch (transit) {
8853 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8854 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8855 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8856 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8857 break;
8858 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8859 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8860 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8861 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8862 break;
8863 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008864 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008865 "New transit: " + transit);
8866 } else if (oldWallpaper != null) {
8867 // We are transitioning from an activity with
8868 // a wallpaper to one without.
8869 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008870 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008871 "New transit away from wallpaper: " + transit);
8872 } else if (mWallpaperTarget != null) {
8873 // We are transitioning from an activity without
8874 // a wallpaper to now showing the wallpaper
8875 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008876 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008877 "New transit into wallpaper: " + transit);
8878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008879
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008880 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8881 mLastEnterAnimToken = animToken;
8882 mLastEnterAnimParams = animLp;
8883 } else if (mLastEnterAnimParams != null) {
8884 animLp = mLastEnterAnimParams;
8885 mLastEnterAnimToken = null;
8886 mLastEnterAnimParams = null;
8887 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008888
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008889 // If all closing windows are obscured, then there is
8890 // no need to do an animation. This is the case, for
8891 // example, when this transition is being done behind
8892 // the lock screen.
8893 if (!mPolicy.allowAppAnimationsLw()) {
8894 animLp = null;
8895 }
8896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008897 NN = mOpeningApps.size();
8898 for (i=0; i<NN; i++) {
8899 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008900 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008901 "Now opening app" + wtoken);
8902 wtoken.reportedVisible = false;
8903 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008904 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008905 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008906 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008907 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008908 wtoken.showAllWindowsLocked();
8909 }
8910 NN = mClosingApps.size();
8911 for (i=0; i<NN; i++) {
8912 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008913 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008914 "Now closing app" + wtoken);
8915 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008916 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008917 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008918 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008919 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008920 // Force the allDrawn flag, because we want to start
8921 // this guy's animations regardless of whether it's
8922 // gotten drawn.
8923 wtoken.allDrawn = true;
8924 }
8925
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008926 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008928 mOpeningApps.clear();
8929 mClosingApps.clear();
8930
8931 // This has changed the visibility of windows, so perform
8932 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008933 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008934 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07008935 if (!moveInputMethodWindowsIfNeededLocked(true)) {
8936 assignLayersLocked();
8937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008938 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008939 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008940 }
8941 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008942
Dianne Hackborn16064f92010-03-25 00:47:24 -07008943 int adjResult = 0;
8944
Dianne Hackborna8f60182009-09-01 19:01:50 -07008945 if (!animating && mAppTransitionRunning) {
8946 // We have finished the animation of an app transition. To do
8947 // this, we have delayed a lot of operations like showing and
8948 // hiding apps, moving apps in Z-order, etc. The app token list
8949 // reflects the correct Z-order, but the window list may now
8950 // be out of sync with it. So here we will just rebuild the
8951 // entire app window list. Fun!
8952 mAppTransitionRunning = false;
8953 // Clear information about apps that were moving.
8954 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008955
Dianne Hackborna8f60182009-09-01 19:01:50 -07008956 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008957 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07008958 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008959 moveInputMethodWindowsIfNeededLocked(false);
8960 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08008961 // Since the window list has been rebuilt, focus might
8962 // have to be recomputed since the actual order of windows
8963 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008964 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008965 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008966
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008967 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008968 // At this point, there was a window with a wallpaper that
8969 // was force hiding other windows behind it, but now it
8970 // is going away. This may be simple -- just animate
8971 // away the wallpaper and its window -- or it may be
8972 // hard -- the wallpaper now needs to be shown behind
8973 // something that was hidden.
8974 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008975 if (mLowerWallpaperTarget != null
8976 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008977 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008978 "wallpaperForceHiding changed with lower="
8979 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008980 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008981 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
8982 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
8983 if (mLowerWallpaperTarget.mAppToken.hidden) {
8984 // The lower target has become hidden before we
8985 // actually started the animation... let's completely
8986 // re-evaluate everything.
8987 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008988 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008989 }
8990 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07008991 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008992 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008993 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008994 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008995 + " NEW: " + mWallpaperTarget
8996 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008997 if (mLowerWallpaperTarget == null) {
8998 // Whoops, we don't need a special wallpaper animation.
8999 // Clear them out.
9000 forceHiding = false;
9001 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009002 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009003 if (w.mSurface != null) {
9004 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009005 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009006 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009007 forceHiding = true;
9008 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9009 if (!w.mAnimating) {
9010 // We set the animation above so it
9011 // is not yet running.
9012 w.clearAnimation();
9013 }
9014 }
9015 }
9016 }
9017 }
9018 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009019
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009020 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009021 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009022 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009023 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009024 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009025
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009026 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009027 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009028 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009029 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009030 assignLayersLocked();
9031 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009032 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009033 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009034 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009036
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009037 if (mFocusMayChange) {
9038 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009039 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009040 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009041 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009042 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009043 }
9044
9045 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009046 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009047 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009048
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009049 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9050 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009051
Jeff Browne33348b2010-07-15 23:54:05 -07009052 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009053 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054
9055 // THIRD LOOP: Update the surfaces of all windows.
9056
9057 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9058
9059 boolean obscured = false;
9060 boolean blurring = false;
9061 boolean dimming = false;
9062 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009063 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009064 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009065
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009066 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009068 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009069 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009070
9071 boolean displayed = false;
9072 final WindowManager.LayoutParams attrs = w.mAttrs;
9073 final int attrFlags = attrs.flags;
9074
9075 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009076 // XXX NOTE: The logic here could be improved. We have
9077 // the decision about whether to resize a window separated
9078 // from whether to hide the surface. This can cause us to
9079 // resize a surface even if we are going to hide it. You
9080 // can see this by (1) holding device in landscape mode on
9081 // home screen; (2) tapping browser icon (device will rotate
9082 // to landscape; (3) tap home. The wallpaper will be resized
9083 // in step 2 but then immediately hidden, causing us to
9084 // have to resize and then redraw it again in step 3. It
9085 // would be nice to figure out how to avoid this, but it is
9086 // difficult because we do need to resize surfaces in some
9087 // cases while they are hidden such as when first showing a
9088 // window.
9089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009090 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009091 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009092 TAG, "Placing surface #" + i + " " + w.mSurface
9093 + ": new=" + w.mShownFrame + ", old="
9094 + w.mLastShownFrame);
9095
9096 boolean resize;
9097 int width, height;
9098 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9099 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9100 w.mLastRequestedHeight != w.mRequestedHeight;
9101 // for a scaled surface, we just want to use
9102 // the requested size.
9103 width = w.mRequestedWidth;
9104 height = w.mRequestedHeight;
9105 w.mLastRequestedWidth = width;
9106 w.mLastRequestedHeight = height;
9107 w.mLastShownFrame.set(w.mShownFrame);
9108 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009109 if (SHOW_TRANSACTIONS) logSurface(w,
9110 "POS " + w.mShownFrame.left
9111 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009112 w.mSurfaceX = w.mShownFrame.left;
9113 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009114 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9115 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009116 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009117 if (!recoveringMemory) {
9118 reclaimSomeSurfaceMemoryLocked(w, "position");
9119 }
9120 }
9121 } else {
9122 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9123 width = w.mShownFrame.width();
9124 height = w.mShownFrame.height();
9125 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009126 }
9127
9128 if (resize) {
9129 if (width < 1) width = 1;
9130 if (height < 1) height = 1;
9131 if (w.mSurface != null) {
9132 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009133 if (SHOW_TRANSACTIONS) logSurface(w,
9134 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009135 + w.mShownFrame.top + " SIZE "
9136 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009137 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009138 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009139 w.mSurfaceW = width;
9140 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009141 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009142 w.mSurfaceX = w.mShownFrame.left;
9143 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009144 w.mSurface.setPosition(w.mShownFrame.left,
9145 w.mShownFrame.top);
9146 } catch (RuntimeException e) {
9147 // If something goes wrong with the surface (such
9148 // as running out of memory), don't take down the
9149 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009150 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009151 + "size=(" + width + "x" + height
9152 + "), pos=(" + w.mShownFrame.left
9153 + "," + w.mShownFrame.top + ")", e);
9154 if (!recoveringMemory) {
9155 reclaimSomeSurfaceMemoryLocked(w, "size");
9156 }
9157 }
9158 }
9159 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009160 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009161 w.mContentInsetsChanged =
9162 !w.mLastContentInsets.equals(w.mContentInsets);
9163 w.mVisibleInsetsChanged =
9164 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009165 boolean configChanged =
9166 w.mConfiguration != mCurConfiguration
9167 && (w.mConfiguration == null
9168 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009169 if (DEBUG_CONFIGURATION && configChanged) {
9170 Slog.v(TAG, "Win " + w + " config changed: "
9171 + mCurConfiguration);
9172 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009173 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009174 + ": configChanged=" + configChanged
9175 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009176 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009177 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009178 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009179 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009180 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009181 w.mLastFrame.set(w.mFrame);
9182 w.mLastContentInsets.set(w.mContentInsets);
9183 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009184 // If the screen is currently frozen, then keep
9185 // it frozen until this window draws at its new
9186 // orientation.
9187 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009188 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009189 "Resizing while display frozen: " + w);
9190 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009191 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009192 mWindowsFreezingScreen = true;
9193 // XXX should probably keep timeout from
9194 // when we first froze the display.
9195 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9196 mH.sendMessageDelayed(mH.obtainMessage(
9197 H.WINDOW_FREEZE_TIMEOUT), 2000);
9198 }
9199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009200 // If the orientation is changing, then we need to
9201 // hold off on unfreezing the display until this
9202 // window has been redrawn; to do that, we need
9203 // to go through the process of getting informed
9204 // by the application when it has finished drawing.
9205 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009206 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009207 "Orientation start waiting for draw in "
9208 + w + ", surface " + w.mSurface);
9209 w.mDrawPending = true;
9210 w.mCommitDrawPending = false;
9211 w.mReadyToShow = false;
9212 if (w.mAppToken != null) {
9213 w.mAppToken.allDrawn = false;
9214 }
9215 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009216 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009217 "Resizing window " + w + " to " + w.mFrame);
9218 mResizingWindows.add(w);
9219 } else if (w.mOrientationChanging) {
9220 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009221 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009222 "Orientation not waiting for draw in "
9223 + w + ", surface " + w.mSurface);
9224 w.mOrientationChanging = false;
9225 }
9226 }
9227 }
9228
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009229 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009230 if (!w.mLastHidden) {
9231 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009232 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9233 + w.mRootToken.waitingToShow + " polvis="
9234 + w.mPolicyVisibility + " atthid="
9235 + w.mAttachedHidden + " tokhid="
9236 + w.mRootToken.hidden + " vis="
9237 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009238 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009239 if (SHOW_TRANSACTIONS) logSurface(w,
9240 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009241 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009242 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009243 try {
9244 w.mSurface.hide();
9245 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009246 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 }
9248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009249 }
9250 // If we are waiting for this window to handle an
9251 // orientation change, well, it is hidden, so
9252 // doesn't really matter. Note that this does
9253 // introduce a potential glitch if the window
9254 // becomes unhidden before it has drawn for the
9255 // new orientation.
9256 if (w.mOrientationChanging) {
9257 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009258 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009259 "Orientation change skips hidden " + w);
9260 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009261 } else if (w.mLastLayer != w.mAnimLayer
9262 || w.mLastAlpha != w.mShownAlpha
9263 || w.mLastDsDx != w.mDsDx
9264 || w.mLastDtDx != w.mDtDx
9265 || w.mLastDsDy != w.mDsDy
9266 || w.mLastDtDy != w.mDtDy
9267 || w.mLastHScale != w.mHScale
9268 || w.mLastVScale != w.mVScale
9269 || w.mLastHidden) {
9270 displayed = true;
9271 w.mLastAlpha = w.mShownAlpha;
9272 w.mLastLayer = w.mAnimLayer;
9273 w.mLastDsDx = w.mDsDx;
9274 w.mLastDtDx = w.mDtDx;
9275 w.mLastDsDy = w.mDsDy;
9276 w.mLastDtDy = w.mDtDy;
9277 w.mLastHScale = w.mHScale;
9278 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009279 if (SHOW_TRANSACTIONS) logSurface(w,
9280 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009281 + " matrix=[" + (w.mDsDx*w.mHScale)
9282 + "," + (w.mDtDx*w.mVScale)
9283 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009284 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009285 if (w.mSurface != null) {
9286 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009287 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009288 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009289 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009290 w.mSurface.setLayer(w.mAnimLayer);
9291 w.mSurface.setMatrix(
9292 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9293 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9294 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009295 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009296 if (!recoveringMemory) {
9297 reclaimSomeSurfaceMemoryLocked(w, "update");
9298 }
9299 }
9300 }
9301
9302 if (w.mLastHidden && !w.mDrawPending
9303 && !w.mCommitDrawPending
9304 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009305 if (SHOW_TRANSACTIONS) logSurface(w,
9306 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009307 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009308 + " during relayout");
9309 if (showSurfaceRobustlyLocked(w)) {
9310 w.mHasDrawn = true;
9311 w.mLastHidden = false;
9312 } else {
9313 w.mOrientationChanging = false;
9314 }
9315 }
9316 if (w.mSurface != null) {
9317 w.mToken.hasVisible = true;
9318 }
9319 } else {
9320 displayed = true;
9321 }
9322
9323 if (displayed) {
9324 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009325 if (attrs.width == LayoutParams.MATCH_PARENT
9326 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 covered = true;
9328 }
9329 }
9330 if (w.mOrientationChanging) {
9331 if (w.mDrawPending || w.mCommitDrawPending) {
9332 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009333 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009334 "Orientation continue waiting for draw in " + w);
9335 } else {
9336 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009337 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009338 "Orientation change complete in " + w);
9339 }
9340 }
9341 w.mToken.hasVisible = true;
9342 }
9343 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009344 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009345 "Orientation change skips hidden " + w);
9346 w.mOrientationChanging = false;
9347 }
9348
9349 final boolean canBeSeen = w.isDisplayedLw();
9350
9351 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9352 focusDisplayed = true;
9353 }
9354
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009355 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009357 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009358 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009359 if (w.mSurface != null) {
9360 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9361 holdScreen = w.mSession;
9362 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009363 if (!syswin && w.mAttrs.screenBrightness >= 0
9364 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009365 screenBrightness = w.mAttrs.screenBrightness;
9366 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009367 if (!syswin && w.mAttrs.buttonBrightness >= 0
9368 && buttonBrightness < 0) {
9369 buttonBrightness = w.mAttrs.buttonBrightness;
9370 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009371 if (canBeSeen
9372 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9373 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9374 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009375 syswin = true;
9376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009377 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009378
Dianne Hackborn25994b42009-09-04 14:21:19 -07009379 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9380 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 // This window completely covers everything behind it,
9382 // so we want to leave all of them as unblurred (for
9383 // performance reasons).
9384 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009385 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009386 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009387 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009388 obscured = true;
9389 if (mBackgroundFillerSurface == null) {
9390 try {
9391 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009392 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009393 0, dw, dh,
9394 PixelFormat.OPAQUE,
9395 Surface.FX_SURFACE_NORMAL);
9396 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009397 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009398 }
9399 }
9400 try {
9401 mBackgroundFillerSurface.setPosition(0, 0);
9402 mBackgroundFillerSurface.setSize(dw, dh);
9403 // Using the same layer as Dim because they will never be shown at the
9404 // same time.
9405 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9406 mBackgroundFillerSurface.show();
9407 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009408 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009409 }
9410 backgroundFillerShown = true;
9411 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009412 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009413 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009414 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 + ": blurring=" + blurring
9416 + " obscured=" + obscured
9417 + " displayed=" + displayed);
9418 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9419 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009420 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009421 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009422 if (mDimAnimator == null) {
9423 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009424 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009425 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009426 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009428 }
9429 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9430 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009431 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009432 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009433 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009434 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009435 + mBlurSurface + ": CREATE");
9436 try {
Romain Guy06882f82009-06-10 13:36:04 -07009437 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009438 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009439 -1, 16, 16,
9440 PixelFormat.OPAQUE,
9441 Surface.FX_SURFACE_BLUR);
9442 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009443 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009444 }
9445 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009446 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009447 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9448 + mBlurSurface + ": pos=(0,0) (" +
9449 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009450 mBlurSurface.setPosition(0, 0);
9451 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009452 mBlurSurface.setLayer(w.mAnimLayer-2);
9453 if (!mBlurShown) {
9454 try {
9455 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9456 + mBlurSurface + ": SHOW");
9457 mBlurSurface.show();
9458 } catch (RuntimeException e) {
9459 Slog.w(TAG, "Failure showing blur surface", e);
9460 }
9461 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009462 }
9463 }
9464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009465 }
9466 }
9467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009468
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009469 if (obscuredChanged && mWallpaperTarget == w) {
9470 // This is the wallpaper target and its obscured state
9471 // changed... make sure the current wallaper's visibility
9472 // has been updated accordingly.
9473 updateWallpaperVisibilityLocked();
9474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009475 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009476
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009477 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9478 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009479 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009480 try {
9481 mBackgroundFillerSurface.hide();
9482 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009483 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009484 }
9485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009487 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009488 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9489 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009490 }
Romain Guy06882f82009-06-10 13:36:04 -07009491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009492 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009493 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 + ": HIDE");
9495 try {
9496 mBlurSurface.hide();
9497 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009498 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 }
9500 mBlurShown = false;
9501 }
9502
Joe Onorato8a9b2202010-02-26 18:56:32 -08009503 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009504 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009505 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009506 }
9507
Jeff Browne33348b2010-07-15 23:54:05 -07009508 mInputMonitor.updateInputWindowsLw();
9509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009511
Joe Onorato8a9b2202010-02-26 18:56:32 -08009512 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009513 "With display frozen, orientationChangeComplete="
9514 + orientationChangeComplete);
9515 if (orientationChangeComplete) {
9516 if (mWindowsFreezingScreen) {
9517 mWindowsFreezingScreen = false;
9518 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9519 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009520 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009521 }
Romain Guy06882f82009-06-10 13:36:04 -07009522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 i = mResizingWindows.size();
9524 if (i > 0) {
9525 do {
9526 i--;
9527 WindowState win = mResizingWindows.get(i);
9528 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009529 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9530 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009531 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009532 boolean configChanged =
9533 win.mConfiguration != mCurConfiguration
9534 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009535 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9536 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9537 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009538 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009539 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009540 + " / " + mCurConfiguration + " / 0x"
9541 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009542 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009543 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009544 win.mClient.resized(win.mFrame.width(),
9545 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009546 win.mLastVisibleInsets, win.mDrawPending,
9547 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 win.mContentInsetsChanged = false;
9549 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009550 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009551 } catch (RemoteException e) {
9552 win.mOrientationChanging = false;
9553 }
9554 } while (i > 0);
9555 mResizingWindows.clear();
9556 }
Romain Guy06882f82009-06-10 13:36:04 -07009557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009558 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009559 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 i = mDestroySurface.size();
9561 if (i > 0) {
9562 do {
9563 i--;
9564 WindowState win = mDestroySurface.get(i);
9565 win.mDestroying = false;
9566 if (mInputMethodWindow == win) {
9567 mInputMethodWindow = null;
9568 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009569 if (win == mWallpaperTarget) {
9570 wallpaperDestroyed = true;
9571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 win.destroySurfaceLocked();
9573 } while (i > 0);
9574 mDestroySurface.clear();
9575 }
9576
9577 // Time to remove any exiting tokens?
9578 for (i=mExitingTokens.size()-1; i>=0; i--) {
9579 WindowToken token = mExitingTokens.get(i);
9580 if (!token.hasVisible) {
9581 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009582 if (token.windowType == TYPE_WALLPAPER) {
9583 mWallpaperTokens.remove(token);
9584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009585 }
9586 }
9587
9588 // Time to remove any exiting applications?
9589 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9590 AppWindowToken token = mExitingAppTokens.get(i);
9591 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009592 // Make sure there is no animation running on this token,
9593 // so any windows associated with it will be removed as
9594 // soon as their animations are complete
9595 token.animation = null;
9596 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009597 mAppTokens.remove(token);
9598 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009599 if (mLastEnterAnimToken == token) {
9600 mLastEnterAnimToken = null;
9601 mLastEnterAnimParams = null;
9602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009603 }
9604 }
9605
Dianne Hackborna8f60182009-09-01 19:01:50 -07009606 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009607
Dianne Hackborna8f60182009-09-01 19:01:50 -07009608 if (!animating && mAppTransitionRunning) {
9609 // We have finished the animation of an app transition. To do
9610 // this, we have delayed a lot of operations like showing and
9611 // hiding apps, moving apps in Z-order, etc. The app token list
9612 // reflects the correct Z-order, but the window list may now
9613 // be out of sync with it. So here we will just rebuild the
9614 // entire app window list. Fun!
9615 mAppTransitionRunning = false;
9616 needRelayout = true;
9617 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009618 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009619 // Clear information about apps that were moving.
9620 mToBottomApps.clear();
9621 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009623 if (focusDisplayed) {
9624 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9625 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009626 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009627 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009628 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009629 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009630 requestAnimationLocked(0);
9631 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009632 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9633 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009634
Jeff Browne33348b2010-07-15 23:54:05 -07009635 mInputMonitor.updateInputWindowsLw();
9636
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009637 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9638 + " holdScreen=" + holdScreen);
9639 if (!mDisplayFrozen) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009640 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009641 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9642 mPowerManager.setScreenBrightnessOverride(-1);
9643 } else {
9644 mPowerManager.setScreenBrightnessOverride((int)
9645 (screenBrightness * Power.BRIGHTNESS_ON));
9646 }
9647 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9648 mPowerManager.setButtonBrightnessOverride(-1);
9649 } else {
9650 mPowerManager.setButtonBrightnessOverride((int)
9651 (buttonBrightness * Power.BRIGHTNESS_ON));
9652 }
9653 if (holdScreen != mHoldingScreenOn) {
9654 mHoldingScreenOn = holdScreen;
9655 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9656 mH.sendMessage(m);
9657 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009658 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009659
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009660 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009661 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009662 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9663 LocalPowerManager.BUTTON_EVENT, true);
9664 mTurnOnScreen = false;
9665 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009666
9667 // Check to see if we are now in a state where the screen should
9668 // be enabled, because the window obscured flags have changed.
9669 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009670 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009671
9672 /**
9673 * Must be called with the main window manager lock held.
9674 */
9675 void setHoldScreenLocked(boolean holding) {
9676 boolean state = mHoldingScreenWakeLock.isHeld();
9677 if (holding != state) {
9678 if (holding) {
9679 mHoldingScreenWakeLock.acquire();
9680 } else {
9681 mPolicy.screenOnStoppedLw();
9682 mHoldingScreenWakeLock.release();
9683 }
9684 }
9685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009686
9687 void requestAnimationLocked(long delay) {
9688 if (!mAnimationPending) {
9689 mAnimationPending = true;
9690 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9691 }
9692 }
Romain Guy06882f82009-06-10 13:36:04 -07009693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009694 /**
9695 * Have the surface flinger show a surface, robustly dealing with
9696 * error conditions. In particular, if there is not enough memory
9697 * to show the surface, then we will try to get rid of other surfaces
9698 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009699 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009700 * @return Returns true if the surface was successfully shown.
9701 */
9702 boolean showSurfaceRobustlyLocked(WindowState win) {
9703 try {
9704 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009705 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009706 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009707 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009708 if (DEBUG_VISIBILITY) Slog.v(TAG,
9709 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009710 win.mTurnOnScreen = false;
9711 mTurnOnScreen = true;
9712 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009713 }
9714 return true;
9715 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009716 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009717 }
Romain Guy06882f82009-06-10 13:36:04 -07009718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009719 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009721 return false;
9722 }
Romain Guy06882f82009-06-10 13:36:04 -07009723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009724 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9725 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009726
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009727 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009730 if (mForceRemoves == null) {
9731 mForceRemoves = new ArrayList<WindowState>();
9732 }
Romain Guy06882f82009-06-10 13:36:04 -07009733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009734 long callingIdentity = Binder.clearCallingIdentity();
9735 try {
9736 // There was some problem... first, do a sanity check of the
9737 // window list to make sure we haven't left any dangling surfaces
9738 // around.
9739 int N = mWindows.size();
9740 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009741 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009743 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009744 if (ws.mSurface != null) {
9745 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009746 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009747 + ws + " surface=" + ws.mSurface
9748 + " token=" + win.mToken
9749 + " pid=" + ws.mSession.mPid
9750 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009751 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009752 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009753 ws.mSurface = null;
9754 mForceRemoves.add(ws);
9755 i--;
9756 N--;
9757 leakedSurface = true;
9758 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009759 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009760 + ws + " surface=" + ws.mSurface
9761 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009762 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009763 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 ws.mSurface = null;
9765 leakedSurface = true;
9766 }
9767 }
9768 }
Romain Guy06882f82009-06-10 13:36:04 -07009769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009770 boolean killedApps = false;
9771 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009772 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009773 SparseIntArray pidCandidates = new SparseIntArray();
9774 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009775 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009776 if (ws.mSurface != null) {
9777 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9778 }
9779 }
9780 if (pidCandidates.size() > 0) {
9781 int[] pids = new int[pidCandidates.size()];
9782 for (int i=0; i<pids.length; i++) {
9783 pids[i] = pidCandidates.keyAt(i);
9784 }
9785 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009786 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 killedApps = true;
9788 }
9789 } catch (RemoteException e) {
9790 }
9791 }
9792 }
Romain Guy06882f82009-06-10 13:36:04 -07009793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 if (leakedSurface || killedApps) {
9795 // We managed to reclaim some memory, so get rid of the trouble
9796 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009797 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009798 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009799 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009800 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 win.mSurface = null;
9802 }
Romain Guy06882f82009-06-10 13:36:04 -07009803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 try {
9805 win.mClient.dispatchGetNewSurface();
9806 } catch (RemoteException e) {
9807 }
9808 }
9809 } finally {
9810 Binder.restoreCallingIdentity(callingIdentity);
9811 }
9812 }
Romain Guy06882f82009-06-10 13:36:04 -07009813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009814 private boolean updateFocusedWindowLocked(int mode) {
9815 WindowState newFocus = computeFocusedWindowLocked();
9816 if (mCurrentFocus != newFocus) {
9817 // This check makes sure that we don't already have the focus
9818 // change message pending.
9819 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9820 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009821 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009822 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9823 final WindowState oldFocus = mCurrentFocus;
9824 mCurrentFocus = newFocus;
9825 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009827 final WindowState imWindow = mInputMethodWindow;
9828 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009829 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009830 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009831 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9832 mLayoutNeeded = true;
9833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009834 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9835 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009836 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9837 // Client will do the layout, but we need to assign layers
9838 // for handleNewWindowLocked() below.
9839 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 }
9841 }
Jeff Brown349703e2010-06-22 01:27:15 -07009842
9843 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9844 // If we defer assigning layers, then the caller is responsible for
9845 // doing this part.
9846 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009847 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 return true;
9849 }
9850 return false;
9851 }
Jeff Brown349703e2010-06-22 01:27:15 -07009852
9853 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009854 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009855 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856
9857 private WindowState computeFocusedWindowLocked() {
9858 WindowState result = null;
9859 WindowState win;
9860
9861 int i = mWindows.size() - 1;
9862 int nextAppIndex = mAppTokens.size()-1;
9863 WindowToken nextApp = nextAppIndex >= 0
9864 ? mAppTokens.get(nextAppIndex) : null;
9865
9866 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009867 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868
Joe Onorato8a9b2202010-02-26 18:56:32 -08009869 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009870 TAG, "Looking for focus: " + i
9871 + " = " + win
9872 + ", flags=" + win.mAttrs.flags
9873 + ", canReceive=" + win.canReceiveKeys());
9874
9875 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009877 // If this window's application has been removed, just skip it.
9878 if (thisApp != null && thisApp.removed) {
9879 i--;
9880 continue;
9881 }
Romain Guy06882f82009-06-10 13:36:04 -07009882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883 // If there is a focused app, don't allow focus to go to any
9884 // windows below it. If this is an application window, step
9885 // through the app tokens until we find its app.
9886 if (thisApp != null && nextApp != null && thisApp != nextApp
9887 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9888 int origAppIndex = nextAppIndex;
9889 while (nextAppIndex > 0) {
9890 if (nextApp == mFocusedApp) {
9891 // Whoops, we are below the focused app... no focus
9892 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009893 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009894 TAG, "Reached focused app: " + mFocusedApp);
9895 return null;
9896 }
9897 nextAppIndex--;
9898 nextApp = mAppTokens.get(nextAppIndex);
9899 if (nextApp == thisApp) {
9900 break;
9901 }
9902 }
9903 if (thisApp != nextApp) {
9904 // Uh oh, the app token doesn't exist! This shouldn't
9905 // happen, but if it does we can get totally hosed...
9906 // so restart at the original app.
9907 nextAppIndex = origAppIndex;
9908 nextApp = mAppTokens.get(nextAppIndex);
9909 }
9910 }
9911
9912 // Dispatch to this window if it is wants key events.
9913 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009914 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009915 TAG, "Found focus @ " + i + " = " + win);
9916 result = win;
9917 break;
9918 }
9919
9920 i--;
9921 }
9922
9923 return result;
9924 }
9925
9926 private void startFreezingDisplayLocked() {
9927 if (mDisplayFrozen) {
9928 return;
9929 }
Romain Guy06882f82009-06-10 13:36:04 -07009930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009931 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -07009932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009933 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009934 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009935 if (mFreezeGcPending != 0) {
9936 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009937 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009938 mH.removeMessages(H.FORCE_GC);
9939 Runtime.getRuntime().gc();
9940 mFreezeGcPending = now;
9941 }
9942 } else {
9943 mFreezeGcPending = now;
9944 }
Romain Guy06882f82009-06-10 13:36:04 -07009945
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009946 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
9947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009948 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -07009949
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009950 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -07009951
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009952 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
9953 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009954 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009955 mAppTransitionReady = true;
9956 }
Romain Guy06882f82009-06-10 13:36:04 -07009957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009958 if (PROFILE_ORIENTATION) {
9959 File file = new File("/data/system/frozen");
9960 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
9961 }
9962 Surface.freezeDisplay(0);
9963 }
Romain Guy06882f82009-06-10 13:36:04 -07009964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 private void stopFreezingDisplayLocked() {
9966 if (!mDisplayFrozen) {
9967 return;
9968 }
Romain Guy06882f82009-06-10 13:36:04 -07009969
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009970 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
9971 return;
9972 }
9973
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009974 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
9975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009976 mDisplayFrozen = false;
9977 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
9978 if (PROFILE_ORIENTATION) {
9979 Debug.stopMethodTracing();
9980 }
9981 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -07009982
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009983 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984
Christopher Tateb696aee2010-04-02 19:08:30 -07009985 // While the display is frozen we don't re-compute the orientation
9986 // to avoid inconsistent states. However, something interesting
9987 // could have actually changed during that time so re-evaluate it
9988 // now to catch that.
9989 if (updateOrientationFromAppTokensLocked()) {
9990 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9991 }
9992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009993 // A little kludge: a lot could have happened while the
9994 // display was frozen, so now that we are coming back we
9995 // do a gc so that any remote references the system
9996 // processes holds on others can be released if they are
9997 // no longer needed.
9998 mH.removeMessages(H.FORCE_GC);
9999 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10000 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010002 mScreenFrozenLock.release();
10003 }
Romain Guy06882f82009-06-10 13:36:04 -070010004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 @Override
10006 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10007 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10008 != PackageManager.PERMISSION_GRANTED) {
10009 pw.println("Permission Denial: can't dump WindowManager from from pid="
10010 + Binder.getCallingPid()
10011 + ", uid=" + Binder.getCallingUid());
10012 return;
10013 }
Romain Guy06882f82009-06-10 13:36:04 -070010014
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010015 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010016 pw.println(" ");
10017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 synchronized(mWindowMap) {
10019 pw.println("Current Window Manager state:");
10020 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010021 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010022 pw.print(" Window #"); pw.print(i); pw.print(' ');
10023 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 w.dump(pw, " ");
10025 }
10026 if (mInputMethodDialogs.size() > 0) {
10027 pw.println(" ");
10028 pw.println(" Input method dialogs:");
10029 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10030 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010031 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010032 }
10033 }
10034 if (mPendingRemove.size() > 0) {
10035 pw.println(" ");
10036 pw.println(" Remove pending for:");
10037 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10038 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010039 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10040 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010041 w.dump(pw, " ");
10042 }
10043 }
10044 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10045 pw.println(" ");
10046 pw.println(" Windows force removing:");
10047 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10048 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010049 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10050 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010051 w.dump(pw, " ");
10052 }
10053 }
10054 if (mDestroySurface.size() > 0) {
10055 pw.println(" ");
10056 pw.println(" Windows waiting to destroy their surface:");
10057 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10058 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010059 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10060 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010061 w.dump(pw, " ");
10062 }
10063 }
10064 if (mLosingFocus.size() > 0) {
10065 pw.println(" ");
10066 pw.println(" Windows losing focus:");
10067 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10068 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010069 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10070 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010071 w.dump(pw, " ");
10072 }
10073 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010074 if (mResizingWindows.size() > 0) {
10075 pw.println(" ");
10076 pw.println(" Windows waiting to resize:");
10077 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10078 WindowState w = mResizingWindows.get(i);
10079 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10080 pw.print(w); pw.println(":");
10081 w.dump(pw, " ");
10082 }
10083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010084 if (mSessions.size() > 0) {
10085 pw.println(" ");
10086 pw.println(" All active sessions:");
10087 Iterator<Session> it = mSessions.iterator();
10088 while (it.hasNext()) {
10089 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010090 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010091 s.dump(pw, " ");
10092 }
10093 }
10094 if (mTokenMap.size() > 0) {
10095 pw.println(" ");
10096 pw.println(" All tokens:");
10097 Iterator<WindowToken> it = mTokenMap.values().iterator();
10098 while (it.hasNext()) {
10099 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010100 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010101 token.dump(pw, " ");
10102 }
10103 }
10104 if (mTokenList.size() > 0) {
10105 pw.println(" ");
10106 pw.println(" Window token list:");
10107 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010108 pw.print(" #"); pw.print(i); pw.print(": ");
10109 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010110 }
10111 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010112 if (mWallpaperTokens.size() > 0) {
10113 pw.println(" ");
10114 pw.println(" Wallpaper tokens:");
10115 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10116 WindowToken token = mWallpaperTokens.get(i);
10117 pw.print(" Wallpaper #"); pw.print(i);
10118 pw.print(' '); pw.print(token); pw.println(':');
10119 token.dump(pw, " ");
10120 }
10121 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010122 if (mAppTokens.size() > 0) {
10123 pw.println(" ");
10124 pw.println(" Application tokens in Z order:");
10125 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010126 pw.print(" App #"); pw.print(i); pw.print(": ");
10127 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010128 }
10129 }
10130 if (mFinishedStarting.size() > 0) {
10131 pw.println(" ");
10132 pw.println(" Finishing start of application tokens:");
10133 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10134 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010135 pw.print(" Finished Starting #"); pw.print(i);
10136 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010137 token.dump(pw, " ");
10138 }
10139 }
10140 if (mExitingTokens.size() > 0) {
10141 pw.println(" ");
10142 pw.println(" Exiting tokens:");
10143 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10144 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010145 pw.print(" Exiting #"); pw.print(i);
10146 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010147 token.dump(pw, " ");
10148 }
10149 }
10150 if (mExitingAppTokens.size() > 0) {
10151 pw.println(" ");
10152 pw.println(" Exiting application tokens:");
10153 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10154 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010155 pw.print(" Exiting App #"); pw.print(i);
10156 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010157 token.dump(pw, " ");
10158 }
10159 }
10160 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010161 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10162 pw.print(" mLastFocus="); pw.println(mLastFocus);
10163 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10164 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10165 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010166 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010167 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10168 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10169 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10170 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010171 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10172 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10173 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010174 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10175 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10176 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10177 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010178 if (mDimAnimator != null) {
10179 mDimAnimator.printTo(pw);
10180 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010181 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010182 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010183 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010184 pw.print(mInputMethodAnimLayerAdjustment);
10185 pw.print(" mWallpaperAnimLayerAdjustment=");
10186 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010187 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10188 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010189 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10190 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010191 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10192 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010193 pw.print(" mRotation="); pw.print(mRotation);
10194 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10195 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10196 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10197 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10198 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10199 pw.print(" mNextAppTransition=0x");
10200 pw.print(Integer.toHexString(mNextAppTransition));
10201 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010202 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010203 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010204 if (mNextAppTransitionPackage != null) {
10205 pw.print(" mNextAppTransitionPackage=");
10206 pw.print(mNextAppTransitionPackage);
10207 pw.print(", mNextAppTransitionEnter=0x");
10208 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10209 pw.print(", mNextAppTransitionExit=0x");
10210 pw.print(Integer.toHexString(mNextAppTransitionExit));
10211 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010212 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10213 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010214 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10215 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10216 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10217 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010218 if (mOpeningApps.size() > 0) {
10219 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10220 }
10221 if (mClosingApps.size() > 0) {
10222 pw.print(" mClosingApps="); pw.println(mClosingApps);
10223 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010224 if (mToTopApps.size() > 0) {
10225 pw.print(" mToTopApps="); pw.println(mToTopApps);
10226 }
10227 if (mToBottomApps.size() > 0) {
10228 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10229 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010230 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10231 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010232 }
10233 }
10234
Jeff Brown349703e2010-06-22 01:27:15 -070010235 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010236 public void monitor() {
10237 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010238 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010239 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010240
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010241 /**
10242 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010243 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010244 */
10245 private static class DimAnimator {
10246 Surface mDimSurface;
10247 boolean mDimShown = false;
10248 float mDimCurrentAlpha;
10249 float mDimTargetAlpha;
10250 float mDimDeltaPerMs;
10251 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010252
10253 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010254
10255 DimAnimator (SurfaceSession session) {
10256 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010257 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010258 + mDimSurface + ": CREATE");
10259 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010260 mDimSurface = new Surface(session, 0,
10261 "DimSurface",
10262 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010263 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010264 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010265 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010266 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010267 }
10268 }
10269 }
10270
10271 /**
10272 * Show the dim surface.
10273 */
10274 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010275 if (!mDimShown) {
10276 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10277 dw + "x" + dh + ")");
10278 mDimShown = true;
10279 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010280 mLastDimWidth = dw;
10281 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010282 mDimSurface.setPosition(0, 0);
10283 mDimSurface.setSize(dw, dh);
10284 mDimSurface.show();
10285 } catch (RuntimeException e) {
10286 Slog.w(TAG, "Failure showing dim surface", e);
10287 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010288 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10289 mLastDimWidth = dw;
10290 mLastDimHeight = dh;
10291 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010292 }
10293 }
10294
10295 /**
10296 * Set's the dim surface's layer and update dim parameters that will be used in
10297 * {@link updateSurface} after all windows are examined.
10298 */
10299 void updateParameters(WindowState w, long currentTime) {
10300 mDimSurface.setLayer(w.mAnimLayer-1);
10301
10302 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010303 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010304 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010305 if (mDimTargetAlpha != target) {
10306 // If the desired dim level has changed, then
10307 // start an animation to it.
10308 mLastDimAnimTime = currentTime;
10309 long duration = (w.mAnimating && w.mAnimation != null)
10310 ? w.mAnimation.computeDurationHint()
10311 : DEFAULT_DIM_DURATION;
10312 if (target > mDimTargetAlpha) {
10313 // This is happening behind the activity UI,
10314 // so we can make it run a little longer to
10315 // give a stronger impression without disrupting
10316 // the user.
10317 duration *= DIM_DURATION_MULTIPLIER;
10318 }
10319 if (duration < 1) {
10320 // Don't divide by zero
10321 duration = 1;
10322 }
10323 mDimTargetAlpha = target;
10324 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10325 }
10326 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010327
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010328 /**
10329 * Updating the surface's alpha. Returns true if the animation continues, or returns
10330 * false when the animation is finished and the dim surface is hidden.
10331 */
10332 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10333 if (!dimming) {
10334 if (mDimTargetAlpha != 0) {
10335 mLastDimAnimTime = currentTime;
10336 mDimTargetAlpha = 0;
10337 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10338 }
10339 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010340
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010341 boolean animating = false;
10342 if (mLastDimAnimTime != 0) {
10343 mDimCurrentAlpha += mDimDeltaPerMs
10344 * (currentTime-mLastDimAnimTime);
10345 boolean more = true;
10346 if (displayFrozen) {
10347 // If the display is frozen, there is no reason to animate.
10348 more = false;
10349 } else if (mDimDeltaPerMs > 0) {
10350 if (mDimCurrentAlpha > mDimTargetAlpha) {
10351 more = false;
10352 }
10353 } else if (mDimDeltaPerMs < 0) {
10354 if (mDimCurrentAlpha < mDimTargetAlpha) {
10355 more = false;
10356 }
10357 } else {
10358 more = false;
10359 }
10360
10361 // Do we need to continue animating?
10362 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010363 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010364 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10365 mLastDimAnimTime = currentTime;
10366 mDimSurface.setAlpha(mDimCurrentAlpha);
10367 animating = true;
10368 } else {
10369 mDimCurrentAlpha = mDimTargetAlpha;
10370 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010371 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010372 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10373 mDimSurface.setAlpha(mDimCurrentAlpha);
10374 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010375 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010376 + ": HIDE");
10377 try {
10378 mDimSurface.hide();
10379 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010380 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010381 }
10382 mDimShown = false;
10383 }
10384 }
10385 }
10386 return animating;
10387 }
10388
10389 public void printTo(PrintWriter pw) {
10390 pw.print(" mDimShown="); pw.print(mDimShown);
10391 pw.print(" current="); pw.print(mDimCurrentAlpha);
10392 pw.print(" target="); pw.print(mDimTargetAlpha);
10393 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10394 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10395 }
10396 }
10397
10398 /**
10399 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10400 * This is used for opening/closing transition for apps in compatible mode.
10401 */
10402 private static class FadeInOutAnimation extends Animation {
10403 int mWidth;
10404 boolean mFadeIn;
10405
10406 public FadeInOutAnimation(boolean fadeIn) {
10407 setInterpolator(new AccelerateInterpolator());
10408 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10409 mFadeIn = fadeIn;
10410 }
10411
10412 @Override
10413 protected void applyTransformation(float interpolatedTime, Transformation t) {
10414 float x = interpolatedTime;
10415 if (!mFadeIn) {
10416 x = 1.0f - x; // reverse the interpolation for fade out
10417 }
10418 if (x < 0.5) {
10419 // move the window out of the screen.
10420 t.getMatrix().setTranslate(mWidth, 0);
10421 } else {
10422 t.getMatrix().setTranslate(0, 0);// show
10423 t.setAlpha((x - 0.5f) * 2);
10424 }
10425 }
10426
10427 @Override
10428 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10429 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10430 mWidth = width;
10431 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010432
10433 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010434 public int getZAdjustment() {
10435 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010436 }
10437 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010438}