blob: 57f93c44638055249856e18ddeb010c1f6ec798b [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;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070065import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070067import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.graphics.PixelFormat;
69import android.graphics.Rect;
70import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070071import android.graphics.Typeface;
72import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.BatteryStats;
74import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070075import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import android.os.Debug;
77import android.os.Handler;
78import android.os.IBinder;
Michael Chan53071d62009-05-13 17:29:48 -070079import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080import android.os.LocalPowerManager;
81import android.os.Looper;
82import android.os.Message;
83import android.os.Parcel;
84import android.os.ParcelFileDescriptor;
85import android.os.Power;
86import android.os.PowerManager;
87import android.os.Process;
88import android.os.RemoteException;
89import android.os.ServiceManager;
90import android.os.SystemClock;
91import android.os.SystemProperties;
92import android.os.TokenWatcher;
93import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070094import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070096import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080097import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070099import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Display;
101import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700102import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103import android.view.IApplicationToken;
104import android.view.IOnKeyguardExitResult;
105import android.view.IRotationWatcher;
106import android.view.IWindow;
107import android.view.IWindowManager;
108import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700109import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700111import android.view.InputEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
Dianne Hackborn83fe3f52009-09-12 23:38:30 -0700118import android.view.ViewConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119import android.view.ViewTreeObserver;
120import android.view.WindowManager;
121import android.view.WindowManagerImpl;
122import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700123import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700125import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import android.view.animation.Animation;
127import android.view.animation.AnimationUtils;
128import android.view.animation.Transformation;
129
130import java.io.BufferedWriter;
131import java.io.File;
132import java.io.FileDescriptor;
133import java.io.IOException;
134import java.io.OutputStream;
135import java.io.OutputStreamWriter;
136import java.io.PrintWriter;
137import java.io.StringWriter;
138import java.net.Socket;
139import java.util.ArrayList;
140import java.util.HashMap;
141import java.util.HashSet;
142import java.util.Iterator;
143import java.util.List;
144
145/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700146public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700147 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 static final String TAG = "WindowManager";
149 static final boolean DEBUG = false;
150 static final boolean DEBUG_FOCUS = false;
151 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800152 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800153 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 static final boolean DEBUG_LAYERS = false;
155 static final boolean DEBUG_INPUT = false;
156 static final boolean DEBUG_INPUT_METHOD = false;
157 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700158 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700160 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 static final boolean DEBUG_APP_TRANSITIONS = false;
162 static final boolean DEBUG_STARTING_WINDOW = false;
163 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700164 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700166 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700167 static final boolean MEASURE_LATENCY = false;
168 static private LatencyTimer lt;
169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 static final boolean PROFILE_ORIENTATION = false;
171 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700172 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /** How much to multiply the policy's type layer, to reserve room
175 * for multiple windows of the same type and Z-ordering adjustment
176 * with TYPE_LAYER_OFFSET. */
177 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
180 * or below others in the same layer. */
181 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 /** How much to increment the layer for each window, to reserve room
184 * for effect surfaces between them.
185 */
186 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 /** The maximum length we will accept for a loaded animation duration:
189 * this is 10 seconds.
190 */
191 static final int MAX_ANIMATION_DURATION = 10*1000;
192
193 /** Amount of time (in milliseconds) to animate the dim surface from one
194 * value to another, when no window animation is driving it.
195 */
196 static final int DEFAULT_DIM_DURATION = 200;
197
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700198 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
199 * compatible windows.
200 */
201 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 /** Adjustment to time to perform a dim, to make it more dramatic.
204 */
205 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700206
207 // Maximum number of milliseconds to wait for input event injection.
208 // FIXME is this value reasonable?
209 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700210
211 // Default input dispatching timeout in nanoseconds.
212 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 static final int UPDATE_FOCUS_NORMAL = 0;
215 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
216 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
217 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700220 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221
222 /**
223 * Condition waited on by {@link #reenableKeyguard} to know the call to
224 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500225 * This is set to true only if mKeyguardTokenWatcher.acquired() has
226 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500228 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229
Jim Miller284b62e2010-06-08 14:27:42 -0700230 private static final int ALLOW_DISABLE_YES = 1;
231 private static final int ALLOW_DISABLE_NO = 0;
232 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
233 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
234
Mike Lockwood983ee092009-11-22 01:42:24 -0500235 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
236 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700238 if (shouldAllowDisableKeyguard()) {
239 mPolicy.enableKeyguard(false);
240 mKeyguardDisabled = true;
241 } else {
242 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700246 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500247 synchronized (mKeyguardTokenWatcher) {
248 mKeyguardDisabled = false;
249 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 }
251 }
252 };
253
Jim Miller284b62e2010-06-08 14:27:42 -0700254 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
255 @Override
256 public void onReceive(Context context, Intent intent) {
257 mPolicy.enableKeyguard(true);
258 synchronized(mKeyguardTokenWatcher) {
259 // lazily evaluate this next time we're asked to disable keyguard
260 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
261 mKeyguardDisabled = false;
262 }
263 }
264 };
265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 final Context mContext;
267
268 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
273
274 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * All currently active sessions with clients.
280 */
281 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 /**
284 * Mapping from an IWindow IBinder to the server's Window object.
285 * This is also used as the lock for all of our state.
286 */
287 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
288
289 /**
290 * Mapping from a token IBinder to a WindowToken object.
291 */
292 final HashMap<IBinder, WindowToken> mTokenMap =
293 new HashMap<IBinder, WindowToken>();
294
295 /**
296 * The same tokens as mTokenMap, stored in a list for efficient iteration
297 * over them.
298 */
299 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 /**
302 * Window tokens that are in the process of exiting, but still
303 * on screen for animations.
304 */
305 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
306
307 /**
308 * Z-ordered (bottom-most first) list of all application tokens, for
309 * controlling the ordering of windows in different applications. This
310 * contains WindowToken objects.
311 */
312 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
313
314 /**
315 * Application tokens that are in the process of exiting, but still
316 * on screen for animations.
317 */
318 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
319
320 /**
321 * List of window tokens that have finished starting their application,
322 * and now need to have the policy remove their windows.
323 */
324 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
325
326 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700327 * This was the app token that was used to retrieve the last enter
328 * animation. It will be used for the next exit animation.
329 */
330 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800331
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700332 /**
333 * These were the layout params used to retrieve the last enter animation.
334 * They will be used for the next exit animation.
335 */
336 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800337
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700338 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 * Z-ordered (bottom-most first) list of all Window objects.
340 */
Jeff Browne33348b2010-07-15 23:54:05 -0700341 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342
343 /**
344 * Windows that are being resized. Used so we can tell the client about
345 * the resize after closing the transaction in which we resized the
346 * underlying surface.
347 */
348 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
349
350 /**
351 * Windows whose animations have ended and now must be removed.
352 */
353 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
354
355 /**
356 * Windows whose surface should be destroyed.
357 */
358 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
359
360 /**
361 * Windows that have lost input focus and are waiting for the new
362 * focus window to be displayed before they are told about this.
363 */
364 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
365
366 /**
367 * This is set when we have run out of memory, and will either be an empty
368 * list or contain windows that need to be force removed.
369 */
370 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700375 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 Surface mBlurSurface;
377 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700378 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 final float[] mTmpFloats = new float[9];
383
384 boolean mSafeMode;
385 boolean mDisplayEnabled = false;
386 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700387 int mInitialDisplayWidth = 0;
388 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 int mRotation = 0;
390 int mRequestedRotation = 0;
391 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700392 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 ArrayList<IRotationWatcher> mRotationWatchers
394 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 boolean mLayoutNeeded = true;
397 boolean mAnimationPending = false;
398 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800399 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 boolean mWindowsFreezingScreen = false;
401 long mFreezeGcPending = 0;
402 int mAppsFreezingScreen = 0;
403
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800404 int mLayoutSeq = 0;
405
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800406 // State while inside of layoutAndPlaceSurfacesLocked().
407 boolean mFocusMayChange;
408
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800409 Configuration mCurConfiguration = new Configuration();
410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // This is held as long as we have the screen frozen, to give us time to
412 // perform a rotation animation when turning off shows the lock screen which
413 // changes the orientation.
414 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 // State management of app transitions. When we are preparing for a
417 // transition, mNextAppTransition will be the kind of transition to
418 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
419 // mOpeningApps and mClosingApps are the lists of tokens that will be
420 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700421 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700422 String mNextAppTransitionPackage;
423 int mNextAppTransitionEnter;
424 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700426 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionTimeout = false;
428 boolean mStartingIconInTransition = false;
429 boolean mSkipAppTransitionAnimation = false;
430 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
431 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700432 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 H mH = new H();
438
439 WindowState mCurrentFocus = null;
440 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 // This just indicates the window the input method is on top of, not
443 // necessarily the window its input is going to.
444 WindowState mInputMethodTarget = null;
445 WindowState mUpcomingInputMethodTarget = null;
446 boolean mInputMethodTargetWaitingAnim;
447 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 WindowState mInputMethodWindow = null;
450 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
451
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700452 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800453
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700454 // If non-null, this is the currently visible window that is associated
455 // with the wallpaper.
456 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700457 // If non-null, we are in the middle of animating from one wallpaper target
458 // to another, and this is the lower one in Z-order.
459 WindowState mLowerWallpaperTarget = null;
460 // If non-null, we are in the middle of animating from one wallpaper target
461 // to another, and this is the higher one in Z-order.
462 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700463 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700464 float mLastWallpaperX = -1;
465 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800466 float mLastWallpaperXStep = -1;
467 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700468 // This is set when we are waiting for a wallpaper to tell us it is done
469 // changing its scroll position.
470 WindowState mWaitingOnWallpaper;
471 // The last time we had a timeout when waiting for a wallpaper.
472 long mLastWallpaperTimeoutTime;
473 // We give a wallpaper up to 150ms to finish scrolling.
474 static final long WALLPAPER_TIMEOUT = 150;
475 // Time we wait after a timeout before trying to wait again.
476 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 AppWindowToken mFocusedApp = null;
479
480 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 float mWindowAnimationScale = 1.0f;
483 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700484
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700485 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486
487 // Who is holding the screen on.
488 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700489 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700490
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700491 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 /**
494 * Whether the UI is currently running in touch mode (not showing
495 * navigational focus because the user is directly pressing the screen).
496 */
497 boolean mInTouchMode = false;
498
499 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700500 private ArrayList<WindowChangeListener> mWindowChangeListeners =
501 new ArrayList<WindowChangeListener>();
502 private boolean mWindowsChanged = false;
503
504 public interface WindowChangeListener {
505 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700506 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700507 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508
Dianne Hackbornc485a602009-03-24 22:39:49 -0700509 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700510 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700511
512 // The frame use to limit the size of the app running in compatibility mode.
513 Rect mCompatibleScreenFrame = new Rect();
514 // The surface used to fill the outer rim of the app running in compatibility mode.
515 Surface mBackgroundFillerSurface = null;
516 boolean mBackgroundFillerShown = false;
517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 public static WindowManagerService main(Context context,
519 PowerManagerService pm, boolean haveInputMethods) {
520 WMThread thr = new WMThread(context, pm, haveInputMethods);
521 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 synchronized (thr) {
524 while (thr.mService == null) {
525 try {
526 thr.wait();
527 } catch (InterruptedException e) {
528 }
529 }
530 }
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 return thr.mService;
533 }
Romain Guy06882f82009-06-10 13:36:04 -0700534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 static class WMThread extends Thread {
536 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 private final Context mContext;
539 private final PowerManagerService mPM;
540 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700541
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 public WMThread(Context context, PowerManagerService pm,
543 boolean haveInputMethods) {
544 super("WindowManager");
545 mContext = context;
546 mPM = pm;
547 mHaveInputMethods = haveInputMethods;
548 }
Romain Guy06882f82009-06-10 13:36:04 -0700549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 public void run() {
551 Looper.prepare();
552 WindowManagerService s = new WindowManagerService(mContext, mPM,
553 mHaveInputMethods);
554 android.os.Process.setThreadPriority(
555 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700556 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 synchronized (this) {
559 mService = s;
560 notifyAll();
561 }
Romain Guy06882f82009-06-10 13:36:04 -0700562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 Looper.loop();
564 }
565 }
566
567 static class PolicyThread extends Thread {
568 private final WindowManagerPolicy mPolicy;
569 private final WindowManagerService mService;
570 private final Context mContext;
571 private final PowerManagerService mPM;
572 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 public PolicyThread(WindowManagerPolicy policy,
575 WindowManagerService service, Context context,
576 PowerManagerService pm) {
577 super("WindowManagerPolicy");
578 mPolicy = policy;
579 mService = service;
580 mContext = context;
581 mPM = pm;
582 }
Romain Guy06882f82009-06-10 13:36:04 -0700583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 public void run() {
585 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800586 WindowManagerPolicyThread.set(this, Looper.myLooper());
587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800589 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 android.os.Process.setThreadPriority(
591 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700592 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 synchronized (this) {
596 mRunning = true;
597 notifyAll();
598 }
Romain Guy06882f82009-06-10 13:36:04 -0700599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 Looper.loop();
601 }
602 }
603
604 private WindowManagerService(Context context, PowerManagerService pm,
605 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700606 if (MEASURE_LATENCY) {
607 lt = new LatencyTimer(100, 1000);
608 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 mContext = context;
611 mHaveInputMethods = haveInputMethods;
612 mLimitedAlphaCompositing = context.getResources().getBoolean(
613 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 mPowerManager = pm;
616 mPowerManager.setPolicy(mPolicy);
617 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
618 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
619 "SCREEN_FROZEN");
620 mScreenFrozenLock.setReferenceCounted(false);
621
622 mActivityManager = ActivityManagerNative.getDefault();
623 mBatteryStats = BatteryStatsService.getService();
624
625 // Get persisted window scale setting
626 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
627 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
628 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
629 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700630
Jim Miller284b62e2010-06-08 14:27:42 -0700631 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
632 IntentFilter filter = new IntentFilter();
633 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
634 mContext.registerReceiver(mBroadcastReceiver, filter);
635
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700636 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
637 "KEEP_SCREEN_ON_FLAG");
638 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639
Jeff Browne33348b2010-07-15 23:54:05 -0700640 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
643 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 synchronized (thr) {
646 while (!thr.mRunning) {
647 try {
648 thr.wait();
649 } catch (InterruptedException e) {
650 }
651 }
652 }
Romain Guy06882f82009-06-10 13:36:04 -0700653
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700654 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 // Add ourself to the Watchdog monitors.
657 Watchdog.getInstance().addMonitor(this);
658 }
659
660 @Override
661 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
662 throws RemoteException {
663 try {
664 return super.onTransact(code, data, reply, flags);
665 } catch (RuntimeException e) {
666 // The window manager only throws security exceptions, so let's
667 // log all others.
668 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800669 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 }
671 throw e;
672 }
673 }
674
Jeff Browne33348b2010-07-15 23:54:05 -0700675 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800677 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 TAG, "Adding window " + window + " at "
679 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
680 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700681 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 }
683
Jeff Browne33348b2010-07-15 23:54:05 -0700684 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800686 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 TAG, "Adding window " + window + " at "
688 + i + " of " + mWindows.size() + " (before " + pos + ")");
689 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700690 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 }
692
693 //This method finds out the index of a window that has the same app token as
694 //win. used for z ordering the windows in mWindows
695 private int findIdxBasedOnAppTokens(WindowState win) {
696 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700697 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 int jmax = localmWindows.size();
699 if(jmax == 0) {
700 return -1;
701 }
702 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700703 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 if(wentry.mAppToken == win.mAppToken) {
705 return j;
706 }
707 }
708 return -1;
709 }
Romain Guy06882f82009-06-10 13:36:04 -0700710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
712 final IWindow client = win.mClient;
713 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700714 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 final int N = localmWindows.size();
717 final WindowState attached = win.mAttachedWindow;
718 int i;
719 if (attached == null) {
720 int tokenWindowsPos = token.windows.size();
721 if (token.appWindowToken != null) {
722 int index = tokenWindowsPos-1;
723 if (index >= 0) {
724 // If this application has existing windows, we
725 // simply place the new window on top of them... but
726 // keep the starting window on top.
727 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
728 // Base windows go behind everything else.
729 placeWindowBefore(token.windows.get(0), win);
730 tokenWindowsPos = 0;
731 } else {
732 AppWindowToken atoken = win.mAppToken;
733 if (atoken != null &&
734 token.windows.get(index) == atoken.startingWindow) {
735 placeWindowBefore(token.windows.get(index), win);
736 tokenWindowsPos--;
737 } else {
738 int newIdx = findIdxBasedOnAppTokens(win);
739 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700740 //there is a window above this one associated with the same
741 //apptoken note that the window could be a floating window
742 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800744 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700745 TAG, "Adding window " + win + " at "
746 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700748 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
751 }
752 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800753 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 TAG, "Figuring out where to add app window "
755 + client.asBinder() + " (token=" + token + ")");
756 // Figure out where the window should go, based on the
757 // order of applications.
758 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700759 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 for (i=NA-1; i>=0; i--) {
761 AppWindowToken t = mAppTokens.get(i);
762 if (t == token) {
763 i--;
764 break;
765 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800766
Dianne Hackborna8f60182009-09-01 19:01:50 -0700767 // We haven't reached the token yet; if this token
768 // is not going to the bottom and has windows, we can
769 // use it as an anchor for when we do reach the token.
770 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 pos = t.windows.get(0);
772 }
773 }
774 // We now know the index into the apps. If we found
775 // an app window above, that gives us the position; else
776 // we need to look some more.
777 if (pos != null) {
778 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700779 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 if (atoken != null) {
781 final int NC = atoken.windows.size();
782 if (NC > 0) {
783 WindowState bottom = atoken.windows.get(0);
784 if (bottom.mSubLayer < 0) {
785 pos = bottom;
786 }
787 }
788 }
789 placeWindowBefore(pos, win);
790 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700791 // Continue looking down until we find the first
792 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 while (i >= 0) {
794 AppWindowToken t = mAppTokens.get(i);
795 final int NW = t.windows.size();
796 if (NW > 0) {
797 pos = t.windows.get(NW-1);
798 break;
799 }
800 i--;
801 }
802 if (pos != null) {
803 // Move in front of any windows attached to this
804 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700805 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 if (atoken != null) {
807 final int NC = atoken.windows.size();
808 if (NC > 0) {
809 WindowState top = atoken.windows.get(NC-1);
810 if (top.mSubLayer >= 0) {
811 pos = top;
812 }
813 }
814 }
815 placeWindowAfter(pos, win);
816 } else {
817 // Just search for the start of this layer.
818 final int myLayer = win.mBaseLayer;
819 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700820 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 if (w.mBaseLayer > myLayer) {
822 break;
823 }
824 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800825 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700826 TAG, "Adding window " + win + " at "
827 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700829 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 }
831 }
832 }
833 } else {
834 // Figure out where window should go, based on layer.
835 final int myLayer = win.mBaseLayer;
836 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700837 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 i++;
839 break;
840 }
841 }
842 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800843 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700844 TAG, "Adding window " + win + " at "
845 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700847 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
849 if (addToToken) {
850 token.windows.add(tokenWindowsPos, win);
851 }
852
853 } else {
854 // Figure out this window's ordering relative to the window
855 // it is attached to.
856 final int NA = token.windows.size();
857 final int sublayer = win.mSubLayer;
858 int largestSublayer = Integer.MIN_VALUE;
859 WindowState windowWithLargestSublayer = null;
860 for (i=0; i<NA; i++) {
861 WindowState w = token.windows.get(i);
862 final int wSublayer = w.mSubLayer;
863 if (wSublayer >= largestSublayer) {
864 largestSublayer = wSublayer;
865 windowWithLargestSublayer = w;
866 }
867 if (sublayer < 0) {
868 // For negative sublayers, we go below all windows
869 // in the same sublayer.
870 if (wSublayer >= sublayer) {
871 if (addToToken) {
872 token.windows.add(i, win);
873 }
874 placeWindowBefore(
875 wSublayer >= 0 ? attached : w, win);
876 break;
877 }
878 } else {
879 // For positive sublayers, we go above all windows
880 // in the same sublayer.
881 if (wSublayer > sublayer) {
882 if (addToToken) {
883 token.windows.add(i, win);
884 }
885 placeWindowBefore(w, win);
886 break;
887 }
888 }
889 }
890 if (i >= NA) {
891 if (addToToken) {
892 token.windows.add(win);
893 }
894 if (sublayer < 0) {
895 placeWindowBefore(attached, win);
896 } else {
897 placeWindowAfter(largestSublayer >= 0
898 ? windowWithLargestSublayer
899 : attached,
900 win);
901 }
902 }
903 }
Romain Guy06882f82009-06-10 13:36:04 -0700904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 if (win.mAppToken != null && addToToken) {
906 win.mAppToken.allAppWindows.add(win);
907 }
908 }
Romain Guy06882f82009-06-10 13:36:04 -0700909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 static boolean canBeImeTarget(WindowState w) {
911 final int fl = w.mAttrs.flags
912 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
913 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
914 return w.isVisibleOrAdding();
915 }
916 return false;
917 }
Romain Guy06882f82009-06-10 13:36:04 -0700918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700920 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 final int N = localmWindows.size();
922 WindowState w = null;
923 int i = N;
924 while (i > 0) {
925 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700926 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700927
Joe Onorato8a9b2202010-02-26 18:56:32 -0800928 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 // + Integer.toHexString(w.mAttrs.flags));
930 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800931 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 // Yet more tricksyness! If this window is a "starting"
934 // window, we do actually want to be on top of it, but
935 // it is not -really- where input will go. So if the caller
936 // is not actually looking to move the IME, look down below
937 // for a real window to target...
938 if (!willMove
939 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
940 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700941 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
943 i--;
944 w = wb;
945 }
946 }
947 break;
948 }
949 }
Romain Guy06882f82009-06-10 13:36:04 -0700950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700952
Joe Onorato8a9b2202010-02-26 18:56:32 -0800953 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 if (willMove && w != null) {
957 final WindowState curTarget = mInputMethodTarget;
958 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 // Now some fun for dealing with window animations that
961 // modify the Z order. We need to look at all windows below
962 // the current target that are in this app, finding the highest
963 // visible one in layering.
964 AppWindowToken token = curTarget.mAppToken;
965 WindowState highestTarget = null;
966 int highestPos = 0;
967 if (token.animating || token.animation != null) {
968 int pos = 0;
969 pos = localmWindows.indexOf(curTarget);
970 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700971 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 if (win.mAppToken != token) {
973 break;
974 }
975 if (!win.mRemoved) {
976 if (highestTarget == null || win.mAnimLayer >
977 highestTarget.mAnimLayer) {
978 highestTarget = win;
979 highestPos = pos;
980 }
981 }
982 pos--;
983 }
984 }
Romain Guy06882f82009-06-10 13:36:04 -0700985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800987 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 + mNextAppTransition + " " + highestTarget
989 + " animating=" + highestTarget.isAnimating()
990 + " layer=" + highestTarget.mAnimLayer
991 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700992
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700993 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 // If we are currently setting up for an animation,
995 // hold everything until we can find out what will happen.
996 mInputMethodTargetWaitingAnim = true;
997 mInputMethodTarget = highestTarget;
998 return highestPos + 1;
999 } else if (highestTarget.isAnimating() &&
1000 highestTarget.mAnimLayer > w.mAnimLayer) {
1001 // If the window we are currently targeting is involved
1002 // with an animation, and it is on top of the next target
1003 // we will be over, then hold off on moving until
1004 // that is done.
1005 mInputMethodTarget = highestTarget;
1006 return highestPos + 1;
1007 }
1008 }
1009 }
1010 }
Romain Guy06882f82009-06-10 13:36:04 -07001011
Joe Onorato8a9b2202010-02-26 18:56:32 -08001012 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 if (w != null) {
1014 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001015 if (DEBUG_INPUT_METHOD) {
1016 RuntimeException e = null;
1017 if (!HIDE_STACK_CRAWLS) {
1018 e = new RuntimeException();
1019 e.fillInStackTrace();
1020 }
1021 Slog.w(TAG, "Moving IM target from "
1022 + mInputMethodTarget + " to " + w, e);
1023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001024 mInputMethodTarget = w;
1025 if (w.mAppToken != null) {
1026 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1027 } else {
1028 setInputMethodAnimLayerAdjustment(0);
1029 }
1030 }
1031 return i+1;
1032 }
1033 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001034 if (DEBUG_INPUT_METHOD) {
1035 RuntimeException e = null;
1036 if (!HIDE_STACK_CRAWLS) {
1037 e = new RuntimeException();
1038 e.fillInStackTrace();
1039 }
1040 Slog.w(TAG, "Moving IM target from "
1041 + mInputMethodTarget + " to null", e);
1042 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 mInputMethodTarget = null;
1044 setInputMethodAnimLayerAdjustment(0);
1045 }
1046 return -1;
1047 }
Romain Guy06882f82009-06-10 13:36:04 -07001048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 void addInputMethodWindowToListLocked(WindowState win) {
1050 int pos = findDesiredInputMethodWindowIndexLocked(true);
1051 if (pos >= 0) {
1052 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001053 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001054 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001056 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 moveInputMethodDialogsLocked(pos+1);
1058 return;
1059 }
1060 win.mTargetAppToken = null;
1061 addWindowToListInOrderLocked(win, true);
1062 moveInputMethodDialogsLocked(pos);
1063 }
Romain Guy06882f82009-06-10 13:36:04 -07001064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 mInputMethodAnimLayerAdjustment = adj;
1068 WindowState imw = mInputMethodWindow;
1069 if (imw != null) {
1070 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 + " anim layer: " + imw.mAnimLayer);
1073 int wi = imw.mChildWindows.size();
1074 while (wi > 0) {
1075 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001076 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001078 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 + " anim layer: " + cw.mAnimLayer);
1080 }
1081 }
1082 int di = mInputMethodDialogs.size();
1083 while (di > 0) {
1084 di --;
1085 imw = mInputMethodDialogs.get(di);
1086 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001087 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 + " anim layer: " + imw.mAnimLayer);
1089 }
1090 }
Romain Guy06882f82009-06-10 13:36:04 -07001091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1093 int wpos = mWindows.indexOf(win);
1094 if (wpos >= 0) {
1095 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001096 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001098 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 int NC = win.mChildWindows.size();
1100 while (NC > 0) {
1101 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001102 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 int cpos = mWindows.indexOf(cw);
1104 if (cpos >= 0) {
1105 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001106 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001107 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 mWindows.remove(cpos);
1109 }
1110 }
1111 }
1112 return interestingPos;
1113 }
Romain Guy06882f82009-06-10 13:36:04 -07001114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 private void reAddWindowToListInOrderLocked(WindowState win) {
1116 addWindowToListInOrderLocked(win, false);
1117 // This is a hack to get all of the child windows added as well
1118 // at the right position. Child windows should be rare and
1119 // this case should be rare, so it shouldn't be that big a deal.
1120 int wpos = mWindows.indexOf(win);
1121 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001122 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001123 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001125 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 reAddWindowLocked(wpos, win);
1127 }
1128 }
Romain Guy06882f82009-06-10 13:36:04 -07001129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 void logWindowList(String prefix) {
1131 int N = mWindows.size();
1132 while (N > 0) {
1133 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001134 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 }
1136 }
Romain Guy06882f82009-06-10 13:36:04 -07001137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 void moveInputMethodDialogsLocked(int pos) {
1139 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001142 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 for (int i=0; i<N; i++) {
1144 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1145 }
1146 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001147 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 logWindowList(" ");
1149 }
Romain Guy06882f82009-06-10 13:36:04 -07001150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 if (pos >= 0) {
1152 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1153 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001154 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 if (wp == mInputMethodWindow) {
1156 pos++;
1157 }
1158 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001159 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 for (int i=0; i<N; i++) {
1161 WindowState win = dialogs.get(i);
1162 win.mTargetAppToken = targetAppToken;
1163 pos = reAddWindowLocked(pos, win);
1164 }
1165 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001166 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 logWindowList(" ");
1168 }
1169 return;
1170 }
1171 for (int i=0; i<N; i++) {
1172 WindowState win = dialogs.get(i);
1173 win.mTargetAppToken = null;
1174 reAddWindowToListInOrderLocked(win);
1175 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001176 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 logWindowList(" ");
1178 }
1179 }
1180 }
Romain Guy06882f82009-06-10 13:36:04 -07001181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1183 final WindowState imWin = mInputMethodWindow;
1184 final int DN = mInputMethodDialogs.size();
1185 if (imWin == null && DN == 0) {
1186 return false;
1187 }
Romain Guy06882f82009-06-10 13:36:04 -07001188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1190 if (imPos >= 0) {
1191 // In this case, the input method windows are to be placed
1192 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 // First check to see if the input method windows are already
1195 // located here, and contiguous.
1196 final int N = mWindows.size();
1197 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001198 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 // Figure out the actual input method window that should be
1201 // at the bottom of their stack.
1202 WindowState baseImWin = imWin != null
1203 ? imWin : mInputMethodDialogs.get(0);
1204 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001205 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 if (cw.mSubLayer < 0) baseImWin = cw;
1207 }
Romain Guy06882f82009-06-10 13:36:04 -07001208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 if (firstImWin == baseImWin) {
1210 // The windows haven't moved... but are they still contiguous?
1211 // First find the top IM window.
1212 int pos = imPos+1;
1213 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001214 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 break;
1216 }
1217 pos++;
1218 }
1219 pos++;
1220 // Now there should be no more input method windows above.
1221 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001222 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 break;
1224 }
1225 pos++;
1226 }
1227 if (pos >= N) {
1228 // All is good!
1229 return false;
1230 }
1231 }
Romain Guy06882f82009-06-10 13:36:04 -07001232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 if (imWin != null) {
1234 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001235 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 logWindowList(" ");
1237 }
1238 imPos = tmpRemoveWindowLocked(imPos, imWin);
1239 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001240 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001241 logWindowList(" ");
1242 }
1243 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1244 reAddWindowLocked(imPos, imWin);
1245 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001246 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 logWindowList(" ");
1248 }
1249 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1250 } else {
1251 moveInputMethodDialogsLocked(imPos);
1252 }
Romain Guy06882f82009-06-10 13:36:04 -07001253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001254 } else {
1255 // In this case, the input method windows go in a fixed layer,
1256 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001259 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 tmpRemoveWindowLocked(0, imWin);
1261 imWin.mTargetAppToken = null;
1262 reAddWindowToListInOrderLocked(imWin);
1263 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001264 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 logWindowList(" ");
1266 }
1267 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1268 } else {
1269 moveInputMethodDialogsLocked(-1);;
1270 }
Romain Guy06882f82009-06-10 13:36:04 -07001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 }
Romain Guy06882f82009-06-10 13:36:04 -07001273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 if (needAssignLayers) {
1275 assignLayersLocked();
1276 }
Romain Guy06882f82009-06-10 13:36:04 -07001277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 return true;
1279 }
Romain Guy06882f82009-06-10 13:36:04 -07001280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 void adjustInputMethodDialogsLocked() {
1282 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1283 }
Romain Guy06882f82009-06-10 13:36:04 -07001284
Dianne Hackborn25994b42009-09-04 14:21:19 -07001285 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001286 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001287 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1288 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1289 ? wallpaperTarget.mAppToken.animation : null)
1290 + " upper=" + mUpperWallpaperTarget
1291 + " lower=" + mLowerWallpaperTarget);
1292 return (wallpaperTarget != null
1293 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1294 && wallpaperTarget.mAppToken.animation != null)))
1295 || mUpperWallpaperTarget != null
1296 || mLowerWallpaperTarget != null;
1297 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001298
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001299 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1300 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001301
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001302 int adjustWallpaperWindowsLocked() {
1303 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001304
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001305 final int dw = mDisplay.getWidth();
1306 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001307
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001308 // First find top-most window that has asked to be on top of the
1309 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001310 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001311 int N = localmWindows.size();
1312 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001313 WindowState foundW = null;
1314 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001315 WindowState topCurW = null;
1316 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001317 int i = N;
1318 while (i > 0) {
1319 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001320 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001321 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1322 if (topCurW == null) {
1323 topCurW = w;
1324 topCurI = i;
1325 }
1326 continue;
1327 }
1328 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001329 if (w.mAppToken != null) {
1330 // If this window's app token is hidden and not animating,
1331 // it is of no interest to us.
1332 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001333 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001334 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001335 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001336 continue;
1337 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001338 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001339 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001340 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1341 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001342 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001343 && (mWallpaperTarget == w
1344 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001345 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001346 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001347 foundW = w;
1348 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001349 if (w == mWallpaperTarget && ((w.mAppToken != null
1350 && w.mAppToken.animation != null)
1351 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001352 // The current wallpaper target is animating, so we'll
1353 // look behind it for another possible target and figure
1354 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001355 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001356 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001357 continue;
1358 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001359 break;
1360 }
1361 }
1362
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001363 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001364 // If we are currently waiting for an app transition, and either
1365 // the current target or the next target are involved with it,
1366 // then hold off on doing anything with the wallpaper.
1367 // Note that we are checking here for just whether the target
1368 // is part of an app token... which is potentially overly aggressive
1369 // (the app token may not be involved in the transition), but good
1370 // enough (we'll just wait until whatever transition is pending
1371 // executes).
1372 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001373 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001374 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001375 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001376 }
1377 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001378 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001379 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001380 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001381 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001383
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001384 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001385 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001386 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001387 + " oldTarget: " + mWallpaperTarget);
1388 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001389
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001390 mLowerWallpaperTarget = null;
1391 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001392
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 WindowState oldW = mWallpaperTarget;
1394 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001395
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001396 // Now what is happening... if the current and new targets are
1397 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001398 if (foundW != null && oldW != null) {
1399 boolean oldAnim = oldW.mAnimation != null
1400 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1401 boolean foundAnim = foundW.mAnimation != null
1402 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001403 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001404 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001405 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001406 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001407 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001408 int oldI = localmWindows.indexOf(oldW);
1409 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001410 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001411 }
1412 if (oldI >= 0) {
1413 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001414 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001415 + "=" + oldW + "; new#" + foundI
1416 + "=" + foundW);
1417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001418
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001419 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001420 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001421 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001422 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001423 }
1424 mWallpaperTarget = oldW;
1425 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001426
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001427 // Now set the upper and lower wallpaper targets
1428 // correctly, and make sure that we are positioning
1429 // the wallpaper below the lower.
1430 if (foundI > oldI) {
1431 // The new target is on top of the old one.
1432 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001434 }
1435 mUpperWallpaperTarget = foundW;
1436 mLowerWallpaperTarget = oldW;
1437 foundW = oldW;
1438 foundI = oldI;
1439 } else {
1440 // The new target is below the old one.
1441 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001442 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001443 }
1444 mUpperWallpaperTarget = oldW;
1445 mLowerWallpaperTarget = foundW;
1446 }
1447 }
1448 }
1449 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001450
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001451 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001452 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001453 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1454 || (mLowerWallpaperTarget.mAppToken != null
1455 && mLowerWallpaperTarget.mAppToken.animation != null);
1456 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1457 || (mUpperWallpaperTarget.mAppToken != null
1458 && mUpperWallpaperTarget.mAppToken.animation != null);
1459 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001460 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001461 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001462 }
1463 mLowerWallpaperTarget = null;
1464 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001465 }
1466 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001467
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001468 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001469 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001470 // The window is visible to the compositor... but is it visible
1471 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001472 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001473 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001474
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001475 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001476 // its layer adjustment. Only do this if we are not transfering
1477 // between two wallpaper targets.
1478 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001479 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001480 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001481
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001482 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1483 * TYPE_LAYER_MULTIPLIER
1484 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001485
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001486 // Now w is the window we are supposed to be behind... but we
1487 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001488 // AND any starting window associated with it, AND below the
1489 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001490 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001491 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001492 if (wb.mBaseLayer < maxLayer &&
1493 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001494 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001495 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001496 // This window is not related to the previous one in any
1497 // interesting way, so stop here.
1498 break;
1499 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001500 foundW = wb;
1501 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001502 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001503 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001504 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001505 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001506
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001507 if (foundW == null && topCurW != null) {
1508 // There is no wallpaper target, so it goes at the bottom.
1509 // We will assume it is the same place as last time, if known.
1510 foundW = topCurW;
1511 foundI = topCurI+1;
1512 } else {
1513 // Okay i is the position immediately above the wallpaper. Look at
1514 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001515 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001516 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001517
Dianne Hackborn284ac932009-08-28 10:34:25 -07001518 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001519 if (mWallpaperTarget.mWallpaperX >= 0) {
1520 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001521 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001522 }
1523 if (mWallpaperTarget.mWallpaperY >= 0) {
1524 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001525 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001526 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001527 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001528
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001529 // Start stepping backwards from here, ensuring that our wallpaper windows
1530 // are correctly placed.
1531 int curTokenIndex = mWallpaperTokens.size();
1532 while (curTokenIndex > 0) {
1533 curTokenIndex--;
1534 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001535 if (token.hidden == visible) {
1536 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1537 token.hidden = !visible;
1538 // Need to do a layout to ensure the wallpaper now has the
1539 // correct size.
1540 mLayoutNeeded = true;
1541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001543 int curWallpaperIndex = token.windows.size();
1544 while (curWallpaperIndex > 0) {
1545 curWallpaperIndex--;
1546 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001547
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001548 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001549 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001550 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001551
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001552 // First, make sure the client has the current visibility
1553 // state.
1554 if (wallpaper.mWallpaperVisible != visible) {
1555 wallpaper.mWallpaperVisible = visible;
1556 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001558 "Setting visibility of wallpaper " + wallpaper
1559 + ": " + visible);
1560 wallpaper.mClient.dispatchAppVisibility(visible);
1561 } catch (RemoteException e) {
1562 }
1563 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001564
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001565 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001566 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001567 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001568
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 // First, if this window is at the current index, then all
1570 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001571 if (wallpaper == foundW) {
1572 foundI--;
1573 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001574 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001575 continue;
1576 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001577
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001578 // The window didn't match... the current wallpaper window,
1579 // wherever it is, is in the wrong place, so make sure it is
1580 // not in the list.
1581 int oldIndex = localmWindows.indexOf(wallpaper);
1582 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001583 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001584 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001585 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001586 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001587 if (oldIndex < foundI) {
1588 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001589 }
1590 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001591
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001592 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001593 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001594 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001595 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001596
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001597 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001598 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001599 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001600 }
1601 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001602
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001603 return changed;
1604 }
1605
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001606 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001607 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001608 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001609 mWallpaperAnimLayerAdjustment = adj;
1610 int curTokenIndex = mWallpaperTokens.size();
1611 while (curTokenIndex > 0) {
1612 curTokenIndex--;
1613 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1614 int curWallpaperIndex = token.windows.size();
1615 while (curWallpaperIndex > 0) {
1616 curWallpaperIndex--;
1617 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1618 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001619 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001620 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001621 }
1622 }
1623 }
1624
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001625 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1626 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001627 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001628 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001629 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001630 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001631 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1632 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1633 changed = wallpaperWin.mXOffset != offset;
1634 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001635 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 + wallpaperWin + " x: " + offset);
1637 wallpaperWin.mXOffset = offset;
1638 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001639 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001640 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001641 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001642 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001643 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001644
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001645 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001646 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001647 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1648 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1649 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001650 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001651 + wallpaperWin + " y: " + offset);
1652 changed = true;
1653 wallpaperWin.mYOffset = offset;
1654 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001655 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001656 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001657 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001658 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001659 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001660
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001661 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001662 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001663 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001664 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1665 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001666 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001667 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001668 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001669 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001670 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1671 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001672 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001673 if (mWaitingOnWallpaper != null) {
1674 long start = SystemClock.uptimeMillis();
1675 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1676 < start) {
1677 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001678 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001679 "Waiting for offset complete...");
1680 mWindowMap.wait(WALLPAPER_TIMEOUT);
1681 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001682 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001683 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001684 if ((start+WALLPAPER_TIMEOUT)
1685 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001686 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001687 + wallpaperWin);
1688 mLastWallpaperTimeoutTime = start;
1689 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001690 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001691 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001692 }
1693 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001694 } catch (RemoteException e) {
1695 }
1696 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001697
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001698 return changed;
1699 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001700
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001701 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001702 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001703 if (mWaitingOnWallpaper != null &&
1704 mWaitingOnWallpaper.mClient.asBinder() == window) {
1705 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001706 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001707 }
1708 }
1709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001710
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001711 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001712 final int dw = mDisplay.getWidth();
1713 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001714
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001715 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001716
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001717 WindowState target = mWallpaperTarget;
1718 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001719 if (target.mWallpaperX >= 0) {
1720 mLastWallpaperX = target.mWallpaperX;
1721 } else if (changingTarget.mWallpaperX >= 0) {
1722 mLastWallpaperX = changingTarget.mWallpaperX;
1723 }
1724 if (target.mWallpaperY >= 0) {
1725 mLastWallpaperY = target.mWallpaperY;
1726 } else if (changingTarget.mWallpaperY >= 0) {
1727 mLastWallpaperY = changingTarget.mWallpaperY;
1728 }
1729 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001730
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001731 int curTokenIndex = mWallpaperTokens.size();
1732 while (curTokenIndex > 0) {
1733 curTokenIndex--;
1734 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1735 int curWallpaperIndex = token.windows.size();
1736 while (curWallpaperIndex > 0) {
1737 curWallpaperIndex--;
1738 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1739 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1740 wallpaper.computeShownFrameLocked();
1741 changed = true;
1742 // We only want to be synchronous with one wallpaper.
1743 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001744 }
1745 }
1746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001747
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001748 return changed;
1749 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001750
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001751 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001752 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001753 final int dw = mDisplay.getWidth();
1754 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001755
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001756 int curTokenIndex = mWallpaperTokens.size();
1757 while (curTokenIndex > 0) {
1758 curTokenIndex--;
1759 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001760 if (token.hidden == visible) {
1761 token.hidden = !visible;
1762 // Need to do a layout to ensure the wallpaper now has the
1763 // correct size.
1764 mLayoutNeeded = true;
1765 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001766
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001767 int curWallpaperIndex = token.windows.size();
1768 while (curWallpaperIndex > 0) {
1769 curWallpaperIndex--;
1770 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1771 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001772 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001773 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001774
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001775 if (wallpaper.mWallpaperVisible != visible) {
1776 wallpaper.mWallpaperVisible = visible;
1777 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001778 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001779 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001780 + ": " + visible);
1781 wallpaper.mClient.dispatchAppVisibility(visible);
1782 } catch (RemoteException e) {
1783 }
1784 }
1785 }
1786 }
1787 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 public int addWindow(Session session, IWindow client,
1790 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001791 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 int res = mPolicy.checkAddPermission(attrs);
1793 if (res != WindowManagerImpl.ADD_OKAY) {
1794 return res;
1795 }
Romain Guy06882f82009-06-10 13:36:04 -07001796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 boolean reportNewConfig = false;
1798 WindowState attachedWindow = null;
1799 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001800 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001804 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 }
Romain Guy06882f82009-06-10 13:36:04 -07001806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001808 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1810 }
1811
1812 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001813 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001815 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 + attrs.token + ". Aborting.");
1817 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1818 }
1819 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1820 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001821 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 + attrs.token + ". Aborting.");
1823 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1824 }
1825 }
1826
1827 boolean addToken = false;
1828 WindowToken token = mTokenMap.get(attrs.token);
1829 if (token == null) {
1830 if (attrs.type >= FIRST_APPLICATION_WINDOW
1831 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 + attrs.token + ". Aborting.");
1834 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1835 }
1836 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001837 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 + attrs.token + ". Aborting.");
1839 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1840 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001841 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001842 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001843 + attrs.token + ". Aborting.");
1844 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1845 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 token = new WindowToken(attrs.token, -1, false);
1847 addToken = true;
1848 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1849 && attrs.type <= LAST_APPLICATION_WINDOW) {
1850 AppWindowToken atoken = token.appWindowToken;
1851 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001852 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 + token + ". Aborting.");
1854 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1855 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001856 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 + token + ". Aborting.");
1858 return WindowManagerImpl.ADD_APP_EXITING;
1859 }
1860 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1861 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001862 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001863 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1864 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1865 }
1866 } else if (attrs.type == TYPE_INPUT_METHOD) {
1867 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001868 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 + attrs.token + ". Aborting.");
1870 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1871 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001872 } else if (attrs.type == TYPE_WALLPAPER) {
1873 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001874 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001875 + attrs.token + ". Aborting.");
1876 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 }
1879
1880 win = new WindowState(session, client, token,
1881 attachedWindow, attrs, viewVisibility);
1882 if (win.mDeathRecipient == null) {
1883 // Client has apparently died, so there is no reason to
1884 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001885 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 + " that is dead, aborting.");
1887 return WindowManagerImpl.ADD_APP_EXITING;
1888 }
1889
1890 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001891
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 res = mPolicy.prepareAddWindowLw(win, attrs);
1893 if (res != WindowManagerImpl.ADD_OKAY) {
1894 return res;
1895 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001896
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001897 if (outInputChannel != null) {
1898 String name = win.makeInputChannelName();
1899 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1900 win.mInputChannel = inputChannels[0];
1901 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1902
1903 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905
1906 // From now on, no exceptions or errors allowed!
1907
1908 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001909
Dianne Hackborn5132b372010-07-29 12:51:35 -07001910 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 if (addToken) {
1913 mTokenMap.put(attrs.token, token);
1914 mTokenList.add(token);
1915 }
1916 win.attach();
1917 mWindowMap.put(client.asBinder(), win);
1918
1919 if (attrs.type == TYPE_APPLICATION_STARTING &&
1920 token.appWindowToken != null) {
1921 token.appWindowToken.startingWindow = win;
1922 }
1923
1924 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 if (attrs.type == TYPE_INPUT_METHOD) {
1927 mInputMethodWindow = win;
1928 addInputMethodWindowToListLocked(win);
1929 imMayMove = false;
1930 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1931 mInputMethodDialogs.add(win);
1932 addWindowToListInOrderLocked(win, true);
1933 adjustInputMethodDialogsLocked();
1934 imMayMove = false;
1935 } else {
1936 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001937 if (attrs.type == TYPE_WALLPAPER) {
1938 mLastWallpaperTimeoutTime = 0;
1939 adjustWallpaperWindowsLocked();
1940 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001941 adjustWallpaperWindowsLocked();
1942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 }
Romain Guy06882f82009-06-10 13:36:04 -07001944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001945 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 if (mInTouchMode) {
1950 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1951 }
1952 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1953 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1954 }
Romain Guy06882f82009-06-10 13:36:04 -07001955
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001956 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001958 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1959 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 imMayMove = false;
1961 }
1962 }
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001965 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 }
Romain Guy06882f82009-06-10 13:36:04 -07001967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 assignLayersLocked();
1969 // Don't do layout here, the window must call
1970 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 //dump();
1973
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001974 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001975 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001976 }
Jeff Brown349703e2010-06-22 01:27:15 -07001977
Joe Onorato8a9b2202010-02-26 18:56:32 -08001978 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 TAG, "New client " + client.asBinder()
1980 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001981
1982 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1983 reportNewConfig = true;
1984 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 }
1986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 if (reportNewConfig) {
1988 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07001990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001991 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 return res;
1994 }
Romain Guy06882f82009-06-10 13:36:04 -07001995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 public void removeWindow(Session session, IWindow client) {
1997 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001998 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 if (win == null) {
2000 return;
2001 }
2002 removeWindowLocked(session, win);
2003 }
2004 }
Romain Guy06882f82009-06-10 13:36:04 -07002005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 public void removeWindowLocked(Session session, WindowState win) {
2007
Joe Onorato8a9b2202010-02-26 18:56:32 -08002008 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 TAG, "Remove " + win + " client="
2010 + Integer.toHexString(System.identityHashCode(
2011 win.mClient.asBinder()))
2012 + ", surface=" + win.mSurface);
2013
2014 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002015
2016 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002017
Joe Onorato8a9b2202010-02-26 18:56:32 -08002018 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002019 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2020 + " mExiting=" + win.mExiting
2021 + " isAnimating=" + win.isAnimating()
2022 + " app-animation="
2023 + (win.mAppToken != null ? win.mAppToken.animation : null)
2024 + " inPendingTransaction="
2025 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2026 + " mDisplayFrozen=" + mDisplayFrozen);
2027 // Visibility of the removed window. Will be used later to update orientation later on.
2028 boolean wasVisible = false;
2029 // First, see if we need to run an animation. If we do, we have
2030 // to hold off on removing the window until the animation is done.
2031 // If the display is frozen, just remove immediately, since the
2032 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002033 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 // If we are not currently running the exit animation, we
2035 // need to see about starting one.
2036 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2039 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2040 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2041 }
2042 // Try starting an animation.
2043 if (applyAnimationLocked(win, transit, false)) {
2044 win.mExiting = true;
2045 }
2046 }
2047 if (win.mExiting || win.isAnimating()) {
2048 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002049 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 win.mExiting = true;
2051 win.mRemoveOnExit = true;
2052 mLayoutNeeded = true;
2053 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2054 performLayoutAndPlaceSurfacesLocked();
2055 if (win.mAppToken != null) {
2056 win.mAppToken.updateReportedVisibilityLocked();
2057 }
2058 //dump();
2059 Binder.restoreCallingIdentity(origId);
2060 return;
2061 }
2062 }
2063
2064 removeWindowInnerLocked(session, win);
2065 // Removing a visible window will effect the computed orientation
2066 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002067 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002068 != mForcedAppOrientation
2069 && updateOrientationFromAppTokensLocked()) {
2070 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 }
2072 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2073 Binder.restoreCallingIdentity(origId);
2074 }
Romain Guy06882f82009-06-10 13:36:04 -07002075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002077 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 if (mInputMethodTarget == win) {
2080 moveInputMethodWindowsIfNeededLocked(false);
2081 }
Romain Guy06882f82009-06-10 13:36:04 -07002082
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002083 if (false) {
2084 RuntimeException e = new RuntimeException("here");
2085 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002086 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002087 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 mPolicy.removeWindowLw(win);
2090 win.removeLocked();
2091
2092 mWindowMap.remove(win.mClient.asBinder());
2093 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002094 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002095 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096
2097 if (mInputMethodWindow == win) {
2098 mInputMethodWindow = null;
2099 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2100 mInputMethodDialogs.remove(win);
2101 }
Romain Guy06882f82009-06-10 13:36:04 -07002102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103 final WindowToken token = win.mToken;
2104 final AppWindowToken atoken = win.mAppToken;
2105 token.windows.remove(win);
2106 if (atoken != null) {
2107 atoken.allAppWindows.remove(win);
2108 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002109 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002110 TAG, "**** Removing window " + win + ": count="
2111 + token.windows.size());
2112 if (token.windows.size() == 0) {
2113 if (!token.explicit) {
2114 mTokenMap.remove(token.token);
2115 mTokenList.remove(token);
2116 } else if (atoken != null) {
2117 atoken.firstWindowDrawn = false;
2118 }
2119 }
2120
2121 if (atoken != null) {
2122 if (atoken.startingWindow == win) {
2123 atoken.startingWindow = null;
2124 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2125 // If this is the last window and we had requested a starting
2126 // transition window, well there is no point now.
2127 atoken.startingData = null;
2128 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2129 // If this is the last window except for a starting transition
2130 // window, we need to get rid of the starting transition.
2131 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002132 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 + ": no more real windows");
2134 }
2135 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2136 mH.sendMessage(m);
2137 }
2138 }
Romain Guy06882f82009-06-10 13:36:04 -07002139
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002140 if (win.mAttrs.type == TYPE_WALLPAPER) {
2141 mLastWallpaperTimeoutTime = 0;
2142 adjustWallpaperWindowsLocked();
2143 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002144 adjustWallpaperWindowsLocked();
2145 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 if (!mInLayout) {
2148 assignLayersLocked();
2149 mLayoutNeeded = true;
2150 performLayoutAndPlaceSurfacesLocked();
2151 if (win.mAppToken != null) {
2152 win.mAppToken.updateReportedVisibilityLocked();
2153 }
2154 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002155
2156 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 }
2158
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002159 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2160 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2161 + ": " + msg + " / " + w.mAttrs.getTitle();
2162 if (where != null) {
2163 Slog.i(TAG, str, where);
2164 } else {
2165 Slog.i(TAG, str);
2166 }
2167 }
2168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2170 long origId = Binder.clearCallingIdentity();
2171 try {
2172 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002173 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002175 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 Surface.openTransaction();
2177 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002178 if (SHOW_TRANSACTIONS) logSurface(w,
2179 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 w.mSurface.setTransparentRegionHint(region);
2181 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002182 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 Surface.closeTransaction();
2184 }
2185 }
2186 }
2187 } finally {
2188 Binder.restoreCallingIdentity(origId);
2189 }
2190 }
2191
2192 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002193 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194 Rect visibleInsets) {
2195 long origId = Binder.clearCallingIdentity();
2196 try {
2197 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002198 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199 if (w != null) {
2200 w.mGivenInsetsPending = false;
2201 w.mGivenContentInsets.set(contentInsets);
2202 w.mGivenVisibleInsets.set(visibleInsets);
2203 w.mTouchableInsets = touchableInsets;
2204 mLayoutNeeded = true;
2205 performLayoutAndPlaceSurfacesLocked();
2206 }
2207 }
2208 } finally {
2209 Binder.restoreCallingIdentity(origId);
2210 }
2211 }
Romain Guy06882f82009-06-10 13:36:04 -07002212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 public void getWindowDisplayFrame(Session session, IWindow client,
2214 Rect outDisplayFrame) {
2215 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002216 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 if (win == null) {
2218 outDisplayFrame.setEmpty();
2219 return;
2220 }
2221 outDisplayFrame.set(win.mDisplayFrame);
2222 }
2223 }
2224
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002225 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2226 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002227 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2228 window.mWallpaperX = x;
2229 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002230 window.mWallpaperXStep = xStep;
2231 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002232 if (updateWallpaperOffsetLocked(window, true)) {
2233 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002234 }
2235 }
2236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002237
Dianne Hackborn75804932009-10-20 20:15:20 -07002238 void wallpaperCommandComplete(IBinder window, Bundle result) {
2239 synchronized (mWindowMap) {
2240 if (mWaitingOnWallpaper != null &&
2241 mWaitingOnWallpaper.mClient.asBinder() == window) {
2242 mWaitingOnWallpaper = null;
2243 mWindowMap.notifyAll();
2244 }
2245 }
2246 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002247
Dianne Hackborn75804932009-10-20 20:15:20 -07002248 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2249 String action, int x, int y, int z, Bundle extras, boolean sync) {
2250 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2251 || window == mUpperWallpaperTarget) {
2252 boolean doWait = sync;
2253 int curTokenIndex = mWallpaperTokens.size();
2254 while (curTokenIndex > 0) {
2255 curTokenIndex--;
2256 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2257 int curWallpaperIndex = token.windows.size();
2258 while (curWallpaperIndex > 0) {
2259 curWallpaperIndex--;
2260 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2261 try {
2262 wallpaper.mClient.dispatchWallpaperCommand(action,
2263 x, y, z, extras, sync);
2264 // We only want to be synchronous with one wallpaper.
2265 sync = false;
2266 } catch (RemoteException e) {
2267 }
2268 }
2269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002270
Dianne Hackborn75804932009-10-20 20:15:20 -07002271 if (doWait) {
2272 // XXX Need to wait for result.
2273 }
2274 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002275
Dianne Hackborn75804932009-10-20 20:15:20 -07002276 return null;
2277 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 public int relayoutWindow(Session session, IWindow client,
2280 WindowManager.LayoutParams attrs, int requestedWidth,
2281 int requestedHeight, int viewVisibility, boolean insetsPending,
2282 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002283 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 boolean displayed = false;
2285 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002286 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002290 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 if (win == null) {
2292 return 0;
2293 }
2294 win.mRequestedWidth = requestedWidth;
2295 win.mRequestedHeight = requestedHeight;
2296
2297 if (attrs != null) {
2298 mPolicy.adjustWindowParamsLw(attrs);
2299 }
Romain Guy06882f82009-06-10 13:36:04 -07002300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 int attrChanges = 0;
2302 int flagChanges = 0;
2303 if (attrs != null) {
2304 flagChanges = win.mAttrs.flags ^= attrs.flags;
2305 attrChanges = win.mAttrs.copyFrom(attrs);
2306 }
2307
Joe Onorato8a9b2202010-02-26 18:56:32 -08002308 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309
2310 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2311 win.mAlpha = attrs.alpha;
2312 }
2313
2314 final boolean scaledWindow =
2315 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2316
2317 if (scaledWindow) {
2318 // requested{Width|Height} Surface's physical size
2319 // attrs.{width|height} Size on screen
2320 win.mHScale = (attrs.width != requestedWidth) ?
2321 (attrs.width / (float)requestedWidth) : 1.0f;
2322 win.mVScale = (attrs.height != requestedHeight) ?
2323 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002324 } else {
2325 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 }
2327
2328 boolean imMayMove = (flagChanges&(
2329 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2330 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 boolean focusMayChange = win.mViewVisibility != viewVisibility
2333 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2334 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002335
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002336 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2337 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 win.mRelayoutCalled = true;
2340 final int oldVisibility = win.mViewVisibility;
2341 win.mViewVisibility = viewVisibility;
2342 if (viewVisibility == View.VISIBLE &&
2343 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2344 displayed = !win.isVisibleLw();
2345 if (win.mExiting) {
2346 win.mExiting = false;
2347 win.mAnimation = null;
2348 }
2349 if (win.mDestroying) {
2350 win.mDestroying = false;
2351 mDestroySurface.remove(win);
2352 }
2353 if (oldVisibility == View.GONE) {
2354 win.mEnterAnimationPending = true;
2355 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002356 if (displayed) {
2357 if (win.mSurface != null && !win.mDrawPending
2358 && !win.mCommitDrawPending && !mDisplayFrozen
2359 && mPolicy.isScreenOn()) {
2360 applyEnterAnimationLocked(win);
2361 }
2362 if ((win.mAttrs.flags
2363 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2364 if (DEBUG_VISIBILITY) Slog.v(TAG,
2365 "Relayout window turning screen on: " + win);
2366 win.mTurnOnScreen = true;
2367 }
2368 int diff = 0;
2369 if (win.mConfiguration != mCurConfiguration
2370 && (win.mConfiguration == null
2371 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2372 win.mConfiguration = mCurConfiguration;
2373 if (DEBUG_CONFIGURATION) {
2374 Slog.i(TAG, "Window " + win + " visible with new config: "
2375 + win.mConfiguration + " / 0x"
2376 + Integer.toHexString(diff));
2377 }
2378 outConfig.setTo(mCurConfiguration);
2379 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002380 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2382 // To change the format, we need to re-build the surface.
2383 win.destroySurfaceLocked();
2384 displayed = true;
2385 }
2386 try {
2387 Surface surface = win.createSurfaceLocked();
2388 if (surface != null) {
2389 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002390 win.mReportDestroySurface = false;
2391 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002392 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002393 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002395 // For some reason there isn't a surface. Clear the
2396 // caller's object so they see the same state.
2397 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 }
2399 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002400 mInputMonitor.updateInputWindowsLw();
2401
Joe Onorato8a9b2202010-02-26 18:56:32 -08002402 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002403 + client + " (" + win.mAttrs.getTitle() + ")",
2404 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 Binder.restoreCallingIdentity(origId);
2406 return 0;
2407 }
2408 if (displayed) {
2409 focusMayChange = true;
2410 }
2411 if (win.mAttrs.type == TYPE_INPUT_METHOD
2412 && mInputMethodWindow == null) {
2413 mInputMethodWindow = win;
2414 imMayMove = true;
2415 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002416 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2417 && win.mAppToken != null
2418 && win.mAppToken.startingWindow != null) {
2419 // Special handling of starting window over the base
2420 // window of the app: propagate lock screen flags to it,
2421 // to provide the correct semantics while starting.
2422 final int mask =
2423 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002424 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2425 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002426 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2427 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 } else {
2430 win.mEnterAnimationPending = false;
2431 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002432 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002433 + ": mExiting=" + win.mExiting
2434 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 // If we are not currently running the exit animation, we
2436 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002437 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 // Try starting an animation; if there isn't one, we
2439 // can destroy the surface right away.
2440 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2441 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2442 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2443 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002444 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002446 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 } else if (win.isAnimating()) {
2449 // Currently in a hide animation... turn this into
2450 // an exit.
2451 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002452 } else if (win == mWallpaperTarget) {
2453 // If the wallpaper is currently behind this
2454 // window, we need to change both of them inside
2455 // of a transaction to avoid artifacts.
2456 win.mExiting = true;
2457 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 } else {
2459 if (mInputMethodWindow == win) {
2460 mInputMethodWindow = null;
2461 }
2462 win.destroySurfaceLocked();
2463 }
2464 }
2465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002466
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002467 if (win.mSurface == null || (win.getAttrs().flags
2468 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2469 || win.mSurfacePendingDestroy) {
2470 // We are being called from a local process, which
2471 // means outSurface holds its current surface. Ensure the
2472 // surface object is cleared, but we don't want it actually
2473 // destroyed at this point.
2474 win.mSurfacePendingDestroy = false;
2475 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002476 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002477 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002478 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002479 "Keeping surface, will report destroy: " + win);
2480 win.mReportDestroySurface = true;
2481 outSurface.copyFrom(win.mSurface);
2482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 }
2484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 if (focusMayChange) {
2486 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2487 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 imMayMove = false;
2489 }
2490 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2491 }
Romain Guy06882f82009-06-10 13:36:04 -07002492
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002493 // updateFocusedWindowLocked() already assigned layers so we only need to
2494 // reassign them at this point if the IM window state gets shuffled
2495 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002498 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2499 // Little hack here -- we -should- be able to rely on the
2500 // function to return true if the IME has moved and needs
2501 // its layer recomputed. However, if the IME was hidden
2502 // and isn't actually moved in the list, its layer may be
2503 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 assignLayers = true;
2505 }
2506 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002507 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002508 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002509 assignLayers = true;
2510 }
2511 }
Romain Guy06882f82009-06-10 13:36:04 -07002512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 mLayoutNeeded = true;
2514 win.mGivenInsetsPending = insetsPending;
2515 if (assignLayers) {
2516 assignLayersLocked();
2517 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002518 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002519 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002520 if (displayed && win.mIsWallpaper) {
2521 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002522 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002523 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 if (win.mAppToken != null) {
2525 win.mAppToken.updateReportedVisibilityLocked();
2526 }
2527 outFrame.set(win.mFrame);
2528 outContentInsets.set(win.mContentInsets);
2529 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002530 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002532 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 + ", requestedHeight=" + requestedHeight
2534 + ", viewVisibility=" + viewVisibility
2535 + "\nRelayout returning frame=" + outFrame
2536 + ", surface=" + outSurface);
2537
Joe Onorato8a9b2202010-02-26 18:56:32 -08002538 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2540
2541 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002542
2543 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 }
2545
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002546 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 sendNewConfiguration();
2548 }
Romain Guy06882f82009-06-10 13:36:04 -07002549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2553 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2554 }
2555
2556 public void finishDrawingWindow(Session session, IWindow client) {
2557 final long origId = Binder.clearCallingIdentity();
2558 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002559 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002561 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2562 adjustWallpaperWindowsLocked();
2563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 mLayoutNeeded = true;
2565 performLayoutAndPlaceSurfacesLocked();
2566 }
2567 }
2568 Binder.restoreCallingIdentity(origId);
2569 }
2570
2571 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002572 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 + (lp != null ? lp.packageName : null)
2574 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2575 if (lp != null && lp.windowAnimations != 0) {
2576 // If this is a system resource, don't try to load it from the
2577 // application resources. It is nice to avoid loading application
2578 // resources if we can.
2579 String packageName = lp.packageName != null ? lp.packageName : "android";
2580 int resId = lp.windowAnimations;
2581 if ((resId&0xFF000000) == 0x01000000) {
2582 packageName = "android";
2583 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002584 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 + packageName);
2586 return AttributeCache.instance().get(packageName, resId,
2587 com.android.internal.R.styleable.WindowAnimation);
2588 }
2589 return null;
2590 }
Romain Guy06882f82009-06-10 13:36:04 -07002591
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002592 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002593 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002594 + packageName + " resId=0x" + Integer.toHexString(resId));
2595 if (packageName != null) {
2596 if ((resId&0xFF000000) == 0x01000000) {
2597 packageName = "android";
2598 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002599 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002600 + packageName);
2601 return AttributeCache.instance().get(packageName, resId,
2602 com.android.internal.R.styleable.WindowAnimation);
2603 }
2604 return null;
2605 }
2606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 private void applyEnterAnimationLocked(WindowState win) {
2608 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2609 if (win.mEnterAnimationPending) {
2610 win.mEnterAnimationPending = false;
2611 transit = WindowManagerPolicy.TRANSIT_ENTER;
2612 }
2613
2614 applyAnimationLocked(win, transit, true);
2615 }
2616
2617 private boolean applyAnimationLocked(WindowState win,
2618 int transit, boolean isEntrance) {
2619 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2620 // If we are trying to apply an animation, but already running
2621 // an animation of the same type, then just leave that one alone.
2622 return true;
2623 }
Romain Guy06882f82009-06-10 13:36:04 -07002624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 // Only apply an animation if the display isn't frozen. If it is
2626 // frozen, there is no reason to animate and it can cause strange
2627 // artifacts when we unfreeze the display if some different animation
2628 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002629 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002630 int anim = mPolicy.selectAnimationLw(win, transit);
2631 int attr = -1;
2632 Animation a = null;
2633 if (anim != 0) {
2634 a = AnimationUtils.loadAnimation(mContext, anim);
2635 } else {
2636 switch (transit) {
2637 case WindowManagerPolicy.TRANSIT_ENTER:
2638 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2639 break;
2640 case WindowManagerPolicy.TRANSIT_EXIT:
2641 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2642 break;
2643 case WindowManagerPolicy.TRANSIT_SHOW:
2644 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2645 break;
2646 case WindowManagerPolicy.TRANSIT_HIDE:
2647 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2648 break;
2649 }
2650 if (attr >= 0) {
2651 a = loadAnimation(win.mAttrs, attr);
2652 }
2653 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002654 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2656 + " mAnimation=" + win.mAnimation
2657 + " isEntrance=" + isEntrance);
2658 if (a != null) {
2659 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002660 RuntimeException e = null;
2661 if (!HIDE_STACK_CRAWLS) {
2662 e = new RuntimeException();
2663 e.fillInStackTrace();
2664 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002665 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 }
2667 win.setAnimation(a);
2668 win.mAnimationIsEntrance = isEntrance;
2669 }
2670 } else {
2671 win.clearAnimation();
2672 }
2673
2674 return win.mAnimation != null;
2675 }
2676
2677 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2678 int anim = 0;
2679 Context context = mContext;
2680 if (animAttr >= 0) {
2681 AttributeCache.Entry ent = getCachedAnimations(lp);
2682 if (ent != null) {
2683 context = ent.context;
2684 anim = ent.array.getResourceId(animAttr, 0);
2685 }
2686 }
2687 if (anim != 0) {
2688 return AnimationUtils.loadAnimation(context, anim);
2689 }
2690 return null;
2691 }
Romain Guy06882f82009-06-10 13:36:04 -07002692
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002693 private Animation loadAnimation(String packageName, int resId) {
2694 int anim = 0;
2695 Context context = mContext;
2696 if (resId >= 0) {
2697 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2698 if (ent != null) {
2699 context = ent.context;
2700 anim = resId;
2701 }
2702 }
2703 if (anim != 0) {
2704 return AnimationUtils.loadAnimation(context, anim);
2705 }
2706 return null;
2707 }
2708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 private boolean applyAnimationLocked(AppWindowToken wtoken,
2710 WindowManager.LayoutParams lp, int transit, boolean enter) {
2711 // Only apply an animation if the display isn't frozen. If it is
2712 // frozen, there is no reason to animate and it can cause strange
2713 // artifacts when we unfreeze the display if some different animation
2714 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002715 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002716 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002717 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002718 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002719 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002720 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002721 } else if (mNextAppTransitionPackage != null) {
2722 a = loadAnimation(mNextAppTransitionPackage, enter ?
2723 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002724 } else {
2725 int animAttr = 0;
2726 switch (transit) {
2727 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2728 animAttr = enter
2729 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2730 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2731 break;
2732 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2733 animAttr = enter
2734 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2735 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2736 break;
2737 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2738 animAttr = enter
2739 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2740 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2741 break;
2742 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2743 animAttr = enter
2744 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2745 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2746 break;
2747 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2748 animAttr = enter
2749 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2750 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2751 break;
2752 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2753 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002754 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002755 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2756 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002757 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002758 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002759 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2760 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002761 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002762 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002763 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002764 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2765 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2766 break;
2767 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2768 animAttr = enter
2769 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2770 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2771 break;
2772 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2773 animAttr = enter
2774 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2775 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002776 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002777 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002778 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002779 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002780 + " anim=" + a
2781 + " animAttr=0x" + Integer.toHexString(animAttr)
2782 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 if (a != null) {
2785 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002786 RuntimeException e = null;
2787 if (!HIDE_STACK_CRAWLS) {
2788 e = new RuntimeException();
2789 e.fillInStackTrace();
2790 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002791 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 }
2793 wtoken.setAnimation(a);
2794 }
2795 } else {
2796 wtoken.clearAnimation();
2797 }
2798
2799 return wtoken.animation != null;
2800 }
2801
2802 // -------------------------------------------------------------
2803 // Application Window Tokens
2804 // -------------------------------------------------------------
2805
2806 public void validateAppTokens(List tokens) {
2807 int v = tokens.size()-1;
2808 int m = mAppTokens.size()-1;
2809 while (v >= 0 && m >= 0) {
2810 AppWindowToken wtoken = mAppTokens.get(m);
2811 if (wtoken.removed) {
2812 m--;
2813 continue;
2814 }
2815 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002816 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002817 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2818 }
2819 v--;
2820 m--;
2821 }
2822 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002823 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 v--;
2825 }
2826 while (m >= 0) {
2827 AppWindowToken wtoken = mAppTokens.get(m);
2828 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002829 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 }
2831 m--;
2832 }
2833 }
2834
2835 boolean checkCallingPermission(String permission, String func) {
2836 // Quick check: if the calling permission is me, it's all okay.
2837 if (Binder.getCallingPid() == Process.myPid()) {
2838 return true;
2839 }
Romain Guy06882f82009-06-10 13:36:04 -07002840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 if (mContext.checkCallingPermission(permission)
2842 == PackageManager.PERMISSION_GRANTED) {
2843 return true;
2844 }
2845 String msg = "Permission Denial: " + func + " from pid="
2846 + Binder.getCallingPid()
2847 + ", uid=" + Binder.getCallingUid()
2848 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002849 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 return false;
2851 }
Romain Guy06882f82009-06-10 13:36:04 -07002852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 AppWindowToken findAppWindowToken(IBinder token) {
2854 WindowToken wtoken = mTokenMap.get(token);
2855 if (wtoken == null) {
2856 return null;
2857 }
2858 return wtoken.appWindowToken;
2859 }
Romain Guy06882f82009-06-10 13:36:04 -07002860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 public void addWindowToken(IBinder token, int type) {
2862 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2863 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002864 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 }
Romain Guy06882f82009-06-10 13:36:04 -07002866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 synchronized(mWindowMap) {
2868 WindowToken wtoken = mTokenMap.get(token);
2869 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002870 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002871 return;
2872 }
2873 wtoken = new WindowToken(token, type, true);
2874 mTokenMap.put(token, wtoken);
2875 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002876 if (type == TYPE_WALLPAPER) {
2877 mWallpaperTokens.add(wtoken);
2878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 }
2880 }
Romain Guy06882f82009-06-10 13:36:04 -07002881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 public void removeWindowToken(IBinder token) {
2883 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2884 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002885 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 }
2887
2888 final long origId = Binder.clearCallingIdentity();
2889 synchronized(mWindowMap) {
2890 WindowToken wtoken = mTokenMap.remove(token);
2891 mTokenList.remove(wtoken);
2892 if (wtoken != null) {
2893 boolean delayed = false;
2894 if (!wtoken.hidden) {
2895 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 final int N = wtoken.windows.size();
2898 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 for (int i=0; i<N; i++) {
2901 WindowState win = wtoken.windows.get(i);
2902
2903 if (win.isAnimating()) {
2904 delayed = true;
2905 }
Romain Guy06882f82009-06-10 13:36:04 -07002906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 if (win.isVisibleNow()) {
2908 applyAnimationLocked(win,
2909 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 changed = true;
2911 }
2912 }
2913
2914 if (changed) {
2915 mLayoutNeeded = true;
2916 performLayoutAndPlaceSurfacesLocked();
2917 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2918 }
Romain Guy06882f82009-06-10 13:36:04 -07002919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 if (delayed) {
2921 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002922 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2923 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 }
2925 }
Romain Guy06882f82009-06-10 13:36:04 -07002926
Jeff Brownc5ed5912010-07-14 18:48:53 -07002927 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002929 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 }
2931 }
2932 Binder.restoreCallingIdentity(origId);
2933 }
2934
2935 public void addAppToken(int addPos, IApplicationToken token,
2936 int groupId, int requestedOrientation, boolean fullscreen) {
2937 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2938 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002939 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 }
Jeff Brown349703e2010-06-22 01:27:15 -07002941
2942 // Get the dispatching timeout here while we are not holding any locks so that it
2943 // can be cached by the AppWindowToken. The timeout value is used later by the
2944 // input dispatcher in code that does hold locks. If we did not cache the value
2945 // here we would run the chance of introducing a deadlock between the window manager
2946 // (which holds locks while updating the input dispatcher state) and the activity manager
2947 // (which holds locks while querying the application token).
2948 long inputDispatchingTimeoutNanos;
2949 try {
2950 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2951 } catch (RemoteException ex) {
2952 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2953 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2954 }
Romain Guy06882f82009-06-10 13:36:04 -07002955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 synchronized(mWindowMap) {
2957 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2958 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002959 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 return;
2961 }
2962 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002963 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 wtoken.groupId = groupId;
2965 wtoken.appFullscreen = fullscreen;
2966 wtoken.requestedOrientation = requestedOrientation;
2967 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002968 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 mTokenMap.put(token.asBinder(), wtoken);
2970 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 // Application tokens start out hidden.
2973 wtoken.hidden = true;
2974 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 //dump();
2977 }
2978 }
Romain Guy06882f82009-06-10 13:36:04 -07002979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 public void setAppGroupId(IBinder token, int groupId) {
2981 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2982 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002983 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 }
2985
2986 synchronized(mWindowMap) {
2987 AppWindowToken wtoken = findAppWindowToken(token);
2988 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002989 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002990 return;
2991 }
2992 wtoken.groupId = groupId;
2993 }
2994 }
Romain Guy06882f82009-06-10 13:36:04 -07002995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 public int getOrientationFromWindowsLocked() {
2997 int pos = mWindows.size() - 1;
2998 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07002999 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 pos--;
3001 if (wtoken.mAppToken != null) {
3002 // We hit an application window. so the orientation will be determined by the
3003 // app window. No point in continuing further.
3004 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3005 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003006 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 continue;
3008 }
3009 int req = wtoken.mAttrs.screenOrientation;
3010 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3011 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3012 continue;
3013 } else {
3014 return req;
3015 }
3016 }
3017 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3018 }
Romain Guy06882f82009-06-10 13:36:04 -07003019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003020 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003021 int pos = mAppTokens.size() - 1;
3022 int curGroup = 0;
3023 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3024 boolean findingBehind = false;
3025 boolean haveGroup = false;
3026 boolean lastFullscreen = false;
3027 while (pos >= 0) {
3028 AppWindowToken wtoken = mAppTokens.get(pos);
3029 pos--;
3030 // if we're about to tear down this window and not seek for
3031 // the behind activity, don't use it for orientation
3032 if (!findingBehind
3033 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3034 continue;
3035 }
3036
3037 if (!haveGroup) {
3038 // We ignore any hidden applications on the top.
3039 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003040 continue;
3041 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003042 haveGroup = true;
3043 curGroup = wtoken.groupId;
3044 lastOrientation = wtoken.requestedOrientation;
3045 } else if (curGroup != wtoken.groupId) {
3046 // If we have hit a new application group, and the bottom
3047 // of the previous group didn't explicitly say to use
3048 // the orientation behind it, and the last app was
3049 // full screen, then we'll stick with the
3050 // user's orientation.
3051 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3052 && lastFullscreen) {
3053 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003055 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003056 int or = wtoken.requestedOrientation;
3057 // If this application is fullscreen, and didn't explicitly say
3058 // to use the orientation behind it, then just take whatever
3059 // orientation it has and ignores whatever is under it.
3060 lastFullscreen = wtoken.appFullscreen;
3061 if (lastFullscreen
3062 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3063 return or;
3064 }
3065 // If this application has requested an explicit orientation,
3066 // then use it.
3067 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3068 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3069 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3070 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3071 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3072 return or;
3073 }
3074 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3075 }
3076 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 }
Romain Guy06882f82009-06-10 13:36:04 -07003078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003080 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003081 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3082 "updateOrientationFromAppTokens()")) {
3083 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3084 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003085
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003086 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003088
3089 synchronized(mWindowMap) {
3090 if (updateOrientationFromAppTokensLocked()) {
3091 if (freezeThisOneIfNeeded != null) {
3092 AppWindowToken wtoken = findAppWindowToken(
3093 freezeThisOneIfNeeded);
3094 if (wtoken != null) {
3095 startAppFreezingScreenLocked(wtoken,
3096 ActivityInfo.CONFIG_ORIENTATION);
3097 }
3098 }
3099 config = computeNewConfigurationLocked();
3100
3101 } else if (currentConfig != null) {
3102 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003103 // state mismatches the activity manager's, update it,
3104 // disregarding font scale, which should remain set to
3105 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003106 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003107 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003108 if (computeNewConfigurationLocked(mTempConfiguration)) {
3109 if (currentConfig.diff(mTempConfiguration) != 0) {
3110 mWaitingForConfig = true;
3111 mLayoutNeeded = true;
3112 startFreezingDisplayLocked();
3113 config = new Configuration(mTempConfiguration);
3114 }
3115 }
3116 }
3117 }
3118
Dianne Hackborncfaef692009-06-15 14:24:44 -07003119 Binder.restoreCallingIdentity(ident);
3120 return config;
3121 }
3122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003124 * Determine the new desired orientation of the display, returning
3125 * a non-null new Configuration if it has changed from the current
3126 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3127 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3128 * SCREEN. This will typically be done for you if you call
3129 * sendNewConfiguration().
3130 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 * The orientation is computed from non-application windows first. If none of
3132 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003133 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3135 * android.os.IBinder)
3136 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003137 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003138 if (mDisplayFrozen) {
3139 // If the display is frozen, some activities may be in the middle
3140 // of restarting, and thus have removed their old window. If the
3141 // window has the flag to hide the lock screen, then the lock screen
3142 // can re-appear and inflict its own orientation on us. Keep the
3143 // orientation stable until this all settles down.
3144 return false;
3145 }
3146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003148 long ident = Binder.clearCallingIdentity();
3149 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003150 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 mForcedAppOrientation = req;
3154 //send a message to Policy indicating orientation change to take
3155 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003156 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003157 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3158 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3159 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 }
3161 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003162
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003163 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 } finally {
3165 Binder.restoreCallingIdentity(ident);
3166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167 }
Romain Guy06882f82009-06-10 13:36:04 -07003168
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003169 int computeForcedAppOrientationLocked() {
3170 int req = getOrientationFromWindowsLocked();
3171 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3172 req = getOrientationFromAppTokensLocked();
3173 }
3174 return req;
3175 }
Romain Guy06882f82009-06-10 13:36:04 -07003176
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003177 public void setNewConfiguration(Configuration config) {
3178 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3179 "setNewConfiguration()")) {
3180 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3181 }
3182
3183 synchronized(mWindowMap) {
3184 mCurConfiguration = new Configuration(config);
3185 mWaitingForConfig = false;
3186 performLayoutAndPlaceSurfacesLocked();
3187 }
3188 }
3189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3191 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3192 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003193 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 }
Romain Guy06882f82009-06-10 13:36:04 -07003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 synchronized(mWindowMap) {
3197 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3198 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003199 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 return;
3201 }
Romain Guy06882f82009-06-10 13:36:04 -07003202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003203 wtoken.requestedOrientation = requestedOrientation;
3204 }
3205 }
Romain Guy06882f82009-06-10 13:36:04 -07003206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 public int getAppOrientation(IApplicationToken token) {
3208 synchronized(mWindowMap) {
3209 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3210 if (wtoken == null) {
3211 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3212 }
Romain Guy06882f82009-06-10 13:36:04 -07003213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 return wtoken.requestedOrientation;
3215 }
3216 }
Romain Guy06882f82009-06-10 13:36:04 -07003217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3219 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3220 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003221 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 }
3223
3224 synchronized(mWindowMap) {
3225 boolean changed = false;
3226 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003227 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 changed = mFocusedApp != null;
3229 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003230 if (changed) {
3231 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 } else {
3234 AppWindowToken newFocus = findAppWindowToken(token);
3235 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003236 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 return;
3238 }
3239 changed = mFocusedApp != newFocus;
3240 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003241 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003242 if (changed) {
3243 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 }
3246
3247 if (moveFocusNow && changed) {
3248 final long origId = Binder.clearCallingIdentity();
3249 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3250 Binder.restoreCallingIdentity(origId);
3251 }
3252 }
3253 }
3254
3255 public void prepareAppTransition(int transit) {
3256 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3257 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003258 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 }
Romain Guy06882f82009-06-10 13:36:04 -07003260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003262 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 TAG, "Prepare app transition: transit=" + transit
3264 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003265 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003266 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3267 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003269 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3270 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3271 // Opening a new task always supersedes a close for the anim.
3272 mNextAppTransition = transit;
3273 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3274 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3275 // Opening a new activity always supersedes a close for the anim.
3276 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 }
3278 mAppTransitionReady = false;
3279 mAppTransitionTimeout = false;
3280 mStartingIconInTransition = false;
3281 mSkipAppTransitionAnimation = false;
3282 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3283 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3284 5000);
3285 }
3286 }
3287 }
3288
3289 public int getPendingAppTransition() {
3290 return mNextAppTransition;
3291 }
Romain Guy06882f82009-06-10 13:36:04 -07003292
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003293 public void overridePendingAppTransition(String packageName,
3294 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003295 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003296 mNextAppTransitionPackage = packageName;
3297 mNextAppTransitionEnter = enterAnim;
3298 mNextAppTransitionExit = exitAnim;
3299 }
3300 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 public void executeAppTransition() {
3303 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3304 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003305 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003309 if (DEBUG_APP_TRANSITIONS) {
3310 RuntimeException e = new RuntimeException("here");
3311 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003312 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003313 + mNextAppTransition, e);
3314 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003315 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 mAppTransitionReady = true;
3317 final long origId = Binder.clearCallingIdentity();
3318 performLayoutAndPlaceSurfacesLocked();
3319 Binder.restoreCallingIdentity(origId);
3320 }
3321 }
3322 }
3323
3324 public void setAppStartingWindow(IBinder token, String pkg,
3325 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3326 IBinder transferFrom, boolean createIfNeeded) {
3327 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3328 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003329 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 }
3331
3332 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003333 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3335 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 AppWindowToken wtoken = findAppWindowToken(token);
3338 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003339 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 return;
3341 }
3342
3343 // If the display is frozen, we won't do anything until the
3344 // actual window is displayed so there is no reason to put in
3345 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003346 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 return;
3348 }
Romain Guy06882f82009-06-10 13:36:04 -07003349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 if (wtoken.startingData != null) {
3351 return;
3352 }
Romain Guy06882f82009-06-10 13:36:04 -07003353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 if (transferFrom != null) {
3355 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3356 if (ttoken != null) {
3357 WindowState startingWindow = ttoken.startingWindow;
3358 if (startingWindow != null) {
3359 if (mStartingIconInTransition) {
3360 // In this case, the starting icon has already
3361 // been displayed, so start letting windows get
3362 // shown immediately without any more transitions.
3363 mSkipAppTransitionAnimation = true;
3364 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003365 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 "Moving existing starting from " + ttoken
3367 + " to " + wtoken);
3368 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003369
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 // Transfer the starting window over to the new
3371 // token.
3372 wtoken.startingData = ttoken.startingData;
3373 wtoken.startingView = ttoken.startingView;
3374 wtoken.startingWindow = startingWindow;
3375 ttoken.startingData = null;
3376 ttoken.startingView = null;
3377 ttoken.startingWindow = null;
3378 ttoken.startingMoved = true;
3379 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003380 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003382 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003383 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003385 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386 ttoken.windows.remove(startingWindow);
3387 ttoken.allAppWindows.remove(startingWindow);
3388 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 // Propagate other interesting state between the
3391 // tokens. If the old token is displayed, we should
3392 // immediately force the new one to be displayed. If
3393 // it is animating, we need to move that animation to
3394 // the new one.
3395 if (ttoken.allDrawn) {
3396 wtoken.allDrawn = true;
3397 }
3398 if (ttoken.firstWindowDrawn) {
3399 wtoken.firstWindowDrawn = true;
3400 }
3401 if (!ttoken.hidden) {
3402 wtoken.hidden = false;
3403 wtoken.hiddenRequested = false;
3404 wtoken.willBeHidden = false;
3405 }
3406 if (wtoken.clientHidden != ttoken.clientHidden) {
3407 wtoken.clientHidden = ttoken.clientHidden;
3408 wtoken.sendAppVisibilityToClients();
3409 }
3410 if (ttoken.animation != null) {
3411 wtoken.animation = ttoken.animation;
3412 wtoken.animating = ttoken.animating;
3413 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3414 ttoken.animation = null;
3415 ttoken.animLayerAdjustment = 0;
3416 wtoken.updateLayers();
3417 ttoken.updateLayers();
3418 }
Romain Guy06882f82009-06-10 13:36:04 -07003419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 mLayoutNeeded = true;
3422 performLayoutAndPlaceSurfacesLocked();
3423 Binder.restoreCallingIdentity(origId);
3424 return;
3425 } else if (ttoken.startingData != null) {
3426 // The previous app was getting ready to show a
3427 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003428 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 "Moving pending starting from " + ttoken
3430 + " to " + wtoken);
3431 wtoken.startingData = ttoken.startingData;
3432 ttoken.startingData = null;
3433 ttoken.startingMoved = true;
3434 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3435 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3436 // want to process the message ASAP, before any other queued
3437 // messages.
3438 mH.sendMessageAtFrontOfQueue(m);
3439 return;
3440 }
3441 }
3442 }
3443
3444 // There is no existing starting window, and the caller doesn't
3445 // want us to create one, so that's it!
3446 if (!createIfNeeded) {
3447 return;
3448 }
Romain Guy06882f82009-06-10 13:36:04 -07003449
Dianne Hackborn284ac932009-08-28 10:34:25 -07003450 // If this is a translucent or wallpaper window, then don't
3451 // show a starting window -- the current effect (a full-screen
3452 // opaque starting window that fades away to the real contents
3453 // when it is ready) does not work for this.
3454 if (theme != 0) {
3455 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3456 com.android.internal.R.styleable.Window);
3457 if (ent.array.getBoolean(
3458 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3459 return;
3460 }
3461 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003462 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3463 return;
3464 }
3465 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003466 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3467 return;
3468 }
3469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003471 mStartingIconInTransition = true;
3472 wtoken.startingData = new StartingData(
3473 pkg, theme, nonLocalizedLabel,
3474 labelRes, icon);
3475 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3476 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3477 // want to process the message ASAP, before any other queued
3478 // messages.
3479 mH.sendMessageAtFrontOfQueue(m);
3480 }
3481 }
3482
3483 public void setAppWillBeHidden(IBinder token) {
3484 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3485 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003486 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 }
3488
3489 AppWindowToken wtoken;
3490
3491 synchronized(mWindowMap) {
3492 wtoken = findAppWindowToken(token);
3493 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003494 Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 return;
3496 }
3497 wtoken.willBeHidden = true;
3498 }
3499 }
Romain Guy06882f82009-06-10 13:36:04 -07003500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3502 boolean visible, int transit, boolean performLayout) {
3503 boolean delayed = false;
3504
3505 if (wtoken.clientHidden == visible) {
3506 wtoken.clientHidden = !visible;
3507 wtoken.sendAppVisibilityToClients();
3508 }
Romain Guy06882f82009-06-10 13:36:04 -07003509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 wtoken.willBeHidden = false;
3511 if (wtoken.hidden == visible) {
3512 final int N = wtoken.allAppWindows.size();
3513 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003514 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3516 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003519
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003520 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 if (wtoken.animation == sDummyAnimation) {
3522 wtoken.animation = null;
3523 }
3524 applyAnimationLocked(wtoken, lp, transit, visible);
3525 changed = true;
3526 if (wtoken.animation != null) {
3527 delayed = runningAppAnimation = true;
3528 }
3529 }
Romain Guy06882f82009-06-10 13:36:04 -07003530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 for (int i=0; i<N; i++) {
3532 WindowState win = wtoken.allAppWindows.get(i);
3533 if (win == wtoken.startingWindow) {
3534 continue;
3535 }
3536
3537 if (win.isAnimating()) {
3538 delayed = true;
3539 }
Romain Guy06882f82009-06-10 13:36:04 -07003540
Joe Onorato8a9b2202010-02-26 18:56:32 -08003541 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 //win.dump(" ");
3543 if (visible) {
3544 if (!win.isVisibleNow()) {
3545 if (!runningAppAnimation) {
3546 applyAnimationLocked(win,
3547 WindowManagerPolicy.TRANSIT_ENTER, true);
3548 }
3549 changed = true;
3550 }
3551 } else if (win.isVisibleNow()) {
3552 if (!runningAppAnimation) {
3553 applyAnimationLocked(win,
3554 WindowManagerPolicy.TRANSIT_EXIT, false);
3555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003556 changed = true;
3557 }
3558 }
3559
3560 wtoken.hidden = wtoken.hiddenRequested = !visible;
3561 if (!visible) {
3562 unsetAppFreezingScreenLocked(wtoken, true, true);
3563 } else {
3564 // If we are being set visible, and the starting window is
3565 // not yet displayed, then make sure it doesn't get displayed.
3566 WindowState swin = wtoken.startingWindow;
3567 if (swin != null && (swin.mDrawPending
3568 || swin.mCommitDrawPending)) {
3569 swin.mPolicyVisibility = false;
3570 swin.mPolicyVisibilityAfterAnim = false;
3571 }
3572 }
Romain Guy06882f82009-06-10 13:36:04 -07003573
Joe Onorato8a9b2202010-02-26 18:56:32 -08003574 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3576 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003577
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003578 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003580 if (performLayout) {
3581 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3582 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003583 } else {
3584 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 }
3587 }
3588
3589 if (wtoken.animation != null) {
3590 delayed = true;
3591 }
Romain Guy06882f82009-06-10 13:36:04 -07003592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 return delayed;
3594 }
3595
3596 public void setAppVisibility(IBinder token, boolean visible) {
3597 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3598 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003599 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 }
3601
3602 AppWindowToken wtoken;
3603
3604 synchronized(mWindowMap) {
3605 wtoken = findAppWindowToken(token);
3606 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003607 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 return;
3609 }
3610
3611 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003612 RuntimeException e = null;
3613 if (!HIDE_STACK_CRAWLS) {
3614 e = new RuntimeException();
3615 e.fillInStackTrace();
3616 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003617 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 + "): mNextAppTransition=" + mNextAppTransition
3619 + " hidden=" + wtoken.hidden
3620 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3621 }
Romain Guy06882f82009-06-10 13:36:04 -07003622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 // If we are preparing an app transition, then delay changing
3624 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003625 if (!mDisplayFrozen && mPolicy.isScreenOn()
3626 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 // Already in requested state, don't do anything more.
3628 if (wtoken.hiddenRequested != visible) {
3629 return;
3630 }
3631 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003632
Joe Onorato8a9b2202010-02-26 18:56:32 -08003633 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 TAG, "Setting dummy animation on: " + wtoken);
3635 wtoken.setDummyAnimation();
3636 mOpeningApps.remove(wtoken);
3637 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003638 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003639 wtoken.inPendingTransaction = true;
3640 if (visible) {
3641 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 wtoken.startingDisplayed = false;
3643 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003644
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003645 // If the token is currently hidden (should be the
3646 // common case), then we need to set up to wait for
3647 // its windows to be ready.
3648 if (wtoken.hidden) {
3649 wtoken.allDrawn = false;
3650 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003651
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003652 if (wtoken.clientHidden) {
3653 // In the case where we are making an app visible
3654 // but holding off for a transition, we still need
3655 // to tell the client to make its windows visible so
3656 // they get drawn. Otherwise, we will wait on
3657 // performing the transition until all windows have
3658 // been drawn, they never will be, and we are sad.
3659 wtoken.clientHidden = false;
3660 wtoken.sendAppVisibilityToClients();
3661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 }
3663 } else {
3664 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003665
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003666 // If the token is currently visible (should be the
3667 // common case), then set up to wait for it to be hidden.
3668 if (!wtoken.hidden) {
3669 wtoken.waitingToHide = true;
3670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 }
3672 return;
3673 }
Romain Guy06882f82009-06-10 13:36:04 -07003674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003676 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 wtoken.updateReportedVisibilityLocked();
3678 Binder.restoreCallingIdentity(origId);
3679 }
3680 }
3681
3682 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3683 boolean unfreezeSurfaceNow, boolean force) {
3684 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003685 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 + " force=" + force);
3687 final int N = wtoken.allAppWindows.size();
3688 boolean unfrozeWindows = false;
3689 for (int i=0; i<N; i++) {
3690 WindowState w = wtoken.allAppWindows.get(i);
3691 if (w.mAppFreezing) {
3692 w.mAppFreezing = false;
3693 if (w.mSurface != null && !w.mOrientationChanging) {
3694 w.mOrientationChanging = true;
3695 }
3696 unfrozeWindows = true;
3697 }
3698 }
3699 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003700 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 wtoken.freezingScreen = false;
3702 mAppsFreezingScreen--;
3703 }
3704 if (unfreezeSurfaceNow) {
3705 if (unfrozeWindows) {
3706 mLayoutNeeded = true;
3707 performLayoutAndPlaceSurfacesLocked();
3708 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003709 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 }
3711 }
3712 }
Romain Guy06882f82009-06-10 13:36:04 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3715 int configChanges) {
3716 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003717 RuntimeException e = null;
3718 if (!HIDE_STACK_CRAWLS) {
3719 e = new RuntimeException();
3720 e.fillInStackTrace();
3721 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003722 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 + ": hidden=" + wtoken.hidden + " freezing="
3724 + wtoken.freezingScreen, e);
3725 }
3726 if (!wtoken.hiddenRequested) {
3727 if (!wtoken.freezingScreen) {
3728 wtoken.freezingScreen = true;
3729 mAppsFreezingScreen++;
3730 if (mAppsFreezingScreen == 1) {
3731 startFreezingDisplayLocked();
3732 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3733 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3734 5000);
3735 }
3736 }
3737 final int N = wtoken.allAppWindows.size();
3738 for (int i=0; i<N; i++) {
3739 WindowState w = wtoken.allAppWindows.get(i);
3740 w.mAppFreezing = true;
3741 }
3742 }
3743 }
Romain Guy06882f82009-06-10 13:36:04 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 public void startAppFreezingScreen(IBinder token, int configChanges) {
3746 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3747 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003748 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 }
3750
3751 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003752 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003753 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 return;
3755 }
Romain Guy06882f82009-06-10 13:36:04 -07003756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 AppWindowToken wtoken = findAppWindowToken(token);
3758 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003759 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 return;
3761 }
3762 final long origId = Binder.clearCallingIdentity();
3763 startAppFreezingScreenLocked(wtoken, configChanges);
3764 Binder.restoreCallingIdentity(origId);
3765 }
3766 }
Romain Guy06882f82009-06-10 13:36:04 -07003767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 public void stopAppFreezingScreen(IBinder token, boolean force) {
3769 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3770 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003771 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 }
3773
3774 synchronized(mWindowMap) {
3775 AppWindowToken wtoken = findAppWindowToken(token);
3776 if (wtoken == null || wtoken.appToken == null) {
3777 return;
3778 }
3779 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003780 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3782 unsetAppFreezingScreenLocked(wtoken, true, force);
3783 Binder.restoreCallingIdentity(origId);
3784 }
3785 }
Romain Guy06882f82009-06-10 13:36:04 -07003786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 public void removeAppToken(IBinder token) {
3788 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3789 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003790 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003791 }
3792
3793 AppWindowToken wtoken = null;
3794 AppWindowToken startingToken = null;
3795 boolean delayed = false;
3796
3797 final long origId = Binder.clearCallingIdentity();
3798 synchronized(mWindowMap) {
3799 WindowToken basewtoken = mTokenMap.remove(token);
3800 mTokenList.remove(basewtoken);
3801 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003802 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003803 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 wtoken.inPendingTransaction = false;
3805 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003806 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 if (mClosingApps.contains(wtoken)) {
3808 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003809 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003811 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 delayed = true;
3813 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003814 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 TAG, "Removing app " + wtoken + " delayed=" + delayed
3816 + " animation=" + wtoken.animation
3817 + " animating=" + wtoken.animating);
3818 if (delayed) {
3819 // set the token aside because it has an active animation to be finished
3820 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003821 } else {
3822 // Make sure there is no animation running on this token,
3823 // so any windows associated with it will be removed as
3824 // soon as their animations are complete
3825 wtoken.animation = null;
3826 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 }
3828 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003829 if (mLastEnterAnimToken == wtoken) {
3830 mLastEnterAnimToken = null;
3831 mLastEnterAnimParams = null;
3832 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 wtoken.removed = true;
3834 if (wtoken.startingData != null) {
3835 startingToken = wtoken;
3836 }
3837 unsetAppFreezingScreenLocked(wtoken, true, true);
3838 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003839 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 mFocusedApp = null;
3841 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003842 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 }
3844 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003845 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 }
Romain Guy06882f82009-06-10 13:36:04 -07003847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 if (!delayed && wtoken != null) {
3849 wtoken.updateReportedVisibilityLocked();
3850 }
3851 }
3852 Binder.restoreCallingIdentity(origId);
3853
3854 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003855 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 + startingToken + ": app token removed");
3857 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3858 mH.sendMessage(m);
3859 }
3860 }
3861
3862 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3863 final int NW = token.windows.size();
3864 for (int i=0; i<NW; i++) {
3865 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003866 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003868 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003869 int j = win.mChildWindows.size();
3870 while (j > 0) {
3871 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003872 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003873 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003874 "Tmp removing child window " + cwin);
3875 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 }
3877 }
3878 return NW > 0;
3879 }
3880
3881 void dumpAppTokensLocked() {
3882 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003883 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884 }
3885 }
Romain Guy06882f82009-06-10 13:36:04 -07003886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 void dumpWindowsLocked() {
3888 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003889 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 }
3891 }
Romain Guy06882f82009-06-10 13:36:04 -07003892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 private int findWindowOffsetLocked(int tokenPos) {
3894 final int NW = mWindows.size();
3895
3896 if (tokenPos >= mAppTokens.size()) {
3897 int i = NW;
3898 while (i > 0) {
3899 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003900 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003901 if (win.getAppToken() != null) {
3902 return i+1;
3903 }
3904 }
3905 }
3906
3907 while (tokenPos > 0) {
3908 // Find the first app token below the new position that has
3909 // a window displayed.
3910 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003911 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003912 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003913 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003914 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003915 "Skipping token -- currently sending to bottom");
3916 tokenPos--;
3917 continue;
3918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 int i = wtoken.windows.size();
3920 while (i > 0) {
3921 i--;
3922 WindowState win = wtoken.windows.get(i);
3923 int j = win.mChildWindows.size();
3924 while (j > 0) {
3925 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003926 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003927 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003928 for (int pos=NW-1; pos>=0; pos--) {
3929 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003930 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 "Found child win @" + (pos+1));
3932 return pos+1;
3933 }
3934 }
3935 }
3936 }
3937 for (int pos=NW-1; pos>=0; pos--) {
3938 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003939 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 return pos+1;
3941 }
3942 }
3943 }
3944 tokenPos--;
3945 }
3946
3947 return 0;
3948 }
3949
3950 private final int reAddWindowLocked(int index, WindowState win) {
3951 final int NCW = win.mChildWindows.size();
3952 boolean added = false;
3953 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003954 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003956 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003957 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003958 mWindows.add(index, win);
3959 index++;
3960 added = true;
3961 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003962 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003963 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 mWindows.add(index, cwin);
3965 index++;
3966 }
3967 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003968 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003969 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970 mWindows.add(index, win);
3971 index++;
3972 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003973 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003974 return index;
3975 }
Romain Guy06882f82009-06-10 13:36:04 -07003976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3978 final int NW = token.windows.size();
3979 for (int i=0; i<NW; i++) {
3980 index = reAddWindowLocked(index, token.windows.get(i));
3981 }
3982 return index;
3983 }
3984
3985 public void moveAppToken(int index, IBinder token) {
3986 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3987 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003988 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003989 }
3990
3991 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003992 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 if (DEBUG_REORDER) dumpAppTokensLocked();
3994 final AppWindowToken wtoken = findAppWindowToken(token);
3995 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003996 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 + token + " (" + wtoken + ")");
3998 return;
3999 }
4000 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004001 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004005 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 if (DEBUG_REORDER) dumpWindowsLocked();
4007 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004008 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 if (DEBUG_REORDER) dumpWindowsLocked();
4010 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004011 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 if (DEBUG_REORDER) dumpWindowsLocked();
4013 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004014 mLayoutNeeded = true;
4015 performLayoutAndPlaceSurfacesLocked();
4016 }
4017 Binder.restoreCallingIdentity(origId);
4018 }
4019 }
4020
4021 private void removeAppTokensLocked(List<IBinder> tokens) {
4022 // XXX This should be done more efficiently!
4023 // (take advantage of the fact that both lists should be
4024 // ordered in the same way.)
4025 int N = tokens.size();
4026 for (int i=0; i<N; i++) {
4027 IBinder token = tokens.get(i);
4028 final AppWindowToken wtoken = findAppWindowToken(token);
4029 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004030 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 + token + " (" + wtoken + ")");
4032 i--;
4033 N--;
4034 }
4035 }
4036 }
4037
Dianne Hackborna8f60182009-09-01 19:01:50 -07004038 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4039 boolean updateFocusAndLayout) {
4040 // First remove all of the windows from the list.
4041 tmpRemoveAppWindowsLocked(wtoken);
4042
4043 // Where to start adding?
4044 int pos = findWindowOffsetLocked(tokenPos);
4045
4046 // And now add them back at the correct place.
4047 pos = reAddAppWindowsLocked(pos, wtoken);
4048
4049 if (updateFocusAndLayout) {
4050 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4051 assignLayersLocked();
4052 }
4053 mLayoutNeeded = true;
4054 performLayoutAndPlaceSurfacesLocked();
4055 }
4056 }
4057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004058 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4059 // First remove all of the windows from the list.
4060 final int N = tokens.size();
4061 int i;
4062 for (i=0; i<N; i++) {
4063 WindowToken token = mTokenMap.get(tokens.get(i));
4064 if (token != null) {
4065 tmpRemoveAppWindowsLocked(token);
4066 }
4067 }
4068
4069 // Where to start adding?
4070 int pos = findWindowOffsetLocked(tokenPos);
4071
4072 // And now add them back at the correct place.
4073 for (i=0; i<N; i++) {
4074 WindowToken token = mTokenMap.get(tokens.get(i));
4075 if (token != null) {
4076 pos = reAddAppWindowsLocked(pos, token);
4077 }
4078 }
4079
Dianne Hackborna8f60182009-09-01 19:01:50 -07004080 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4081 assignLayersLocked();
4082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 mLayoutNeeded = true;
4084 performLayoutAndPlaceSurfacesLocked();
4085
4086 //dump();
4087 }
4088
4089 public void moveAppTokensToTop(List<IBinder> tokens) {
4090 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4091 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004092 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 }
4094
4095 final long origId = Binder.clearCallingIdentity();
4096 synchronized(mWindowMap) {
4097 removeAppTokensLocked(tokens);
4098 final int N = tokens.size();
4099 for (int i=0; i<N; i++) {
4100 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4101 if (wt != null) {
4102 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004103 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004104 mToTopApps.remove(wt);
4105 mToBottomApps.remove(wt);
4106 mToTopApps.add(wt);
4107 wt.sendingToBottom = false;
4108 wt.sendingToTop = true;
4109 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004110 }
4111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004112
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004113 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004114 moveAppWindowsLocked(tokens, mAppTokens.size());
4115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117 Binder.restoreCallingIdentity(origId);
4118 }
4119
4120 public void moveAppTokensToBottom(List<IBinder> tokens) {
4121 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4122 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004123 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 }
4125
4126 final long origId = Binder.clearCallingIdentity();
4127 synchronized(mWindowMap) {
4128 removeAppTokensLocked(tokens);
4129 final int N = tokens.size();
4130 int pos = 0;
4131 for (int i=0; i<N; i++) {
4132 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4133 if (wt != null) {
4134 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004135 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004136 mToTopApps.remove(wt);
4137 mToBottomApps.remove(wt);
4138 mToBottomApps.add(i, wt);
4139 wt.sendingToTop = false;
4140 wt.sendingToBottom = true;
4141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142 pos++;
4143 }
4144 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004145
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004146 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004147 moveAppWindowsLocked(tokens, 0);
4148 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004149 }
4150 Binder.restoreCallingIdentity(origId);
4151 }
4152
4153 // -------------------------------------------------------------
4154 // Misc IWindowSession methods
4155 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004156
Jim Miller284b62e2010-06-08 14:27:42 -07004157 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004158 {
Jim Miller284b62e2010-06-08 14:27:42 -07004159 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4160 // called before DevicePolicyManagerService has started.
4161 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4162 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4163 Context.DEVICE_POLICY_SERVICE);
4164 if (dpm != null) {
4165 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4166 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4167 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4168 }
Jim Millerd6b57052010-06-07 17:52:42 -07004169 }
Jim Miller284b62e2010-06-08 14:27:42 -07004170 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004171 }
4172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004174 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004175 != PackageManager.PERMISSION_GRANTED) {
4176 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4177 }
Jim Millerd6b57052010-06-07 17:52:42 -07004178
Jim Miller284b62e2010-06-08 14:27:42 -07004179 synchronized (mKeyguardTokenWatcher) {
4180 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004181 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 }
4183
4184 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004185 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 != PackageManager.PERMISSION_GRANTED) {
4187 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4188 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189
Jim Miller284b62e2010-06-08 14:27:42 -07004190 synchronized (mKeyguardTokenWatcher) {
4191 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004192
Jim Miller284b62e2010-06-08 14:27:42 -07004193 if (!mKeyguardTokenWatcher.isAcquired()) {
4194 // If we are the last one to reenable the keyguard wait until
4195 // we have actually finished reenabling until returning.
4196 // It is possible that reenableKeyguard() can be called before
4197 // the previous disableKeyguard() is handled, in which case
4198 // neither mKeyguardTokenWatcher.acquired() or released() would
4199 // be called. In that case mKeyguardDisabled will be false here
4200 // and we have nothing to wait for.
4201 while (mKeyguardDisabled) {
4202 try {
4203 mKeyguardTokenWatcher.wait();
4204 } catch (InterruptedException e) {
4205 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004206 }
4207 }
4208 }
4209 }
4210 }
4211
4212 /**
4213 * @see android.app.KeyguardManager#exitKeyguardSecurely
4214 */
4215 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004216 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 != PackageManager.PERMISSION_GRANTED) {
4218 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4219 }
4220 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4221 public void onKeyguardExitResult(boolean success) {
4222 try {
4223 callback.onKeyguardExitResult(success);
4224 } catch (RemoteException e) {
4225 // Client has died, we don't care.
4226 }
4227 }
4228 });
4229 }
4230
4231 public boolean inKeyguardRestrictedInputMode() {
4232 return mPolicy.inKeyguardRestrictedKeyInputMode();
4233 }
Romain Guy06882f82009-06-10 13:36:04 -07004234
Dianne Hackbornffa42482009-09-23 22:20:11 -07004235 public void closeSystemDialogs(String reason) {
4236 synchronized(mWindowMap) {
4237 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004238 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004239 if (w.mSurface != null) {
4240 try {
4241 w.mClient.closeSystemDialogs(reason);
4242 } catch (RemoteException e) {
4243 }
4244 }
4245 }
4246 }
4247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 static float fixScale(float scale) {
4250 if (scale < 0) scale = 0;
4251 else if (scale > 20) scale = 20;
4252 return Math.abs(scale);
4253 }
Romain Guy06882f82009-06-10 13:36:04 -07004254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004255 public void setAnimationScale(int which, float scale) {
4256 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4257 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004258 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004259 }
4260
4261 if (scale < 0) scale = 0;
4262 else if (scale > 20) scale = 20;
4263 scale = Math.abs(scale);
4264 switch (which) {
4265 case 0: mWindowAnimationScale = fixScale(scale); break;
4266 case 1: mTransitionAnimationScale = fixScale(scale); break;
4267 }
Romain Guy06882f82009-06-10 13:36:04 -07004268
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 // Persist setting
4270 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4271 }
Romain Guy06882f82009-06-10 13:36:04 -07004272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 public void setAnimationScales(float[] scales) {
4274 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4275 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004276 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 }
4278
4279 if (scales != null) {
4280 if (scales.length >= 1) {
4281 mWindowAnimationScale = fixScale(scales[0]);
4282 }
4283 if (scales.length >= 2) {
4284 mTransitionAnimationScale = fixScale(scales[1]);
4285 }
4286 }
Romain Guy06882f82009-06-10 13:36:04 -07004287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288 // Persist setting
4289 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4290 }
Romain Guy06882f82009-06-10 13:36:04 -07004291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 public float getAnimationScale(int which) {
4293 switch (which) {
4294 case 0: return mWindowAnimationScale;
4295 case 1: return mTransitionAnimationScale;
4296 }
4297 return 0;
4298 }
Romain Guy06882f82009-06-10 13:36:04 -07004299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004300 public float[] getAnimationScales() {
4301 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4302 }
Romain Guy06882f82009-06-10 13:36:04 -07004303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004304 public int getSwitchState(int sw) {
4305 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4306 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004307 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004308 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004309 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
Romain Guy06882f82009-06-10 13:36:04 -07004311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 public int getSwitchStateForDevice(int devid, int sw) {
4313 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4314 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004315 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004316 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004317 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 }
Romain Guy06882f82009-06-10 13:36:04 -07004319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004320 public int getScancodeState(int sw) {
4321 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4322 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004323 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004325 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004326 }
Romain Guy06882f82009-06-10 13:36:04 -07004327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004328 public int getScancodeStateForDevice(int devid, int sw) {
4329 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4330 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004331 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004332 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004333 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 }
Romain Guy06882f82009-06-10 13:36:04 -07004335
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004336 public int getTrackballScancodeState(int sw) {
4337 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4338 "getTrackballScancodeState()")) {
4339 throw new SecurityException("Requires READ_INPUT_STATE permission");
4340 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004341 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004342 }
4343
4344 public int getDPadScancodeState(int sw) {
4345 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4346 "getDPadScancodeState()")) {
4347 throw new SecurityException("Requires READ_INPUT_STATE permission");
4348 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004349 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004350 }
4351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004352 public int getKeycodeState(int sw) {
4353 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4354 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004355 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004357 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 }
Romain Guy06882f82009-06-10 13:36:04 -07004359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 public int getKeycodeStateForDevice(int devid, int sw) {
4361 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4362 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004363 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004365 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004366 }
Romain Guy06882f82009-06-10 13:36:04 -07004367
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004368 public int getTrackballKeycodeState(int sw) {
4369 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4370 "getTrackballKeycodeState()")) {
4371 throw new SecurityException("Requires READ_INPUT_STATE permission");
4372 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004373 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004374 }
4375
4376 public int getDPadKeycodeState(int sw) {
4377 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4378 "getDPadKeycodeState()")) {
4379 throw new SecurityException("Requires READ_INPUT_STATE permission");
4380 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004381 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004382 }
Jeff Browna41ca772010-08-11 14:46:32 -07004383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004384 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004385 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004386 }
Romain Guy06882f82009-06-10 13:36:04 -07004387
Jeff Browna41ca772010-08-11 14:46:32 -07004388 public InputChannel monitorInput(String inputChannelName) {
4389 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4390 "monitorInput()")) {
4391 throw new SecurityException("Requires READ_INPUT_STATE permission");
4392 }
4393 return mInputManager.monitorInput(inputChannelName);
4394 }
4395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 public void enableScreenAfterBoot() {
4397 synchronized(mWindowMap) {
4398 if (mSystemBooted) {
4399 return;
4400 }
4401 mSystemBooted = true;
4402 }
Romain Guy06882f82009-06-10 13:36:04 -07004403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404 performEnableScreen();
4405 }
Romain Guy06882f82009-06-10 13:36:04 -07004406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004407 public void enableScreenIfNeededLocked() {
4408 if (mDisplayEnabled) {
4409 return;
4410 }
4411 if (!mSystemBooted) {
4412 return;
4413 }
4414 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4415 }
Romain Guy06882f82009-06-10 13:36:04 -07004416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417 public void performEnableScreen() {
4418 synchronized(mWindowMap) {
4419 if (mDisplayEnabled) {
4420 return;
4421 }
4422 if (!mSystemBooted) {
4423 return;
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 // Don't enable the screen until all existing windows
4427 // have been drawn.
4428 final int N = mWindows.size();
4429 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004430 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004431 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432 return;
4433 }
4434 }
Romain Guy06882f82009-06-10 13:36:04 -07004435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 mDisplayEnabled = true;
4437 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004438 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004439 StringWriter sw = new StringWriter();
4440 PrintWriter pw = new PrintWriter(sw);
4441 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004442 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004443 }
4444 try {
4445 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4446 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004447 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004448 Parcel data = Parcel.obtain();
4449 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4450 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4451 data, null, 0);
4452 data.recycle();
4453 }
4454 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004455 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 }
4457 }
Romain Guy06882f82009-06-10 13:36:04 -07004458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004462 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4463 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 }
Romain Guy06882f82009-06-10 13:36:04 -07004465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 public void setInTouchMode(boolean mode) {
4467 synchronized(mWindowMap) {
4468 mInTouchMode = mode;
4469 }
4470 }
4471
Romain Guy06882f82009-06-10 13:36:04 -07004472 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004473 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004475 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004476 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 }
4478
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004479 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004480 }
Romain Guy06882f82009-06-10 13:36:04 -07004481
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004482 public void setRotationUnchecked(int rotation,
4483 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004484 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 long origId = Binder.clearCallingIdentity();
4488 boolean changed;
4489 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004490 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004491 }
Romain Guy06882f82009-06-10 13:36:04 -07004492
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004493 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 sendNewConfiguration();
4495 }
Romain Guy06882f82009-06-10 13:36:04 -07004496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 Binder.restoreCallingIdentity(origId);
4498 }
Romain Guy06882f82009-06-10 13:36:04 -07004499
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004500 /**
4501 * Apply a new rotation to the screen, respecting the requests of
4502 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4503 * re-evaluate the desired rotation.
4504 *
4505 * Returns null if the rotation has been changed. In this case YOU
4506 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4507 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004508 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004509 boolean changed;
4510 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4511 rotation = mRequestedRotation;
4512 } else {
4513 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004514 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004516 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004517 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004518 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004519 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004520 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004522 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004523 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004524 "Rotation changed to " + rotation
4525 + " from " + mRotation
4526 + " (forceApp=" + mForcedAppOrientation
4527 + ", req=" + mRequestedRotation + ")");
4528 mRotation = rotation;
4529 mWindowsFreezingScreen = true;
4530 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4531 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4532 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004533 mWaitingForConfig = true;
4534 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004536 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004537 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004538 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004539 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 }
4541 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004542 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004543 if (w.mSurface != null) {
4544 w.mOrientationChanging = true;
4545 }
4546 }
4547 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4548 try {
4549 mRotationWatchers.get(i).onRotationChanged(rotation);
4550 } catch (RemoteException e) {
4551 }
4552 }
4553 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004555 return changed;
4556 }
Romain Guy06882f82009-06-10 13:36:04 -07004557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004558 public int getRotation() {
4559 return mRotation;
4560 }
4561
4562 public int watchRotation(IRotationWatcher watcher) {
4563 final IBinder watcherBinder = watcher.asBinder();
4564 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4565 public void binderDied() {
4566 synchronized (mWindowMap) {
4567 for (int i=0; i<mRotationWatchers.size(); i++) {
4568 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004569 IRotationWatcher removed = mRotationWatchers.remove(i);
4570 if (removed != null) {
4571 removed.asBinder().unlinkToDeath(this, 0);
4572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004573 i--;
4574 }
4575 }
4576 }
4577 }
4578 };
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 synchronized (mWindowMap) {
4581 try {
4582 watcher.asBinder().linkToDeath(dr, 0);
4583 mRotationWatchers.add(watcher);
4584 } catch (RemoteException e) {
4585 // Client died, no cleanup needed.
4586 }
Romain Guy06882f82009-06-10 13:36:04 -07004587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 return mRotation;
4589 }
4590 }
4591
4592 /**
4593 * Starts the view server on the specified port.
4594 *
4595 * @param port The port to listener to.
4596 *
4597 * @return True if the server was successfully started, false otherwise.
4598 *
4599 * @see com.android.server.ViewServer
4600 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4601 */
4602 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004603 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004604 return false;
4605 }
4606
4607 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4608 return false;
4609 }
4610
4611 if (port < 1024) {
4612 return false;
4613 }
4614
4615 if (mViewServer != null) {
4616 if (!mViewServer.isRunning()) {
4617 try {
4618 return mViewServer.start();
4619 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004620 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004621 }
4622 }
4623 return false;
4624 }
4625
4626 try {
4627 mViewServer = new ViewServer(this, port);
4628 return mViewServer.start();
4629 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004630 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 }
4632 return false;
4633 }
4634
Romain Guy06882f82009-06-10 13:36:04 -07004635 private boolean isSystemSecure() {
4636 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4637 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4638 }
4639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 /**
4641 * Stops the view server if it exists.
4642 *
4643 * @return True if the server stopped, false if it wasn't started or
4644 * couldn't be stopped.
4645 *
4646 * @see com.android.server.ViewServer
4647 */
4648 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004649 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004650 return false;
4651 }
4652
4653 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4654 return false;
4655 }
4656
4657 if (mViewServer != null) {
4658 return mViewServer.stop();
4659 }
4660 return false;
4661 }
4662
4663 /**
4664 * Indicates whether the view server is running.
4665 *
4666 * @return True if the server is running, false otherwise.
4667 *
4668 * @see com.android.server.ViewServer
4669 */
4670 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004671 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672 return false;
4673 }
4674
4675 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4676 return false;
4677 }
4678
4679 return mViewServer != null && mViewServer.isRunning();
4680 }
4681
4682 /**
4683 * Lists all availble windows in the system. The listing is written in the
4684 * specified Socket's output stream with the following syntax:
4685 * windowHashCodeInHexadecimal windowName
4686 * Each line of the ouput represents a different window.
4687 *
4688 * @param client The remote client to send the listing to.
4689 * @return False if an error occured, true otherwise.
4690 */
4691 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004692 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004693 return false;
4694 }
4695
4696 boolean result = true;
4697
Jeff Browne33348b2010-07-15 23:54:05 -07004698 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004700 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004701 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702 }
4703
4704 BufferedWriter out = null;
4705
4706 // Any uncaught exception will crash the system process
4707 try {
4708 OutputStream clientStream = client.getOutputStream();
4709 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4710
4711 final int count = windows.length;
4712 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004713 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004714 out.write(Integer.toHexString(System.identityHashCode(w)));
4715 out.write(' ');
4716 out.append(w.mAttrs.getTitle());
4717 out.write('\n');
4718 }
4719
4720 out.write("DONE.\n");
4721 out.flush();
4722 } catch (Exception e) {
4723 result = false;
4724 } finally {
4725 if (out != null) {
4726 try {
4727 out.close();
4728 } catch (IOException e) {
4729 result = false;
4730 }
4731 }
4732 }
4733
4734 return result;
4735 }
4736
4737 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004738 * Returns the focused window in the following format:
4739 * windowHashCodeInHexadecimal windowName
4740 *
4741 * @param client The remote client to send the listing to.
4742 * @return False if an error occurred, true otherwise.
4743 */
4744 boolean viewServerGetFocusedWindow(Socket client) {
4745 if (isSystemSecure()) {
4746 return false;
4747 }
4748
4749 boolean result = true;
4750
4751 WindowState focusedWindow = getFocusedWindow();
4752
4753 BufferedWriter out = null;
4754
4755 // Any uncaught exception will crash the system process
4756 try {
4757 OutputStream clientStream = client.getOutputStream();
4758 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4759
4760 if(focusedWindow != null) {
4761 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4762 out.write(' ');
4763 out.append(focusedWindow.mAttrs.getTitle());
4764 }
4765 out.write('\n');
4766 out.flush();
4767 } catch (Exception e) {
4768 result = false;
4769 } finally {
4770 if (out != null) {
4771 try {
4772 out.close();
4773 } catch (IOException e) {
4774 result = false;
4775 }
4776 }
4777 }
4778
4779 return result;
4780 }
4781
4782 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004783 * Sends a command to a target window. The result of the command, if any, will be
4784 * written in the output stream of the specified socket.
4785 *
4786 * The parameters must follow this syntax:
4787 * windowHashcode extra
4788 *
4789 * Where XX is the length in characeters of the windowTitle.
4790 *
4791 * The first parameter is the target window. The window with the specified hashcode
4792 * will be the target. If no target can be found, nothing happens. The extra parameters
4793 * will be delivered to the target window and as parameters to the command itself.
4794 *
4795 * @param client The remote client to sent the result, if any, to.
4796 * @param command The command to execute.
4797 * @param parameters The command parameters.
4798 *
4799 * @return True if the command was successfully delivered, false otherwise. This does
4800 * not indicate whether the command itself was successful.
4801 */
4802 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004803 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004804 return false;
4805 }
4806
4807 boolean success = true;
4808 Parcel data = null;
4809 Parcel reply = null;
4810
4811 // Any uncaught exception will crash the system process
4812 try {
4813 // Find the hashcode of the window
4814 int index = parameters.indexOf(' ');
4815 if (index == -1) {
4816 index = parameters.length();
4817 }
4818 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004819 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820
4821 // Extract the command's parameter after the window description
4822 if (index < parameters.length()) {
4823 parameters = parameters.substring(index + 1);
4824 } else {
4825 parameters = "";
4826 }
4827
4828 final WindowManagerService.WindowState window = findWindow(hashCode);
4829 if (window == null) {
4830 return false;
4831 }
4832
4833 data = Parcel.obtain();
4834 data.writeInterfaceToken("android.view.IWindow");
4835 data.writeString(command);
4836 data.writeString(parameters);
4837 data.writeInt(1);
4838 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4839
4840 reply = Parcel.obtain();
4841
4842 final IBinder binder = window.mClient.asBinder();
4843 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4844 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4845
4846 reply.readException();
4847
4848 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004849 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 success = false;
4851 } finally {
4852 if (data != null) {
4853 data.recycle();
4854 }
4855 if (reply != null) {
4856 reply.recycle();
4857 }
4858 }
4859
4860 return success;
4861 }
4862
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004863 public void addWindowChangeListener(WindowChangeListener listener) {
4864 synchronized(mWindowMap) {
4865 mWindowChangeListeners.add(listener);
4866 }
4867 }
4868
4869 public void removeWindowChangeListener(WindowChangeListener listener) {
4870 synchronized(mWindowMap) {
4871 mWindowChangeListeners.remove(listener);
4872 }
4873 }
4874
4875 private void notifyWindowsChanged() {
4876 WindowChangeListener[] windowChangeListeners;
4877 synchronized(mWindowMap) {
4878 if(mWindowChangeListeners.isEmpty()) {
4879 return;
4880 }
4881 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4882 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4883 }
4884 int N = windowChangeListeners.length;
4885 for(int i = 0; i < N; i++) {
4886 windowChangeListeners[i].windowsChanged();
4887 }
4888 }
4889
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004890 private void notifyFocusChanged() {
4891 WindowChangeListener[] windowChangeListeners;
4892 synchronized(mWindowMap) {
4893 if(mWindowChangeListeners.isEmpty()) {
4894 return;
4895 }
4896 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4897 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4898 }
4899 int N = windowChangeListeners.length;
4900 for(int i = 0; i < N; i++) {
4901 windowChangeListeners[i].focusChanged();
4902 }
4903 }
4904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004905 private WindowState findWindow(int hashCode) {
4906 if (hashCode == -1) {
4907 return getFocusedWindow();
4908 }
4909
4910 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004911 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004912 final int count = windows.size();
4913
4914 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004915 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 if (System.identityHashCode(w) == hashCode) {
4917 return w;
4918 }
4919 }
4920 }
4921
4922 return null;
4923 }
4924
4925 /*
4926 * Instruct the Activity Manager to fetch the current configuration and broadcast
4927 * that to config-changed listeners if appropriate.
4928 */
4929 void sendNewConfiguration() {
4930 try {
4931 mActivityManager.updateConfiguration(null);
4932 } catch (RemoteException e) {
4933 }
4934 }
Romain Guy06882f82009-06-10 13:36:04 -07004935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004936 public Configuration computeNewConfiguration() {
4937 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004938 return computeNewConfigurationLocked();
4939 }
4940 }
Romain Guy06882f82009-06-10 13:36:04 -07004941
Dianne Hackbornc485a602009-03-24 22:39:49 -07004942 Configuration computeNewConfigurationLocked() {
4943 Configuration config = new Configuration();
4944 if (!computeNewConfigurationLocked(config)) {
4945 return null;
4946 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004947 return config;
4948 }
Romain Guy06882f82009-06-10 13:36:04 -07004949
Dianne Hackbornc485a602009-03-24 22:39:49 -07004950 boolean computeNewConfigurationLocked(Configuration config) {
4951 if (mDisplay == null) {
4952 return false;
4953 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004954
4955 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004956
4957 // Use the effective "visual" dimensions based on current rotation
4958 final boolean rotated = (mRotation == Surface.ROTATION_90
4959 || mRotation == Surface.ROTATION_270);
4960 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4961 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4962
Dianne Hackbornc485a602009-03-24 22:39:49 -07004963 int orientation = Configuration.ORIENTATION_SQUARE;
4964 if (dw < dh) {
4965 orientation = Configuration.ORIENTATION_PORTRAIT;
4966 } else if (dw > dh) {
4967 orientation = Configuration.ORIENTATION_LANDSCAPE;
4968 }
4969 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004970
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004971 DisplayMetrics dm = new DisplayMetrics();
4972 mDisplay.getMetrics(dm);
4973 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4974
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004975 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004976 // Note we only do this once because at this point we don't
4977 // expect the screen to change in this way at runtime, and want
4978 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004979 int longSize = dw;
4980 int shortSize = dh;
4981 if (longSize < shortSize) {
4982 int tmp = longSize;
4983 longSize = shortSize;
4984 shortSize = tmp;
4985 }
4986 longSize = (int)(longSize/dm.density);
4987 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004988
Dianne Hackborn723738c2009-06-25 19:48:04 -07004989 // These semi-magic numbers define our compatibility modes for
4990 // applications with different screens. Don't change unless you
4991 // make sure to test lots and lots of apps!
4992 if (longSize < 470) {
4993 // This is shorter than an HVGA normal density screen (which
4994 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004995 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
4996 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07004997 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07004998 // What size is this screen screen?
4999 if (longSize >= 800 && shortSize >= 600) {
5000 // SVGA or larger screens at medium density are the point
5001 // at which we consider it to be an extra large screen.
5002 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5003 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005004 // VGA or larger screens at medium density are the point
5005 // at which we consider it to be a large screen.
5006 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5007 } else {
5008 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005009
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005010 // If this screen is wider than normal HVGA, or taller
5011 // than FWVGA, then for old apps we want to run in size
5012 // compatibility mode.
5013 if (shortSize > 321 || longSize > 570) {
5014 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5015 }
5016 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005017
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005018 // Is this a long screen?
5019 if (((longSize*3)/5) >= (shortSize-1)) {
5020 // Anything wider than WVGA (5:3) is considering to be long.
5021 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5022 } else {
5023 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5024 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005025 }
5026 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005027 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005028
Dianne Hackbornc485a602009-03-24 22:39:49 -07005029 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5030 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5031 mPolicy.adjustConfigurationLw(config);
5032 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 // -------------------------------------------------------------
5036 // Input Events and Focus Management
5037 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005038
Jeff Brown349703e2010-06-22 01:27:15 -07005039 InputMonitor mInputMonitor = new InputMonitor();
5040
5041 /* Tracks the progress of input dispatch and ensures that input dispatch state
5042 * is kept in sync with changes in window focus, visibility, registration, and
5043 * other relevant Window Manager state transitions. */
5044 final class InputMonitor {
5045 // Current window with input focus for keys and other non-touch events. May be null.
5046 private WindowState mInputFocus;
5047
5048 // When true, prevents input dispatch from proceeding until set to false again.
5049 private boolean mInputDispatchFrozen;
5050
5051 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5052 private boolean mInputDispatchEnabled = true;
5053
5054 // Temporary list of windows information to provide to the input dispatcher.
5055 private InputWindowList mTempInputWindows = new InputWindowList();
5056
5057 // Temporary input application object to provide to the input dispatcher.
5058 private InputApplication mTempInputApplication = new InputApplication();
5059
5060 /* Notifies the window manager about a broken input channel.
5061 *
5062 * Called by the InputManager.
5063 */
5064 public void notifyInputChannelBroken(InputChannel inputChannel) {
5065 synchronized (mWindowMap) {
5066 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5067 if (windowState == null) {
5068 return; // irrelevant
5069 }
5070
5071 Slog.i(TAG, "WINDOW DIED " + windowState);
5072 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005073 }
5074 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005075
Jeff Brown349703e2010-06-22 01:27:15 -07005076 /* Notifies the window manager about an input channel that is not responding.
5077 * The method can either cause dispatching to be aborted by returning -2 or
5078 * return a new timeout in nanoseconds.
5079 *
5080 * Called by the InputManager.
5081 */
5082 public long notifyInputChannelANR(InputChannel inputChannel) {
5083 AppWindowToken token;
5084 synchronized (mWindowMap) {
5085 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5086 if (windowState == null) {
5087 return -2; // irrelevant, abort dispatching (-2)
5088 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005089
Jeff Brown349703e2010-06-22 01:27:15 -07005090 Slog.i(TAG, "Input event dispatching timed out sending to "
5091 + windowState.mAttrs.getTitle());
5092 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005093 }
5094
Jeff Brown349703e2010-06-22 01:27:15 -07005095 return notifyANRInternal(token);
5096 }
5097
5098 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5099 * by successfully delivering the event that originally timed out.
5100 *
5101 * Called by the InputManager.
5102 */
5103 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5104 // Nothing to do just now.
5105 // Just wait for the user to dismiss the ANR dialog.
5106 }
5107
5108 /* Notifies the window manager about an application that is not responding
5109 * in general rather than with respect to a particular input channel.
5110 * The method can either cause dispatching to be aborted by returning -2 or
5111 * return a new timeout in nanoseconds.
5112 *
5113 * Called by the InputManager.
5114 */
5115 public long notifyANR(Object token) {
5116 AppWindowToken appWindowToken = (AppWindowToken) token;
5117
5118 Slog.i(TAG, "Input event dispatching timed out sending to application "
5119 + appWindowToken.stringName);
5120 return notifyANRInternal(appWindowToken);
5121 }
5122
5123 private long notifyANRInternal(AppWindowToken token) {
5124 if (token != null && token.appToken != null) {
5125 try {
5126 // Notify the activity manager about the timeout and let it decide whether
5127 // to abort dispatching or keep waiting.
5128 boolean abort = token.appToken.keyDispatchingTimedOut();
5129 if (! abort) {
5130 // The activity manager declined to abort dispatching.
5131 // Wait a bit longer and timeout again later.
5132 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005133 }
Jeff Brown349703e2010-06-22 01:27:15 -07005134 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005135 }
5136 }
Jeff Brown349703e2010-06-22 01:27:15 -07005137 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005138 }
5139
Jeff Brown349703e2010-06-22 01:27:15 -07005140 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5141 synchronized (mWindowMap) {
5142 return getWindowStateForInputChannelLocked(inputChannel);
5143 }
5144 }
5145
5146 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5147 int windowCount = mWindows.size();
5148 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005149 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005150 if (windowState.mInputChannel == inputChannel) {
5151 return windowState;
5152 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005153 }
5154
Jeff Brown349703e2010-06-22 01:27:15 -07005155 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005156 }
5157
Jeff Brown349703e2010-06-22 01:27:15 -07005158 /* Updates the cached window information provided to the input dispatcher. */
5159 public void updateInputWindowsLw() {
5160 // Populate the input window list with information about all of the windows that
5161 // could potentially receive input.
5162 // As an optimization, we could try to prune the list of windows but this turns
5163 // out to be difficult because only the native code knows for sure which window
5164 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005165 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005166 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005167 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005168 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005169 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005170 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005171 continue;
5172 }
5173
Jeff Brown349703e2010-06-22 01:27:15 -07005174 final int flags = child.mAttrs.flags;
5175 final int type = child.mAttrs.type;
5176
5177 final boolean hasFocus = (child == mInputFocus);
5178 final boolean isVisible = child.isVisibleLw();
5179 final boolean hasWallpaper = (child == mWallpaperTarget)
5180 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5181
5182 // Add a window to our list of input windows.
5183 final InputWindow inputWindow = mTempInputWindows.add();
5184 inputWindow.inputChannel = child.mInputChannel;
5185 inputWindow.layoutParamsFlags = flags;
5186 inputWindow.layoutParamsType = type;
5187 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5188 inputWindow.visible = isVisible;
5189 inputWindow.hasFocus = hasFocus;
5190 inputWindow.hasWallpaper = hasWallpaper;
5191 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5192 inputWindow.ownerPid = child.mSession.mPid;
5193 inputWindow.ownerUid = child.mSession.mUid;
5194
5195 final Rect frame = child.mFrame;
5196 inputWindow.frameLeft = frame.left;
5197 inputWindow.frameTop = frame.top;
5198
5199 switch (child.mTouchableInsets) {
5200 default:
5201 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5202 inputWindow.touchableAreaLeft = frame.left;
5203 inputWindow.touchableAreaTop = frame.top;
5204 inputWindow.touchableAreaRight = frame.right;
5205 inputWindow.touchableAreaBottom = frame.bottom;
5206 break;
5207
5208 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5209 Rect inset = child.mGivenContentInsets;
5210 inputWindow.touchableAreaLeft = frame.left + inset.left;
5211 inputWindow.touchableAreaTop = frame.top + inset.top;
5212 inputWindow.touchableAreaRight = frame.right - inset.right;
5213 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5214 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005215 }
Jeff Brown349703e2010-06-22 01:27:15 -07005216
5217 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5218 Rect inset = child.mGivenVisibleInsets;
5219 inputWindow.touchableAreaLeft = frame.left + inset.left;
5220 inputWindow.touchableAreaTop = frame.top + inset.top;
5221 inputWindow.touchableAreaRight = frame.right - inset.right;
5222 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005223 break;
5224 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005225 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005226 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005227
Jeff Brown349703e2010-06-22 01:27:15 -07005228 // Send windows to native code.
5229 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005230
Jeff Brown349703e2010-06-22 01:27:15 -07005231 // Clear the list in preparation for the next round.
5232 // Also avoids keeping InputChannel objects referenced unnecessarily.
5233 mTempInputWindows.clear();
5234 }
5235
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005236 /* Provides feedback for a virtual key down. */
5237 public void virtualKeyDownFeedback() {
5238 synchronized (mWindowMap) {
5239 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5240 }
5241 }
5242
Jeff Brown349703e2010-06-22 01:27:15 -07005243 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5244 * This essentially starts a .5 second timeout for the application to process
5245 * subsequent input events while waiting for the app switch to occur. If it takes longer
5246 * than this, the pending events will be dropped.
5247 */
5248 public void notifyAppSwitchComing() {
5249 // TODO Not implemented yet. Should go in the native side.
5250 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005251
5252 /* Notifies that the lid switch changed state. */
5253 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5254 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5255 }
5256
Jeff Brown349703e2010-06-22 01:27:15 -07005257 /* Provides an opportunity for the window manager policy to intercept early key
5258 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005259 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5260 int policyFlags, boolean isScreenOn) {
5261 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5262 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005263 }
5264
5265 /* Provides an opportunity for the window manager policy to process a key before
5266 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005267 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5268 int action, int flags, int keyCode, int metaState, int repeatCount,
5269 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005270 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005271 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5272 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005273 }
5274
5275 /* Called when the current input focus changes.
5276 * Layer assignment is assumed to be complete by the time this is called.
5277 */
5278 public void setInputFocusLw(WindowState newWindow) {
5279 if (DEBUG_INPUT) {
5280 Slog.d(TAG, "Input focus has changed to " + newWindow);
5281 }
5282
5283 if (newWindow != mInputFocus) {
5284 if (newWindow != null && newWindow.canReceiveKeys()) {
5285 // If the new input focus is an error window or appears above the current
5286 // input focus, preempt any pending synchronous dispatch so that we can
5287 // start delivering events to the new input focus as soon as possible.
5288 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5289 if (DEBUG_INPUT) {
5290 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005291 }
Jeff Brown349703e2010-06-22 01:27:15 -07005292 preemptInputDispatchLw();
5293 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5294 if (DEBUG_INPUT) {
5295 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5296 + "old win layer=" + mInputFocus.mLayer
5297 + ", new win layer=" + newWindow.mLayer);
5298 }
5299 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005300 }
Jeff Brown349703e2010-06-22 01:27:15 -07005301
5302 // Displaying a window implicitly causes dispatching to be unpaused.
5303 // This is to protect against bugs if someone pauses dispatching but
5304 // forgets to resume.
5305 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005306 }
Jeff Brown349703e2010-06-22 01:27:15 -07005307
5308 mInputFocus = newWindow;
5309 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005310 }
5311 }
5312
Jeff Brown349703e2010-06-22 01:27:15 -07005313 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5314 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5315 * can begin.
5316 */
5317 private void preemptInputDispatchLw() {
5318 mInputManager.preemptInputDispatch();
5319 }
5320
5321 public void setFocusedAppLw(AppWindowToken newApp) {
5322 // Focused app has changed.
5323 if (newApp == null) {
5324 mInputManager.setFocusedApplication(null);
5325 } else {
5326 mTempInputApplication.name = newApp.toString();
5327 mTempInputApplication.dispatchingTimeoutNanos =
5328 newApp.inputDispatchingTimeoutNanos;
5329 mTempInputApplication.token = newApp;
5330
5331 mInputManager.setFocusedApplication(mTempInputApplication);
5332 }
5333 }
5334
Jeff Brown349703e2010-06-22 01:27:15 -07005335 public void pauseDispatchingLw(WindowToken window) {
5336 if (! window.paused) {
5337 if (DEBUG_INPUT) {
5338 Slog.v(TAG, "Pausing WindowToken " + window);
5339 }
5340
5341 window.paused = true;
5342 updateInputWindowsLw();
5343 }
5344 }
5345
5346 public void resumeDispatchingLw(WindowToken window) {
5347 if (window.paused) {
5348 if (DEBUG_INPUT) {
5349 Slog.v(TAG, "Resuming WindowToken " + window);
5350 }
5351
5352 window.paused = false;
5353 updateInputWindowsLw();
5354 }
5355 }
5356
5357 public void freezeInputDispatchingLw() {
5358 if (! mInputDispatchFrozen) {
5359 if (DEBUG_INPUT) {
5360 Slog.v(TAG, "Freezing input dispatching");
5361 }
5362
5363 mInputDispatchFrozen = true;
5364 updateInputDispatchModeLw();
5365 }
5366 }
5367
5368 public void thawInputDispatchingLw() {
5369 if (mInputDispatchFrozen) {
5370 if (DEBUG_INPUT) {
5371 Slog.v(TAG, "Thawing input dispatching");
5372 }
5373
5374 mInputDispatchFrozen = false;
5375 updateInputDispatchModeLw();
5376 }
5377 }
5378
5379 public void setEventDispatchingLw(boolean enabled) {
5380 if (mInputDispatchEnabled != enabled) {
5381 if (DEBUG_INPUT) {
5382 Slog.v(TAG, "Setting event dispatching to " + enabled);
5383 }
5384
5385 mInputDispatchEnabled = enabled;
5386 updateInputDispatchModeLw();
5387 }
5388 }
5389
5390 private void updateInputDispatchModeLw() {
5391 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5392 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005393 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005395 public void pauseKeyDispatching(IBinder _token) {
5396 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5397 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005398 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005399 }
5400
5401 synchronized (mWindowMap) {
5402 WindowToken token = mTokenMap.get(_token);
5403 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005404 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005405 }
5406 }
5407 }
5408
5409 public void resumeKeyDispatching(IBinder _token) {
5410 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5411 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005412 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005413 }
5414
5415 synchronized (mWindowMap) {
5416 WindowToken token = mTokenMap.get(_token);
5417 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005418 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005419 }
5420 }
5421 }
5422
5423 public void setEventDispatching(boolean enabled) {
5424 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5425 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005426 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 }
5428
5429 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005430 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005431 }
5432 }
Romain Guy06882f82009-06-10 13:36:04 -07005433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005434 /**
5435 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005436 * Even when sync is false, this method may block while waiting for current
5437 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005438 *
5439 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005440 * {@link SystemClock#uptimeMillis()} as the timebase.)
5441 * @param sync If true, wait for the event to be completed before returning to the caller.
5442 * @return Returns true if event was dispatched, false if it was dropped for any reason
5443 */
5444 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5445 long downTime = ev.getDownTime();
5446 long eventTime = ev.getEventTime();
5447
5448 int action = ev.getAction();
5449 int code = ev.getKeyCode();
5450 int repeatCount = ev.getRepeatCount();
5451 int metaState = ev.getMetaState();
5452 int deviceId = ev.getDeviceId();
5453 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005454 int source = ev.getSource();
5455
5456 if (source == InputDevice.SOURCE_UNKNOWN) {
5457 source = InputDevice.SOURCE_KEYBOARD;
5458 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005459
5460 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5461 if (downTime == 0) downTime = eventTime;
5462
5463 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005464 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005465
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005466 final int pid = Binder.getCallingPid();
5467 final int uid = Binder.getCallingUid();
5468 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005469
Jeff Brownbbda99d2010-07-28 15:48:59 -07005470 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5471 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5472 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5473 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005474
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005475 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005476 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005477 }
5478
5479 /**
5480 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005481 * Even when sync is false, this method may block while waiting for current
5482 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005483 *
5484 * @param ev A motion event describing the pointer (touch) action. (As noted in
5485 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005486 * {@link SystemClock#uptimeMillis()} as the timebase.)
5487 * @param sync If true, wait for the event to be completed before returning to the caller.
5488 * @return Returns true if event was dispatched, false if it was dropped for any reason
5489 */
5490 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005491 final int pid = Binder.getCallingPid();
5492 final int uid = Binder.getCallingUid();
5493 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005494
Jeff Brownc5ed5912010-07-14 18:48:53 -07005495 MotionEvent newEvent = MotionEvent.obtain(ev);
5496 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5497 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5498 }
5499
Jeff Brownbbda99d2010-07-28 15:48:59 -07005500 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5501 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5502 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5503 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005504
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005505 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005506 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005507 }
Romain Guy06882f82009-06-10 13:36:04 -07005508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005509 /**
5510 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005511 * Even when sync is false, this method may block while waiting for current
5512 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005513 *
5514 * @param ev A motion event describing the trackball action. (As noted in
5515 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005516 * {@link SystemClock#uptimeMillis()} as the timebase.)
5517 * @param sync If true, wait for the event to be completed before returning to the caller.
5518 * @return Returns true if event was dispatched, false if it was dropped for any reason
5519 */
5520 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005521 final int pid = Binder.getCallingPid();
5522 final int uid = Binder.getCallingUid();
5523 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005524
Jeff Brownc5ed5912010-07-14 18:48:53 -07005525 MotionEvent newEvent = MotionEvent.obtain(ev);
5526 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5527 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5528 }
5529
Jeff Brownbbda99d2010-07-28 15:48:59 -07005530 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5531 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5532 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5533 INJECTION_TIMEOUT_MILLIS);
5534
5535 Binder.restoreCallingIdentity(ident);
5536 return reportInjectionResult(result);
5537 }
5538
5539 /**
5540 * Inject an input event into the UI without waiting for dispatch to commence.
5541 * This variant is useful for fire-and-forget input event injection. It does not
5542 * block any longer than it takes to enqueue the input event.
5543 *
5544 * @param ev An input event. (Be sure to set the input source correctly.)
5545 * @return Returns true if event was dispatched, false if it was dropped for any reason
5546 */
5547 public boolean injectInputEventNoWait(InputEvent ev) {
5548 final int pid = Binder.getCallingPid();
5549 final int uid = Binder.getCallingUid();
5550 final long ident = Binder.clearCallingIdentity();
5551
5552 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5553 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5554 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005555
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005556 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005557 return reportInjectionResult(result);
5558 }
5559
5560 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005561 switch (result) {
5562 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5563 Slog.w(TAG, "Input event injection permission denied.");
5564 throw new SecurityException(
5565 "Injecting to another application requires INJECT_EVENTS permission");
5566 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005567 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005568 return true;
5569 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5570 Slog.w(TAG, "Input event injection timed out.");
5571 return false;
5572 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5573 default:
5574 Slog.w(TAG, "Input event injection failed.");
5575 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005577 }
Romain Guy06882f82009-06-10 13:36:04 -07005578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005579 private WindowState getFocusedWindow() {
5580 synchronized (mWindowMap) {
5581 return getFocusedWindowLocked();
5582 }
5583 }
5584
5585 private WindowState getFocusedWindowLocked() {
5586 return mCurrentFocus;
5587 }
Romain Guy06882f82009-06-10 13:36:04 -07005588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005589 public boolean detectSafeMode() {
5590 mSafeMode = mPolicy.detectSafeMode();
5591 return mSafeMode;
5592 }
Romain Guy06882f82009-06-10 13:36:04 -07005593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005594 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005595 synchronized(mWindowMap) {
5596 if (mDisplay != null) {
5597 throw new IllegalStateException("Display already initialized");
5598 }
5599 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5600 mDisplay = wm.getDefaultDisplay();
5601 mInitialDisplayWidth = mDisplay.getWidth();
5602 mInitialDisplayHeight = mDisplay.getHeight();
5603 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
5604 }
5605
5606 try {
5607 mActivityManager.updateConfiguration(null);
5608 } catch (RemoteException e) {
5609 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005610
5611 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005612 }
5613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005614 // -------------------------------------------------------------
5615 // Client Session State
5616 // -------------------------------------------------------------
5617
5618 private final class Session extends IWindowSession.Stub
5619 implements IBinder.DeathRecipient {
5620 final IInputMethodClient mClient;
5621 final IInputContext mInputContext;
5622 final int mUid;
5623 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005624 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005625 SurfaceSession mSurfaceSession;
5626 int mNumWindow = 0;
5627 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005629 public Session(IInputMethodClient client, IInputContext inputContext) {
5630 mClient = client;
5631 mInputContext = inputContext;
5632 mUid = Binder.getCallingUid();
5633 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005634 StringBuilder sb = new StringBuilder();
5635 sb.append("Session{");
5636 sb.append(Integer.toHexString(System.identityHashCode(this)));
5637 sb.append(" uid ");
5638 sb.append(mUid);
5639 sb.append("}");
5640 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005642 synchronized (mWindowMap) {
5643 if (mInputMethodManager == null && mHaveInputMethods) {
5644 IBinder b = ServiceManager.getService(
5645 Context.INPUT_METHOD_SERVICE);
5646 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5647 }
5648 }
5649 long ident = Binder.clearCallingIdentity();
5650 try {
5651 // Note: it is safe to call in to the input method manager
5652 // here because we are not holding our lock.
5653 if (mInputMethodManager != null) {
5654 mInputMethodManager.addClient(client, inputContext,
5655 mUid, mPid);
5656 } else {
5657 client.setUsingInputMethod(false);
5658 }
5659 client.asBinder().linkToDeath(this, 0);
5660 } catch (RemoteException e) {
5661 // The caller has died, so we can just forget about this.
5662 try {
5663 if (mInputMethodManager != null) {
5664 mInputMethodManager.removeClient(client);
5665 }
5666 } catch (RemoteException ee) {
5667 }
5668 } finally {
5669 Binder.restoreCallingIdentity(ident);
5670 }
5671 }
Romain Guy06882f82009-06-10 13:36:04 -07005672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005673 @Override
5674 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5675 throws RemoteException {
5676 try {
5677 return super.onTransact(code, data, reply, flags);
5678 } catch (RuntimeException e) {
5679 // Log all 'real' exceptions thrown to the caller
5680 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005681 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005682 }
5683 throw e;
5684 }
5685 }
5686
5687 public void binderDied() {
5688 // Note: it is safe to call in to the input method manager
5689 // here because we are not holding our lock.
5690 try {
5691 if (mInputMethodManager != null) {
5692 mInputMethodManager.removeClient(mClient);
5693 }
5694 } catch (RemoteException e) {
5695 }
5696 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005697 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005698 mClientDead = true;
5699 killSessionLocked();
5700 }
5701 }
5702
5703 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005704 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5705 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5706 outInputChannel);
5707 }
5708
5709 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005710 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005711 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 }
Romain Guy06882f82009-06-10 13:36:04 -07005713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005714 public void remove(IWindow window) {
5715 removeWindow(this, window);
5716 }
Romain Guy06882f82009-06-10 13:36:04 -07005717
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005718 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5719 int requestedWidth, int requestedHeight, int viewFlags,
5720 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005721 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005722 return relayoutWindow(this, window, attrs,
5723 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005724 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 }
Romain Guy06882f82009-06-10 13:36:04 -07005726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005727 public void setTransparentRegion(IWindow window, Region region) {
5728 setTransparentRegionWindow(this, window, region);
5729 }
Romain Guy06882f82009-06-10 13:36:04 -07005730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005731 public void setInsets(IWindow window, int touchableInsets,
5732 Rect contentInsets, Rect visibleInsets) {
5733 setInsetsWindow(this, window, touchableInsets, contentInsets,
5734 visibleInsets);
5735 }
Romain Guy06882f82009-06-10 13:36:04 -07005736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5738 getWindowDisplayFrame(this, window, outDisplayFrame);
5739 }
Romain Guy06882f82009-06-10 13:36:04 -07005740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005741 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005742 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005743 TAG, "IWindow finishDrawing called for " + window);
5744 finishDrawingWindow(this, window);
5745 }
5746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005747 public void setInTouchMode(boolean mode) {
5748 synchronized(mWindowMap) {
5749 mInTouchMode = mode;
5750 }
5751 }
5752
5753 public boolean getInTouchMode() {
5754 synchronized(mWindowMap) {
5755 return mInTouchMode;
5756 }
5757 }
5758
5759 public boolean performHapticFeedback(IWindow window, int effectId,
5760 boolean always) {
5761 synchronized(mWindowMap) {
5762 long ident = Binder.clearCallingIdentity();
5763 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005764 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005765 windowForClientLocked(this, window, true),
5766 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005767 } finally {
5768 Binder.restoreCallingIdentity(ident);
5769 }
5770 }
5771 }
Romain Guy06882f82009-06-10 13:36:04 -07005772
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005773 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005774 synchronized(mWindowMap) {
5775 long ident = Binder.clearCallingIdentity();
5776 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005777 setWindowWallpaperPositionLocked(
5778 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005779 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005780 } finally {
5781 Binder.restoreCallingIdentity(ident);
5782 }
5783 }
5784 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005785
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005786 public void wallpaperOffsetsComplete(IBinder window) {
5787 WindowManagerService.this.wallpaperOffsetsComplete(window);
5788 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005789
Dianne Hackborn75804932009-10-20 20:15:20 -07005790 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5791 int z, Bundle extras, boolean sync) {
5792 synchronized(mWindowMap) {
5793 long ident = Binder.clearCallingIdentity();
5794 try {
5795 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005796 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005797 action, x, y, z, extras, sync);
5798 } finally {
5799 Binder.restoreCallingIdentity(ident);
5800 }
5801 }
5802 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005803
Dianne Hackborn75804932009-10-20 20:15:20 -07005804 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5805 WindowManagerService.this.wallpaperCommandComplete(window, result);
5806 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005808 void windowAddedLocked() {
5809 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005810 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 TAG, "First window added to " + this + ", creating SurfaceSession");
5812 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005813 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005814 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005815 mSessions.add(this);
5816 }
5817 mNumWindow++;
5818 }
5819
5820 void windowRemovedLocked() {
5821 mNumWindow--;
5822 killSessionLocked();
5823 }
Romain Guy06882f82009-06-10 13:36:04 -07005824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 void killSessionLocked() {
5826 if (mNumWindow <= 0 && mClientDead) {
5827 mSessions.remove(this);
5828 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005829 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 TAG, "Last window removed from " + this
5831 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005832 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005833 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005834 try {
5835 mSurfaceSession.kill();
5836 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005837 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 + mSurfaceSession + " in session " + this
5839 + ": " + e.toString());
5840 }
5841 mSurfaceSession = null;
5842 }
5843 }
5844 }
Romain Guy06882f82009-06-10 13:36:04 -07005845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005846 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005847 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5848 pw.print(" mClientDead="); pw.print(mClientDead);
5849 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005850 }
5851
5852 @Override
5853 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005854 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005855 }
5856 }
5857
5858 // -------------------------------------------------------------
5859 // Client Window State
5860 // -------------------------------------------------------------
5861
5862 private final class WindowState implements WindowManagerPolicy.WindowState {
5863 final Session mSession;
5864 final IWindow mClient;
5865 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005866 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005867 AppWindowToken mAppToken;
5868 AppWindowToken mTargetAppToken;
5869 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5870 final DeathRecipient mDeathRecipient;
5871 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005872 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005873 final int mBaseLayer;
5874 final int mSubLayer;
5875 final boolean mLayoutAttached;
5876 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005877 final boolean mIsWallpaper;
5878 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005879 int mViewVisibility;
5880 boolean mPolicyVisibility = true;
5881 boolean mPolicyVisibilityAfterAnim = true;
5882 boolean mAppFreezing;
5883 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005884 boolean mReportDestroySurface;
5885 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005886 boolean mAttachedHidden; // is our parent window hidden?
5887 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005888 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005889 int mRequestedWidth;
5890 int mRequestedHeight;
5891 int mLastRequestedWidth;
5892 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005893 int mLayer;
5894 int mAnimLayer;
5895 int mLastLayer;
5896 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005897 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005898 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005899
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005900 int mLayoutSeq = -1;
5901
5902 Configuration mConfiguration = null;
5903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005904 // Actual frame shown on-screen (may be modified by animation)
5905 final Rect mShownFrame = new Rect();
5906 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005907
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005908 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005909 * Set when we have changed the size of the surface, to know that
5910 * we must tell them application to resize (and thus redraw itself).
5911 */
5912 boolean mSurfaceResized;
5913
5914 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 * Insets that determine the actually visible area
5916 */
5917 final Rect mVisibleInsets = new Rect();
5918 final Rect mLastVisibleInsets = new Rect();
5919 boolean mVisibleInsetsChanged;
5920
5921 /**
5922 * Insets that are covered by system windows
5923 */
5924 final Rect mContentInsets = new Rect();
5925 final Rect mLastContentInsets = new Rect();
5926 boolean mContentInsetsChanged;
5927
5928 /**
5929 * Set to true if we are waiting for this window to receive its
5930 * given internal insets before laying out other windows based on it.
5931 */
5932 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005934 /**
5935 * These are the content insets that were given during layout for
5936 * this window, to be applied to windows behind it.
5937 */
5938 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005940 /**
5941 * These are the visible insets that were given during layout for
5942 * this window, to be applied to windows behind it.
5943 */
5944 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005946 /**
5947 * Flag indicating whether the touchable region should be adjusted by
5948 * the visible insets; if false the area outside the visible insets is
5949 * NOT touchable, so we must use those to adjust the frame during hit
5950 * tests.
5951 */
5952 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005954 // Current transformation being applied.
5955 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5956 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5957 float mHScale=1, mVScale=1;
5958 float mLastHScale=1, mLastVScale=1;
5959 final Matrix mTmpMatrix = new Matrix();
5960
5961 // "Real" frame that the application sees.
5962 final Rect mFrame = new Rect();
5963 final Rect mLastFrame = new Rect();
5964
5965 final Rect mContainingFrame = new Rect();
5966 final Rect mDisplayFrame = new Rect();
5967 final Rect mContentFrame = new Rect();
5968 final Rect mVisibleFrame = new Rect();
5969
5970 float mShownAlpha = 1;
5971 float mAlpha = 1;
5972 float mLastAlpha = 1;
5973
5974 // Set to true if, when the window gets displayed, it should perform
5975 // an enter animation.
5976 boolean mEnterAnimationPending;
5977
5978 // Currently running animation.
5979 boolean mAnimating;
5980 boolean mLocalAnimating;
5981 Animation mAnimation;
5982 boolean mAnimationIsEntrance;
5983 boolean mHasTransformation;
5984 boolean mHasLocalTransformation;
5985 final Transformation mTransformation = new Transformation();
5986
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005987 // If a window showing a wallpaper: the requested offset for the
5988 // wallpaper; if a wallpaper window: the currently applied offset.
5989 float mWallpaperX = -1;
5990 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005991
5992 // If a window showing a wallpaper: what fraction of the offset
5993 // range corresponds to a full virtual screen.
5994 float mWallpaperXStep = -1;
5995 float mWallpaperYStep = -1;
5996
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005997 // Wallpaper windows: pixels offset based on above variables.
5998 int mXOffset;
5999 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 // This is set after IWindowSession.relayout() has been called at
6002 // least once for the window. It allows us to detect the situation
6003 // where we don't yet have a surface, but should have one soon, so
6004 // we can give the window focus before waiting for the relayout.
6005 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006007 // This is set after the Surface has been created but before the
6008 // window has been drawn. During this time the surface is hidden.
6009 boolean mDrawPending;
6010
6011 // This is set after the window has finished drawing for the first
6012 // time but before its surface is shown. The surface will be
6013 // displayed when the next layout is run.
6014 boolean mCommitDrawPending;
6015
6016 // This is set during the time after the window's drawing has been
6017 // committed, and before its surface is actually shown. It is used
6018 // to delay showing the surface until all windows in a token are ready
6019 // to be shown.
6020 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006022 // Set when the window has been shown in the screen the first time.
6023 boolean mHasDrawn;
6024
6025 // Currently running an exit animation?
6026 boolean mExiting;
6027
6028 // Currently on the mDestroySurface list?
6029 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006031 // Completely remove from window manager after exit animation?
6032 boolean mRemoveOnExit;
6033
6034 // Set when the orientation is changing and this window has not yet
6035 // been updated for the new orientation.
6036 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006038 // Is this window now (or just being) removed?
6039 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006040
Dianne Hackborn16064f92010-03-25 00:47:24 -07006041 // For debugging, this is the last information given to the surface flinger.
6042 boolean mSurfaceShown;
6043 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6044 int mSurfaceLayer;
6045 float mSurfaceAlpha;
6046
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006047 // Input channel
6048 InputChannel mInputChannel;
6049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006050 WindowState(Session s, IWindow c, WindowToken token,
6051 WindowState attachedWindow, WindowManager.LayoutParams a,
6052 int viewVisibility) {
6053 mSession = s;
6054 mClient = c;
6055 mToken = token;
6056 mAttrs.copyFrom(a);
6057 mViewVisibility = viewVisibility;
6058 DeathRecipient deathRecipient = new DeathRecipient();
6059 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006060 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006061 TAG, "Window " + this + " client=" + c.asBinder()
6062 + " token=" + token + " (" + mAttrs.token + ")");
6063 try {
6064 c.asBinder().linkToDeath(deathRecipient, 0);
6065 } catch (RemoteException e) {
6066 mDeathRecipient = null;
6067 mAttachedWindow = null;
6068 mLayoutAttached = false;
6069 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006070 mIsWallpaper = false;
6071 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 mBaseLayer = 0;
6073 mSubLayer = 0;
6074 return;
6075 }
6076 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006078 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6079 mAttrs.type <= LAST_SUB_WINDOW)) {
6080 // The multiplier here is to reserve space for multiple
6081 // windows in the same type layer.
6082 mBaseLayer = mPolicy.windowTypeToLayerLw(
6083 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6084 + TYPE_LAYER_OFFSET;
6085 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6086 mAttachedWindow = attachedWindow;
6087 mAttachedWindow.mChildWindows.add(this);
6088 mLayoutAttached = mAttrs.type !=
6089 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6090 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6091 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006092 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6093 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006094 } else {
6095 // The multiplier here is to reserve space for multiple
6096 // windows in the same type layer.
6097 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6098 * TYPE_LAYER_MULTIPLIER
6099 + TYPE_LAYER_OFFSET;
6100 mSubLayer = 0;
6101 mAttachedWindow = null;
6102 mLayoutAttached = false;
6103 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6104 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006105 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6106 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006107 }
6108
6109 WindowState appWin = this;
6110 while (appWin.mAttachedWindow != null) {
6111 appWin = mAttachedWindow;
6112 }
6113 WindowToken appToken = appWin.mToken;
6114 while (appToken.appWindowToken == null) {
6115 WindowToken parent = mTokenMap.get(appToken.token);
6116 if (parent == null || appToken == parent) {
6117 break;
6118 }
6119 appToken = parent;
6120 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006121 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 mAppToken = appToken.appWindowToken;
6123
6124 mSurface = null;
6125 mRequestedWidth = 0;
6126 mRequestedHeight = 0;
6127 mLastRequestedWidth = 0;
6128 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006129 mXOffset = 0;
6130 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006131 mLayer = 0;
6132 mAnimLayer = 0;
6133 mLastLayer = 0;
6134 }
6135
6136 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006137 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 TAG, "Attaching " + this + " token=" + mToken
6139 + ", list=" + mToken.windows);
6140 mSession.windowAddedLocked();
6141 }
6142
6143 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6144 mHaveFrame = true;
6145
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006146 final Rect container = mContainingFrame;
6147 container.set(pf);
6148
6149 final Rect display = mDisplayFrame;
6150 display.set(df);
6151
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006152 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006153 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006154 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6155 display.intersect(mCompatibleScreenFrame);
6156 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006157 }
6158
6159 final int pw = container.right - container.left;
6160 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006161
6162 int w,h;
6163 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6164 w = mAttrs.width < 0 ? pw : mAttrs.width;
6165 h = mAttrs.height< 0 ? ph : mAttrs.height;
6166 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006167 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6168 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006169 }
Romain Guy06882f82009-06-10 13:36:04 -07006170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006171 final Rect content = mContentFrame;
6172 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006174 final Rect visible = mVisibleFrame;
6175 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006177 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006178 final int fw = frame.width();
6179 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006181 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6182 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6183
6184 Gravity.apply(mAttrs.gravity, w, h, container,
6185 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6186 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6187
6188 //System.out.println("Out: " + mFrame);
6189
6190 // Now make sure the window fits in the overall display.
6191 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 // Make sure the content and visible frames are inside of the
6194 // final window frame.
6195 if (content.left < frame.left) content.left = frame.left;
6196 if (content.top < frame.top) content.top = frame.top;
6197 if (content.right > frame.right) content.right = frame.right;
6198 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6199 if (visible.left < frame.left) visible.left = frame.left;
6200 if (visible.top < frame.top) visible.top = frame.top;
6201 if (visible.right > frame.right) visible.right = frame.right;
6202 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 final Rect contentInsets = mContentInsets;
6205 contentInsets.left = content.left-frame.left;
6206 contentInsets.top = content.top-frame.top;
6207 contentInsets.right = frame.right-content.right;
6208 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006210 final Rect visibleInsets = mVisibleInsets;
6211 visibleInsets.left = visible.left-frame.left;
6212 visibleInsets.top = visible.top-frame.top;
6213 visibleInsets.right = frame.right-visible.right;
6214 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006215
Dianne Hackborn284ac932009-08-28 10:34:25 -07006216 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6217 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006218 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006219 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006221 if (localLOGV) {
6222 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6223 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006224 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006225 + mRequestedWidth + ", mRequestedheight="
6226 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6227 + "): frame=" + mFrame.toShortString()
6228 + " ci=" + contentInsets.toShortString()
6229 + " vi=" + visibleInsets.toShortString());
6230 //}
6231 }
6232 }
Romain Guy06882f82009-06-10 13:36:04 -07006233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006234 public Rect getFrameLw() {
6235 return mFrame;
6236 }
6237
6238 public Rect getShownFrameLw() {
6239 return mShownFrame;
6240 }
6241
6242 public Rect getDisplayFrameLw() {
6243 return mDisplayFrame;
6244 }
6245
6246 public Rect getContentFrameLw() {
6247 return mContentFrame;
6248 }
6249
6250 public Rect getVisibleFrameLw() {
6251 return mVisibleFrame;
6252 }
6253
6254 public boolean getGivenInsetsPendingLw() {
6255 return mGivenInsetsPending;
6256 }
6257
6258 public Rect getGivenContentInsetsLw() {
6259 return mGivenContentInsets;
6260 }
Romain Guy06882f82009-06-10 13:36:04 -07006261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006262 public Rect getGivenVisibleInsetsLw() {
6263 return mGivenVisibleInsets;
6264 }
Romain Guy06882f82009-06-10 13:36:04 -07006265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006266 public WindowManager.LayoutParams getAttrs() {
6267 return mAttrs;
6268 }
6269
6270 public int getSurfaceLayer() {
6271 return mLayer;
6272 }
Romain Guy06882f82009-06-10 13:36:04 -07006273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006274 public IApplicationToken getAppToken() {
6275 return mAppToken != null ? mAppToken.appToken : null;
6276 }
Jeff Brown349703e2010-06-22 01:27:15 -07006277
6278 public long getInputDispatchingTimeoutNanos() {
6279 return mAppToken != null
6280 ? mAppToken.inputDispatchingTimeoutNanos
6281 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6282 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006283
6284 public boolean hasAppShownWindows() {
6285 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6286 }
6287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006288 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006289 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006290 TAG, "Setting animation in " + this + ": " + anim);
6291 mAnimating = false;
6292 mLocalAnimating = false;
6293 mAnimation = anim;
6294 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6295 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6296 }
6297
6298 public void clearAnimation() {
6299 if (mAnimation != null) {
6300 mAnimating = true;
6301 mLocalAnimating = false;
6302 mAnimation = null;
6303 }
6304 }
Romain Guy06882f82009-06-10 13:36:04 -07006305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 Surface createSurfaceLocked() {
6307 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006308 mReportDestroySurface = false;
6309 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006310 mDrawPending = true;
6311 mCommitDrawPending = false;
6312 mReadyToShow = false;
6313 if (mAppToken != null) {
6314 mAppToken.allDrawn = false;
6315 }
6316
6317 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006318 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006319 flags |= Surface.PUSH_BUFFERS;
6320 }
6321
6322 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6323 flags |= Surface.SECURE;
6324 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006325 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006326 TAG, "Creating surface in session "
6327 + mSession.mSurfaceSession + " window " + this
6328 + " w=" + mFrame.width()
6329 + " h=" + mFrame.height() + " format="
6330 + mAttrs.format + " flags=" + flags);
6331
6332 int w = mFrame.width();
6333 int h = mFrame.height();
6334 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6335 // for a scaled surface, we always want the requested
6336 // size.
6337 w = mRequestedWidth;
6338 h = mRequestedHeight;
6339 }
6340
Romain Guy9825ec62009-10-01 00:58:09 -07006341 // Something is wrong and SurfaceFlinger will not like this,
6342 // try to revert to sane values
6343 if (w <= 0) w = 1;
6344 if (h <= 0) h = 1;
6345
Dianne Hackborn16064f92010-03-25 00:47:24 -07006346 mSurfaceShown = false;
6347 mSurfaceLayer = 0;
6348 mSurfaceAlpha = 1;
6349 mSurfaceX = 0;
6350 mSurfaceY = 0;
6351 mSurfaceW = w;
6352 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006353 try {
6354 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006355 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006356 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006357 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006358 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006359 + mSurface + " IN SESSION "
6360 + mSession.mSurfaceSession
6361 + ": pid=" + mSession.mPid + " format="
6362 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006363 + Integer.toHexString(flags)
6364 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006366 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 reclaimSomeSurfaceMemoryLocked(this, "create");
6368 return null;
6369 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006370 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006371 return null;
6372 }
Romain Guy06882f82009-06-10 13:36:04 -07006373
Joe Onorato8a9b2202010-02-26 18:56:32 -08006374 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 TAG, "Got surface: " + mSurface
6376 + ", set left=" + mFrame.left + " top=" + mFrame.top
6377 + ", animLayer=" + mAnimLayer);
6378 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006379 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006380 if (SHOW_TRANSACTIONS) logSurface(this,
6381 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6382 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6383 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006384 }
6385 Surface.openTransaction();
6386 try {
6387 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006388 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006389 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006390 mSurface.setPosition(mSurfaceX, mSurfaceY);
6391 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006392 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006393 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006394 mSurface.hide();
6395 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006396 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 mSurface.setFlags(Surface.SURFACE_DITHER,
6398 Surface.SURFACE_DITHER);
6399 }
6400 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006401 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006402 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6403 }
6404 mLastHidden = true;
6405 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006406 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006407 Surface.closeTransaction();
6408 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006409 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 TAG, "Created surface " + this);
6411 }
6412 return mSurface;
6413 }
Romain Guy06882f82009-06-10 13:36:04 -07006414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006416 if (mAppToken != null && this == mAppToken.startingWindow) {
6417 mAppToken.startingDisplayed = false;
6418 }
Romain Guy06882f82009-06-10 13:36:04 -07006419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006420 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006421 mDrawPending = false;
6422 mCommitDrawPending = false;
6423 mReadyToShow = false;
6424
6425 int i = mChildWindows.size();
6426 while (i > 0) {
6427 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006428 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006429 c.mAttachedHidden = true;
6430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006431
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006432 if (mReportDestroySurface) {
6433 mReportDestroySurface = false;
6434 mSurfacePendingDestroy = true;
6435 try {
6436 mClient.dispatchGetNewSurface();
6437 // We'll really destroy on the next time around.
6438 return;
6439 } catch (RemoteException e) {
6440 }
6441 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006443 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006444 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006445 RuntimeException e = null;
6446 if (!HIDE_STACK_CRAWLS) {
6447 e = new RuntimeException();
6448 e.fillInStackTrace();
6449 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006450 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006451 + mSurface + ", session " + mSession, e);
6452 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006453 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006454 RuntimeException e = null;
6455 if (!HIDE_STACK_CRAWLS) {
6456 e = new RuntimeException();
6457 e.fillInStackTrace();
6458 }
6459 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006460 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006461 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006462 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006463 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006464 + " surface " + mSurface + " session " + mSession
6465 + ": " + e.toString());
6466 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006467
Dianne Hackborn16064f92010-03-25 00:47:24 -07006468 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006469 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 }
6471 }
6472
6473 boolean finishDrawingLocked() {
6474 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006475 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006476 TAG, "finishDrawingLocked: " + mSurface);
6477 mCommitDrawPending = true;
6478 mDrawPending = false;
6479 return true;
6480 }
6481 return false;
6482 }
6483
6484 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006485 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006486 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006487 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006488 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006489 }
6490 mCommitDrawPending = false;
6491 mReadyToShow = true;
6492 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6493 final AppWindowToken atoken = mAppToken;
6494 if (atoken == null || atoken.allDrawn || starting) {
6495 performShowLocked();
6496 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006497 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 }
6499
6500 // This must be called while inside a transaction.
6501 boolean performShowLocked() {
6502 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006503 RuntimeException e = null;
6504 if (!HIDE_STACK_CRAWLS) {
6505 e = new RuntimeException();
6506 e.fillInStackTrace();
6507 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006508 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006509 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6510 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6511 }
6512 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006513 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6514 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006515 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006516 + " during animation: policyVis=" + mPolicyVisibility
6517 + " attHidden=" + mAttachedHidden
6518 + " tok.hiddenRequested="
6519 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006520 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006521 + (mAppToken != null ? mAppToken.hidden : false)
6522 + " animating=" + mAnimating
6523 + " tok animating="
6524 + (mAppToken != null ? mAppToken.animating : false));
6525 if (!showSurfaceRobustlyLocked(this)) {
6526 return false;
6527 }
6528 mLastAlpha = -1;
6529 mHasDrawn = true;
6530 mLastHidden = false;
6531 mReadyToShow = false;
6532 enableScreenIfNeededLocked();
6533
6534 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006536 int i = mChildWindows.size();
6537 while (i > 0) {
6538 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006539 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006540 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006541 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006542 if (c.mSurface != null) {
6543 c.performShowLocked();
6544 // It hadn't been shown, which means layout not
6545 // performed on it, so now we want to make sure to
6546 // do a layout. If called from within the transaction
6547 // loop, this will cause it to restart with a new
6548 // layout.
6549 mLayoutNeeded = true;
6550 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006551 }
6552 }
Romain Guy06882f82009-06-10 13:36:04 -07006553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006554 if (mAttrs.type != TYPE_APPLICATION_STARTING
6555 && mAppToken != null) {
6556 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006557
Dianne Hackborn248b1882009-09-16 16:46:44 -07006558 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006559 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006560 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006561 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006562 // If this initial window is animating, stop it -- we
6563 // will do an animation to reveal it from behind the
6564 // starting window, so there is no need for it to also
6565 // be doing its own stuff.
6566 if (mAnimation != null) {
6567 mAnimation = null;
6568 // Make sure we clean up the animation.
6569 mAnimating = true;
6570 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006571 mFinishedStarting.add(mAppToken);
6572 mH.sendEmptyMessage(H.FINISHED_STARTING);
6573 }
6574 mAppToken.updateReportedVisibilityLocked();
6575 }
6576 }
6577 return true;
6578 }
Romain Guy06882f82009-06-10 13:36:04 -07006579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580 // This must be called while inside a transaction. Returns true if
6581 // there is more animation to run.
6582 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006583 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006584 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006586 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6587 mHasTransformation = true;
6588 mHasLocalTransformation = true;
6589 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006590 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006591 TAG, "Starting animation in " + this +
6592 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6593 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6594 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6595 mAnimation.setStartTime(currentTime);
6596 mLocalAnimating = true;
6597 mAnimating = true;
6598 }
6599 mTransformation.clear();
6600 final boolean more = mAnimation.getTransformation(
6601 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006602 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 TAG, "Stepped animation in " + this +
6604 ": more=" + more + ", xform=" + mTransformation);
6605 if (more) {
6606 // we're not done!
6607 return true;
6608 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006609 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006610 TAG, "Finished animation in " + this +
6611 " @ " + currentTime);
6612 mAnimation = null;
6613 //WindowManagerService.this.dump();
6614 }
6615 mHasLocalTransformation = false;
6616 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006617 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006618 // When our app token is animating, we kind-of pretend like
6619 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6620 // part of this check means that we will only do this if
6621 // our window is not currently exiting, or it is not
6622 // locally animating itself. The idea being that one that
6623 // is exiting and doing a local animation should be removed
6624 // once that animation is done.
6625 mAnimating = true;
6626 mHasTransformation = true;
6627 mTransformation.clear();
6628 return false;
6629 } else if (mHasTransformation) {
6630 // Little trick to get through the path below to act like
6631 // we have finished an animation.
6632 mAnimating = true;
6633 } else if (isAnimating()) {
6634 mAnimating = true;
6635 }
6636 } else if (mAnimation != null) {
6637 // If the display is frozen, and there is a pending animation,
6638 // clear it and make sure we run the cleanup code.
6639 mAnimating = true;
6640 mLocalAnimating = true;
6641 mAnimation = null;
6642 }
Romain Guy06882f82009-06-10 13:36:04 -07006643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006644 if (!mAnimating && !mLocalAnimating) {
6645 return false;
6646 }
6647
Joe Onorato8a9b2202010-02-26 18:56:32 -08006648 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006649 TAG, "Animation done in " + this + ": exiting=" + mExiting
6650 + ", reportedVisible="
6651 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006653 mAnimating = false;
6654 mLocalAnimating = false;
6655 mAnimation = null;
6656 mAnimLayer = mLayer;
6657 if (mIsImWindow) {
6658 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006659 } else if (mIsWallpaper) {
6660 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006661 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006662 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006663 + " anim layer: " + mAnimLayer);
6664 mHasTransformation = false;
6665 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006666 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6667 if (DEBUG_VISIBILITY) {
6668 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6669 + mPolicyVisibilityAfterAnim);
6670 }
6671 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6672 if (!mPolicyVisibility) {
6673 if (mCurrentFocus == this) {
6674 mFocusMayChange = true;
6675 }
6676 // Window is no longer visible -- make sure if we were waiting
6677 // for it to be displayed before enabling the display, that
6678 // we allow the display to be enabled now.
6679 enableScreenIfNeededLocked();
6680 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006681 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006682 mTransformation.clear();
6683 if (mHasDrawn
6684 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6685 && mAppToken != null
6686 && mAppToken.firstWindowDrawn
6687 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006688 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006689 + mToken + ": first real window done animating");
6690 mFinishedStarting.add(mAppToken);
6691 mH.sendEmptyMessage(H.FINISHED_STARTING);
6692 }
Romain Guy06882f82009-06-10 13:36:04 -07006693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006694 finishExit();
6695
6696 if (mAppToken != null) {
6697 mAppToken.updateReportedVisibilityLocked();
6698 }
6699
6700 return false;
6701 }
6702
6703 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006704 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006705 TAG, "finishExit in " + this
6706 + ": exiting=" + mExiting
6707 + " remove=" + mRemoveOnExit
6708 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006710 final int N = mChildWindows.size();
6711 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006712 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006713 }
Romain Guy06882f82009-06-10 13:36:04 -07006714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 if (!mExiting) {
6716 return;
6717 }
Romain Guy06882f82009-06-10 13:36:04 -07006718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006719 if (isWindowAnimating()) {
6720 return;
6721 }
6722
Joe Onorato8a9b2202010-02-26 18:56:32 -08006723 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006724 TAG, "Exit animation finished in " + this
6725 + ": remove=" + mRemoveOnExit);
6726 if (mSurface != null) {
6727 mDestroySurface.add(this);
6728 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006729 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006730 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 try {
6732 mSurface.hide();
6733 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006734 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 }
6736 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 }
6738 mExiting = false;
6739 if (mRemoveOnExit) {
6740 mPendingRemove.add(this);
6741 mRemoveOnExit = false;
6742 }
6743 }
Romain Guy06882f82009-06-10 13:36:04 -07006744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006745 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6746 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6747 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6748 if (dtdx < -.000001f || dtdx > .000001f) return false;
6749 if (dsdy < -.000001f || dsdy > .000001f) return false;
6750 return true;
6751 }
Romain Guy06882f82009-06-10 13:36:04 -07006752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 void computeShownFrameLocked() {
6754 final boolean selfTransformation = mHasLocalTransformation;
6755 Transformation attachedTransformation =
6756 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6757 ? mAttachedWindow.mTransformation : null;
6758 Transformation appTransformation =
6759 (mAppToken != null && mAppToken.hasTransformation)
6760 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006761
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006762 // Wallpapers are animated based on the "real" window they
6763 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006764 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006765 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006766 if (mWallpaperTarget.mHasLocalTransformation &&
6767 mWallpaperTarget.mAnimation != null &&
6768 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006769 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006770 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006771 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006772 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006773 }
6774 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006775 mWallpaperTarget.mAppToken.hasTransformation &&
6776 mWallpaperTarget.mAppToken.animation != null &&
6777 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006778 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006779 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006780 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006781 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006782 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006783 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006784
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006785 if (selfTransformation || attachedTransformation != null
6786 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006787 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006788 final Rect frame = mFrame;
6789 final float tmpFloats[] = mTmpFloats;
6790 final Matrix tmpMatrix = mTmpMatrix;
6791
6792 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006793 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006794 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006795 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006796 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006797 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006798 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006799 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 }
6801 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006802 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006803 }
6804
6805 // "convert" it into SurfaceFlinger's format
6806 // (a 2x2 matrix + an offset)
6807 // Here we must not transform the position of the surface
6808 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006809 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006811 tmpMatrix.getValues(tmpFloats);
6812 mDsDx = tmpFloats[Matrix.MSCALE_X];
6813 mDtDx = tmpFloats[Matrix.MSKEW_X];
6814 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6815 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006816 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6817 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 int w = frame.width();
6819 int h = frame.height();
6820 mShownFrame.set(x, y, x+w, y+h);
6821
6822 // Now set the alpha... but because our current hardware
6823 // can't do alpha transformation on a non-opaque surface,
6824 // turn it off if we are running an animation that is also
6825 // transforming since it is more important to have that
6826 // animation be smooth.
6827 mShownAlpha = mAlpha;
6828 if (!mLimitedAlphaCompositing
6829 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6830 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6831 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006832 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006833 if (selfTransformation) {
6834 mShownAlpha *= mTransformation.getAlpha();
6835 }
6836 if (attachedTransformation != null) {
6837 mShownAlpha *= attachedTransformation.getAlpha();
6838 }
6839 if (appTransformation != null) {
6840 mShownAlpha *= appTransformation.getAlpha();
6841 }
6842 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006843 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006844 }
Romain Guy06882f82009-06-10 13:36:04 -07006845
Joe Onorato8a9b2202010-02-26 18:56:32 -08006846 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847 TAG, "Continuing animation in " + this +
6848 ": " + mShownFrame +
6849 ", alpha=" + mTransformation.getAlpha());
6850 return;
6851 }
Romain Guy06882f82009-06-10 13:36:04 -07006852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006853 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006854 if (mXOffset != 0 || mYOffset != 0) {
6855 mShownFrame.offset(mXOffset, mYOffset);
6856 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006857 mShownAlpha = mAlpha;
6858 mDsDx = 1;
6859 mDtDx = 0;
6860 mDsDy = 0;
6861 mDtDy = 1;
6862 }
Romain Guy06882f82009-06-10 13:36:04 -07006863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006864 /**
6865 * Is this window visible? It is not visible if there is no
6866 * surface, or we are in the process of running an exit animation
6867 * that will remove the surface, or its app token has been hidden.
6868 */
6869 public boolean isVisibleLw() {
6870 final AppWindowToken atoken = mAppToken;
6871 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6872 && (atoken == null || !atoken.hiddenRequested)
6873 && !mExiting && !mDestroying;
6874 }
6875
6876 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006877 * Like {@link #isVisibleLw}, but also counts a window that is currently
6878 * "hidden" behind the keyguard as visible. This allows us to apply
6879 * things like window flags that impact the keyguard.
6880 * XXX I am starting to think we need to have ANOTHER visibility flag
6881 * for this "hidden behind keyguard" state rather than overloading
6882 * mPolicyVisibility. Ungh.
6883 */
6884 public boolean isVisibleOrBehindKeyguardLw() {
6885 final AppWindowToken atoken = mAppToken;
6886 return mSurface != null && !mAttachedHidden
6887 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006888 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006889 && !mExiting && !mDestroying;
6890 }
6891
6892 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006893 * Is this window visible, ignoring its app token? It is not visible
6894 * if there is no surface, or we are in the process of running an exit animation
6895 * that will remove the surface.
6896 */
6897 public boolean isWinVisibleLw() {
6898 final AppWindowToken atoken = mAppToken;
6899 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6900 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6901 && !mExiting && !mDestroying;
6902 }
6903
6904 /**
6905 * The same as isVisible(), but follows the current hidden state of
6906 * the associated app token, not the pending requested hidden state.
6907 */
6908 boolean isVisibleNow() {
6909 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006910 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006911 }
6912
6913 /**
6914 * Same as isVisible(), but we also count it as visible between the
6915 * call to IWindowSession.add() and the first relayout().
6916 */
6917 boolean isVisibleOrAdding() {
6918 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006919 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006920 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6921 && mPolicyVisibility && !mAttachedHidden
6922 && (atoken == null || !atoken.hiddenRequested)
6923 && !mExiting && !mDestroying;
6924 }
6925
6926 /**
6927 * Is this window currently on-screen? It is on-screen either if it
6928 * is visible or it is currently running an animation before no longer
6929 * being visible.
6930 */
6931 boolean isOnScreen() {
6932 final AppWindowToken atoken = mAppToken;
6933 if (atoken != null) {
6934 return mSurface != null && mPolicyVisibility && !mDestroying
6935 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006936 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006937 } else {
6938 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006939 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006940 }
6941 }
Romain Guy06882f82009-06-10 13:36:04 -07006942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006943 /**
6944 * Like isOnScreen(), but we don't return true if the window is part
6945 * of a transition that has not yet been started.
6946 */
6947 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006948 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006949 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006950 return false;
6951 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006952 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006953 final boolean animating = atoken != null
6954 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006955 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006956 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6957 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006958 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 }
6960
6961 /** Is the window or its container currently animating? */
6962 boolean isAnimating() {
6963 final WindowState attached = mAttachedWindow;
6964 final AppWindowToken atoken = mAppToken;
6965 return mAnimation != null
6966 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006967 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 (atoken.animation != null
6969 || atoken.inPendingTransaction));
6970 }
6971
6972 /** Is this window currently animating? */
6973 boolean isWindowAnimating() {
6974 return mAnimation != null;
6975 }
6976
6977 /**
6978 * Like isOnScreen, but returns false if the surface hasn't yet
6979 * been drawn.
6980 */
6981 public boolean isDisplayedLw() {
6982 final AppWindowToken atoken = mAppToken;
6983 return mSurface != null && mPolicyVisibility && !mDestroying
6984 && !mDrawPending && !mCommitDrawPending
6985 && ((!mAttachedHidden &&
6986 (atoken == null || !atoken.hiddenRequested))
6987 || mAnimating);
6988 }
6989
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006990 /**
6991 * Returns true if the window has a surface that it has drawn a
6992 * complete UI in to.
6993 */
6994 public boolean isDrawnLw() {
6995 final AppWindowToken atoken = mAppToken;
6996 return mSurface != null && !mDestroying
6997 && !mDrawPending && !mCommitDrawPending;
6998 }
6999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007000 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7001 boolean shownFrame, boolean onlyOpaque) {
7002 if (mSurface == null) {
7003 return false;
7004 }
7005 if (mAppToken != null && !mAppToken.appFullscreen) {
7006 return false;
7007 }
7008 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7009 return false;
7010 }
7011 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007012
7013 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7014 return frame.left <= mCompatibleScreenFrame.left &&
7015 frame.top <= mCompatibleScreenFrame.top &&
7016 frame.right >= mCompatibleScreenFrame.right &&
7017 frame.bottom >= mCompatibleScreenFrame.bottom;
7018 } else {
7019 return frame.left <= 0 && frame.top <= 0
7020 && frame.right >= screenWidth
7021 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007023 }
Romain Guy06882f82009-06-10 13:36:04 -07007024
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007025 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007026 * Return true if the window is opaque and fully drawn. This indicates
7027 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007028 */
7029 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007030 return (mAttrs.format == PixelFormat.OPAQUE
7031 || mAttrs.type == TYPE_WALLPAPER)
7032 && mSurface != null && mAnimation == null
7033 && (mAppToken == null || mAppToken.animation == null)
7034 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007035 }
7036
7037 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7038 return
7039 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007040 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7041 // only if it's visible
7042 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007043 // and only if the application fills the compatible screen
7044 mFrame.left <= mCompatibleScreenFrame.left &&
7045 mFrame.top <= mCompatibleScreenFrame.top &&
7046 mFrame.right >= mCompatibleScreenFrame.right &&
7047 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007048 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007049 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007050 }
7051
7052 boolean isFullscreen(int screenWidth, int screenHeight) {
7053 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007054 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007055 }
7056
7057 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007058 disposeInputChannel();
7059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007060 if (mAttachedWindow != null) {
7061 mAttachedWindow.mChildWindows.remove(this);
7062 }
7063 destroySurfaceLocked();
7064 mSession.windowRemovedLocked();
7065 try {
7066 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7067 } catch (RuntimeException e) {
7068 // Ignore if it has already been removed (usually because
7069 // we are doing this as part of processing a death note.)
7070 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007071 }
7072
7073 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007074 if (mInputChannel != null) {
7075 mInputManager.unregisterInputChannel(mInputChannel);
7076
7077 mInputChannel.dispose();
7078 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007079 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007080 }
7081
7082 private class DeathRecipient implements IBinder.DeathRecipient {
7083 public void binderDied() {
7084 try {
7085 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007086 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007087 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007088 if (win != null) {
7089 removeWindowLocked(mSession, win);
7090 }
7091 }
7092 } catch (IllegalArgumentException ex) {
7093 // This will happen if the window has already been
7094 // removed.
7095 }
7096 }
7097 }
7098
7099 /** Returns true if this window desires key events. */
7100 public final boolean canReceiveKeys() {
7101 return isVisibleOrAdding()
7102 && (mViewVisibility == View.VISIBLE)
7103 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7104 }
7105
7106 public boolean hasDrawnLw() {
7107 return mHasDrawn;
7108 }
7109
7110 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007111 return showLw(doAnimation, true);
7112 }
7113
7114 boolean showLw(boolean doAnimation, boolean requestAnim) {
7115 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7116 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007117 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007118 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007119 if (doAnimation) {
7120 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7121 + mPolicyVisibility + " mAnimation=" + mAnimation);
7122 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7123 doAnimation = false;
7124 } else if (mPolicyVisibility && mAnimation == null) {
7125 // Check for the case where we are currently visible and
7126 // not animating; we do not want to do animation at such a
7127 // point to become visible when we already are.
7128 doAnimation = false;
7129 }
7130 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007131 mPolicyVisibility = true;
7132 mPolicyVisibilityAfterAnim = true;
7133 if (doAnimation) {
7134 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7135 }
7136 if (requestAnim) {
7137 requestAnimationLocked(0);
7138 }
7139 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007140 }
7141
7142 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007143 return hideLw(doAnimation, true);
7144 }
7145
7146 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007147 if (doAnimation) {
7148 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7149 doAnimation = false;
7150 }
7151 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7153 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007154 if (!current) {
7155 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007156 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007157 if (doAnimation) {
7158 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7159 if (mAnimation == null) {
7160 doAnimation = false;
7161 }
7162 }
7163 if (doAnimation) {
7164 mPolicyVisibilityAfterAnim = false;
7165 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007166 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007167 mPolicyVisibilityAfterAnim = false;
7168 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007169 // Window is no longer visible -- make sure if we were waiting
7170 // for it to be displayed before enabling the display, that
7171 // we allow the display to be enabled now.
7172 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007173 if (mCurrentFocus == this) {
7174 mFocusMayChange = true;
7175 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007176 }
7177 if (requestAnim) {
7178 requestAnimationLocked(0);
7179 }
7180 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007181 }
7182
7183 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007184 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7185 pw.print(" mClient="); pw.println(mClient.asBinder());
7186 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7187 if (mAttachedWindow != null || mLayoutAttached) {
7188 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7189 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7190 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007191 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7192 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7193 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007194 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7195 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007196 }
7197 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7198 pw.print(" mSubLayer="); pw.print(mSubLayer);
7199 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7200 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7201 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7202 pw.print("="); pw.print(mAnimLayer);
7203 pw.print(" mLastLayer="); pw.println(mLastLayer);
7204 if (mSurface != null) {
7205 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007206 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7207 pw.print(" layer="); pw.print(mSurfaceLayer);
7208 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7209 pw.print(" rect=("); pw.print(mSurfaceX);
7210 pw.print(","); pw.print(mSurfaceY);
7211 pw.print(") "); pw.print(mSurfaceW);
7212 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007213 }
7214 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7215 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7216 if (mAppToken != null) {
7217 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7218 }
7219 if (mTargetAppToken != null) {
7220 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7221 }
7222 pw.print(prefix); pw.print("mViewVisibility=0x");
7223 pw.print(Integer.toHexString(mViewVisibility));
7224 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007225 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7226 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007227 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7228 pw.print(prefix); pw.print("mPolicyVisibility=");
7229 pw.print(mPolicyVisibility);
7230 pw.print(" mPolicyVisibilityAfterAnim=");
7231 pw.print(mPolicyVisibilityAfterAnim);
7232 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7233 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007234 if (!mRelayoutCalled) {
7235 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7236 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007237 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007238 pw.print(" h="); pw.print(mRequestedHeight);
7239 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007240 if (mXOffset != 0 || mYOffset != 0) {
7241 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7242 pw.print(" y="); pw.println(mYOffset);
7243 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007244 pw.print(prefix); pw.print("mGivenContentInsets=");
7245 mGivenContentInsets.printShortString(pw);
7246 pw.print(" mGivenVisibleInsets=");
7247 mGivenVisibleInsets.printShortString(pw);
7248 pw.println();
7249 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7250 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7251 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7252 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007253 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007254 pw.print(prefix); pw.print("mShownFrame=");
7255 mShownFrame.printShortString(pw);
7256 pw.print(" last="); mLastShownFrame.printShortString(pw);
7257 pw.println();
7258 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7259 pw.print(" last="); mLastFrame.printShortString(pw);
7260 pw.println();
7261 pw.print(prefix); pw.print("mContainingFrame=");
7262 mContainingFrame.printShortString(pw);
7263 pw.print(" mDisplayFrame=");
7264 mDisplayFrame.printShortString(pw);
7265 pw.println();
7266 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7267 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7268 pw.println();
7269 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7270 pw.print(" last="); mLastContentInsets.printShortString(pw);
7271 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7272 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7273 pw.println();
7274 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7275 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7276 pw.print(" mAlpha="); pw.print(mAlpha);
7277 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7278 }
7279 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7280 || mAnimation != null) {
7281 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7282 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7283 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7284 pw.print(" mAnimation="); pw.println(mAnimation);
7285 }
7286 if (mHasTransformation || mHasLocalTransformation) {
7287 pw.print(prefix); pw.print("XForm: has=");
7288 pw.print(mHasTransformation);
7289 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7290 pw.print(" "); mTransformation.printShortString(pw);
7291 pw.println();
7292 }
7293 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7294 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7295 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7296 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7297 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7298 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7299 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7300 pw.print(" mDestroying="); pw.print(mDestroying);
7301 pw.print(" mRemoved="); pw.println(mRemoved);
7302 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007303 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007304 pw.print(prefix); pw.print("mOrientationChanging=");
7305 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007306 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7307 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007308 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007309 if (mHScale != 1 || mVScale != 1) {
7310 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7311 pw.print(" mVScale="); pw.println(mVScale);
7312 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007313 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007314 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7315 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7316 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007317 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7318 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7319 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7320 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007321 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007322
7323 String makeInputChannelName() {
7324 return Integer.toHexString(System.identityHashCode(this))
7325 + " " + mAttrs.getTitle();
7326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007327
7328 @Override
7329 public String toString() {
7330 return "Window{"
7331 + Integer.toHexString(System.identityHashCode(this))
7332 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7333 }
7334 }
Romain Guy06882f82009-06-10 13:36:04 -07007335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007336 // -------------------------------------------------------------
7337 // Window Token State
7338 // -------------------------------------------------------------
7339
7340 class WindowToken {
7341 // The actual token.
7342 final IBinder token;
7343
7344 // The type of window this token is for, as per WindowManager.LayoutParams.
7345 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007347 // Set if this token was explicitly added by a client, so should
7348 // not be removed when all windows are removed.
7349 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007350
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007351 // For printing.
7352 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007354 // If this is an AppWindowToken, this is non-null.
7355 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007357 // All of the windows associated with this token.
7358 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7359
7360 // Is key dispatching paused for this token?
7361 boolean paused = false;
7362
7363 // Should this token's windows be hidden?
7364 boolean hidden;
7365
7366 // Temporary for finding which tokens no longer have visible windows.
7367 boolean hasVisible;
7368
Dianne Hackborna8f60182009-09-01 19:01:50 -07007369 // Set to true when this token is in a pending transaction where it
7370 // will be shown.
7371 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007372
Dianne Hackborna8f60182009-09-01 19:01:50 -07007373 // Set to true when this token is in a pending transaction where it
7374 // will be hidden.
7375 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007376
Dianne Hackborna8f60182009-09-01 19:01:50 -07007377 // Set to true when this token is in a pending transaction where its
7378 // windows will be put to the bottom of the list.
7379 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007380
Dianne Hackborna8f60182009-09-01 19:01:50 -07007381 // Set to true when this token is in a pending transaction where its
7382 // windows will be put to the top of the list.
7383 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007385 WindowToken(IBinder _token, int type, boolean _explicit) {
7386 token = _token;
7387 windowType = type;
7388 explicit = _explicit;
7389 }
7390
7391 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007392 pw.print(prefix); pw.print("token="); pw.println(token);
7393 pw.print(prefix); pw.print("windows="); pw.println(windows);
7394 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7395 pw.print(" hidden="); pw.print(hidden);
7396 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007397 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7398 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7399 pw.print(" waitingToHide="); pw.print(waitingToHide);
7400 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7401 pw.print(" sendingToTop="); pw.println(sendingToTop);
7402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007403 }
7404
7405 @Override
7406 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007407 if (stringName == null) {
7408 StringBuilder sb = new StringBuilder();
7409 sb.append("WindowToken{");
7410 sb.append(Integer.toHexString(System.identityHashCode(this)));
7411 sb.append(" token="); sb.append(token); sb.append('}');
7412 stringName = sb.toString();
7413 }
7414 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007415 }
7416 };
7417
7418 class AppWindowToken extends WindowToken {
7419 // Non-null only for application tokens.
7420 final IApplicationToken appToken;
7421
7422 // All of the windows and child windows that are included in this
7423 // application token. Note this list is NOT sorted!
7424 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7425
7426 int groupId = -1;
7427 boolean appFullscreen;
7428 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007429
7430 // The input dispatching timeout for this application token in nanoseconds.
7431 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 // These are used for determining when all windows associated with
7434 // an activity have been drawn, so they can be made visible together
7435 // at the same time.
7436 int lastTransactionSequence = mTransactionSequence-1;
7437 int numInterestingWindows;
7438 int numDrawnWindows;
7439 boolean inPendingTransaction;
7440 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 // Is this token going to be hidden in a little while? If so, it
7443 // won't be taken into account for setting the screen orientation.
7444 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007446 // Is this window's surface needed? This is almost like hidden, except
7447 // it will sometimes be true a little earlier: when the token has
7448 // been shown, but is still waiting for its app transition to execute
7449 // before making its windows shown.
7450 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007452 // Have we told the window clients to hide themselves?
7453 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 // Last visibility state we reported to the app token.
7456 boolean reportedVisible;
7457
7458 // Set to true when the token has been removed from the window mgr.
7459 boolean removed;
7460
7461 // Have we been asked to have this token keep the screen frozen?
7462 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 boolean animating;
7465 Animation animation;
7466 boolean hasTransformation;
7467 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 // Offset to the window of all layers in the token, for use by
7470 // AppWindowToken animations.
7471 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007473 // Information about an application starting window if displayed.
7474 StartingData startingData;
7475 WindowState startingWindow;
7476 View startingView;
7477 boolean startingDisplayed;
7478 boolean startingMoved;
7479 boolean firstWindowDrawn;
7480
7481 AppWindowToken(IApplicationToken _token) {
7482 super(_token.asBinder(),
7483 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7484 appWindowToken = this;
7485 appToken = _token;
7486 }
Romain Guy06882f82009-06-10 13:36:04 -07007487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007488 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007489 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007490 TAG, "Setting animation in " + this + ": " + anim);
7491 animation = anim;
7492 animating = false;
7493 anim.restrictDuration(MAX_ANIMATION_DURATION);
7494 anim.scaleCurrentDuration(mTransitionAnimationScale);
7495 int zorder = anim.getZAdjustment();
7496 int adj = 0;
7497 if (zorder == Animation.ZORDER_TOP) {
7498 adj = TYPE_LAYER_OFFSET;
7499 } else if (zorder == Animation.ZORDER_BOTTOM) {
7500 adj = -TYPE_LAYER_OFFSET;
7501 }
Romain Guy06882f82009-06-10 13:36:04 -07007502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007503 if (animLayerAdjustment != adj) {
7504 animLayerAdjustment = adj;
7505 updateLayers();
7506 }
7507 }
Romain Guy06882f82009-06-10 13:36:04 -07007508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007509 public void setDummyAnimation() {
7510 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007511 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 TAG, "Setting dummy animation in " + this);
7513 animation = sDummyAnimation;
7514 }
7515 }
7516
7517 public void clearAnimation() {
7518 if (animation != null) {
7519 animation = null;
7520 animating = true;
7521 }
7522 }
Romain Guy06882f82009-06-10 13:36:04 -07007523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007524 void updateLayers() {
7525 final int N = allAppWindows.size();
7526 final int adj = animLayerAdjustment;
7527 for (int i=0; i<N; i++) {
7528 WindowState w = allAppWindows.get(i);
7529 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007530 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 + w.mAnimLayer);
7532 if (w == mInputMethodTarget) {
7533 setInputMethodAnimLayerAdjustment(adj);
7534 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007535 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007536 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007538 }
7539 }
Romain Guy06882f82009-06-10 13:36:04 -07007540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007541 void sendAppVisibilityToClients() {
7542 final int N = allAppWindows.size();
7543 for (int i=0; i<N; i++) {
7544 WindowState win = allAppWindows.get(i);
7545 if (win == startingWindow && clientHidden) {
7546 // Don't hide the starting window.
7547 continue;
7548 }
7549 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007550 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007551 "Setting visibility of " + win + ": " + (!clientHidden));
7552 win.mClient.dispatchAppVisibility(!clientHidden);
7553 } catch (RemoteException e) {
7554 }
7555 }
7556 }
Romain Guy06882f82009-06-10 13:36:04 -07007557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007558 void showAllWindowsLocked() {
7559 final int NW = allAppWindows.size();
7560 for (int i=0; i<NW; i++) {
7561 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007562 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 "performing show on: " + w);
7564 w.performShowLocked();
7565 }
7566 }
Romain Guy06882f82009-06-10 13:36:04 -07007567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007568 // This must be called while inside a transaction.
7569 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007570 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007571 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 if (animation == sDummyAnimation) {
7574 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007575 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007576 // when it is really time to animate, this will be set to
7577 // a real animation and the next call will execute normally.
7578 return false;
7579 }
Romain Guy06882f82009-06-10 13:36:04 -07007580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007581 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7582 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007583 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007584 TAG, "Starting animation in " + this +
7585 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7586 + " scale=" + mTransitionAnimationScale
7587 + " allDrawn=" + allDrawn + " animating=" + animating);
7588 animation.initialize(dw, dh, dw, dh);
7589 animation.setStartTime(currentTime);
7590 animating = true;
7591 }
7592 transformation.clear();
7593 final boolean more = animation.getTransformation(
7594 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007595 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007596 TAG, "Stepped animation in " + this +
7597 ": more=" + more + ", xform=" + transformation);
7598 if (more) {
7599 // we're done!
7600 hasTransformation = true;
7601 return true;
7602 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007603 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007604 TAG, "Finished animation in " + this +
7605 " @ " + currentTime);
7606 animation = null;
7607 }
7608 } else if (animation != null) {
7609 // If the display is frozen, and there is a pending animation,
7610 // clear it and make sure we run the cleanup code.
7611 animating = true;
7612 animation = null;
7613 }
7614
7615 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 if (!animating) {
7618 return false;
7619 }
7620
7621 clearAnimation();
7622 animating = false;
7623 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7624 moveInputMethodWindowsIfNeededLocked(true);
7625 }
Romain Guy06882f82009-06-10 13:36:04 -07007626
Joe Onorato8a9b2202010-02-26 18:56:32 -08007627 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007628 TAG, "Animation done in " + this
7629 + ": reportedVisible=" + reportedVisible);
7630
7631 transformation.clear();
7632 if (animLayerAdjustment != 0) {
7633 animLayerAdjustment = 0;
7634 updateLayers();
7635 }
Romain Guy06882f82009-06-10 13:36:04 -07007636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007637 final int N = windows.size();
7638 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007639 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007640 }
7641 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007643 return false;
7644 }
7645
7646 void updateReportedVisibilityLocked() {
7647 if (appToken == null) {
7648 return;
7649 }
Romain Guy06882f82009-06-10 13:36:04 -07007650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007651 int numInteresting = 0;
7652 int numVisible = 0;
7653 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007654
Joe Onorato8a9b2202010-02-26 18:56:32 -08007655 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007656 final int N = allAppWindows.size();
7657 for (int i=0; i<N; i++) {
7658 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007659 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007660 || win.mViewVisibility != View.VISIBLE
7661 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007662 continue;
7663 }
7664 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007665 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007666 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007667 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007668 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007669 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007670 + " pv=" + win.mPolicyVisibility
7671 + " dp=" + win.mDrawPending
7672 + " cdp=" + win.mCommitDrawPending
7673 + " ah=" + win.mAttachedHidden
7674 + " th="
7675 + (win.mAppToken != null
7676 ? win.mAppToken.hiddenRequested : false)
7677 + " a=" + win.mAnimating);
7678 }
7679 }
7680 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007681 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007682 if (!win.isAnimating()) {
7683 numVisible++;
7684 }
7685 nowGone = false;
7686 } else if (win.isAnimating()) {
7687 nowGone = false;
7688 }
7689 }
Romain Guy06882f82009-06-10 13:36:04 -07007690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007691 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007692 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007693 + numInteresting + " visible=" + numVisible);
7694 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007695 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007696 TAG, "Visibility changed in " + this
7697 + ": vis=" + nowVisible);
7698 reportedVisible = nowVisible;
7699 Message m = mH.obtainMessage(
7700 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7701 nowVisible ? 1 : 0,
7702 nowGone ? 1 : 0,
7703 this);
7704 mH.sendMessage(m);
7705 }
7706 }
Romain Guy06882f82009-06-10 13:36:04 -07007707
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007708 WindowState findMainWindow() {
7709 int j = windows.size();
7710 while (j > 0) {
7711 j--;
7712 WindowState win = windows.get(j);
7713 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7714 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7715 return win;
7716 }
7717 }
7718 return null;
7719 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007721 void dump(PrintWriter pw, String prefix) {
7722 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007723 if (appToken != null) {
7724 pw.print(prefix); pw.println("app=true");
7725 }
7726 if (allAppWindows.size() > 0) {
7727 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7728 }
7729 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007730 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007731 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7732 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7733 pw.print(" clientHidden="); pw.print(clientHidden);
7734 pw.print(" willBeHidden="); pw.print(willBeHidden);
7735 pw.print(" reportedVisible="); pw.println(reportedVisible);
7736 if (paused || freezingScreen) {
7737 pw.print(prefix); pw.print("paused="); pw.print(paused);
7738 pw.print(" freezingScreen="); pw.println(freezingScreen);
7739 }
7740 if (numInterestingWindows != 0 || numDrawnWindows != 0
7741 || inPendingTransaction || allDrawn) {
7742 pw.print(prefix); pw.print("numInterestingWindows=");
7743 pw.print(numInterestingWindows);
7744 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7745 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7746 pw.print(" allDrawn="); pw.println(allDrawn);
7747 }
7748 if (animating || animation != null) {
7749 pw.print(prefix); pw.print("animating="); pw.print(animating);
7750 pw.print(" animation="); pw.println(animation);
7751 }
7752 if (animLayerAdjustment != 0) {
7753 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7754 }
7755 if (hasTransformation) {
7756 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7757 pw.print(" transformation="); transformation.printShortString(pw);
7758 pw.println();
7759 }
7760 if (startingData != null || removed || firstWindowDrawn) {
7761 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7762 pw.print(" removed="); pw.print(removed);
7763 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7764 }
7765 if (startingWindow != null || startingView != null
7766 || startingDisplayed || startingMoved) {
7767 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7768 pw.print(" startingView="); pw.print(startingView);
7769 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7770 pw.print(" startingMoved"); pw.println(startingMoved);
7771 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007772 }
7773
7774 @Override
7775 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007776 if (stringName == null) {
7777 StringBuilder sb = new StringBuilder();
7778 sb.append("AppWindowToken{");
7779 sb.append(Integer.toHexString(System.identityHashCode(this)));
7780 sb.append(" token="); sb.append(token); sb.append('}');
7781 stringName = sb.toString();
7782 }
7783 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007784 }
7785 }
Romain Guy06882f82009-06-10 13:36:04 -07007786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007787 // -------------------------------------------------------------
7788 // DummyAnimation
7789 // -------------------------------------------------------------
7790
7791 // This is an animation that does nothing: it just immediately finishes
7792 // itself every time it is called. It is used as a stub animation in cases
7793 // where we want to synchronize multiple things that may be animating.
7794 static final class DummyAnimation extends Animation {
7795 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7796 return false;
7797 }
7798 }
7799 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007801 // -------------------------------------------------------------
7802 // Async Handler
7803 // -------------------------------------------------------------
7804
7805 static final class StartingData {
7806 final String pkg;
7807 final int theme;
7808 final CharSequence nonLocalizedLabel;
7809 final int labelRes;
7810 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007812 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7813 int _labelRes, int _icon) {
7814 pkg = _pkg;
7815 theme = _theme;
7816 nonLocalizedLabel = _nonLocalizedLabel;
7817 labelRes = _labelRes;
7818 icon = _icon;
7819 }
7820 }
7821
7822 private final class H extends Handler {
7823 public static final int REPORT_FOCUS_CHANGE = 2;
7824 public static final int REPORT_LOSING_FOCUS = 3;
7825 public static final int ANIMATE = 4;
7826 public static final int ADD_STARTING = 5;
7827 public static final int REMOVE_STARTING = 6;
7828 public static final int FINISHED_STARTING = 7;
7829 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007830 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7831 public static final int HOLD_SCREEN_CHANGED = 12;
7832 public static final int APP_TRANSITION_TIMEOUT = 13;
7833 public static final int PERSIST_ANIMATION_SCALE = 14;
7834 public static final int FORCE_GC = 15;
7835 public static final int ENABLE_SCREEN = 16;
7836 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007837 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007838 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007840 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007842 public H() {
7843 }
Romain Guy06882f82009-06-10 13:36:04 -07007844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007845 @Override
7846 public void handleMessage(Message msg) {
7847 switch (msg.what) {
7848 case REPORT_FOCUS_CHANGE: {
7849 WindowState lastFocus;
7850 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007852 synchronized(mWindowMap) {
7853 lastFocus = mLastFocus;
7854 newFocus = mCurrentFocus;
7855 if (lastFocus == newFocus) {
7856 // Focus is not changing, so nothing to do.
7857 return;
7858 }
7859 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007860 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007861 // + " to " + newFocus);
7862 if (newFocus != null && lastFocus != null
7863 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007864 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007865 mLosingFocus.add(lastFocus);
7866 lastFocus = null;
7867 }
7868 }
7869
7870 if (lastFocus != newFocus) {
7871 //System.out.println("Changing focus from " + lastFocus
7872 // + " to " + newFocus);
7873 if (newFocus != null) {
7874 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007875 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007876 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7877 } catch (RemoteException e) {
7878 // Ignore if process has died.
7879 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007880 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007881 }
7882
7883 if (lastFocus != null) {
7884 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007885 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007886 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7887 } catch (RemoteException e) {
7888 // Ignore if process has died.
7889 }
7890 }
7891 }
7892 } break;
7893
7894 case REPORT_LOSING_FOCUS: {
7895 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007897 synchronized(mWindowMap) {
7898 losers = mLosingFocus;
7899 mLosingFocus = new ArrayList<WindowState>();
7900 }
7901
7902 final int N = losers.size();
7903 for (int i=0; i<N; i++) {
7904 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007905 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007906 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7907 } catch (RemoteException e) {
7908 // Ignore if process has died.
7909 }
7910 }
7911 } break;
7912
7913 case ANIMATE: {
7914 synchronized(mWindowMap) {
7915 mAnimationPending = false;
7916 performLayoutAndPlaceSurfacesLocked();
7917 }
7918 } break;
7919
7920 case ADD_STARTING: {
7921 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7922 final StartingData sd = wtoken.startingData;
7923
7924 if (sd == null) {
7925 // Animation has been canceled... do nothing.
7926 return;
7927 }
Romain Guy06882f82009-06-10 13:36:04 -07007928
Joe Onorato8a9b2202010-02-26 18:56:32 -08007929 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007930 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007932 View view = null;
7933 try {
7934 view = mPolicy.addStartingWindow(
7935 wtoken.token, sd.pkg,
7936 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7937 sd.icon);
7938 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007939 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007940 }
7941
7942 if (view != null) {
7943 boolean abort = false;
7944
7945 synchronized(mWindowMap) {
7946 if (wtoken.removed || wtoken.startingData == null) {
7947 // If the window was successfully added, then
7948 // we need to remove it.
7949 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007950 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007951 "Aborted starting " + wtoken
7952 + ": removed=" + wtoken.removed
7953 + " startingData=" + wtoken.startingData);
7954 wtoken.startingWindow = null;
7955 wtoken.startingData = null;
7956 abort = true;
7957 }
7958 } else {
7959 wtoken.startingView = view;
7960 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007961 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 "Added starting " + wtoken
7963 + ": startingWindow="
7964 + wtoken.startingWindow + " startingView="
7965 + wtoken.startingView);
7966 }
7967
7968 if (abort) {
7969 try {
7970 mPolicy.removeStartingWindow(wtoken.token, view);
7971 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007972 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 }
7974 }
7975 }
7976 } break;
7977
7978 case REMOVE_STARTING: {
7979 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7980 IBinder token = null;
7981 View view = null;
7982 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007983 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007984 + wtoken + ": startingWindow="
7985 + wtoken.startingWindow + " startingView="
7986 + wtoken.startingView);
7987 if (wtoken.startingWindow != null) {
7988 view = wtoken.startingView;
7989 token = wtoken.token;
7990 wtoken.startingData = null;
7991 wtoken.startingView = null;
7992 wtoken.startingWindow = null;
7993 }
7994 }
7995 if (view != null) {
7996 try {
7997 mPolicy.removeStartingWindow(token, view);
7998 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007999 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008000 }
8001 }
8002 } break;
8003
8004 case FINISHED_STARTING: {
8005 IBinder token = null;
8006 View view = null;
8007 while (true) {
8008 synchronized (mWindowMap) {
8009 final int N = mFinishedStarting.size();
8010 if (N <= 0) {
8011 break;
8012 }
8013 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8014
Joe Onorato8a9b2202010-02-26 18:56:32 -08008015 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 "Finished starting " + wtoken
8017 + ": startingWindow=" + wtoken.startingWindow
8018 + " startingView=" + wtoken.startingView);
8019
8020 if (wtoken.startingWindow == null) {
8021 continue;
8022 }
8023
8024 view = wtoken.startingView;
8025 token = wtoken.token;
8026 wtoken.startingData = null;
8027 wtoken.startingView = null;
8028 wtoken.startingWindow = null;
8029 }
8030
8031 try {
8032 mPolicy.removeStartingWindow(token, view);
8033 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008034 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008035 }
8036 }
8037 } break;
8038
8039 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8040 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8041
8042 boolean nowVisible = msg.arg1 != 0;
8043 boolean nowGone = msg.arg2 != 0;
8044
8045 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008046 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008047 TAG, "Reporting visible in " + wtoken
8048 + " visible=" + nowVisible
8049 + " gone=" + nowGone);
8050 if (nowVisible) {
8051 wtoken.appToken.windowsVisible();
8052 } else {
8053 wtoken.appToken.windowsGone();
8054 }
8055 } catch (RemoteException ex) {
8056 }
8057 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008059 case WINDOW_FREEZE_TIMEOUT: {
8060 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008061 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 int i = mWindows.size();
8063 while (i > 0) {
8064 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008065 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008066 if (w.mOrientationChanging) {
8067 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008068 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 }
8070 }
8071 performLayoutAndPlaceSurfacesLocked();
8072 }
8073 break;
8074 }
Romain Guy06882f82009-06-10 13:36:04 -07008075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008076 case HOLD_SCREEN_CHANGED: {
8077 Session oldHold;
8078 Session newHold;
8079 synchronized (mWindowMap) {
8080 oldHold = mLastReportedHold;
8081 newHold = (Session)msg.obj;
8082 mLastReportedHold = newHold;
8083 }
Romain Guy06882f82009-06-10 13:36:04 -07008084
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008085 if (oldHold != newHold) {
8086 try {
8087 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008088 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008089 "window",
8090 BatteryStats.WAKE_TYPE_WINDOW);
8091 }
8092 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008093 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008094 "window",
8095 BatteryStats.WAKE_TYPE_WINDOW);
8096 }
8097 } catch (RemoteException e) {
8098 }
8099 }
8100 break;
8101 }
Romain Guy06882f82009-06-10 13:36:04 -07008102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 case APP_TRANSITION_TIMEOUT: {
8104 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008105 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008106 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 "*** APP TRANSITION TIMEOUT");
8108 mAppTransitionReady = true;
8109 mAppTransitionTimeout = true;
8110 performLayoutAndPlaceSurfacesLocked();
8111 }
8112 }
8113 break;
8114 }
Romain Guy06882f82009-06-10 13:36:04 -07008115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008116 case PERSIST_ANIMATION_SCALE: {
8117 Settings.System.putFloat(mContext.getContentResolver(),
8118 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8119 Settings.System.putFloat(mContext.getContentResolver(),
8120 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8121 break;
8122 }
Romain Guy06882f82009-06-10 13:36:04 -07008123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008124 case FORCE_GC: {
8125 synchronized(mWindowMap) {
8126 if (mAnimationPending) {
8127 // If we are animating, don't do the gc now but
8128 // delay a bit so we don't interrupt the animation.
8129 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8130 2000);
8131 return;
8132 }
8133 // If we are currently rotating the display, it will
8134 // schedule a new message when done.
8135 if (mDisplayFrozen) {
8136 return;
8137 }
8138 mFreezeGcPending = 0;
8139 }
8140 Runtime.getRuntime().gc();
8141 break;
8142 }
Romain Guy06882f82009-06-10 13:36:04 -07008143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008144 case ENABLE_SCREEN: {
8145 performEnableScreen();
8146 break;
8147 }
Romain Guy06882f82009-06-10 13:36:04 -07008148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008149 case APP_FREEZE_TIMEOUT: {
8150 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008151 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008152 int i = mAppTokens.size();
8153 while (i > 0) {
8154 i--;
8155 AppWindowToken tok = mAppTokens.get(i);
8156 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008157 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008158 unsetAppFreezingScreenLocked(tok, true, true);
8159 }
8160 }
8161 }
8162 break;
8163 }
Romain Guy06882f82009-06-10 13:36:04 -07008164
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008165 case SEND_NEW_CONFIGURATION: {
8166 removeMessages(SEND_NEW_CONFIGURATION);
8167 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008168 break;
8169 }
Romain Guy06882f82009-06-10 13:36:04 -07008170
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008171 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008172 if (mWindowsChanged) {
8173 synchronized (mWindowMap) {
8174 mWindowsChanged = false;
8175 }
8176 notifyWindowsChanged();
8177 }
8178 break;
8179 }
8180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008181 }
8182 }
8183 }
8184
8185 // -------------------------------------------------------------
8186 // IWindowManager API
8187 // -------------------------------------------------------------
8188
8189 public IWindowSession openSession(IInputMethodClient client,
8190 IInputContext inputContext) {
8191 if (client == null) throw new IllegalArgumentException("null client");
8192 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008193 Session session = new Session(client, inputContext);
8194 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008195 }
8196
8197 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8198 synchronized (mWindowMap) {
8199 // The focus for the client is the window immediately below
8200 // where we would place the input method window.
8201 int idx = findDesiredInputMethodWindowIndexLocked(false);
8202 WindowState imFocus;
8203 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008204 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008205 if (imFocus != null) {
8206 if (imFocus.mSession.mClient != null &&
8207 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8208 return true;
8209 }
8210 }
8211 }
8212 }
8213 return false;
8214 }
Romain Guy06882f82009-06-10 13:36:04 -07008215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008216 // -------------------------------------------------------------
8217 // Internals
8218 // -------------------------------------------------------------
8219
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008220 final WindowState windowForClientLocked(Session session, IWindow client,
8221 boolean throwOnError) {
8222 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008223 }
Romain Guy06882f82009-06-10 13:36:04 -07008224
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008225 final WindowState windowForClientLocked(Session session, IBinder client,
8226 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008227 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008228 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008229 TAG, "Looking up client " + client + ": " + win);
8230 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008231 RuntimeException ex = new IllegalArgumentException(
8232 "Requested window " + client + " does not exist");
8233 if (throwOnError) {
8234 throw ex;
8235 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008236 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008237 return null;
8238 }
8239 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008240 RuntimeException ex = new IllegalArgumentException(
8241 "Requested window " + client + " is in session " +
8242 win.mSession + ", not " + session);
8243 if (throwOnError) {
8244 throw ex;
8245 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008246 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008247 return null;
8248 }
8249
8250 return win;
8251 }
8252
Dianne Hackborna8f60182009-09-01 19:01:50 -07008253 final void rebuildAppWindowListLocked() {
8254 int NW = mWindows.size();
8255 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008256 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008257 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008258
Dianne Hackborna8f60182009-09-01 19:01:50 -07008259 // First remove all existing app windows.
8260 i=0;
8261 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008262 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008263 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008264 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008265 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008266 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008267 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008268 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008269 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008270 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008271 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8272 && lastWallpaper == i-1) {
8273 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008274 }
8275 i++;
8276 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008277
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008278 // The wallpaper window(s) typically live at the bottom of the stack,
8279 // so skip them before adding app tokens.
8280 lastWallpaper++;
8281 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008282
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008283 // First add all of the exiting app tokens... these are no longer
8284 // in the main app list, but still have windows shown. We put them
8285 // in the back because now that the animation is over we no longer
8286 // will care about them.
8287 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008288 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008289 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8290 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008291
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008292 // And add in the still active app tokens in Z order.
8293 NT = mAppTokens.size();
8294 for (int j=0; j<NT; j++) {
8295 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008296 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008297
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008298 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008299 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008300 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008301 + " windows but added " + i);
8302 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008303 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008305 private final void assignLayersLocked() {
8306 int N = mWindows.size();
8307 int curBaseLayer = 0;
8308 int curLayer = 0;
8309 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008311 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008312 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008313 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8314 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008315 curLayer += WINDOW_LAYER_MULTIPLIER;
8316 w.mLayer = curLayer;
8317 } else {
8318 curBaseLayer = curLayer = w.mBaseLayer;
8319 w.mLayer = curLayer;
8320 }
8321 if (w.mTargetAppToken != null) {
8322 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8323 } else if (w.mAppToken != null) {
8324 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8325 } else {
8326 w.mAnimLayer = w.mLayer;
8327 }
8328 if (w.mIsImWindow) {
8329 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008330 } else if (w.mIsWallpaper) {
8331 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008332 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008333 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008334 + w.mAnimLayer);
8335 //System.out.println(
8336 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8337 }
8338 }
8339
8340 private boolean mInLayout = false;
8341 private final void performLayoutAndPlaceSurfacesLocked() {
8342 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008343 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008344 throw new RuntimeException("Recursive call!");
8345 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008346 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008347 return;
8348 }
8349
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008350 if (mWaitingForConfig) {
8351 // Our configuration has changed (most likely rotation), but we
8352 // don't yet have the complete configuration to report to
8353 // applications. Don't do any window layout until we have it.
8354 return;
8355 }
8356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008357 boolean recoveringMemory = false;
8358 if (mForceRemoves != null) {
8359 recoveringMemory = true;
8360 // Wait a little it for things to settle down, and off we go.
8361 for (int i=0; i<mForceRemoves.size(); i++) {
8362 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008363 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 removeWindowInnerLocked(ws.mSession, ws);
8365 }
8366 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008367 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008368 Object tmp = new Object();
8369 synchronized (tmp) {
8370 try {
8371 tmp.wait(250);
8372 } catch (InterruptedException e) {
8373 }
8374 }
8375 }
Romain Guy06882f82009-06-10 13:36:04 -07008376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 mInLayout = true;
8378 try {
8379 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008381 int i = mPendingRemove.size()-1;
8382 if (i >= 0) {
8383 while (i >= 0) {
8384 WindowState w = mPendingRemove.get(i);
8385 removeWindowInnerLocked(w.mSession, w);
8386 i--;
8387 }
8388 mPendingRemove.clear();
8389
8390 mInLayout = false;
8391 assignLayersLocked();
8392 mLayoutNeeded = true;
8393 performLayoutAndPlaceSurfacesLocked();
8394
8395 } else {
8396 mInLayout = false;
8397 if (mLayoutNeeded) {
8398 requestAnimationLocked(0);
8399 }
8400 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008401 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008402 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8403 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008405 } catch (RuntimeException e) {
8406 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008407 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008408 }
8409 }
8410
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008411 private final int performLayoutLockedInner() {
8412 if (!mLayoutNeeded) {
8413 return 0;
8414 }
8415
8416 mLayoutNeeded = false;
8417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 final int dw = mDisplay.getWidth();
8419 final int dh = mDisplay.getHeight();
8420
8421 final int N = mWindows.size();
8422 int i;
8423
Joe Onorato8a9b2202010-02-26 18:56:32 -08008424 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008425 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8426
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008427 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008428
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008429 int seq = mLayoutSeq+1;
8430 if (seq < 0) seq = 0;
8431 mLayoutSeq = seq;
8432
8433 // First perform layout of any root windows (not attached
8434 // to another window).
8435 int topAttached = -1;
8436 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008437 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008438
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008439 // Don't do layout of a window if it is not visible, or
8440 // soon won't be visible, to avoid wasting time and funky
8441 // changes while a window is animating away.
8442 final AppWindowToken atoken = win.mAppToken;
8443 final boolean gone = win.mViewVisibility == View.GONE
8444 || !win.mRelayoutCalled
8445 || win.mRootToken.hidden
8446 || (atoken != null && atoken.hiddenRequested)
8447 || win.mAttachedHidden
8448 || win.mExiting || win.mDestroying;
8449
8450 if (!win.mLayoutAttached) {
8451 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8452 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8453 + " mLayoutAttached=" + win.mLayoutAttached);
8454 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8455 + win.mViewVisibility + " mRelayoutCalled="
8456 + win.mRelayoutCalled + " hidden="
8457 + win.mRootToken.hidden + " hiddenRequested="
8458 + (atoken != null && atoken.hiddenRequested)
8459 + " mAttachedHidden=" + win.mAttachedHidden);
8460 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008461
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008462 // If this view is GONE, then skip it -- keep the current
8463 // frame, and let the caller know so they can ignore it
8464 // if they want. (We do the normal layout for INVISIBLE
8465 // windows, since that means "perform layout as normal,
8466 // just don't display").
8467 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008468 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008469 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8470 win.mLayoutSeq = seq;
8471 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8472 + win.mFrame + " mContainingFrame="
8473 + win.mContainingFrame + " mDisplayFrame="
8474 + win.mDisplayFrame);
8475 } else {
8476 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008477 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008479 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008480
8481 // Now perform layout of attached windows, which usually
8482 // depend on the position of the window they are attached to.
8483 // XXX does not deal with windows that are attached to windows
8484 // that are themselves attached.
8485 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008486 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008487
8488 // If this view is GONE, then skip it -- keep the current
8489 // frame, and let the caller know so they can ignore it
8490 // if they want. (We do the normal layout for INVISIBLE
8491 // windows, since that means "perform layout as normal,
8492 // just don't display").
8493 if (win.mLayoutAttached) {
8494 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8495 + " mHaveFrame=" + win.mHaveFrame
8496 + " mViewVisibility=" + win.mViewVisibility
8497 + " mRelayoutCalled=" + win.mRelayoutCalled);
8498 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8499 || !win.mHaveFrame) {
8500 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8501 win.mLayoutSeq = seq;
8502 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8503 + win.mFrame + " mContainingFrame="
8504 + win.mContainingFrame + " mDisplayFrame="
8505 + win.mDisplayFrame);
8506 }
8507 }
8508 }
Jeff Brown349703e2010-06-22 01:27:15 -07008509
8510 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008511 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008512
8513 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 }
Romain Guy06882f82009-06-10 13:36:04 -07008515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008516 private final void performLayoutAndPlaceSurfacesLockedInner(
8517 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008518 if (mDisplay == null) {
8519 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8520 return;
8521 }
8522
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008523 final long currentTime = SystemClock.uptimeMillis();
8524 final int dw = mDisplay.getWidth();
8525 final int dh = mDisplay.getHeight();
8526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008527 int i;
8528
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008529 if (mFocusMayChange) {
8530 mFocusMayChange = false;
8531 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8532 }
8533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008534 // Initialize state of exiting tokens.
8535 for (i=mExitingTokens.size()-1; i>=0; i--) {
8536 mExitingTokens.get(i).hasVisible = false;
8537 }
8538
8539 // Initialize state of exiting applications.
8540 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8541 mExitingAppTokens.get(i).hasVisible = false;
8542 }
8543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008544 boolean orientationChangeComplete = true;
8545 Session holdScreen = null;
8546 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008547 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008548 boolean focusDisplayed = false;
8549 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008550 boolean createWatermark = false;
8551
8552 if (mFxSession == null) {
8553 mFxSession = new SurfaceSession();
8554 createWatermark = true;
8555 }
8556
8557 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008558
8559 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008560
8561 if (createWatermark) {
8562 createWatermark();
8563 }
8564 if (mWatermark != null) {
8565 mWatermark.positionSurface(dw, dh);
8566 }
8567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008568 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008569 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008570 int repeats = 0;
8571 int changes = 0;
8572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008573 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008574 repeats++;
8575 if (repeats > 6) {
8576 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8577 mLayoutNeeded = false;
8578 break;
8579 }
8580
8581 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8582 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8583 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8584 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8585 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8586 assignLayersLocked();
8587 mLayoutNeeded = true;
8588 }
8589 }
8590 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8591 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8592 if (updateOrientationFromAppTokensLocked()) {
8593 mLayoutNeeded = true;
8594 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8595 }
8596 }
8597 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8598 mLayoutNeeded = true;
8599 }
8600 }
8601
8602 // FIRST LOOP: Perform a layout, if needed.
8603 if (repeats < 4) {
8604 changes = performLayoutLockedInner();
8605 if (changes != 0) {
8606 continue;
8607 }
8608 } else {
8609 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8610 changes = 0;
8611 }
8612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008613 final int transactionSequence = ++mTransactionSequence;
8614
8615 // Update animations of all applications, including those
8616 // associated with exiting/removed apps
8617 boolean tokensAnimating = false;
8618 final int NAT = mAppTokens.size();
8619 for (i=0; i<NAT; i++) {
8620 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8621 tokensAnimating = true;
8622 }
8623 }
8624 final int NEAT = mExitingAppTokens.size();
8625 for (i=0; i<NEAT; i++) {
8626 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8627 tokensAnimating = true;
8628 }
8629 }
8630
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008631 // SECOND LOOP: Execute animations and update visibility of windows.
8632
Joe Onorato8a9b2202010-02-26 18:56:32 -08008633 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008634 + transactionSequence + " tokensAnimating="
8635 + tokensAnimating);
8636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008637 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638
8639 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008640 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008641 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008642
8643 mPolicy.beginAnimationLw(dw, dh);
8644
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008645 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008647 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008648 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008649
8650 final WindowManager.LayoutParams attrs = w.mAttrs;
8651
8652 if (w.mSurface != null) {
8653 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008654 if (w.commitFinishDrawingLocked(currentTime)) {
8655 if ((w.mAttrs.flags
8656 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008657 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008658 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008659 wallpaperMayChange = true;
8660 }
8661 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008662
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008663 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8665 animating = true;
8666 //w.dump(" ");
8667 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008668 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8669 wallpaperMayChange = true;
8670 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008671
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008672 if (mPolicy.doesForceHide(w, attrs)) {
8673 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008674 if (DEBUG_VISIBILITY) Slog.v(TAG,
8675 "Animation done that could impact force hide: "
8676 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008677 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008678 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008679 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8680 forceHiding = true;
8681 }
8682 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8683 boolean changed;
8684 if (forceHiding) {
8685 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008686 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8687 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008688 } else {
8689 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008690 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8691 "Now policy shown: " + w);
8692 if (changed) {
8693 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008694 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008695 // Assume we will need to animate. If
8696 // we don't (because the wallpaper will
8697 // stay with the lock screen), then we will
8698 // clean up later.
8699 Animation a = mPolicy.createForceHideEnterAnimation();
8700 if (a != null) {
8701 w.setAnimation(a);
8702 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008703 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008704 if (mCurrentFocus == null ||
8705 mCurrentFocus.mLayer < w.mLayer) {
8706 // We are showing on to of the current
8707 // focus, so re-evaluate focus to make
8708 // sure it is correct.
8709 mFocusMayChange = true;
8710 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008711 }
8712 }
8713 if (changed && (attrs.flags
8714 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8715 wallpaperMayChange = true;
8716 }
8717 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008719 mPolicy.animatingWindowLw(w, attrs);
8720 }
8721
8722 final AppWindowToken atoken = w.mAppToken;
8723 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8724 if (atoken.lastTransactionSequence != transactionSequence) {
8725 atoken.lastTransactionSequence = transactionSequence;
8726 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8727 atoken.startingDisplayed = false;
8728 }
8729 if ((w.isOnScreen() || w.mAttrs.type
8730 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8731 && !w.mExiting && !w.mDestroying) {
8732 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008733 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008734 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008735 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008736 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008737 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008738 + " pv=" + w.mPolicyVisibility
8739 + " dp=" + w.mDrawPending
8740 + " cdp=" + w.mCommitDrawPending
8741 + " ah=" + w.mAttachedHidden
8742 + " th=" + atoken.hiddenRequested
8743 + " a=" + w.mAnimating);
8744 }
8745 }
8746 if (w != atoken.startingWindow) {
8747 if (!atoken.freezingScreen || !w.mAppFreezing) {
8748 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008749 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008750 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008751 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008752 "tokenMayBeDrawn: " + atoken
8753 + " freezingScreen=" + atoken.freezingScreen
8754 + " mAppFreezing=" + w.mAppFreezing);
8755 tokenMayBeDrawn = true;
8756 }
8757 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008758 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008759 atoken.startingDisplayed = true;
8760 }
8761 }
8762 } else if (w.mReadyToShow) {
8763 w.performShowLocked();
8764 }
8765 }
8766
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008767 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008768
8769 if (tokenMayBeDrawn) {
8770 // See if any windows have been drawn, so they (and others
8771 // associated with them) can now be shown.
8772 final int NT = mTokenList.size();
8773 for (i=0; i<NT; i++) {
8774 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8775 if (wtoken == null) {
8776 continue;
8777 }
8778 if (wtoken.freezingScreen) {
8779 int numInteresting = wtoken.numInterestingWindows;
8780 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008781 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008782 "allDrawn: " + wtoken
8783 + " interesting=" + numInteresting
8784 + " drawn=" + wtoken.numDrawnWindows);
8785 wtoken.showAllWindowsLocked();
8786 unsetAppFreezingScreenLocked(wtoken, false, true);
8787 orientationChangeComplete = true;
8788 }
8789 } else if (!wtoken.allDrawn) {
8790 int numInteresting = wtoken.numInterestingWindows;
8791 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008792 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008793 "allDrawn: " + wtoken
8794 + " interesting=" + numInteresting
8795 + " drawn=" + wtoken.numDrawnWindows);
8796 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008797 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008798
8799 // We can now show all of the drawn windows!
8800 if (!mOpeningApps.contains(wtoken)) {
8801 wtoken.showAllWindowsLocked();
8802 }
8803 }
8804 }
8805 }
8806 }
8807
8808 // If we are ready to perform an app transition, check through
8809 // all of the app tokens to be shown and see if they are ready
8810 // to go.
8811 if (mAppTransitionReady) {
8812 int NN = mOpeningApps.size();
8813 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008814 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008815 "Checking " + NN + " opening apps (frozen="
8816 + mDisplayFrozen + " timeout="
8817 + mAppTransitionTimeout + ")...");
8818 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8819 // If the display isn't frozen, wait to do anything until
8820 // all of the apps are ready. Otherwise just go because
8821 // we'll unfreeze the display when everyone is ready.
8822 for (i=0; i<NN && goodToGo; i++) {
8823 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008824 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 "Check opening app" + wtoken + ": allDrawn="
8826 + wtoken.allDrawn + " startingDisplayed="
8827 + wtoken.startingDisplayed);
8828 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8829 && !wtoken.startingMoved) {
8830 goodToGo = false;
8831 }
8832 }
8833 }
8834 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008835 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008836 int transit = mNextAppTransition;
8837 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008838 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008839 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008840 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008841 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008842 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 mAppTransitionTimeout = false;
8844 mStartingIconInTransition = false;
8845 mSkipAppTransitionAnimation = false;
8846
8847 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8848
Dianne Hackborna8f60182009-09-01 19:01:50 -07008849 // If there are applications waiting to come to the
8850 // top of the stack, now is the time to move their windows.
8851 // (Note that we don't do apps going to the bottom
8852 // here -- we want to keep their windows in the old
8853 // Z-order until the animation completes.)
8854 if (mToTopApps.size() > 0) {
8855 NN = mAppTokens.size();
8856 for (i=0; i<NN; i++) {
8857 AppWindowToken wtoken = mAppTokens.get(i);
8858 if (wtoken.sendingToTop) {
8859 wtoken.sendingToTop = false;
8860 moveAppWindowsLocked(wtoken, NN, false);
8861 }
8862 }
8863 mToTopApps.clear();
8864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008865
Dianne Hackborn25994b42009-09-04 14:21:19 -07008866 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008867
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008868 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008869 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008870
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008871 // The top-most window will supply the layout params,
8872 // and we will determine it below.
8873 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008874 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008875 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008876
Joe Onorato8a9b2202010-02-26 18:56:32 -08008877 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008878 "New wallpaper target=" + mWallpaperTarget
8879 + ", lower target=" + mLowerWallpaperTarget
8880 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008881 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008882 // Do a first pass through the tokens for two
8883 // things:
8884 // (1) Determine if both the closing and opening
8885 // app token sets are wallpaper targets, in which
8886 // case special animations are needed
8887 // (since the wallpaper needs to stay static
8888 // behind them).
8889 // (2) Find the layout params of the top-most
8890 // application window in the tokens, which is
8891 // what will control the animation theme.
8892 final int NC = mClosingApps.size();
8893 NN = NC + mOpeningApps.size();
8894 for (i=0; i<NN; i++) {
8895 AppWindowToken wtoken;
8896 int mode;
8897 if (i < NC) {
8898 wtoken = mClosingApps.get(i);
8899 mode = 1;
8900 } else {
8901 wtoken = mOpeningApps.get(i-NC);
8902 mode = 2;
8903 }
8904 if (mLowerWallpaperTarget != null) {
8905 if (mLowerWallpaperTarget.mAppToken == wtoken
8906 || mUpperWallpaperTarget.mAppToken == wtoken) {
8907 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008908 }
8909 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008910 if (wtoken.appFullscreen) {
8911 WindowState ws = wtoken.findMainWindow();
8912 if (ws != null) {
8913 // If this is a compatibility mode
8914 // window, we will always use its anim.
8915 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8916 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008917 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008918 bestAnimLayer = Integer.MAX_VALUE;
8919 } else if (ws.mLayer > bestAnimLayer) {
8920 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008921 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008922 bestAnimLayer = ws.mLayer;
8923 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008924 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008925 }
8926 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008927
Dianne Hackborn25994b42009-09-04 14:21:19 -07008928 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008929 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008930 "Wallpaper animation!");
8931 switch (transit) {
8932 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8933 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8934 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8935 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8936 break;
8937 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8938 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8939 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8940 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8941 break;
8942 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008943 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008944 "New transit: " + transit);
8945 } else if (oldWallpaper != null) {
8946 // We are transitioning from an activity with
8947 // a wallpaper to one without.
8948 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008949 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008950 "New transit away from wallpaper: " + transit);
8951 } else if (mWallpaperTarget != null) {
8952 // We are transitioning from an activity without
8953 // a wallpaper to now showing the wallpaper
8954 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008955 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008956 "New transit into wallpaper: " + transit);
8957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008958
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008959 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8960 mLastEnterAnimToken = animToken;
8961 mLastEnterAnimParams = animLp;
8962 } else if (mLastEnterAnimParams != null) {
8963 animLp = mLastEnterAnimParams;
8964 mLastEnterAnimToken = null;
8965 mLastEnterAnimParams = null;
8966 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008967
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008968 // If all closing windows are obscured, then there is
8969 // no need to do an animation. This is the case, for
8970 // example, when this transition is being done behind
8971 // the lock screen.
8972 if (!mPolicy.allowAppAnimationsLw()) {
8973 animLp = null;
8974 }
8975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 NN = mOpeningApps.size();
8977 for (i=0; i<NN; i++) {
8978 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008979 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008980 "Now opening app" + wtoken);
8981 wtoken.reportedVisible = false;
8982 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008983 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008984 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008985 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008986 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008987 wtoken.showAllWindowsLocked();
8988 }
8989 NN = mClosingApps.size();
8990 for (i=0; i<NN; i++) {
8991 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008992 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008993 "Now closing app" + wtoken);
8994 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008995 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008996 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008997 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008998 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008999 // Force the allDrawn flag, because we want to start
9000 // this guy's animations regardless of whether it's
9001 // gotten drawn.
9002 wtoken.allDrawn = true;
9003 }
9004
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009005 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009007 mOpeningApps.clear();
9008 mClosingApps.clear();
9009
9010 // This has changed the visibility of windows, so perform
9011 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009012 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009013 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009014 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9015 assignLayersLocked();
9016 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009017 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009018 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 }
9020 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009021
Dianne Hackborn16064f92010-03-25 00:47:24 -07009022 int adjResult = 0;
9023
Dianne Hackborna8f60182009-09-01 19:01:50 -07009024 if (!animating && mAppTransitionRunning) {
9025 // We have finished the animation of an app transition. To do
9026 // this, we have delayed a lot of operations like showing and
9027 // hiding apps, moving apps in Z-order, etc. The app token list
9028 // reflects the correct Z-order, but the window list may now
9029 // be out of sync with it. So here we will just rebuild the
9030 // entire app window list. Fun!
9031 mAppTransitionRunning = false;
9032 // Clear information about apps that were moving.
9033 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009034
Dianne Hackborna8f60182009-09-01 19:01:50 -07009035 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009036 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009037 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009038 moveInputMethodWindowsIfNeededLocked(false);
9039 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009040 // Since the window list has been rebuilt, focus might
9041 // have to be recomputed since the actual order of windows
9042 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009043 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009045
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009046 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009047 // At this point, there was a window with a wallpaper that
9048 // was force hiding other windows behind it, but now it
9049 // is going away. This may be simple -- just animate
9050 // away the wallpaper and its window -- or it may be
9051 // hard -- the wallpaper now needs to be shown behind
9052 // something that was hidden.
9053 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009054 if (mLowerWallpaperTarget != null
9055 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009056 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009057 "wallpaperForceHiding changed with lower="
9058 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009059 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009060 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9061 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9062 if (mLowerWallpaperTarget.mAppToken.hidden) {
9063 // The lower target has become hidden before we
9064 // actually started the animation... let's completely
9065 // re-evaluate everything.
9066 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009067 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009068 }
9069 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009070 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009071 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009072 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009073 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009074 + " NEW: " + mWallpaperTarget
9075 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009076 if (mLowerWallpaperTarget == null) {
9077 // Whoops, we don't need a special wallpaper animation.
9078 // Clear them out.
9079 forceHiding = false;
9080 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009081 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009082 if (w.mSurface != null) {
9083 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009084 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009085 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009086 forceHiding = true;
9087 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9088 if (!w.mAnimating) {
9089 // We set the animation above so it
9090 // is not yet running.
9091 w.clearAnimation();
9092 }
9093 }
9094 }
9095 }
9096 }
9097 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009098
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009099 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009100 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009101 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009102 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009103 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009104
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009105 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009106 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009107 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009108 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009109 assignLayersLocked();
9110 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009111 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009112 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009113 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009114 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009115
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009116 if (mFocusMayChange) {
9117 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009118 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009119 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009120 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009121 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009122 }
9123
9124 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009125 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009126 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009127
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009128 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9129 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009130
Jeff Browne33348b2010-07-15 23:54:05 -07009131 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009132 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133
9134 // THIRD LOOP: Update the surfaces of all windows.
9135
9136 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9137
9138 boolean obscured = false;
9139 boolean blurring = false;
9140 boolean dimming = false;
9141 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009142 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009143 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009144
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009145 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009147 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009148 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009149
9150 boolean displayed = false;
9151 final WindowManager.LayoutParams attrs = w.mAttrs;
9152 final int attrFlags = attrs.flags;
9153
9154 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009155 // XXX NOTE: The logic here could be improved. We have
9156 // the decision about whether to resize a window separated
9157 // from whether to hide the surface. This can cause us to
9158 // resize a surface even if we are going to hide it. You
9159 // can see this by (1) holding device in landscape mode on
9160 // home screen; (2) tapping browser icon (device will rotate
9161 // to landscape; (3) tap home. The wallpaper will be resized
9162 // in step 2 but then immediately hidden, causing us to
9163 // have to resize and then redraw it again in step 3. It
9164 // would be nice to figure out how to avoid this, but it is
9165 // difficult because we do need to resize surfaces in some
9166 // cases while they are hidden such as when first showing a
9167 // window.
9168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009169 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009170 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171 TAG, "Placing surface #" + i + " " + w.mSurface
9172 + ": new=" + w.mShownFrame + ", old="
9173 + w.mLastShownFrame);
9174
9175 boolean resize;
9176 int width, height;
9177 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9178 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9179 w.mLastRequestedHeight != w.mRequestedHeight;
9180 // for a scaled surface, we just want to use
9181 // the requested size.
9182 width = w.mRequestedWidth;
9183 height = w.mRequestedHeight;
9184 w.mLastRequestedWidth = width;
9185 w.mLastRequestedHeight = height;
9186 w.mLastShownFrame.set(w.mShownFrame);
9187 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009188 if (SHOW_TRANSACTIONS) logSurface(w,
9189 "POS " + w.mShownFrame.left
9190 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009191 w.mSurfaceX = w.mShownFrame.left;
9192 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009193 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9194 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009195 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009196 if (!recoveringMemory) {
9197 reclaimSomeSurfaceMemoryLocked(w, "position");
9198 }
9199 }
9200 } else {
9201 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9202 width = w.mShownFrame.width();
9203 height = w.mShownFrame.height();
9204 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 }
9206
9207 if (resize) {
9208 if (width < 1) width = 1;
9209 if (height < 1) height = 1;
9210 if (w.mSurface != null) {
9211 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009212 if (SHOW_TRANSACTIONS) logSurface(w,
9213 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009214 + w.mShownFrame.top + " SIZE "
9215 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009216 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009217 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009218 w.mSurfaceW = width;
9219 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009220 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009221 w.mSurfaceX = w.mShownFrame.left;
9222 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009223 w.mSurface.setPosition(w.mShownFrame.left,
9224 w.mShownFrame.top);
9225 } catch (RuntimeException e) {
9226 // If something goes wrong with the surface (such
9227 // as running out of memory), don't take down the
9228 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009229 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009230 + "size=(" + width + "x" + height
9231 + "), pos=(" + w.mShownFrame.left
9232 + "," + w.mShownFrame.top + ")", e);
9233 if (!recoveringMemory) {
9234 reclaimSomeSurfaceMemoryLocked(w, "size");
9235 }
9236 }
9237 }
9238 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009239 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009240 w.mContentInsetsChanged =
9241 !w.mLastContentInsets.equals(w.mContentInsets);
9242 w.mVisibleInsetsChanged =
9243 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009244 boolean configChanged =
9245 w.mConfiguration != mCurConfiguration
9246 && (w.mConfiguration == null
9247 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009248 if (DEBUG_CONFIGURATION && configChanged) {
9249 Slog.v(TAG, "Win " + w + " config changed: "
9250 + mCurConfiguration);
9251 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009252 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009253 + ": configChanged=" + configChanged
9254 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009255 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009256 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009257 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009258 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009259 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009260 w.mLastFrame.set(w.mFrame);
9261 w.mLastContentInsets.set(w.mContentInsets);
9262 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009263 // If the screen is currently frozen, then keep
9264 // it frozen until this window draws at its new
9265 // orientation.
9266 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009267 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009268 "Resizing while display frozen: " + w);
9269 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009270 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009271 mWindowsFreezingScreen = true;
9272 // XXX should probably keep timeout from
9273 // when we first froze the display.
9274 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9275 mH.sendMessageDelayed(mH.obtainMessage(
9276 H.WINDOW_FREEZE_TIMEOUT), 2000);
9277 }
9278 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009279 // If the orientation is changing, then we need to
9280 // hold off on unfreezing the display until this
9281 // window has been redrawn; to do that, we need
9282 // to go through the process of getting informed
9283 // by the application when it has finished drawing.
9284 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009285 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009286 "Orientation start waiting for draw in "
9287 + w + ", surface " + w.mSurface);
9288 w.mDrawPending = true;
9289 w.mCommitDrawPending = false;
9290 w.mReadyToShow = false;
9291 if (w.mAppToken != null) {
9292 w.mAppToken.allDrawn = false;
9293 }
9294 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009295 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009296 "Resizing window " + w + " to " + w.mFrame);
9297 mResizingWindows.add(w);
9298 } else if (w.mOrientationChanging) {
9299 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009300 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009301 "Orientation not waiting for draw in "
9302 + w + ", surface " + w.mSurface);
9303 w.mOrientationChanging = false;
9304 }
9305 }
9306 }
9307
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009308 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009309 if (!w.mLastHidden) {
9310 //dump();
9311 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009312 if (SHOW_TRANSACTIONS) logSurface(w,
9313 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009314 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009315 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009316 try {
9317 w.mSurface.hide();
9318 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009319 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009320 }
9321 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 }
9323 // If we are waiting for this window to handle an
9324 // orientation change, well, it is hidden, so
9325 // doesn't really matter. Note that this does
9326 // introduce a potential glitch if the window
9327 // becomes unhidden before it has drawn for the
9328 // new orientation.
9329 if (w.mOrientationChanging) {
9330 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009331 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009332 "Orientation change skips hidden " + w);
9333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009334 } else if (w.mLastLayer != w.mAnimLayer
9335 || w.mLastAlpha != w.mShownAlpha
9336 || w.mLastDsDx != w.mDsDx
9337 || w.mLastDtDx != w.mDtDx
9338 || w.mLastDsDy != w.mDsDy
9339 || w.mLastDtDy != w.mDtDy
9340 || w.mLastHScale != w.mHScale
9341 || w.mLastVScale != w.mVScale
9342 || w.mLastHidden) {
9343 displayed = true;
9344 w.mLastAlpha = w.mShownAlpha;
9345 w.mLastLayer = w.mAnimLayer;
9346 w.mLastDsDx = w.mDsDx;
9347 w.mLastDtDx = w.mDtDx;
9348 w.mLastDsDy = w.mDsDy;
9349 w.mLastDtDy = w.mDtDy;
9350 w.mLastHScale = w.mHScale;
9351 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009352 if (SHOW_TRANSACTIONS) logSurface(w,
9353 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009354 + " matrix=[" + (w.mDsDx*w.mHScale)
9355 + "," + (w.mDtDx*w.mVScale)
9356 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009357 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 if (w.mSurface != null) {
9359 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009360 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009361 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009362 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009363 w.mSurface.setLayer(w.mAnimLayer);
9364 w.mSurface.setMatrix(
9365 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9366 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9367 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009368 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009369 if (!recoveringMemory) {
9370 reclaimSomeSurfaceMemoryLocked(w, "update");
9371 }
9372 }
9373 }
9374
9375 if (w.mLastHidden && !w.mDrawPending
9376 && !w.mCommitDrawPending
9377 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009378 if (SHOW_TRANSACTIONS) logSurface(w,
9379 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009380 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009381 + " during relayout");
9382 if (showSurfaceRobustlyLocked(w)) {
9383 w.mHasDrawn = true;
9384 w.mLastHidden = false;
9385 } else {
9386 w.mOrientationChanging = false;
9387 }
9388 }
9389 if (w.mSurface != null) {
9390 w.mToken.hasVisible = true;
9391 }
9392 } else {
9393 displayed = true;
9394 }
9395
9396 if (displayed) {
9397 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009398 if (attrs.width == LayoutParams.MATCH_PARENT
9399 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009400 covered = true;
9401 }
9402 }
9403 if (w.mOrientationChanging) {
9404 if (w.mDrawPending || w.mCommitDrawPending) {
9405 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009406 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009407 "Orientation continue waiting for draw in " + w);
9408 } else {
9409 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009410 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009411 "Orientation change complete in " + w);
9412 }
9413 }
9414 w.mToken.hasVisible = true;
9415 }
9416 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009417 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009418 "Orientation change skips hidden " + w);
9419 w.mOrientationChanging = false;
9420 }
9421
9422 final boolean canBeSeen = w.isDisplayedLw();
9423
9424 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9425 focusDisplayed = true;
9426 }
9427
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009428 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009430 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009431 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009432 if (w.mSurface != null) {
9433 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9434 holdScreen = w.mSession;
9435 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009436 if (!syswin && w.mAttrs.screenBrightness >= 0
9437 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009438 screenBrightness = w.mAttrs.screenBrightness;
9439 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009440 if (!syswin && w.mAttrs.buttonBrightness >= 0
9441 && buttonBrightness < 0) {
9442 buttonBrightness = w.mAttrs.buttonBrightness;
9443 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009444 if (canBeSeen
9445 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9446 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9447 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009448 syswin = true;
9449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009450 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009451
Dianne Hackborn25994b42009-09-04 14:21:19 -07009452 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9453 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009454 // This window completely covers everything behind it,
9455 // so we want to leave all of them as unblurred (for
9456 // performance reasons).
9457 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009458 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009459 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009460 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009461 obscured = true;
9462 if (mBackgroundFillerSurface == null) {
9463 try {
9464 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009465 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009466 0, dw, dh,
9467 PixelFormat.OPAQUE,
9468 Surface.FX_SURFACE_NORMAL);
9469 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009470 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009471 }
9472 }
9473 try {
9474 mBackgroundFillerSurface.setPosition(0, 0);
9475 mBackgroundFillerSurface.setSize(dw, dh);
9476 // Using the same layer as Dim because they will never be shown at the
9477 // same time.
9478 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9479 mBackgroundFillerSurface.show();
9480 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009481 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009482 }
9483 backgroundFillerShown = true;
9484 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009485 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009486 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009487 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009488 + ": blurring=" + blurring
9489 + " obscured=" + obscured
9490 + " displayed=" + displayed);
9491 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9492 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009493 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009495 if (mDimAnimator == null) {
9496 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009498 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009499 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009501 }
9502 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9503 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009504 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009506 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009507 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009508 + mBlurSurface + ": CREATE");
9509 try {
Romain Guy06882f82009-06-10 13:36:04 -07009510 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009511 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009512 -1, 16, 16,
9513 PixelFormat.OPAQUE,
9514 Surface.FX_SURFACE_BLUR);
9515 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009516 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009517 }
9518 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009520 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9521 + mBlurSurface + ": pos=(0,0) (" +
9522 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 mBlurSurface.setPosition(0, 0);
9524 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009525 mBlurSurface.setLayer(w.mAnimLayer-2);
9526 if (!mBlurShown) {
9527 try {
9528 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9529 + mBlurSurface + ": SHOW");
9530 mBlurSurface.show();
9531 } catch (RuntimeException e) {
9532 Slog.w(TAG, "Failure showing blur surface", e);
9533 }
9534 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009535 }
9536 }
9537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009538 }
9539 }
9540 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009541
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009542 if (obscuredChanged && mWallpaperTarget == w) {
9543 // This is the wallpaper target and its obscured state
9544 // changed... make sure the current wallaper's visibility
9545 // has been updated accordingly.
9546 updateWallpaperVisibilityLocked();
9547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009548 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009549
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009550 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9551 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009552 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009553 try {
9554 mBackgroundFillerSurface.hide();
9555 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009556 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009557 }
9558 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009559
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009560 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009561 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9562 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009563 }
Romain Guy06882f82009-06-10 13:36:04 -07009564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009565 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009566 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009567 + ": HIDE");
9568 try {
9569 mBlurSurface.hide();
9570 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009571 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009572 }
9573 mBlurShown = false;
9574 }
9575
Joe Onorato8a9b2202010-02-26 18:56:32 -08009576 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009577 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009578 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009579 }
9580
Jeff Browne33348b2010-07-15 23:54:05 -07009581 mInputMonitor.updateInputWindowsLw();
9582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009583 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009584
Joe Onorato8a9b2202010-02-26 18:56:32 -08009585 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009586 "With display frozen, orientationChangeComplete="
9587 + orientationChangeComplete);
9588 if (orientationChangeComplete) {
9589 if (mWindowsFreezingScreen) {
9590 mWindowsFreezingScreen = false;
9591 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9592 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009593 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594 }
Romain Guy06882f82009-06-10 13:36:04 -07009595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009596 i = mResizingWindows.size();
9597 if (i > 0) {
9598 do {
9599 i--;
9600 WindowState win = mResizingWindows.get(i);
9601 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009602 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9603 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009604 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009605 boolean configChanged =
9606 win.mConfiguration != mCurConfiguration
9607 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009608 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9609 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9610 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009611 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009612 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009613 + " / " + mCurConfiguration + " / 0x"
9614 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009615 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009616 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009617 win.mClient.resized(win.mFrame.width(),
9618 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009619 win.mLastVisibleInsets, win.mDrawPending,
9620 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009621 win.mContentInsetsChanged = false;
9622 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009623 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009624 } catch (RemoteException e) {
9625 win.mOrientationChanging = false;
9626 }
9627 } while (i > 0);
9628 mResizingWindows.clear();
9629 }
Romain Guy06882f82009-06-10 13:36:04 -07009630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009631 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009632 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 i = mDestroySurface.size();
9634 if (i > 0) {
9635 do {
9636 i--;
9637 WindowState win = mDestroySurface.get(i);
9638 win.mDestroying = false;
9639 if (mInputMethodWindow == win) {
9640 mInputMethodWindow = null;
9641 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009642 if (win == mWallpaperTarget) {
9643 wallpaperDestroyed = true;
9644 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009645 win.destroySurfaceLocked();
9646 } while (i > 0);
9647 mDestroySurface.clear();
9648 }
9649
9650 // Time to remove any exiting tokens?
9651 for (i=mExitingTokens.size()-1; i>=0; i--) {
9652 WindowToken token = mExitingTokens.get(i);
9653 if (!token.hasVisible) {
9654 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009655 if (token.windowType == TYPE_WALLPAPER) {
9656 mWallpaperTokens.remove(token);
9657 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009658 }
9659 }
9660
9661 // Time to remove any exiting applications?
9662 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9663 AppWindowToken token = mExitingAppTokens.get(i);
9664 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009665 // Make sure there is no animation running on this token,
9666 // so any windows associated with it will be removed as
9667 // soon as their animations are complete
9668 token.animation = null;
9669 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009670 mAppTokens.remove(token);
9671 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009672 if (mLastEnterAnimToken == token) {
9673 mLastEnterAnimToken = null;
9674 mLastEnterAnimParams = null;
9675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009676 }
9677 }
9678
Dianne Hackborna8f60182009-09-01 19:01:50 -07009679 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009680
Dianne Hackborna8f60182009-09-01 19:01:50 -07009681 if (!animating && mAppTransitionRunning) {
9682 // We have finished the animation of an app transition. To do
9683 // this, we have delayed a lot of operations like showing and
9684 // hiding apps, moving apps in Z-order, etc. The app token list
9685 // reflects the correct Z-order, but the window list may now
9686 // be out of sync with it. So here we will just rebuild the
9687 // entire app window list. Fun!
9688 mAppTransitionRunning = false;
9689 needRelayout = true;
9690 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009691 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009692 // Clear information about apps that were moving.
9693 mToBottomApps.clear();
9694 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009695
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009696 if (focusDisplayed) {
9697 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9698 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009699 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009700 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009701 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009702 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009703 requestAnimationLocked(0);
9704 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009705 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9706 }
Jeff Browneb857f12010-07-16 10:06:33 -07009707
Jeff Browne33348b2010-07-15 23:54:05 -07009708 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009709
Jeff Brown8e03b752010-06-13 19:16:55 -07009710 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009711 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9712 mPowerManager.setScreenBrightnessOverride(-1);
9713 } else {
9714 mPowerManager.setScreenBrightnessOverride((int)
9715 (screenBrightness * Power.BRIGHTNESS_ON));
9716 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009717 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9718 mPowerManager.setButtonBrightnessOverride(-1);
9719 } else {
9720 mPowerManager.setButtonBrightnessOverride((int)
9721 (buttonBrightness * Power.BRIGHTNESS_ON));
9722 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009723 if (holdScreen != mHoldingScreenOn) {
9724 mHoldingScreenOn = holdScreen;
9725 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9726 mH.sendMessage(m);
9727 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009728
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009729 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009730 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009731 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9732 LocalPowerManager.BUTTON_EVENT, true);
9733 mTurnOnScreen = false;
9734 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009735
9736 // Check to see if we are now in a state where the screen should
9737 // be enabled, because the window obscured flags have changed.
9738 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009739 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009740
9741 /**
9742 * Must be called with the main window manager lock held.
9743 */
9744 void setHoldScreenLocked(boolean holding) {
9745 boolean state = mHoldingScreenWakeLock.isHeld();
9746 if (holding != state) {
9747 if (holding) {
9748 mHoldingScreenWakeLock.acquire();
9749 } else {
9750 mPolicy.screenOnStoppedLw();
9751 mHoldingScreenWakeLock.release();
9752 }
9753 }
9754 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009755
9756 void requestAnimationLocked(long delay) {
9757 if (!mAnimationPending) {
9758 mAnimationPending = true;
9759 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9760 }
9761 }
Romain Guy06882f82009-06-10 13:36:04 -07009762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009763 /**
9764 * Have the surface flinger show a surface, robustly dealing with
9765 * error conditions. In particular, if there is not enough memory
9766 * to show the surface, then we will try to get rid of other surfaces
9767 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009768 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009769 * @return Returns true if the surface was successfully shown.
9770 */
9771 boolean showSurfaceRobustlyLocked(WindowState win) {
9772 try {
9773 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009774 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009775 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009776 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009777 if (DEBUG_VISIBILITY) Slog.v(TAG,
9778 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009779 win.mTurnOnScreen = false;
9780 mTurnOnScreen = true;
9781 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 }
9783 return true;
9784 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009785 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009786 }
Romain Guy06882f82009-06-10 13:36:04 -07009787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009788 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009790 return false;
9791 }
Romain Guy06882f82009-06-10 13:36:04 -07009792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009793 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9794 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009795
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009796 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009797 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009799 if (mForceRemoves == null) {
9800 mForceRemoves = new ArrayList<WindowState>();
9801 }
Romain Guy06882f82009-06-10 13:36:04 -07009802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009803 long callingIdentity = Binder.clearCallingIdentity();
9804 try {
9805 // There was some problem... first, do a sanity check of the
9806 // window list to make sure we haven't left any dangling surfaces
9807 // around.
9808 int N = mWindows.size();
9809 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009810 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009811 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009812 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009813 if (ws.mSurface != null) {
9814 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009815 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 + ws + " surface=" + ws.mSurface
9817 + " token=" + win.mToken
9818 + " pid=" + ws.mSession.mPid
9819 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009820 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009821 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009822 ws.mSurface = null;
9823 mForceRemoves.add(ws);
9824 i--;
9825 N--;
9826 leakedSurface = true;
9827 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009828 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 + ws + " surface=" + ws.mSurface
9830 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009831 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009832 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009833 ws.mSurface = null;
9834 leakedSurface = true;
9835 }
9836 }
9837 }
Romain Guy06882f82009-06-10 13:36:04 -07009838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 boolean killedApps = false;
9840 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009841 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009842 SparseIntArray pidCandidates = new SparseIntArray();
9843 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009844 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009845 if (ws.mSurface != null) {
9846 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9847 }
9848 }
9849 if (pidCandidates.size() > 0) {
9850 int[] pids = new int[pidCandidates.size()];
9851 for (int i=0; i<pids.length; i++) {
9852 pids[i] = pidCandidates.keyAt(i);
9853 }
9854 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009855 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009856 killedApps = true;
9857 }
9858 } catch (RemoteException e) {
9859 }
9860 }
9861 }
Romain Guy06882f82009-06-10 13:36:04 -07009862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009863 if (leakedSurface || killedApps) {
9864 // We managed to reclaim some memory, so get rid of the trouble
9865 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009866 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009868 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009869 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009870 win.mSurface = null;
9871 }
Romain Guy06882f82009-06-10 13:36:04 -07009872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009873 try {
9874 win.mClient.dispatchGetNewSurface();
9875 } catch (RemoteException e) {
9876 }
9877 }
9878 } finally {
9879 Binder.restoreCallingIdentity(callingIdentity);
9880 }
9881 }
Romain Guy06882f82009-06-10 13:36:04 -07009882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009883 private boolean updateFocusedWindowLocked(int mode) {
9884 WindowState newFocus = computeFocusedWindowLocked();
9885 if (mCurrentFocus != newFocus) {
9886 // This check makes sure that we don't already have the focus
9887 // change message pending.
9888 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9889 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009890 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009891 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9892 final WindowState oldFocus = mCurrentFocus;
9893 mCurrentFocus = newFocus;
9894 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 final WindowState imWindow = mInputMethodWindow;
9897 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009898 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009900 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9901 mLayoutNeeded = true;
9902 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009903 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9904 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009905 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9906 // Client will do the layout, but we need to assign layers
9907 // for handleNewWindowLocked() below.
9908 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 }
9910 }
Jeff Brown349703e2010-06-22 01:27:15 -07009911
9912 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9913 // If we defer assigning layers, then the caller is responsible for
9914 // doing this part.
9915 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 return true;
9918 }
9919 return false;
9920 }
Jeff Brown349703e2010-06-22 01:27:15 -07009921
9922 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009923 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009924 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925
9926 private WindowState computeFocusedWindowLocked() {
9927 WindowState result = null;
9928 WindowState win;
9929
9930 int i = mWindows.size() - 1;
9931 int nextAppIndex = mAppTokens.size()-1;
9932 WindowToken nextApp = nextAppIndex >= 0
9933 ? mAppTokens.get(nextAppIndex) : null;
9934
9935 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009936 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009937
Joe Onorato8a9b2202010-02-26 18:56:32 -08009938 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009939 TAG, "Looking for focus: " + i
9940 + " = " + win
9941 + ", flags=" + win.mAttrs.flags
9942 + ", canReceive=" + win.canReceiveKeys());
9943
9944 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009946 // If this window's application has been removed, just skip it.
9947 if (thisApp != null && thisApp.removed) {
9948 i--;
9949 continue;
9950 }
Romain Guy06882f82009-06-10 13:36:04 -07009951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009952 // If there is a focused app, don't allow focus to go to any
9953 // windows below it. If this is an application window, step
9954 // through the app tokens until we find its app.
9955 if (thisApp != null && nextApp != null && thisApp != nextApp
9956 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9957 int origAppIndex = nextAppIndex;
9958 while (nextAppIndex > 0) {
9959 if (nextApp == mFocusedApp) {
9960 // Whoops, we are below the focused app... no focus
9961 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009962 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963 TAG, "Reached focused app: " + mFocusedApp);
9964 return null;
9965 }
9966 nextAppIndex--;
9967 nextApp = mAppTokens.get(nextAppIndex);
9968 if (nextApp == thisApp) {
9969 break;
9970 }
9971 }
9972 if (thisApp != nextApp) {
9973 // Uh oh, the app token doesn't exist! This shouldn't
9974 // happen, but if it does we can get totally hosed...
9975 // so restart at the original app.
9976 nextAppIndex = origAppIndex;
9977 nextApp = mAppTokens.get(nextAppIndex);
9978 }
9979 }
9980
9981 // Dispatch to this window if it is wants key events.
9982 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009983 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009984 TAG, "Found focus @ " + i + " = " + win);
9985 result = win;
9986 break;
9987 }
9988
9989 i--;
9990 }
9991
9992 return result;
9993 }
9994
9995 private void startFreezingDisplayLocked() {
9996 if (mDisplayFrozen) {
9997 return;
9998 }
Romain Guy06882f82009-06-10 13:36:04 -07009999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010000 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010002 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010003 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010004 if (mFreezeGcPending != 0) {
10005 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010006 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010007 mH.removeMessages(H.FORCE_GC);
10008 Runtime.getRuntime().gc();
10009 mFreezeGcPending = now;
10010 }
10011 } else {
10012 mFreezeGcPending = now;
10013 }
Romain Guy06882f82009-06-10 13:36:04 -070010014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010015 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010016
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010017 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010018
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010019 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10020 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010021 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010022 mAppTransitionReady = true;
10023 }
Romain Guy06882f82009-06-10 13:36:04 -070010024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 if (PROFILE_ORIENTATION) {
10026 File file = new File("/data/system/frozen");
10027 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10028 }
10029 Surface.freezeDisplay(0);
10030 }
Romain Guy06882f82009-06-10 13:36:04 -070010031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010032 private void stopFreezingDisplayLocked() {
10033 if (!mDisplayFrozen) {
10034 return;
10035 }
Romain Guy06882f82009-06-10 13:36:04 -070010036
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010037 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10038 return;
10039 }
10040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010041 mDisplayFrozen = false;
10042 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10043 if (PROFILE_ORIENTATION) {
10044 Debug.stopMethodTracing();
10045 }
10046 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010047
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010048 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010049
Christopher Tateb696aee2010-04-02 19:08:30 -070010050 // While the display is frozen we don't re-compute the orientation
10051 // to avoid inconsistent states. However, something interesting
10052 // could have actually changed during that time so re-evaluate it
10053 // now to catch that.
10054 if (updateOrientationFromAppTokensLocked()) {
10055 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10056 }
10057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 // A little kludge: a lot could have happened while the
10059 // display was frozen, so now that we are coming back we
10060 // do a gc so that any remote references the system
10061 // processes holds on others can be released if they are
10062 // no longer needed.
10063 mH.removeMessages(H.FORCE_GC);
10064 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10065 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010067 mScreenFrozenLock.release();
10068 }
Romain Guy06882f82009-06-10 13:36:04 -070010069
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010070 static int getPropertyInt(String name, int defUnits, int defDps, DisplayMetrics dm) {
10071 String str = SystemProperties.get(name);
10072 try {
10073 int val = Integer.parseInt(str);
10074 return val;
10075 } catch (Exception e) {
10076 }
10077 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10078 return defDps;
10079 }
10080 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10081 return val;
10082 }
10083
10084 class Watermark {
10085 Surface mSurface;
10086 int mWidth;
10087 int mHeight;
10088 int mXPercent;
10089 int mYPercent;
10090
10091 Watermark(SurfaceSession session, String text) {
10092 final DisplayMetrics dm = new DisplayMetrics();
10093 mDisplay.getMetrics(dm);
10094
10095 int fontSize = getPropertyInt("ro.watermark.height",
10096 TypedValue.COMPLEX_UNIT_DIP, 48, dm);
10097 mXPercent = getPropertyInt("ro.watermark.x",
10098 TypedValue.COMPLEX_UNIT_PX, 50, dm);
10099 mYPercent = getPropertyInt("ro.watermark.y",
10100 TypedValue.COMPLEX_UNIT_PX, 99, dm);
10101 int color = getPropertyInt("ro.watermark.color",
10102 TypedValue.COMPLEX_UNIT_PX, 0x80ffffff, dm);
10103 int shadowRadius = getPropertyInt("ro.watermark.shadow.radius",
10104 TypedValue.COMPLEX_UNIT_PX, 5, dm);
10105 int shadowDx = getPropertyInt("ro.watermark.shadow.dx",
10106 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10107 int shadowDy = getPropertyInt("ro.watermark.shadow.dy",
10108 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10109 int shadowColor = getPropertyInt("ro.watermark.shadow.color",
10110 TypedValue.COMPLEX_UNIT_PX, 0xff000000, dm);
10111
10112 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
10113 paint.setTextSize(fontSize);
10114 paint.setColor(color);
10115 paint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
10116 paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10117
10118 FontMetricsInt fm = paint.getFontMetricsInt();
10119 mHeight = fm.descent - fm.ascent + 20;
10120 mWidth = (int)paint.measureText(text) + 20;
10121
10122 try {
10123 mSurface = new Surface(session, 0,
10124 "WatermarkSurface",
10125 -1, mWidth, mHeight, PixelFormat.TRANSLUCENT, 0);
10126 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
10127 Rect dirty = new Rect(0, 0, mWidth, mHeight);
10128 Canvas c = mSurface.lockCanvas(dirty);
10129 c.drawText(text, 10, -fm.ascent+10, paint);
10130 mSurface.unlockCanvasAndPost(c);
10131 mSurface.show();
10132 } catch (OutOfResourcesException e) {
10133 }
10134 }
10135
10136 void positionSurface(int dw, int dh) {
10137 int availW = dw - mWidth;
10138 int availH = dh - mHeight;
10139 mSurface.setPosition((availW*mXPercent)/100,
10140 (availH*mYPercent)/100);
10141 }
10142 }
10143
10144 void createWatermark() {
10145 if (mWatermark != null) {
10146 return;
10147 }
10148
10149 String text = SystemProperties.get("ro.watermark.text");
10150 if (text == null || text.length() <= 0) {
10151 return;
10152 }
10153
10154 mWatermark = new Watermark(mFxSession, text);
10155 }
10156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010157 @Override
10158 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10159 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10160 != PackageManager.PERMISSION_GRANTED) {
10161 pw.println("Permission Denial: can't dump WindowManager from from pid="
10162 + Binder.getCallingPid()
10163 + ", uid=" + Binder.getCallingUid());
10164 return;
10165 }
Romain Guy06882f82009-06-10 13:36:04 -070010166
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010167 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010168 pw.println(" ");
10169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010170 synchronized(mWindowMap) {
10171 pw.println("Current Window Manager state:");
10172 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010173 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010174 pw.print(" Window #"); pw.print(i); pw.print(' ');
10175 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010176 w.dump(pw, " ");
10177 }
10178 if (mInputMethodDialogs.size() > 0) {
10179 pw.println(" ");
10180 pw.println(" Input method dialogs:");
10181 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10182 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010183 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010184 }
10185 }
10186 if (mPendingRemove.size() > 0) {
10187 pw.println(" ");
10188 pw.println(" Remove pending for:");
10189 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10190 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010191 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10192 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010193 w.dump(pw, " ");
10194 }
10195 }
10196 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10197 pw.println(" ");
10198 pw.println(" Windows force removing:");
10199 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10200 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010201 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10202 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010203 w.dump(pw, " ");
10204 }
10205 }
10206 if (mDestroySurface.size() > 0) {
10207 pw.println(" ");
10208 pw.println(" Windows waiting to destroy their surface:");
10209 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10210 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010211 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10212 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010213 w.dump(pw, " ");
10214 }
10215 }
10216 if (mLosingFocus.size() > 0) {
10217 pw.println(" ");
10218 pw.println(" Windows losing focus:");
10219 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10220 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010221 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10222 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010223 w.dump(pw, " ");
10224 }
10225 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010226 if (mResizingWindows.size() > 0) {
10227 pw.println(" ");
10228 pw.println(" Windows waiting to resize:");
10229 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10230 WindowState w = mResizingWindows.get(i);
10231 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10232 pw.print(w); pw.println(":");
10233 w.dump(pw, " ");
10234 }
10235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010236 if (mSessions.size() > 0) {
10237 pw.println(" ");
10238 pw.println(" All active sessions:");
10239 Iterator<Session> it = mSessions.iterator();
10240 while (it.hasNext()) {
10241 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010242 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010243 s.dump(pw, " ");
10244 }
10245 }
10246 if (mTokenMap.size() > 0) {
10247 pw.println(" ");
10248 pw.println(" All tokens:");
10249 Iterator<WindowToken> it = mTokenMap.values().iterator();
10250 while (it.hasNext()) {
10251 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010252 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010253 token.dump(pw, " ");
10254 }
10255 }
10256 if (mTokenList.size() > 0) {
10257 pw.println(" ");
10258 pw.println(" Window token list:");
10259 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010260 pw.print(" #"); pw.print(i); pw.print(": ");
10261 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010262 }
10263 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010264 if (mWallpaperTokens.size() > 0) {
10265 pw.println(" ");
10266 pw.println(" Wallpaper tokens:");
10267 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10268 WindowToken token = mWallpaperTokens.get(i);
10269 pw.print(" Wallpaper #"); pw.print(i);
10270 pw.print(' '); pw.print(token); pw.println(':');
10271 token.dump(pw, " ");
10272 }
10273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010274 if (mAppTokens.size() > 0) {
10275 pw.println(" ");
10276 pw.println(" Application tokens in Z order:");
10277 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010278 pw.print(" App #"); pw.print(i); pw.print(": ");
10279 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 }
10281 }
10282 if (mFinishedStarting.size() > 0) {
10283 pw.println(" ");
10284 pw.println(" Finishing start of application tokens:");
10285 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10286 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010287 pw.print(" Finished Starting #"); pw.print(i);
10288 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 token.dump(pw, " ");
10290 }
10291 }
10292 if (mExitingTokens.size() > 0) {
10293 pw.println(" ");
10294 pw.println(" Exiting tokens:");
10295 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10296 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010297 pw.print(" Exiting #"); pw.print(i);
10298 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010299 token.dump(pw, " ");
10300 }
10301 }
10302 if (mExitingAppTokens.size() > 0) {
10303 pw.println(" ");
10304 pw.println(" Exiting application tokens:");
10305 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10306 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010307 pw.print(" Exiting App #"); pw.print(i);
10308 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010309 token.dump(pw, " ");
10310 }
10311 }
10312 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010313 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10314 pw.print(" mLastFocus="); pw.println(mLastFocus);
10315 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10316 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10317 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010318 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010319 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10320 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10321 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10322 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010323 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10324 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10325 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010326 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10327 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10328 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10329 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010330 if (mDimAnimator != null) {
10331 mDimAnimator.printTo(pw);
10332 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010333 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010334 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010335 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010336 pw.print(mInputMethodAnimLayerAdjustment);
10337 pw.print(" mWallpaperAnimLayerAdjustment=");
10338 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010339 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10340 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010341 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10342 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010343 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10344 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010345 pw.print(" mRotation="); pw.print(mRotation);
10346 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10347 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10348 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10349 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10350 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10351 pw.print(" mNextAppTransition=0x");
10352 pw.print(Integer.toHexString(mNextAppTransition));
10353 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010354 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010355 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010356 if (mNextAppTransitionPackage != null) {
10357 pw.print(" mNextAppTransitionPackage=");
10358 pw.print(mNextAppTransitionPackage);
10359 pw.print(", mNextAppTransitionEnter=0x");
10360 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10361 pw.print(", mNextAppTransitionExit=0x");
10362 pw.print(Integer.toHexString(mNextAppTransitionExit));
10363 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010364 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10365 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010366 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10367 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10368 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10369 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010370 if (mOpeningApps.size() > 0) {
10371 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10372 }
10373 if (mClosingApps.size() > 0) {
10374 pw.print(" mClosingApps="); pw.println(mClosingApps);
10375 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010376 if (mToTopApps.size() > 0) {
10377 pw.print(" mToTopApps="); pw.println(mToTopApps);
10378 }
10379 if (mToBottomApps.size() > 0) {
10380 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10381 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010382 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10383 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010384 }
10385 }
10386
Jeff Brown349703e2010-06-22 01:27:15 -070010387 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010388 public void monitor() {
10389 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010390 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010391 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010392
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010393 /**
10394 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010395 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010396 */
10397 private static class DimAnimator {
10398 Surface mDimSurface;
10399 boolean mDimShown = false;
10400 float mDimCurrentAlpha;
10401 float mDimTargetAlpha;
10402 float mDimDeltaPerMs;
10403 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010404
10405 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010406
10407 DimAnimator (SurfaceSession session) {
10408 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010409 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010410 + mDimSurface + ": CREATE");
10411 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010412 mDimSurface = new Surface(session, 0,
10413 "DimSurface",
10414 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010415 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010416 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010417 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010418 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010419 }
10420 }
10421 }
10422
10423 /**
10424 * Show the dim surface.
10425 */
10426 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010427 if (!mDimShown) {
10428 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10429 dw + "x" + dh + ")");
10430 mDimShown = true;
10431 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010432 mLastDimWidth = dw;
10433 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010434 mDimSurface.setPosition(0, 0);
10435 mDimSurface.setSize(dw, dh);
10436 mDimSurface.show();
10437 } catch (RuntimeException e) {
10438 Slog.w(TAG, "Failure showing dim surface", e);
10439 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010440 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10441 mLastDimWidth = dw;
10442 mLastDimHeight = dh;
10443 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010444 }
10445 }
10446
10447 /**
10448 * Set's the dim surface's layer and update dim parameters that will be used in
10449 * {@link updateSurface} after all windows are examined.
10450 */
10451 void updateParameters(WindowState w, long currentTime) {
10452 mDimSurface.setLayer(w.mAnimLayer-1);
10453
10454 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010455 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010456 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010457 if (mDimTargetAlpha != target) {
10458 // If the desired dim level has changed, then
10459 // start an animation to it.
10460 mLastDimAnimTime = currentTime;
10461 long duration = (w.mAnimating && w.mAnimation != null)
10462 ? w.mAnimation.computeDurationHint()
10463 : DEFAULT_DIM_DURATION;
10464 if (target > mDimTargetAlpha) {
10465 // This is happening behind the activity UI,
10466 // so we can make it run a little longer to
10467 // give a stronger impression without disrupting
10468 // the user.
10469 duration *= DIM_DURATION_MULTIPLIER;
10470 }
10471 if (duration < 1) {
10472 // Don't divide by zero
10473 duration = 1;
10474 }
10475 mDimTargetAlpha = target;
10476 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10477 }
10478 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010479
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010480 /**
10481 * Updating the surface's alpha. Returns true if the animation continues, or returns
10482 * false when the animation is finished and the dim surface is hidden.
10483 */
10484 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10485 if (!dimming) {
10486 if (mDimTargetAlpha != 0) {
10487 mLastDimAnimTime = currentTime;
10488 mDimTargetAlpha = 0;
10489 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10490 }
10491 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010492
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010493 boolean animating = false;
10494 if (mLastDimAnimTime != 0) {
10495 mDimCurrentAlpha += mDimDeltaPerMs
10496 * (currentTime-mLastDimAnimTime);
10497 boolean more = true;
10498 if (displayFrozen) {
10499 // If the display is frozen, there is no reason to animate.
10500 more = false;
10501 } else if (mDimDeltaPerMs > 0) {
10502 if (mDimCurrentAlpha > mDimTargetAlpha) {
10503 more = false;
10504 }
10505 } else if (mDimDeltaPerMs < 0) {
10506 if (mDimCurrentAlpha < mDimTargetAlpha) {
10507 more = false;
10508 }
10509 } else {
10510 more = false;
10511 }
10512
10513 // Do we need to continue animating?
10514 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010515 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010516 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10517 mLastDimAnimTime = currentTime;
10518 mDimSurface.setAlpha(mDimCurrentAlpha);
10519 animating = true;
10520 } else {
10521 mDimCurrentAlpha = mDimTargetAlpha;
10522 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010523 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010524 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10525 mDimSurface.setAlpha(mDimCurrentAlpha);
10526 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010527 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010528 + ": HIDE");
10529 try {
10530 mDimSurface.hide();
10531 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010532 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010533 }
10534 mDimShown = false;
10535 }
10536 }
10537 }
10538 return animating;
10539 }
10540
10541 public void printTo(PrintWriter pw) {
10542 pw.print(" mDimShown="); pw.print(mDimShown);
10543 pw.print(" current="); pw.print(mDimCurrentAlpha);
10544 pw.print(" target="); pw.print(mDimTargetAlpha);
10545 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10546 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10547 }
10548 }
10549
10550 /**
10551 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10552 * This is used for opening/closing transition for apps in compatible mode.
10553 */
10554 private static class FadeInOutAnimation extends Animation {
10555 int mWidth;
10556 boolean mFadeIn;
10557
10558 public FadeInOutAnimation(boolean fadeIn) {
10559 setInterpolator(new AccelerateInterpolator());
10560 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10561 mFadeIn = fadeIn;
10562 }
10563
10564 @Override
10565 protected void applyTransformation(float interpolatedTime, Transformation t) {
10566 float x = interpolatedTime;
10567 if (!mFadeIn) {
10568 x = 1.0f - x; // reverse the interpolation for fade out
10569 }
10570 if (x < 0.5) {
10571 // move the window out of the screen.
10572 t.getMatrix().setTranslate(mWidth, 0);
10573 } else {
10574 t.getMatrix().setTranslate(0, 0);// show
10575 t.setAlpha((x - 0.5f) * 2);
10576 }
10577 }
10578
10579 @Override
10580 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10581 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10582 mWidth = width;
10583 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010584
10585 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010586 public int getZAdjustment() {
10587 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010588 }
10589 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010590}