blob: 59deef3eaefeb2d81cfe7d92689b8cc2a573c7cd [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 Brown46b9ac02010-04-22 18:58:52 -0700109import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -0700111import android.view.InputEvent;
Jeff Brown46b9ac02010-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;
Dianne Hackbornce73c1e2010-04-12 23:11:38 -0700165 static final boolean DEBUG_FREEZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700167 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700168 static final boolean MEASURE_LATENCY = false;
169 static private LatencyTimer lt;
170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 static final boolean PROFILE_ORIENTATION = false;
172 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700173 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 /** How much to multiply the policy's type layer, to reserve room
176 * for multiple windows of the same type and Z-ordering adjustment
177 * with TYPE_LAYER_OFFSET. */
178 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
181 * or below others in the same layer. */
182 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 /** How much to increment the layer for each window, to reserve room
185 * for effect surfaces between them.
186 */
187 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 /** The maximum length we will accept for a loaded animation duration:
190 * this is 10 seconds.
191 */
192 static final int MAX_ANIMATION_DURATION = 10*1000;
193
194 /** Amount of time (in milliseconds) to animate the dim surface from one
195 * value to another, when no window animation is driving it.
196 */
197 static final int DEFAULT_DIM_DURATION = 200;
198
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700199 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
200 * compatible windows.
201 */
202 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 /** Adjustment to time to perform a dim, to make it more dramatic.
205 */
206 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700207
208 // Maximum number of milliseconds to wait for input event injection.
209 // FIXME is this value reasonable?
210 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700211
212 // Default input dispatching timeout in nanoseconds.
213 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 static final int UPDATE_FOCUS_NORMAL = 0;
216 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
217 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
218 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700221 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
223 /**
224 * Condition waited on by {@link #reenableKeyguard} to know the call to
225 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500226 * This is set to true only if mKeyguardTokenWatcher.acquired() has
227 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
Jim Miller284b62e2010-06-08 14:27:42 -0700231 private static final int ALLOW_DISABLE_YES = 1;
232 private static final int ALLOW_DISABLE_NO = 0;
233 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
234 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
235
Mike Lockwood983ee092009-11-22 01:42:24 -0500236 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
237 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700239 if (shouldAllowDisableKeyguard()) {
240 mPolicy.enableKeyguard(false);
241 mKeyguardDisabled = true;
242 } else {
243 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 }
246 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700247 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500248 synchronized (mKeyguardTokenWatcher) {
249 mKeyguardDisabled = false;
250 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 }
252 }
253 };
254
Jim Miller284b62e2010-06-08 14:27:42 -0700255 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
256 @Override
257 public void onReceive(Context context, Intent intent) {
258 mPolicy.enableKeyguard(true);
259 synchronized(mKeyguardTokenWatcher) {
260 // lazily evaluate this next time we're asked to disable keyguard
261 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
262 mKeyguardDisabled = false;
263 }
264 }
265 };
266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 final Context mContext;
268
269 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
274
275 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 /**
280 * All currently active sessions with clients.
281 */
282 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 /**
285 * Mapping from an IWindow IBinder to the server's Window object.
286 * This is also used as the lock for all of our state.
287 */
288 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
289
290 /**
291 * Mapping from a token IBinder to a WindowToken object.
292 */
293 final HashMap<IBinder, WindowToken> mTokenMap =
294 new HashMap<IBinder, WindowToken>();
295
296 /**
297 * The same tokens as mTokenMap, stored in a list for efficient iteration
298 * over them.
299 */
300 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 /**
303 * Window tokens that are in the process of exiting, but still
304 * on screen for animations.
305 */
306 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
307
308 /**
309 * Z-ordered (bottom-most first) list of all application tokens, for
310 * controlling the ordering of windows in different applications. This
311 * contains WindowToken objects.
312 */
313 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
314
315 /**
316 * Application tokens that are in the process of exiting, but still
317 * on screen for animations.
318 */
319 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
320
321 /**
322 * List of window tokens that have finished starting their application,
323 * and now need to have the policy remove their windows.
324 */
325 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
326
327 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700328 * This was the app token that was used to retrieve the last enter
329 * animation. It will be used for the next exit animation.
330 */
331 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800332
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700333 /**
334 * These were the layout params used to retrieve the last enter animation.
335 * They will be used for the next exit animation.
336 */
337 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800338
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700339 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 * Z-ordered (bottom-most first) list of all Window objects.
341 */
Jeff Browne33348b2010-07-15 23:54:05 -0700342 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343
344 /**
345 * Windows that are being resized. Used so we can tell the client about
346 * the resize after closing the transaction in which we resized the
347 * underlying surface.
348 */
349 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
350
351 /**
352 * Windows whose animations have ended and now must be removed.
353 */
354 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
355
356 /**
357 * Windows whose surface should be destroyed.
358 */
359 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
360
361 /**
362 * Windows that have lost input focus and are waiting for the new
363 * focus window to be displayed before they are told about this.
364 */
365 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
366
367 /**
368 * This is set when we have run out of memory, and will either be an empty
369 * list or contain windows that need to be force removed.
370 */
371 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700376 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 Surface mBlurSurface;
378 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700379 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 final float[] mTmpFloats = new float[9];
384
385 boolean mSafeMode;
386 boolean mDisplayEnabled = false;
387 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700388 int mInitialDisplayWidth = 0;
389 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 int mRotation = 0;
391 int mRequestedRotation = 0;
392 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700393 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 ArrayList<IRotationWatcher> mRotationWatchers
395 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 boolean mLayoutNeeded = true;
398 boolean mAnimationPending = false;
399 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800400 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 boolean mWindowsFreezingScreen = false;
402 long mFreezeGcPending = 0;
403 int mAppsFreezingScreen = 0;
404
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800405 int mLayoutSeq = 0;
406
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800407 // State while inside of layoutAndPlaceSurfacesLocked().
408 boolean mFocusMayChange;
409
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800410 Configuration mCurConfiguration = new Configuration();
411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 // This is held as long as we have the screen frozen, to give us time to
413 // perform a rotation animation when turning off shows the lock screen which
414 // changes the orientation.
415 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 // State management of app transitions. When we are preparing for a
418 // transition, mNextAppTransition will be the kind of transition to
419 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
420 // mOpeningApps and mClosingApps are the lists of tokens that will be
421 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700422 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700423 String mNextAppTransitionPackage;
424 int mNextAppTransitionEnter;
425 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700427 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 boolean mAppTransitionTimeout = false;
429 boolean mStartingIconInTransition = false;
430 boolean mSkipAppTransitionAnimation = false;
431 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
432 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700433 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
434 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 H mH = new H();
439
440 WindowState mCurrentFocus = null;
441 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 // This just indicates the window the input method is on top of, not
444 // necessarily the window its input is going to.
445 WindowState mInputMethodTarget = null;
446 WindowState mUpcomingInputMethodTarget = null;
447 boolean mInputMethodTargetWaitingAnim;
448 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 WindowState mInputMethodWindow = null;
451 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
452
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700453 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800454
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700455 // If non-null, this is the currently visible window that is associated
456 // with the wallpaper.
457 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700458 // If non-null, we are in the middle of animating from one wallpaper target
459 // to another, and this is the lower one in Z-order.
460 WindowState mLowerWallpaperTarget = null;
461 // If non-null, we are in the middle of animating from one wallpaper target
462 // to another, and this is the higher one in Z-order.
463 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700464 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700465 float mLastWallpaperX = -1;
466 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800467 float mLastWallpaperXStep = -1;
468 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700469 // This is set when we are waiting for a wallpaper to tell us it is done
470 // changing its scroll position.
471 WindowState mWaitingOnWallpaper;
472 // The last time we had a timeout when waiting for a wallpaper.
473 long mLastWallpaperTimeoutTime;
474 // We give a wallpaper up to 150ms to finish scrolling.
475 static final long WALLPAPER_TIMEOUT = 150;
476 // Time we wait after a timeout before trying to wait again.
477 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 AppWindowToken mFocusedApp = null;
480
481 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 float mWindowAnimationScale = 1.0f;
484 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700485
Jeff Brown46b9ac02010-04-22 18:58:52 -0700486 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487
488 // Who is holding the screen on.
489 Session mHoldingScreenOn;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700490 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700491
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700492 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 /**
495 * Whether the UI is currently running in touch mode (not showing
496 * navigational focus because the user is directly pressing the screen).
497 */
498 boolean mInTouchMode = false;
499
500 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700501 private ArrayList<WindowChangeListener> mWindowChangeListeners =
502 new ArrayList<WindowChangeListener>();
503 private boolean mWindowsChanged = false;
504
505 public interface WindowChangeListener {
506 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700507 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700508 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509
Dianne Hackbornc485a602009-03-24 22:39:49 -0700510 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700511 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700512
513 // The frame use to limit the size of the app running in compatibility mode.
514 Rect mCompatibleScreenFrame = new Rect();
515 // The surface used to fill the outer rim of the app running in compatibility mode.
516 Surface mBackgroundFillerSurface = null;
517 boolean mBackgroundFillerShown = false;
518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 public static WindowManagerService main(Context context,
520 PowerManagerService pm, boolean haveInputMethods) {
521 WMThread thr = new WMThread(context, pm, haveInputMethods);
522 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 synchronized (thr) {
525 while (thr.mService == null) {
526 try {
527 thr.wait();
528 } catch (InterruptedException e) {
529 }
530 }
531 }
Romain Guy06882f82009-06-10 13:36:04 -0700532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 return thr.mService;
534 }
Romain Guy06882f82009-06-10 13:36:04 -0700535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 static class WMThread extends Thread {
537 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 private final Context mContext;
540 private final PowerManagerService mPM;
541 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 public WMThread(Context context, PowerManagerService pm,
544 boolean haveInputMethods) {
545 super("WindowManager");
546 mContext = context;
547 mPM = pm;
548 mHaveInputMethods = haveInputMethods;
549 }
Romain Guy06882f82009-06-10 13:36:04 -0700550
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 public void run() {
552 Looper.prepare();
553 WindowManagerService s = new WindowManagerService(mContext, mPM,
554 mHaveInputMethods);
555 android.os.Process.setThreadPriority(
556 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700557 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 synchronized (this) {
560 mService = s;
561 notifyAll();
562 }
Romain Guy06882f82009-06-10 13:36:04 -0700563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 Looper.loop();
565 }
566 }
567
568 static class PolicyThread extends Thread {
569 private final WindowManagerPolicy mPolicy;
570 private final WindowManagerService mService;
571 private final Context mContext;
572 private final PowerManagerService mPM;
573 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 public PolicyThread(WindowManagerPolicy policy,
576 WindowManagerService service, Context context,
577 PowerManagerService pm) {
578 super("WindowManagerPolicy");
579 mPolicy = policy;
580 mService = service;
581 mContext = context;
582 mPM = pm;
583 }
Romain Guy06882f82009-06-10 13:36:04 -0700584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 public void run() {
586 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800587 WindowManagerPolicyThread.set(this, Looper.myLooper());
588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800590 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 android.os.Process.setThreadPriority(
592 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700593 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 synchronized (this) {
597 mRunning = true;
598 notifyAll();
599 }
Romain Guy06882f82009-06-10 13:36:04 -0700600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 Looper.loop();
602 }
603 }
604
605 private WindowManagerService(Context context, PowerManagerService pm,
606 boolean haveInputMethods) {
Michael Chan53071d62009-05-13 17:29:48 -0700607 if (MEASURE_LATENCY) {
608 lt = new LatencyTimer(100, 1000);
609 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 mContext = context;
612 mHaveInputMethods = haveInputMethods;
613 mLimitedAlphaCompositing = context.getResources().getBoolean(
614 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 mPowerManager = pm;
617 mPowerManager.setPolicy(mPolicy);
618 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
619 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
620 "SCREEN_FROZEN");
621 mScreenFrozenLock.setReferenceCounted(false);
622
623 mActivityManager = ActivityManagerNative.getDefault();
624 mBatteryStats = BatteryStatsService.getService();
625
626 // Get persisted window scale setting
627 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
628 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
629 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
630 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700631
Jim Miller284b62e2010-06-08 14:27:42 -0700632 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
633 IntentFilter filter = new IntentFilter();
634 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
635 mContext.registerReceiver(mBroadcastReceiver, filter);
636
Jeff Brown46b9ac02010-04-22 18:58:52 -0700637 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
638 "KEEP_SCREEN_ON_FLAG");
639 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640
Jeff Browne33348b2010-07-15 23:54:05 -0700641 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
644 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 synchronized (thr) {
647 while (!thr.mRunning) {
648 try {
649 thr.wait();
650 } catch (InterruptedException e) {
651 }
652 }
653 }
Romain Guy06882f82009-06-10 13:36:04 -0700654
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700655 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 // Add ourself to the Watchdog monitors.
658 Watchdog.getInstance().addMonitor(this);
659 }
660
661 @Override
662 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
663 throws RemoteException {
664 try {
665 return super.onTransact(code, data, reply, flags);
666 } catch (RuntimeException e) {
667 // The window manager only throws security exceptions, so let's
668 // log all others.
669 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800670 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 }
672 throw e;
673 }
674 }
675
Jeff Browne33348b2010-07-15 23:54:05 -0700676 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800678 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 TAG, "Adding window " + window + " at "
680 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
681 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700682 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 }
684
Jeff Browne33348b2010-07-15 23:54:05 -0700685 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800687 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 TAG, "Adding window " + window + " at "
689 + i + " of " + mWindows.size() + " (before " + pos + ")");
690 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700691 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693
694 //This method finds out the index of a window that has the same app token as
695 //win. used for z ordering the windows in mWindows
696 private int findIdxBasedOnAppTokens(WindowState win) {
697 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700698 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 int jmax = localmWindows.size();
700 if(jmax == 0) {
701 return -1;
702 }
703 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700704 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 if(wentry.mAppToken == win.mAppToken) {
706 return j;
707 }
708 }
709 return -1;
710 }
Romain Guy06882f82009-06-10 13:36:04 -0700711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
713 final IWindow client = win.mClient;
714 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700715 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 final int N = localmWindows.size();
718 final WindowState attached = win.mAttachedWindow;
719 int i;
720 if (attached == null) {
721 int tokenWindowsPos = token.windows.size();
722 if (token.appWindowToken != null) {
723 int index = tokenWindowsPos-1;
724 if (index >= 0) {
725 // If this application has existing windows, we
726 // simply place the new window on top of them... but
727 // keep the starting window on top.
728 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
729 // Base windows go behind everything else.
730 placeWindowBefore(token.windows.get(0), win);
731 tokenWindowsPos = 0;
732 } else {
733 AppWindowToken atoken = win.mAppToken;
734 if (atoken != null &&
735 token.windows.get(index) == atoken.startingWindow) {
736 placeWindowBefore(token.windows.get(index), win);
737 tokenWindowsPos--;
738 } else {
739 int newIdx = findIdxBasedOnAppTokens(win);
740 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700741 //there is a window above this one associated with the same
742 //apptoken note that the window could be a floating window
743 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800745 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700746 TAG, "Adding window " + win + " at "
747 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700749 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700750 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 }
752 }
753 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800754 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 TAG, "Figuring out where to add app window "
756 + client.asBinder() + " (token=" + token + ")");
757 // Figure out where the window should go, based on the
758 // order of applications.
759 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700760 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 for (i=NA-1; i>=0; i--) {
762 AppWindowToken t = mAppTokens.get(i);
763 if (t == token) {
764 i--;
765 break;
766 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800767
Dianne Hackborna8f60182009-09-01 19:01:50 -0700768 // We haven't reached the token yet; if this token
769 // is not going to the bottom and has windows, we can
770 // use it as an anchor for when we do reach the token.
771 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 pos = t.windows.get(0);
773 }
774 }
775 // We now know the index into the apps. If we found
776 // an app window above, that gives us the position; else
777 // we need to look some more.
778 if (pos != null) {
779 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700780 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 if (atoken != null) {
782 final int NC = atoken.windows.size();
783 if (NC > 0) {
784 WindowState bottom = atoken.windows.get(0);
785 if (bottom.mSubLayer < 0) {
786 pos = bottom;
787 }
788 }
789 }
790 placeWindowBefore(pos, win);
791 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700792 // Continue looking down until we find the first
793 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 while (i >= 0) {
795 AppWindowToken t = mAppTokens.get(i);
796 final int NW = t.windows.size();
797 if (NW > 0) {
798 pos = t.windows.get(NW-1);
799 break;
800 }
801 i--;
802 }
803 if (pos != null) {
804 // Move in front of any windows attached to this
805 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700806 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 if (atoken != null) {
808 final int NC = atoken.windows.size();
809 if (NC > 0) {
810 WindowState top = atoken.windows.get(NC-1);
811 if (top.mSubLayer >= 0) {
812 pos = top;
813 }
814 }
815 }
816 placeWindowAfter(pos, win);
817 } else {
818 // Just search for the start of this layer.
819 final int myLayer = win.mBaseLayer;
820 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700821 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 if (w.mBaseLayer > myLayer) {
823 break;
824 }
825 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800826 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700827 TAG, "Adding window " + win + " at "
828 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700830 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 }
832 }
833 }
834 } else {
835 // Figure out where window should go, based on layer.
836 final int myLayer = win.mBaseLayer;
837 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700838 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 i++;
840 break;
841 }
842 }
843 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800844 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700845 TAG, "Adding window " + win + " at "
846 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700848 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 }
850 if (addToToken) {
851 token.windows.add(tokenWindowsPos, win);
852 }
853
854 } else {
855 // Figure out this window's ordering relative to the window
856 // it is attached to.
857 final int NA = token.windows.size();
858 final int sublayer = win.mSubLayer;
859 int largestSublayer = Integer.MIN_VALUE;
860 WindowState windowWithLargestSublayer = null;
861 for (i=0; i<NA; i++) {
862 WindowState w = token.windows.get(i);
863 final int wSublayer = w.mSubLayer;
864 if (wSublayer >= largestSublayer) {
865 largestSublayer = wSublayer;
866 windowWithLargestSublayer = w;
867 }
868 if (sublayer < 0) {
869 // For negative sublayers, we go below all windows
870 // in the same sublayer.
871 if (wSublayer >= sublayer) {
872 if (addToToken) {
873 token.windows.add(i, win);
874 }
875 placeWindowBefore(
876 wSublayer >= 0 ? attached : w, win);
877 break;
878 }
879 } else {
880 // For positive sublayers, we go above all windows
881 // in the same sublayer.
882 if (wSublayer > sublayer) {
883 if (addToToken) {
884 token.windows.add(i, win);
885 }
886 placeWindowBefore(w, win);
887 break;
888 }
889 }
890 }
891 if (i >= NA) {
892 if (addToToken) {
893 token.windows.add(win);
894 }
895 if (sublayer < 0) {
896 placeWindowBefore(attached, win);
897 } else {
898 placeWindowAfter(largestSublayer >= 0
899 ? windowWithLargestSublayer
900 : attached,
901 win);
902 }
903 }
904 }
Romain Guy06882f82009-06-10 13:36:04 -0700905
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 if (win.mAppToken != null && addToToken) {
907 win.mAppToken.allAppWindows.add(win);
908 }
909 }
Romain Guy06882f82009-06-10 13:36:04 -0700910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 static boolean canBeImeTarget(WindowState w) {
912 final int fl = w.mAttrs.flags
913 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
914 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
915 return w.isVisibleOrAdding();
916 }
917 return false;
918 }
Romain Guy06882f82009-06-10 13:36:04 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700921 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 final int N = localmWindows.size();
923 WindowState w = null;
924 int i = N;
925 while (i > 0) {
926 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700927 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700928
Joe Onorato8a9b2202010-02-26 18:56:32 -0800929 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 // + Integer.toHexString(w.mAttrs.flags));
931 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800932 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 // Yet more tricksyness! If this window is a "starting"
935 // window, we do actually want to be on top of it, but
936 // it is not -really- where input will go. So if the caller
937 // is not actually looking to move the IME, look down below
938 // for a real window to target...
939 if (!willMove
940 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
941 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700942 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
944 i--;
945 w = wb;
946 }
947 }
948 break;
949 }
950 }
Romain Guy06882f82009-06-10 13:36:04 -0700951
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700953
Joe Onorato8a9b2202010-02-26 18:56:32 -0800954 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 if (willMove && w != null) {
958 final WindowState curTarget = mInputMethodTarget;
959 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 // Now some fun for dealing with window animations that
962 // modify the Z order. We need to look at all windows below
963 // the current target that are in this app, finding the highest
964 // visible one in layering.
965 AppWindowToken token = curTarget.mAppToken;
966 WindowState highestTarget = null;
967 int highestPos = 0;
968 if (token.animating || token.animation != null) {
969 int pos = 0;
970 pos = localmWindows.indexOf(curTarget);
971 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700972 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 if (win.mAppToken != token) {
974 break;
975 }
976 if (!win.mRemoved) {
977 if (highestTarget == null || win.mAnimLayer >
978 highestTarget.mAnimLayer) {
979 highestTarget = win;
980 highestPos = pos;
981 }
982 }
983 pos--;
984 }
985 }
Romain Guy06882f82009-06-10 13:36:04 -0700986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800988 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 + mNextAppTransition + " " + highestTarget
990 + " animating=" + highestTarget.isAnimating()
991 + " layer=" + highestTarget.mAnimLayer
992 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700993
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700994 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 // If we are currently setting up for an animation,
996 // hold everything until we can find out what will happen.
997 mInputMethodTargetWaitingAnim = true;
998 mInputMethodTarget = highestTarget;
999 return highestPos + 1;
1000 } else if (highestTarget.isAnimating() &&
1001 highestTarget.mAnimLayer > w.mAnimLayer) {
1002 // If the window we are currently targeting is involved
1003 // with an animation, and it is on top of the next target
1004 // we will be over, then hold off on moving until
1005 // that is done.
1006 mInputMethodTarget = highestTarget;
1007 return highestPos + 1;
1008 }
1009 }
1010 }
1011 }
Romain Guy06882f82009-06-10 13:36:04 -07001012
Joe Onorato8a9b2202010-02-26 18:56:32 -08001013 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 if (w != null) {
1015 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001016 if (DEBUG_INPUT_METHOD) {
1017 RuntimeException e = null;
1018 if (!HIDE_STACK_CRAWLS) {
1019 e = new RuntimeException();
1020 e.fillInStackTrace();
1021 }
1022 Slog.w(TAG, "Moving IM target from "
1023 + mInputMethodTarget + " to " + w, e);
1024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 mInputMethodTarget = w;
1026 if (w.mAppToken != null) {
1027 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1028 } else {
1029 setInputMethodAnimLayerAdjustment(0);
1030 }
1031 }
1032 return i+1;
1033 }
1034 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001035 if (DEBUG_INPUT_METHOD) {
1036 RuntimeException e = null;
1037 if (!HIDE_STACK_CRAWLS) {
1038 e = new RuntimeException();
1039 e.fillInStackTrace();
1040 }
1041 Slog.w(TAG, "Moving IM target from "
1042 + mInputMethodTarget + " to null", e);
1043 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 mInputMethodTarget = null;
1045 setInputMethodAnimLayerAdjustment(0);
1046 }
1047 return -1;
1048 }
Romain Guy06882f82009-06-10 13:36:04 -07001049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 void addInputMethodWindowToListLocked(WindowState win) {
1051 int pos = findDesiredInputMethodWindowIndexLocked(true);
1052 if (pos >= 0) {
1053 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001054 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001055 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001057 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 moveInputMethodDialogsLocked(pos+1);
1059 return;
1060 }
1061 win.mTargetAppToken = null;
1062 addWindowToListInOrderLocked(win, true);
1063 moveInputMethodDialogsLocked(pos);
1064 }
Romain Guy06882f82009-06-10 13:36:04 -07001065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001067 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 mInputMethodAnimLayerAdjustment = adj;
1069 WindowState imw = mInputMethodWindow;
1070 if (imw != null) {
1071 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 + " anim layer: " + imw.mAnimLayer);
1074 int wi = imw.mChildWindows.size();
1075 while (wi > 0) {
1076 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001077 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001079 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 + " anim layer: " + cw.mAnimLayer);
1081 }
1082 }
1083 int di = mInputMethodDialogs.size();
1084 while (di > 0) {
1085 di --;
1086 imw = mInputMethodDialogs.get(di);
1087 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001088 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 + " anim layer: " + imw.mAnimLayer);
1090 }
1091 }
Romain Guy06882f82009-06-10 13:36:04 -07001092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1094 int wpos = mWindows.indexOf(win);
1095 if (wpos >= 0) {
1096 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001097 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001099 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 int NC = win.mChildWindows.size();
1101 while (NC > 0) {
1102 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001103 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 int cpos = mWindows.indexOf(cw);
1105 if (cpos >= 0) {
1106 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001107 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001108 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 mWindows.remove(cpos);
1110 }
1111 }
1112 }
1113 return interestingPos;
1114 }
Romain Guy06882f82009-06-10 13:36:04 -07001115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 private void reAddWindowToListInOrderLocked(WindowState win) {
1117 addWindowToListInOrderLocked(win, false);
1118 // This is a hack to get all of the child windows added as well
1119 // at the right position. Child windows should be rare and
1120 // this case should be rare, so it shouldn't be that big a deal.
1121 int wpos = mWindows.indexOf(win);
1122 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001123 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001124 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001126 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 reAddWindowLocked(wpos, win);
1128 }
1129 }
Romain Guy06882f82009-06-10 13:36:04 -07001130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 void logWindowList(String prefix) {
1132 int N = mWindows.size();
1133 while (N > 0) {
1134 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001135 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 }
1137 }
Romain Guy06882f82009-06-10 13:36:04 -07001138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 void moveInputMethodDialogsLocked(int pos) {
1140 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001143 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 for (int i=0; i<N; i++) {
1145 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1146 }
1147 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001148 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001149 logWindowList(" ");
1150 }
Romain Guy06882f82009-06-10 13:36:04 -07001151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 if (pos >= 0) {
1153 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1154 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001155 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 if (wp == mInputMethodWindow) {
1157 pos++;
1158 }
1159 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001160 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 for (int i=0; i<N; i++) {
1162 WindowState win = dialogs.get(i);
1163 win.mTargetAppToken = targetAppToken;
1164 pos = reAddWindowLocked(pos, win);
1165 }
1166 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001167 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 logWindowList(" ");
1169 }
1170 return;
1171 }
1172 for (int i=0; i<N; i++) {
1173 WindowState win = dialogs.get(i);
1174 win.mTargetAppToken = null;
1175 reAddWindowToListInOrderLocked(win);
1176 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001177 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 logWindowList(" ");
1179 }
1180 }
1181 }
Romain Guy06882f82009-06-10 13:36:04 -07001182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1184 final WindowState imWin = mInputMethodWindow;
1185 final int DN = mInputMethodDialogs.size();
1186 if (imWin == null && DN == 0) {
1187 return false;
1188 }
Romain Guy06882f82009-06-10 13:36:04 -07001189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1191 if (imPos >= 0) {
1192 // In this case, the input method windows are to be placed
1193 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 // First check to see if the input method windows are already
1196 // located here, and contiguous.
1197 final int N = mWindows.size();
1198 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001199 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 // Figure out the actual input method window that should be
1202 // at the bottom of their stack.
1203 WindowState baseImWin = imWin != null
1204 ? imWin : mInputMethodDialogs.get(0);
1205 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001206 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 if (cw.mSubLayer < 0) baseImWin = cw;
1208 }
Romain Guy06882f82009-06-10 13:36:04 -07001209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 if (firstImWin == baseImWin) {
1211 // The windows haven't moved... but are they still contiguous?
1212 // First find the top IM window.
1213 int pos = imPos+1;
1214 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001215 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 break;
1217 }
1218 pos++;
1219 }
1220 pos++;
1221 // Now there should be no more input method windows above.
1222 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001223 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 break;
1225 }
1226 pos++;
1227 }
1228 if (pos >= N) {
1229 // All is good!
1230 return false;
1231 }
1232 }
Romain Guy06882f82009-06-10 13:36:04 -07001233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 if (imWin != null) {
1235 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001236 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 logWindowList(" ");
1238 }
1239 imPos = tmpRemoveWindowLocked(imPos, imWin);
1240 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001241 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 logWindowList(" ");
1243 }
1244 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1245 reAddWindowLocked(imPos, imWin);
1246 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001247 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 logWindowList(" ");
1249 }
1250 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1251 } else {
1252 moveInputMethodDialogsLocked(imPos);
1253 }
Romain Guy06882f82009-06-10 13:36:04 -07001254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 } else {
1256 // In this case, the input method windows go in a fixed layer,
1257 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001260 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 tmpRemoveWindowLocked(0, imWin);
1262 imWin.mTargetAppToken = null;
1263 reAddWindowToListInOrderLocked(imWin);
1264 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001265 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266 logWindowList(" ");
1267 }
1268 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1269 } else {
1270 moveInputMethodDialogsLocked(-1);;
1271 }
Romain Guy06882f82009-06-10 13:36:04 -07001272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 if (needAssignLayers) {
1276 assignLayersLocked();
1277 }
Romain Guy06882f82009-06-10 13:36:04 -07001278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 return true;
1280 }
Romain Guy06882f82009-06-10 13:36:04 -07001281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001282 void adjustInputMethodDialogsLocked() {
1283 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1284 }
Romain Guy06882f82009-06-10 13:36:04 -07001285
Dianne Hackborn25994b42009-09-04 14:21:19 -07001286 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001287 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001288 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1289 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1290 ? wallpaperTarget.mAppToken.animation : null)
1291 + " upper=" + mUpperWallpaperTarget
1292 + " lower=" + mLowerWallpaperTarget);
1293 return (wallpaperTarget != null
1294 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1295 && wallpaperTarget.mAppToken.animation != null)))
1296 || mUpperWallpaperTarget != null
1297 || mLowerWallpaperTarget != null;
1298 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001299
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001300 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1301 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001302
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001303 int adjustWallpaperWindowsLocked() {
1304 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001305
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001306 final int dw = mDisplay.getWidth();
1307 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001308
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001309 // First find top-most window that has asked to be on top of the
1310 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001311 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001312 int N = localmWindows.size();
1313 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001314 WindowState foundW = null;
1315 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001316 WindowState topCurW = null;
1317 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001318 int i = N;
1319 while (i > 0) {
1320 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001321 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001322 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1323 if (topCurW == null) {
1324 topCurW = w;
1325 topCurI = i;
1326 }
1327 continue;
1328 }
1329 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001330 if (w.mAppToken != null) {
1331 // If this window's app token is hidden and not animating,
1332 // it is of no interest to us.
1333 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001334 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001335 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001336 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001337 continue;
1338 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001339 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001340 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001341 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1342 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001343 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001344 && (mWallpaperTarget == w
1345 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001346 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001347 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001348 foundW = w;
1349 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001350 if (w == mWallpaperTarget && ((w.mAppToken != null
1351 && w.mAppToken.animation != null)
1352 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001353 // The current wallpaper target is animating, so we'll
1354 // look behind it for another possible target and figure
1355 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001356 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001357 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001358 continue;
1359 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001360 break;
1361 }
1362 }
1363
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001364 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001365 // If we are currently waiting for an app transition, and either
1366 // the current target or the next target are involved with it,
1367 // then hold off on doing anything with the wallpaper.
1368 // Note that we are checking here for just whether the target
1369 // is part of an app token... which is potentially overly aggressive
1370 // (the app token may not be involved in the transition), but good
1371 // enough (we'll just wait until whatever transition is pending
1372 // executes).
1373 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001374 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001375 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001376 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001377 }
1378 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001379 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001381 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001382 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001383 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001384
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001385 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001386 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001387 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001388 + " oldTarget: " + mWallpaperTarget);
1389 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001390
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001391 mLowerWallpaperTarget = null;
1392 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001393
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001394 WindowState oldW = mWallpaperTarget;
1395 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001396
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001397 // Now what is happening... if the current and new targets are
1398 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001399 if (foundW != null && oldW != null) {
1400 boolean oldAnim = oldW.mAnimation != null
1401 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1402 boolean foundAnim = foundW.mAnimation != null
1403 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001404 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001406 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001407 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001408 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001409 int oldI = localmWindows.indexOf(oldW);
1410 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001411 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001412 }
1413 if (oldI >= 0) {
1414 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001415 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001416 + "=" + oldW + "; new#" + foundI
1417 + "=" + foundW);
1418 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001419
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001420 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001421 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001422 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001423 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001424 }
1425 mWallpaperTarget = oldW;
1426 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001427
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001428 // Now set the upper and lower wallpaper targets
1429 // correctly, and make sure that we are positioning
1430 // the wallpaper below the lower.
1431 if (foundI > oldI) {
1432 // The new target is on top of the old one.
1433 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001434 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001435 }
1436 mUpperWallpaperTarget = foundW;
1437 mLowerWallpaperTarget = oldW;
1438 foundW = oldW;
1439 foundI = oldI;
1440 } else {
1441 // The new target is below the old one.
1442 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001443 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001444 }
1445 mUpperWallpaperTarget = oldW;
1446 mLowerWallpaperTarget = foundW;
1447 }
1448 }
1449 }
1450 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001451
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001452 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001453 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001454 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1455 || (mLowerWallpaperTarget.mAppToken != null
1456 && mLowerWallpaperTarget.mAppToken.animation != null);
1457 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1458 || (mUpperWallpaperTarget.mAppToken != null
1459 && mUpperWallpaperTarget.mAppToken.animation != null);
1460 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001461 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001462 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001463 }
1464 mLowerWallpaperTarget = null;
1465 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001466 }
1467 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001468
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001469 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001470 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001471 // The window is visible to the compositor... but is it visible
1472 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001473 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001474 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001475
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001476 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001477 // its layer adjustment. Only do this if we are not transfering
1478 // between two wallpaper targets.
1479 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001480 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001481 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001482
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001483 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1484 * TYPE_LAYER_MULTIPLIER
1485 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001486
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001487 // Now w is the window we are supposed to be behind... but we
1488 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001489 // AND any starting window associated with it, AND below the
1490 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001491 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001492 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001493 if (wb.mBaseLayer < maxLayer &&
1494 wb.mAttachedWindow != foundW &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001495 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001496 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001497 // This window is not related to the previous one in any
1498 // interesting way, so stop here.
1499 break;
1500 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001501 foundW = wb;
1502 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001503 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001504 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001505 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001506 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001507
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001508 if (foundW == null && topCurW != null) {
1509 // There is no wallpaper target, so it goes at the bottom.
1510 // We will assume it is the same place as last time, if known.
1511 foundW = topCurW;
1512 foundI = topCurI+1;
1513 } else {
1514 // Okay i is the position immediately above the wallpaper. Look at
1515 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001516 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001517 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001518
Dianne Hackborn284ac932009-08-28 10:34:25 -07001519 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001520 if (mWallpaperTarget.mWallpaperX >= 0) {
1521 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001522 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001523 }
1524 if (mWallpaperTarget.mWallpaperY >= 0) {
1525 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001526 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001527 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001528 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001529
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001530 // Start stepping backwards from here, ensuring that our wallpaper windows
1531 // are correctly placed.
1532 int curTokenIndex = mWallpaperTokens.size();
1533 while (curTokenIndex > 0) {
1534 curTokenIndex--;
1535 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001536 if (token.hidden == visible) {
1537 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1538 token.hidden = !visible;
1539 // Need to do a layout to ensure the wallpaper now has the
1540 // correct size.
1541 mLayoutNeeded = true;
1542 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001543
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001544 int curWallpaperIndex = token.windows.size();
1545 while (curWallpaperIndex > 0) {
1546 curWallpaperIndex--;
1547 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001548
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001549 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001550 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001551 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001552
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001553 // First, make sure the client has the current visibility
1554 // state.
1555 if (wallpaper.mWallpaperVisible != visible) {
1556 wallpaper.mWallpaperVisible = visible;
1557 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001558 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001559 "Setting visibility of wallpaper " + wallpaper
1560 + ": " + visible);
1561 wallpaper.mClient.dispatchAppVisibility(visible);
1562 } catch (RemoteException e) {
1563 }
1564 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001565
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001566 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001568 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001569
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001570 // First, if this window is at the current index, then all
1571 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001572 if (wallpaper == foundW) {
1573 foundI--;
1574 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001575 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 continue;
1577 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001578
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001579 // The window didn't match... the current wallpaper window,
1580 // wherever it is, is in the wrong place, so make sure it is
1581 // not in the list.
1582 int oldIndex = localmWindows.indexOf(wallpaper);
1583 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001585 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001586 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001587 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001588 if (oldIndex < foundI) {
1589 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001590 }
1591 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001592
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001593 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001594 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001595 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001596 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001597
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001598 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001599 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001600 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001601 }
1602 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001603
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001604 return changed;
1605 }
1606
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001607 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001608 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001609 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001610 mWallpaperAnimLayerAdjustment = adj;
1611 int curTokenIndex = mWallpaperTokens.size();
1612 while (curTokenIndex > 0) {
1613 curTokenIndex--;
1614 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1615 int curWallpaperIndex = token.windows.size();
1616 while (curWallpaperIndex > 0) {
1617 curWallpaperIndex--;
1618 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1619 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001620 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001621 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001622 }
1623 }
1624 }
1625
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001626 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1627 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001628 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001629 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001630 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001631 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001632 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1633 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1634 changed = wallpaperWin.mXOffset != offset;
1635 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001636 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001637 + wallpaperWin + " x: " + offset);
1638 wallpaperWin.mXOffset = offset;
1639 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001640 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001641 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001642 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001643 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001644 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001645
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001646 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001647 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001648 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1649 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1650 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001651 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001652 + wallpaperWin + " y: " + offset);
1653 changed = true;
1654 wallpaperWin.mYOffset = offset;
1655 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001656 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001657 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001658 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001659 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001660 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001661
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001662 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001663 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001664 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001665 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1666 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001667 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001668 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001669 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001670 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001671 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1672 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001673 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001674 if (mWaitingOnWallpaper != null) {
1675 long start = SystemClock.uptimeMillis();
1676 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1677 < start) {
1678 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001679 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001680 "Waiting for offset complete...");
1681 mWindowMap.wait(WALLPAPER_TIMEOUT);
1682 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001684 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001685 if ((start+WALLPAPER_TIMEOUT)
1686 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001687 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001688 + wallpaperWin);
1689 mLastWallpaperTimeoutTime = start;
1690 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001691 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001692 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001693 }
1694 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001695 } catch (RemoteException e) {
1696 }
1697 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001698
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001699 return changed;
1700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001701
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001702 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001703 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001704 if (mWaitingOnWallpaper != null &&
1705 mWaitingOnWallpaper.mClient.asBinder() == window) {
1706 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001707 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001708 }
1709 }
1710 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001711
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001712 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001713 final int dw = mDisplay.getWidth();
1714 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001715
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001716 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001717
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001718 WindowState target = mWallpaperTarget;
1719 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001720 if (target.mWallpaperX >= 0) {
1721 mLastWallpaperX = target.mWallpaperX;
1722 } else if (changingTarget.mWallpaperX >= 0) {
1723 mLastWallpaperX = changingTarget.mWallpaperX;
1724 }
1725 if (target.mWallpaperY >= 0) {
1726 mLastWallpaperY = target.mWallpaperY;
1727 } else if (changingTarget.mWallpaperY >= 0) {
1728 mLastWallpaperY = changingTarget.mWallpaperY;
1729 }
1730 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001731
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001732 int curTokenIndex = mWallpaperTokens.size();
1733 while (curTokenIndex > 0) {
1734 curTokenIndex--;
1735 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1736 int curWallpaperIndex = token.windows.size();
1737 while (curWallpaperIndex > 0) {
1738 curWallpaperIndex--;
1739 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1740 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1741 wallpaper.computeShownFrameLocked();
1742 changed = true;
1743 // We only want to be synchronous with one wallpaper.
1744 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001745 }
1746 }
1747 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001748
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001749 return changed;
1750 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001751
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001752 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001753 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001754 final int dw = mDisplay.getWidth();
1755 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001756
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001757 int curTokenIndex = mWallpaperTokens.size();
1758 while (curTokenIndex > 0) {
1759 curTokenIndex--;
1760 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001761 if (token.hidden == visible) {
1762 token.hidden = !visible;
1763 // Need to do a layout to ensure the wallpaper now has the
1764 // correct size.
1765 mLayoutNeeded = true;
1766 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001767
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001768 int curWallpaperIndex = token.windows.size();
1769 while (curWallpaperIndex > 0) {
1770 curWallpaperIndex--;
1771 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1772 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001773 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001774 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001775
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001776 if (wallpaper.mWallpaperVisible != visible) {
1777 wallpaper.mWallpaperVisible = visible;
1778 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001779 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001780 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001781 + ": " + visible);
1782 wallpaper.mClient.dispatchAppVisibility(visible);
1783 } catch (RemoteException e) {
1784 }
1785 }
1786 }
1787 }
1788 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 public int addWindow(Session session, IWindow client,
1791 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001792 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 int res = mPolicy.checkAddPermission(attrs);
1794 if (res != WindowManagerImpl.ADD_OKAY) {
1795 return res;
1796 }
Romain Guy06882f82009-06-10 13:36:04 -07001797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 boolean reportNewConfig = false;
1799 WindowState attachedWindow = null;
1800 WindowState win = null;
Romain Guy06882f82009-06-10 13:36:04 -07001801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 synchronized(mWindowMap) {
1803 // Instantiating a Display requires talking with the simulator,
1804 // so don't do it until we know the system is mostly up and
1805 // running.
1806 if (mDisplay == null) {
1807 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1808 mDisplay = wm.getDefaultDisplay();
Christopher Tateb696aee2010-04-02 19:08:30 -07001809 mInitialDisplayWidth = mDisplay.getWidth();
1810 mInitialDisplayHeight = mDisplay.getHeight();
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001811 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 reportNewConfig = true;
1813 }
Romain Guy06882f82009-06-10 13:36:04 -07001814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001816 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1818 }
1819
1820 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001821 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001823 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 + attrs.token + ". Aborting.");
1825 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1826 }
1827 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1828 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001829 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 + attrs.token + ". Aborting.");
1831 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1832 }
1833 }
1834
1835 boolean addToken = false;
1836 WindowToken token = mTokenMap.get(attrs.token);
1837 if (token == null) {
1838 if (attrs.type >= FIRST_APPLICATION_WINDOW
1839 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001840 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001841 + attrs.token + ". Aborting.");
1842 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1843 }
1844 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001845 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 + attrs.token + ". Aborting.");
1847 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1848 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001849 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001850 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001851 + attrs.token + ". Aborting.");
1852 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1853 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 token = new WindowToken(attrs.token, -1, false);
1855 addToken = true;
1856 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1857 && attrs.type <= LAST_APPLICATION_WINDOW) {
1858 AppWindowToken atoken = token.appWindowToken;
1859 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001860 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 + token + ". Aborting.");
1862 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1863 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001864 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001865 + token + ". Aborting.");
1866 return WindowManagerImpl.ADD_APP_EXITING;
1867 }
1868 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1869 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001870 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1872 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1873 }
1874 } else if (attrs.type == TYPE_INPUT_METHOD) {
1875 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001876 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 + attrs.token + ". Aborting.");
1878 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1879 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001880 } else if (attrs.type == TYPE_WALLPAPER) {
1881 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001882 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001883 + attrs.token + ". Aborting.");
1884 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 }
1887
1888 win = new WindowState(session, client, token,
1889 attachedWindow, attrs, viewVisibility);
1890 if (win.mDeathRecipient == null) {
1891 // Client has apparently died, so there is no reason to
1892 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001893 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 + " that is dead, aborting.");
1895 return WindowManagerImpl.ADD_APP_EXITING;
1896 }
1897
1898 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 res = mPolicy.prepareAddWindowLw(win, attrs);
1901 if (res != WindowManagerImpl.ADD_OKAY) {
1902 return res;
1903 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001904
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001905 if (outInputChannel != null) {
1906 String name = win.makeInputChannelName();
1907 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1908 win.mInputChannel = inputChannels[0];
1909 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1910
1911 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913
1914 // From now on, no exceptions or errors allowed!
1915
1916 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 if (addToken) {
1921 mTokenMap.put(attrs.token, token);
1922 mTokenList.add(token);
1923 }
1924 win.attach();
1925 mWindowMap.put(client.asBinder(), win);
1926
1927 if (attrs.type == TYPE_APPLICATION_STARTING &&
1928 token.appWindowToken != null) {
1929 token.appWindowToken.startingWindow = win;
1930 }
1931
1932 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 if (attrs.type == TYPE_INPUT_METHOD) {
1935 mInputMethodWindow = win;
1936 addInputMethodWindowToListLocked(win);
1937 imMayMove = false;
1938 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1939 mInputMethodDialogs.add(win);
1940 addWindowToListInOrderLocked(win, true);
1941 adjustInputMethodDialogsLocked();
1942 imMayMove = false;
1943 } else {
1944 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001945 if (attrs.type == TYPE_WALLPAPER) {
1946 mLastWallpaperTimeoutTime = 0;
1947 adjustWallpaperWindowsLocked();
1948 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001949 adjustWallpaperWindowsLocked();
1950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 }
Romain Guy06882f82009-06-10 13:36:04 -07001952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 if (mInTouchMode) {
1958 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1959 }
1960 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1961 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1962 }
Romain Guy06882f82009-06-10 13:36:04 -07001963
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001964 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001966 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1967 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 imMayMove = false;
1969 }
1970 }
Romain Guy06882f82009-06-10 13:36:04 -07001971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001973 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974 }
Romain Guy06882f82009-06-10 13:36:04 -07001975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 assignLayersLocked();
1977 // Don't do layout here, the window must call
1978 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001979
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 //dump();
1981
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001982 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001983 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001984 }
Jeff Brown349703e2010-06-22 01:27:15 -07001985
Joe Onorato8a9b2202010-02-26 18:56:32 -08001986 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 TAG, "New client " + client.asBinder()
1988 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001989
1990 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1991 reportNewConfig = true;
1992 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 }
1994
1995 // sendNewConfiguration() checks caller permissions so we must call it with
1996 // privilege. updateOrientationFromAppTokens() clears and resets the caller
1997 // identity anyway, so it's safe to just clear & restore around this whole
1998 // block.
1999 final long origId = Binder.clearCallingIdentity();
2000 if (reportNewConfig) {
2001 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 }
2003 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 return res;
2006 }
Romain Guy06882f82009-06-10 13:36:04 -07002007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008 public void removeWindow(Session session, IWindow client) {
2009 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002010 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 if (win == null) {
2012 return;
2013 }
2014 removeWindowLocked(session, win);
2015 }
2016 }
Romain Guy06882f82009-06-10 13:36:04 -07002017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 public void removeWindowLocked(Session session, WindowState win) {
2019
Joe Onorato8a9b2202010-02-26 18:56:32 -08002020 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 TAG, "Remove " + win + " client="
2022 + Integer.toHexString(System.identityHashCode(
2023 win.mClient.asBinder()))
2024 + ", surface=" + win.mSurface);
2025
2026 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002027
2028 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002029
Joe Onorato8a9b2202010-02-26 18:56:32 -08002030 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2032 + " mExiting=" + win.mExiting
2033 + " isAnimating=" + win.isAnimating()
2034 + " app-animation="
2035 + (win.mAppToken != null ? win.mAppToken.animation : null)
2036 + " inPendingTransaction="
2037 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2038 + " mDisplayFrozen=" + mDisplayFrozen);
2039 // Visibility of the removed window. Will be used later to update orientation later on.
2040 boolean wasVisible = false;
2041 // First, see if we need to run an animation. If we do, we have
2042 // to hold off on removing the window until the animation is done.
2043 // If the display is frozen, just remove immediately, since the
2044 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002045 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 // If we are not currently running the exit animation, we
2047 // need to see about starting one.
2048 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2051 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2052 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2053 }
2054 // Try starting an animation.
2055 if (applyAnimationLocked(win, transit, false)) {
2056 win.mExiting = true;
2057 }
2058 }
2059 if (win.mExiting || win.isAnimating()) {
2060 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002061 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 win.mExiting = true;
2063 win.mRemoveOnExit = true;
2064 mLayoutNeeded = true;
2065 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2066 performLayoutAndPlaceSurfacesLocked();
2067 if (win.mAppToken != null) {
2068 win.mAppToken.updateReportedVisibilityLocked();
2069 }
2070 //dump();
2071 Binder.restoreCallingIdentity(origId);
2072 return;
2073 }
2074 }
2075
2076 removeWindowInnerLocked(session, win);
2077 // Removing a visible window will effect the computed orientation
2078 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002079 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002080 != mForcedAppOrientation
2081 && updateOrientationFromAppTokensLocked()) {
2082 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 }
2084 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2085 Binder.restoreCallingIdentity(origId);
2086 }
Romain Guy06882f82009-06-10 13:36:04 -07002087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 if (mInputMethodTarget == win) {
2092 moveInputMethodWindowsIfNeededLocked(false);
2093 }
Romain Guy06882f82009-06-10 13:36:04 -07002094
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002095 if (false) {
2096 RuntimeException e = new RuntimeException("here");
2097 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002098 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002099 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101 mPolicy.removeWindowLw(win);
2102 win.removeLocked();
2103
2104 mWindowMap.remove(win.mClient.asBinder());
2105 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002106 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002107 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108
2109 if (mInputMethodWindow == win) {
2110 mInputMethodWindow = null;
2111 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2112 mInputMethodDialogs.remove(win);
2113 }
Romain Guy06882f82009-06-10 13:36:04 -07002114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 final WindowToken token = win.mToken;
2116 final AppWindowToken atoken = win.mAppToken;
2117 token.windows.remove(win);
2118 if (atoken != null) {
2119 atoken.allAppWindows.remove(win);
2120 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002121 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 TAG, "**** Removing window " + win + ": count="
2123 + token.windows.size());
2124 if (token.windows.size() == 0) {
2125 if (!token.explicit) {
2126 mTokenMap.remove(token.token);
2127 mTokenList.remove(token);
2128 } else if (atoken != null) {
2129 atoken.firstWindowDrawn = false;
2130 }
2131 }
2132
2133 if (atoken != null) {
2134 if (atoken.startingWindow == win) {
2135 atoken.startingWindow = null;
2136 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2137 // If this is the last window and we had requested a starting
2138 // transition window, well there is no point now.
2139 atoken.startingData = null;
2140 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2141 // If this is the last window except for a starting transition
2142 // window, we need to get rid of the starting transition.
2143 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002144 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 + ": no more real windows");
2146 }
2147 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2148 mH.sendMessage(m);
2149 }
2150 }
Romain Guy06882f82009-06-10 13:36:04 -07002151
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002152 if (win.mAttrs.type == TYPE_WALLPAPER) {
2153 mLastWallpaperTimeoutTime = 0;
2154 adjustWallpaperWindowsLocked();
2155 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002156 adjustWallpaperWindowsLocked();
2157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 if (!mInLayout) {
2160 assignLayersLocked();
2161 mLayoutNeeded = true;
2162 performLayoutAndPlaceSurfacesLocked();
2163 if (win.mAppToken != null) {
2164 win.mAppToken.updateReportedVisibilityLocked();
2165 }
2166 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002167
2168 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 }
2170
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002171 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2172 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2173 + ": " + msg + " / " + w.mAttrs.getTitle();
2174 if (where != null) {
2175 Slog.i(TAG, str, where);
2176 } else {
2177 Slog.i(TAG, str);
2178 }
2179 }
2180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2182 long origId = Binder.clearCallingIdentity();
2183 try {
2184 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002185 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002187 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 Surface.openTransaction();
2189 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002190 if (SHOW_TRANSACTIONS) logSurface(w,
2191 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 w.mSurface.setTransparentRegionHint(region);
2193 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002194 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 Surface.closeTransaction();
2196 }
2197 }
2198 }
2199 } finally {
2200 Binder.restoreCallingIdentity(origId);
2201 }
2202 }
2203
2204 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002205 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 Rect visibleInsets) {
2207 long origId = Binder.clearCallingIdentity();
2208 try {
2209 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002210 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 if (w != null) {
2212 w.mGivenInsetsPending = false;
2213 w.mGivenContentInsets.set(contentInsets);
2214 w.mGivenVisibleInsets.set(visibleInsets);
2215 w.mTouchableInsets = touchableInsets;
2216 mLayoutNeeded = true;
2217 performLayoutAndPlaceSurfacesLocked();
2218 }
2219 }
2220 } finally {
2221 Binder.restoreCallingIdentity(origId);
2222 }
2223 }
Romain Guy06882f82009-06-10 13:36:04 -07002224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 public void getWindowDisplayFrame(Session session, IWindow client,
2226 Rect outDisplayFrame) {
2227 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002228 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002229 if (win == null) {
2230 outDisplayFrame.setEmpty();
2231 return;
2232 }
2233 outDisplayFrame.set(win.mDisplayFrame);
2234 }
2235 }
2236
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002237 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2238 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002239 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2240 window.mWallpaperX = x;
2241 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002242 window.mWallpaperXStep = xStep;
2243 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002244 if (updateWallpaperOffsetLocked(window, true)) {
2245 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002246 }
2247 }
2248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002249
Dianne Hackborn75804932009-10-20 20:15:20 -07002250 void wallpaperCommandComplete(IBinder window, Bundle result) {
2251 synchronized (mWindowMap) {
2252 if (mWaitingOnWallpaper != null &&
2253 mWaitingOnWallpaper.mClient.asBinder() == window) {
2254 mWaitingOnWallpaper = null;
2255 mWindowMap.notifyAll();
2256 }
2257 }
2258 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002259
Dianne Hackborn75804932009-10-20 20:15:20 -07002260 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2261 String action, int x, int y, int z, Bundle extras, boolean sync) {
2262 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2263 || window == mUpperWallpaperTarget) {
2264 boolean doWait = sync;
2265 int curTokenIndex = mWallpaperTokens.size();
2266 while (curTokenIndex > 0) {
2267 curTokenIndex--;
2268 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2269 int curWallpaperIndex = token.windows.size();
2270 while (curWallpaperIndex > 0) {
2271 curWallpaperIndex--;
2272 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2273 try {
2274 wallpaper.mClient.dispatchWallpaperCommand(action,
2275 x, y, z, extras, sync);
2276 // We only want to be synchronous with one wallpaper.
2277 sync = false;
2278 } catch (RemoteException e) {
2279 }
2280 }
2281 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002282
Dianne Hackborn75804932009-10-20 20:15:20 -07002283 if (doWait) {
2284 // XXX Need to wait for result.
2285 }
2286 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002287
Dianne Hackborn75804932009-10-20 20:15:20 -07002288 return null;
2289 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 public int relayoutWindow(Session session, IWindow client,
2292 WindowManager.LayoutParams attrs, int requestedWidth,
2293 int requestedHeight, int viewVisibility, boolean insetsPending,
2294 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002295 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 boolean displayed = false;
2297 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002298 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002302 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 if (win == null) {
2304 return 0;
2305 }
2306 win.mRequestedWidth = requestedWidth;
2307 win.mRequestedHeight = requestedHeight;
2308
2309 if (attrs != null) {
2310 mPolicy.adjustWindowParamsLw(attrs);
2311 }
Romain Guy06882f82009-06-10 13:36:04 -07002312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 int attrChanges = 0;
2314 int flagChanges = 0;
2315 if (attrs != null) {
2316 flagChanges = win.mAttrs.flags ^= attrs.flags;
2317 attrChanges = win.mAttrs.copyFrom(attrs);
2318 }
2319
Joe Onorato8a9b2202010-02-26 18:56:32 -08002320 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321
2322 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2323 win.mAlpha = attrs.alpha;
2324 }
2325
2326 final boolean scaledWindow =
2327 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2328
2329 if (scaledWindow) {
2330 // requested{Width|Height} Surface's physical size
2331 // attrs.{width|height} Size on screen
2332 win.mHScale = (attrs.width != requestedWidth) ?
2333 (attrs.width / (float)requestedWidth) : 1.0f;
2334 win.mVScale = (attrs.height != requestedHeight) ?
2335 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002336 } else {
2337 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 }
2339
2340 boolean imMayMove = (flagChanges&(
2341 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2342 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 boolean focusMayChange = win.mViewVisibility != viewVisibility
2345 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2346 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002347
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002348 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2349 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002351 win.mRelayoutCalled = true;
2352 final int oldVisibility = win.mViewVisibility;
2353 win.mViewVisibility = viewVisibility;
2354 if (viewVisibility == View.VISIBLE &&
2355 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2356 displayed = !win.isVisibleLw();
2357 if (win.mExiting) {
2358 win.mExiting = false;
2359 win.mAnimation = null;
2360 }
2361 if (win.mDestroying) {
2362 win.mDestroying = false;
2363 mDestroySurface.remove(win);
2364 }
2365 if (oldVisibility == View.GONE) {
2366 win.mEnterAnimationPending = true;
2367 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002368 if (displayed) {
2369 if (win.mSurface != null && !win.mDrawPending
2370 && !win.mCommitDrawPending && !mDisplayFrozen
2371 && mPolicy.isScreenOn()) {
2372 applyEnterAnimationLocked(win);
2373 }
2374 if ((win.mAttrs.flags
2375 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2376 if (DEBUG_VISIBILITY) Slog.v(TAG,
2377 "Relayout window turning screen on: " + win);
2378 win.mTurnOnScreen = true;
2379 }
2380 int diff = 0;
2381 if (win.mConfiguration != mCurConfiguration
2382 && (win.mConfiguration == null
2383 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2384 win.mConfiguration = mCurConfiguration;
2385 if (DEBUG_CONFIGURATION) {
2386 Slog.i(TAG, "Window " + win + " visible with new config: "
2387 + win.mConfiguration + " / 0x"
2388 + Integer.toHexString(diff));
2389 }
2390 outConfig.setTo(mCurConfiguration);
2391 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2394 // To change the format, we need to re-build the surface.
2395 win.destroySurfaceLocked();
2396 displayed = true;
2397 }
2398 try {
2399 Surface surface = win.createSurfaceLocked();
2400 if (surface != null) {
2401 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002402 win.mReportDestroySurface = false;
2403 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002404 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002405 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002407 // For some reason there isn't a surface. Clear the
2408 // caller's object so they see the same state.
2409 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 }
2411 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002412 mInputMonitor.updateInputWindowsLw();
2413
Joe Onorato8a9b2202010-02-26 18:56:32 -08002414 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002415 + client + " (" + win.mAttrs.getTitle() + ")",
2416 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 Binder.restoreCallingIdentity(origId);
2418 return 0;
2419 }
2420 if (displayed) {
2421 focusMayChange = true;
2422 }
2423 if (win.mAttrs.type == TYPE_INPUT_METHOD
2424 && mInputMethodWindow == null) {
2425 mInputMethodWindow = win;
2426 imMayMove = true;
2427 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002428 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2429 && win.mAppToken != null
2430 && win.mAppToken.startingWindow != null) {
2431 // Special handling of starting window over the base
2432 // window of the app: propagate lock screen flags to it,
2433 // to provide the correct semantics while starting.
2434 final int mask =
2435 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002436 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2437 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002438 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2439 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 } else {
2442 win.mEnterAnimationPending = false;
2443 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002444 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002445 + ": mExiting=" + win.mExiting
2446 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 // If we are not currently running the exit animation, we
2448 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002449 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 // Try starting an animation; if there isn't one, we
2451 // can destroy the surface right away.
2452 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2453 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2454 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2455 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002456 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002458 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 } else if (win.isAnimating()) {
2461 // Currently in a hide animation... turn this into
2462 // an exit.
2463 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002464 } else if (win == mWallpaperTarget) {
2465 // If the wallpaper is currently behind this
2466 // window, we need to change both of them inside
2467 // of a transaction to avoid artifacts.
2468 win.mExiting = true;
2469 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 } else {
2471 if (mInputMethodWindow == win) {
2472 mInputMethodWindow = null;
2473 }
2474 win.destroySurfaceLocked();
2475 }
2476 }
2477 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002478
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002479 if (win.mSurface == null || (win.getAttrs().flags
2480 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2481 || win.mSurfacePendingDestroy) {
2482 // We are being called from a local process, which
2483 // means outSurface holds its current surface. Ensure the
2484 // surface object is cleared, but we don't want it actually
2485 // destroyed at this point.
2486 win.mSurfacePendingDestroy = false;
2487 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002488 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002489 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002490 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002491 "Keeping surface, will report destroy: " + win);
2492 win.mReportDestroySurface = true;
2493 outSurface.copyFrom(win.mSurface);
2494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 }
2496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 if (focusMayChange) {
2498 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2499 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 imMayMove = false;
2501 }
2502 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2503 }
Romain Guy06882f82009-06-10 13:36:04 -07002504
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002505 // updateFocusedWindowLocked() already assigned layers so we only need to
2506 // reassign them at this point if the IM window state gets shuffled
2507 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002510 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2511 // Little hack here -- we -should- be able to rely on the
2512 // function to return true if the IME has moved and needs
2513 // its layer recomputed. However, if the IME was hidden
2514 // and isn't actually moved in the list, its layer may be
2515 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 assignLayers = true;
2517 }
2518 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002519 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002520 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002521 assignLayers = true;
2522 }
2523 }
Romain Guy06882f82009-06-10 13:36:04 -07002524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 mLayoutNeeded = true;
2526 win.mGivenInsetsPending = insetsPending;
2527 if (assignLayers) {
2528 assignLayersLocked();
2529 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002530 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002532 if (displayed && win.mIsWallpaper) {
2533 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002534 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 if (win.mAppToken != null) {
2537 win.mAppToken.updateReportedVisibilityLocked();
2538 }
2539 outFrame.set(win.mFrame);
2540 outContentInsets.set(win.mContentInsets);
2541 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002542 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002544 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 + ", requestedHeight=" + requestedHeight
2546 + ", viewVisibility=" + viewVisibility
2547 + "\nRelayout returning frame=" + outFrame
2548 + ", surface=" + outSurface);
2549
Joe Onorato8a9b2202010-02-26 18:56:32 -08002550 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2552
2553 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002554
2555 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 }
2557
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002558 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 sendNewConfiguration();
2560 }
Romain Guy06882f82009-06-10 13:36:04 -07002561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2565 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2566 }
2567
2568 public void finishDrawingWindow(Session session, IWindow client) {
2569 final long origId = Binder.clearCallingIdentity();
2570 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002571 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002573 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2574 adjustWallpaperWindowsLocked();
2575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 mLayoutNeeded = true;
2577 performLayoutAndPlaceSurfacesLocked();
2578 }
2579 }
2580 Binder.restoreCallingIdentity(origId);
2581 }
2582
2583 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002584 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 + (lp != null ? lp.packageName : null)
2586 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2587 if (lp != null && lp.windowAnimations != 0) {
2588 // If this is a system resource, don't try to load it from the
2589 // application resources. It is nice to avoid loading application
2590 // resources if we can.
2591 String packageName = lp.packageName != null ? lp.packageName : "android";
2592 int resId = lp.windowAnimations;
2593 if ((resId&0xFF000000) == 0x01000000) {
2594 packageName = "android";
2595 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002596 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002597 + packageName);
2598 return AttributeCache.instance().get(packageName, resId,
2599 com.android.internal.R.styleable.WindowAnimation);
2600 }
2601 return null;
2602 }
Romain Guy06882f82009-06-10 13:36:04 -07002603
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002604 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002605 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002606 + packageName + " resId=0x" + Integer.toHexString(resId));
2607 if (packageName != null) {
2608 if ((resId&0xFF000000) == 0x01000000) {
2609 packageName = "android";
2610 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002611 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002612 + packageName);
2613 return AttributeCache.instance().get(packageName, resId,
2614 com.android.internal.R.styleable.WindowAnimation);
2615 }
2616 return null;
2617 }
2618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 private void applyEnterAnimationLocked(WindowState win) {
2620 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2621 if (win.mEnterAnimationPending) {
2622 win.mEnterAnimationPending = false;
2623 transit = WindowManagerPolicy.TRANSIT_ENTER;
2624 }
2625
2626 applyAnimationLocked(win, transit, true);
2627 }
2628
2629 private boolean applyAnimationLocked(WindowState win,
2630 int transit, boolean isEntrance) {
2631 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2632 // If we are trying to apply an animation, but already running
2633 // an animation of the same type, then just leave that one alone.
2634 return true;
2635 }
Romain Guy06882f82009-06-10 13:36:04 -07002636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637 // Only apply an animation if the display isn't frozen. If it is
2638 // frozen, there is no reason to animate and it can cause strange
2639 // artifacts when we unfreeze the display if some different animation
2640 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002641 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 int anim = mPolicy.selectAnimationLw(win, transit);
2643 int attr = -1;
2644 Animation a = null;
2645 if (anim != 0) {
2646 a = AnimationUtils.loadAnimation(mContext, anim);
2647 } else {
2648 switch (transit) {
2649 case WindowManagerPolicy.TRANSIT_ENTER:
2650 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2651 break;
2652 case WindowManagerPolicy.TRANSIT_EXIT:
2653 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2654 break;
2655 case WindowManagerPolicy.TRANSIT_SHOW:
2656 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2657 break;
2658 case WindowManagerPolicy.TRANSIT_HIDE:
2659 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2660 break;
2661 }
2662 if (attr >= 0) {
2663 a = loadAnimation(win.mAttrs, attr);
2664 }
2665 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002666 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2668 + " mAnimation=" + win.mAnimation
2669 + " isEntrance=" + isEntrance);
2670 if (a != null) {
2671 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002672 RuntimeException e = null;
2673 if (!HIDE_STACK_CRAWLS) {
2674 e = new RuntimeException();
2675 e.fillInStackTrace();
2676 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002677 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678 }
2679 win.setAnimation(a);
2680 win.mAnimationIsEntrance = isEntrance;
2681 }
2682 } else {
2683 win.clearAnimation();
2684 }
2685
2686 return win.mAnimation != null;
2687 }
2688
2689 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2690 int anim = 0;
2691 Context context = mContext;
2692 if (animAttr >= 0) {
2693 AttributeCache.Entry ent = getCachedAnimations(lp);
2694 if (ent != null) {
2695 context = ent.context;
2696 anim = ent.array.getResourceId(animAttr, 0);
2697 }
2698 }
2699 if (anim != 0) {
2700 return AnimationUtils.loadAnimation(context, anim);
2701 }
2702 return null;
2703 }
Romain Guy06882f82009-06-10 13:36:04 -07002704
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002705 private Animation loadAnimation(String packageName, int resId) {
2706 int anim = 0;
2707 Context context = mContext;
2708 if (resId >= 0) {
2709 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2710 if (ent != null) {
2711 context = ent.context;
2712 anim = resId;
2713 }
2714 }
2715 if (anim != 0) {
2716 return AnimationUtils.loadAnimation(context, anim);
2717 }
2718 return null;
2719 }
2720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002721 private boolean applyAnimationLocked(AppWindowToken wtoken,
2722 WindowManager.LayoutParams lp, int transit, boolean enter) {
2723 // Only apply an animation if the display isn't frozen. If it is
2724 // frozen, there is no reason to animate and it can cause strange
2725 // artifacts when we unfreeze the display if some different animation
2726 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002727 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002728 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002729 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002730 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002731 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002732 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002733 } else if (mNextAppTransitionPackage != null) {
2734 a = loadAnimation(mNextAppTransitionPackage, enter ?
2735 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002736 } else {
2737 int animAttr = 0;
2738 switch (transit) {
2739 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2740 animAttr = enter
2741 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2742 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2743 break;
2744 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2745 animAttr = enter
2746 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2747 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2748 break;
2749 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2750 animAttr = enter
2751 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2752 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2753 break;
2754 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2755 animAttr = enter
2756 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2757 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2758 break;
2759 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2760 animAttr = enter
2761 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2762 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2763 break;
2764 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2765 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002766 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002767 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2768 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002769 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002770 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002771 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2772 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002773 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002774 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002775 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002776 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2777 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2778 break;
2779 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2780 animAttr = enter
2781 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2782 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2783 break;
2784 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2785 animAttr = enter
2786 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2787 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002788 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002789 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002790 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002791 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002792 + " anim=" + a
2793 + " animAttr=0x" + Integer.toHexString(animAttr)
2794 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 if (a != null) {
2797 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002798 RuntimeException e = null;
2799 if (!HIDE_STACK_CRAWLS) {
2800 e = new RuntimeException();
2801 e.fillInStackTrace();
2802 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002803 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 }
2805 wtoken.setAnimation(a);
2806 }
2807 } else {
2808 wtoken.clearAnimation();
2809 }
2810
2811 return wtoken.animation != null;
2812 }
2813
2814 // -------------------------------------------------------------
2815 // Application Window Tokens
2816 // -------------------------------------------------------------
2817
2818 public void validateAppTokens(List tokens) {
2819 int v = tokens.size()-1;
2820 int m = mAppTokens.size()-1;
2821 while (v >= 0 && m >= 0) {
2822 AppWindowToken wtoken = mAppTokens.get(m);
2823 if (wtoken.removed) {
2824 m--;
2825 continue;
2826 }
2827 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002828 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2830 }
2831 v--;
2832 m--;
2833 }
2834 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002835 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 v--;
2837 }
2838 while (m >= 0) {
2839 AppWindowToken wtoken = mAppTokens.get(m);
2840 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002841 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 }
2843 m--;
2844 }
2845 }
2846
2847 boolean checkCallingPermission(String permission, String func) {
2848 // Quick check: if the calling permission is me, it's all okay.
2849 if (Binder.getCallingPid() == Process.myPid()) {
2850 return true;
2851 }
Romain Guy06882f82009-06-10 13:36:04 -07002852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 if (mContext.checkCallingPermission(permission)
2854 == PackageManager.PERMISSION_GRANTED) {
2855 return true;
2856 }
2857 String msg = "Permission Denial: " + func + " from pid="
2858 + Binder.getCallingPid()
2859 + ", uid=" + Binder.getCallingUid()
2860 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002861 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 return false;
2863 }
Romain Guy06882f82009-06-10 13:36:04 -07002864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 AppWindowToken findAppWindowToken(IBinder token) {
2866 WindowToken wtoken = mTokenMap.get(token);
2867 if (wtoken == null) {
2868 return null;
2869 }
2870 return wtoken.appWindowToken;
2871 }
Romain Guy06882f82009-06-10 13:36:04 -07002872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 public void addWindowToken(IBinder token, int type) {
2874 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2875 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002876 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 }
Romain Guy06882f82009-06-10 13:36:04 -07002878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 synchronized(mWindowMap) {
2880 WindowToken wtoken = mTokenMap.get(token);
2881 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002882 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 return;
2884 }
2885 wtoken = new WindowToken(token, type, true);
2886 mTokenMap.put(token, wtoken);
2887 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002888 if (type == TYPE_WALLPAPER) {
2889 mWallpaperTokens.add(wtoken);
2890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 }
2892 }
Romain Guy06882f82009-06-10 13:36:04 -07002893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 public void removeWindowToken(IBinder token) {
2895 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2896 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002897 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 }
2899
2900 final long origId = Binder.clearCallingIdentity();
2901 synchronized(mWindowMap) {
2902 WindowToken wtoken = mTokenMap.remove(token);
2903 mTokenList.remove(wtoken);
2904 if (wtoken != null) {
2905 boolean delayed = false;
2906 if (!wtoken.hidden) {
2907 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 final int N = wtoken.windows.size();
2910 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 for (int i=0; i<N; i++) {
2913 WindowState win = wtoken.windows.get(i);
2914
2915 if (win.isAnimating()) {
2916 delayed = true;
2917 }
Romain Guy06882f82009-06-10 13:36:04 -07002918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 if (win.isVisibleNow()) {
2920 applyAnimationLocked(win,
2921 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 changed = true;
2923 }
2924 }
2925
2926 if (changed) {
2927 mLayoutNeeded = true;
2928 performLayoutAndPlaceSurfacesLocked();
2929 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2930 }
Romain Guy06882f82009-06-10 13:36:04 -07002931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 if (delayed) {
2933 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002934 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2935 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936 }
2937 }
Romain Guy06882f82009-06-10 13:36:04 -07002938
Jeff Brownc5ed5912010-07-14 18:48:53 -07002939 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002941 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 }
2943 }
2944 Binder.restoreCallingIdentity(origId);
2945 }
2946
2947 public void addAppToken(int addPos, IApplicationToken token,
2948 int groupId, int requestedOrientation, boolean fullscreen) {
2949 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2950 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002951 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 }
Jeff Brown349703e2010-06-22 01:27:15 -07002953
2954 // Get the dispatching timeout here while we are not holding any locks so that it
2955 // can be cached by the AppWindowToken. The timeout value is used later by the
2956 // input dispatcher in code that does hold locks. If we did not cache the value
2957 // here we would run the chance of introducing a deadlock between the window manager
2958 // (which holds locks while updating the input dispatcher state) and the activity manager
2959 // (which holds locks while querying the application token).
2960 long inputDispatchingTimeoutNanos;
2961 try {
2962 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2963 } catch (RemoteException ex) {
2964 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2965 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2966 }
Romain Guy06882f82009-06-10 13:36:04 -07002967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 synchronized(mWindowMap) {
2969 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2970 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002971 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 return;
2973 }
2974 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002975 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 wtoken.groupId = groupId;
2977 wtoken.appFullscreen = fullscreen;
2978 wtoken.requestedOrientation = requestedOrientation;
2979 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002980 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 mTokenMap.put(token.asBinder(), wtoken);
2982 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 // Application tokens start out hidden.
2985 wtoken.hidden = true;
2986 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 //dump();
2989 }
2990 }
Romain Guy06882f82009-06-10 13:36:04 -07002991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 public void setAppGroupId(IBinder token, int groupId) {
2993 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2994 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002995 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 }
2997
2998 synchronized(mWindowMap) {
2999 AppWindowToken wtoken = findAppWindowToken(token);
3000 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003001 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 return;
3003 }
3004 wtoken.groupId = groupId;
3005 }
3006 }
Romain Guy06882f82009-06-10 13:36:04 -07003007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003008 public int getOrientationFromWindowsLocked() {
3009 int pos = mWindows.size() - 1;
3010 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003011 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 pos--;
3013 if (wtoken.mAppToken != null) {
3014 // We hit an application window. so the orientation will be determined by the
3015 // app window. No point in continuing further.
3016 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3017 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003018 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 continue;
3020 }
3021 int req = wtoken.mAttrs.screenOrientation;
3022 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3023 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3024 continue;
3025 } else {
3026 return req;
3027 }
3028 }
3029 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3030 }
Romain Guy06882f82009-06-10 13:36:04 -07003031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003033 int pos = mAppTokens.size() - 1;
3034 int curGroup = 0;
3035 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3036 boolean findingBehind = false;
3037 boolean haveGroup = false;
3038 boolean lastFullscreen = false;
3039 while (pos >= 0) {
3040 AppWindowToken wtoken = mAppTokens.get(pos);
3041 pos--;
3042 // if we're about to tear down this window and not seek for
3043 // the behind activity, don't use it for orientation
3044 if (!findingBehind
3045 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3046 continue;
3047 }
3048
3049 if (!haveGroup) {
3050 // We ignore any hidden applications on the top.
3051 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003052 continue;
3053 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003054 haveGroup = true;
3055 curGroup = wtoken.groupId;
3056 lastOrientation = wtoken.requestedOrientation;
3057 } else if (curGroup != wtoken.groupId) {
3058 // If we have hit a new application group, and the bottom
3059 // of the previous group didn't explicitly say to use
3060 // the orientation behind it, and the last app was
3061 // full screen, then we'll stick with the
3062 // user's orientation.
3063 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3064 && lastFullscreen) {
3065 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003068 int or = wtoken.requestedOrientation;
3069 // If this application is fullscreen, and didn't explicitly say
3070 // to use the orientation behind it, then just take whatever
3071 // orientation it has and ignores whatever is under it.
3072 lastFullscreen = wtoken.appFullscreen;
3073 if (lastFullscreen
3074 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3075 return or;
3076 }
3077 // If this application has requested an explicit orientation,
3078 // then use it.
3079 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3080 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3081 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3082 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3083 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3084 return or;
3085 }
3086 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3087 }
3088 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 }
Romain Guy06882f82009-06-10 13:36:04 -07003090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003091 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003092 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003093 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3094 "updateOrientationFromAppTokens()")) {
3095 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3096 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003097
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003098 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003100
3101 synchronized(mWindowMap) {
3102 if (updateOrientationFromAppTokensLocked()) {
3103 if (freezeThisOneIfNeeded != null) {
3104 AppWindowToken wtoken = findAppWindowToken(
3105 freezeThisOneIfNeeded);
3106 if (wtoken != null) {
3107 startAppFreezingScreenLocked(wtoken,
3108 ActivityInfo.CONFIG_ORIENTATION);
3109 }
3110 }
3111 config = computeNewConfigurationLocked();
3112
3113 } else if (currentConfig != null) {
3114 // No obvious action we need to take, but if our current
3115 // state mismatches the activity maanager's, update it
3116 mTempConfiguration.setToDefaults();
3117 if (computeNewConfigurationLocked(mTempConfiguration)) {
3118 if (currentConfig.diff(mTempConfiguration) != 0) {
3119 mWaitingForConfig = true;
3120 mLayoutNeeded = true;
3121 startFreezingDisplayLocked();
3122 config = new Configuration(mTempConfiguration);
3123 }
3124 }
3125 }
3126 }
3127
Dianne Hackborncfaef692009-06-15 14:24:44 -07003128 Binder.restoreCallingIdentity(ident);
3129 return config;
3130 }
3131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003132 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003133 * Determine the new desired orientation of the display, returning
3134 * a non-null new Configuration if it has changed from the current
3135 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3136 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3137 * SCREEN. This will typically be done for you if you call
3138 * sendNewConfiguration().
3139 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140 * The orientation is computed from non-application windows first. If none of
3141 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003142 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3144 * android.os.IBinder)
3145 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003146 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003147 if (mDisplayFrozen) {
3148 // If the display is frozen, some activities may be in the middle
3149 // of restarting, and thus have removed their old window. If the
3150 // window has the flag to hide the lock screen, then the lock screen
3151 // can re-appear and inflict its own orientation on us. Keep the
3152 // orientation stable until this all settles down.
3153 return false;
3154 }
3155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003157 long ident = Binder.clearCallingIdentity();
3158 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003159 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 mForcedAppOrientation = req;
3163 //send a message to Policy indicating orientation change to take
3164 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003165 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003166 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3167 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3168 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 }
3170 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003171
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003172 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 } finally {
3174 Binder.restoreCallingIdentity(ident);
3175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 }
Romain Guy06882f82009-06-10 13:36:04 -07003177
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003178 int computeForcedAppOrientationLocked() {
3179 int req = getOrientationFromWindowsLocked();
3180 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3181 req = getOrientationFromAppTokensLocked();
3182 }
3183 return req;
3184 }
Romain Guy06882f82009-06-10 13:36:04 -07003185
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003186 public void setNewConfiguration(Configuration config) {
3187 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3188 "setNewConfiguration()")) {
3189 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3190 }
3191
3192 synchronized(mWindowMap) {
3193 mCurConfiguration = new Configuration(config);
3194 mWaitingForConfig = false;
3195 performLayoutAndPlaceSurfacesLocked();
3196 }
3197 }
3198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3200 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3201 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003202 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003203 }
Romain Guy06882f82009-06-10 13:36:04 -07003204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 synchronized(mWindowMap) {
3206 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3207 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003208 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 return;
3210 }
Romain Guy06882f82009-06-10 13:36:04 -07003211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003212 wtoken.requestedOrientation = requestedOrientation;
3213 }
3214 }
Romain Guy06882f82009-06-10 13:36:04 -07003215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003216 public int getAppOrientation(IApplicationToken token) {
3217 synchronized(mWindowMap) {
3218 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3219 if (wtoken == null) {
3220 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3221 }
Romain Guy06882f82009-06-10 13:36:04 -07003222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 return wtoken.requestedOrientation;
3224 }
3225 }
Romain Guy06882f82009-06-10 13:36:04 -07003226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3228 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3229 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003230 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 }
3232
3233 synchronized(mWindowMap) {
3234 boolean changed = false;
3235 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003236 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 changed = mFocusedApp != null;
3238 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003239 if (changed) {
3240 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 } else {
3243 AppWindowToken newFocus = findAppWindowToken(token);
3244 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003245 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003246 return;
3247 }
3248 changed = mFocusedApp != newFocus;
3249 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003250 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003251 if (changed) {
3252 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 }
3255
3256 if (moveFocusNow && changed) {
3257 final long origId = Binder.clearCallingIdentity();
3258 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3259 Binder.restoreCallingIdentity(origId);
3260 }
3261 }
3262 }
3263
3264 public void prepareAppTransition(int transit) {
3265 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3266 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003267 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 }
Romain Guy06882f82009-06-10 13:36:04 -07003269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003271 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 TAG, "Prepare app transition: transit=" + transit
3273 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003274 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003275 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3276 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003277 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003278 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3279 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3280 // Opening a new task always supersedes a close for the anim.
3281 mNextAppTransition = transit;
3282 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3283 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3284 // Opening a new activity always supersedes a close for the anim.
3285 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003286 }
3287 mAppTransitionReady = false;
3288 mAppTransitionTimeout = false;
3289 mStartingIconInTransition = false;
3290 mSkipAppTransitionAnimation = false;
3291 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3292 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3293 5000);
3294 }
3295 }
3296 }
3297
3298 public int getPendingAppTransition() {
3299 return mNextAppTransition;
3300 }
Romain Guy06882f82009-06-10 13:36:04 -07003301
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003302 public void overridePendingAppTransition(String packageName,
3303 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003304 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003305 mNextAppTransitionPackage = packageName;
3306 mNextAppTransitionEnter = enterAnim;
3307 mNextAppTransitionExit = exitAnim;
3308 }
3309 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 public void executeAppTransition() {
3312 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3313 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003314 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 }
Romain Guy06882f82009-06-10 13:36:04 -07003316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003318 if (DEBUG_APP_TRANSITIONS) {
3319 RuntimeException e = new RuntimeException("here");
3320 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003321 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003322 + mNextAppTransition, e);
3323 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003324 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 mAppTransitionReady = true;
3326 final long origId = Binder.clearCallingIdentity();
3327 performLayoutAndPlaceSurfacesLocked();
3328 Binder.restoreCallingIdentity(origId);
3329 }
3330 }
3331 }
3332
3333 public void setAppStartingWindow(IBinder token, String pkg,
3334 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3335 IBinder transferFrom, boolean createIfNeeded) {
3336 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3337 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003338 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003339 }
3340
3341 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003342 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3344 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 AppWindowToken wtoken = findAppWindowToken(token);
3347 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003348 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 return;
3350 }
3351
3352 // If the display is frozen, we won't do anything until the
3353 // actual window is displayed so there is no reason to put in
3354 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003355 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 return;
3357 }
Romain Guy06882f82009-06-10 13:36:04 -07003358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 if (wtoken.startingData != null) {
3360 return;
3361 }
Romain Guy06882f82009-06-10 13:36:04 -07003362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 if (transferFrom != null) {
3364 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3365 if (ttoken != null) {
3366 WindowState startingWindow = ttoken.startingWindow;
3367 if (startingWindow != null) {
3368 if (mStartingIconInTransition) {
3369 // In this case, the starting icon has already
3370 // been displayed, so start letting windows get
3371 // shown immediately without any more transitions.
3372 mSkipAppTransitionAnimation = true;
3373 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003374 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 "Moving existing starting from " + ttoken
3376 + " to " + wtoken);
3377 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003379 // Transfer the starting window over to the new
3380 // token.
3381 wtoken.startingData = ttoken.startingData;
3382 wtoken.startingView = ttoken.startingView;
3383 wtoken.startingWindow = startingWindow;
3384 ttoken.startingData = null;
3385 ttoken.startingView = null;
3386 ttoken.startingWindow = null;
3387 ttoken.startingMoved = true;
3388 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003389 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003391 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003392 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003394 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 ttoken.windows.remove(startingWindow);
3396 ttoken.allAppWindows.remove(startingWindow);
3397 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003399 // Propagate other interesting state between the
3400 // tokens. If the old token is displayed, we should
3401 // immediately force the new one to be displayed. If
3402 // it is animating, we need to move that animation to
3403 // the new one.
3404 if (ttoken.allDrawn) {
3405 wtoken.allDrawn = true;
3406 }
3407 if (ttoken.firstWindowDrawn) {
3408 wtoken.firstWindowDrawn = true;
3409 }
3410 if (!ttoken.hidden) {
3411 wtoken.hidden = false;
3412 wtoken.hiddenRequested = false;
3413 wtoken.willBeHidden = false;
3414 }
3415 if (wtoken.clientHidden != ttoken.clientHidden) {
3416 wtoken.clientHidden = ttoken.clientHidden;
3417 wtoken.sendAppVisibilityToClients();
3418 }
3419 if (ttoken.animation != null) {
3420 wtoken.animation = ttoken.animation;
3421 wtoken.animating = ttoken.animating;
3422 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3423 ttoken.animation = null;
3424 ttoken.animLayerAdjustment = 0;
3425 wtoken.updateLayers();
3426 ttoken.updateLayers();
3427 }
Romain Guy06882f82009-06-10 13:36:04 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 mLayoutNeeded = true;
3431 performLayoutAndPlaceSurfacesLocked();
3432 Binder.restoreCallingIdentity(origId);
3433 return;
3434 } else if (ttoken.startingData != null) {
3435 // The previous app was getting ready to show a
3436 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003437 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 "Moving pending starting from " + ttoken
3439 + " to " + wtoken);
3440 wtoken.startingData = ttoken.startingData;
3441 ttoken.startingData = null;
3442 ttoken.startingMoved = true;
3443 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3444 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3445 // want to process the message ASAP, before any other queued
3446 // messages.
3447 mH.sendMessageAtFrontOfQueue(m);
3448 return;
3449 }
3450 }
3451 }
3452
3453 // There is no existing starting window, and the caller doesn't
3454 // want us to create one, so that's it!
3455 if (!createIfNeeded) {
3456 return;
3457 }
Romain Guy06882f82009-06-10 13:36:04 -07003458
Dianne Hackborn284ac932009-08-28 10:34:25 -07003459 // If this is a translucent or wallpaper window, then don't
3460 // show a starting window -- the current effect (a full-screen
3461 // opaque starting window that fades away to the real contents
3462 // when it is ready) does not work for this.
3463 if (theme != 0) {
3464 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3465 com.android.internal.R.styleable.Window);
3466 if (ent.array.getBoolean(
3467 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3468 return;
3469 }
3470 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003471 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3472 return;
3473 }
3474 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003475 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3476 return;
3477 }
3478 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 mStartingIconInTransition = true;
3481 wtoken.startingData = new StartingData(
3482 pkg, theme, nonLocalizedLabel,
3483 labelRes, icon);
3484 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3485 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3486 // want to process the message ASAP, before any other queued
3487 // messages.
3488 mH.sendMessageAtFrontOfQueue(m);
3489 }
3490 }
3491
3492 public void setAppWillBeHidden(IBinder token) {
3493 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3494 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003495 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 }
3497
3498 AppWindowToken wtoken;
3499
3500 synchronized(mWindowMap) {
3501 wtoken = findAppWindowToken(token);
3502 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003503 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 -08003504 return;
3505 }
3506 wtoken.willBeHidden = true;
3507 }
3508 }
Romain Guy06882f82009-06-10 13:36:04 -07003509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3511 boolean visible, int transit, boolean performLayout) {
3512 boolean delayed = false;
3513
3514 if (wtoken.clientHidden == visible) {
3515 wtoken.clientHidden = !visible;
3516 wtoken.sendAppVisibilityToClients();
3517 }
Romain Guy06882f82009-06-10 13:36:04 -07003518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 wtoken.willBeHidden = false;
3520 if (wtoken.hidden == visible) {
3521 final int N = wtoken.allAppWindows.size();
3522 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003523 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3525 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003527 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003528
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003529 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 if (wtoken.animation == sDummyAnimation) {
3531 wtoken.animation = null;
3532 }
3533 applyAnimationLocked(wtoken, lp, transit, visible);
3534 changed = true;
3535 if (wtoken.animation != null) {
3536 delayed = runningAppAnimation = true;
3537 }
3538 }
Romain Guy06882f82009-06-10 13:36:04 -07003539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 for (int i=0; i<N; i++) {
3541 WindowState win = wtoken.allAppWindows.get(i);
3542 if (win == wtoken.startingWindow) {
3543 continue;
3544 }
3545
3546 if (win.isAnimating()) {
3547 delayed = true;
3548 }
Romain Guy06882f82009-06-10 13:36:04 -07003549
Joe Onorato8a9b2202010-02-26 18:56:32 -08003550 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003551 //win.dump(" ");
3552 if (visible) {
3553 if (!win.isVisibleNow()) {
3554 if (!runningAppAnimation) {
3555 applyAnimationLocked(win,
3556 WindowManagerPolicy.TRANSIT_ENTER, true);
3557 }
3558 changed = true;
3559 }
3560 } else if (win.isVisibleNow()) {
3561 if (!runningAppAnimation) {
3562 applyAnimationLocked(win,
3563 WindowManagerPolicy.TRANSIT_EXIT, false);
3564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003565 changed = true;
3566 }
3567 }
3568
3569 wtoken.hidden = wtoken.hiddenRequested = !visible;
3570 if (!visible) {
3571 unsetAppFreezingScreenLocked(wtoken, true, true);
3572 } else {
3573 // If we are being set visible, and the starting window is
3574 // not yet displayed, then make sure it doesn't get displayed.
3575 WindowState swin = wtoken.startingWindow;
3576 if (swin != null && (swin.mDrawPending
3577 || swin.mCommitDrawPending)) {
3578 swin.mPolicyVisibility = false;
3579 swin.mPolicyVisibilityAfterAnim = false;
3580 }
3581 }
Romain Guy06882f82009-06-10 13:36:04 -07003582
Joe Onorato8a9b2202010-02-26 18:56:32 -08003583 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3585 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003586
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003587 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003589 if (performLayout) {
3590 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3591 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003592 } else {
3593 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 }
3596 }
3597
3598 if (wtoken.animation != null) {
3599 delayed = true;
3600 }
Romain Guy06882f82009-06-10 13:36:04 -07003601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 return delayed;
3603 }
3604
3605 public void setAppVisibility(IBinder token, boolean visible) {
3606 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3607 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003608 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 }
3610
3611 AppWindowToken wtoken;
3612
3613 synchronized(mWindowMap) {
3614 wtoken = findAppWindowToken(token);
3615 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003616 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 return;
3618 }
3619
3620 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003621 RuntimeException e = null;
3622 if (!HIDE_STACK_CRAWLS) {
3623 e = new RuntimeException();
3624 e.fillInStackTrace();
3625 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003626 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 + "): mNextAppTransition=" + mNextAppTransition
3628 + " hidden=" + wtoken.hidden
3629 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3630 }
Romain Guy06882f82009-06-10 13:36:04 -07003631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 // If we are preparing an app transition, then delay changing
3633 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003634 if (!mDisplayFrozen && mPolicy.isScreenOn()
3635 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003636 // Already in requested state, don't do anything more.
3637 if (wtoken.hiddenRequested != visible) {
3638 return;
3639 }
3640 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003641
Joe Onorato8a9b2202010-02-26 18:56:32 -08003642 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003643 TAG, "Setting dummy animation on: " + wtoken);
3644 wtoken.setDummyAnimation();
3645 mOpeningApps.remove(wtoken);
3646 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003647 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 wtoken.inPendingTransaction = true;
3649 if (visible) {
3650 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 wtoken.startingDisplayed = false;
3652 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003653
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003654 // If the token is currently hidden (should be the
3655 // common case), then we need to set up to wait for
3656 // its windows to be ready.
3657 if (wtoken.hidden) {
3658 wtoken.allDrawn = false;
3659 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003660
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003661 if (wtoken.clientHidden) {
3662 // In the case where we are making an app visible
3663 // but holding off for a transition, we still need
3664 // to tell the client to make its windows visible so
3665 // they get drawn. Otherwise, we will wait on
3666 // performing the transition until all windows have
3667 // been drawn, they never will be, and we are sad.
3668 wtoken.clientHidden = false;
3669 wtoken.sendAppVisibilityToClients();
3670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003671 }
3672 } else {
3673 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003674
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003675 // If the token is currently visible (should be the
3676 // common case), then set up to wait for it to be hidden.
3677 if (!wtoken.hidden) {
3678 wtoken.waitingToHide = true;
3679 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 }
3681 return;
3682 }
Romain Guy06882f82009-06-10 13:36:04 -07003683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003685 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 wtoken.updateReportedVisibilityLocked();
3687 Binder.restoreCallingIdentity(origId);
3688 }
3689 }
3690
3691 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3692 boolean unfreezeSurfaceNow, boolean force) {
3693 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003694 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 + " force=" + force);
3696 final int N = wtoken.allAppWindows.size();
3697 boolean unfrozeWindows = false;
3698 for (int i=0; i<N; i++) {
3699 WindowState w = wtoken.allAppWindows.get(i);
3700 if (w.mAppFreezing) {
3701 w.mAppFreezing = false;
3702 if (w.mSurface != null && !w.mOrientationChanging) {
3703 w.mOrientationChanging = true;
3704 }
3705 unfrozeWindows = true;
3706 }
3707 }
3708 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003709 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 wtoken.freezingScreen = false;
3711 mAppsFreezingScreen--;
3712 }
3713 if (unfreezeSurfaceNow) {
3714 if (unfrozeWindows) {
3715 mLayoutNeeded = true;
3716 performLayoutAndPlaceSurfacesLocked();
3717 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003718 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 }
3720 }
3721 }
Romain Guy06882f82009-06-10 13:36:04 -07003722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3724 int configChanges) {
3725 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003726 RuntimeException e = null;
3727 if (!HIDE_STACK_CRAWLS) {
3728 e = new RuntimeException();
3729 e.fillInStackTrace();
3730 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003731 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003732 + ": hidden=" + wtoken.hidden + " freezing="
3733 + wtoken.freezingScreen, e);
3734 }
3735 if (!wtoken.hiddenRequested) {
3736 if (!wtoken.freezingScreen) {
3737 wtoken.freezingScreen = true;
3738 mAppsFreezingScreen++;
3739 if (mAppsFreezingScreen == 1) {
3740 startFreezingDisplayLocked();
3741 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3742 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3743 5000);
3744 }
3745 }
3746 final int N = wtoken.allAppWindows.size();
3747 for (int i=0; i<N; i++) {
3748 WindowState w = wtoken.allAppWindows.get(i);
3749 w.mAppFreezing = true;
3750 }
3751 }
3752 }
Romain Guy06882f82009-06-10 13:36:04 -07003753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 public void startAppFreezingScreen(IBinder token, int configChanges) {
3755 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3756 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003757 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 }
3759
3760 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003761 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003762 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 return;
3764 }
Romain Guy06882f82009-06-10 13:36:04 -07003765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 AppWindowToken wtoken = findAppWindowToken(token);
3767 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003768 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003769 return;
3770 }
3771 final long origId = Binder.clearCallingIdentity();
3772 startAppFreezingScreenLocked(wtoken, configChanges);
3773 Binder.restoreCallingIdentity(origId);
3774 }
3775 }
Romain Guy06882f82009-06-10 13:36:04 -07003776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 public void stopAppFreezingScreen(IBinder token, boolean force) {
3778 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3779 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003780 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 }
3782
3783 synchronized(mWindowMap) {
3784 AppWindowToken wtoken = findAppWindowToken(token);
3785 if (wtoken == null || wtoken.appToken == null) {
3786 return;
3787 }
3788 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003789 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3791 unsetAppFreezingScreenLocked(wtoken, true, force);
3792 Binder.restoreCallingIdentity(origId);
3793 }
3794 }
Romain Guy06882f82009-06-10 13:36:04 -07003795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 public void removeAppToken(IBinder token) {
3797 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3798 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003799 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 }
3801
3802 AppWindowToken wtoken = null;
3803 AppWindowToken startingToken = null;
3804 boolean delayed = false;
3805
3806 final long origId = Binder.clearCallingIdentity();
3807 synchronized(mWindowMap) {
3808 WindowToken basewtoken = mTokenMap.remove(token);
3809 mTokenList.remove(basewtoken);
3810 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003811 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003812 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 wtoken.inPendingTransaction = false;
3814 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003815 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 if (mClosingApps.contains(wtoken)) {
3817 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003818 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003820 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 delayed = true;
3822 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003823 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 TAG, "Removing app " + wtoken + " delayed=" + delayed
3825 + " animation=" + wtoken.animation
3826 + " animating=" + wtoken.animating);
3827 if (delayed) {
3828 // set the token aside because it has an active animation to be finished
3829 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003830 } else {
3831 // Make sure there is no animation running on this token,
3832 // so any windows associated with it will be removed as
3833 // soon as their animations are complete
3834 wtoken.animation = null;
3835 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 }
3837 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003838 if (mLastEnterAnimToken == wtoken) {
3839 mLastEnterAnimToken = null;
3840 mLastEnterAnimParams = null;
3841 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 wtoken.removed = true;
3843 if (wtoken.startingData != null) {
3844 startingToken = wtoken;
3845 }
3846 unsetAppFreezingScreenLocked(wtoken, true, true);
3847 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003848 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003849 mFocusedApp = null;
3850 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003851 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003852 }
3853 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003854 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855 }
Romain Guy06882f82009-06-10 13:36:04 -07003856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 if (!delayed && wtoken != null) {
3858 wtoken.updateReportedVisibilityLocked();
3859 }
3860 }
3861 Binder.restoreCallingIdentity(origId);
3862
3863 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 + startingToken + ": app token removed");
3866 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3867 mH.sendMessage(m);
3868 }
3869 }
3870
3871 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3872 final int NW = token.windows.size();
3873 for (int i=0; i<NW; i++) {
3874 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003875 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003876 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003877 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 int j = win.mChildWindows.size();
3879 while (j > 0) {
3880 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003881 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003882 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003883 "Tmp removing child window " + cwin);
3884 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003885 }
3886 }
3887 return NW > 0;
3888 }
3889
3890 void dumpAppTokensLocked() {
3891 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003892 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003893 }
3894 }
Romain Guy06882f82009-06-10 13:36:04 -07003895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 void dumpWindowsLocked() {
3897 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003898 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 }
3900 }
Romain Guy06882f82009-06-10 13:36:04 -07003901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003902 private int findWindowOffsetLocked(int tokenPos) {
3903 final int NW = mWindows.size();
3904
3905 if (tokenPos >= mAppTokens.size()) {
3906 int i = NW;
3907 while (i > 0) {
3908 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003909 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 if (win.getAppToken() != null) {
3911 return i+1;
3912 }
3913 }
3914 }
3915
3916 while (tokenPos > 0) {
3917 // Find the first app token below the new position that has
3918 // a window displayed.
3919 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003920 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003922 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003923 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003924 "Skipping token -- currently sending to bottom");
3925 tokenPos--;
3926 continue;
3927 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003928 int i = wtoken.windows.size();
3929 while (i > 0) {
3930 i--;
3931 WindowState win = wtoken.windows.get(i);
3932 int j = win.mChildWindows.size();
3933 while (j > 0) {
3934 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003935 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003936 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003937 for (int pos=NW-1; pos>=0; pos--) {
3938 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003939 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003940 "Found child win @" + (pos+1));
3941 return pos+1;
3942 }
3943 }
3944 }
3945 }
3946 for (int pos=NW-1; pos>=0; pos--) {
3947 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003948 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 return pos+1;
3950 }
3951 }
3952 }
3953 tokenPos--;
3954 }
3955
3956 return 0;
3957 }
3958
3959 private final int reAddWindowLocked(int index, WindowState win) {
3960 final int NCW = win.mChildWindows.size();
3961 boolean added = false;
3962 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003963 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003965 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003966 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 mWindows.add(index, win);
3968 index++;
3969 added = true;
3970 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003971 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003972 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003973 mWindows.add(index, cwin);
3974 index++;
3975 }
3976 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003977 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003978 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003979 mWindows.add(index, win);
3980 index++;
3981 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003982 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 return index;
3984 }
Romain Guy06882f82009-06-10 13:36:04 -07003985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3987 final int NW = token.windows.size();
3988 for (int i=0; i<NW; i++) {
3989 index = reAddWindowLocked(index, token.windows.get(i));
3990 }
3991 return index;
3992 }
3993
3994 public void moveAppToken(int index, IBinder token) {
3995 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3996 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003997 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003998 }
3999
4000 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004001 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 if (DEBUG_REORDER) dumpAppTokensLocked();
4003 final AppWindowToken wtoken = findAppWindowToken(token);
4004 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004005 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 + token + " (" + wtoken + ")");
4007 return;
4008 }
4009 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004014 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004015 if (DEBUG_REORDER) dumpWindowsLocked();
4016 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004017 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004018 if (DEBUG_REORDER) dumpWindowsLocked();
4019 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004020 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004021 if (DEBUG_REORDER) dumpWindowsLocked();
4022 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004023 mLayoutNeeded = true;
4024 performLayoutAndPlaceSurfacesLocked();
4025 }
4026 Binder.restoreCallingIdentity(origId);
4027 }
4028 }
4029
4030 private void removeAppTokensLocked(List<IBinder> tokens) {
4031 // XXX This should be done more efficiently!
4032 // (take advantage of the fact that both lists should be
4033 // ordered in the same way.)
4034 int N = tokens.size();
4035 for (int i=0; i<N; i++) {
4036 IBinder token = tokens.get(i);
4037 final AppWindowToken wtoken = findAppWindowToken(token);
4038 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004039 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004040 + token + " (" + wtoken + ")");
4041 i--;
4042 N--;
4043 }
4044 }
4045 }
4046
Dianne Hackborna8f60182009-09-01 19:01:50 -07004047 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4048 boolean updateFocusAndLayout) {
4049 // First remove all of the windows from the list.
4050 tmpRemoveAppWindowsLocked(wtoken);
4051
4052 // Where to start adding?
4053 int pos = findWindowOffsetLocked(tokenPos);
4054
4055 // And now add them back at the correct place.
4056 pos = reAddAppWindowsLocked(pos, wtoken);
4057
4058 if (updateFocusAndLayout) {
4059 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4060 assignLayersLocked();
4061 }
4062 mLayoutNeeded = true;
4063 performLayoutAndPlaceSurfacesLocked();
4064 }
4065 }
4066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4068 // First remove all of the windows from the list.
4069 final int N = tokens.size();
4070 int i;
4071 for (i=0; i<N; i++) {
4072 WindowToken token = mTokenMap.get(tokens.get(i));
4073 if (token != null) {
4074 tmpRemoveAppWindowsLocked(token);
4075 }
4076 }
4077
4078 // Where to start adding?
4079 int pos = findWindowOffsetLocked(tokenPos);
4080
4081 // And now add them back at the correct place.
4082 for (i=0; i<N; i++) {
4083 WindowToken token = mTokenMap.get(tokens.get(i));
4084 if (token != null) {
4085 pos = reAddAppWindowsLocked(pos, token);
4086 }
4087 }
4088
Dianne Hackborna8f60182009-09-01 19:01:50 -07004089 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4090 assignLayersLocked();
4091 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004092 mLayoutNeeded = true;
4093 performLayoutAndPlaceSurfacesLocked();
4094
4095 //dump();
4096 }
4097
4098 public void moveAppTokensToTop(List<IBinder> tokens) {
4099 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4100 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004101 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 }
4103
4104 final long origId = Binder.clearCallingIdentity();
4105 synchronized(mWindowMap) {
4106 removeAppTokensLocked(tokens);
4107 final int N = tokens.size();
4108 for (int i=0; i<N; i++) {
4109 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4110 if (wt != null) {
4111 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004112 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004113 mToTopApps.remove(wt);
4114 mToBottomApps.remove(wt);
4115 mToTopApps.add(wt);
4116 wt.sendingToBottom = false;
4117 wt.sendingToTop = true;
4118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 }
4120 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004121
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004122 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004123 moveAppWindowsLocked(tokens, mAppTokens.size());
4124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 }
4126 Binder.restoreCallingIdentity(origId);
4127 }
4128
4129 public void moveAppTokensToBottom(List<IBinder> tokens) {
4130 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4131 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004132 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 }
4134
4135 final long origId = Binder.clearCallingIdentity();
4136 synchronized(mWindowMap) {
4137 removeAppTokensLocked(tokens);
4138 final int N = tokens.size();
4139 int pos = 0;
4140 for (int i=0; i<N; i++) {
4141 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4142 if (wt != null) {
4143 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004144 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004145 mToTopApps.remove(wt);
4146 mToBottomApps.remove(wt);
4147 mToBottomApps.add(i, wt);
4148 wt.sendingToTop = false;
4149 wt.sendingToBottom = true;
4150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004151 pos++;
4152 }
4153 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004154
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004155 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004156 moveAppWindowsLocked(tokens, 0);
4157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 }
4159 Binder.restoreCallingIdentity(origId);
4160 }
4161
4162 // -------------------------------------------------------------
4163 // Misc IWindowSession methods
4164 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004165
Jim Miller284b62e2010-06-08 14:27:42 -07004166 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004167 {
Jim Miller284b62e2010-06-08 14:27:42 -07004168 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4169 // called before DevicePolicyManagerService has started.
4170 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4171 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4172 Context.DEVICE_POLICY_SERVICE);
4173 if (dpm != null) {
4174 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4175 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4176 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4177 }
Jim Millerd6b57052010-06-07 17:52:42 -07004178 }
Jim Miller284b62e2010-06-08 14:27:42 -07004179 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004180 }
4181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004183 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004184 != PackageManager.PERMISSION_GRANTED) {
4185 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4186 }
Jim Millerd6b57052010-06-07 17:52:42 -07004187
Jim Miller284b62e2010-06-08 14:27:42 -07004188 synchronized (mKeyguardTokenWatcher) {
4189 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004190 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191 }
4192
4193 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004194 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004195 != PackageManager.PERMISSION_GRANTED) {
4196 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4197 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004198
Jim Miller284b62e2010-06-08 14:27:42 -07004199 synchronized (mKeyguardTokenWatcher) {
4200 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004201
Jim Miller284b62e2010-06-08 14:27:42 -07004202 if (!mKeyguardTokenWatcher.isAcquired()) {
4203 // If we are the last one to reenable the keyguard wait until
4204 // we have actually finished reenabling until returning.
4205 // It is possible that reenableKeyguard() can be called before
4206 // the previous disableKeyguard() is handled, in which case
4207 // neither mKeyguardTokenWatcher.acquired() or released() would
4208 // be called. In that case mKeyguardDisabled will be false here
4209 // and we have nothing to wait for.
4210 while (mKeyguardDisabled) {
4211 try {
4212 mKeyguardTokenWatcher.wait();
4213 } catch (InterruptedException e) {
4214 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 }
4216 }
4217 }
4218 }
4219 }
4220
4221 /**
4222 * @see android.app.KeyguardManager#exitKeyguardSecurely
4223 */
4224 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004225 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 != PackageManager.PERMISSION_GRANTED) {
4227 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4228 }
4229 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4230 public void onKeyguardExitResult(boolean success) {
4231 try {
4232 callback.onKeyguardExitResult(success);
4233 } catch (RemoteException e) {
4234 // Client has died, we don't care.
4235 }
4236 }
4237 });
4238 }
4239
4240 public boolean inKeyguardRestrictedInputMode() {
4241 return mPolicy.inKeyguardRestrictedKeyInputMode();
4242 }
Romain Guy06882f82009-06-10 13:36:04 -07004243
Dianne Hackbornffa42482009-09-23 22:20:11 -07004244 public void closeSystemDialogs(String reason) {
4245 synchronized(mWindowMap) {
4246 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004247 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004248 if (w.mSurface != null) {
4249 try {
4250 w.mClient.closeSystemDialogs(reason);
4251 } catch (RemoteException e) {
4252 }
4253 }
4254 }
4255 }
4256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004258 static float fixScale(float scale) {
4259 if (scale < 0) scale = 0;
4260 else if (scale > 20) scale = 20;
4261 return Math.abs(scale);
4262 }
Romain Guy06882f82009-06-10 13:36:04 -07004263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 public void setAnimationScale(int which, float scale) {
4265 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4266 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004267 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004268 }
4269
4270 if (scale < 0) scale = 0;
4271 else if (scale > 20) scale = 20;
4272 scale = Math.abs(scale);
4273 switch (which) {
4274 case 0: mWindowAnimationScale = fixScale(scale); break;
4275 case 1: mTransitionAnimationScale = fixScale(scale); break;
4276 }
Romain Guy06882f82009-06-10 13:36:04 -07004277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278 // Persist setting
4279 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4280 }
Romain Guy06882f82009-06-10 13:36:04 -07004281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004282 public void setAnimationScales(float[] scales) {
4283 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4284 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004285 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004286 }
4287
4288 if (scales != null) {
4289 if (scales.length >= 1) {
4290 mWindowAnimationScale = fixScale(scales[0]);
4291 }
4292 if (scales.length >= 2) {
4293 mTransitionAnimationScale = fixScale(scales[1]);
4294 }
4295 }
Romain Guy06882f82009-06-10 13:36:04 -07004296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297 // Persist setting
4298 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4299 }
Romain Guy06882f82009-06-10 13:36:04 -07004300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 public float getAnimationScale(int which) {
4302 switch (which) {
4303 case 0: return mWindowAnimationScale;
4304 case 1: return mTransitionAnimationScale;
4305 }
4306 return 0;
4307 }
Romain Guy06882f82009-06-10 13:36:04 -07004308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 public float[] getAnimationScales() {
4310 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4311 }
Romain Guy06882f82009-06-10 13:36:04 -07004312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004313 public int getSwitchState(int sw) {
4314 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4315 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004316 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004318 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 }
Romain Guy06882f82009-06-10 13:36:04 -07004320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321 public int getSwitchStateForDevice(int devid, int sw) {
4322 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4323 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004324 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004326 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 }
Romain Guy06882f82009-06-10 13:36:04 -07004328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 public int getScancodeState(int sw) {
4330 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4331 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004332 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004334 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004335 }
Romain Guy06882f82009-06-10 13:36:04 -07004336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 public int getScancodeStateForDevice(int devid, int sw) {
4338 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4339 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004340 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004341 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004342 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 }
Romain Guy06882f82009-06-10 13:36:04 -07004344
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004345 public int getTrackballScancodeState(int sw) {
4346 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4347 "getTrackballScancodeState()")) {
4348 throw new SecurityException("Requires READ_INPUT_STATE permission");
4349 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004350 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004351 }
4352
4353 public int getDPadScancodeState(int sw) {
4354 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4355 "getDPadScancodeState()")) {
4356 throw new SecurityException("Requires READ_INPUT_STATE permission");
4357 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004358 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004359 }
4360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 public int getKeycodeState(int sw) {
4362 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4363 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004364 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004366 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367 }
Romain Guy06882f82009-06-10 13:36:04 -07004368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369 public int getKeycodeStateForDevice(int devid, int sw) {
4370 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4371 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004372 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004373 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004374 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004375 }
Romain Guy06882f82009-06-10 13:36:04 -07004376
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004377 public int getTrackballKeycodeState(int sw) {
4378 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4379 "getTrackballKeycodeState()")) {
4380 throw new SecurityException("Requires READ_INPUT_STATE permission");
4381 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004382 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004383 }
4384
4385 public int getDPadKeycodeState(int sw) {
4386 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4387 "getDPadKeycodeState()")) {
4388 throw new SecurityException("Requires READ_INPUT_STATE permission");
4389 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004390 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004391 }
Jeff Browna41ca772010-08-11 14:46:32 -07004392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004393 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004394 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 }
Romain Guy06882f82009-06-10 13:36:04 -07004396
Jeff Browna41ca772010-08-11 14:46:32 -07004397 public InputChannel monitorInput(String inputChannelName) {
4398 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4399 "monitorInput()")) {
4400 throw new SecurityException("Requires READ_INPUT_STATE permission");
4401 }
4402 return mInputManager.monitorInput(inputChannelName);
4403 }
4404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004405 public void enableScreenAfterBoot() {
4406 synchronized(mWindowMap) {
4407 if (mSystemBooted) {
4408 return;
4409 }
4410 mSystemBooted = true;
4411 }
Romain Guy06882f82009-06-10 13:36:04 -07004412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 performEnableScreen();
4414 }
Romain Guy06882f82009-06-10 13:36:04 -07004415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 public void enableScreenIfNeededLocked() {
4417 if (mDisplayEnabled) {
4418 return;
4419 }
4420 if (!mSystemBooted) {
4421 return;
4422 }
4423 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4424 }
Romain Guy06882f82009-06-10 13:36:04 -07004425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 public void performEnableScreen() {
4427 synchronized(mWindowMap) {
4428 if (mDisplayEnabled) {
4429 return;
4430 }
4431 if (!mSystemBooted) {
4432 return;
4433 }
Romain Guy06882f82009-06-10 13:36:04 -07004434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 // Don't enable the screen until all existing windows
4436 // have been drawn.
4437 final int N = mWindows.size();
4438 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004439 WindowState w = mWindows.get(i);
Dianne Hackborn5943c202010-04-12 21:36:49 -07004440 if (w.isVisibleLw() && !w.mObscured
4441 && (w.mOrientationChanging || !w.isDrawnLw())) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004442 return;
4443 }
4444 }
Romain Guy06882f82009-06-10 13:36:04 -07004445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 mDisplayEnabled = true;
4447 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004448 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 StringWriter sw = new StringWriter();
4450 PrintWriter pw = new PrintWriter(sw);
4451 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004452 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 }
4454 try {
4455 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4456 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004457 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 Parcel data = Parcel.obtain();
4459 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4460 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4461 data, null, 0);
4462 data.recycle();
4463 }
4464 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004465 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004466 }
4467 }
Romain Guy06882f82009-06-10 13:36:04 -07004468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004469 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004471 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004472 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4473 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 }
Romain Guy06882f82009-06-10 13:36:04 -07004475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 public void setInTouchMode(boolean mode) {
4477 synchronized(mWindowMap) {
4478 mInTouchMode = mode;
4479 }
4480 }
4481
Romain Guy06882f82009-06-10 13:36:04 -07004482 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004483 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004485 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004486 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 }
4488
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004489 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004492 public void setRotationUnchecked(int rotation,
4493 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004494 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004495 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 long origId = Binder.clearCallingIdentity();
4498 boolean changed;
4499 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004500 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004501 }
Romain Guy06882f82009-06-10 13:36:04 -07004502
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004503 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004504 sendNewConfiguration();
4505 }
Romain Guy06882f82009-06-10 13:36:04 -07004506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 Binder.restoreCallingIdentity(origId);
4508 }
Romain Guy06882f82009-06-10 13:36:04 -07004509
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004510 /**
4511 * Apply a new rotation to the screen, respecting the requests of
4512 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4513 * re-evaluate the desired rotation.
4514 *
4515 * Returns null if the rotation has been changed. In this case YOU
4516 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4517 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004518 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 boolean changed;
4520 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4521 rotation = mRequestedRotation;
4522 } else {
4523 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004524 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004526 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004527 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004528 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004529 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004533 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004534 "Rotation changed to " + rotation
4535 + " from " + mRotation
4536 + " (forceApp=" + mForcedAppOrientation
4537 + ", req=" + mRequestedRotation + ")");
4538 mRotation = rotation;
4539 mWindowsFreezingScreen = true;
4540 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4541 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4542 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004543 mWaitingForConfig = true;
4544 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004545 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004546 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004547 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004549 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 }
4551 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004552 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004553 if (w.mSurface != null) {
4554 w.mOrientationChanging = true;
4555 }
4556 }
4557 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4558 try {
4559 mRotationWatchers.get(i).onRotationChanged(rotation);
4560 } catch (RemoteException e) {
4561 }
4562 }
4563 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 return changed;
4566 }
Romain Guy06882f82009-06-10 13:36:04 -07004567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004568 public int getRotation() {
4569 return mRotation;
4570 }
4571
4572 public int watchRotation(IRotationWatcher watcher) {
4573 final IBinder watcherBinder = watcher.asBinder();
4574 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4575 public void binderDied() {
4576 synchronized (mWindowMap) {
4577 for (int i=0; i<mRotationWatchers.size(); i++) {
4578 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004579 IRotationWatcher removed = mRotationWatchers.remove(i);
4580 if (removed != null) {
4581 removed.asBinder().unlinkToDeath(this, 0);
4582 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004583 i--;
4584 }
4585 }
4586 }
4587 }
4588 };
Romain Guy06882f82009-06-10 13:36:04 -07004589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004590 synchronized (mWindowMap) {
4591 try {
4592 watcher.asBinder().linkToDeath(dr, 0);
4593 mRotationWatchers.add(watcher);
4594 } catch (RemoteException e) {
4595 // Client died, no cleanup needed.
4596 }
Romain Guy06882f82009-06-10 13:36:04 -07004597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 return mRotation;
4599 }
4600 }
4601
4602 /**
4603 * Starts the view server on the specified port.
4604 *
4605 * @param port The port to listener to.
4606 *
4607 * @return True if the server was successfully started, false otherwise.
4608 *
4609 * @see com.android.server.ViewServer
4610 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4611 */
4612 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004613 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004614 return false;
4615 }
4616
4617 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4618 return false;
4619 }
4620
4621 if (port < 1024) {
4622 return false;
4623 }
4624
4625 if (mViewServer != null) {
4626 if (!mViewServer.isRunning()) {
4627 try {
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 }
4633 return false;
4634 }
4635
4636 try {
4637 mViewServer = new ViewServer(this, port);
4638 return mViewServer.start();
4639 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004640 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 }
4642 return false;
4643 }
4644
Romain Guy06882f82009-06-10 13:36:04 -07004645 private boolean isSystemSecure() {
4646 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4647 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4648 }
4649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004650 /**
4651 * Stops the view server if it exists.
4652 *
4653 * @return True if the server stopped, false if it wasn't started or
4654 * couldn't be stopped.
4655 *
4656 * @see com.android.server.ViewServer
4657 */
4658 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004659 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 return false;
4661 }
4662
4663 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4664 return false;
4665 }
4666
4667 if (mViewServer != null) {
4668 return mViewServer.stop();
4669 }
4670 return false;
4671 }
4672
4673 /**
4674 * Indicates whether the view server is running.
4675 *
4676 * @return True if the server is running, false otherwise.
4677 *
4678 * @see com.android.server.ViewServer
4679 */
4680 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004681 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682 return false;
4683 }
4684
4685 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4686 return false;
4687 }
4688
4689 return mViewServer != null && mViewServer.isRunning();
4690 }
4691
4692 /**
4693 * Lists all availble windows in the system. The listing is written in the
4694 * specified Socket's output stream with the following syntax:
4695 * windowHashCodeInHexadecimal windowName
4696 * Each line of the ouput represents a different window.
4697 *
4698 * @param client The remote client to send the listing to.
4699 * @return False if an error occured, true otherwise.
4700 */
4701 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004702 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004703 return false;
4704 }
4705
4706 boolean result = true;
4707
Jeff Browne33348b2010-07-15 23:54:05 -07004708 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004710 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004711 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712 }
4713
4714 BufferedWriter out = null;
4715
4716 // Any uncaught exception will crash the system process
4717 try {
4718 OutputStream clientStream = client.getOutputStream();
4719 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4720
4721 final int count = windows.length;
4722 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004723 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004724 out.write(Integer.toHexString(System.identityHashCode(w)));
4725 out.write(' ');
4726 out.append(w.mAttrs.getTitle());
4727 out.write('\n');
4728 }
4729
4730 out.write("DONE.\n");
4731 out.flush();
4732 } catch (Exception e) {
4733 result = false;
4734 } finally {
4735 if (out != null) {
4736 try {
4737 out.close();
4738 } catch (IOException e) {
4739 result = false;
4740 }
4741 }
4742 }
4743
4744 return result;
4745 }
4746
4747 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004748 * Returns the focused window in the following format:
4749 * windowHashCodeInHexadecimal windowName
4750 *
4751 * @param client The remote client to send the listing to.
4752 * @return False if an error occurred, true otherwise.
4753 */
4754 boolean viewServerGetFocusedWindow(Socket client) {
4755 if (isSystemSecure()) {
4756 return false;
4757 }
4758
4759 boolean result = true;
4760
4761 WindowState focusedWindow = getFocusedWindow();
4762
4763 BufferedWriter out = null;
4764
4765 // Any uncaught exception will crash the system process
4766 try {
4767 OutputStream clientStream = client.getOutputStream();
4768 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4769
4770 if(focusedWindow != null) {
4771 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4772 out.write(' ');
4773 out.append(focusedWindow.mAttrs.getTitle());
4774 }
4775 out.write('\n');
4776 out.flush();
4777 } catch (Exception e) {
4778 result = false;
4779 } finally {
4780 if (out != null) {
4781 try {
4782 out.close();
4783 } catch (IOException e) {
4784 result = false;
4785 }
4786 }
4787 }
4788
4789 return result;
4790 }
4791
4792 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004793 * Sends a command to a target window. The result of the command, if any, will be
4794 * written in the output stream of the specified socket.
4795 *
4796 * The parameters must follow this syntax:
4797 * windowHashcode extra
4798 *
4799 * Where XX is the length in characeters of the windowTitle.
4800 *
4801 * The first parameter is the target window. The window with the specified hashcode
4802 * will be the target. If no target can be found, nothing happens. The extra parameters
4803 * will be delivered to the target window and as parameters to the command itself.
4804 *
4805 * @param client The remote client to sent the result, if any, to.
4806 * @param command The command to execute.
4807 * @param parameters The command parameters.
4808 *
4809 * @return True if the command was successfully delivered, false otherwise. This does
4810 * not indicate whether the command itself was successful.
4811 */
4812 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004813 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004814 return false;
4815 }
4816
4817 boolean success = true;
4818 Parcel data = null;
4819 Parcel reply = null;
4820
4821 // Any uncaught exception will crash the system process
4822 try {
4823 // Find the hashcode of the window
4824 int index = parameters.indexOf(' ');
4825 if (index == -1) {
4826 index = parameters.length();
4827 }
4828 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004829 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830
4831 // Extract the command's parameter after the window description
4832 if (index < parameters.length()) {
4833 parameters = parameters.substring(index + 1);
4834 } else {
4835 parameters = "";
4836 }
4837
4838 final WindowManagerService.WindowState window = findWindow(hashCode);
4839 if (window == null) {
4840 return false;
4841 }
4842
4843 data = Parcel.obtain();
4844 data.writeInterfaceToken("android.view.IWindow");
4845 data.writeString(command);
4846 data.writeString(parameters);
4847 data.writeInt(1);
4848 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4849
4850 reply = Parcel.obtain();
4851
4852 final IBinder binder = window.mClient.asBinder();
4853 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4854 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4855
4856 reply.readException();
4857
4858 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004859 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004860 success = false;
4861 } finally {
4862 if (data != null) {
4863 data.recycle();
4864 }
4865 if (reply != null) {
4866 reply.recycle();
4867 }
4868 }
4869
4870 return success;
4871 }
4872
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004873 public void addWindowChangeListener(WindowChangeListener listener) {
4874 synchronized(mWindowMap) {
4875 mWindowChangeListeners.add(listener);
4876 }
4877 }
4878
4879 public void removeWindowChangeListener(WindowChangeListener listener) {
4880 synchronized(mWindowMap) {
4881 mWindowChangeListeners.remove(listener);
4882 }
4883 }
4884
4885 private void notifyWindowsChanged() {
4886 WindowChangeListener[] windowChangeListeners;
4887 synchronized(mWindowMap) {
4888 if(mWindowChangeListeners.isEmpty()) {
4889 return;
4890 }
4891 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4892 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4893 }
4894 int N = windowChangeListeners.length;
4895 for(int i = 0; i < N; i++) {
4896 windowChangeListeners[i].windowsChanged();
4897 }
4898 }
4899
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004900 private void notifyFocusChanged() {
4901 WindowChangeListener[] windowChangeListeners;
4902 synchronized(mWindowMap) {
4903 if(mWindowChangeListeners.isEmpty()) {
4904 return;
4905 }
4906 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4907 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4908 }
4909 int N = windowChangeListeners.length;
4910 for(int i = 0; i < N; i++) {
4911 windowChangeListeners[i].focusChanged();
4912 }
4913 }
4914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004915 private WindowState findWindow(int hashCode) {
4916 if (hashCode == -1) {
4917 return getFocusedWindow();
4918 }
4919
4920 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004921 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004922 final int count = windows.size();
4923
4924 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004925 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 if (System.identityHashCode(w) == hashCode) {
4927 return w;
4928 }
4929 }
4930 }
4931
4932 return null;
4933 }
4934
4935 /*
4936 * Instruct the Activity Manager to fetch the current configuration and broadcast
4937 * that to config-changed listeners if appropriate.
4938 */
4939 void sendNewConfiguration() {
4940 try {
4941 mActivityManager.updateConfiguration(null);
4942 } catch (RemoteException e) {
4943 }
4944 }
Romain Guy06882f82009-06-10 13:36:04 -07004945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004946 public Configuration computeNewConfiguration() {
4947 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004948 return computeNewConfigurationLocked();
4949 }
4950 }
Romain Guy06882f82009-06-10 13:36:04 -07004951
Dianne Hackbornc485a602009-03-24 22:39:49 -07004952 Configuration computeNewConfigurationLocked() {
4953 Configuration config = new Configuration();
4954 if (!computeNewConfigurationLocked(config)) {
4955 return null;
4956 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004957 return config;
4958 }
Romain Guy06882f82009-06-10 13:36:04 -07004959
Dianne Hackbornc485a602009-03-24 22:39:49 -07004960 boolean computeNewConfigurationLocked(Configuration config) {
4961 if (mDisplay == null) {
4962 return false;
4963 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004964
4965 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004966
4967 // Use the effective "visual" dimensions based on current rotation
4968 final boolean rotated = (mRotation == Surface.ROTATION_90
4969 || mRotation == Surface.ROTATION_270);
4970 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4971 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4972
Dianne Hackbornc485a602009-03-24 22:39:49 -07004973 int orientation = Configuration.ORIENTATION_SQUARE;
4974 if (dw < dh) {
4975 orientation = Configuration.ORIENTATION_PORTRAIT;
4976 } else if (dw > dh) {
4977 orientation = Configuration.ORIENTATION_LANDSCAPE;
4978 }
4979 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004980
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004981 DisplayMetrics dm = new DisplayMetrics();
4982 mDisplay.getMetrics(dm);
4983 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4984
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004985 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004986 // Note we only do this once because at this point we don't
4987 // expect the screen to change in this way at runtime, and want
4988 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004989 int longSize = dw;
4990 int shortSize = dh;
4991 if (longSize < shortSize) {
4992 int tmp = longSize;
4993 longSize = shortSize;
4994 shortSize = tmp;
4995 }
4996 longSize = (int)(longSize/dm.density);
4997 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004998
Dianne Hackborn723738c2009-06-25 19:48:04 -07004999 // These semi-magic numbers define our compatibility modes for
5000 // applications with different screens. Don't change unless you
5001 // make sure to test lots and lots of apps!
5002 if (longSize < 470) {
5003 // This is shorter than an HVGA normal density screen (which
5004 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005005 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5006 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005007 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005008 // What size is this screen screen?
5009 if (longSize >= 800 && shortSize >= 600) {
5010 // SVGA or larger screens at medium density are the point
5011 // at which we consider it to be an extra large screen.
5012 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5013 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005014 // VGA or larger screens at medium density are the point
5015 // at which we consider it to be a large screen.
5016 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5017 } else {
5018 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005019
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005020 // If this screen is wider than normal HVGA, or taller
5021 // than FWVGA, then for old apps we want to run in size
5022 // compatibility mode.
5023 if (shortSize > 321 || longSize > 570) {
5024 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5025 }
5026 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005027
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005028 // Is this a long screen?
5029 if (((longSize*3)/5) >= (shortSize-1)) {
5030 // Anything wider than WVGA (5:3) is considering to be long.
5031 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5032 } else {
5033 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5034 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005035 }
5036 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005037 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005038
Dianne Hackbornc485a602009-03-24 22:39:49 -07005039 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5040 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5041 mPolicy.adjustConfigurationLw(config);
5042 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005043 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 // -------------------------------------------------------------
5046 // Input Events and Focus Management
5047 // -------------------------------------------------------------
Jeff Brown46b9ac02010-04-22 18:58:52 -07005048
Jeff Brown349703e2010-06-22 01:27:15 -07005049 InputMonitor mInputMonitor = new InputMonitor();
5050
5051 /* Tracks the progress of input dispatch and ensures that input dispatch state
5052 * is kept in sync with changes in window focus, visibility, registration, and
5053 * other relevant Window Manager state transitions. */
5054 final class InputMonitor {
5055 // Current window with input focus for keys and other non-touch events. May be null.
5056 private WindowState mInputFocus;
5057
5058 // When true, prevents input dispatch from proceeding until set to false again.
5059 private boolean mInputDispatchFrozen;
5060
5061 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5062 private boolean mInputDispatchEnabled = true;
5063
5064 // Temporary list of windows information to provide to the input dispatcher.
5065 private InputWindowList mTempInputWindows = new InputWindowList();
5066
5067 // Temporary input application object to provide to the input dispatcher.
5068 private InputApplication mTempInputApplication = new InputApplication();
5069
5070 /* Notifies the window manager about a broken input channel.
5071 *
5072 * Called by the InputManager.
5073 */
5074 public void notifyInputChannelBroken(InputChannel inputChannel) {
5075 synchronized (mWindowMap) {
5076 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5077 if (windowState == null) {
5078 return; // irrelevant
5079 }
5080
5081 Slog.i(TAG, "WINDOW DIED " + windowState);
5082 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005083 }
5084 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005085
Jeff Brown349703e2010-06-22 01:27:15 -07005086 /* Notifies the window manager about an input channel that is not responding.
5087 * The method can either cause dispatching to be aborted by returning -2 or
5088 * return a new timeout in nanoseconds.
5089 *
5090 * Called by the InputManager.
5091 */
5092 public long notifyInputChannelANR(InputChannel inputChannel) {
5093 AppWindowToken token;
5094 synchronized (mWindowMap) {
5095 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5096 if (windowState == null) {
5097 return -2; // irrelevant, abort dispatching (-2)
5098 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005099
Jeff Brown349703e2010-06-22 01:27:15 -07005100 Slog.i(TAG, "Input event dispatching timed out sending to "
5101 + windowState.mAttrs.getTitle());
5102 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005103 }
5104
Jeff Brown349703e2010-06-22 01:27:15 -07005105 return notifyANRInternal(token);
5106 }
5107
5108 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5109 * by successfully delivering the event that originally timed out.
5110 *
5111 * Called by the InputManager.
5112 */
5113 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5114 // Nothing to do just now.
5115 // Just wait for the user to dismiss the ANR dialog.
5116 }
5117
5118 /* Notifies the window manager about an application that is not responding
5119 * in general rather than with respect to a particular input channel.
5120 * The method can either cause dispatching to be aborted by returning -2 or
5121 * return a new timeout in nanoseconds.
5122 *
5123 * Called by the InputManager.
5124 */
5125 public long notifyANR(Object token) {
5126 AppWindowToken appWindowToken = (AppWindowToken) token;
5127
5128 Slog.i(TAG, "Input event dispatching timed out sending to application "
5129 + appWindowToken.stringName);
5130 return notifyANRInternal(appWindowToken);
5131 }
5132
5133 private long notifyANRInternal(AppWindowToken token) {
5134 if (token != null && token.appToken != null) {
5135 try {
5136 // Notify the activity manager about the timeout and let it decide whether
5137 // to abort dispatching or keep waiting.
5138 boolean abort = token.appToken.keyDispatchingTimedOut();
5139 if (! abort) {
5140 // The activity manager declined to abort dispatching.
5141 // Wait a bit longer and timeout again later.
5142 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005143 }
Jeff Brown349703e2010-06-22 01:27:15 -07005144 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005145 }
5146 }
Jeff Brown349703e2010-06-22 01:27:15 -07005147 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005148 }
5149
Jeff Brown349703e2010-06-22 01:27:15 -07005150 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5151 synchronized (mWindowMap) {
5152 return getWindowStateForInputChannelLocked(inputChannel);
5153 }
5154 }
5155
5156 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5157 int windowCount = mWindows.size();
5158 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005159 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005160 if (windowState.mInputChannel == inputChannel) {
5161 return windowState;
5162 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005163 }
5164
Jeff Brown349703e2010-06-22 01:27:15 -07005165 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005166 }
5167
Jeff Brown349703e2010-06-22 01:27:15 -07005168 /* Updates the cached window information provided to the input dispatcher. */
5169 public void updateInputWindowsLw() {
5170 // Populate the input window list with information about all of the windows that
5171 // could potentially receive input.
5172 // As an optimization, we could try to prune the list of windows but this turns
5173 // out to be difficult because only the native code knows for sure which window
5174 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005175 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005176 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005177 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005178 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005179 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005180 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005181 continue;
5182 }
5183
Jeff Brown349703e2010-06-22 01:27:15 -07005184 final int flags = child.mAttrs.flags;
5185 final int type = child.mAttrs.type;
5186
5187 final boolean hasFocus = (child == mInputFocus);
5188 final boolean isVisible = child.isVisibleLw();
5189 final boolean hasWallpaper = (child == mWallpaperTarget)
5190 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5191
5192 // Add a window to our list of input windows.
5193 final InputWindow inputWindow = mTempInputWindows.add();
5194 inputWindow.inputChannel = child.mInputChannel;
5195 inputWindow.layoutParamsFlags = flags;
5196 inputWindow.layoutParamsType = type;
5197 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5198 inputWindow.visible = isVisible;
5199 inputWindow.hasFocus = hasFocus;
5200 inputWindow.hasWallpaper = hasWallpaper;
5201 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5202 inputWindow.ownerPid = child.mSession.mPid;
5203 inputWindow.ownerUid = child.mSession.mUid;
5204
5205 final Rect frame = child.mFrame;
5206 inputWindow.frameLeft = frame.left;
5207 inputWindow.frameTop = frame.top;
5208
5209 switch (child.mTouchableInsets) {
5210 default:
5211 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5212 inputWindow.touchableAreaLeft = frame.left;
5213 inputWindow.touchableAreaTop = frame.top;
5214 inputWindow.touchableAreaRight = frame.right;
5215 inputWindow.touchableAreaBottom = frame.bottom;
5216 break;
5217
5218 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5219 Rect inset = child.mGivenContentInsets;
5220 inputWindow.touchableAreaLeft = frame.left + inset.left;
5221 inputWindow.touchableAreaTop = frame.top + inset.top;
5222 inputWindow.touchableAreaRight = frame.right - inset.right;
5223 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5224 break;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005225 }
Jeff Brown349703e2010-06-22 01:27:15 -07005226
5227 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5228 Rect inset = child.mGivenVisibleInsets;
5229 inputWindow.touchableAreaLeft = frame.left + inset.left;
5230 inputWindow.touchableAreaTop = frame.top + inset.top;
5231 inputWindow.touchableAreaRight = frame.right - inset.right;
5232 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005233 break;
5234 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005235 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005236 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005237
Jeff Brown349703e2010-06-22 01:27:15 -07005238 // Send windows to native code.
5239 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac02010-04-22 18:58:52 -07005240
Jeff Brown349703e2010-06-22 01:27:15 -07005241 // Clear the list in preparation for the next round.
5242 // Also avoids keeping InputChannel objects referenced unnecessarily.
5243 mTempInputWindows.clear();
5244 }
5245
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005246 /* Provides feedback for a virtual key down. */
5247 public void virtualKeyDownFeedback() {
5248 synchronized (mWindowMap) {
5249 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5250 }
5251 }
5252
Jeff Brown349703e2010-06-22 01:27:15 -07005253 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5254 * This essentially starts a .5 second timeout for the application to process
5255 * subsequent input events while waiting for the app switch to occur. If it takes longer
5256 * than this, the pending events will be dropped.
5257 */
5258 public void notifyAppSwitchComing() {
5259 // TODO Not implemented yet. Should go in the native side.
5260 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005261
5262 /* Notifies that the lid switch changed state. */
5263 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5264 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5265 }
5266
Jeff Brown349703e2010-06-22 01:27:15 -07005267 /* Provides an opportunity for the window manager policy to intercept early key
5268 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005269 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5270 int policyFlags, boolean isScreenOn) {
5271 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5272 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005273 }
5274
5275 /* Provides an opportunity for the window manager policy to process a key before
5276 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005277 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5278 int action, int flags, int keyCode, int metaState, int repeatCount,
5279 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005280 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005281 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5282 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005283 }
5284
5285 /* Called when the current input focus changes.
5286 * Layer assignment is assumed to be complete by the time this is called.
5287 */
5288 public void setInputFocusLw(WindowState newWindow) {
5289 if (DEBUG_INPUT) {
5290 Slog.d(TAG, "Input focus has changed to " + newWindow);
5291 }
5292
5293 if (newWindow != mInputFocus) {
5294 if (newWindow != null && newWindow.canReceiveKeys()) {
5295 // If the new input focus is an error window or appears above the current
5296 // input focus, preempt any pending synchronous dispatch so that we can
5297 // start delivering events to the new input focus as soon as possible.
5298 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5299 if (DEBUG_INPUT) {
5300 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac02010-04-22 18:58:52 -07005301 }
Jeff Brown349703e2010-06-22 01:27:15 -07005302 preemptInputDispatchLw();
5303 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5304 if (DEBUG_INPUT) {
5305 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5306 + "old win layer=" + mInputFocus.mLayer
5307 + ", new win layer=" + newWindow.mLayer);
5308 }
5309 preemptInputDispatchLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005310 }
Jeff Brown349703e2010-06-22 01:27:15 -07005311
5312 // Displaying a window implicitly causes dispatching to be unpaused.
5313 // This is to protect against bugs if someone pauses dispatching but
5314 // forgets to resume.
5315 newWindow.mToken.paused = false;
Jeff Brown46b9ac02010-04-22 18:58:52 -07005316 }
Jeff Brown349703e2010-06-22 01:27:15 -07005317
5318 mInputFocus = newWindow;
5319 updateInputWindowsLw();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005320 }
5321 }
5322
Jeff Brown349703e2010-06-22 01:27:15 -07005323 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5324 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5325 * can begin.
5326 */
5327 private void preemptInputDispatchLw() {
5328 mInputManager.preemptInputDispatch();
5329 }
5330
5331 public void setFocusedAppLw(AppWindowToken newApp) {
5332 // Focused app has changed.
5333 if (newApp == null) {
5334 mInputManager.setFocusedApplication(null);
5335 } else {
5336 mTempInputApplication.name = newApp.toString();
5337 mTempInputApplication.dispatchingTimeoutNanos =
5338 newApp.inputDispatchingTimeoutNanos;
5339 mTempInputApplication.token = newApp;
5340
5341 mInputManager.setFocusedApplication(mTempInputApplication);
5342 }
5343 }
5344
Jeff Brown349703e2010-06-22 01:27:15 -07005345 public void pauseDispatchingLw(WindowToken window) {
5346 if (! window.paused) {
5347 if (DEBUG_INPUT) {
5348 Slog.v(TAG, "Pausing WindowToken " + window);
5349 }
5350
5351 window.paused = true;
5352 updateInputWindowsLw();
5353 }
5354 }
5355
5356 public void resumeDispatchingLw(WindowToken window) {
5357 if (window.paused) {
5358 if (DEBUG_INPUT) {
5359 Slog.v(TAG, "Resuming WindowToken " + window);
5360 }
5361
5362 window.paused = false;
5363 updateInputWindowsLw();
5364 }
5365 }
5366
5367 public void freezeInputDispatchingLw() {
5368 if (! mInputDispatchFrozen) {
5369 if (DEBUG_INPUT) {
5370 Slog.v(TAG, "Freezing input dispatching");
5371 }
5372
5373 mInputDispatchFrozen = true;
5374 updateInputDispatchModeLw();
5375 }
5376 }
5377
5378 public void thawInputDispatchingLw() {
5379 if (mInputDispatchFrozen) {
5380 if (DEBUG_INPUT) {
5381 Slog.v(TAG, "Thawing input dispatching");
5382 }
5383
5384 mInputDispatchFrozen = false;
5385 updateInputDispatchModeLw();
5386 }
5387 }
5388
5389 public void setEventDispatchingLw(boolean enabled) {
5390 if (mInputDispatchEnabled != enabled) {
5391 if (DEBUG_INPUT) {
5392 Slog.v(TAG, "Setting event dispatching to " + enabled);
5393 }
5394
5395 mInputDispatchEnabled = enabled;
5396 updateInputDispatchModeLw();
5397 }
5398 }
5399
5400 private void updateInputDispatchModeLw() {
5401 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5402 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07005403 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005405 public void pauseKeyDispatching(IBinder _token) {
5406 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5407 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005408 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005409 }
5410
5411 synchronized (mWindowMap) {
5412 WindowToken token = mTokenMap.get(_token);
5413 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005414 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005415 }
5416 }
5417 }
5418
5419 public void resumeKeyDispatching(IBinder _token) {
5420 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5421 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005422 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005423 }
5424
5425 synchronized (mWindowMap) {
5426 WindowToken token = mTokenMap.get(_token);
5427 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005428 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005429 }
5430 }
5431 }
5432
5433 public void setEventDispatching(boolean enabled) {
5434 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5435 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005436 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005437 }
5438
5439 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005440 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005441 }
5442 }
Romain Guy06882f82009-06-10 13:36:04 -07005443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005444 /**
5445 * Injects a keystroke event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005446 * Even when sync is false, this method may block while waiting for current
5447 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005448 *
5449 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005450 * {@link SystemClock#uptimeMillis()} as the timebase.)
5451 * @param sync If true, wait for the event to be completed before returning to the caller.
5452 * @return Returns true if event was dispatched, false if it was dropped for any reason
5453 */
5454 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5455 long downTime = ev.getDownTime();
5456 long eventTime = ev.getEventTime();
5457
5458 int action = ev.getAction();
5459 int code = ev.getKeyCode();
5460 int repeatCount = ev.getRepeatCount();
5461 int metaState = ev.getMetaState();
5462 int deviceId = ev.getDeviceId();
5463 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005464 int source = ev.getSource();
5465
5466 if (source == InputDevice.SOURCE_UNKNOWN) {
5467 source = InputDevice.SOURCE_KEYBOARD;
5468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005469
5470 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5471 if (downTime == 0) downTime = eventTime;
5472
5473 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005474 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005475
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005476 final int pid = Binder.getCallingPid();
5477 final int uid = Binder.getCallingUid();
5478 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005479
Jeff Brown6ec402b2010-07-28 15:48:59 -07005480 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5481 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5482 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5483 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005484
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005485 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005486 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005487 }
5488
5489 /**
5490 * Inject a pointer (touch) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005491 * Even when sync is false, this method may block while waiting for current
5492 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005493 *
5494 * @param ev A motion event describing the pointer (touch) action. (As noted in
5495 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005496 * {@link SystemClock#uptimeMillis()} as the timebase.)
5497 * @param sync If true, wait for the event to be completed before returning to the caller.
5498 * @return Returns true if event was dispatched, false if it was dropped for any reason
5499 */
5500 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005501 final int pid = Binder.getCallingPid();
5502 final int uid = Binder.getCallingUid();
5503 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005504
Jeff Brownc5ed5912010-07-14 18:48:53 -07005505 MotionEvent newEvent = MotionEvent.obtain(ev);
5506 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5507 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5508 }
5509
Jeff Brown6ec402b2010-07-28 15:48:59 -07005510 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5511 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5512 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5513 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005514
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005515 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005516 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005517 }
Romain Guy06882f82009-06-10 13:36:04 -07005518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005519 /**
5520 * Inject a trackball (navigation device) event into the UI.
Jeff Brown6ec402b2010-07-28 15:48:59 -07005521 * Even when sync is false, this method may block while waiting for current
5522 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005523 *
5524 * @param ev A motion event describing the trackball action. (As noted in
5525 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005526 * {@link SystemClock#uptimeMillis()} as the timebase.)
5527 * @param sync If true, wait for the event to be completed before returning to the caller.
5528 * @return Returns true if event was dispatched, false if it was dropped for any reason
5529 */
5530 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005531 final int pid = Binder.getCallingPid();
5532 final int uid = Binder.getCallingUid();
5533 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac02010-04-22 18:58:52 -07005534
Jeff Brownc5ed5912010-07-14 18:48:53 -07005535 MotionEvent newEvent = MotionEvent.obtain(ev);
5536 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5537 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5538 }
5539
Jeff Brown6ec402b2010-07-28 15:48:59 -07005540 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5541 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5542 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5543 INJECTION_TIMEOUT_MILLIS);
5544
5545 Binder.restoreCallingIdentity(ident);
5546 return reportInjectionResult(result);
5547 }
5548
5549 /**
5550 * Inject an input event into the UI without waiting for dispatch to commence.
5551 * This variant is useful for fire-and-forget input event injection. It does not
5552 * block any longer than it takes to enqueue the input event.
5553 *
5554 * @param ev An input event. (Be sure to set the input source correctly.)
5555 * @return Returns true if event was dispatched, false if it was dropped for any reason
5556 */
5557 public boolean injectInputEventNoWait(InputEvent ev) {
5558 final int pid = Binder.getCallingPid();
5559 final int uid = Binder.getCallingUid();
5560 final long ident = Binder.clearCallingIdentity();
5561
5562 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5563 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5564 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005565
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005566 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005567 return reportInjectionResult(result);
5568 }
5569
5570 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005571 switch (result) {
5572 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5573 Slog.w(TAG, "Input event injection permission denied.");
5574 throw new SecurityException(
5575 "Injecting to another application requires INJECT_EVENTS permission");
5576 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005577 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005578 return true;
5579 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5580 Slog.w(TAG, "Input event injection timed out.");
5581 return false;
5582 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5583 default:
5584 Slog.w(TAG, "Input event injection failed.");
5585 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005586 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005587 }
Romain Guy06882f82009-06-10 13:36:04 -07005588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005589 private WindowState getFocusedWindow() {
5590 synchronized (mWindowMap) {
5591 return getFocusedWindowLocked();
5592 }
5593 }
5594
5595 private WindowState getFocusedWindowLocked() {
5596 return mCurrentFocus;
5597 }
Romain Guy06882f82009-06-10 13:36:04 -07005598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005599 public boolean detectSafeMode() {
5600 mSafeMode = mPolicy.detectSafeMode();
5601 return mSafeMode;
5602 }
Romain Guy06882f82009-06-10 13:36:04 -07005603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005604 public void systemReady() {
5605 mPolicy.systemReady();
5606 }
Romain Guy06882f82009-06-10 13:36:04 -07005607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005608 // -------------------------------------------------------------
5609 // Client Session State
5610 // -------------------------------------------------------------
5611
5612 private final class Session extends IWindowSession.Stub
5613 implements IBinder.DeathRecipient {
5614 final IInputMethodClient mClient;
5615 final IInputContext mInputContext;
5616 final int mUid;
5617 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005618 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005619 SurfaceSession mSurfaceSession;
5620 int mNumWindow = 0;
5621 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005623 public Session(IInputMethodClient client, IInputContext inputContext) {
5624 mClient = client;
5625 mInputContext = inputContext;
5626 mUid = Binder.getCallingUid();
5627 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005628 StringBuilder sb = new StringBuilder();
5629 sb.append("Session{");
5630 sb.append(Integer.toHexString(System.identityHashCode(this)));
5631 sb.append(" uid ");
5632 sb.append(mUid);
5633 sb.append("}");
5634 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636 synchronized (mWindowMap) {
5637 if (mInputMethodManager == null && mHaveInputMethods) {
5638 IBinder b = ServiceManager.getService(
5639 Context.INPUT_METHOD_SERVICE);
5640 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5641 }
5642 }
5643 long ident = Binder.clearCallingIdentity();
5644 try {
5645 // Note: it is safe to call in to the input method manager
5646 // here because we are not holding our lock.
5647 if (mInputMethodManager != null) {
5648 mInputMethodManager.addClient(client, inputContext,
5649 mUid, mPid);
5650 } else {
5651 client.setUsingInputMethod(false);
5652 }
5653 client.asBinder().linkToDeath(this, 0);
5654 } catch (RemoteException e) {
5655 // The caller has died, so we can just forget about this.
5656 try {
5657 if (mInputMethodManager != null) {
5658 mInputMethodManager.removeClient(client);
5659 }
5660 } catch (RemoteException ee) {
5661 }
5662 } finally {
5663 Binder.restoreCallingIdentity(ident);
5664 }
5665 }
Romain Guy06882f82009-06-10 13:36:04 -07005666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005667 @Override
5668 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5669 throws RemoteException {
5670 try {
5671 return super.onTransact(code, data, reply, flags);
5672 } catch (RuntimeException e) {
5673 // Log all 'real' exceptions thrown to the caller
5674 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005675 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005676 }
5677 throw e;
5678 }
5679 }
5680
5681 public void binderDied() {
5682 // Note: it is safe to call in to the input method manager
5683 // here because we are not holding our lock.
5684 try {
5685 if (mInputMethodManager != null) {
5686 mInputMethodManager.removeClient(mClient);
5687 }
5688 } catch (RemoteException e) {
5689 }
5690 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005691 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005692 mClientDead = true;
5693 killSessionLocked();
5694 }
5695 }
5696
5697 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac02010-04-22 18:58:52 -07005698 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5699 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5700 outInputChannel);
5701 }
5702
5703 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005704 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07005705 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005706 }
Romain Guy06882f82009-06-10 13:36:04 -07005707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005708 public void remove(IWindow window) {
5709 removeWindow(this, window);
5710 }
Romain Guy06882f82009-06-10 13:36:04 -07005711
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005712 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5713 int requestedWidth, int requestedHeight, int viewFlags,
5714 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005715 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005716 return relayoutWindow(this, window, attrs,
5717 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005718 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005719 }
Romain Guy06882f82009-06-10 13:36:04 -07005720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005721 public void setTransparentRegion(IWindow window, Region region) {
5722 setTransparentRegionWindow(this, window, region);
5723 }
Romain Guy06882f82009-06-10 13:36:04 -07005724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005725 public void setInsets(IWindow window, int touchableInsets,
5726 Rect contentInsets, Rect visibleInsets) {
5727 setInsetsWindow(this, window, touchableInsets, contentInsets,
5728 visibleInsets);
5729 }
Romain Guy06882f82009-06-10 13:36:04 -07005730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005731 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5732 getWindowDisplayFrame(this, window, outDisplayFrame);
5733 }
Romain Guy06882f82009-06-10 13:36:04 -07005734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005735 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005736 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005737 TAG, "IWindow finishDrawing called for " + window);
5738 finishDrawingWindow(this, window);
5739 }
5740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005741 public void setInTouchMode(boolean mode) {
5742 synchronized(mWindowMap) {
5743 mInTouchMode = mode;
5744 }
5745 }
5746
5747 public boolean getInTouchMode() {
5748 synchronized(mWindowMap) {
5749 return mInTouchMode;
5750 }
5751 }
5752
5753 public boolean performHapticFeedback(IWindow window, int effectId,
5754 boolean always) {
5755 synchronized(mWindowMap) {
5756 long ident = Binder.clearCallingIdentity();
5757 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005758 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005759 windowForClientLocked(this, window, true),
5760 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005761 } finally {
5762 Binder.restoreCallingIdentity(ident);
5763 }
5764 }
5765 }
Romain Guy06882f82009-06-10 13:36:04 -07005766
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005767 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005768 synchronized(mWindowMap) {
5769 long ident = Binder.clearCallingIdentity();
5770 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005771 setWindowWallpaperPositionLocked(
5772 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005773 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005774 } finally {
5775 Binder.restoreCallingIdentity(ident);
5776 }
5777 }
5778 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005779
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005780 public void wallpaperOffsetsComplete(IBinder window) {
5781 WindowManagerService.this.wallpaperOffsetsComplete(window);
5782 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005783
Dianne Hackborn75804932009-10-20 20:15:20 -07005784 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5785 int z, Bundle extras, boolean sync) {
5786 synchronized(mWindowMap) {
5787 long ident = Binder.clearCallingIdentity();
5788 try {
5789 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005790 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005791 action, x, y, z, extras, sync);
5792 } finally {
5793 Binder.restoreCallingIdentity(ident);
5794 }
5795 }
5796 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005797
Dianne Hackborn75804932009-10-20 20:15:20 -07005798 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5799 WindowManagerService.this.wallpaperCommandComplete(window, result);
5800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005802 void windowAddedLocked() {
5803 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005804 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005805 TAG, "First window added to " + this + ", creating SurfaceSession");
5806 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005807 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005808 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005809 mSessions.add(this);
5810 }
5811 mNumWindow++;
5812 }
5813
5814 void windowRemovedLocked() {
5815 mNumWindow--;
5816 killSessionLocked();
5817 }
Romain Guy06882f82009-06-10 13:36:04 -07005818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005819 void killSessionLocked() {
5820 if (mNumWindow <= 0 && mClientDead) {
5821 mSessions.remove(this);
5822 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005823 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005824 TAG, "Last window removed from " + this
5825 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005826 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005827 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005828 try {
5829 mSurfaceSession.kill();
5830 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005831 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005832 + mSurfaceSession + " in session " + this
5833 + ": " + e.toString());
5834 }
5835 mSurfaceSession = null;
5836 }
5837 }
5838 }
Romain Guy06882f82009-06-10 13:36:04 -07005839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005840 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005841 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5842 pw.print(" mClientDead="); pw.print(mClientDead);
5843 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005844 }
5845
5846 @Override
5847 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005848 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005849 }
5850 }
5851
5852 // -------------------------------------------------------------
5853 // Client Window State
5854 // -------------------------------------------------------------
5855
5856 private final class WindowState implements WindowManagerPolicy.WindowState {
5857 final Session mSession;
5858 final IWindow mClient;
5859 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005860 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005861 AppWindowToken mAppToken;
5862 AppWindowToken mTargetAppToken;
5863 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5864 final DeathRecipient mDeathRecipient;
5865 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005866 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005867 final int mBaseLayer;
5868 final int mSubLayer;
5869 final boolean mLayoutAttached;
5870 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005871 final boolean mIsWallpaper;
5872 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005873 int mViewVisibility;
5874 boolean mPolicyVisibility = true;
5875 boolean mPolicyVisibilityAfterAnim = true;
5876 boolean mAppFreezing;
5877 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005878 boolean mReportDestroySurface;
5879 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005880 boolean mAttachedHidden; // is our parent window hidden?
5881 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005882 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005883 int mRequestedWidth;
5884 int mRequestedHeight;
5885 int mLastRequestedWidth;
5886 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005887 int mLayer;
5888 int mAnimLayer;
5889 int mLastLayer;
5890 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005891 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005892 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005893
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005894 int mLayoutSeq = -1;
5895
5896 Configuration mConfiguration = null;
5897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005898 // Actual frame shown on-screen (may be modified by animation)
5899 final Rect mShownFrame = new Rect();
5900 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005901
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005902 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005903 * Set when we have changed the size of the surface, to know that
5904 * we must tell them application to resize (and thus redraw itself).
5905 */
5906 boolean mSurfaceResized;
5907
5908 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005909 * Insets that determine the actually visible area
5910 */
5911 final Rect mVisibleInsets = new Rect();
5912 final Rect mLastVisibleInsets = new Rect();
5913 boolean mVisibleInsetsChanged;
5914
5915 /**
5916 * Insets that are covered by system windows
5917 */
5918 final Rect mContentInsets = new Rect();
5919 final Rect mLastContentInsets = new Rect();
5920 boolean mContentInsetsChanged;
5921
5922 /**
5923 * Set to true if we are waiting for this window to receive its
5924 * given internal insets before laying out other windows based on it.
5925 */
5926 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005928 /**
5929 * These are the content insets that were given during layout for
5930 * this window, to be applied to windows behind it.
5931 */
5932 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005934 /**
5935 * These are the visible insets that were given during layout for
5936 * this window, to be applied to windows behind it.
5937 */
5938 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005940 /**
5941 * Flag indicating whether the touchable region should be adjusted by
5942 * the visible insets; if false the area outside the visible insets is
5943 * NOT touchable, so we must use those to adjust the frame during hit
5944 * tests.
5945 */
5946 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005948 // Current transformation being applied.
5949 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5950 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5951 float mHScale=1, mVScale=1;
5952 float mLastHScale=1, mLastVScale=1;
5953 final Matrix mTmpMatrix = new Matrix();
5954
5955 // "Real" frame that the application sees.
5956 final Rect mFrame = new Rect();
5957 final Rect mLastFrame = new Rect();
5958
5959 final Rect mContainingFrame = new Rect();
5960 final Rect mDisplayFrame = new Rect();
5961 final Rect mContentFrame = new Rect();
5962 final Rect mVisibleFrame = new Rect();
5963
5964 float mShownAlpha = 1;
5965 float mAlpha = 1;
5966 float mLastAlpha = 1;
5967
5968 // Set to true if, when the window gets displayed, it should perform
5969 // an enter animation.
5970 boolean mEnterAnimationPending;
5971
5972 // Currently running animation.
5973 boolean mAnimating;
5974 boolean mLocalAnimating;
5975 Animation mAnimation;
5976 boolean mAnimationIsEntrance;
5977 boolean mHasTransformation;
5978 boolean mHasLocalTransformation;
5979 final Transformation mTransformation = new Transformation();
5980
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005981 // If a window showing a wallpaper: the requested offset for the
5982 // wallpaper; if a wallpaper window: the currently applied offset.
5983 float mWallpaperX = -1;
5984 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005985
5986 // If a window showing a wallpaper: what fraction of the offset
5987 // range corresponds to a full virtual screen.
5988 float mWallpaperXStep = -1;
5989 float mWallpaperYStep = -1;
5990
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07005991 // Wallpaper windows: pixels offset based on above variables.
5992 int mXOffset;
5993 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005995 // This is set after IWindowSession.relayout() has been called at
5996 // least once for the window. It allows us to detect the situation
5997 // where we don't yet have a surface, but should have one soon, so
5998 // we can give the window focus before waiting for the relayout.
5999 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006001 // This is set after the Surface has been created but before the
6002 // window has been drawn. During this time the surface is hidden.
6003 boolean mDrawPending;
6004
6005 // This is set after the window has finished drawing for the first
6006 // time but before its surface is shown. The surface will be
6007 // displayed when the next layout is run.
6008 boolean mCommitDrawPending;
6009
6010 // This is set during the time after the window's drawing has been
6011 // committed, and before its surface is actually shown. It is used
6012 // to delay showing the surface until all windows in a token are ready
6013 // to be shown.
6014 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006016 // Set when the window has been shown in the screen the first time.
6017 boolean mHasDrawn;
6018
6019 // Currently running an exit animation?
6020 boolean mExiting;
6021
6022 // Currently on the mDestroySurface list?
6023 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006025 // Completely remove from window manager after exit animation?
6026 boolean mRemoveOnExit;
6027
6028 // Set when the orientation is changing and this window has not yet
6029 // been updated for the new orientation.
6030 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006032 // Is this window now (or just being) removed?
6033 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006034
Dianne Hackborn16064f92010-03-25 00:47:24 -07006035 // For debugging, this is the last information given to the surface flinger.
6036 boolean mSurfaceShown;
6037 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6038 int mSurfaceLayer;
6039 float mSurfaceAlpha;
6040
Jeff Brown46b9ac02010-04-22 18:58:52 -07006041 // Input channel
6042 InputChannel mInputChannel;
6043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006044 WindowState(Session s, IWindow c, WindowToken token,
6045 WindowState attachedWindow, WindowManager.LayoutParams a,
6046 int viewVisibility) {
6047 mSession = s;
6048 mClient = c;
6049 mToken = token;
6050 mAttrs.copyFrom(a);
6051 mViewVisibility = viewVisibility;
6052 DeathRecipient deathRecipient = new DeathRecipient();
6053 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006054 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006055 TAG, "Window " + this + " client=" + c.asBinder()
6056 + " token=" + token + " (" + mAttrs.token + ")");
6057 try {
6058 c.asBinder().linkToDeath(deathRecipient, 0);
6059 } catch (RemoteException e) {
6060 mDeathRecipient = null;
6061 mAttachedWindow = null;
6062 mLayoutAttached = false;
6063 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006064 mIsWallpaper = false;
6065 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 mBaseLayer = 0;
6067 mSubLayer = 0;
6068 return;
6069 }
6070 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6073 mAttrs.type <= LAST_SUB_WINDOW)) {
6074 // The multiplier here is to reserve space for multiple
6075 // windows in the same type layer.
6076 mBaseLayer = mPolicy.windowTypeToLayerLw(
6077 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6078 + TYPE_LAYER_OFFSET;
6079 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6080 mAttachedWindow = attachedWindow;
6081 mAttachedWindow.mChildWindows.add(this);
6082 mLayoutAttached = mAttrs.type !=
6083 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6084 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6085 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006086 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6087 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006088 } else {
6089 // The multiplier here is to reserve space for multiple
6090 // windows in the same type layer.
6091 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6092 * TYPE_LAYER_MULTIPLIER
6093 + TYPE_LAYER_OFFSET;
6094 mSubLayer = 0;
6095 mAttachedWindow = null;
6096 mLayoutAttached = false;
6097 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6098 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006099 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6100 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006101 }
6102
6103 WindowState appWin = this;
6104 while (appWin.mAttachedWindow != null) {
6105 appWin = mAttachedWindow;
6106 }
6107 WindowToken appToken = appWin.mToken;
6108 while (appToken.appWindowToken == null) {
6109 WindowToken parent = mTokenMap.get(appToken.token);
6110 if (parent == null || appToken == parent) {
6111 break;
6112 }
6113 appToken = parent;
6114 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006115 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 mAppToken = appToken.appWindowToken;
6117
6118 mSurface = null;
6119 mRequestedWidth = 0;
6120 mRequestedHeight = 0;
6121 mLastRequestedWidth = 0;
6122 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006123 mXOffset = 0;
6124 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006125 mLayer = 0;
6126 mAnimLayer = 0;
6127 mLastLayer = 0;
6128 }
6129
6130 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006131 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 TAG, "Attaching " + this + " token=" + mToken
6133 + ", list=" + mToken.windows);
6134 mSession.windowAddedLocked();
6135 }
6136
6137 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6138 mHaveFrame = true;
6139
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006140 final Rect container = mContainingFrame;
6141 container.set(pf);
6142
6143 final Rect display = mDisplayFrame;
6144 display.set(df);
6145
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006146 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006147 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006148 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6149 display.intersect(mCompatibleScreenFrame);
6150 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006151 }
6152
6153 final int pw = container.right - container.left;
6154 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006155
6156 int w,h;
6157 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6158 w = mAttrs.width < 0 ? pw : mAttrs.width;
6159 h = mAttrs.height< 0 ? ph : mAttrs.height;
6160 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006161 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6162 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006163 }
Romain Guy06882f82009-06-10 13:36:04 -07006164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006165 final Rect content = mContentFrame;
6166 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 final Rect visible = mVisibleFrame;
6169 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006171 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006172 final int fw = frame.width();
6173 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006175 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6176 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6177
6178 Gravity.apply(mAttrs.gravity, w, h, container,
6179 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6180 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6181
6182 //System.out.println("Out: " + mFrame);
6183
6184 // Now make sure the window fits in the overall display.
6185 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006187 // Make sure the content and visible frames are inside of the
6188 // final window frame.
6189 if (content.left < frame.left) content.left = frame.left;
6190 if (content.top < frame.top) content.top = frame.top;
6191 if (content.right > frame.right) content.right = frame.right;
6192 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6193 if (visible.left < frame.left) visible.left = frame.left;
6194 if (visible.top < frame.top) visible.top = frame.top;
6195 if (visible.right > frame.right) visible.right = frame.right;
6196 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006198 final Rect contentInsets = mContentInsets;
6199 contentInsets.left = content.left-frame.left;
6200 contentInsets.top = content.top-frame.top;
6201 contentInsets.right = frame.right-content.right;
6202 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006204 final Rect visibleInsets = mVisibleInsets;
6205 visibleInsets.left = visible.left-frame.left;
6206 visibleInsets.top = visible.top-frame.top;
6207 visibleInsets.right = frame.right-visible.right;
6208 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006209
Dianne Hackborn284ac932009-08-28 10:34:25 -07006210 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6211 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006212 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006213 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215 if (localLOGV) {
6216 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6217 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006218 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006219 + mRequestedWidth + ", mRequestedheight="
6220 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6221 + "): frame=" + mFrame.toShortString()
6222 + " ci=" + contentInsets.toShortString()
6223 + " vi=" + visibleInsets.toShortString());
6224 //}
6225 }
6226 }
Romain Guy06882f82009-06-10 13:36:04 -07006227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006228 public Rect getFrameLw() {
6229 return mFrame;
6230 }
6231
6232 public Rect getShownFrameLw() {
6233 return mShownFrame;
6234 }
6235
6236 public Rect getDisplayFrameLw() {
6237 return mDisplayFrame;
6238 }
6239
6240 public Rect getContentFrameLw() {
6241 return mContentFrame;
6242 }
6243
6244 public Rect getVisibleFrameLw() {
6245 return mVisibleFrame;
6246 }
6247
6248 public boolean getGivenInsetsPendingLw() {
6249 return mGivenInsetsPending;
6250 }
6251
6252 public Rect getGivenContentInsetsLw() {
6253 return mGivenContentInsets;
6254 }
Romain Guy06882f82009-06-10 13:36:04 -07006255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 public Rect getGivenVisibleInsetsLw() {
6257 return mGivenVisibleInsets;
6258 }
Romain Guy06882f82009-06-10 13:36:04 -07006259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006260 public WindowManager.LayoutParams getAttrs() {
6261 return mAttrs;
6262 }
6263
6264 public int getSurfaceLayer() {
6265 return mLayer;
6266 }
Romain Guy06882f82009-06-10 13:36:04 -07006267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 public IApplicationToken getAppToken() {
6269 return mAppToken != null ? mAppToken.appToken : null;
6270 }
Jeff Brown349703e2010-06-22 01:27:15 -07006271
6272 public long getInputDispatchingTimeoutNanos() {
6273 return mAppToken != null
6274 ? mAppToken.inputDispatchingTimeoutNanos
6275 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6276 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006277
6278 public boolean hasAppShownWindows() {
6279 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6280 }
6281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006282 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006283 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006284 TAG, "Setting animation in " + this + ": " + anim);
6285 mAnimating = false;
6286 mLocalAnimating = false;
6287 mAnimation = anim;
6288 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6289 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6290 }
6291
6292 public void clearAnimation() {
6293 if (mAnimation != null) {
6294 mAnimating = true;
6295 mLocalAnimating = false;
6296 mAnimation = null;
6297 }
6298 }
Romain Guy06882f82009-06-10 13:36:04 -07006299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006300 Surface createSurfaceLocked() {
6301 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006302 mReportDestroySurface = false;
6303 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006304 mDrawPending = true;
6305 mCommitDrawPending = false;
6306 mReadyToShow = false;
6307 if (mAppToken != null) {
6308 mAppToken.allDrawn = false;
6309 }
6310
6311 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006312 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 flags |= Surface.PUSH_BUFFERS;
6314 }
6315
6316 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6317 flags |= Surface.SECURE;
6318 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006319 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006320 TAG, "Creating surface in session "
6321 + mSession.mSurfaceSession + " window " + this
6322 + " w=" + mFrame.width()
6323 + " h=" + mFrame.height() + " format="
6324 + mAttrs.format + " flags=" + flags);
6325
6326 int w = mFrame.width();
6327 int h = mFrame.height();
6328 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6329 // for a scaled surface, we always want the requested
6330 // size.
6331 w = mRequestedWidth;
6332 h = mRequestedHeight;
6333 }
6334
Romain Guy9825ec62009-10-01 00:58:09 -07006335 // Something is wrong and SurfaceFlinger will not like this,
6336 // try to revert to sane values
6337 if (w <= 0) w = 1;
6338 if (h <= 0) h = 1;
6339
Dianne Hackborn16064f92010-03-25 00:47:24 -07006340 mSurfaceShown = false;
6341 mSurfaceLayer = 0;
6342 mSurfaceAlpha = 1;
6343 mSurfaceX = 0;
6344 mSurfaceY = 0;
6345 mSurfaceW = w;
6346 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006347 try {
6348 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006349 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006350 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006351 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006352 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006353 + mSurface + " IN SESSION "
6354 + mSession.mSurfaceSession
6355 + ": pid=" + mSession.mPid + " format="
6356 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006357 + Integer.toHexString(flags)
6358 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006359 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006360 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006361 reclaimSomeSurfaceMemoryLocked(this, "create");
6362 return null;
6363 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006364 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006365 return null;
6366 }
Romain Guy06882f82009-06-10 13:36:04 -07006367
Joe Onorato8a9b2202010-02-26 18:56:32 -08006368 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006369 TAG, "Got surface: " + mSurface
6370 + ", set left=" + mFrame.left + " top=" + mFrame.top
6371 + ", animLayer=" + mAnimLayer);
6372 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006373 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006374 if (SHOW_TRANSACTIONS) logSurface(this,
6375 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6376 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6377 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006378 }
6379 Surface.openTransaction();
6380 try {
6381 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006382 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006383 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006384 mSurface.setPosition(mSurfaceX, mSurfaceY);
6385 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006386 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006387 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006388 mSurface.hide();
6389 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006390 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006391 mSurface.setFlags(Surface.SURFACE_DITHER,
6392 Surface.SURFACE_DITHER);
6393 }
6394 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006395 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6397 }
6398 mLastHidden = true;
6399 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006400 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006401 Surface.closeTransaction();
6402 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006403 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006404 TAG, "Created surface " + this);
6405 }
6406 return mSurface;
6407 }
Romain Guy06882f82009-06-10 13:36:04 -07006408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006409 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006410 if (mAppToken != null && this == mAppToken.startingWindow) {
6411 mAppToken.startingDisplayed = false;
6412 }
Romain Guy06882f82009-06-10 13:36:04 -07006413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006415 mDrawPending = false;
6416 mCommitDrawPending = false;
6417 mReadyToShow = false;
6418
6419 int i = mChildWindows.size();
6420 while (i > 0) {
6421 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006422 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006423 c.mAttachedHidden = true;
6424 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006425
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006426 if (mReportDestroySurface) {
6427 mReportDestroySurface = false;
6428 mSurfacePendingDestroy = true;
6429 try {
6430 mClient.dispatchGetNewSurface();
6431 // We'll really destroy on the next time around.
6432 return;
6433 } catch (RemoteException e) {
6434 }
6435 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006437 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006438 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006439 RuntimeException e = null;
6440 if (!HIDE_STACK_CRAWLS) {
6441 e = new RuntimeException();
6442 e.fillInStackTrace();
6443 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006444 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006445 + mSurface + ", session " + mSession, e);
6446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006447 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006448 RuntimeException e = null;
6449 if (!HIDE_STACK_CRAWLS) {
6450 e = new RuntimeException();
6451 e.fillInStackTrace();
6452 }
6453 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006454 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006455 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006456 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006457 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006458 + " surface " + mSurface + " session " + mSession
6459 + ": " + e.toString());
6460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006461
Dianne Hackborn16064f92010-03-25 00:47:24 -07006462 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006463 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006464 }
6465 }
6466
6467 boolean finishDrawingLocked() {
6468 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006469 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006470 TAG, "finishDrawingLocked: " + mSurface);
6471 mCommitDrawPending = true;
6472 mDrawPending = false;
6473 return true;
6474 }
6475 return false;
6476 }
6477
6478 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006479 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006480 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006481 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006482 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006483 }
6484 mCommitDrawPending = false;
6485 mReadyToShow = true;
6486 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6487 final AppWindowToken atoken = mAppToken;
6488 if (atoken == null || atoken.allDrawn || starting) {
6489 performShowLocked();
6490 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006491 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 }
6493
6494 // This must be called while inside a transaction.
6495 boolean performShowLocked() {
6496 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006497 RuntimeException e = null;
6498 if (!HIDE_STACK_CRAWLS) {
6499 e = new RuntimeException();
6500 e.fillInStackTrace();
6501 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006502 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6504 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6505 }
6506 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006507 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6508 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006509 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006510 + " during animation: policyVis=" + mPolicyVisibility
6511 + " attHidden=" + mAttachedHidden
6512 + " tok.hiddenRequested="
6513 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006514 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006515 + (mAppToken != null ? mAppToken.hidden : false)
6516 + " animating=" + mAnimating
6517 + " tok animating="
6518 + (mAppToken != null ? mAppToken.animating : false));
6519 if (!showSurfaceRobustlyLocked(this)) {
6520 return false;
6521 }
6522 mLastAlpha = -1;
6523 mHasDrawn = true;
6524 mLastHidden = false;
6525 mReadyToShow = false;
6526 enableScreenIfNeededLocked();
6527
6528 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006529
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006530 int i = mChildWindows.size();
6531 while (i > 0) {
6532 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006533 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006534 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006535 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006536 if (c.mSurface != null) {
6537 c.performShowLocked();
6538 // It hadn't been shown, which means layout not
6539 // performed on it, so now we want to make sure to
6540 // do a layout. If called from within the transaction
6541 // loop, this will cause it to restart with a new
6542 // layout.
6543 mLayoutNeeded = true;
6544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006545 }
6546 }
Romain Guy06882f82009-06-10 13:36:04 -07006547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006548 if (mAttrs.type != TYPE_APPLICATION_STARTING
6549 && mAppToken != null) {
6550 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006551
Dianne Hackborn248b1882009-09-16 16:46:44 -07006552 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006553 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006554 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006555 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006556 // If this initial window is animating, stop it -- we
6557 // will do an animation to reveal it from behind the
6558 // starting window, so there is no need for it to also
6559 // be doing its own stuff.
6560 if (mAnimation != null) {
6561 mAnimation = null;
6562 // Make sure we clean up the animation.
6563 mAnimating = true;
6564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006565 mFinishedStarting.add(mAppToken);
6566 mH.sendEmptyMessage(H.FINISHED_STARTING);
6567 }
6568 mAppToken.updateReportedVisibilityLocked();
6569 }
6570 }
6571 return true;
6572 }
Romain Guy06882f82009-06-10 13:36:04 -07006573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006574 // This must be called while inside a transaction. Returns true if
6575 // there is more animation to run.
6576 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006577 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006578 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006580 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6581 mHasTransformation = true;
6582 mHasLocalTransformation = true;
6583 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006584 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006585 TAG, "Starting animation in " + this +
6586 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6587 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6588 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6589 mAnimation.setStartTime(currentTime);
6590 mLocalAnimating = true;
6591 mAnimating = true;
6592 }
6593 mTransformation.clear();
6594 final boolean more = mAnimation.getTransformation(
6595 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006596 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006597 TAG, "Stepped animation in " + this +
6598 ": more=" + more + ", xform=" + mTransformation);
6599 if (more) {
6600 // we're not done!
6601 return true;
6602 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006603 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006604 TAG, "Finished animation in " + this +
6605 " @ " + currentTime);
6606 mAnimation = null;
6607 //WindowManagerService.this.dump();
6608 }
6609 mHasLocalTransformation = false;
6610 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006611 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006612 // When our app token is animating, we kind-of pretend like
6613 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6614 // part of this check means that we will only do this if
6615 // our window is not currently exiting, or it is not
6616 // locally animating itself. The idea being that one that
6617 // is exiting and doing a local animation should be removed
6618 // once that animation is done.
6619 mAnimating = true;
6620 mHasTransformation = true;
6621 mTransformation.clear();
6622 return false;
6623 } else if (mHasTransformation) {
6624 // Little trick to get through the path below to act like
6625 // we have finished an animation.
6626 mAnimating = true;
6627 } else if (isAnimating()) {
6628 mAnimating = true;
6629 }
6630 } else if (mAnimation != null) {
6631 // If the display is frozen, and there is a pending animation,
6632 // clear it and make sure we run the cleanup code.
6633 mAnimating = true;
6634 mLocalAnimating = true;
6635 mAnimation = null;
6636 }
Romain Guy06882f82009-06-10 13:36:04 -07006637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006638 if (!mAnimating && !mLocalAnimating) {
6639 return false;
6640 }
6641
Joe Onorato8a9b2202010-02-26 18:56:32 -08006642 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006643 TAG, "Animation done in " + this + ": exiting=" + mExiting
6644 + ", reportedVisible="
6645 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006647 mAnimating = false;
6648 mLocalAnimating = false;
6649 mAnimation = null;
6650 mAnimLayer = mLayer;
6651 if (mIsImWindow) {
6652 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006653 } else if (mIsWallpaper) {
6654 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006656 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006657 + " anim layer: " + mAnimLayer);
6658 mHasTransformation = false;
6659 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006660 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6661 if (DEBUG_VISIBILITY) {
6662 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6663 + mPolicyVisibilityAfterAnim);
6664 }
6665 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6666 if (!mPolicyVisibility) {
6667 if (mCurrentFocus == this) {
6668 mFocusMayChange = true;
6669 }
6670 // Window is no longer visible -- make sure if we were waiting
6671 // for it to be displayed before enabling the display, that
6672 // we allow the display to be enabled now.
6673 enableScreenIfNeededLocked();
6674 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006676 mTransformation.clear();
6677 if (mHasDrawn
6678 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6679 && mAppToken != null
6680 && mAppToken.firstWindowDrawn
6681 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006682 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 + mToken + ": first real window done animating");
6684 mFinishedStarting.add(mAppToken);
6685 mH.sendEmptyMessage(H.FINISHED_STARTING);
6686 }
Romain Guy06882f82009-06-10 13:36:04 -07006687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006688 finishExit();
6689
6690 if (mAppToken != null) {
6691 mAppToken.updateReportedVisibilityLocked();
6692 }
6693
6694 return false;
6695 }
6696
6697 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006698 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006699 TAG, "finishExit in " + this
6700 + ": exiting=" + mExiting
6701 + " remove=" + mRemoveOnExit
6702 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006704 final int N = mChildWindows.size();
6705 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006706 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006707 }
Romain Guy06882f82009-06-10 13:36:04 -07006708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006709 if (!mExiting) {
6710 return;
6711 }
Romain Guy06882f82009-06-10 13:36:04 -07006712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006713 if (isWindowAnimating()) {
6714 return;
6715 }
6716
Joe Onorato8a9b2202010-02-26 18:56:32 -08006717 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006718 TAG, "Exit animation finished in " + this
6719 + ": remove=" + mRemoveOnExit);
6720 if (mSurface != null) {
6721 mDestroySurface.add(this);
6722 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006723 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006724 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006725 try {
6726 mSurface.hide();
6727 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006728 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006729 }
6730 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006731 }
6732 mExiting = false;
6733 if (mRemoveOnExit) {
6734 mPendingRemove.add(this);
6735 mRemoveOnExit = false;
6736 }
6737 }
Romain Guy06882f82009-06-10 13:36:04 -07006738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006739 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6740 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6741 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6742 if (dtdx < -.000001f || dtdx > .000001f) return false;
6743 if (dsdy < -.000001f || dsdy > .000001f) return false;
6744 return true;
6745 }
Romain Guy06882f82009-06-10 13:36:04 -07006746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 void computeShownFrameLocked() {
6748 final boolean selfTransformation = mHasLocalTransformation;
6749 Transformation attachedTransformation =
6750 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6751 ? mAttachedWindow.mTransformation : null;
6752 Transformation appTransformation =
6753 (mAppToken != null && mAppToken.hasTransformation)
6754 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006755
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006756 // Wallpapers are animated based on the "real" window they
6757 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006758 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006759 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006760 if (mWallpaperTarget.mHasLocalTransformation &&
6761 mWallpaperTarget.mAnimation != null &&
6762 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006763 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006764 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006765 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006766 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006767 }
6768 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006769 mWallpaperTarget.mAppToken.hasTransformation &&
6770 mWallpaperTarget.mAppToken.animation != null &&
6771 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006772 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006773 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006774 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006775 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006776 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006779 if (selfTransformation || attachedTransformation != null
6780 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006781 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006782 final Rect frame = mFrame;
6783 final float tmpFloats[] = mTmpFloats;
6784 final Matrix tmpMatrix = mTmpMatrix;
6785
6786 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006787 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006788 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006789 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006790 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006791 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006792 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006793 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006794 }
6795 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006796 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006797 }
6798
6799 // "convert" it into SurfaceFlinger's format
6800 // (a 2x2 matrix + an offset)
6801 // Here we must not transform the position of the surface
6802 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006803 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006805 tmpMatrix.getValues(tmpFloats);
6806 mDsDx = tmpFloats[Matrix.MSCALE_X];
6807 mDtDx = tmpFloats[Matrix.MSKEW_X];
6808 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6809 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006810 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6811 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006812 int w = frame.width();
6813 int h = frame.height();
6814 mShownFrame.set(x, y, x+w, y+h);
6815
6816 // Now set the alpha... but because our current hardware
6817 // can't do alpha transformation on a non-opaque surface,
6818 // turn it off if we are running an animation that is also
6819 // transforming since it is more important to have that
6820 // animation be smooth.
6821 mShownAlpha = mAlpha;
6822 if (!mLimitedAlphaCompositing
6823 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6824 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6825 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006826 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006827 if (selfTransformation) {
6828 mShownAlpha *= mTransformation.getAlpha();
6829 }
6830 if (attachedTransformation != null) {
6831 mShownAlpha *= attachedTransformation.getAlpha();
6832 }
6833 if (appTransformation != null) {
6834 mShownAlpha *= appTransformation.getAlpha();
6835 }
6836 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006837 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 }
Romain Guy06882f82009-06-10 13:36:04 -07006839
Joe Onorato8a9b2202010-02-26 18:56:32 -08006840 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006841 TAG, "Continuing animation in " + this +
6842 ": " + mShownFrame +
6843 ", alpha=" + mTransformation.getAlpha());
6844 return;
6845 }
Romain Guy06882f82009-06-10 13:36:04 -07006846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006847 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006848 if (mXOffset != 0 || mYOffset != 0) {
6849 mShownFrame.offset(mXOffset, mYOffset);
6850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006851 mShownAlpha = mAlpha;
6852 mDsDx = 1;
6853 mDtDx = 0;
6854 mDsDy = 0;
6855 mDtDy = 1;
6856 }
Romain Guy06882f82009-06-10 13:36:04 -07006857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006858 /**
6859 * Is this window visible? It is not visible if there is no
6860 * surface, or we are in the process of running an exit animation
6861 * that will remove the surface, or its app token has been hidden.
6862 */
6863 public boolean isVisibleLw() {
6864 final AppWindowToken atoken = mAppToken;
6865 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6866 && (atoken == null || !atoken.hiddenRequested)
6867 && !mExiting && !mDestroying;
6868 }
6869
6870 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006871 * Like {@link #isVisibleLw}, but also counts a window that is currently
6872 * "hidden" behind the keyguard as visible. This allows us to apply
6873 * things like window flags that impact the keyguard.
6874 * XXX I am starting to think we need to have ANOTHER visibility flag
6875 * for this "hidden behind keyguard" state rather than overloading
6876 * mPolicyVisibility. Ungh.
6877 */
6878 public boolean isVisibleOrBehindKeyguardLw() {
6879 final AppWindowToken atoken = mAppToken;
6880 return mSurface != null && !mAttachedHidden
6881 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackborn5943c202010-04-12 21:36:49 -07006882 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending))
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006883 && !mExiting && !mDestroying;
6884 }
6885
6886 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006887 * Is this window visible, ignoring its app token? It is not visible
6888 * if there is no surface, or we are in the process of running an exit animation
6889 * that will remove the surface.
6890 */
6891 public boolean isWinVisibleLw() {
6892 final AppWindowToken atoken = mAppToken;
6893 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6894 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6895 && !mExiting && !mDestroying;
6896 }
6897
6898 /**
6899 * The same as isVisible(), but follows the current hidden state of
6900 * the associated app token, not the pending requested hidden state.
6901 */
6902 boolean isVisibleNow() {
6903 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006904 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006905 }
6906
6907 /**
6908 * Same as isVisible(), but we also count it as visible between the
6909 * call to IWindowSession.add() and the first relayout().
6910 */
6911 boolean isVisibleOrAdding() {
6912 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006913 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006914 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6915 && mPolicyVisibility && !mAttachedHidden
6916 && (atoken == null || !atoken.hiddenRequested)
6917 && !mExiting && !mDestroying;
6918 }
6919
6920 /**
6921 * Is this window currently on-screen? It is on-screen either if it
6922 * is visible or it is currently running an animation before no longer
6923 * being visible.
6924 */
6925 boolean isOnScreen() {
6926 final AppWindowToken atoken = mAppToken;
6927 if (atoken != null) {
6928 return mSurface != null && mPolicyVisibility && !mDestroying
6929 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006930 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006931 } else {
6932 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006933 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 }
6935 }
Romain Guy06882f82009-06-10 13:36:04 -07006936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006937 /**
6938 * Like isOnScreen(), but we don't return true if the window is part
6939 * of a transition that has not yet been started.
6940 */
6941 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006942 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006943 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006944 return false;
6945 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006946 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006947 final boolean animating = atoken != null
6948 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006949 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006950 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6951 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006952 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006953 }
6954
6955 /** Is the window or its container currently animating? */
6956 boolean isAnimating() {
6957 final WindowState attached = mAttachedWindow;
6958 final AppWindowToken atoken = mAppToken;
6959 return mAnimation != null
6960 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006961 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 (atoken.animation != null
6963 || atoken.inPendingTransaction));
6964 }
6965
6966 /** Is this window currently animating? */
6967 boolean isWindowAnimating() {
6968 return mAnimation != null;
6969 }
6970
6971 /**
6972 * Like isOnScreen, but returns false if the surface hasn't yet
6973 * been drawn.
6974 */
6975 public boolean isDisplayedLw() {
6976 final AppWindowToken atoken = mAppToken;
6977 return mSurface != null && mPolicyVisibility && !mDestroying
6978 && !mDrawPending && !mCommitDrawPending
6979 && ((!mAttachedHidden &&
6980 (atoken == null || !atoken.hiddenRequested))
6981 || mAnimating);
6982 }
6983
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006984 /**
6985 * Returns true if the window has a surface that it has drawn a
Dianne Hackborn5943c202010-04-12 21:36:49 -07006986 * complete UI in to. Note that this returns true if the orientation
6987 * is changing even if the window hasn't redrawn because we don't want
6988 * to stop things from executing during that time.
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006989 */
6990 public boolean isDrawnLw() {
6991 final AppWindowToken atoken = mAppToken;
6992 return mSurface != null && !mDestroying
Dianne Hackborn5943c202010-04-12 21:36:49 -07006993 && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending));
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07006994 }
6995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006996 public boolean fillsScreenLw(int screenWidth, int screenHeight,
6997 boolean shownFrame, boolean onlyOpaque) {
6998 if (mSurface == null) {
6999 return false;
7000 }
7001 if (mAppToken != null && !mAppToken.appFullscreen) {
7002 return false;
7003 }
7004 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7005 return false;
7006 }
7007 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007008
7009 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7010 return frame.left <= mCompatibleScreenFrame.left &&
7011 frame.top <= mCompatibleScreenFrame.top &&
7012 frame.right >= mCompatibleScreenFrame.right &&
7013 frame.bottom >= mCompatibleScreenFrame.bottom;
7014 } else {
7015 return frame.left <= 0 && frame.top <= 0
7016 && frame.right >= screenWidth
7017 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007019 }
Romain Guy06882f82009-06-10 13:36:04 -07007020
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007021 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007022 * Return true if the window is opaque and fully drawn. This indicates
7023 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007024 */
7025 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007026 return (mAttrs.format == PixelFormat.OPAQUE
7027 || mAttrs.type == TYPE_WALLPAPER)
7028 && mSurface != null && mAnimation == null
7029 && (mAppToken == null || mAppToken.animation == null)
7030 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007031 }
7032
7033 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7034 return
7035 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007036 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7037 // only if it's visible
7038 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007039 // and only if the application fills the compatible screen
7040 mFrame.left <= mCompatibleScreenFrame.left &&
7041 mFrame.top <= mCompatibleScreenFrame.top &&
7042 mFrame.right >= mCompatibleScreenFrame.right &&
7043 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007044 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007045 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007046 }
7047
7048 boolean isFullscreen(int screenWidth, int screenHeight) {
7049 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007050 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007051 }
7052
7053 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007054 disposeInputChannel();
7055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007056 if (mAttachedWindow != null) {
7057 mAttachedWindow.mChildWindows.remove(this);
7058 }
7059 destroySurfaceLocked();
7060 mSession.windowRemovedLocked();
7061 try {
7062 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7063 } catch (RuntimeException e) {
7064 // Ignore if it has already been removed (usually because
7065 // we are doing this as part of processing a death note.)
7066 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007067 }
7068
7069 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007070 if (mInputChannel != null) {
7071 mInputManager.unregisterInputChannel(mInputChannel);
7072
7073 mInputChannel.dispose();
7074 mInputChannel = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07007075 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007076 }
7077
7078 private class DeathRecipient implements IBinder.DeathRecipient {
7079 public void binderDied() {
7080 try {
7081 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007082 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007083 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 if (win != null) {
7085 removeWindowLocked(mSession, win);
7086 }
7087 }
7088 } catch (IllegalArgumentException ex) {
7089 // This will happen if the window has already been
7090 // removed.
7091 }
7092 }
7093 }
7094
7095 /** Returns true if this window desires key events. */
7096 public final boolean canReceiveKeys() {
7097 return isVisibleOrAdding()
7098 && (mViewVisibility == View.VISIBLE)
7099 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7100 }
7101
7102 public boolean hasDrawnLw() {
7103 return mHasDrawn;
7104 }
7105
7106 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007107 return showLw(doAnimation, true);
7108 }
7109
7110 boolean showLw(boolean doAnimation, boolean requestAnim) {
7111 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7112 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007113 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007114 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007115 if (doAnimation) {
7116 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7117 + mPolicyVisibility + " mAnimation=" + mAnimation);
7118 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7119 doAnimation = false;
7120 } else if (mPolicyVisibility && mAnimation == null) {
7121 // Check for the case where we are currently visible and
7122 // not animating; we do not want to do animation at such a
7123 // point to become visible when we already are.
7124 doAnimation = false;
7125 }
7126 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007127 mPolicyVisibility = true;
7128 mPolicyVisibilityAfterAnim = true;
7129 if (doAnimation) {
7130 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7131 }
7132 if (requestAnim) {
7133 requestAnimationLocked(0);
7134 }
7135 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007136 }
7137
7138 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007139 return hideLw(doAnimation, true);
7140 }
7141
7142 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007143 if (doAnimation) {
7144 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7145 doAnimation = false;
7146 }
7147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007148 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7149 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007150 if (!current) {
7151 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007152 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007153 if (doAnimation) {
7154 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7155 if (mAnimation == null) {
7156 doAnimation = false;
7157 }
7158 }
7159 if (doAnimation) {
7160 mPolicyVisibilityAfterAnim = false;
7161 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007162 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007163 mPolicyVisibilityAfterAnim = false;
7164 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007165 // Window is no longer visible -- make sure if we were waiting
7166 // for it to be displayed before enabling the display, that
7167 // we allow the display to be enabled now.
7168 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007169 if (mCurrentFocus == this) {
7170 mFocusMayChange = true;
7171 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007172 }
7173 if (requestAnim) {
7174 requestAnimationLocked(0);
7175 }
7176 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007177 }
7178
7179 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007180 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7181 pw.print(" mClient="); pw.println(mClient.asBinder());
7182 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7183 if (mAttachedWindow != null || mLayoutAttached) {
7184 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7185 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7186 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007187 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7188 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7189 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007190 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7191 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007192 }
7193 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7194 pw.print(" mSubLayer="); pw.print(mSubLayer);
7195 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7196 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7197 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7198 pw.print("="); pw.print(mAnimLayer);
7199 pw.print(" mLastLayer="); pw.println(mLastLayer);
7200 if (mSurface != null) {
7201 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007202 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7203 pw.print(" layer="); pw.print(mSurfaceLayer);
7204 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7205 pw.print(" rect=("); pw.print(mSurfaceX);
7206 pw.print(","); pw.print(mSurfaceY);
7207 pw.print(") "); pw.print(mSurfaceW);
7208 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007209 }
7210 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7211 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7212 if (mAppToken != null) {
7213 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7214 }
7215 if (mTargetAppToken != null) {
7216 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7217 }
7218 pw.print(prefix); pw.print("mViewVisibility=0x");
7219 pw.print(Integer.toHexString(mViewVisibility));
7220 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007221 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7222 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007223 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7224 pw.print(prefix); pw.print("mPolicyVisibility=");
7225 pw.print(mPolicyVisibility);
7226 pw.print(" mPolicyVisibilityAfterAnim=");
7227 pw.print(mPolicyVisibilityAfterAnim);
7228 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7229 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007230 if (!mRelayoutCalled) {
7231 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7232 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007233 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007234 pw.print(" h="); pw.print(mRequestedHeight);
7235 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007236 if (mXOffset != 0 || mYOffset != 0) {
7237 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7238 pw.print(" y="); pw.println(mYOffset);
7239 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007240 pw.print(prefix); pw.print("mGivenContentInsets=");
7241 mGivenContentInsets.printShortString(pw);
7242 pw.print(" mGivenVisibleInsets=");
7243 mGivenVisibleInsets.printShortString(pw);
7244 pw.println();
7245 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7246 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7247 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7248 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007249 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007250 pw.print(prefix); pw.print("mShownFrame=");
7251 mShownFrame.printShortString(pw);
7252 pw.print(" last="); mLastShownFrame.printShortString(pw);
7253 pw.println();
7254 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7255 pw.print(" last="); mLastFrame.printShortString(pw);
7256 pw.println();
7257 pw.print(prefix); pw.print("mContainingFrame=");
7258 mContainingFrame.printShortString(pw);
7259 pw.print(" mDisplayFrame=");
7260 mDisplayFrame.printShortString(pw);
7261 pw.println();
7262 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7263 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7264 pw.println();
7265 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7266 pw.print(" last="); mLastContentInsets.printShortString(pw);
7267 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7268 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7269 pw.println();
7270 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7271 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7272 pw.print(" mAlpha="); pw.print(mAlpha);
7273 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7274 }
7275 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7276 || mAnimation != null) {
7277 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7278 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7279 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7280 pw.print(" mAnimation="); pw.println(mAnimation);
7281 }
7282 if (mHasTransformation || mHasLocalTransformation) {
7283 pw.print(prefix); pw.print("XForm: has=");
7284 pw.print(mHasTransformation);
7285 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7286 pw.print(" "); mTransformation.printShortString(pw);
7287 pw.println();
7288 }
7289 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7290 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7291 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7292 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7293 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7294 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7295 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7296 pw.print(" mDestroying="); pw.print(mDestroying);
7297 pw.print(" mRemoved="); pw.println(mRemoved);
7298 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007299 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007300 pw.print(prefix); pw.print("mOrientationChanging=");
7301 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007302 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7303 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007304 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007305 if (mHScale != 1 || mVScale != 1) {
7306 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7307 pw.print(" mVScale="); pw.println(mVScale);
7308 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007309 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007310 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7311 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7312 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007313 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7314 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7315 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7316 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007317 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07007318
7319 String makeInputChannelName() {
7320 return Integer.toHexString(System.identityHashCode(this))
7321 + " " + mAttrs.getTitle();
7322 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007323
7324 @Override
7325 public String toString() {
7326 return "Window{"
7327 + Integer.toHexString(System.identityHashCode(this))
7328 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7329 }
7330 }
Romain Guy06882f82009-06-10 13:36:04 -07007331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007332 // -------------------------------------------------------------
7333 // Window Token State
7334 // -------------------------------------------------------------
7335
7336 class WindowToken {
7337 // The actual token.
7338 final IBinder token;
7339
7340 // The type of window this token is for, as per WindowManager.LayoutParams.
7341 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 // Set if this token was explicitly added by a client, so should
7344 // not be removed when all windows are removed.
7345 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007346
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007347 // For printing.
7348 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007350 // If this is an AppWindowToken, this is non-null.
7351 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007353 // All of the windows associated with this token.
7354 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7355
7356 // Is key dispatching paused for this token?
7357 boolean paused = false;
7358
7359 // Should this token's windows be hidden?
7360 boolean hidden;
7361
7362 // Temporary for finding which tokens no longer have visible windows.
7363 boolean hasVisible;
7364
Dianne Hackborna8f60182009-09-01 19:01:50 -07007365 // Set to true when this token is in a pending transaction where it
7366 // will be shown.
7367 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007368
Dianne Hackborna8f60182009-09-01 19:01:50 -07007369 // Set to true when this token is in a pending transaction where it
7370 // will be hidden.
7371 boolean waitingToHide;
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 its
7374 // windows will be put to the bottom of the list.
7375 boolean sendingToBottom;
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 top of the list.
7379 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007381 WindowToken(IBinder _token, int type, boolean _explicit) {
7382 token = _token;
7383 windowType = type;
7384 explicit = _explicit;
7385 }
7386
7387 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007388 pw.print(prefix); pw.print("token="); pw.println(token);
7389 pw.print(prefix); pw.print("windows="); pw.println(windows);
7390 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7391 pw.print(" hidden="); pw.print(hidden);
7392 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007393 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7394 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7395 pw.print(" waitingToHide="); pw.print(waitingToHide);
7396 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7397 pw.print(" sendingToTop="); pw.println(sendingToTop);
7398 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007399 }
7400
7401 @Override
7402 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007403 if (stringName == null) {
7404 StringBuilder sb = new StringBuilder();
7405 sb.append("WindowToken{");
7406 sb.append(Integer.toHexString(System.identityHashCode(this)));
7407 sb.append(" token="); sb.append(token); sb.append('}');
7408 stringName = sb.toString();
7409 }
7410 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007411 }
7412 };
7413
7414 class AppWindowToken extends WindowToken {
7415 // Non-null only for application tokens.
7416 final IApplicationToken appToken;
7417
7418 // All of the windows and child windows that are included in this
7419 // application token. Note this list is NOT sorted!
7420 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7421
7422 int groupId = -1;
7423 boolean appFullscreen;
7424 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007425
7426 // The input dispatching timeout for this application token in nanoseconds.
7427 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007429 // These are used for determining when all windows associated with
7430 // an activity have been drawn, so they can be made visible together
7431 // at the same time.
7432 int lastTransactionSequence = mTransactionSequence-1;
7433 int numInterestingWindows;
7434 int numDrawnWindows;
7435 boolean inPendingTransaction;
7436 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007438 // Is this token going to be hidden in a little while? If so, it
7439 // won't be taken into account for setting the screen orientation.
7440 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 // Is this window's surface needed? This is almost like hidden, except
7443 // it will sometimes be true a little earlier: when the token has
7444 // been shown, but is still waiting for its app transition to execute
7445 // before making its windows shown.
7446 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007448 // Have we told the window clients to hide themselves?
7449 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007451 // Last visibility state we reported to the app token.
7452 boolean reportedVisible;
7453
7454 // Set to true when the token has been removed from the window mgr.
7455 boolean removed;
7456
7457 // Have we been asked to have this token keep the screen frozen?
7458 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007460 boolean animating;
7461 Animation animation;
7462 boolean hasTransformation;
7463 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007465 // Offset to the window of all layers in the token, for use by
7466 // AppWindowToken animations.
7467 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007469 // Information about an application starting window if displayed.
7470 StartingData startingData;
7471 WindowState startingWindow;
7472 View startingView;
7473 boolean startingDisplayed;
7474 boolean startingMoved;
7475 boolean firstWindowDrawn;
7476
7477 AppWindowToken(IApplicationToken _token) {
7478 super(_token.asBinder(),
7479 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7480 appWindowToken = this;
7481 appToken = _token;
7482 }
Romain Guy06882f82009-06-10 13:36:04 -07007483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007484 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007485 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 TAG, "Setting animation in " + this + ": " + anim);
7487 animation = anim;
7488 animating = false;
7489 anim.restrictDuration(MAX_ANIMATION_DURATION);
7490 anim.scaleCurrentDuration(mTransitionAnimationScale);
7491 int zorder = anim.getZAdjustment();
7492 int adj = 0;
7493 if (zorder == Animation.ZORDER_TOP) {
7494 adj = TYPE_LAYER_OFFSET;
7495 } else if (zorder == Animation.ZORDER_BOTTOM) {
7496 adj = -TYPE_LAYER_OFFSET;
7497 }
Romain Guy06882f82009-06-10 13:36:04 -07007498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007499 if (animLayerAdjustment != adj) {
7500 animLayerAdjustment = adj;
7501 updateLayers();
7502 }
7503 }
Romain Guy06882f82009-06-10 13:36:04 -07007504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007505 public void setDummyAnimation() {
7506 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007507 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007508 TAG, "Setting dummy animation in " + this);
7509 animation = sDummyAnimation;
7510 }
7511 }
7512
7513 public void clearAnimation() {
7514 if (animation != null) {
7515 animation = null;
7516 animating = true;
7517 }
7518 }
Romain Guy06882f82009-06-10 13:36:04 -07007519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 void updateLayers() {
7521 final int N = allAppWindows.size();
7522 final int adj = animLayerAdjustment;
7523 for (int i=0; i<N; i++) {
7524 WindowState w = allAppWindows.get(i);
7525 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007526 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007527 + w.mAnimLayer);
7528 if (w == mInputMethodTarget) {
7529 setInputMethodAnimLayerAdjustment(adj);
7530 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007531 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007532 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007533 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007534 }
7535 }
Romain Guy06882f82009-06-10 13:36:04 -07007536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007537 void sendAppVisibilityToClients() {
7538 final int N = allAppWindows.size();
7539 for (int i=0; i<N; i++) {
7540 WindowState win = allAppWindows.get(i);
7541 if (win == startingWindow && clientHidden) {
7542 // Don't hide the starting window.
7543 continue;
7544 }
7545 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007546 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007547 "Setting visibility of " + win + ": " + (!clientHidden));
7548 win.mClient.dispatchAppVisibility(!clientHidden);
7549 } catch (RemoteException e) {
7550 }
7551 }
7552 }
Romain Guy06882f82009-06-10 13:36:04 -07007553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007554 void showAllWindowsLocked() {
7555 final int NW = allAppWindows.size();
7556 for (int i=0; i<NW; i++) {
7557 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007558 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007559 "performing show on: " + w);
7560 w.performShowLocked();
7561 }
7562 }
Romain Guy06882f82009-06-10 13:36:04 -07007563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007564 // This must be called while inside a transaction.
7565 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007566 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007567 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007569 if (animation == sDummyAnimation) {
7570 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007571 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007572 // when it is really time to animate, this will be set to
7573 // a real animation and the next call will execute normally.
7574 return false;
7575 }
Romain Guy06882f82009-06-10 13:36:04 -07007576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007577 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7578 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007579 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 TAG, "Starting animation in " + this +
7581 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7582 + " scale=" + mTransitionAnimationScale
7583 + " allDrawn=" + allDrawn + " animating=" + animating);
7584 animation.initialize(dw, dh, dw, dh);
7585 animation.setStartTime(currentTime);
7586 animating = true;
7587 }
7588 transformation.clear();
7589 final boolean more = animation.getTransformation(
7590 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007591 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007592 TAG, "Stepped animation in " + this +
7593 ": more=" + more + ", xform=" + transformation);
7594 if (more) {
7595 // we're done!
7596 hasTransformation = true;
7597 return true;
7598 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007599 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007600 TAG, "Finished animation in " + this +
7601 " @ " + currentTime);
7602 animation = null;
7603 }
7604 } else if (animation != null) {
7605 // If the display is frozen, and there is a pending animation,
7606 // clear it and make sure we run the cleanup code.
7607 animating = true;
7608 animation = null;
7609 }
7610
7611 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007613 if (!animating) {
7614 return false;
7615 }
7616
7617 clearAnimation();
7618 animating = false;
7619 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7620 moveInputMethodWindowsIfNeededLocked(true);
7621 }
Romain Guy06882f82009-06-10 13:36:04 -07007622
Joe Onorato8a9b2202010-02-26 18:56:32 -08007623 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007624 TAG, "Animation done in " + this
7625 + ": reportedVisible=" + reportedVisible);
7626
7627 transformation.clear();
7628 if (animLayerAdjustment != 0) {
7629 animLayerAdjustment = 0;
7630 updateLayers();
7631 }
Romain Guy06882f82009-06-10 13:36:04 -07007632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007633 final int N = windows.size();
7634 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007635 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007636 }
7637 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 return false;
7640 }
7641
7642 void updateReportedVisibilityLocked() {
7643 if (appToken == null) {
7644 return;
7645 }
Romain Guy06882f82009-06-10 13:36:04 -07007646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007647 int numInteresting = 0;
7648 int numVisible = 0;
7649 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007650
Joe Onorato8a9b2202010-02-26 18:56:32 -08007651 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007652 final int N = allAppWindows.size();
7653 for (int i=0; i<N; i++) {
7654 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007655 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007656 || win.mViewVisibility != View.VISIBLE
7657 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007658 continue;
7659 }
7660 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007661 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007662 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007663 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007664 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007665 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007666 + " pv=" + win.mPolicyVisibility
7667 + " dp=" + win.mDrawPending
7668 + " cdp=" + win.mCommitDrawPending
7669 + " ah=" + win.mAttachedHidden
7670 + " th="
7671 + (win.mAppToken != null
7672 ? win.mAppToken.hiddenRequested : false)
7673 + " a=" + win.mAnimating);
7674 }
7675 }
7676 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007677 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 if (!win.isAnimating()) {
7679 numVisible++;
7680 }
7681 nowGone = false;
7682 } else if (win.isAnimating()) {
7683 nowGone = false;
7684 }
7685 }
Romain Guy06882f82009-06-10 13:36:04 -07007686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007687 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007688 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 + numInteresting + " visible=" + numVisible);
7690 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007691 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 TAG, "Visibility changed in " + this
7693 + ": vis=" + nowVisible);
7694 reportedVisible = nowVisible;
7695 Message m = mH.obtainMessage(
7696 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7697 nowVisible ? 1 : 0,
7698 nowGone ? 1 : 0,
7699 this);
7700 mH.sendMessage(m);
7701 }
7702 }
Romain Guy06882f82009-06-10 13:36:04 -07007703
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007704 WindowState findMainWindow() {
7705 int j = windows.size();
7706 while (j > 0) {
7707 j--;
7708 WindowState win = windows.get(j);
7709 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7710 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7711 return win;
7712 }
7713 }
7714 return null;
7715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007717 void dump(PrintWriter pw, String prefix) {
7718 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007719 if (appToken != null) {
7720 pw.print(prefix); pw.println("app=true");
7721 }
7722 if (allAppWindows.size() > 0) {
7723 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7724 }
7725 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007726 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007727 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7728 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7729 pw.print(" clientHidden="); pw.print(clientHidden);
7730 pw.print(" willBeHidden="); pw.print(willBeHidden);
7731 pw.print(" reportedVisible="); pw.println(reportedVisible);
7732 if (paused || freezingScreen) {
7733 pw.print(prefix); pw.print("paused="); pw.print(paused);
7734 pw.print(" freezingScreen="); pw.println(freezingScreen);
7735 }
7736 if (numInterestingWindows != 0 || numDrawnWindows != 0
7737 || inPendingTransaction || allDrawn) {
7738 pw.print(prefix); pw.print("numInterestingWindows=");
7739 pw.print(numInterestingWindows);
7740 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7741 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7742 pw.print(" allDrawn="); pw.println(allDrawn);
7743 }
7744 if (animating || animation != null) {
7745 pw.print(prefix); pw.print("animating="); pw.print(animating);
7746 pw.print(" animation="); pw.println(animation);
7747 }
7748 if (animLayerAdjustment != 0) {
7749 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7750 }
7751 if (hasTransformation) {
7752 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7753 pw.print(" transformation="); transformation.printShortString(pw);
7754 pw.println();
7755 }
7756 if (startingData != null || removed || firstWindowDrawn) {
7757 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7758 pw.print(" removed="); pw.print(removed);
7759 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7760 }
7761 if (startingWindow != null || startingView != null
7762 || startingDisplayed || startingMoved) {
7763 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7764 pw.print(" startingView="); pw.print(startingView);
7765 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7766 pw.print(" startingMoved"); pw.println(startingMoved);
7767 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007768 }
7769
7770 @Override
7771 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007772 if (stringName == null) {
7773 StringBuilder sb = new StringBuilder();
7774 sb.append("AppWindowToken{");
7775 sb.append(Integer.toHexString(System.identityHashCode(this)));
7776 sb.append(" token="); sb.append(token); sb.append('}');
7777 stringName = sb.toString();
7778 }
7779 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007780 }
7781 }
Romain Guy06882f82009-06-10 13:36:04 -07007782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007783 // -------------------------------------------------------------
7784 // DummyAnimation
7785 // -------------------------------------------------------------
7786
7787 // This is an animation that does nothing: it just immediately finishes
7788 // itself every time it is called. It is used as a stub animation in cases
7789 // where we want to synchronize multiple things that may be animating.
7790 static final class DummyAnimation extends Animation {
7791 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7792 return false;
7793 }
7794 }
7795 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007797 // -------------------------------------------------------------
7798 // Async Handler
7799 // -------------------------------------------------------------
7800
7801 static final class StartingData {
7802 final String pkg;
7803 final int theme;
7804 final CharSequence nonLocalizedLabel;
7805 final int labelRes;
7806 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007808 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7809 int _labelRes, int _icon) {
7810 pkg = _pkg;
7811 theme = _theme;
7812 nonLocalizedLabel = _nonLocalizedLabel;
7813 labelRes = _labelRes;
7814 icon = _icon;
7815 }
7816 }
7817
7818 private final class H extends Handler {
7819 public static final int REPORT_FOCUS_CHANGE = 2;
7820 public static final int REPORT_LOSING_FOCUS = 3;
7821 public static final int ANIMATE = 4;
7822 public static final int ADD_STARTING = 5;
7823 public static final int REMOVE_STARTING = 6;
7824 public static final int FINISHED_STARTING = 7;
7825 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007826 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7827 public static final int HOLD_SCREEN_CHANGED = 12;
7828 public static final int APP_TRANSITION_TIMEOUT = 13;
7829 public static final int PERSIST_ANIMATION_SCALE = 14;
7830 public static final int FORCE_GC = 15;
7831 public static final int ENABLE_SCREEN = 16;
7832 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007833 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007834 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007836 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007838 public H() {
7839 }
Romain Guy06882f82009-06-10 13:36:04 -07007840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007841 @Override
7842 public void handleMessage(Message msg) {
7843 switch (msg.what) {
7844 case REPORT_FOCUS_CHANGE: {
7845 WindowState lastFocus;
7846 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007848 synchronized(mWindowMap) {
7849 lastFocus = mLastFocus;
7850 newFocus = mCurrentFocus;
7851 if (lastFocus == newFocus) {
7852 // Focus is not changing, so nothing to do.
7853 return;
7854 }
7855 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007856 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007857 // + " to " + newFocus);
7858 if (newFocus != null && lastFocus != null
7859 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007860 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007861 mLosingFocus.add(lastFocus);
7862 lastFocus = null;
7863 }
7864 }
7865
7866 if (lastFocus != newFocus) {
7867 //System.out.println("Changing focus from " + lastFocus
7868 // + " to " + newFocus);
7869 if (newFocus != null) {
7870 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007871 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007872 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7873 } catch (RemoteException e) {
7874 // Ignore if process has died.
7875 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007876 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007877 }
7878
7879 if (lastFocus != null) {
7880 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007881 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007882 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7883 } catch (RemoteException e) {
7884 // Ignore if process has died.
7885 }
7886 }
7887 }
7888 } break;
7889
7890 case REPORT_LOSING_FOCUS: {
7891 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007893 synchronized(mWindowMap) {
7894 losers = mLosingFocus;
7895 mLosingFocus = new ArrayList<WindowState>();
7896 }
7897
7898 final int N = losers.size();
7899 for (int i=0; i<N; i++) {
7900 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007901 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007902 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7903 } catch (RemoteException e) {
7904 // Ignore if process has died.
7905 }
7906 }
7907 } break;
7908
7909 case ANIMATE: {
7910 synchronized(mWindowMap) {
7911 mAnimationPending = false;
7912 performLayoutAndPlaceSurfacesLocked();
7913 }
7914 } break;
7915
7916 case ADD_STARTING: {
7917 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7918 final StartingData sd = wtoken.startingData;
7919
7920 if (sd == null) {
7921 // Animation has been canceled... do nothing.
7922 return;
7923 }
Romain Guy06882f82009-06-10 13:36:04 -07007924
Joe Onorato8a9b2202010-02-26 18:56:32 -08007925 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007926 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007928 View view = null;
7929 try {
7930 view = mPolicy.addStartingWindow(
7931 wtoken.token, sd.pkg,
7932 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7933 sd.icon);
7934 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007935 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007936 }
7937
7938 if (view != null) {
7939 boolean abort = false;
7940
7941 synchronized(mWindowMap) {
7942 if (wtoken.removed || wtoken.startingData == null) {
7943 // If the window was successfully added, then
7944 // we need to remove it.
7945 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007946 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007947 "Aborted starting " + wtoken
7948 + ": removed=" + wtoken.removed
7949 + " startingData=" + wtoken.startingData);
7950 wtoken.startingWindow = null;
7951 wtoken.startingData = null;
7952 abort = true;
7953 }
7954 } else {
7955 wtoken.startingView = view;
7956 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007957 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007958 "Added starting " + wtoken
7959 + ": startingWindow="
7960 + wtoken.startingWindow + " startingView="
7961 + wtoken.startingView);
7962 }
7963
7964 if (abort) {
7965 try {
7966 mPolicy.removeStartingWindow(wtoken.token, view);
7967 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007968 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007969 }
7970 }
7971 }
7972 } break;
7973
7974 case REMOVE_STARTING: {
7975 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7976 IBinder token = null;
7977 View view = null;
7978 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007979 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007980 + wtoken + ": startingWindow="
7981 + wtoken.startingWindow + " startingView="
7982 + wtoken.startingView);
7983 if (wtoken.startingWindow != null) {
7984 view = wtoken.startingView;
7985 token = wtoken.token;
7986 wtoken.startingData = null;
7987 wtoken.startingView = null;
7988 wtoken.startingWindow = null;
7989 }
7990 }
7991 if (view != null) {
7992 try {
7993 mPolicy.removeStartingWindow(token, view);
7994 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007995 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007996 }
7997 }
7998 } break;
7999
8000 case FINISHED_STARTING: {
8001 IBinder token = null;
8002 View view = null;
8003 while (true) {
8004 synchronized (mWindowMap) {
8005 final int N = mFinishedStarting.size();
8006 if (N <= 0) {
8007 break;
8008 }
8009 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8010
Joe Onorato8a9b2202010-02-26 18:56:32 -08008011 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008012 "Finished starting " + wtoken
8013 + ": startingWindow=" + wtoken.startingWindow
8014 + " startingView=" + wtoken.startingView);
8015
8016 if (wtoken.startingWindow == null) {
8017 continue;
8018 }
8019
8020 view = wtoken.startingView;
8021 token = wtoken.token;
8022 wtoken.startingData = null;
8023 wtoken.startingView = null;
8024 wtoken.startingWindow = null;
8025 }
8026
8027 try {
8028 mPolicy.removeStartingWindow(token, view);
8029 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008030 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008031 }
8032 }
8033 } break;
8034
8035 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8036 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8037
8038 boolean nowVisible = msg.arg1 != 0;
8039 boolean nowGone = msg.arg2 != 0;
8040
8041 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008042 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008043 TAG, "Reporting visible in " + wtoken
8044 + " visible=" + nowVisible
8045 + " gone=" + nowGone);
8046 if (nowVisible) {
8047 wtoken.appToken.windowsVisible();
8048 } else {
8049 wtoken.appToken.windowsGone();
8050 }
8051 } catch (RemoteException ex) {
8052 }
8053 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008055 case WINDOW_FREEZE_TIMEOUT: {
8056 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008057 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008058 int i = mWindows.size();
8059 while (i > 0) {
8060 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008061 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008062 if (w.mOrientationChanging) {
8063 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008064 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008065 }
8066 }
8067 performLayoutAndPlaceSurfacesLocked();
8068 }
8069 break;
8070 }
Romain Guy06882f82009-06-10 13:36:04 -07008071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008072 case HOLD_SCREEN_CHANGED: {
8073 Session oldHold;
8074 Session newHold;
8075 synchronized (mWindowMap) {
8076 oldHold = mLastReportedHold;
8077 newHold = (Session)msg.obj;
8078 mLastReportedHold = newHold;
8079 }
Romain Guy06882f82009-06-10 13:36:04 -07008080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008081 if (oldHold != newHold) {
8082 try {
8083 if (oldHold != null) {
8084 mBatteryStats.noteStopWakelock(oldHold.mUid,
8085 "window",
8086 BatteryStats.WAKE_TYPE_WINDOW);
8087 }
8088 if (newHold != null) {
8089 mBatteryStats.noteStartWakelock(newHold.mUid,
8090 "window",
8091 BatteryStats.WAKE_TYPE_WINDOW);
8092 }
8093 } catch (RemoteException e) {
8094 }
8095 }
8096 break;
8097 }
Romain Guy06882f82009-06-10 13:36:04 -07008098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008099 case APP_TRANSITION_TIMEOUT: {
8100 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008101 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008102 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008103 "*** APP TRANSITION TIMEOUT");
8104 mAppTransitionReady = true;
8105 mAppTransitionTimeout = true;
8106 performLayoutAndPlaceSurfacesLocked();
8107 }
8108 }
8109 break;
8110 }
Romain Guy06882f82009-06-10 13:36:04 -07008111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008112 case PERSIST_ANIMATION_SCALE: {
8113 Settings.System.putFloat(mContext.getContentResolver(),
8114 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8115 Settings.System.putFloat(mContext.getContentResolver(),
8116 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8117 break;
8118 }
Romain Guy06882f82009-06-10 13:36:04 -07008119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008120 case FORCE_GC: {
8121 synchronized(mWindowMap) {
8122 if (mAnimationPending) {
8123 // If we are animating, don't do the gc now but
8124 // delay a bit so we don't interrupt the animation.
8125 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8126 2000);
8127 return;
8128 }
8129 // If we are currently rotating the display, it will
8130 // schedule a new message when done.
8131 if (mDisplayFrozen) {
8132 return;
8133 }
8134 mFreezeGcPending = 0;
8135 }
8136 Runtime.getRuntime().gc();
8137 break;
8138 }
Romain Guy06882f82009-06-10 13:36:04 -07008139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008140 case ENABLE_SCREEN: {
8141 performEnableScreen();
8142 break;
8143 }
Romain Guy06882f82009-06-10 13:36:04 -07008144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008145 case APP_FREEZE_TIMEOUT: {
8146 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008147 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 int i = mAppTokens.size();
8149 while (i > 0) {
8150 i--;
8151 AppWindowToken tok = mAppTokens.get(i);
8152 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008153 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008154 unsetAppFreezingScreenLocked(tok, true, true);
8155 }
8156 }
8157 }
8158 break;
8159 }
Romain Guy06882f82009-06-10 13:36:04 -07008160
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008161 case SEND_NEW_CONFIGURATION: {
8162 removeMessages(SEND_NEW_CONFIGURATION);
8163 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008164 break;
8165 }
Romain Guy06882f82009-06-10 13:36:04 -07008166
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008167 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008168 if (mWindowsChanged) {
8169 synchronized (mWindowMap) {
8170 mWindowsChanged = false;
8171 }
8172 notifyWindowsChanged();
8173 }
8174 break;
8175 }
8176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008177 }
8178 }
8179 }
8180
8181 // -------------------------------------------------------------
8182 // IWindowManager API
8183 // -------------------------------------------------------------
8184
8185 public IWindowSession openSession(IInputMethodClient client,
8186 IInputContext inputContext) {
8187 if (client == null) throw new IllegalArgumentException("null client");
8188 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac02010-04-22 18:58:52 -07008189 Session session = new Session(client, inputContext);
8190 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008191 }
8192
8193 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8194 synchronized (mWindowMap) {
8195 // The focus for the client is the window immediately below
8196 // where we would place the input method window.
8197 int idx = findDesiredInputMethodWindowIndexLocked(false);
8198 WindowState imFocus;
8199 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008200 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008201 if (imFocus != null) {
8202 if (imFocus.mSession.mClient != null &&
8203 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8204 return true;
8205 }
8206 }
8207 }
8208 }
8209 return false;
8210 }
Romain Guy06882f82009-06-10 13:36:04 -07008211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008212 // -------------------------------------------------------------
8213 // Internals
8214 // -------------------------------------------------------------
8215
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008216 final WindowState windowForClientLocked(Session session, IWindow client,
8217 boolean throwOnError) {
8218 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008219 }
Romain Guy06882f82009-06-10 13:36:04 -07008220
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008221 final WindowState windowForClientLocked(Session session, IBinder client,
8222 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008223 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008224 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008225 TAG, "Looking up client " + client + ": " + win);
8226 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008227 RuntimeException ex = new IllegalArgumentException(
8228 "Requested window " + client + " does not exist");
8229 if (throwOnError) {
8230 throw ex;
8231 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008232 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008233 return null;
8234 }
8235 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008236 RuntimeException ex = new IllegalArgumentException(
8237 "Requested window " + client + " is in session " +
8238 win.mSession + ", not " + session);
8239 if (throwOnError) {
8240 throw ex;
8241 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008242 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008243 return null;
8244 }
8245
8246 return win;
8247 }
8248
Dianne Hackborna8f60182009-09-01 19:01:50 -07008249 final void rebuildAppWindowListLocked() {
8250 int NW = mWindows.size();
8251 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008252 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008253 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008254
Dianne Hackborna8f60182009-09-01 19:01:50 -07008255 // First remove all existing app windows.
8256 i=0;
8257 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008258 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008259 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008260 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008261 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008262 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008263 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008264 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008265 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008266 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008267 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8268 && lastWallpaper == i-1) {
8269 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008270 }
8271 i++;
8272 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008273
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008274 // The wallpaper window(s) typically live at the bottom of the stack,
8275 // so skip them before adding app tokens.
8276 lastWallpaper++;
8277 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008278
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008279 // First add all of the exiting app tokens... these are no longer
8280 // in the main app list, but still have windows shown. We put them
8281 // in the back because now that the animation is over we no longer
8282 // will care about them.
8283 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008284 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008285 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8286 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008287
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008288 // And add in the still active app tokens in Z order.
8289 NT = mAppTokens.size();
8290 for (int j=0; j<NT; j++) {
8291 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008292 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008293
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008294 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008295 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008296 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008297 + " windows but added " + i);
8298 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008301 private final void assignLayersLocked() {
8302 int N = mWindows.size();
8303 int curBaseLayer = 0;
8304 int curLayer = 0;
8305 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008308 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008309 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8310 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008311 curLayer += WINDOW_LAYER_MULTIPLIER;
8312 w.mLayer = curLayer;
8313 } else {
8314 curBaseLayer = curLayer = w.mBaseLayer;
8315 w.mLayer = curLayer;
8316 }
8317 if (w.mTargetAppToken != null) {
8318 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8319 } else if (w.mAppToken != null) {
8320 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8321 } else {
8322 w.mAnimLayer = w.mLayer;
8323 }
8324 if (w.mIsImWindow) {
8325 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008326 } else if (w.mIsWallpaper) {
8327 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008329 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008330 + w.mAnimLayer);
8331 //System.out.println(
8332 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8333 }
8334 }
8335
8336 private boolean mInLayout = false;
8337 private final void performLayoutAndPlaceSurfacesLocked() {
8338 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008339 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008340 throw new RuntimeException("Recursive call!");
8341 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008342 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008343 return;
8344 }
8345
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008346 if (mWaitingForConfig) {
8347 // Our configuration has changed (most likely rotation), but we
8348 // don't yet have the complete configuration to report to
8349 // applications. Don't do any window layout until we have it.
8350 return;
8351 }
8352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 boolean recoveringMemory = false;
8354 if (mForceRemoves != null) {
8355 recoveringMemory = true;
8356 // Wait a little it for things to settle down, and off we go.
8357 for (int i=0; i<mForceRemoves.size(); i++) {
8358 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008359 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008360 removeWindowInnerLocked(ws.mSession, ws);
8361 }
8362 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008363 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 Object tmp = new Object();
8365 synchronized (tmp) {
8366 try {
8367 tmp.wait(250);
8368 } catch (InterruptedException e) {
8369 }
8370 }
8371 }
Romain Guy06882f82009-06-10 13:36:04 -07008372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008373 mInLayout = true;
8374 try {
8375 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008377 int i = mPendingRemove.size()-1;
8378 if (i >= 0) {
8379 while (i >= 0) {
8380 WindowState w = mPendingRemove.get(i);
8381 removeWindowInnerLocked(w.mSession, w);
8382 i--;
8383 }
8384 mPendingRemove.clear();
8385
8386 mInLayout = false;
8387 assignLayersLocked();
8388 mLayoutNeeded = true;
8389 performLayoutAndPlaceSurfacesLocked();
8390
8391 } else {
8392 mInLayout = false;
8393 if (mLayoutNeeded) {
8394 requestAnimationLocked(0);
8395 }
8396 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008397 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008398 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8399 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008401 } catch (RuntimeException e) {
8402 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008403 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008404 }
8405 }
8406
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008407 private final int performLayoutLockedInner() {
8408 if (!mLayoutNeeded) {
8409 return 0;
8410 }
8411
8412 mLayoutNeeded = false;
8413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008414 final int dw = mDisplay.getWidth();
8415 final int dh = mDisplay.getHeight();
8416
8417 final int N = mWindows.size();
8418 int i;
8419
Joe Onorato8a9b2202010-02-26 18:56:32 -08008420 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008421 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8422
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008423 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008424
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008425 int seq = mLayoutSeq+1;
8426 if (seq < 0) seq = 0;
8427 mLayoutSeq = seq;
8428
8429 // First perform layout of any root windows (not attached
8430 // to another window).
8431 int topAttached = -1;
8432 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008433 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008434
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008435 // Don't do layout of a window if it is not visible, or
8436 // soon won't be visible, to avoid wasting time and funky
8437 // changes while a window is animating away.
8438 final AppWindowToken atoken = win.mAppToken;
8439 final boolean gone = win.mViewVisibility == View.GONE
8440 || !win.mRelayoutCalled
8441 || win.mRootToken.hidden
8442 || (atoken != null && atoken.hiddenRequested)
8443 || win.mAttachedHidden
8444 || win.mExiting || win.mDestroying;
8445
8446 if (!win.mLayoutAttached) {
8447 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8448 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8449 + " mLayoutAttached=" + win.mLayoutAttached);
8450 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8451 + win.mViewVisibility + " mRelayoutCalled="
8452 + win.mRelayoutCalled + " hidden="
8453 + win.mRootToken.hidden + " hiddenRequested="
8454 + (atoken != null && atoken.hiddenRequested)
8455 + " mAttachedHidden=" + win.mAttachedHidden);
8456 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008457
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008458 // If this view is GONE, then skip it -- keep the current
8459 // frame, and let the caller know so they can ignore it
8460 // if they want. (We do the normal layout for INVISIBLE
8461 // windows, since that means "perform layout as normal,
8462 // just don't display").
8463 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008464 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008465 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8466 win.mLayoutSeq = seq;
8467 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8468 + win.mFrame + " mContainingFrame="
8469 + win.mContainingFrame + " mDisplayFrame="
8470 + win.mDisplayFrame);
8471 } else {
8472 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008473 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008475 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008476
8477 // Now perform layout of attached windows, which usually
8478 // depend on the position of the window they are attached to.
8479 // XXX does not deal with windows that are attached to windows
8480 // that are themselves attached.
8481 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008482 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008483
8484 // If this view is GONE, then skip it -- keep the current
8485 // frame, and let the caller know so they can ignore it
8486 // if they want. (We do the normal layout for INVISIBLE
8487 // windows, since that means "perform layout as normal,
8488 // just don't display").
8489 if (win.mLayoutAttached) {
8490 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8491 + " mHaveFrame=" + win.mHaveFrame
8492 + " mViewVisibility=" + win.mViewVisibility
8493 + " mRelayoutCalled=" + win.mRelayoutCalled);
8494 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8495 || !win.mHaveFrame) {
8496 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8497 win.mLayoutSeq = seq;
8498 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8499 + win.mFrame + " mContainingFrame="
8500 + win.mContainingFrame + " mDisplayFrame="
8501 + win.mDisplayFrame);
8502 }
8503 }
8504 }
Jeff Brown349703e2010-06-22 01:27:15 -07008505
8506 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008507 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008508
8509 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008510 }
Romain Guy06882f82009-06-10 13:36:04 -07008511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008512 private final void performLayoutAndPlaceSurfacesLockedInner(
8513 boolean recoveringMemory) {
8514 final long currentTime = SystemClock.uptimeMillis();
8515 final int dw = mDisplay.getWidth();
8516 final int dh = mDisplay.getHeight();
8517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008518 int i;
8519
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008520 if (mFocusMayChange) {
8521 mFocusMayChange = false;
8522 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8523 }
8524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008525 // Initialize state of exiting tokens.
8526 for (i=mExitingTokens.size()-1; i>=0; i--) {
8527 mExitingTokens.get(i).hasVisible = false;
8528 }
8529
8530 // Initialize state of exiting applications.
8531 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8532 mExitingAppTokens.get(i).hasVisible = false;
8533 }
8534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008535 boolean orientationChangeComplete = true;
8536 Session holdScreen = null;
8537 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008538 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008539 boolean focusDisplayed = false;
8540 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008541 boolean createWatermark = false;
8542
8543 if (mFxSession == null) {
8544 mFxSession = new SurfaceSession();
8545 createWatermark = true;
8546 }
8547
8548 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549
8550 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008551
8552 if (createWatermark) {
8553 createWatermark();
8554 }
8555 if (mWatermark != null) {
8556 mWatermark.positionSurface(dw, dh);
8557 }
8558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008559 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008560 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008561 int repeats = 0;
8562 int changes = 0;
8563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008564 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008565 repeats++;
8566 if (repeats > 6) {
8567 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8568 mLayoutNeeded = false;
8569 break;
8570 }
8571
8572 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8573 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8574 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8575 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8576 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8577 assignLayersLocked();
8578 mLayoutNeeded = true;
8579 }
8580 }
8581 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8582 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8583 if (updateOrientationFromAppTokensLocked()) {
8584 mLayoutNeeded = true;
8585 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8586 }
8587 }
8588 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8589 mLayoutNeeded = true;
8590 }
8591 }
8592
8593 // FIRST LOOP: Perform a layout, if needed.
8594 if (repeats < 4) {
8595 changes = performLayoutLockedInner();
8596 if (changes != 0) {
8597 continue;
8598 }
8599 } else {
8600 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8601 changes = 0;
8602 }
8603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008604 final int transactionSequence = ++mTransactionSequence;
8605
8606 // Update animations of all applications, including those
8607 // associated with exiting/removed apps
8608 boolean tokensAnimating = false;
8609 final int NAT = mAppTokens.size();
8610 for (i=0; i<NAT; i++) {
8611 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8612 tokensAnimating = true;
8613 }
8614 }
8615 final int NEAT = mExitingAppTokens.size();
8616 for (i=0; i<NEAT; i++) {
8617 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8618 tokensAnimating = true;
8619 }
8620 }
8621
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008622 // SECOND LOOP: Execute animations and update visibility of windows.
8623
Joe Onorato8a9b2202010-02-26 18:56:32 -08008624 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008625 + transactionSequence + " tokensAnimating="
8626 + tokensAnimating);
8627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008628 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008629
8630 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008631 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008632 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008633
8634 mPolicy.beginAnimationLw(dw, dh);
8635
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008636 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008638 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008639 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008640
8641 final WindowManager.LayoutParams attrs = w.mAttrs;
8642
8643 if (w.mSurface != null) {
8644 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008645 if (w.commitFinishDrawingLocked(currentTime)) {
8646 if ((w.mAttrs.flags
8647 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008648 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008649 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008650 wallpaperMayChange = true;
8651 }
8652 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008653
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008654 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008655 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8656 animating = true;
8657 //w.dump(" ");
8658 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008659 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8660 wallpaperMayChange = true;
8661 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008662
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008663 if (mPolicy.doesForceHide(w, attrs)) {
8664 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008665 if (DEBUG_VISIBILITY) Slog.v(TAG,
8666 "Animation done that could impact force hide: "
8667 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008668 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008669 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008670 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8671 forceHiding = true;
8672 }
8673 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8674 boolean changed;
8675 if (forceHiding) {
8676 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008677 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8678 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008679 } else {
8680 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008681 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8682 "Now policy shown: " + w);
8683 if (changed) {
8684 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008685 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008686 // Assume we will need to animate. If
8687 // we don't (because the wallpaper will
8688 // stay with the lock screen), then we will
8689 // clean up later.
8690 Animation a = mPolicy.createForceHideEnterAnimation();
8691 if (a != null) {
8692 w.setAnimation(a);
8693 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008694 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008695 if (mCurrentFocus == null ||
8696 mCurrentFocus.mLayer < w.mLayer) {
8697 // We are showing on to of the current
8698 // focus, so re-evaluate focus to make
8699 // sure it is correct.
8700 mFocusMayChange = true;
8701 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008702 }
8703 }
8704 if (changed && (attrs.flags
8705 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8706 wallpaperMayChange = true;
8707 }
8708 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 mPolicy.animatingWindowLw(w, attrs);
8711 }
8712
8713 final AppWindowToken atoken = w.mAppToken;
8714 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8715 if (atoken.lastTransactionSequence != transactionSequence) {
8716 atoken.lastTransactionSequence = transactionSequence;
8717 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8718 atoken.startingDisplayed = false;
8719 }
8720 if ((w.isOnScreen() || w.mAttrs.type
8721 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8722 && !w.mExiting && !w.mDestroying) {
8723 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008724 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008725 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008726 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008727 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008728 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008729 + " pv=" + w.mPolicyVisibility
8730 + " dp=" + w.mDrawPending
8731 + " cdp=" + w.mCommitDrawPending
8732 + " ah=" + w.mAttachedHidden
8733 + " th=" + atoken.hiddenRequested
8734 + " a=" + w.mAnimating);
8735 }
8736 }
8737 if (w != atoken.startingWindow) {
8738 if (!atoken.freezingScreen || !w.mAppFreezing) {
8739 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008740 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008741 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008742 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008743 "tokenMayBeDrawn: " + atoken
8744 + " freezingScreen=" + atoken.freezingScreen
8745 + " mAppFreezing=" + w.mAppFreezing);
8746 tokenMayBeDrawn = true;
8747 }
8748 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008749 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008750 atoken.startingDisplayed = true;
8751 }
8752 }
8753 } else if (w.mReadyToShow) {
8754 w.performShowLocked();
8755 }
8756 }
8757
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008758 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008759
8760 if (tokenMayBeDrawn) {
8761 // See if any windows have been drawn, so they (and others
8762 // associated with them) can now be shown.
8763 final int NT = mTokenList.size();
8764 for (i=0; i<NT; i++) {
8765 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8766 if (wtoken == null) {
8767 continue;
8768 }
8769 if (wtoken.freezingScreen) {
8770 int numInteresting = wtoken.numInterestingWindows;
8771 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008772 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008773 "allDrawn: " + wtoken
8774 + " interesting=" + numInteresting
8775 + " drawn=" + wtoken.numDrawnWindows);
8776 wtoken.showAllWindowsLocked();
8777 unsetAppFreezingScreenLocked(wtoken, false, true);
8778 orientationChangeComplete = true;
8779 }
8780 } else if (!wtoken.allDrawn) {
8781 int numInteresting = wtoken.numInterestingWindows;
8782 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008783 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008784 "allDrawn: " + wtoken
8785 + " interesting=" + numInteresting
8786 + " drawn=" + wtoken.numDrawnWindows);
8787 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008788 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008789
8790 // We can now show all of the drawn windows!
8791 if (!mOpeningApps.contains(wtoken)) {
8792 wtoken.showAllWindowsLocked();
8793 }
8794 }
8795 }
8796 }
8797 }
8798
8799 // If we are ready to perform an app transition, check through
8800 // all of the app tokens to be shown and see if they are ready
8801 // to go.
8802 if (mAppTransitionReady) {
8803 int NN = mOpeningApps.size();
8804 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008805 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008806 "Checking " + NN + " opening apps (frozen="
8807 + mDisplayFrozen + " timeout="
8808 + mAppTransitionTimeout + ")...");
8809 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8810 // If the display isn't frozen, wait to do anything until
8811 // all of the apps are ready. Otherwise just go because
8812 // we'll unfreeze the display when everyone is ready.
8813 for (i=0; i<NN && goodToGo; i++) {
8814 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008815 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008816 "Check opening app" + wtoken + ": allDrawn="
8817 + wtoken.allDrawn + " startingDisplayed="
8818 + wtoken.startingDisplayed);
8819 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8820 && !wtoken.startingMoved) {
8821 goodToGo = false;
8822 }
8823 }
8824 }
8825 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008826 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008827 int transit = mNextAppTransition;
8828 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008829 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008830 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008831 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008832 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008833 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008834 mAppTransitionTimeout = false;
8835 mStartingIconInTransition = false;
8836 mSkipAppTransitionAnimation = false;
8837
8838 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8839
Dianne Hackborna8f60182009-09-01 19:01:50 -07008840 // If there are applications waiting to come to the
8841 // top of the stack, now is the time to move their windows.
8842 // (Note that we don't do apps going to the bottom
8843 // here -- we want to keep their windows in the old
8844 // Z-order until the animation completes.)
8845 if (mToTopApps.size() > 0) {
8846 NN = mAppTokens.size();
8847 for (i=0; i<NN; i++) {
8848 AppWindowToken wtoken = mAppTokens.get(i);
8849 if (wtoken.sendingToTop) {
8850 wtoken.sendingToTop = false;
8851 moveAppWindowsLocked(wtoken, NN, false);
8852 }
8853 }
8854 mToTopApps.clear();
8855 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008856
Dianne Hackborn25994b42009-09-04 14:21:19 -07008857 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008858
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008859 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008860 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008861
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008862 // The top-most window will supply the layout params,
8863 // and we will determine it below.
8864 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008865 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008866 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008867
Joe Onorato8a9b2202010-02-26 18:56:32 -08008868 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008869 "New wallpaper target=" + mWallpaperTarget
8870 + ", lower target=" + mLowerWallpaperTarget
8871 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008872 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008873 // Do a first pass through the tokens for two
8874 // things:
8875 // (1) Determine if both the closing and opening
8876 // app token sets are wallpaper targets, in which
8877 // case special animations are needed
8878 // (since the wallpaper needs to stay static
8879 // behind them).
8880 // (2) Find the layout params of the top-most
8881 // application window in the tokens, which is
8882 // what will control the animation theme.
8883 final int NC = mClosingApps.size();
8884 NN = NC + mOpeningApps.size();
8885 for (i=0; i<NN; i++) {
8886 AppWindowToken wtoken;
8887 int mode;
8888 if (i < NC) {
8889 wtoken = mClosingApps.get(i);
8890 mode = 1;
8891 } else {
8892 wtoken = mOpeningApps.get(i-NC);
8893 mode = 2;
8894 }
8895 if (mLowerWallpaperTarget != null) {
8896 if (mLowerWallpaperTarget.mAppToken == wtoken
8897 || mUpperWallpaperTarget.mAppToken == wtoken) {
8898 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008899 }
8900 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008901 if (wtoken.appFullscreen) {
8902 WindowState ws = wtoken.findMainWindow();
8903 if (ws != null) {
8904 // If this is a compatibility mode
8905 // window, we will always use its anim.
8906 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8907 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008908 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008909 bestAnimLayer = Integer.MAX_VALUE;
8910 } else if (ws.mLayer > bestAnimLayer) {
8911 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008912 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008913 bestAnimLayer = ws.mLayer;
8914 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008915 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008916 }
8917 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008918
Dianne Hackborn25994b42009-09-04 14:21:19 -07008919 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008920 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008921 "Wallpaper animation!");
8922 switch (transit) {
8923 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8924 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8925 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8926 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8927 break;
8928 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8929 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8930 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8931 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8932 break;
8933 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008934 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008935 "New transit: " + transit);
8936 } else if (oldWallpaper != null) {
8937 // We are transitioning from an activity with
8938 // a wallpaper to one without.
8939 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008940 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008941 "New transit away from wallpaper: " + transit);
8942 } else if (mWallpaperTarget != null) {
8943 // We are transitioning from an activity without
8944 // a wallpaper to now showing the wallpaper
8945 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008946 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008947 "New transit into wallpaper: " + transit);
8948 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008949
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008950 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8951 mLastEnterAnimToken = animToken;
8952 mLastEnterAnimParams = animLp;
8953 } else if (mLastEnterAnimParams != null) {
8954 animLp = mLastEnterAnimParams;
8955 mLastEnterAnimToken = null;
8956 mLastEnterAnimParams = null;
8957 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008958
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008959 // If all closing windows are obscured, then there is
8960 // no need to do an animation. This is the case, for
8961 // example, when this transition is being done behind
8962 // the lock screen.
8963 if (!mPolicy.allowAppAnimationsLw()) {
8964 animLp = null;
8965 }
8966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008967 NN = mOpeningApps.size();
8968 for (i=0; i<NN; i++) {
8969 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008970 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008971 "Now opening app" + wtoken);
8972 wtoken.reportedVisible = false;
8973 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008974 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008975 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008976 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008977 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008978 wtoken.showAllWindowsLocked();
8979 }
8980 NN = mClosingApps.size();
8981 for (i=0; i<NN; i++) {
8982 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008983 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008984 "Now closing app" + wtoken);
8985 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07008986 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008987 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008988 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008989 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008990 // Force the allDrawn flag, because we want to start
8991 // this guy's animations regardless of whether it's
8992 // gotten drawn.
8993 wtoken.allDrawn = true;
8994 }
8995
Dianne Hackborn8b571a82009-09-25 16:09:43 -07008996 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008998 mOpeningApps.clear();
8999 mClosingApps.clear();
9000
9001 // This has changed the visibility of windows, so perform
9002 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009003 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009004 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009005 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9006 assignLayersLocked();
9007 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009008 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009009 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009010 }
9011 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009012
Dianne Hackborn16064f92010-03-25 00:47:24 -07009013 int adjResult = 0;
9014
Dianne Hackborna8f60182009-09-01 19:01:50 -07009015 if (!animating && mAppTransitionRunning) {
9016 // We have finished the animation of an app transition. To do
9017 // this, we have delayed a lot of operations like showing and
9018 // hiding apps, moving apps in Z-order, etc. The app token list
9019 // reflects the correct Z-order, but the window list may now
9020 // be out of sync with it. So here we will just rebuild the
9021 // entire app window list. Fun!
9022 mAppTransitionRunning = false;
9023 // Clear information about apps that were moving.
9024 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009025
Dianne Hackborna8f60182009-09-01 19:01:50 -07009026 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009027 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009028 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009029 moveInputMethodWindowsIfNeededLocked(false);
9030 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009031 // Since the window list has been rebuilt, focus might
9032 // have to be recomputed since the actual order of windows
9033 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009034 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009036
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009037 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009038 // At this point, there was a window with a wallpaper that
9039 // was force hiding other windows behind it, but now it
9040 // is going away. This may be simple -- just animate
9041 // away the wallpaper and its window -- or it may be
9042 // hard -- the wallpaper now needs to be shown behind
9043 // something that was hidden.
9044 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009045 if (mLowerWallpaperTarget != null
9046 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009047 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009048 "wallpaperForceHiding changed with lower="
9049 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009050 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009051 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9052 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9053 if (mLowerWallpaperTarget.mAppToken.hidden) {
9054 // The lower target has become hidden before we
9055 // actually started the animation... let's completely
9056 // re-evaluate everything.
9057 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009058 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009059 }
9060 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009061 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009062 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009063 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009064 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009065 + " NEW: " + mWallpaperTarget
9066 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009067 if (mLowerWallpaperTarget == null) {
9068 // Whoops, we don't need a special wallpaper animation.
9069 // Clear them out.
9070 forceHiding = false;
9071 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009072 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009073 if (w.mSurface != null) {
9074 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009075 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009076 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009077 forceHiding = true;
9078 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9079 if (!w.mAnimating) {
9080 // We set the animation above so it
9081 // is not yet running.
9082 w.clearAnimation();
9083 }
9084 }
9085 }
9086 }
9087 }
9088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009089
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009090 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009091 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009092 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009093 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009094 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009095
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009096 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009097 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009098 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009099 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009100 assignLayersLocked();
9101 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009102 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009103 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009104 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009105 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009106
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009107 if (mFocusMayChange) {
9108 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009109 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009110 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009111 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009112 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009113 }
9114
9115 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009116 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009117 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009118
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009119 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9120 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009121
Jeff Browne33348b2010-07-15 23:54:05 -07009122 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009123 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124
9125 // THIRD LOOP: Update the surfaces of all windows.
9126
9127 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9128
9129 boolean obscured = false;
9130 boolean blurring = false;
9131 boolean dimming = false;
9132 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009133 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009134 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009135
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009136 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009138 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009139 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009140
9141 boolean displayed = false;
9142 final WindowManager.LayoutParams attrs = w.mAttrs;
9143 final int attrFlags = attrs.flags;
9144
9145 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009146 // XXX NOTE: The logic here could be improved. We have
9147 // the decision about whether to resize a window separated
9148 // from whether to hide the surface. This can cause us to
9149 // resize a surface even if we are going to hide it. You
9150 // can see this by (1) holding device in landscape mode on
9151 // home screen; (2) tapping browser icon (device will rotate
9152 // to landscape; (3) tap home. The wallpaper will be resized
9153 // in step 2 but then immediately hidden, causing us to
9154 // have to resize and then redraw it again in step 3. It
9155 // would be nice to figure out how to avoid this, but it is
9156 // difficult because we do need to resize surfaces in some
9157 // cases while they are hidden such as when first showing a
9158 // window.
9159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009160 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009161 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009162 TAG, "Placing surface #" + i + " " + w.mSurface
9163 + ": new=" + w.mShownFrame + ", old="
9164 + w.mLastShownFrame);
9165
9166 boolean resize;
9167 int width, height;
9168 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9169 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9170 w.mLastRequestedHeight != w.mRequestedHeight;
9171 // for a scaled surface, we just want to use
9172 // the requested size.
9173 width = w.mRequestedWidth;
9174 height = w.mRequestedHeight;
9175 w.mLastRequestedWidth = width;
9176 w.mLastRequestedHeight = height;
9177 w.mLastShownFrame.set(w.mShownFrame);
9178 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009179 if (SHOW_TRANSACTIONS) logSurface(w,
9180 "POS " + w.mShownFrame.left
9181 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009182 w.mSurfaceX = w.mShownFrame.left;
9183 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009184 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9185 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009186 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009187 if (!recoveringMemory) {
9188 reclaimSomeSurfaceMemoryLocked(w, "position");
9189 }
9190 }
9191 } else {
9192 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9193 width = w.mShownFrame.width();
9194 height = w.mShownFrame.height();
9195 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009196 }
9197
9198 if (resize) {
9199 if (width < 1) width = 1;
9200 if (height < 1) height = 1;
9201 if (w.mSurface != null) {
9202 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009203 if (SHOW_TRANSACTIONS) logSurface(w,
9204 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009205 + w.mShownFrame.top + " SIZE "
9206 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009207 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009208 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009209 w.mSurfaceW = width;
9210 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009211 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009212 w.mSurfaceX = w.mShownFrame.left;
9213 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009214 w.mSurface.setPosition(w.mShownFrame.left,
9215 w.mShownFrame.top);
9216 } catch (RuntimeException e) {
9217 // If something goes wrong with the surface (such
9218 // as running out of memory), don't take down the
9219 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009220 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009221 + "size=(" + width + "x" + height
9222 + "), pos=(" + w.mShownFrame.left
9223 + "," + w.mShownFrame.top + ")", e);
9224 if (!recoveringMemory) {
9225 reclaimSomeSurfaceMemoryLocked(w, "size");
9226 }
9227 }
9228 }
9229 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009230 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009231 w.mContentInsetsChanged =
9232 !w.mLastContentInsets.equals(w.mContentInsets);
9233 w.mVisibleInsetsChanged =
9234 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009235 boolean configChanged =
9236 w.mConfiguration != mCurConfiguration
9237 && (w.mConfiguration == null
9238 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009239 if (DEBUG_CONFIGURATION && configChanged) {
9240 Slog.v(TAG, "Win " + w + " config changed: "
9241 + mCurConfiguration);
9242 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009243 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009244 + ": configChanged=" + configChanged
9245 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009246 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009247 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009248 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009249 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009250 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009251 w.mLastFrame.set(w.mFrame);
9252 w.mLastContentInsets.set(w.mContentInsets);
9253 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009254 // If the screen is currently frozen, then keep
9255 // it frozen until this window draws at its new
9256 // orientation.
9257 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009258 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009259 "Resizing while display frozen: " + w);
9260 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009261 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009262 mWindowsFreezingScreen = true;
9263 // XXX should probably keep timeout from
9264 // when we first froze the display.
9265 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9266 mH.sendMessageDelayed(mH.obtainMessage(
9267 H.WINDOW_FREEZE_TIMEOUT), 2000);
9268 }
9269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009270 // If the orientation is changing, then we need to
9271 // hold off on unfreezing the display until this
9272 // window has been redrawn; to do that, we need
9273 // to go through the process of getting informed
9274 // by the application when it has finished drawing.
9275 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009276 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009277 "Orientation start waiting for draw in "
9278 + w + ", surface " + w.mSurface);
9279 w.mDrawPending = true;
9280 w.mCommitDrawPending = false;
9281 w.mReadyToShow = false;
9282 if (w.mAppToken != null) {
9283 w.mAppToken.allDrawn = false;
9284 }
9285 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009286 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009287 "Resizing window " + w + " to " + w.mFrame);
9288 mResizingWindows.add(w);
9289 } else if (w.mOrientationChanging) {
9290 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009291 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009292 "Orientation not waiting for draw in "
9293 + w + ", surface " + w.mSurface);
9294 w.mOrientationChanging = false;
9295 }
9296 }
9297 }
9298
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009299 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009300 if (!w.mLastHidden) {
9301 //dump();
Dianne Hackborn5943c202010-04-12 21:36:49 -07009302 if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow="
9303 + w.mRootToken.waitingToShow + " polvis="
9304 + w.mPolicyVisibility + " atthid="
9305 + w.mAttachedHidden + " tokhid="
9306 + w.mRootToken.hidden + " vis="
9307 + w.mViewVisibility);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009308 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009309 if (SHOW_TRANSACTIONS) logSurface(w,
9310 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009312 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009313 try {
9314 w.mSurface.hide();
9315 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009316 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009317 }
9318 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009319 }
9320 // If we are waiting for this window to handle an
9321 // orientation change, well, it is hidden, so
9322 // doesn't really matter. Note that this does
9323 // introduce a potential glitch if the window
9324 // becomes unhidden before it has drawn for the
9325 // new orientation.
9326 if (w.mOrientationChanging) {
9327 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009328 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 "Orientation change skips hidden " + w);
9330 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009331 } else if (w.mLastLayer != w.mAnimLayer
9332 || w.mLastAlpha != w.mShownAlpha
9333 || w.mLastDsDx != w.mDsDx
9334 || w.mLastDtDx != w.mDtDx
9335 || w.mLastDsDy != w.mDsDy
9336 || w.mLastDtDy != w.mDtDy
9337 || w.mLastHScale != w.mHScale
9338 || w.mLastVScale != w.mVScale
9339 || w.mLastHidden) {
9340 displayed = true;
9341 w.mLastAlpha = w.mShownAlpha;
9342 w.mLastLayer = w.mAnimLayer;
9343 w.mLastDsDx = w.mDsDx;
9344 w.mLastDtDx = w.mDtDx;
9345 w.mLastDsDy = w.mDsDy;
9346 w.mLastDtDy = w.mDtDy;
9347 w.mLastHScale = w.mHScale;
9348 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009349 if (SHOW_TRANSACTIONS) logSurface(w,
9350 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009351 + " matrix=[" + (w.mDsDx*w.mHScale)
9352 + "," + (w.mDtDx*w.mVScale)
9353 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009354 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009355 if (w.mSurface != null) {
9356 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009357 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009358 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009359 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009360 w.mSurface.setLayer(w.mAnimLayer);
9361 w.mSurface.setMatrix(
9362 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9363 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9364 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009365 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009366 if (!recoveringMemory) {
9367 reclaimSomeSurfaceMemoryLocked(w, "update");
9368 }
9369 }
9370 }
9371
9372 if (w.mLastHidden && !w.mDrawPending
9373 && !w.mCommitDrawPending
9374 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009375 if (SHOW_TRANSACTIONS) logSurface(w,
9376 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009377 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009378 + " during relayout");
9379 if (showSurfaceRobustlyLocked(w)) {
9380 w.mHasDrawn = true;
9381 w.mLastHidden = false;
9382 } else {
9383 w.mOrientationChanging = false;
9384 }
9385 }
9386 if (w.mSurface != null) {
9387 w.mToken.hasVisible = true;
9388 }
9389 } else {
9390 displayed = true;
9391 }
9392
9393 if (displayed) {
9394 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009395 if (attrs.width == LayoutParams.MATCH_PARENT
9396 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009397 covered = true;
9398 }
9399 }
9400 if (w.mOrientationChanging) {
9401 if (w.mDrawPending || w.mCommitDrawPending) {
9402 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009403 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009404 "Orientation continue waiting for draw in " + w);
9405 } else {
9406 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009407 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009408 "Orientation change complete in " + w);
9409 }
9410 }
9411 w.mToken.hasVisible = true;
9412 }
9413 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009414 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009415 "Orientation change skips hidden " + w);
9416 w.mOrientationChanging = false;
9417 }
9418
9419 final boolean canBeSeen = w.isDisplayedLw();
9420
9421 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9422 focusDisplayed = true;
9423 }
9424
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009425 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009427 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009428 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 if (w.mSurface != null) {
9430 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9431 holdScreen = w.mSession;
9432 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009433 if (!syswin && w.mAttrs.screenBrightness >= 0
9434 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009435 screenBrightness = w.mAttrs.screenBrightness;
9436 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009437 if (!syswin && w.mAttrs.buttonBrightness >= 0
9438 && buttonBrightness < 0) {
9439 buttonBrightness = w.mAttrs.buttonBrightness;
9440 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009441 if (canBeSeen
9442 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9443 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9444 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009445 syswin = true;
9446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009447 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009448
Dianne Hackborn25994b42009-09-04 14:21:19 -07009449 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9450 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009451 // This window completely covers everything behind it,
9452 // so we want to leave all of them as unblurred (for
9453 // performance reasons).
9454 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009455 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009456 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009457 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009458 obscured = true;
9459 if (mBackgroundFillerSurface == null) {
9460 try {
9461 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009462 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009463 0, dw, dh,
9464 PixelFormat.OPAQUE,
9465 Surface.FX_SURFACE_NORMAL);
9466 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009467 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009468 }
9469 }
9470 try {
9471 mBackgroundFillerSurface.setPosition(0, 0);
9472 mBackgroundFillerSurface.setSize(dw, dh);
9473 // Using the same layer as Dim because they will never be shown at the
9474 // same time.
9475 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9476 mBackgroundFillerSurface.show();
9477 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009478 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009479 }
9480 backgroundFillerShown = true;
9481 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009482 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009484 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 + ": blurring=" + blurring
9486 + " obscured=" + obscured
9487 + " displayed=" + displayed);
9488 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9489 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009490 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009491 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009492 if (mDimAnimator == null) {
9493 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009494 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009495 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009496 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009497 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009498 }
9499 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9500 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009501 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009502 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009504 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 + mBlurSurface + ": CREATE");
9506 try {
Romain Guy06882f82009-06-10 13:36:04 -07009507 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009508 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009509 -1, 16, 16,
9510 PixelFormat.OPAQUE,
9511 Surface.FX_SURFACE_BLUR);
9512 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009513 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009514 }
9515 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009517 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9518 + mBlurSurface + ": pos=(0,0) (" +
9519 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009520 mBlurSurface.setPosition(0, 0);
9521 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009522 mBlurSurface.setLayer(w.mAnimLayer-2);
9523 if (!mBlurShown) {
9524 try {
9525 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9526 + mBlurSurface + ": SHOW");
9527 mBlurSurface.show();
9528 } catch (RuntimeException e) {
9529 Slog.w(TAG, "Failure showing blur surface", e);
9530 }
9531 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009532 }
9533 }
9534 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009535 }
9536 }
9537 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009538
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009539 if (obscuredChanged && mWallpaperTarget == w) {
9540 // This is the wallpaper target and its obscured state
9541 // changed... make sure the current wallaper's visibility
9542 // has been updated accordingly.
9543 updateWallpaperVisibilityLocked();
9544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009546
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009547 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9548 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009549 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009550 try {
9551 mBackgroundFillerSurface.hide();
9552 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009553 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009554 }
9555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009556
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009557 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009558 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9559 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 }
Romain Guy06882f82009-06-10 13:36:04 -07009561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009562 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009563 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009564 + ": HIDE");
9565 try {
9566 mBlurSurface.hide();
9567 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009568 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009569 }
9570 mBlurShown = false;
9571 }
9572
Joe Onorato8a9b2202010-02-26 18:56:32 -08009573 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009574 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009575 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009576 }
9577
Jeff Browne33348b2010-07-15 23:54:05 -07009578 mInputMonitor.updateInputWindowsLw();
9579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009580 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009581
Joe Onorato8a9b2202010-02-26 18:56:32 -08009582 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009583 "With display frozen, orientationChangeComplete="
9584 + orientationChangeComplete);
9585 if (orientationChangeComplete) {
9586 if (mWindowsFreezingScreen) {
9587 mWindowsFreezingScreen = false;
9588 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9589 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009590 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009591 }
Romain Guy06882f82009-06-10 13:36:04 -07009592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009593 i = mResizingWindows.size();
9594 if (i > 0) {
9595 do {
9596 i--;
9597 WindowState win = mResizingWindows.get(i);
9598 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009599 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9600 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009601 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009602 boolean configChanged =
9603 win.mConfiguration != mCurConfiguration
9604 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009605 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9606 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9607 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009608 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009609 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009610 + " / " + mCurConfiguration + " / 0x"
9611 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009612 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009613 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009614 win.mClient.resized(win.mFrame.width(),
9615 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009616 win.mLastVisibleInsets, win.mDrawPending,
9617 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009618 win.mContentInsetsChanged = false;
9619 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009620 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009621 } catch (RemoteException e) {
9622 win.mOrientationChanging = false;
9623 }
9624 } while (i > 0);
9625 mResizingWindows.clear();
9626 }
Romain Guy06882f82009-06-10 13:36:04 -07009627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009628 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009629 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630 i = mDestroySurface.size();
9631 if (i > 0) {
9632 do {
9633 i--;
9634 WindowState win = mDestroySurface.get(i);
9635 win.mDestroying = false;
9636 if (mInputMethodWindow == win) {
9637 mInputMethodWindow = null;
9638 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009639 if (win == mWallpaperTarget) {
9640 wallpaperDestroyed = true;
9641 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009642 win.destroySurfaceLocked();
9643 } while (i > 0);
9644 mDestroySurface.clear();
9645 }
9646
9647 // Time to remove any exiting tokens?
9648 for (i=mExitingTokens.size()-1; i>=0; i--) {
9649 WindowToken token = mExitingTokens.get(i);
9650 if (!token.hasVisible) {
9651 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009652 if (token.windowType == TYPE_WALLPAPER) {
9653 mWallpaperTokens.remove(token);
9654 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009655 }
9656 }
9657
9658 // Time to remove any exiting applications?
9659 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9660 AppWindowToken token = mExitingAppTokens.get(i);
9661 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009662 // Make sure there is no animation running on this token,
9663 // so any windows associated with it will be removed as
9664 // soon as their animations are complete
9665 token.animation = null;
9666 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009667 mAppTokens.remove(token);
9668 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009669 if (mLastEnterAnimToken == token) {
9670 mLastEnterAnimToken = null;
9671 mLastEnterAnimParams = null;
9672 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009673 }
9674 }
9675
Dianne Hackborna8f60182009-09-01 19:01:50 -07009676 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009677
Dianne Hackborna8f60182009-09-01 19:01:50 -07009678 if (!animating && mAppTransitionRunning) {
9679 // We have finished the animation of an app transition. To do
9680 // this, we have delayed a lot of operations like showing and
9681 // hiding apps, moving apps in Z-order, etc. The app token list
9682 // reflects the correct Z-order, but the window list may now
9683 // be out of sync with it. So here we will just rebuild the
9684 // entire app window list. Fun!
9685 mAppTransitionRunning = false;
9686 needRelayout = true;
9687 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009688 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009689 // Clear information about apps that were moving.
9690 mToBottomApps.clear();
9691 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009692
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009693 if (focusDisplayed) {
9694 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9695 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009696 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009697 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009698 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009699 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009700 requestAnimationLocked(0);
9701 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9703 }
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009704
Jeff Browne33348b2010-07-15 23:54:05 -07009705 mInputMonitor.updateInputWindowsLw();
9706
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009707 if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen
9708 + " holdScreen=" + holdScreen);
9709 if (!mDisplayFrozen) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07009710 setHoldScreenLocked(holdScreen != null);
Dianne Hackbornce73c1e2010-04-12 23:11:38 -07009711 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9712 mPowerManager.setScreenBrightnessOverride(-1);
9713 } else {
9714 mPowerManager.setScreenBrightnessOverride((int)
9715 (screenBrightness * Power.BRIGHTNESS_ON));
9716 }
9717 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9718 mPowerManager.setButtonBrightnessOverride(-1);
9719 } else {
9720 mPowerManager.setButtonBrightnessOverride((int)
9721 (buttonBrightness * Power.BRIGHTNESS_ON));
9722 }
9723 if (holdScreen != mHoldingScreenOn) {
9724 mHoldingScreenOn = holdScreen;
9725 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9726 mH.sendMessage(m);
9727 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009728 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009729
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009730 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009731 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009732 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9733 LocalPowerManager.BUTTON_EVENT, true);
9734 mTurnOnScreen = false;
9735 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009736
9737 // Check to see if we are now in a state where the screen should
9738 // be enabled, because the window obscured flags have changed.
9739 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009740 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07009741
9742 /**
9743 * Must be called with the main window manager lock held.
9744 */
9745 void setHoldScreenLocked(boolean holding) {
9746 boolean state = mHoldingScreenWakeLock.isHeld();
9747 if (holding != state) {
9748 if (holding) {
9749 mHoldingScreenWakeLock.acquire();
9750 } else {
9751 mPolicy.screenOnStoppedLw();
9752 mHoldingScreenWakeLock.release();
9753 }
9754 }
9755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009756
9757 void requestAnimationLocked(long delay) {
9758 if (!mAnimationPending) {
9759 mAnimationPending = true;
9760 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9761 }
9762 }
Romain Guy06882f82009-06-10 13:36:04 -07009763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009764 /**
9765 * Have the surface flinger show a surface, robustly dealing with
9766 * error conditions. In particular, if there is not enough memory
9767 * to show the surface, then we will try to get rid of other surfaces
9768 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009769 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009770 * @return Returns true if the surface was successfully shown.
9771 */
9772 boolean showSurfaceRobustlyLocked(WindowState win) {
9773 try {
9774 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009775 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009776 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009777 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009778 if (DEBUG_VISIBILITY) Slog.v(TAG,
9779 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009780 win.mTurnOnScreen = false;
9781 mTurnOnScreen = true;
9782 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009783 }
9784 return true;
9785 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009786 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 }
Romain Guy06882f82009-06-10 13:36:04 -07009788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009791 return false;
9792 }
Romain Guy06882f82009-06-10 13:36:04 -07009793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009794 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9795 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009796
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009797 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009798 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 if (mForceRemoves == null) {
9801 mForceRemoves = new ArrayList<WindowState>();
9802 }
Romain Guy06882f82009-06-10 13:36:04 -07009803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009804 long callingIdentity = Binder.clearCallingIdentity();
9805 try {
9806 // There was some problem... first, do a sanity check of the
9807 // window list to make sure we haven't left any dangling surfaces
9808 // around.
9809 int N = mWindows.size();
9810 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009811 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009813 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009814 if (ws.mSurface != null) {
9815 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009816 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009817 + ws + " surface=" + ws.mSurface
9818 + " token=" + win.mToken
9819 + " pid=" + ws.mSession.mPid
9820 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009821 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009822 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009823 ws.mSurface = null;
9824 mForceRemoves.add(ws);
9825 i--;
9826 N--;
9827 leakedSurface = true;
9828 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009829 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009830 + ws + " surface=" + ws.mSurface
9831 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009832 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009833 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009834 ws.mSurface = null;
9835 leakedSurface = true;
9836 }
9837 }
9838 }
Romain Guy06882f82009-06-10 13:36:04 -07009839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009840 boolean killedApps = false;
9841 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009842 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009843 SparseIntArray pidCandidates = new SparseIntArray();
9844 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009845 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009846 if (ws.mSurface != null) {
9847 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9848 }
9849 }
9850 if (pidCandidates.size() > 0) {
9851 int[] pids = new int[pidCandidates.size()];
9852 for (int i=0; i<pids.length; i++) {
9853 pids[i] = pidCandidates.keyAt(i);
9854 }
9855 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009856 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009857 killedApps = true;
9858 }
9859 } catch (RemoteException e) {
9860 }
9861 }
9862 }
Romain Guy06882f82009-06-10 13:36:04 -07009863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009864 if (leakedSurface || killedApps) {
9865 // We managed to reclaim some memory, so get rid of the trouble
9866 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009867 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009869 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009870 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009871 win.mSurface = null;
9872 }
Romain Guy06882f82009-06-10 13:36:04 -07009873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009874 try {
9875 win.mClient.dispatchGetNewSurface();
9876 } catch (RemoteException e) {
9877 }
9878 }
9879 } finally {
9880 Binder.restoreCallingIdentity(callingIdentity);
9881 }
9882 }
Romain Guy06882f82009-06-10 13:36:04 -07009883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009884 private boolean updateFocusedWindowLocked(int mode) {
9885 WindowState newFocus = computeFocusedWindowLocked();
9886 if (mCurrentFocus != newFocus) {
9887 // This check makes sure that we don't already have the focus
9888 // change message pending.
9889 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9890 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009891 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009892 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9893 final WindowState oldFocus = mCurrentFocus;
9894 mCurrentFocus = newFocus;
9895 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009897 final WindowState imWindow = mInputMethodWindow;
9898 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009899 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009900 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009901 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9902 mLayoutNeeded = true;
9903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009904 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9905 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009906 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9907 // Client will do the layout, but we need to assign layers
9908 // for handleNewWindowLocked() below.
9909 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009910 }
9911 }
Jeff Brown349703e2010-06-22 01:27:15 -07009912
9913 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9914 // If we defer assigning layers, then the caller is responsible for
9915 // doing this part.
9916 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009917 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009918 return true;
9919 }
9920 return false;
9921 }
Jeff Brown349703e2010-06-22 01:27:15 -07009922
9923 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009924 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009925 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009926
9927 private WindowState computeFocusedWindowLocked() {
9928 WindowState result = null;
9929 WindowState win;
9930
9931 int i = mWindows.size() - 1;
9932 int nextAppIndex = mAppTokens.size()-1;
9933 WindowToken nextApp = nextAppIndex >= 0
9934 ? mAppTokens.get(nextAppIndex) : null;
9935
9936 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009937 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009938
Joe Onorato8a9b2202010-02-26 18:56:32 -08009939 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 TAG, "Looking for focus: " + i
9941 + " = " + win
9942 + ", flags=" + win.mAttrs.flags
9943 + ", canReceive=" + win.canReceiveKeys());
9944
9945 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009947 // If this window's application has been removed, just skip it.
9948 if (thisApp != null && thisApp.removed) {
9949 i--;
9950 continue;
9951 }
Romain Guy06882f82009-06-10 13:36:04 -07009952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009953 // If there is a focused app, don't allow focus to go to any
9954 // windows below it. If this is an application window, step
9955 // through the app tokens until we find its app.
9956 if (thisApp != null && nextApp != null && thisApp != nextApp
9957 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9958 int origAppIndex = nextAppIndex;
9959 while (nextAppIndex > 0) {
9960 if (nextApp == mFocusedApp) {
9961 // Whoops, we are below the focused app... no focus
9962 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009963 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009964 TAG, "Reached focused app: " + mFocusedApp);
9965 return null;
9966 }
9967 nextAppIndex--;
9968 nextApp = mAppTokens.get(nextAppIndex);
9969 if (nextApp == thisApp) {
9970 break;
9971 }
9972 }
9973 if (thisApp != nextApp) {
9974 // Uh oh, the app token doesn't exist! This shouldn't
9975 // happen, but if it does we can get totally hosed...
9976 // so restart at the original app.
9977 nextAppIndex = origAppIndex;
9978 nextApp = mAppTokens.get(nextAppIndex);
9979 }
9980 }
9981
9982 // Dispatch to this window if it is wants key events.
9983 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009984 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009985 TAG, "Found focus @ " + i + " = " + win);
9986 result = win;
9987 break;
9988 }
9989
9990 i--;
9991 }
9992
9993 return result;
9994 }
9995
9996 private void startFreezingDisplayLocked() {
9997 if (mDisplayFrozen) {
9998 return;
9999 }
Romain Guy06882f82009-06-10 13:36:04 -070010000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010001 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010004 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 if (mFreezeGcPending != 0) {
10006 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010007 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010008 mH.removeMessages(H.FORCE_GC);
10009 Runtime.getRuntime().gc();
10010 mFreezeGcPending = now;
10011 }
10012 } else {
10013 mFreezeGcPending = now;
10014 }
Romain Guy06882f82009-06-10 13:36:04 -070010015
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010016 if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException());
10017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010018 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010019
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010020 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010021
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010022 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10023 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010024 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010025 mAppTransitionReady = true;
10026 }
Romain Guy06882f82009-06-10 13:36:04 -070010027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010028 if (PROFILE_ORIENTATION) {
10029 File file = new File("/data/system/frozen");
10030 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10031 }
10032 Surface.freezeDisplay(0);
10033 }
Romain Guy06882f82009-06-10 13:36:04 -070010034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010035 private void stopFreezingDisplayLocked() {
10036 if (!mDisplayFrozen) {
10037 return;
10038 }
Romain Guy06882f82009-06-10 13:36:04 -070010039
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010040 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10041 return;
10042 }
10043
Dianne Hackbornce73c1e2010-04-12 23:11:38 -070010044 if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException());
10045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010046 mDisplayFrozen = false;
10047 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10048 if (PROFILE_ORIENTATION) {
10049 Debug.stopMethodTracing();
10050 }
10051 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010052
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010053 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010054
Christopher Tateb696aee2010-04-02 19:08:30 -070010055 // While the display is frozen we don't re-compute the orientation
10056 // to avoid inconsistent states. However, something interesting
10057 // could have actually changed during that time so re-evaluate it
10058 // now to catch that.
10059 if (updateOrientationFromAppTokensLocked()) {
10060 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10061 }
10062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 // A little kludge: a lot could have happened while the
10064 // display was frozen, so now that we are coming back we
10065 // do a gc so that any remote references the system
10066 // processes holds on others can be released if they are
10067 // no longer needed.
10068 mH.removeMessages(H.FORCE_GC);
10069 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10070 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010072 mScreenFrozenLock.release();
10073 }
Romain Guy06882f82009-06-10 13:36:04 -070010074
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010075 static int getPropertyInt(String name, int defUnits, int defDps, DisplayMetrics dm) {
10076 String str = SystemProperties.get(name);
10077 try {
10078 int val = Integer.parseInt(str);
10079 return val;
10080 } catch (Exception e) {
10081 }
10082 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10083 return defDps;
10084 }
10085 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10086 return val;
10087 }
10088
10089 class Watermark {
10090 Surface mSurface;
10091 int mWidth;
10092 int mHeight;
10093 int mXPercent;
10094 int mYPercent;
10095
10096 Watermark(SurfaceSession session, String text) {
10097 final DisplayMetrics dm = new DisplayMetrics();
10098 mDisplay.getMetrics(dm);
10099
10100 int fontSize = getPropertyInt("ro.watermark.height",
10101 TypedValue.COMPLEX_UNIT_DIP, 48, dm);
10102 mXPercent = getPropertyInt("ro.watermark.x",
10103 TypedValue.COMPLEX_UNIT_PX, 50, dm);
10104 mYPercent = getPropertyInt("ro.watermark.y",
10105 TypedValue.COMPLEX_UNIT_PX, 99, dm);
10106 int color = getPropertyInt("ro.watermark.color",
10107 TypedValue.COMPLEX_UNIT_PX, 0x80ffffff, dm);
10108 int shadowRadius = getPropertyInt("ro.watermark.shadow.radius",
10109 TypedValue.COMPLEX_UNIT_PX, 5, dm);
10110 int shadowDx = getPropertyInt("ro.watermark.shadow.dx",
10111 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10112 int shadowDy = getPropertyInt("ro.watermark.shadow.dy",
10113 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10114 int shadowColor = getPropertyInt("ro.watermark.shadow.color",
10115 TypedValue.COMPLEX_UNIT_PX, 0xff000000, dm);
10116
10117 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
10118 paint.setTextSize(fontSize);
10119 paint.setColor(color);
10120 paint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
10121 paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10122
10123 FontMetricsInt fm = paint.getFontMetricsInt();
10124 mHeight = fm.descent - fm.ascent + 20;
10125 mWidth = (int)paint.measureText(text) + 20;
10126
10127 try {
10128 mSurface = new Surface(session, 0,
10129 "WatermarkSurface",
10130 -1, mWidth, mHeight, PixelFormat.TRANSLUCENT, 0);
10131 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
10132 Rect dirty = new Rect(0, 0, mWidth, mHeight);
10133 Canvas c = mSurface.lockCanvas(dirty);
10134 c.drawText(text, 10, -fm.ascent+10, paint);
10135 mSurface.unlockCanvasAndPost(c);
10136 mSurface.show();
10137 } catch (OutOfResourcesException e) {
10138 }
10139 }
10140
10141 void positionSurface(int dw, int dh) {
10142 int availW = dw - mWidth;
10143 int availH = dh - mHeight;
10144 mSurface.setPosition((availW*mXPercent)/100,
10145 (availH*mYPercent)/100);
10146 }
10147 }
10148
10149 void createWatermark() {
10150 if (mWatermark != null) {
10151 return;
10152 }
10153
10154 String text = SystemProperties.get("ro.watermark.text");
10155 if (text == null || text.length() <= 0) {
10156 return;
10157 }
10158
10159 mWatermark = new Watermark(mFxSession, text);
10160 }
10161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010162 @Override
10163 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10164 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10165 != PackageManager.PERMISSION_GRANTED) {
10166 pw.println("Permission Denial: can't dump WindowManager from from pid="
10167 + Binder.getCallingPid()
10168 + ", uid=" + Binder.getCallingUid());
10169 return;
10170 }
Romain Guy06882f82009-06-10 13:36:04 -070010171
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010172 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010173 pw.println(" ");
10174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010175 synchronized(mWindowMap) {
10176 pw.println("Current Window Manager state:");
10177 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010178 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010179 pw.print(" Window #"); pw.print(i); pw.print(' ');
10180 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010181 w.dump(pw, " ");
10182 }
10183 if (mInputMethodDialogs.size() > 0) {
10184 pw.println(" ");
10185 pw.println(" Input method dialogs:");
10186 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10187 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010188 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010189 }
10190 }
10191 if (mPendingRemove.size() > 0) {
10192 pw.println(" ");
10193 pw.println(" Remove pending for:");
10194 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10195 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010196 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10197 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010198 w.dump(pw, " ");
10199 }
10200 }
10201 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10202 pw.println(" ");
10203 pw.println(" Windows force removing:");
10204 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10205 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010206 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10207 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010208 w.dump(pw, " ");
10209 }
10210 }
10211 if (mDestroySurface.size() > 0) {
10212 pw.println(" ");
10213 pw.println(" Windows waiting to destroy their surface:");
10214 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10215 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010216 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10217 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010218 w.dump(pw, " ");
10219 }
10220 }
10221 if (mLosingFocus.size() > 0) {
10222 pw.println(" ");
10223 pw.println(" Windows losing focus:");
10224 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10225 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010226 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10227 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010228 w.dump(pw, " ");
10229 }
10230 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010231 if (mResizingWindows.size() > 0) {
10232 pw.println(" ");
10233 pw.println(" Windows waiting to resize:");
10234 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10235 WindowState w = mResizingWindows.get(i);
10236 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10237 pw.print(w); pw.println(":");
10238 w.dump(pw, " ");
10239 }
10240 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010241 if (mSessions.size() > 0) {
10242 pw.println(" ");
10243 pw.println(" All active sessions:");
10244 Iterator<Session> it = mSessions.iterator();
10245 while (it.hasNext()) {
10246 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010247 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010248 s.dump(pw, " ");
10249 }
10250 }
10251 if (mTokenMap.size() > 0) {
10252 pw.println(" ");
10253 pw.println(" All tokens:");
10254 Iterator<WindowToken> it = mTokenMap.values().iterator();
10255 while (it.hasNext()) {
10256 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010257 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010258 token.dump(pw, " ");
10259 }
10260 }
10261 if (mTokenList.size() > 0) {
10262 pw.println(" ");
10263 pw.println(" Window token list:");
10264 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010265 pw.print(" #"); pw.print(i); pw.print(": ");
10266 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010267 }
10268 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010269 if (mWallpaperTokens.size() > 0) {
10270 pw.println(" ");
10271 pw.println(" Wallpaper tokens:");
10272 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10273 WindowToken token = mWallpaperTokens.get(i);
10274 pw.print(" Wallpaper #"); pw.print(i);
10275 pw.print(' '); pw.print(token); pw.println(':');
10276 token.dump(pw, " ");
10277 }
10278 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010279 if (mAppTokens.size() > 0) {
10280 pw.println(" ");
10281 pw.println(" Application tokens in Z order:");
10282 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010283 pw.print(" App #"); pw.print(i); pw.print(": ");
10284 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010285 }
10286 }
10287 if (mFinishedStarting.size() > 0) {
10288 pw.println(" ");
10289 pw.println(" Finishing start of application tokens:");
10290 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10291 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010292 pw.print(" Finished Starting #"); pw.print(i);
10293 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010294 token.dump(pw, " ");
10295 }
10296 }
10297 if (mExitingTokens.size() > 0) {
10298 pw.println(" ");
10299 pw.println(" Exiting tokens:");
10300 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10301 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010302 pw.print(" Exiting #"); pw.print(i);
10303 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010304 token.dump(pw, " ");
10305 }
10306 }
10307 if (mExitingAppTokens.size() > 0) {
10308 pw.println(" ");
10309 pw.println(" Exiting application tokens:");
10310 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10311 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010312 pw.print(" Exiting App #"); pw.print(i);
10313 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010314 token.dump(pw, " ");
10315 }
10316 }
10317 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010318 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10319 pw.print(" mLastFocus="); pw.println(mLastFocus);
10320 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10321 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10322 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010323 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010324 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10325 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10326 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10327 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010328 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10329 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10330 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010331 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10332 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10333 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10334 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010335 if (mDimAnimator != null) {
10336 mDimAnimator.printTo(pw);
10337 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010338 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010339 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010340 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010341 pw.print(mInputMethodAnimLayerAdjustment);
10342 pw.print(" mWallpaperAnimLayerAdjustment=");
10343 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010344 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10345 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010346 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10347 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010348 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10349 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010350 pw.print(" mRotation="); pw.print(mRotation);
10351 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10352 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10353 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10354 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10355 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10356 pw.print(" mNextAppTransition=0x");
10357 pw.print(Integer.toHexString(mNextAppTransition));
10358 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010359 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010360 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010361 if (mNextAppTransitionPackage != null) {
10362 pw.print(" mNextAppTransitionPackage=");
10363 pw.print(mNextAppTransitionPackage);
10364 pw.print(", mNextAppTransitionEnter=0x");
10365 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10366 pw.print(", mNextAppTransitionExit=0x");
10367 pw.print(Integer.toHexString(mNextAppTransitionExit));
10368 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010369 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10370 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010371 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10372 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10373 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10374 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010375 if (mOpeningApps.size() > 0) {
10376 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10377 }
10378 if (mClosingApps.size() > 0) {
10379 pw.print(" mClosingApps="); pw.println(mClosingApps);
10380 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010381 if (mToTopApps.size() > 0) {
10382 pw.print(" mToTopApps="); pw.println(mToTopApps);
10383 }
10384 if (mToBottomApps.size() > 0) {
10385 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10386 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010387 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10388 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010389 }
10390 }
10391
Jeff Brown349703e2010-06-22 01:27:15 -070010392 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 public void monitor() {
10394 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010395 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010396 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010397
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010398 /**
10399 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010400 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010401 */
10402 private static class DimAnimator {
10403 Surface mDimSurface;
10404 boolean mDimShown = false;
10405 float mDimCurrentAlpha;
10406 float mDimTargetAlpha;
10407 float mDimDeltaPerMs;
10408 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010409
10410 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010411
10412 DimAnimator (SurfaceSession session) {
10413 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010414 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010415 + mDimSurface + ": CREATE");
10416 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010417 mDimSurface = new Surface(session, 0,
10418 "DimSurface",
10419 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010420 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010421 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010422 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010423 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010424 }
10425 }
10426 }
10427
10428 /**
10429 * Show the dim surface.
10430 */
10431 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010432 if (!mDimShown) {
10433 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10434 dw + "x" + dh + ")");
10435 mDimShown = true;
10436 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010437 mLastDimWidth = dw;
10438 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010439 mDimSurface.setPosition(0, 0);
10440 mDimSurface.setSize(dw, dh);
10441 mDimSurface.show();
10442 } catch (RuntimeException e) {
10443 Slog.w(TAG, "Failure showing dim surface", e);
10444 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010445 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10446 mLastDimWidth = dw;
10447 mLastDimHeight = dh;
10448 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010449 }
10450 }
10451
10452 /**
10453 * Set's the dim surface's layer and update dim parameters that will be used in
10454 * {@link updateSurface} after all windows are examined.
10455 */
10456 void updateParameters(WindowState w, long currentTime) {
10457 mDimSurface.setLayer(w.mAnimLayer-1);
10458
10459 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010460 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010461 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010462 if (mDimTargetAlpha != target) {
10463 // If the desired dim level has changed, then
10464 // start an animation to it.
10465 mLastDimAnimTime = currentTime;
10466 long duration = (w.mAnimating && w.mAnimation != null)
10467 ? w.mAnimation.computeDurationHint()
10468 : DEFAULT_DIM_DURATION;
10469 if (target > mDimTargetAlpha) {
10470 // This is happening behind the activity UI,
10471 // so we can make it run a little longer to
10472 // give a stronger impression without disrupting
10473 // the user.
10474 duration *= DIM_DURATION_MULTIPLIER;
10475 }
10476 if (duration < 1) {
10477 // Don't divide by zero
10478 duration = 1;
10479 }
10480 mDimTargetAlpha = target;
10481 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10482 }
10483 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010484
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010485 /**
10486 * Updating the surface's alpha. Returns true if the animation continues, or returns
10487 * false when the animation is finished and the dim surface is hidden.
10488 */
10489 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10490 if (!dimming) {
10491 if (mDimTargetAlpha != 0) {
10492 mLastDimAnimTime = currentTime;
10493 mDimTargetAlpha = 0;
10494 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10495 }
10496 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010497
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010498 boolean animating = false;
10499 if (mLastDimAnimTime != 0) {
10500 mDimCurrentAlpha += mDimDeltaPerMs
10501 * (currentTime-mLastDimAnimTime);
10502 boolean more = true;
10503 if (displayFrozen) {
10504 // If the display is frozen, there is no reason to animate.
10505 more = false;
10506 } else if (mDimDeltaPerMs > 0) {
10507 if (mDimCurrentAlpha > mDimTargetAlpha) {
10508 more = false;
10509 }
10510 } else if (mDimDeltaPerMs < 0) {
10511 if (mDimCurrentAlpha < mDimTargetAlpha) {
10512 more = false;
10513 }
10514 } else {
10515 more = false;
10516 }
10517
10518 // Do we need to continue animating?
10519 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010520 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010521 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10522 mLastDimAnimTime = currentTime;
10523 mDimSurface.setAlpha(mDimCurrentAlpha);
10524 animating = true;
10525 } else {
10526 mDimCurrentAlpha = mDimTargetAlpha;
10527 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010528 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010529 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10530 mDimSurface.setAlpha(mDimCurrentAlpha);
10531 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010532 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010533 + ": HIDE");
10534 try {
10535 mDimSurface.hide();
10536 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010537 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010538 }
10539 mDimShown = false;
10540 }
10541 }
10542 }
10543 return animating;
10544 }
10545
10546 public void printTo(PrintWriter pw) {
10547 pw.print(" mDimShown="); pw.print(mDimShown);
10548 pw.print(" current="); pw.print(mDimCurrentAlpha);
10549 pw.print(" target="); pw.print(mDimTargetAlpha);
10550 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10551 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10552 }
10553 }
10554
10555 /**
10556 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10557 * This is used for opening/closing transition for apps in compatible mode.
10558 */
10559 private static class FadeInOutAnimation extends Animation {
10560 int mWidth;
10561 boolean mFadeIn;
10562
10563 public FadeInOutAnimation(boolean fadeIn) {
10564 setInterpolator(new AccelerateInterpolator());
10565 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10566 mFadeIn = fadeIn;
10567 }
10568
10569 @Override
10570 protected void applyTransformation(float interpolatedTime, Transformation t) {
10571 float x = interpolatedTime;
10572 if (!mFadeIn) {
10573 x = 1.0f - x; // reverse the interpolation for fade out
10574 }
10575 if (x < 0.5) {
10576 // move the window out of the screen.
10577 t.getMatrix().setTranslate(mWidth, 0);
10578 } else {
10579 t.getMatrix().setTranslate(0, 0);// show
10580 t.setAlpha((x - 0.5f) * 2);
10581 }
10582 }
10583
10584 @Override
10585 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10586 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10587 mWidth = width;
10588 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010589
10590 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010591 public int getZAdjustment() {
10592 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010593 }
10594 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010595}