blob: b6a090f734256bb77d1e4ccacefdc1b24a625e23 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
21import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070022import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
24import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -070025import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
27import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
28import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070029import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
31import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
33import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
34import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
35import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070037import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
39import com.android.internal.app.IBatteryStats;
40import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080041import com.android.internal.policy.impl.PhoneWindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import com.android.internal.view.IInputContext;
43import com.android.internal.view.IInputMethodClient;
44import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080045import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import com.android.server.am.BatteryStatsService;
47
48import android.Manifest;
49import android.app.ActivityManagerNative;
50import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070051import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070052import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.Intent;
55import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.content.pm.ActivityInfo;
57import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070058import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070060import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070062import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.graphics.PixelFormat;
64import android.graphics.Rect;
65import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Typeface;
67import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.os.BatteryStats;
69import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070070import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.Debug;
72import android.os.Handler;
73import android.os.IBinder;
74import android.os.LocalPowerManager;
75import android.os.Looper;
76import android.os.Message;
77import android.os.Parcel;
78import android.os.ParcelFileDescriptor;
79import android.os.Power;
80import android.os.PowerManager;
81import android.os.Process;
82import android.os.RemoteException;
83import android.os.ServiceManager;
84import android.os.SystemClock;
85import android.os.SystemProperties;
86import android.os.TokenWatcher;
87import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070088import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070090import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080091import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070093import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094import android.view.Display;
95import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -070096import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.view.IApplicationToken;
98import android.view.IOnKeyguardExitResult;
99import android.view.IRotationWatcher;
100import android.view.IWindow;
101import android.view.IWindowManager;
102import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700103import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700104import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700105import android.view.InputEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106import android.view.KeyEvent;
107import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108import android.view.Surface;
109import android.view.SurfaceSession;
110import android.view.View;
111import android.view.ViewTreeObserver;
112import android.view.WindowManager;
113import android.view.WindowManagerImpl;
114import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700115import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700117import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118import android.view.animation.Animation;
119import android.view.animation.AnimationUtils;
120import android.view.animation.Transformation;
121
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700122import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700124import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import java.io.File;
126import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700127import java.io.FileInputStream;
128import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129import java.io.IOException;
130import java.io.OutputStream;
131import java.io.OutputStreamWriter;
132import java.io.PrintWriter;
133import java.io.StringWriter;
134import java.net.Socket;
135import java.util.ArrayList;
136import java.util.HashMap;
137import java.util.HashSet;
138import java.util.Iterator;
139import java.util.List;
140
141/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700142public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700143 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 static final String TAG = "WindowManager";
145 static final boolean DEBUG = false;
146 static final boolean DEBUG_FOCUS = false;
147 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800148 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800149 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final boolean DEBUG_LAYERS = false;
151 static final boolean DEBUG_INPUT = false;
152 static final boolean DEBUG_INPUT_METHOD = false;
153 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700154 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700156 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_APP_TRANSITIONS = false;
158 static final boolean DEBUG_STARTING_WINDOW = false;
159 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700160 static final boolean DEBUG_WALLPAPER = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700162 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean PROFILE_ORIENTATION = false;
165 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700166 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 /** How much to multiply the policy's type layer, to reserve room
169 * for multiple windows of the same type and Z-ordering adjustment
170 * with TYPE_LAYER_OFFSET. */
171 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
174 * or below others in the same layer. */
175 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /** How much to increment the layer for each window, to reserve room
178 * for effect surfaces between them.
179 */
180 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 /** The maximum length we will accept for a loaded animation duration:
183 * this is 10 seconds.
184 */
185 static final int MAX_ANIMATION_DURATION = 10*1000;
186
187 /** Amount of time (in milliseconds) to animate the dim surface from one
188 * value to another, when no window animation is driving it.
189 */
190 static final int DEFAULT_DIM_DURATION = 200;
191
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700192 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
193 * compatible windows.
194 */
195 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 /** Adjustment to time to perform a dim, to make it more dramatic.
198 */
199 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700200
201 // Maximum number of milliseconds to wait for input event injection.
202 // FIXME is this value reasonable?
203 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700204
205 // Default input dispatching timeout in nanoseconds.
206 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 static final int UPDATE_FOCUS_NORMAL = 0;
209 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
210 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
211 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700214 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215
216 /**
217 * Condition waited on by {@link #reenableKeyguard} to know the call to
218 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500219 * This is set to true only if mKeyguardTokenWatcher.acquired() has
220 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500222 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
Jim Miller284b62e2010-06-08 14:27:42 -0700224 private static final int ALLOW_DISABLE_YES = 1;
225 private static final int ALLOW_DISABLE_NO = 0;
226 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
227 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
228
Mike Lockwood983ee092009-11-22 01:42:24 -0500229 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
230 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700232 if (shouldAllowDisableKeyguard()) {
233 mPolicy.enableKeyguard(false);
234 mKeyguardDisabled = true;
235 } else {
236 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 }
239 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700240 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500241 synchronized (mKeyguardTokenWatcher) {
242 mKeyguardDisabled = false;
243 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245 }
246 };
247
Jim Miller284b62e2010-06-08 14:27:42 -0700248 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
249 @Override
250 public void onReceive(Context context, Intent intent) {
251 mPolicy.enableKeyguard(true);
252 synchronized(mKeyguardTokenWatcher) {
253 // lazily evaluate this next time we're asked to disable keyguard
254 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
255 mKeyguardDisabled = false;
256 }
257 }
258 };
259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 final Context mContext;
261
262 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
267
268 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 /**
273 * All currently active sessions with clients.
274 */
275 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 /**
278 * Mapping from an IWindow IBinder to the server's Window object.
279 * This is also used as the lock for all of our state.
280 */
281 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
282
283 /**
284 * Mapping from a token IBinder to a WindowToken object.
285 */
286 final HashMap<IBinder, WindowToken> mTokenMap =
287 new HashMap<IBinder, WindowToken>();
288
289 /**
290 * The same tokens as mTokenMap, stored in a list for efficient iteration
291 * over them.
292 */
293 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 /**
296 * Window tokens that are in the process of exiting, but still
297 * on screen for animations.
298 */
299 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
300
301 /**
302 * Z-ordered (bottom-most first) list of all application tokens, for
303 * controlling the ordering of windows in different applications. This
304 * contains WindowToken objects.
305 */
306 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
307
308 /**
309 * Application tokens that are in the process of exiting, but still
310 * on screen for animations.
311 */
312 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
313
314 /**
315 * List of window tokens that have finished starting their application,
316 * and now need to have the policy remove their windows.
317 */
318 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
319
320 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700321 * This was the app token that was used to retrieve the last enter
322 * animation. It will be used for the next exit animation.
323 */
324 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800325
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700326 /**
327 * These were the layout params used to retrieve the last enter animation.
328 * They will be used for the next exit animation.
329 */
330 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800331
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700332 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 * Z-ordered (bottom-most first) list of all Window objects.
334 */
Jeff Browne33348b2010-07-15 23:54:05 -0700335 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
337 /**
338 * Windows that are being resized. Used so we can tell the client about
339 * the resize after closing the transaction in which we resized the
340 * underlying surface.
341 */
342 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
343
344 /**
345 * Windows whose animations have ended and now must be removed.
346 */
347 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
348
349 /**
350 * Windows whose surface should be destroyed.
351 */
352 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
353
354 /**
355 * Windows that have lost input focus and are waiting for the new
356 * focus window to be displayed before they are told about this.
357 */
358 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
359
360 /**
361 * This is set when we have run out of memory, and will either be an empty
362 * list or contain windows that need to be force removed.
363 */
364 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700369 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 Surface mBlurSurface;
371 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700372 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 final float[] mTmpFloats = new float[9];
377
378 boolean mSafeMode;
379 boolean mDisplayEnabled = false;
380 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700381 int mInitialDisplayWidth = 0;
382 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 int mRotation = 0;
384 int mRequestedRotation = 0;
385 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700386 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 ArrayList<IRotationWatcher> mRotationWatchers
388 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 boolean mLayoutNeeded = true;
391 boolean mAnimationPending = false;
392 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800393 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 boolean mWindowsFreezingScreen = false;
395 long mFreezeGcPending = 0;
396 int mAppsFreezingScreen = 0;
397
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800398 int mLayoutSeq = 0;
399
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800400 // State while inside of layoutAndPlaceSurfacesLocked().
401 boolean mFocusMayChange;
402
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800403 Configuration mCurConfiguration = new Configuration();
404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 // This is held as long as we have the screen frozen, to give us time to
406 // perform a rotation animation when turning off shows the lock screen which
407 // changes the orientation.
408 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 // State management of app transitions. When we are preparing for a
411 // transition, mNextAppTransition will be the kind of transition to
412 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
413 // mOpeningApps and mClosingApps are the lists of tokens that will be
414 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700415 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700416 String mNextAppTransitionPackage;
417 int mNextAppTransitionEnter;
418 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700420 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 boolean mAppTransitionTimeout = false;
422 boolean mStartingIconInTransition = false;
423 boolean mSkipAppTransitionAnimation = false;
424 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
425 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700426 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
427 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 H mH = new H();
432
433 WindowState mCurrentFocus = null;
434 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 // This just indicates the window the input method is on top of, not
437 // necessarily the window its input is going to.
438 WindowState mInputMethodTarget = null;
439 WindowState mUpcomingInputMethodTarget = null;
440 boolean mInputMethodTargetWaitingAnim;
441 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 WindowState mInputMethodWindow = null;
444 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
445
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700446 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800447
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700448 // If non-null, this is the currently visible window that is associated
449 // with the wallpaper.
450 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700451 // If non-null, we are in the middle of animating from one wallpaper target
452 // to another, and this is the lower one in Z-order.
453 WindowState mLowerWallpaperTarget = null;
454 // If non-null, we are in the middle of animating from one wallpaper target
455 // to another, and this is the higher one in Z-order.
456 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700457 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700458 float mLastWallpaperX = -1;
459 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800460 float mLastWallpaperXStep = -1;
461 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700462 // This is set when we are waiting for a wallpaper to tell us it is done
463 // changing its scroll position.
464 WindowState mWaitingOnWallpaper;
465 // The last time we had a timeout when waiting for a wallpaper.
466 long mLastWallpaperTimeoutTime;
467 // We give a wallpaper up to 150ms to finish scrolling.
468 static final long WALLPAPER_TIMEOUT = 150;
469 // Time we wait after a timeout before trying to wait again.
470 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 AppWindowToken mFocusedApp = null;
473
474 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 float mWindowAnimationScale = 1.0f;
477 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700478
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700479 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480
481 // Who is holding the screen on.
482 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700483 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700484
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700485 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 /**
488 * Whether the UI is currently running in touch mode (not showing
489 * navigational focus because the user is directly pressing the screen).
490 */
491 boolean mInTouchMode = false;
492
493 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700494 private ArrayList<WindowChangeListener> mWindowChangeListeners =
495 new ArrayList<WindowChangeListener>();
496 private boolean mWindowsChanged = false;
497
498 public interface WindowChangeListener {
499 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700500 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502
Dianne Hackbornc485a602009-03-24 22:39:49 -0700503 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700504 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700505
506 // The frame use to limit the size of the app running in compatibility mode.
507 Rect mCompatibleScreenFrame = new Rect();
508 // The surface used to fill the outer rim of the app running in compatibility mode.
509 Surface mBackgroundFillerSurface = null;
510 boolean mBackgroundFillerShown = false;
511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 public static WindowManagerService main(Context context,
513 PowerManagerService pm, boolean haveInputMethods) {
514 WMThread thr = new WMThread(context, pm, haveInputMethods);
515 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 synchronized (thr) {
518 while (thr.mService == null) {
519 try {
520 thr.wait();
521 } catch (InterruptedException e) {
522 }
523 }
524 }
Romain Guy06882f82009-06-10 13:36:04 -0700525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 return thr.mService;
527 }
Romain Guy06882f82009-06-10 13:36:04 -0700528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 static class WMThread extends Thread {
530 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 private final Context mContext;
533 private final PowerManagerService mPM;
534 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 public WMThread(Context context, PowerManagerService pm,
537 boolean haveInputMethods) {
538 super("WindowManager");
539 mContext = context;
540 mPM = pm;
541 mHaveInputMethods = haveInputMethods;
542 }
Romain Guy06882f82009-06-10 13:36:04 -0700543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 public void run() {
545 Looper.prepare();
546 WindowManagerService s = new WindowManagerService(mContext, mPM,
547 mHaveInputMethods);
548 android.os.Process.setThreadPriority(
549 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700550 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 synchronized (this) {
553 mService = s;
554 notifyAll();
555 }
Romain Guy06882f82009-06-10 13:36:04 -0700556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 Looper.loop();
558 }
559 }
560
561 static class PolicyThread extends Thread {
562 private final WindowManagerPolicy mPolicy;
563 private final WindowManagerService mService;
564 private final Context mContext;
565 private final PowerManagerService mPM;
566 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 public PolicyThread(WindowManagerPolicy policy,
569 WindowManagerService service, Context context,
570 PowerManagerService pm) {
571 super("WindowManagerPolicy");
572 mPolicy = policy;
573 mService = service;
574 mContext = context;
575 mPM = pm;
576 }
Romain Guy06882f82009-06-10 13:36:04 -0700577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 public void run() {
579 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800580 WindowManagerPolicyThread.set(this, Looper.myLooper());
581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800583 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 android.os.Process.setThreadPriority(
585 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700586 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 synchronized (this) {
590 mRunning = true;
591 notifyAll();
592 }
Romain Guy06882f82009-06-10 13:36:04 -0700593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 Looper.loop();
595 }
596 }
597
598 private WindowManagerService(Context context, PowerManagerService pm,
599 boolean haveInputMethods) {
600 mContext = context;
601 mHaveInputMethods = haveInputMethods;
602 mLimitedAlphaCompositing = context.getResources().getBoolean(
603 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 mPowerManager = pm;
606 mPowerManager.setPolicy(mPolicy);
607 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
608 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
609 "SCREEN_FROZEN");
610 mScreenFrozenLock.setReferenceCounted(false);
611
612 mActivityManager = ActivityManagerNative.getDefault();
613 mBatteryStats = BatteryStatsService.getService();
614
615 // Get persisted window scale setting
616 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
617 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
618 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
619 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700620
Jim Miller284b62e2010-06-08 14:27:42 -0700621 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
622 IntentFilter filter = new IntentFilter();
623 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
624 mContext.registerReceiver(mBroadcastReceiver, filter);
625
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700626 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
627 "KEEP_SCREEN_ON_FLAG");
628 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629
Jeff Browne33348b2010-07-15 23:54:05 -0700630 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
633 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 synchronized (thr) {
636 while (!thr.mRunning) {
637 try {
638 thr.wait();
639 } catch (InterruptedException e) {
640 }
641 }
642 }
Romain Guy06882f82009-06-10 13:36:04 -0700643
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700644 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 // Add ourself to the Watchdog monitors.
647 Watchdog.getInstance().addMonitor(this);
648 }
649
650 @Override
651 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
652 throws RemoteException {
653 try {
654 return super.onTransact(code, data, reply, flags);
655 } catch (RuntimeException e) {
656 // The window manager only throws security exceptions, so let's
657 // log all others.
658 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800659 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 }
661 throw e;
662 }
663 }
664
Jeff Browne33348b2010-07-15 23:54:05 -0700665 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800667 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 TAG, "Adding window " + window + " at "
669 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
670 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700671 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 }
673
Jeff Browne33348b2010-07-15 23:54:05 -0700674 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800676 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 TAG, "Adding window " + window + " at "
678 + i + " of " + mWindows.size() + " (before " + pos + ")");
679 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700680 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 }
682
683 //This method finds out the index of a window that has the same app token as
684 //win. used for z ordering the windows in mWindows
685 private int findIdxBasedOnAppTokens(WindowState win) {
686 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -0700687 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 int jmax = localmWindows.size();
689 if(jmax == 0) {
690 return -1;
691 }
692 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700693 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 if(wentry.mAppToken == win.mAppToken) {
695 return j;
696 }
697 }
698 return -1;
699 }
Romain Guy06882f82009-06-10 13:36:04 -0700700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
702 final IWindow client = win.mClient;
703 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -0700704 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -0700705
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706 final int N = localmWindows.size();
707 final WindowState attached = win.mAttachedWindow;
708 int i;
709 if (attached == null) {
710 int tokenWindowsPos = token.windows.size();
711 if (token.appWindowToken != null) {
712 int index = tokenWindowsPos-1;
713 if (index >= 0) {
714 // If this application has existing windows, we
715 // simply place the new window on top of them... but
716 // keep the starting window on top.
717 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
718 // Base windows go behind everything else.
719 placeWindowBefore(token.windows.get(0), win);
720 tokenWindowsPos = 0;
721 } else {
722 AppWindowToken atoken = win.mAppToken;
723 if (atoken != null &&
724 token.windows.get(index) == atoken.startingWindow) {
725 placeWindowBefore(token.windows.get(index), win);
726 tokenWindowsPos--;
727 } else {
728 int newIdx = findIdxBasedOnAppTokens(win);
729 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -0700730 //there is a window above this one associated with the same
731 //apptoken note that the window could be a floating window
732 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800734 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700735 TAG, "Adding window " + win + " at "
736 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700738 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -0700739 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 }
741 }
742 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800743 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 TAG, "Figuring out where to add app window "
745 + client.asBinder() + " (token=" + token + ")");
746 // Figure out where the window should go, based on the
747 // order of applications.
748 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -0700749 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 for (i=NA-1; i>=0; i--) {
751 AppWindowToken t = mAppTokens.get(i);
752 if (t == token) {
753 i--;
754 break;
755 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800756
Dianne Hackborna8f60182009-09-01 19:01:50 -0700757 // We haven't reached the token yet; if this token
758 // is not going to the bottom and has windows, we can
759 // use it as an anchor for when we do reach the token.
760 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 pos = t.windows.get(0);
762 }
763 }
764 // We now know the index into the apps. If we found
765 // an app window above, that gives us the position; else
766 // we need to look some more.
767 if (pos != null) {
768 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -0700769 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 if (atoken != null) {
771 final int NC = atoken.windows.size();
772 if (NC > 0) {
773 WindowState bottom = atoken.windows.get(0);
774 if (bottom.mSubLayer < 0) {
775 pos = bottom;
776 }
777 }
778 }
779 placeWindowBefore(pos, win);
780 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700781 // Continue looking down until we find the first
782 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 while (i >= 0) {
784 AppWindowToken t = mAppTokens.get(i);
785 final int NW = t.windows.size();
786 if (NW > 0) {
787 pos = t.windows.get(NW-1);
788 break;
789 }
790 i--;
791 }
792 if (pos != null) {
793 // Move in front of any windows attached to this
794 // one.
Jeff Browne33348b2010-07-15 23:54:05 -0700795 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 if (atoken != null) {
797 final int NC = atoken.windows.size();
798 if (NC > 0) {
799 WindowState top = atoken.windows.get(NC-1);
800 if (top.mSubLayer >= 0) {
801 pos = top;
802 }
803 }
804 }
805 placeWindowAfter(pos, win);
806 } else {
807 // Just search for the start of this layer.
808 final int myLayer = win.mBaseLayer;
809 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -0700810 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 if (w.mBaseLayer > myLayer) {
812 break;
813 }
814 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800815 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700816 TAG, "Adding window " + win + " at "
817 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700819 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 }
821 }
822 }
823 } else {
824 // Figure out where window should go, based on layer.
825 final int myLayer = win.mBaseLayer;
826 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -0700827 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 i++;
829 break;
830 }
831 }
832 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800833 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700834 TAG, "Adding window " + win + " at "
835 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700837 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 }
839 if (addToToken) {
840 token.windows.add(tokenWindowsPos, win);
841 }
842
843 } else {
844 // Figure out this window's ordering relative to the window
845 // it is attached to.
846 final int NA = token.windows.size();
847 final int sublayer = win.mSubLayer;
848 int largestSublayer = Integer.MIN_VALUE;
849 WindowState windowWithLargestSublayer = null;
850 for (i=0; i<NA; i++) {
851 WindowState w = token.windows.get(i);
852 final int wSublayer = w.mSubLayer;
853 if (wSublayer >= largestSublayer) {
854 largestSublayer = wSublayer;
855 windowWithLargestSublayer = w;
856 }
857 if (sublayer < 0) {
858 // For negative sublayers, we go below all windows
859 // in the same sublayer.
860 if (wSublayer >= sublayer) {
861 if (addToToken) {
862 token.windows.add(i, win);
863 }
864 placeWindowBefore(
865 wSublayer >= 0 ? attached : w, win);
866 break;
867 }
868 } else {
869 // For positive sublayers, we go above all windows
870 // in the same sublayer.
871 if (wSublayer > sublayer) {
872 if (addToToken) {
873 token.windows.add(i, win);
874 }
875 placeWindowBefore(w, win);
876 break;
877 }
878 }
879 }
880 if (i >= NA) {
881 if (addToToken) {
882 token.windows.add(win);
883 }
884 if (sublayer < 0) {
885 placeWindowBefore(attached, win);
886 } else {
887 placeWindowAfter(largestSublayer >= 0
888 ? windowWithLargestSublayer
889 : attached,
890 win);
891 }
892 }
893 }
Romain Guy06882f82009-06-10 13:36:04 -0700894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 if (win.mAppToken != null && addToToken) {
896 win.mAppToken.allAppWindows.add(win);
897 }
898 }
Romain Guy06882f82009-06-10 13:36:04 -0700899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 static boolean canBeImeTarget(WindowState w) {
901 final int fl = w.mAttrs.flags
902 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
903 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
904 return w.isVisibleOrAdding();
905 }
906 return false;
907 }
Romain Guy06882f82009-06-10 13:36:04 -0700908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -0700910 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 final int N = localmWindows.size();
912 WindowState w = null;
913 int i = N;
914 while (i > 0) {
915 i--;
Jeff Browne33348b2010-07-15 23:54:05 -0700916 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -0700917
Joe Onorato8a9b2202010-02-26 18:56:32 -0800918 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 // + Integer.toHexString(w.mAttrs.flags));
920 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800921 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -0700922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 // Yet more tricksyness! If this window is a "starting"
924 // window, we do actually want to be on top of it, but
925 // it is not -really- where input will go. So if the caller
926 // is not actually looking to move the IME, look down below
927 // for a real window to target...
928 if (!willMove
929 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
930 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700931 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
933 i--;
934 w = wb;
935 }
936 }
937 break;
938 }
939 }
Romain Guy06882f82009-06-10 13:36:04 -0700940
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -0700942
Joe Onorato8a9b2202010-02-26 18:56:32 -0800943 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -0700945
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 if (willMove && w != null) {
947 final WindowState curTarget = mInputMethodTarget;
948 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 // Now some fun for dealing with window animations that
951 // modify the Z order. We need to look at all windows below
952 // the current target that are in this app, finding the highest
953 // visible one in layering.
954 AppWindowToken token = curTarget.mAppToken;
955 WindowState highestTarget = null;
956 int highestPos = 0;
957 if (token.animating || token.animation != null) {
958 int pos = 0;
959 pos = localmWindows.indexOf(curTarget);
960 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -0700961 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 if (win.mAppToken != token) {
963 break;
964 }
965 if (!win.mRemoved) {
966 if (highestTarget == null || win.mAnimLayer >
967 highestTarget.mAnimLayer) {
968 highestTarget = win;
969 highestPos = pos;
970 }
971 }
972 pos--;
973 }
974 }
Romain Guy06882f82009-06-10 13:36:04 -0700975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800977 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 + mNextAppTransition + " " + highestTarget
979 + " animating=" + highestTarget.isAnimating()
980 + " layer=" + highestTarget.mAnimLayer
981 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -0700982
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700983 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 // If we are currently setting up for an animation,
985 // hold everything until we can find out what will happen.
986 mInputMethodTargetWaitingAnim = true;
987 mInputMethodTarget = highestTarget;
988 return highestPos + 1;
989 } else if (highestTarget.isAnimating() &&
990 highestTarget.mAnimLayer > w.mAnimLayer) {
991 // If the window we are currently targeting is involved
992 // with an animation, and it is on top of the next target
993 // we will be over, then hold off on moving until
994 // that is done.
995 mInputMethodTarget = highestTarget;
996 return highestPos + 1;
997 }
998 }
999 }
1000 }
Romain Guy06882f82009-06-10 13:36:04 -07001001
Joe Onorato8a9b2202010-02-26 18:56:32 -08001002 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 if (w != null) {
1004 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001005 if (DEBUG_INPUT_METHOD) {
1006 RuntimeException e = null;
1007 if (!HIDE_STACK_CRAWLS) {
1008 e = new RuntimeException();
1009 e.fillInStackTrace();
1010 }
1011 Slog.w(TAG, "Moving IM target from "
1012 + mInputMethodTarget + " to " + w, e);
1013 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 mInputMethodTarget = w;
1015 if (w.mAppToken != null) {
1016 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1017 } else {
1018 setInputMethodAnimLayerAdjustment(0);
1019 }
1020 }
1021 return i+1;
1022 }
1023 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001024 if (DEBUG_INPUT_METHOD) {
1025 RuntimeException e = null;
1026 if (!HIDE_STACK_CRAWLS) {
1027 e = new RuntimeException();
1028 e.fillInStackTrace();
1029 }
1030 Slog.w(TAG, "Moving IM target from "
1031 + mInputMethodTarget + " to null", e);
1032 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033 mInputMethodTarget = null;
1034 setInputMethodAnimLayerAdjustment(0);
1035 }
1036 return -1;
1037 }
Romain Guy06882f82009-06-10 13:36:04 -07001038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 void addInputMethodWindowToListLocked(WindowState win) {
1040 int pos = findDesiredInputMethodWindowIndexLocked(true);
1041 if (pos >= 0) {
1042 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001043 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001044 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001046 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 moveInputMethodDialogsLocked(pos+1);
1048 return;
1049 }
1050 win.mTargetAppToken = null;
1051 addWindowToListInOrderLocked(win, true);
1052 moveInputMethodDialogsLocked(pos);
1053 }
Romain Guy06882f82009-06-10 13:36:04 -07001054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001056 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 mInputMethodAnimLayerAdjustment = adj;
1058 WindowState imw = mInputMethodWindow;
1059 if (imw != null) {
1060 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001061 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 + " anim layer: " + imw.mAnimLayer);
1063 int wi = imw.mChildWindows.size();
1064 while (wi > 0) {
1065 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001066 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 + " anim layer: " + cw.mAnimLayer);
1070 }
1071 }
1072 int di = mInputMethodDialogs.size();
1073 while (di > 0) {
1074 di --;
1075 imw = mInputMethodDialogs.get(di);
1076 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001077 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 + " anim layer: " + imw.mAnimLayer);
1079 }
1080 }
Romain Guy06882f82009-06-10 13:36:04 -07001081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1083 int wpos = mWindows.indexOf(win);
1084 if (wpos >= 0) {
1085 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001086 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001088 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 int NC = win.mChildWindows.size();
1090 while (NC > 0) {
1091 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001092 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 int cpos = mWindows.indexOf(cw);
1094 if (cpos >= 0) {
1095 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001096 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001097 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 mWindows.remove(cpos);
1099 }
1100 }
1101 }
1102 return interestingPos;
1103 }
Romain Guy06882f82009-06-10 13:36:04 -07001104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 private void reAddWindowToListInOrderLocked(WindowState win) {
1106 addWindowToListInOrderLocked(win, false);
1107 // This is a hack to get all of the child windows added as well
1108 // at the right position. Child windows should be rare and
1109 // this case should be rare, so it shouldn't be that big a deal.
1110 int wpos = mWindows.indexOf(win);
1111 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001112 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001113 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001115 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 reAddWindowLocked(wpos, win);
1117 }
1118 }
Romain Guy06882f82009-06-10 13:36:04 -07001119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 void logWindowList(String prefix) {
1121 int N = mWindows.size();
1122 while (N > 0) {
1123 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001124 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 }
1126 }
Romain Guy06882f82009-06-10 13:36:04 -07001127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 void moveInputMethodDialogsLocked(int pos) {
1129 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001132 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 for (int i=0; i<N; i++) {
1134 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1135 }
1136 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001137 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 logWindowList(" ");
1139 }
Romain Guy06882f82009-06-10 13:36:04 -07001140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 if (pos >= 0) {
1142 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1143 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001144 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 if (wp == mInputMethodWindow) {
1146 pos++;
1147 }
1148 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001149 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 for (int i=0; i<N; i++) {
1151 WindowState win = dialogs.get(i);
1152 win.mTargetAppToken = targetAppToken;
1153 pos = reAddWindowLocked(pos, win);
1154 }
1155 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001156 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 logWindowList(" ");
1158 }
1159 return;
1160 }
1161 for (int i=0; i<N; i++) {
1162 WindowState win = dialogs.get(i);
1163 win.mTargetAppToken = null;
1164 reAddWindowToListInOrderLocked(win);
1165 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001166 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 logWindowList(" ");
1168 }
1169 }
1170 }
Romain Guy06882f82009-06-10 13:36:04 -07001171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1173 final WindowState imWin = mInputMethodWindow;
1174 final int DN = mInputMethodDialogs.size();
1175 if (imWin == null && DN == 0) {
1176 return false;
1177 }
Romain Guy06882f82009-06-10 13:36:04 -07001178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1180 if (imPos >= 0) {
1181 // In this case, the input method windows are to be placed
1182 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 // First check to see if the input method windows are already
1185 // located here, and contiguous.
1186 final int N = mWindows.size();
1187 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001188 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 // Figure out the actual input method window that should be
1191 // at the bottom of their stack.
1192 WindowState baseImWin = imWin != null
1193 ? imWin : mInputMethodDialogs.get(0);
1194 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001195 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 if (cw.mSubLayer < 0) baseImWin = cw;
1197 }
Romain Guy06882f82009-06-10 13:36:04 -07001198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 if (firstImWin == baseImWin) {
1200 // The windows haven't moved... but are they still contiguous?
1201 // First find the top IM window.
1202 int pos = imPos+1;
1203 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001204 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 break;
1206 }
1207 pos++;
1208 }
1209 pos++;
1210 // Now there should be no more input method windows above.
1211 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001212 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 break;
1214 }
1215 pos++;
1216 }
1217 if (pos >= N) {
1218 // All is good!
1219 return false;
1220 }
1221 }
Romain Guy06882f82009-06-10 13:36:04 -07001222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 if (imWin != null) {
1224 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001225 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 logWindowList(" ");
1227 }
1228 imPos = tmpRemoveWindowLocked(imPos, imWin);
1229 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001230 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 logWindowList(" ");
1232 }
1233 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1234 reAddWindowLocked(imPos, imWin);
1235 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001236 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 logWindowList(" ");
1238 }
1239 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1240 } else {
1241 moveInputMethodDialogsLocked(imPos);
1242 }
Romain Guy06882f82009-06-10 13:36:04 -07001243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 } else {
1245 // In this case, the input method windows go in a fixed layer,
1246 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001249 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 tmpRemoveWindowLocked(0, imWin);
1251 imWin.mTargetAppToken = null;
1252 reAddWindowToListInOrderLocked(imWin);
1253 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001254 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 logWindowList(" ");
1256 }
1257 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1258 } else {
1259 moveInputMethodDialogsLocked(-1);;
1260 }
Romain Guy06882f82009-06-10 13:36:04 -07001261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 }
Romain Guy06882f82009-06-10 13:36:04 -07001263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001264 if (needAssignLayers) {
1265 assignLayersLocked();
1266 }
Romain Guy06882f82009-06-10 13:36:04 -07001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 return true;
1269 }
Romain Guy06882f82009-06-10 13:36:04 -07001270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001271 void adjustInputMethodDialogsLocked() {
1272 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1273 }
Romain Guy06882f82009-06-10 13:36:04 -07001274
Dianne Hackborn25994b42009-09-04 14:21:19 -07001275 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001276 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001277 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1278 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1279 ? wallpaperTarget.mAppToken.animation : null)
1280 + " upper=" + mUpperWallpaperTarget
1281 + " lower=" + mLowerWallpaperTarget);
1282 return (wallpaperTarget != null
1283 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1284 && wallpaperTarget.mAppToken.animation != null)))
1285 || mUpperWallpaperTarget != null
1286 || mLowerWallpaperTarget != null;
1287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001288
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001289 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1290 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001291
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001292 int adjustWallpaperWindowsLocked() {
1293 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001294
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001295 final int dw = mDisplay.getWidth();
1296 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001297
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001298 // First find top-most window that has asked to be on top of the
1299 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001300 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001301 int N = localmWindows.size();
1302 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001303 WindowState foundW = null;
1304 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001305 WindowState topCurW = null;
1306 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001307 int i = N;
1308 while (i > 0) {
1309 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001310 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001311 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1312 if (topCurW == null) {
1313 topCurW = w;
1314 topCurI = i;
1315 }
1316 continue;
1317 }
1318 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001319 if (w.mAppToken != null) {
1320 // If this window's app token is hidden and not animating,
1321 // it is of no interest to us.
1322 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001323 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001324 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001325 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001326 continue;
1327 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001328 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001329 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001330 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1331 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001332 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001333 && (mWallpaperTarget == w
1334 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001335 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001336 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001337 foundW = w;
1338 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001339 if (w == mWallpaperTarget && ((w.mAppToken != null
1340 && w.mAppToken.animation != null)
1341 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001342 // The current wallpaper target is animating, so we'll
1343 // look behind it for another possible target and figure
1344 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001345 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001346 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001347 continue;
1348 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001349 break;
1350 }
1351 }
1352
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001353 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001354 // If we are currently waiting for an app transition, and either
1355 // the current target or the next target are involved with it,
1356 // then hold off on doing anything with the wallpaper.
1357 // Note that we are checking here for just whether the target
1358 // is part of an app token... which is potentially overly aggressive
1359 // (the app token may not be involved in the transition), but good
1360 // enough (we'll just wait until whatever transition is pending
1361 // executes).
1362 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001363 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001364 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001365 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001366 }
1367 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001368 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001369 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001370 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001371 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001372 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001373
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001374 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001375 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001376 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001377 + " oldTarget: " + mWallpaperTarget);
1378 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001379
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001380 mLowerWallpaperTarget = null;
1381 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001382
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001383 WindowState oldW = mWallpaperTarget;
1384 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001385
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001386 // Now what is happening... if the current and new targets are
1387 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001388 if (foundW != null && oldW != null) {
1389 boolean oldAnim = oldW.mAnimation != null
1390 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1391 boolean foundAnim = foundW.mAnimation != null
1392 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001393 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001394 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001395 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001396 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001397 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001398 int oldI = localmWindows.indexOf(oldW);
1399 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001400 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001401 }
1402 if (oldI >= 0) {
1403 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001404 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001405 + "=" + oldW + "; new#" + foundI
1406 + "=" + foundW);
1407 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001408
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001409 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001410 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001411 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001412 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001413 }
1414 mWallpaperTarget = oldW;
1415 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001416
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001417 // Now set the upper and lower wallpaper targets
1418 // correctly, and make sure that we are positioning
1419 // the wallpaper below the lower.
1420 if (foundI > oldI) {
1421 // The new target is on top of the old one.
1422 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001423 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001424 }
1425 mUpperWallpaperTarget = foundW;
1426 mLowerWallpaperTarget = oldW;
1427 foundW = oldW;
1428 foundI = oldI;
1429 } else {
1430 // The new target is below the old one.
1431 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001432 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001433 }
1434 mUpperWallpaperTarget = oldW;
1435 mLowerWallpaperTarget = foundW;
1436 }
1437 }
1438 }
1439 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001440
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001441 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001442 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001443 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1444 || (mLowerWallpaperTarget.mAppToken != null
1445 && mLowerWallpaperTarget.mAppToken.animation != null);
1446 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1447 || (mUpperWallpaperTarget.mAppToken != null
1448 && mUpperWallpaperTarget.mAppToken.animation != null);
1449 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001450 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001452 }
1453 mLowerWallpaperTarget = null;
1454 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001455 }
1456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001457
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001458 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001459 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001460 // The window is visible to the compositor... but is it visible
1461 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001462 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001463 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001464
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001465 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001466 // its layer adjustment. Only do this if we are not transfering
1467 // between two wallpaper targets.
1468 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001469 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001470 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001471
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001472 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1473 * TYPE_LAYER_MULTIPLIER
1474 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001475
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001476 // Now w is the window we are supposed to be behind... but we
1477 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001478 // AND any starting window associated with it, AND below the
1479 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001480 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001481 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001482 if (wb.mBaseLayer < maxLayer &&
1483 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001484 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001485 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001486 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001487 // This window is not related to the previous one in any
1488 // interesting way, so stop here.
1489 break;
1490 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001491 foundW = wb;
1492 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001493 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001494 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001495 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001496 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001497
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001498 if (foundW == null && topCurW != null) {
1499 // There is no wallpaper target, so it goes at the bottom.
1500 // We will assume it is the same place as last time, if known.
1501 foundW = topCurW;
1502 foundI = topCurI+1;
1503 } else {
1504 // Okay i is the position immediately above the wallpaper. Look at
1505 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001506 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001508
Dianne Hackborn284ac932009-08-28 10:34:25 -07001509 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001510 if (mWallpaperTarget.mWallpaperX >= 0) {
1511 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001512 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001513 }
1514 if (mWallpaperTarget.mWallpaperY >= 0) {
1515 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001516 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001517 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001519
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001520 // Start stepping backwards from here, ensuring that our wallpaper windows
1521 // are correctly placed.
1522 int curTokenIndex = mWallpaperTokens.size();
1523 while (curTokenIndex > 0) {
1524 curTokenIndex--;
1525 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001526 if (token.hidden == visible) {
1527 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1528 token.hidden = !visible;
1529 // Need to do a layout to ensure the wallpaper now has the
1530 // correct size.
1531 mLayoutNeeded = true;
1532 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001533
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001534 int curWallpaperIndex = token.windows.size();
1535 while (curWallpaperIndex > 0) {
1536 curWallpaperIndex--;
1537 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001538
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001539 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001540 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001541 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001543 // First, make sure the client has the current visibility
1544 // state.
1545 if (wallpaper.mWallpaperVisible != visible) {
1546 wallpaper.mWallpaperVisible = visible;
1547 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001548 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001549 "Setting visibility of wallpaper " + wallpaper
1550 + ": " + visible);
1551 wallpaper.mClient.dispatchAppVisibility(visible);
1552 } catch (RemoteException e) {
1553 }
1554 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001555
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001556 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001557 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001558 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001559
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001560 // First, if this window is at the current index, then all
1561 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001562 if (wallpaper == foundW) {
1563 foundI--;
1564 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001565 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001566 continue;
1567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001568
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001569 // The window didn't match... the current wallpaper window,
1570 // wherever it is, is in the wrong place, so make sure it is
1571 // not in the list.
1572 int oldIndex = localmWindows.indexOf(wallpaper);
1573 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001574 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001575 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001576 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001577 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001578 if (oldIndex < foundI) {
1579 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001580 }
1581 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001582
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001583 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001584 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001585 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001586 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001587
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001588 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001589 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001590 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001591 }
1592 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001593
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001594 return changed;
1595 }
1596
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001597 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001598 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001599 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001600 mWallpaperAnimLayerAdjustment = adj;
1601 int curTokenIndex = mWallpaperTokens.size();
1602 while (curTokenIndex > 0) {
1603 curTokenIndex--;
1604 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1605 int curWallpaperIndex = token.windows.size();
1606 while (curWallpaperIndex > 0) {
1607 curWallpaperIndex--;
1608 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1609 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001610 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001611 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001612 }
1613 }
1614 }
1615
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001616 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1617 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001618 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001619 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001620 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001621 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001622 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1623 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1624 changed = wallpaperWin.mXOffset != offset;
1625 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001626 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001627 + wallpaperWin + " x: " + offset);
1628 wallpaperWin.mXOffset = offset;
1629 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001630 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001631 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001632 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001633 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001634 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001635
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001636 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001637 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001638 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1639 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1640 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001641 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001642 + wallpaperWin + " y: " + offset);
1643 changed = true;
1644 wallpaperWin.mYOffset = offset;
1645 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001646 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001647 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001648 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001649 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001650 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001651
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001652 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001653 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001654 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001655 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1656 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001657 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001658 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001659 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001660 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001661 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1662 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001663 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001664 if (mWaitingOnWallpaper != null) {
1665 long start = SystemClock.uptimeMillis();
1666 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
1667 < start) {
1668 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001669 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07001670 "Waiting for offset complete...");
1671 mWindowMap.wait(WALLPAPER_TIMEOUT);
1672 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001673 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001674 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07001675 if ((start+WALLPAPER_TIMEOUT)
1676 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001677 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07001678 + wallpaperWin);
1679 mLastWallpaperTimeoutTime = start;
1680 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001681 }
Dianne Hackborn75804932009-10-20 20:15:20 -07001682 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001683 }
1684 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001685 } catch (RemoteException e) {
1686 }
1687 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001688
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001689 return changed;
1690 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001691
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001692 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001693 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001694 if (mWaitingOnWallpaper != null &&
1695 mWaitingOnWallpaper.mClient.asBinder() == window) {
1696 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07001697 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001698 }
1699 }
1700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001701
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001702 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001703 final int dw = mDisplay.getWidth();
1704 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001705
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001706 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001707
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001708 WindowState target = mWallpaperTarget;
1709 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001710 if (target.mWallpaperX >= 0) {
1711 mLastWallpaperX = target.mWallpaperX;
1712 } else if (changingTarget.mWallpaperX >= 0) {
1713 mLastWallpaperX = changingTarget.mWallpaperX;
1714 }
1715 if (target.mWallpaperY >= 0) {
1716 mLastWallpaperY = target.mWallpaperY;
1717 } else if (changingTarget.mWallpaperY >= 0) {
1718 mLastWallpaperY = changingTarget.mWallpaperY;
1719 }
1720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001721
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001722 int curTokenIndex = mWallpaperTokens.size();
1723 while (curTokenIndex > 0) {
1724 curTokenIndex--;
1725 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1726 int curWallpaperIndex = token.windows.size();
1727 while (curWallpaperIndex > 0) {
1728 curWallpaperIndex--;
1729 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1730 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
1731 wallpaper.computeShownFrameLocked();
1732 changed = true;
1733 // We only want to be synchronous with one wallpaper.
1734 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001735 }
1736 }
1737 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001738
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001739 return changed;
1740 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001741
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001742 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07001743 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001744 final int dw = mDisplay.getWidth();
1745 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001746
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001747 int curTokenIndex = mWallpaperTokens.size();
1748 while (curTokenIndex > 0) {
1749 curTokenIndex--;
1750 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001751 if (token.hidden == visible) {
1752 token.hidden = !visible;
1753 // Need to do a layout to ensure the wallpaper now has the
1754 // correct size.
1755 mLayoutNeeded = true;
1756 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001757
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001758 int curWallpaperIndex = token.windows.size();
1759 while (curWallpaperIndex > 0) {
1760 curWallpaperIndex--;
1761 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1762 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001763 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001764 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001765
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001766 if (wallpaper.mWallpaperVisible != visible) {
1767 wallpaper.mWallpaperVisible = visible;
1768 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07001770 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001771 + ": " + visible);
1772 wallpaper.mClient.dispatchAppVisibility(visible);
1773 } catch (RemoteException e) {
1774 }
1775 }
1776 }
1777 }
1778 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08001779
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 public int addWindow(Session session, IWindow client,
1781 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001782 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 int res = mPolicy.checkAddPermission(attrs);
1784 if (res != WindowManagerImpl.ADD_OKAY) {
1785 return res;
1786 }
Romain Guy06882f82009-06-10 13:36:04 -07001787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 boolean reportNewConfig = false;
1789 WindowState attachedWindow = null;
1790 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07001791 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07001792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07001795 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 }
Romain Guy06882f82009-06-10 13:36:04 -07001797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001799 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 return WindowManagerImpl.ADD_DUPLICATE_ADD;
1801 }
1802
1803 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001804 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001806 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 + attrs.token + ". Aborting.");
1808 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1809 }
1810 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
1811 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001812 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 + attrs.token + ". Aborting.");
1814 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
1815 }
1816 }
1817
1818 boolean addToken = false;
1819 WindowToken token = mTokenMap.get(attrs.token);
1820 if (token == null) {
1821 if (attrs.type >= FIRST_APPLICATION_WINDOW
1822 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001823 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 + attrs.token + ". Aborting.");
1825 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1826 }
1827 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001828 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 + attrs.token + ". Aborting.");
1830 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1831 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001832 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001833 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001834 + attrs.token + ". Aborting.");
1835 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1836 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001837 token = new WindowToken(attrs.token, -1, false);
1838 addToken = true;
1839 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
1840 && attrs.type <= LAST_APPLICATION_WINDOW) {
1841 AppWindowToken atoken = token.appWindowToken;
1842 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001843 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844 + token + ". Aborting.");
1845 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
1846 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001847 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 + token + ". Aborting.");
1849 return WindowManagerImpl.ADD_APP_EXITING;
1850 }
1851 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
1852 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08001853 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 TAG, "**** NO NEED TO START: " + attrs.getTitle());
1855 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
1856 }
1857 } else if (attrs.type == TYPE_INPUT_METHOD) {
1858 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001859 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 + attrs.token + ". Aborting.");
1861 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1862 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001863 } else if (attrs.type == TYPE_WALLPAPER) {
1864 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001865 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001866 + attrs.token + ". Aborting.");
1867 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
1868 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001869 }
1870
1871 win = new WindowState(session, client, token,
1872 attachedWindow, attrs, viewVisibility);
1873 if (win.mDeathRecipient == null) {
1874 // Client has apparently died, so there is no reason to
1875 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001876 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 + " that is dead, aborting.");
1878 return WindowManagerImpl.ADD_APP_EXITING;
1879 }
1880
1881 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07001882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 res = mPolicy.prepareAddWindowLw(win, attrs);
1884 if (res != WindowManagerImpl.ADD_OKAY) {
1885 return res;
1886 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001887
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001888 if (outInputChannel != null) {
1889 String name = win.makeInputChannelName();
1890 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1891 win.mInputChannel = inputChannels[0];
1892 inputChannels[1].transferToBinderOutParameter(outInputChannel);
1893
1894 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896
1897 // From now on, no exceptions or errors allowed!
1898
1899 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07001900
Dianne Hackborn5132b372010-07-29 12:51:35 -07001901 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07001902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 if (addToken) {
1904 mTokenMap.put(attrs.token, token);
1905 mTokenList.add(token);
1906 }
1907 win.attach();
1908 mWindowMap.put(client.asBinder(), win);
1909
1910 if (attrs.type == TYPE_APPLICATION_STARTING &&
1911 token.appWindowToken != null) {
1912 token.appWindowToken.startingWindow = win;
1913 }
1914
1915 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07001916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 if (attrs.type == TYPE_INPUT_METHOD) {
1918 mInputMethodWindow = win;
1919 addInputMethodWindowToListLocked(win);
1920 imMayMove = false;
1921 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
1922 mInputMethodDialogs.add(win);
1923 addWindowToListInOrderLocked(win, true);
1924 adjustInputMethodDialogsLocked();
1925 imMayMove = false;
1926 } else {
1927 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001928 if (attrs.type == TYPE_WALLPAPER) {
1929 mLastWallpaperTimeoutTime = 0;
1930 adjustWallpaperWindowsLocked();
1931 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001932 adjustWallpaperWindowsLocked();
1933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 }
Romain Guy06882f82009-06-10 13:36:04 -07001935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07001937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07001939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 if (mInTouchMode) {
1941 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
1942 }
1943 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
1944 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
1945 }
Romain Guy06882f82009-06-10 13:36:04 -07001946
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001947 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07001949 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
1950 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 imMayMove = false;
1952 }
1953 }
Romain Guy06882f82009-06-10 13:36:04 -07001954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07001956 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 }
Romain Guy06882f82009-06-10 13:36:04 -07001958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 assignLayersLocked();
1960 // Don't do layout here, the window must call
1961 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07001962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 //dump();
1964
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001965 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07001966 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08001967 }
Jeff Brown349703e2010-06-22 01:27:15 -07001968
Joe Onorato8a9b2202010-02-26 18:56:32 -08001969 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 TAG, "New client " + client.asBinder()
1971 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001972
1973 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
1974 reportNewConfig = true;
1975 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 }
1977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 if (reportNewConfig) {
1979 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07001981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07001983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 return res;
1985 }
Romain Guy06882f82009-06-10 13:36:04 -07001986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 public void removeWindow(Session session, IWindow client) {
1988 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001989 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001990 if (win == null) {
1991 return;
1992 }
1993 removeWindowLocked(session, win);
1994 }
1995 }
Romain Guy06882f82009-06-10 13:36:04 -07001996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001997 public void removeWindowLocked(Session session, WindowState win) {
1998
Joe Onorato8a9b2202010-02-26 18:56:32 -08001999 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 TAG, "Remove " + win + " client="
2001 + Integer.toHexString(System.identityHashCode(
2002 win.mClient.asBinder()))
2003 + ", surface=" + win.mSurface);
2004
2005 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002006
2007 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002008
Joe Onorato8a9b2202010-02-26 18:56:32 -08002009 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2011 + " mExiting=" + win.mExiting
2012 + " isAnimating=" + win.isAnimating()
2013 + " app-animation="
2014 + (win.mAppToken != null ? win.mAppToken.animation : null)
2015 + " inPendingTransaction="
2016 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2017 + " mDisplayFrozen=" + mDisplayFrozen);
2018 // Visibility of the removed window. Will be used later to update orientation later on.
2019 boolean wasVisible = false;
2020 // First, see if we need to run an animation. If we do, we have
2021 // to hold off on removing the window until the animation is done.
2022 // If the display is frozen, just remove immediately, since the
2023 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002024 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 // If we are not currently running the exit animation, we
2026 // need to see about starting one.
2027 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2030 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2031 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2032 }
2033 // Try starting an animation.
2034 if (applyAnimationLocked(win, transit, false)) {
2035 win.mExiting = true;
2036 }
2037 }
2038 if (win.mExiting || win.isAnimating()) {
2039 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002040 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 win.mExiting = true;
2042 win.mRemoveOnExit = true;
2043 mLayoutNeeded = true;
2044 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2045 performLayoutAndPlaceSurfacesLocked();
2046 if (win.mAppToken != null) {
2047 win.mAppToken.updateReportedVisibilityLocked();
2048 }
2049 //dump();
2050 Binder.restoreCallingIdentity(origId);
2051 return;
2052 }
2053 }
2054
2055 removeWindowInnerLocked(session, win);
2056 // Removing a visible window will effect the computed orientation
2057 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002058 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002059 != mForcedAppOrientation
2060 && updateOrientationFromAppTokensLocked()) {
2061 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 }
2063 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2064 Binder.restoreCallingIdentity(origId);
2065 }
Romain Guy06882f82009-06-10 13:36:04 -07002066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002067 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 if (mInputMethodTarget == win) {
2071 moveInputMethodWindowsIfNeededLocked(false);
2072 }
Romain Guy06882f82009-06-10 13:36:04 -07002073
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002074 if (false) {
2075 RuntimeException e = new RuntimeException("here");
2076 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002077 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002078 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 mPolicy.removeWindowLw(win);
2081 win.removeLocked();
2082
2083 mWindowMap.remove(win.mClient.asBinder());
2084 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002085 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002086 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087
2088 if (mInputMethodWindow == win) {
2089 mInputMethodWindow = null;
2090 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2091 mInputMethodDialogs.remove(win);
2092 }
Romain Guy06882f82009-06-10 13:36:04 -07002093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 final WindowToken token = win.mToken;
2095 final AppWindowToken atoken = win.mAppToken;
2096 token.windows.remove(win);
2097 if (atoken != null) {
2098 atoken.allAppWindows.remove(win);
2099 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002100 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101 TAG, "**** Removing window " + win + ": count="
2102 + token.windows.size());
2103 if (token.windows.size() == 0) {
2104 if (!token.explicit) {
2105 mTokenMap.remove(token.token);
2106 mTokenList.remove(token);
2107 } else if (atoken != null) {
2108 atoken.firstWindowDrawn = false;
2109 }
2110 }
2111
2112 if (atoken != null) {
2113 if (atoken.startingWindow == win) {
2114 atoken.startingWindow = null;
2115 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2116 // If this is the last window and we had requested a starting
2117 // transition window, well there is no point now.
2118 atoken.startingData = null;
2119 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2120 // If this is the last window except for a starting transition
2121 // window, we need to get rid of the starting transition.
2122 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002123 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002124 + ": no more real windows");
2125 }
2126 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2127 mH.sendMessage(m);
2128 }
2129 }
Romain Guy06882f82009-06-10 13:36:04 -07002130
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002131 if (win.mAttrs.type == TYPE_WALLPAPER) {
2132 mLastWallpaperTimeoutTime = 0;
2133 adjustWallpaperWindowsLocked();
2134 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002135 adjustWallpaperWindowsLocked();
2136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 if (!mInLayout) {
2139 assignLayersLocked();
2140 mLayoutNeeded = true;
2141 performLayoutAndPlaceSurfacesLocked();
2142 if (win.mAppToken != null) {
2143 win.mAppToken.updateReportedVisibilityLocked();
2144 }
2145 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002146
2147 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 }
2149
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002150 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2151 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2152 + ": " + msg + " / " + w.mAttrs.getTitle();
2153 if (where != null) {
2154 Slog.i(TAG, str, where);
2155 } else {
2156 Slog.i(TAG, str);
2157 }
2158 }
2159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2161 long origId = Binder.clearCallingIdentity();
2162 try {
2163 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002164 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002166 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 Surface.openTransaction();
2168 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002169 if (SHOW_TRANSACTIONS) logSurface(w,
2170 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 w.mSurface.setTransparentRegionHint(region);
2172 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002173 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 Surface.closeTransaction();
2175 }
2176 }
2177 }
2178 } finally {
2179 Binder.restoreCallingIdentity(origId);
2180 }
2181 }
2182
2183 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002184 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 Rect visibleInsets) {
2186 long origId = Binder.clearCallingIdentity();
2187 try {
2188 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002189 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 if (w != null) {
2191 w.mGivenInsetsPending = false;
2192 w.mGivenContentInsets.set(contentInsets);
2193 w.mGivenVisibleInsets.set(visibleInsets);
2194 w.mTouchableInsets = touchableInsets;
2195 mLayoutNeeded = true;
2196 performLayoutAndPlaceSurfacesLocked();
2197 }
2198 }
2199 } finally {
2200 Binder.restoreCallingIdentity(origId);
2201 }
2202 }
Romain Guy06882f82009-06-10 13:36:04 -07002203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 public void getWindowDisplayFrame(Session session, IWindow client,
2205 Rect outDisplayFrame) {
2206 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002207 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 if (win == null) {
2209 outDisplayFrame.setEmpty();
2210 return;
2211 }
2212 outDisplayFrame.set(win.mDisplayFrame);
2213 }
2214 }
2215
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002216 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2217 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002218 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2219 window.mWallpaperX = x;
2220 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002221 window.mWallpaperXStep = xStep;
2222 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002223 if (updateWallpaperOffsetLocked(window, true)) {
2224 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002225 }
2226 }
2227 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002228
Dianne Hackborn75804932009-10-20 20:15:20 -07002229 void wallpaperCommandComplete(IBinder window, Bundle result) {
2230 synchronized (mWindowMap) {
2231 if (mWaitingOnWallpaper != null &&
2232 mWaitingOnWallpaper.mClient.asBinder() == window) {
2233 mWaitingOnWallpaper = null;
2234 mWindowMap.notifyAll();
2235 }
2236 }
2237 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002238
Dianne Hackborn75804932009-10-20 20:15:20 -07002239 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2240 String action, int x, int y, int z, Bundle extras, boolean sync) {
2241 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2242 || window == mUpperWallpaperTarget) {
2243 boolean doWait = sync;
2244 int curTokenIndex = mWallpaperTokens.size();
2245 while (curTokenIndex > 0) {
2246 curTokenIndex--;
2247 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2248 int curWallpaperIndex = token.windows.size();
2249 while (curWallpaperIndex > 0) {
2250 curWallpaperIndex--;
2251 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2252 try {
2253 wallpaper.mClient.dispatchWallpaperCommand(action,
2254 x, y, z, extras, sync);
2255 // We only want to be synchronous with one wallpaper.
2256 sync = false;
2257 } catch (RemoteException e) {
2258 }
2259 }
2260 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002261
Dianne Hackborn75804932009-10-20 20:15:20 -07002262 if (doWait) {
2263 // XXX Need to wait for result.
2264 }
2265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002266
Dianne Hackborn75804932009-10-20 20:15:20 -07002267 return null;
2268 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 public int relayoutWindow(Session session, IWindow client,
2271 WindowManager.LayoutParams attrs, int requestedWidth,
2272 int requestedHeight, int viewVisibility, boolean insetsPending,
2273 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002274 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 boolean displayed = false;
2276 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002277 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002281 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 if (win == null) {
2283 return 0;
2284 }
2285 win.mRequestedWidth = requestedWidth;
2286 win.mRequestedHeight = requestedHeight;
2287
2288 if (attrs != null) {
2289 mPolicy.adjustWindowParamsLw(attrs);
2290 }
Romain Guy06882f82009-06-10 13:36:04 -07002291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 int attrChanges = 0;
2293 int flagChanges = 0;
2294 if (attrs != null) {
2295 flagChanges = win.mAttrs.flags ^= attrs.flags;
2296 attrChanges = win.mAttrs.copyFrom(attrs);
2297 }
2298
Joe Onorato8a9b2202010-02-26 18:56:32 -08002299 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300
2301 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2302 win.mAlpha = attrs.alpha;
2303 }
2304
2305 final boolean scaledWindow =
2306 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2307
2308 if (scaledWindow) {
2309 // requested{Width|Height} Surface's physical size
2310 // attrs.{width|height} Size on screen
2311 win.mHScale = (attrs.width != requestedWidth) ?
2312 (attrs.width / (float)requestedWidth) : 1.0f;
2313 win.mVScale = (attrs.height != requestedHeight) ?
2314 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002315 } else {
2316 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 }
2318
2319 boolean imMayMove = (flagChanges&(
2320 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2321 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 boolean focusMayChange = win.mViewVisibility != viewVisibility
2324 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2325 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002326
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002327 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2328 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 win.mRelayoutCalled = true;
2331 final int oldVisibility = win.mViewVisibility;
2332 win.mViewVisibility = viewVisibility;
2333 if (viewVisibility == View.VISIBLE &&
2334 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2335 displayed = !win.isVisibleLw();
2336 if (win.mExiting) {
2337 win.mExiting = false;
2338 win.mAnimation = null;
2339 }
2340 if (win.mDestroying) {
2341 win.mDestroying = false;
2342 mDestroySurface.remove(win);
2343 }
2344 if (oldVisibility == View.GONE) {
2345 win.mEnterAnimationPending = true;
2346 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002347 if (displayed) {
2348 if (win.mSurface != null && !win.mDrawPending
2349 && !win.mCommitDrawPending && !mDisplayFrozen
2350 && mPolicy.isScreenOn()) {
2351 applyEnterAnimationLocked(win);
2352 }
2353 if ((win.mAttrs.flags
2354 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2355 if (DEBUG_VISIBILITY) Slog.v(TAG,
2356 "Relayout window turning screen on: " + win);
2357 win.mTurnOnScreen = true;
2358 }
2359 int diff = 0;
2360 if (win.mConfiguration != mCurConfiguration
2361 && (win.mConfiguration == null
2362 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2363 win.mConfiguration = mCurConfiguration;
2364 if (DEBUG_CONFIGURATION) {
2365 Slog.i(TAG, "Window " + win + " visible with new config: "
2366 + win.mConfiguration + " / 0x"
2367 + Integer.toHexString(diff));
2368 }
2369 outConfig.setTo(mCurConfiguration);
2370 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2373 // To change the format, we need to re-build the surface.
2374 win.destroySurfaceLocked();
2375 displayed = true;
2376 }
2377 try {
2378 Surface surface = win.createSurfaceLocked();
2379 if (surface != null) {
2380 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002381 win.mReportDestroySurface = false;
2382 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002383 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002384 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002386 // For some reason there isn't a surface. Clear the
2387 // caller's object so they see the same state.
2388 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 }
2390 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002391 mInputMonitor.updateInputWindowsLw();
2392
Joe Onorato8a9b2202010-02-26 18:56:32 -08002393 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002394 + client + " (" + win.mAttrs.getTitle() + ")",
2395 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 Binder.restoreCallingIdentity(origId);
2397 return 0;
2398 }
2399 if (displayed) {
2400 focusMayChange = true;
2401 }
2402 if (win.mAttrs.type == TYPE_INPUT_METHOD
2403 && mInputMethodWindow == null) {
2404 mInputMethodWindow = win;
2405 imMayMove = true;
2406 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002407 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2408 && win.mAppToken != null
2409 && win.mAppToken.startingWindow != null) {
2410 // Special handling of starting window over the base
2411 // window of the app: propagate lock screen flags to it,
2412 // to provide the correct semantics while starting.
2413 final int mask =
2414 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002415 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2416 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002417 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2418 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2419 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 } else {
2421 win.mEnterAnimationPending = false;
2422 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002423 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002424 + ": mExiting=" + win.mExiting
2425 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 // If we are not currently running the exit animation, we
2427 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002428 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 // Try starting an animation; if there isn't one, we
2430 // can destroy the surface right away.
2431 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2432 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2433 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2434 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002435 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002437 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 } else if (win.isAnimating()) {
2440 // Currently in a hide animation... turn this into
2441 // an exit.
2442 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002443 } else if (win == mWallpaperTarget) {
2444 // If the wallpaper is currently behind this
2445 // window, we need to change both of them inside
2446 // of a transaction to avoid artifacts.
2447 win.mExiting = true;
2448 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 } else {
2450 if (mInputMethodWindow == win) {
2451 mInputMethodWindow = null;
2452 }
2453 win.destroySurfaceLocked();
2454 }
2455 }
2456 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002457
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002458 if (win.mSurface == null || (win.getAttrs().flags
2459 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2460 || win.mSurfacePendingDestroy) {
2461 // We are being called from a local process, which
2462 // means outSurface holds its current surface. Ensure the
2463 // surface object is cleared, but we don't want it actually
2464 // destroyed at this point.
2465 win.mSurfacePendingDestroy = false;
2466 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002467 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002468 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002469 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002470 "Keeping surface, will report destroy: " + win);
2471 win.mReportDestroySurface = true;
2472 outSurface.copyFrom(win.mSurface);
2473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 }
2475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 if (focusMayChange) {
2477 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2478 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 imMayMove = false;
2480 }
2481 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2482 }
Romain Guy06882f82009-06-10 13:36:04 -07002483
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002484 // updateFocusedWindowLocked() already assigned layers so we only need to
2485 // reassign them at this point if the IM window state gets shuffled
2486 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002489 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2490 // Little hack here -- we -should- be able to rely on the
2491 // function to return true if the IME has moved and needs
2492 // its layer recomputed. However, if the IME was hidden
2493 // and isn't actually moved in the list, its layer may be
2494 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 assignLayers = true;
2496 }
2497 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002498 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002499 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002500 assignLayers = true;
2501 }
2502 }
Romain Guy06882f82009-06-10 13:36:04 -07002503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 mLayoutNeeded = true;
2505 win.mGivenInsetsPending = insetsPending;
2506 if (assignLayers) {
2507 assignLayersLocked();
2508 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002509 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002511 if (displayed && win.mIsWallpaper) {
2512 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002513 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002514 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 if (win.mAppToken != null) {
2516 win.mAppToken.updateReportedVisibilityLocked();
2517 }
2518 outFrame.set(win.mFrame);
2519 outContentInsets.set(win.mContentInsets);
2520 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002521 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002523 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 + ", requestedHeight=" + requestedHeight
2525 + ", viewVisibility=" + viewVisibility
2526 + "\nRelayout returning frame=" + outFrame
2527 + ", surface=" + outSurface);
2528
Joe Onorato8a9b2202010-02-26 18:56:32 -08002529 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2531
2532 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002533
2534 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 }
2536
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002537 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 sendNewConfiguration();
2539 }
Romain Guy06882f82009-06-10 13:36:04 -07002540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2544 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2545 }
2546
2547 public void finishDrawingWindow(Session session, IWindow client) {
2548 final long origId = Binder.clearCallingIdentity();
2549 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002550 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002552 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2553 adjustWallpaperWindowsLocked();
2554 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 mLayoutNeeded = true;
2556 performLayoutAndPlaceSurfacesLocked();
2557 }
2558 }
2559 Binder.restoreCallingIdentity(origId);
2560 }
2561
2562 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002563 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 + (lp != null ? lp.packageName : null)
2565 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2566 if (lp != null && lp.windowAnimations != 0) {
2567 // If this is a system resource, don't try to load it from the
2568 // application resources. It is nice to avoid loading application
2569 // resources if we can.
2570 String packageName = lp.packageName != null ? lp.packageName : "android";
2571 int resId = lp.windowAnimations;
2572 if ((resId&0xFF000000) == 0x01000000) {
2573 packageName = "android";
2574 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002575 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 + packageName);
2577 return AttributeCache.instance().get(packageName, resId,
2578 com.android.internal.R.styleable.WindowAnimation);
2579 }
2580 return null;
2581 }
Romain Guy06882f82009-06-10 13:36:04 -07002582
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002583 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002584 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002585 + packageName + " resId=0x" + Integer.toHexString(resId));
2586 if (packageName != null) {
2587 if ((resId&0xFF000000) == 0x01000000) {
2588 packageName = "android";
2589 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002590 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002591 + packageName);
2592 return AttributeCache.instance().get(packageName, resId,
2593 com.android.internal.R.styleable.WindowAnimation);
2594 }
2595 return null;
2596 }
2597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 private void applyEnterAnimationLocked(WindowState win) {
2599 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2600 if (win.mEnterAnimationPending) {
2601 win.mEnterAnimationPending = false;
2602 transit = WindowManagerPolicy.TRANSIT_ENTER;
2603 }
2604
2605 applyAnimationLocked(win, transit, true);
2606 }
2607
2608 private boolean applyAnimationLocked(WindowState win,
2609 int transit, boolean isEntrance) {
2610 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2611 // If we are trying to apply an animation, but already running
2612 // an animation of the same type, then just leave that one alone.
2613 return true;
2614 }
Romain Guy06882f82009-06-10 13:36:04 -07002615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002616 // Only apply an animation if the display isn't frozen. If it is
2617 // frozen, there is no reason to animate and it can cause strange
2618 // artifacts when we unfreeze the display if some different animation
2619 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002620 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 int anim = mPolicy.selectAnimationLw(win, transit);
2622 int attr = -1;
2623 Animation a = null;
2624 if (anim != 0) {
2625 a = AnimationUtils.loadAnimation(mContext, anim);
2626 } else {
2627 switch (transit) {
2628 case WindowManagerPolicy.TRANSIT_ENTER:
2629 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2630 break;
2631 case WindowManagerPolicy.TRANSIT_EXIT:
2632 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2633 break;
2634 case WindowManagerPolicy.TRANSIT_SHOW:
2635 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2636 break;
2637 case WindowManagerPolicy.TRANSIT_HIDE:
2638 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2639 break;
2640 }
2641 if (attr >= 0) {
2642 a = loadAnimation(win.mAttrs, attr);
2643 }
2644 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002645 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2647 + " mAnimation=" + win.mAnimation
2648 + " isEntrance=" + isEntrance);
2649 if (a != null) {
2650 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002651 RuntimeException e = null;
2652 if (!HIDE_STACK_CRAWLS) {
2653 e = new RuntimeException();
2654 e.fillInStackTrace();
2655 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002656 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 }
2658 win.setAnimation(a);
2659 win.mAnimationIsEntrance = isEntrance;
2660 }
2661 } else {
2662 win.clearAnimation();
2663 }
2664
2665 return win.mAnimation != null;
2666 }
2667
2668 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
2669 int anim = 0;
2670 Context context = mContext;
2671 if (animAttr >= 0) {
2672 AttributeCache.Entry ent = getCachedAnimations(lp);
2673 if (ent != null) {
2674 context = ent.context;
2675 anim = ent.array.getResourceId(animAttr, 0);
2676 }
2677 }
2678 if (anim != 0) {
2679 return AnimationUtils.loadAnimation(context, anim);
2680 }
2681 return null;
2682 }
Romain Guy06882f82009-06-10 13:36:04 -07002683
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002684 private Animation loadAnimation(String packageName, int resId) {
2685 int anim = 0;
2686 Context context = mContext;
2687 if (resId >= 0) {
2688 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
2689 if (ent != null) {
2690 context = ent.context;
2691 anim = resId;
2692 }
2693 }
2694 if (anim != 0) {
2695 return AnimationUtils.loadAnimation(context, anim);
2696 }
2697 return null;
2698 }
2699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 private boolean applyAnimationLocked(AppWindowToken wtoken,
2701 WindowManager.LayoutParams lp, int transit, boolean enter) {
2702 // Only apply an animation if the display isn't frozen. If it is
2703 // frozen, there is no reason to animate and it can cause strange
2704 // artifacts when we unfreeze the display if some different animation
2705 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002706 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002707 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07002708 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002709 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002710 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002711 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002712 } else if (mNextAppTransitionPackage != null) {
2713 a = loadAnimation(mNextAppTransitionPackage, enter ?
2714 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002715 } else {
2716 int animAttr = 0;
2717 switch (transit) {
2718 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
2719 animAttr = enter
2720 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
2721 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
2722 break;
2723 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
2724 animAttr = enter
2725 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
2726 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
2727 break;
2728 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
2729 animAttr = enter
2730 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
2731 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
2732 break;
2733 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
2734 animAttr = enter
2735 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
2736 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
2737 break;
2738 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
2739 animAttr = enter
2740 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
2741 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
2742 break;
2743 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
2744 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07002745 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002746 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
2747 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002748 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002749 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002750 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
2751 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002752 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07002753 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002754 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07002755 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
2756 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
2757 break;
2758 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
2759 animAttr = enter
2760 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
2761 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
2762 break;
2763 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
2764 animAttr = enter
2765 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
2766 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07002767 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002768 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07002769 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002770 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07002771 + " anim=" + a
2772 + " animAttr=0x" + Integer.toHexString(animAttr)
2773 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 if (a != null) {
2776 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002777 RuntimeException e = null;
2778 if (!HIDE_STACK_CRAWLS) {
2779 e = new RuntimeException();
2780 e.fillInStackTrace();
2781 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002782 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 }
2784 wtoken.setAnimation(a);
2785 }
2786 } else {
2787 wtoken.clearAnimation();
2788 }
2789
2790 return wtoken.animation != null;
2791 }
2792
2793 // -------------------------------------------------------------
2794 // Application Window Tokens
2795 // -------------------------------------------------------------
2796
2797 public void validateAppTokens(List tokens) {
2798 int v = tokens.size()-1;
2799 int m = mAppTokens.size()-1;
2800 while (v >= 0 && m >= 0) {
2801 AppWindowToken wtoken = mAppTokens.get(m);
2802 if (wtoken.removed) {
2803 m--;
2804 continue;
2805 }
2806 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002807 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
2809 }
2810 v--;
2811 m--;
2812 }
2813 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002814 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 v--;
2816 }
2817 while (m >= 0) {
2818 AppWindowToken wtoken = mAppTokens.get(m);
2819 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002820 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 }
2822 m--;
2823 }
2824 }
2825
2826 boolean checkCallingPermission(String permission, String func) {
2827 // Quick check: if the calling permission is me, it's all okay.
2828 if (Binder.getCallingPid() == Process.myPid()) {
2829 return true;
2830 }
Romain Guy06882f82009-06-10 13:36:04 -07002831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 if (mContext.checkCallingPermission(permission)
2833 == PackageManager.PERMISSION_GRANTED) {
2834 return true;
2835 }
2836 String msg = "Permission Denial: " + func + " from pid="
2837 + Binder.getCallingPid()
2838 + ", uid=" + Binder.getCallingUid()
2839 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002840 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 return false;
2842 }
Romain Guy06882f82009-06-10 13:36:04 -07002843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 AppWindowToken findAppWindowToken(IBinder token) {
2845 WindowToken wtoken = mTokenMap.get(token);
2846 if (wtoken == null) {
2847 return null;
2848 }
2849 return wtoken.appWindowToken;
2850 }
Romain Guy06882f82009-06-10 13:36:04 -07002851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 public void addWindowToken(IBinder token, int type) {
2853 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2854 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002855 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 }
Romain Guy06882f82009-06-10 13:36:04 -07002857
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 synchronized(mWindowMap) {
2859 WindowToken wtoken = mTokenMap.get(token);
2860 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002861 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 return;
2863 }
2864 wtoken = new WindowToken(token, type, true);
2865 mTokenMap.put(token, wtoken);
2866 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002867 if (type == TYPE_WALLPAPER) {
2868 mWallpaperTokens.add(wtoken);
2869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 }
2871 }
Romain Guy06882f82009-06-10 13:36:04 -07002872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 public void removeWindowToken(IBinder token) {
2874 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2875 "removeWindowToken()")) {
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 }
2878
2879 final long origId = Binder.clearCallingIdentity();
2880 synchronized(mWindowMap) {
2881 WindowToken wtoken = mTokenMap.remove(token);
2882 mTokenList.remove(wtoken);
2883 if (wtoken != null) {
2884 boolean delayed = false;
2885 if (!wtoken.hidden) {
2886 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07002887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 final int N = wtoken.windows.size();
2889 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07002890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 for (int i=0; i<N; i++) {
2892 WindowState win = wtoken.windows.get(i);
2893
2894 if (win.isAnimating()) {
2895 delayed = true;
2896 }
Romain Guy06882f82009-06-10 13:36:04 -07002897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 if (win.isVisibleNow()) {
2899 applyAnimationLocked(win,
2900 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 changed = true;
2902 }
2903 }
2904
2905 if (changed) {
2906 mLayoutNeeded = true;
2907 performLayoutAndPlaceSurfacesLocked();
2908 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2909 }
Romain Guy06882f82009-06-10 13:36:04 -07002910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 if (delayed) {
2912 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002913 } else if (wtoken.windowType == TYPE_WALLPAPER) {
2914 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 }
2916 }
Romain Guy06882f82009-06-10 13:36:04 -07002917
Jeff Brownc5ed5912010-07-14 18:48:53 -07002918 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002920 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 }
2922 }
2923 Binder.restoreCallingIdentity(origId);
2924 }
2925
2926 public void addAppToken(int addPos, IApplicationToken token,
2927 int groupId, int requestedOrientation, boolean fullscreen) {
2928 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2929 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002930 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 }
Jeff Brown349703e2010-06-22 01:27:15 -07002932
2933 // Get the dispatching timeout here while we are not holding any locks so that it
2934 // can be cached by the AppWindowToken. The timeout value is used later by the
2935 // input dispatcher in code that does hold locks. If we did not cache the value
2936 // here we would run the chance of introducing a deadlock between the window manager
2937 // (which holds locks while updating the input dispatcher state) and the activity manager
2938 // (which holds locks while querying the application token).
2939 long inputDispatchingTimeoutNanos;
2940 try {
2941 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
2942 } catch (RemoteException ex) {
2943 Slog.w(TAG, "Could not get dispatching timeout.", ex);
2944 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
2945 }
Romain Guy06882f82009-06-10 13:36:04 -07002946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 synchronized(mWindowMap) {
2948 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
2949 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002950 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 return;
2952 }
2953 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07002954 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 wtoken.groupId = groupId;
2956 wtoken.appFullscreen = fullscreen;
2957 wtoken.requestedOrientation = requestedOrientation;
2958 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002959 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 mTokenMap.put(token.asBinder(), wtoken);
2961 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07002962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963 // Application tokens start out hidden.
2964 wtoken.hidden = true;
2965 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07002966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 //dump();
2968 }
2969 }
Romain Guy06882f82009-06-10 13:36:04 -07002970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 public void setAppGroupId(IBinder token, int groupId) {
2972 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
2973 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07002974 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 }
2976
2977 synchronized(mWindowMap) {
2978 AppWindowToken wtoken = findAppWindowToken(token);
2979 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002980 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 return;
2982 }
2983 wtoken.groupId = groupId;
2984 }
2985 }
Romain Guy06882f82009-06-10 13:36:04 -07002986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 public int getOrientationFromWindowsLocked() {
2988 int pos = mWindows.size() - 1;
2989 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07002990 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 pos--;
2992 if (wtoken.mAppToken != null) {
2993 // We hit an application window. so the orientation will be determined by the
2994 // app window. No point in continuing further.
2995 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
2996 }
Christopher Tateb696aee2010-04-02 19:08:30 -07002997 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 continue;
2999 }
3000 int req = wtoken.mAttrs.screenOrientation;
3001 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3002 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3003 continue;
3004 } else {
3005 return req;
3006 }
3007 }
3008 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3009 }
Romain Guy06882f82009-06-10 13:36:04 -07003010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003011 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003012 int pos = mAppTokens.size() - 1;
3013 int curGroup = 0;
3014 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3015 boolean findingBehind = false;
3016 boolean haveGroup = false;
3017 boolean lastFullscreen = false;
3018 while (pos >= 0) {
3019 AppWindowToken wtoken = mAppTokens.get(pos);
3020 pos--;
3021 // if we're about to tear down this window and not seek for
3022 // the behind activity, don't use it for orientation
3023 if (!findingBehind
3024 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3025 continue;
3026 }
3027
3028 if (!haveGroup) {
3029 // We ignore any hidden applications on the top.
3030 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003031 continue;
3032 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003033 haveGroup = true;
3034 curGroup = wtoken.groupId;
3035 lastOrientation = wtoken.requestedOrientation;
3036 } else if (curGroup != wtoken.groupId) {
3037 // If we have hit a new application group, and the bottom
3038 // of the previous group didn't explicitly say to use
3039 // the orientation behind it, and the last app was
3040 // full screen, then we'll stick with the
3041 // user's orientation.
3042 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3043 && lastFullscreen) {
3044 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003046 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003047 int or = wtoken.requestedOrientation;
3048 // If this application is fullscreen, and didn't explicitly say
3049 // to use the orientation behind it, then just take whatever
3050 // orientation it has and ignores whatever is under it.
3051 lastFullscreen = wtoken.appFullscreen;
3052 if (lastFullscreen
3053 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3054 return or;
3055 }
3056 // If this application has requested an explicit orientation,
3057 // then use it.
3058 if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
3059 or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
3060 or == ActivityInfo.SCREEN_ORIENTATION_SENSOR ||
3061 or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ||
3062 or == ActivityInfo.SCREEN_ORIENTATION_USER) {
3063 return or;
3064 }
3065 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3066 }
3067 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 }
Romain Guy06882f82009-06-10 13:36:04 -07003069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003071 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003072 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3073 "updateOrientationFromAppTokens()")) {
3074 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3075 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003076
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003077 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003079
3080 synchronized(mWindowMap) {
3081 if (updateOrientationFromAppTokensLocked()) {
3082 if (freezeThisOneIfNeeded != null) {
3083 AppWindowToken wtoken = findAppWindowToken(
3084 freezeThisOneIfNeeded);
3085 if (wtoken != null) {
3086 startAppFreezingScreenLocked(wtoken,
3087 ActivityInfo.CONFIG_ORIENTATION);
3088 }
3089 }
3090 config = computeNewConfigurationLocked();
3091
3092 } else if (currentConfig != null) {
3093 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003094 // state mismatches the activity manager's, update it,
3095 // disregarding font scale, which should remain set to
3096 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003097 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003098 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003099 if (computeNewConfigurationLocked(mTempConfiguration)) {
3100 if (currentConfig.diff(mTempConfiguration) != 0) {
3101 mWaitingForConfig = true;
3102 mLayoutNeeded = true;
3103 startFreezingDisplayLocked();
3104 config = new Configuration(mTempConfiguration);
3105 }
3106 }
3107 }
3108 }
3109
Dianne Hackborncfaef692009-06-15 14:24:44 -07003110 Binder.restoreCallingIdentity(ident);
3111 return config;
3112 }
3113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003115 * Determine the new desired orientation of the display, returning
3116 * a non-null new Configuration if it has changed from the current
3117 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3118 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3119 * SCREEN. This will typically be done for you if you call
3120 * sendNewConfiguration().
3121 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 * The orientation is computed from non-application windows first. If none of
3123 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003124 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3126 * android.os.IBinder)
3127 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003128 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003129 if (mDisplayFrozen) {
3130 // If the display is frozen, some activities may be in the middle
3131 // of restarting, and thus have removed their old window. If the
3132 // window has the flag to hide the lock screen, then the lock screen
3133 // can re-appear and inflict its own orientation on us. Keep the
3134 // orientation stable until this all settles down.
3135 return false;
3136 }
3137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 long ident = Binder.clearCallingIdentity();
3140 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003141 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 mForcedAppOrientation = req;
3145 //send a message to Policy indicating orientation change to take
3146 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003147 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003148 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3149 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3150 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 }
3152 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003153
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003154 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155 } finally {
3156 Binder.restoreCallingIdentity(ident);
3157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 }
Romain Guy06882f82009-06-10 13:36:04 -07003159
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003160 int computeForcedAppOrientationLocked() {
3161 int req = getOrientationFromWindowsLocked();
3162 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3163 req = getOrientationFromAppTokensLocked();
3164 }
3165 return req;
3166 }
Romain Guy06882f82009-06-10 13:36:04 -07003167
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003168 public void setNewConfiguration(Configuration config) {
3169 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3170 "setNewConfiguration()")) {
3171 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3172 }
3173
3174 synchronized(mWindowMap) {
3175 mCurConfiguration = new Configuration(config);
3176 mWaitingForConfig = false;
3177 performLayoutAndPlaceSurfacesLocked();
3178 }
3179 }
3180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3182 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3183 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003184 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 }
Romain Guy06882f82009-06-10 13:36:04 -07003186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 synchronized(mWindowMap) {
3188 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3189 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003190 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 return;
3192 }
Romain Guy06882f82009-06-10 13:36:04 -07003193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 wtoken.requestedOrientation = requestedOrientation;
3195 }
3196 }
Romain Guy06882f82009-06-10 13:36:04 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 public int getAppOrientation(IApplicationToken token) {
3199 synchronized(mWindowMap) {
3200 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3201 if (wtoken == null) {
3202 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3203 }
Romain Guy06882f82009-06-10 13:36:04 -07003204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003205 return wtoken.requestedOrientation;
3206 }
3207 }
Romain Guy06882f82009-06-10 13:36:04 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3210 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3211 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003212 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003213 }
3214
3215 synchronized(mWindowMap) {
3216 boolean changed = false;
3217 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003218 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 changed = mFocusedApp != null;
3220 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003221 if (changed) {
3222 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003223 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 } else {
3225 AppWindowToken newFocus = findAppWindowToken(token);
3226 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003227 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 return;
3229 }
3230 changed = mFocusedApp != newFocus;
3231 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003232 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003233 if (changed) {
3234 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 }
3237
3238 if (moveFocusNow && changed) {
3239 final long origId = Binder.clearCallingIdentity();
3240 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3241 Binder.restoreCallingIdentity(origId);
3242 }
3243 }
3244 }
3245
3246 public void prepareAppTransition(int transit) {
3247 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3248 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003249 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 }
Romain Guy06882f82009-06-10 13:36:04 -07003251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003253 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 TAG, "Prepare app transition: transit=" + transit
3255 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003256 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003257 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3258 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003260 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3261 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3262 // Opening a new task always supersedes a close for the anim.
3263 mNextAppTransition = transit;
3264 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3265 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3266 // Opening a new activity always supersedes a close for the anim.
3267 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 }
3269 mAppTransitionReady = false;
3270 mAppTransitionTimeout = false;
3271 mStartingIconInTransition = false;
3272 mSkipAppTransitionAnimation = false;
3273 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3274 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3275 5000);
3276 }
3277 }
3278 }
3279
3280 public int getPendingAppTransition() {
3281 return mNextAppTransition;
3282 }
Romain Guy06882f82009-06-10 13:36:04 -07003283
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003284 public void overridePendingAppTransition(String packageName,
3285 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003286 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003287 mNextAppTransitionPackage = packageName;
3288 mNextAppTransitionEnter = enterAnim;
3289 mNextAppTransitionExit = exitAnim;
3290 }
3291 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 public void executeAppTransition() {
3294 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3295 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003296 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 }
Romain Guy06882f82009-06-10 13:36:04 -07003298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003299 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003300 if (DEBUG_APP_TRANSITIONS) {
3301 RuntimeException e = new RuntimeException("here");
3302 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003303 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003304 + mNextAppTransition, e);
3305 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003306 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 mAppTransitionReady = true;
3308 final long origId = Binder.clearCallingIdentity();
3309 performLayoutAndPlaceSurfacesLocked();
3310 Binder.restoreCallingIdentity(origId);
3311 }
3312 }
3313 }
3314
3315 public void setAppStartingWindow(IBinder token, String pkg,
3316 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3317 IBinder transferFrom, boolean createIfNeeded) {
3318 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3319 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003320 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 }
3322
3323 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003324 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3326 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 AppWindowToken wtoken = findAppWindowToken(token);
3329 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003330 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331 return;
3332 }
3333
3334 // If the display is frozen, we won't do anything until the
3335 // actual window is displayed so there is no reason to put in
3336 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003337 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 return;
3339 }
Romain Guy06882f82009-06-10 13:36:04 -07003340
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003341 if (wtoken.startingData != null) {
3342 return;
3343 }
Romain Guy06882f82009-06-10 13:36:04 -07003344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 if (transferFrom != null) {
3346 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3347 if (ttoken != null) {
3348 WindowState startingWindow = ttoken.startingWindow;
3349 if (startingWindow != null) {
3350 if (mStartingIconInTransition) {
3351 // In this case, the starting icon has already
3352 // been displayed, so start letting windows get
3353 // shown immediately without any more transitions.
3354 mSkipAppTransitionAnimation = true;
3355 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003356 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 "Moving existing starting from " + ttoken
3358 + " to " + wtoken);
3359 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 // Transfer the starting window over to the new
3362 // token.
3363 wtoken.startingData = ttoken.startingData;
3364 wtoken.startingView = ttoken.startingView;
3365 wtoken.startingWindow = startingWindow;
3366 ttoken.startingData = null;
3367 ttoken.startingView = null;
3368 ttoken.startingWindow = null;
3369 ttoken.startingMoved = true;
3370 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003371 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003373 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003374 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003376 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377 ttoken.windows.remove(startingWindow);
3378 ttoken.allAppWindows.remove(startingWindow);
3379 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003380
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381 // Propagate other interesting state between the
3382 // tokens. If the old token is displayed, we should
3383 // immediately force the new one to be displayed. If
3384 // it is animating, we need to move that animation to
3385 // the new one.
3386 if (ttoken.allDrawn) {
3387 wtoken.allDrawn = true;
3388 }
3389 if (ttoken.firstWindowDrawn) {
3390 wtoken.firstWindowDrawn = true;
3391 }
3392 if (!ttoken.hidden) {
3393 wtoken.hidden = false;
3394 wtoken.hiddenRequested = false;
3395 wtoken.willBeHidden = false;
3396 }
3397 if (wtoken.clientHidden != ttoken.clientHidden) {
3398 wtoken.clientHidden = ttoken.clientHidden;
3399 wtoken.sendAppVisibilityToClients();
3400 }
3401 if (ttoken.animation != null) {
3402 wtoken.animation = ttoken.animation;
3403 wtoken.animating = ttoken.animating;
3404 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3405 ttoken.animation = null;
3406 ttoken.animLayerAdjustment = 0;
3407 wtoken.updateLayers();
3408 ttoken.updateLayers();
3409 }
Romain Guy06882f82009-06-10 13:36:04 -07003410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003411 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 mLayoutNeeded = true;
3413 performLayoutAndPlaceSurfacesLocked();
3414 Binder.restoreCallingIdentity(origId);
3415 return;
3416 } else if (ttoken.startingData != null) {
3417 // The previous app was getting ready to show a
3418 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003419 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 "Moving pending starting from " + ttoken
3421 + " to " + wtoken);
3422 wtoken.startingData = ttoken.startingData;
3423 ttoken.startingData = null;
3424 ttoken.startingMoved = true;
3425 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3426 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3427 // want to process the message ASAP, before any other queued
3428 // messages.
3429 mH.sendMessageAtFrontOfQueue(m);
3430 return;
3431 }
3432 }
3433 }
3434
3435 // There is no existing starting window, and the caller doesn't
3436 // want us to create one, so that's it!
3437 if (!createIfNeeded) {
3438 return;
3439 }
Romain Guy06882f82009-06-10 13:36:04 -07003440
Dianne Hackborn284ac932009-08-28 10:34:25 -07003441 // If this is a translucent or wallpaper window, then don't
3442 // show a starting window -- the current effect (a full-screen
3443 // opaque starting window that fades away to the real contents
3444 // when it is ready) does not work for this.
3445 if (theme != 0) {
3446 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3447 com.android.internal.R.styleable.Window);
3448 if (ent.array.getBoolean(
3449 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3450 return;
3451 }
3452 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003453 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3454 return;
3455 }
3456 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003457 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3458 return;
3459 }
3460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003462 mStartingIconInTransition = true;
3463 wtoken.startingData = new StartingData(
3464 pkg, theme, nonLocalizedLabel,
3465 labelRes, icon);
3466 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3467 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3468 // want to process the message ASAP, before any other queued
3469 // messages.
3470 mH.sendMessageAtFrontOfQueue(m);
3471 }
3472 }
3473
3474 public void setAppWillBeHidden(IBinder token) {
3475 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3476 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003477 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003478 }
3479
3480 AppWindowToken wtoken;
3481
3482 synchronized(mWindowMap) {
3483 wtoken = findAppWindowToken(token);
3484 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003485 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 -08003486 return;
3487 }
3488 wtoken.willBeHidden = true;
3489 }
3490 }
Romain Guy06882f82009-06-10 13:36:04 -07003491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3493 boolean visible, int transit, boolean performLayout) {
3494 boolean delayed = false;
3495
3496 if (wtoken.clientHidden == visible) {
3497 wtoken.clientHidden = !visible;
3498 wtoken.sendAppVisibilityToClients();
3499 }
Romain Guy06882f82009-06-10 13:36:04 -07003500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 wtoken.willBeHidden = false;
3502 if (wtoken.hidden == visible) {
3503 final int N = wtoken.allAppWindows.size();
3504 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003505 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3507 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003510
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003511 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 if (wtoken.animation == sDummyAnimation) {
3513 wtoken.animation = null;
3514 }
3515 applyAnimationLocked(wtoken, lp, transit, visible);
3516 changed = true;
3517 if (wtoken.animation != null) {
3518 delayed = runningAppAnimation = true;
3519 }
3520 }
Romain Guy06882f82009-06-10 13:36:04 -07003521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 for (int i=0; i<N; i++) {
3523 WindowState win = wtoken.allAppWindows.get(i);
3524 if (win == wtoken.startingWindow) {
3525 continue;
3526 }
3527
3528 if (win.isAnimating()) {
3529 delayed = true;
3530 }
Romain Guy06882f82009-06-10 13:36:04 -07003531
Joe Onorato8a9b2202010-02-26 18:56:32 -08003532 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 //win.dump(" ");
3534 if (visible) {
3535 if (!win.isVisibleNow()) {
3536 if (!runningAppAnimation) {
3537 applyAnimationLocked(win,
3538 WindowManagerPolicy.TRANSIT_ENTER, true);
3539 }
3540 changed = true;
3541 }
3542 } else if (win.isVisibleNow()) {
3543 if (!runningAppAnimation) {
3544 applyAnimationLocked(win,
3545 WindowManagerPolicy.TRANSIT_EXIT, false);
3546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 changed = true;
3548 }
3549 }
3550
3551 wtoken.hidden = wtoken.hiddenRequested = !visible;
3552 if (!visible) {
3553 unsetAppFreezingScreenLocked(wtoken, true, true);
3554 } else {
3555 // If we are being set visible, and the starting window is
3556 // not yet displayed, then make sure it doesn't get displayed.
3557 WindowState swin = wtoken.startingWindow;
3558 if (swin != null && (swin.mDrawPending
3559 || swin.mCommitDrawPending)) {
3560 swin.mPolicyVisibility = false;
3561 swin.mPolicyVisibilityAfterAnim = false;
3562 }
3563 }
Romain Guy06882f82009-06-10 13:36:04 -07003564
Joe Onorato8a9b2202010-02-26 18:56:32 -08003565 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3567 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003568
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003569 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003571 if (performLayout) {
3572 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3573 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003574 } else {
3575 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 }
3578 }
3579
3580 if (wtoken.animation != null) {
3581 delayed = true;
3582 }
Romain Guy06882f82009-06-10 13:36:04 -07003583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 return delayed;
3585 }
3586
3587 public void setAppVisibility(IBinder token, boolean visible) {
3588 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3589 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003590 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 }
3592
3593 AppWindowToken wtoken;
3594
3595 synchronized(mWindowMap) {
3596 wtoken = findAppWindowToken(token);
3597 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003598 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 return;
3600 }
3601
3602 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003603 RuntimeException e = null;
3604 if (!HIDE_STACK_CRAWLS) {
3605 e = new RuntimeException();
3606 e.fillInStackTrace();
3607 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003608 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 + "): mNextAppTransition=" + mNextAppTransition
3610 + " hidden=" + wtoken.hidden
3611 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3612 }
Romain Guy06882f82009-06-10 13:36:04 -07003613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 // If we are preparing an app transition, then delay changing
3615 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003616 if (!mDisplayFrozen && mPolicy.isScreenOn()
3617 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 // Already in requested state, don't do anything more.
3619 if (wtoken.hiddenRequested != visible) {
3620 return;
3621 }
3622 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003623
Joe Onorato8a9b2202010-02-26 18:56:32 -08003624 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 TAG, "Setting dummy animation on: " + wtoken);
3626 wtoken.setDummyAnimation();
3627 mOpeningApps.remove(wtoken);
3628 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003629 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 wtoken.inPendingTransaction = true;
3631 if (visible) {
3632 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 wtoken.startingDisplayed = false;
3634 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003635
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003636 // If the token is currently hidden (should be the
3637 // common case), then we need to set up to wait for
3638 // its windows to be ready.
3639 if (wtoken.hidden) {
3640 wtoken.allDrawn = false;
3641 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003642
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003643 if (wtoken.clientHidden) {
3644 // In the case where we are making an app visible
3645 // but holding off for a transition, we still need
3646 // to tell the client to make its windows visible so
3647 // they get drawn. Otherwise, we will wait on
3648 // performing the transition until all windows have
3649 // been drawn, they never will be, and we are sad.
3650 wtoken.clientHidden = false;
3651 wtoken.sendAppVisibilityToClients();
3652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 }
3654 } else {
3655 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003656
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003657 // If the token is currently visible (should be the
3658 // common case), then set up to wait for it to be hidden.
3659 if (!wtoken.hidden) {
3660 wtoken.waitingToHide = true;
3661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 }
3663 return;
3664 }
Romain Guy06882f82009-06-10 13:36:04 -07003665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003666 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003667 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 wtoken.updateReportedVisibilityLocked();
3669 Binder.restoreCallingIdentity(origId);
3670 }
3671 }
3672
3673 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
3674 boolean unfreezeSurfaceNow, boolean force) {
3675 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003676 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 + " force=" + force);
3678 final int N = wtoken.allAppWindows.size();
3679 boolean unfrozeWindows = false;
3680 for (int i=0; i<N; i++) {
3681 WindowState w = wtoken.allAppWindows.get(i);
3682 if (w.mAppFreezing) {
3683 w.mAppFreezing = false;
3684 if (w.mSurface != null && !w.mOrientationChanging) {
3685 w.mOrientationChanging = true;
3686 }
3687 unfrozeWindows = true;
3688 }
3689 }
3690 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003691 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 wtoken.freezingScreen = false;
3693 mAppsFreezingScreen--;
3694 }
3695 if (unfreezeSurfaceNow) {
3696 if (unfrozeWindows) {
3697 mLayoutNeeded = true;
3698 performLayoutAndPlaceSurfacesLocked();
3699 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003700 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 }
3702 }
3703 }
Romain Guy06882f82009-06-10 13:36:04 -07003704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003705 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
3706 int configChanges) {
3707 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003708 RuntimeException e = null;
3709 if (!HIDE_STACK_CRAWLS) {
3710 e = new RuntimeException();
3711 e.fillInStackTrace();
3712 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003713 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 + ": hidden=" + wtoken.hidden + " freezing="
3715 + wtoken.freezingScreen, e);
3716 }
3717 if (!wtoken.hiddenRequested) {
3718 if (!wtoken.freezingScreen) {
3719 wtoken.freezingScreen = true;
3720 mAppsFreezingScreen++;
3721 if (mAppsFreezingScreen == 1) {
3722 startFreezingDisplayLocked();
3723 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
3724 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
3725 5000);
3726 }
3727 }
3728 final int N = wtoken.allAppWindows.size();
3729 for (int i=0; i<N; i++) {
3730 WindowState w = wtoken.allAppWindows.get(i);
3731 w.mAppFreezing = true;
3732 }
3733 }
3734 }
Romain Guy06882f82009-06-10 13:36:04 -07003735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 public void startAppFreezingScreen(IBinder token, int configChanges) {
3737 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3738 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003739 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 }
3741
3742 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003743 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003744 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 return;
3746 }
Romain Guy06882f82009-06-10 13:36:04 -07003747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 AppWindowToken wtoken = findAppWindowToken(token);
3749 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003750 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 return;
3752 }
3753 final long origId = Binder.clearCallingIdentity();
3754 startAppFreezingScreenLocked(wtoken, configChanges);
3755 Binder.restoreCallingIdentity(origId);
3756 }
3757 }
Romain Guy06882f82009-06-10 13:36:04 -07003758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 public void stopAppFreezingScreen(IBinder token, boolean force) {
3760 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3761 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003762 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 }
3764
3765 synchronized(mWindowMap) {
3766 AppWindowToken wtoken = findAppWindowToken(token);
3767 if (wtoken == null || wtoken.appToken == null) {
3768 return;
3769 }
3770 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003771 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
3773 unsetAppFreezingScreenLocked(wtoken, true, force);
3774 Binder.restoreCallingIdentity(origId);
3775 }
3776 }
Romain Guy06882f82009-06-10 13:36:04 -07003777
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 public void removeAppToken(IBinder token) {
3779 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3780 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003781 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 }
3783
3784 AppWindowToken wtoken = null;
3785 AppWindowToken startingToken = null;
3786 boolean delayed = false;
3787
3788 final long origId = Binder.clearCallingIdentity();
3789 synchronized(mWindowMap) {
3790 WindowToken basewtoken = mTokenMap.remove(token);
3791 mTokenList.remove(basewtoken);
3792 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003793 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003794 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003795 wtoken.inPendingTransaction = false;
3796 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003797 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 if (mClosingApps.contains(wtoken)) {
3799 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003800 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003802 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 delayed = true;
3804 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003805 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 TAG, "Removing app " + wtoken + " delayed=" + delayed
3807 + " animation=" + wtoken.animation
3808 + " animating=" + wtoken.animating);
3809 if (delayed) {
3810 // set the token aside because it has an active animation to be finished
3811 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003812 } else {
3813 // Make sure there is no animation running on this token,
3814 // so any windows associated with it will be removed as
3815 // soon as their animations are complete
3816 wtoken.animation = null;
3817 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 }
3819 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003820 if (mLastEnterAnimToken == wtoken) {
3821 mLastEnterAnimToken = null;
3822 mLastEnterAnimParams = null;
3823 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 wtoken.removed = true;
3825 if (wtoken.startingData != null) {
3826 startingToken = wtoken;
3827 }
3828 unsetAppFreezingScreenLocked(wtoken, true, true);
3829 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003830 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003831 mFocusedApp = null;
3832 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003833 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 }
3835 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003836 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003837 }
Romain Guy06882f82009-06-10 13:36:04 -07003838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 if (!delayed && wtoken != null) {
3840 wtoken.updateReportedVisibilityLocked();
3841 }
3842 }
3843 Binder.restoreCallingIdentity(origId);
3844
3845 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003846 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 + startingToken + ": app token removed");
3848 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
3849 mH.sendMessage(m);
3850 }
3851 }
3852
3853 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
3854 final int NW = token.windows.size();
3855 for (int i=0; i<NW; i++) {
3856 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003857 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003859 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 int j = win.mChildWindows.size();
3861 while (j > 0) {
3862 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003863 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003864 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003865 "Tmp removing child window " + cwin);
3866 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 }
3868 }
3869 return NW > 0;
3870 }
3871
3872 void dumpAppTokensLocked() {
3873 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003874 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 }
3876 }
Romain Guy06882f82009-06-10 13:36:04 -07003877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 void dumpWindowsLocked() {
3879 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003880 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003881 }
3882 }
Romain Guy06882f82009-06-10 13:36:04 -07003883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884 private int findWindowOffsetLocked(int tokenPos) {
3885 final int NW = mWindows.size();
3886
3887 if (tokenPos >= mAppTokens.size()) {
3888 int i = NW;
3889 while (i > 0) {
3890 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07003891 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003892 if (win.getAppToken() != null) {
3893 return i+1;
3894 }
3895 }
3896 }
3897
3898 while (tokenPos > 0) {
3899 // Find the first app token below the new position that has
3900 // a window displayed.
3901 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003902 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003904 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003905 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07003906 "Skipping token -- currently sending to bottom");
3907 tokenPos--;
3908 continue;
3909 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003910 int i = wtoken.windows.size();
3911 while (i > 0) {
3912 i--;
3913 WindowState win = wtoken.windows.get(i);
3914 int j = win.mChildWindows.size();
3915 while (j > 0) {
3916 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07003917 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003918 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 for (int pos=NW-1; pos>=0; pos--) {
3920 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003921 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003922 "Found child win @" + (pos+1));
3923 return pos+1;
3924 }
3925 }
3926 }
3927 }
3928 for (int pos=NW-1; pos>=0; pos--) {
3929 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003930 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003931 return pos+1;
3932 }
3933 }
3934 }
3935 tokenPos--;
3936 }
3937
3938 return 0;
3939 }
3940
3941 private final int reAddWindowLocked(int index, WindowState win) {
3942 final int NCW = win.mChildWindows.size();
3943 boolean added = false;
3944 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07003945 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003946 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003947 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003948 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003949 mWindows.add(index, win);
3950 index++;
3951 added = true;
3952 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003953 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003954 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003955 mWindows.add(index, cwin);
3956 index++;
3957 }
3958 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003959 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07003960 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003961 mWindows.add(index, win);
3962 index++;
3963 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003964 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003965 return index;
3966 }
Romain Guy06882f82009-06-10 13:36:04 -07003967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003968 private final int reAddAppWindowsLocked(int index, WindowToken token) {
3969 final int NW = token.windows.size();
3970 for (int i=0; i<NW; i++) {
3971 index = reAddWindowLocked(index, token.windows.get(i));
3972 }
3973 return index;
3974 }
3975
3976 public void moveAppToken(int index, IBinder token) {
3977 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3978 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003979 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003980 }
3981
3982 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003983 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003984 if (DEBUG_REORDER) dumpAppTokensLocked();
3985 final AppWindowToken wtoken = findAppWindowToken(token);
3986 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003987 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 + token + " (" + wtoken + ")");
3989 return;
3990 }
3991 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003992 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003993 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003995 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003996 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 if (DEBUG_REORDER) dumpWindowsLocked();
3998 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003999 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 if (DEBUG_REORDER) dumpWindowsLocked();
4001 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004002 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 if (DEBUG_REORDER) dumpWindowsLocked();
4004 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 mLayoutNeeded = true;
4006 performLayoutAndPlaceSurfacesLocked();
4007 }
4008 Binder.restoreCallingIdentity(origId);
4009 }
4010 }
4011
4012 private void removeAppTokensLocked(List<IBinder> tokens) {
4013 // XXX This should be done more efficiently!
4014 // (take advantage of the fact that both lists should be
4015 // ordered in the same way.)
4016 int N = tokens.size();
4017 for (int i=0; i<N; i++) {
4018 IBinder token = tokens.get(i);
4019 final AppWindowToken wtoken = findAppWindowToken(token);
4020 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004021 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004022 + token + " (" + wtoken + ")");
4023 i--;
4024 N--;
4025 }
4026 }
4027 }
4028
Dianne Hackborna8f60182009-09-01 19:01:50 -07004029 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4030 boolean updateFocusAndLayout) {
4031 // First remove all of the windows from the list.
4032 tmpRemoveAppWindowsLocked(wtoken);
4033
4034 // Where to start adding?
4035 int pos = findWindowOffsetLocked(tokenPos);
4036
4037 // And now add them back at the correct place.
4038 pos = reAddAppWindowsLocked(pos, wtoken);
4039
4040 if (updateFocusAndLayout) {
4041 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4042 assignLayersLocked();
4043 }
4044 mLayoutNeeded = true;
4045 performLayoutAndPlaceSurfacesLocked();
4046 }
4047 }
4048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004049 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4050 // First remove all of the windows from the list.
4051 final int N = tokens.size();
4052 int i;
4053 for (i=0; i<N; i++) {
4054 WindowToken token = mTokenMap.get(tokens.get(i));
4055 if (token != null) {
4056 tmpRemoveAppWindowsLocked(token);
4057 }
4058 }
4059
4060 // Where to start adding?
4061 int pos = findWindowOffsetLocked(tokenPos);
4062
4063 // And now add them back at the correct place.
4064 for (i=0; i<N; i++) {
4065 WindowToken token = mTokenMap.get(tokens.get(i));
4066 if (token != null) {
4067 pos = reAddAppWindowsLocked(pos, token);
4068 }
4069 }
4070
Dianne Hackborna8f60182009-09-01 19:01:50 -07004071 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4072 assignLayersLocked();
4073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 mLayoutNeeded = true;
4075 performLayoutAndPlaceSurfacesLocked();
4076
4077 //dump();
4078 }
4079
4080 public void moveAppTokensToTop(List<IBinder> tokens) {
4081 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4082 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004083 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 }
4085
4086 final long origId = Binder.clearCallingIdentity();
4087 synchronized(mWindowMap) {
4088 removeAppTokensLocked(tokens);
4089 final int N = tokens.size();
4090 for (int i=0; i<N; i++) {
4091 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4092 if (wt != null) {
4093 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004094 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004095 mToTopApps.remove(wt);
4096 mToBottomApps.remove(wt);
4097 mToTopApps.add(wt);
4098 wt.sendingToBottom = false;
4099 wt.sendingToTop = true;
4100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 }
4102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004103
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004104 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004105 moveAppWindowsLocked(tokens, mAppTokens.size());
4106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004107 }
4108 Binder.restoreCallingIdentity(origId);
4109 }
4110
4111 public void moveAppTokensToBottom(List<IBinder> tokens) {
4112 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4113 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004114 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 }
4116
4117 final long origId = Binder.clearCallingIdentity();
4118 synchronized(mWindowMap) {
4119 removeAppTokensLocked(tokens);
4120 final int N = tokens.size();
4121 int pos = 0;
4122 for (int i=0; i<N; i++) {
4123 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4124 if (wt != null) {
4125 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004126 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004127 mToTopApps.remove(wt);
4128 mToBottomApps.remove(wt);
4129 mToBottomApps.add(i, wt);
4130 wt.sendingToTop = false;
4131 wt.sendingToBottom = true;
4132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 pos++;
4134 }
4135 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004136
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004137 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004138 moveAppWindowsLocked(tokens, 0);
4139 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 }
4141 Binder.restoreCallingIdentity(origId);
4142 }
4143
4144 // -------------------------------------------------------------
4145 // Misc IWindowSession methods
4146 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004147
Jim Miller284b62e2010-06-08 14:27:42 -07004148 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004149 {
Jim Miller284b62e2010-06-08 14:27:42 -07004150 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4151 // called before DevicePolicyManagerService has started.
4152 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4153 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4154 Context.DEVICE_POLICY_SERVICE);
4155 if (dpm != null) {
4156 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4157 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4158 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4159 }
Jim Millerd6b57052010-06-07 17:52:42 -07004160 }
Jim Miller284b62e2010-06-08 14:27:42 -07004161 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004162 }
4163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004165 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004166 != PackageManager.PERMISSION_GRANTED) {
4167 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4168 }
Jim Millerd6b57052010-06-07 17:52:42 -07004169
Jim Miller284b62e2010-06-08 14:27:42 -07004170 synchronized (mKeyguardTokenWatcher) {
4171 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004172 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 }
4174
4175 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004176 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 != PackageManager.PERMISSION_GRANTED) {
4178 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4179 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004180
Jim Miller284b62e2010-06-08 14:27:42 -07004181 synchronized (mKeyguardTokenWatcher) {
4182 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004183
Jim Miller284b62e2010-06-08 14:27:42 -07004184 if (!mKeyguardTokenWatcher.isAcquired()) {
4185 // If we are the last one to reenable the keyguard wait until
4186 // we have actually finished reenabling until returning.
4187 // It is possible that reenableKeyguard() can be called before
4188 // the previous disableKeyguard() is handled, in which case
4189 // neither mKeyguardTokenWatcher.acquired() or released() would
4190 // be called. In that case mKeyguardDisabled will be false here
4191 // and we have nothing to wait for.
4192 while (mKeyguardDisabled) {
4193 try {
4194 mKeyguardTokenWatcher.wait();
4195 } catch (InterruptedException e) {
4196 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 }
4198 }
4199 }
4200 }
4201 }
4202
4203 /**
4204 * @see android.app.KeyguardManager#exitKeyguardSecurely
4205 */
4206 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004207 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004208 != PackageManager.PERMISSION_GRANTED) {
4209 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4210 }
4211 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4212 public void onKeyguardExitResult(boolean success) {
4213 try {
4214 callback.onKeyguardExitResult(success);
4215 } catch (RemoteException e) {
4216 // Client has died, we don't care.
4217 }
4218 }
4219 });
4220 }
4221
4222 public boolean inKeyguardRestrictedInputMode() {
4223 return mPolicy.inKeyguardRestrictedKeyInputMode();
4224 }
Romain Guy06882f82009-06-10 13:36:04 -07004225
Dianne Hackbornffa42482009-09-23 22:20:11 -07004226 public void closeSystemDialogs(String reason) {
4227 synchronized(mWindowMap) {
4228 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004229 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004230 if (w.mSurface != null) {
4231 try {
4232 w.mClient.closeSystemDialogs(reason);
4233 } catch (RemoteException e) {
4234 }
4235 }
4236 }
4237 }
4238 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004240 static float fixScale(float scale) {
4241 if (scale < 0) scale = 0;
4242 else if (scale > 20) scale = 20;
4243 return Math.abs(scale);
4244 }
Romain Guy06882f82009-06-10 13:36:04 -07004245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004246 public void setAnimationScale(int which, float scale) {
4247 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4248 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004249 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004250 }
4251
4252 if (scale < 0) scale = 0;
4253 else if (scale > 20) scale = 20;
4254 scale = Math.abs(scale);
4255 switch (which) {
4256 case 0: mWindowAnimationScale = fixScale(scale); break;
4257 case 1: mTransitionAnimationScale = fixScale(scale); break;
4258 }
Romain Guy06882f82009-06-10 13:36:04 -07004259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 // Persist setting
4261 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4262 }
Romain Guy06882f82009-06-10 13:36:04 -07004263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 public void setAnimationScales(float[] scales) {
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 (scales != null) {
4271 if (scales.length >= 1) {
4272 mWindowAnimationScale = fixScale(scales[0]);
4273 }
4274 if (scales.length >= 2) {
4275 mTransitionAnimationScale = fixScale(scales[1]);
4276 }
4277 }
Romain Guy06882f82009-06-10 13:36:04 -07004278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 // Persist setting
4280 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4281 }
Romain Guy06882f82009-06-10 13:36:04 -07004282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004283 public float getAnimationScale(int which) {
4284 switch (which) {
4285 case 0: return mWindowAnimationScale;
4286 case 1: return mTransitionAnimationScale;
4287 }
4288 return 0;
4289 }
Romain Guy06882f82009-06-10 13:36:04 -07004290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 public float[] getAnimationScales() {
4292 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4293 }
Romain Guy06882f82009-06-10 13:36:04 -07004294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004295 public int getSwitchState(int sw) {
4296 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4297 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004298 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004300 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 }
Romain Guy06882f82009-06-10 13:36:04 -07004302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004303 public int getSwitchStateForDevice(int devid, int sw) {
4304 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4305 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004306 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004308 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309 }
Romain Guy06882f82009-06-10 13:36:04 -07004310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004311 public int getScancodeState(int sw) {
4312 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4313 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004314 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004316 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004317 }
Romain Guy06882f82009-06-10 13:36:04 -07004318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 public int getScancodeStateForDevice(int devid, int sw) {
4320 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4321 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004322 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004323 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004324 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004325 }
Romain Guy06882f82009-06-10 13:36:04 -07004326
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004327 public int getTrackballScancodeState(int sw) {
4328 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4329 "getTrackballScancodeState()")) {
4330 throw new SecurityException("Requires READ_INPUT_STATE permission");
4331 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004332 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004333 }
4334
4335 public int getDPadScancodeState(int sw) {
4336 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4337 "getDPadScancodeState()")) {
4338 throw new SecurityException("Requires READ_INPUT_STATE permission");
4339 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004340 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004341 }
4342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004343 public int getKeycodeState(int sw) {
4344 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4345 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004346 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004348 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349 }
Romain Guy06882f82009-06-10 13:36:04 -07004350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351 public int getKeycodeStateForDevice(int devid, int sw) {
4352 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4353 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004354 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004356 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004357 }
Romain Guy06882f82009-06-10 13:36:04 -07004358
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004359 public int getTrackballKeycodeState(int sw) {
4360 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4361 "getTrackballKeycodeState()")) {
4362 throw new SecurityException("Requires READ_INPUT_STATE permission");
4363 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004364 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004365 }
4366
4367 public int getDPadKeycodeState(int sw) {
4368 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4369 "getDPadKeycodeState()")) {
4370 throw new SecurityException("Requires READ_INPUT_STATE permission");
4371 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004372 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004373 }
Jeff Browna41ca772010-08-11 14:46:32 -07004374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004375 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004376 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004377 }
Romain Guy06882f82009-06-10 13:36:04 -07004378
Jeff Browna41ca772010-08-11 14:46:32 -07004379 public InputChannel monitorInput(String inputChannelName) {
4380 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4381 "monitorInput()")) {
4382 throw new SecurityException("Requires READ_INPUT_STATE permission");
4383 }
4384 return mInputManager.monitorInput(inputChannelName);
4385 }
4386
Jeff Brown8d608662010-08-30 03:02:23 -07004387 public InputDevice getInputDevice(int deviceId) {
4388 return mInputManager.getInputDevice(deviceId);
4389 }
4390
4391 public int[] getInputDeviceIds() {
4392 return mInputManager.getInputDeviceIds();
4393 }
4394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 public void enableScreenAfterBoot() {
4396 synchronized(mWindowMap) {
4397 if (mSystemBooted) {
4398 return;
4399 }
4400 mSystemBooted = true;
4401 }
Romain Guy06882f82009-06-10 13:36:04 -07004402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 performEnableScreen();
4404 }
Romain Guy06882f82009-06-10 13:36:04 -07004405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 public void enableScreenIfNeededLocked() {
4407 if (mDisplayEnabled) {
4408 return;
4409 }
4410 if (!mSystemBooted) {
4411 return;
4412 }
4413 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4414 }
Romain Guy06882f82009-06-10 13:36:04 -07004415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 public void performEnableScreen() {
4417 synchronized(mWindowMap) {
4418 if (mDisplayEnabled) {
4419 return;
4420 }
4421 if (!mSystemBooted) {
4422 return;
4423 }
Romain Guy06882f82009-06-10 13:36:04 -07004424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425 // Don't enable the screen until all existing windows
4426 // have been drawn.
4427 final int N = mWindows.size();
4428 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004429 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004430 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004431 return;
4432 }
4433 }
Romain Guy06882f82009-06-10 13:36:04 -07004434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 mDisplayEnabled = true;
4436 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004437 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004438 StringWriter sw = new StringWriter();
4439 PrintWriter pw = new PrintWriter(sw);
4440 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004441 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004442 }
4443 try {
4444 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4445 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004446 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004447 Parcel data = Parcel.obtain();
4448 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4449 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4450 data, null, 0);
4451 data.recycle();
4452 }
4453 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004454 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004455 }
4456 }
Romain Guy06882f82009-06-10 13:36:04 -07004457
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004461 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4462 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004463 }
Romain Guy06882f82009-06-10 13:36:04 -07004464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004465 public void setInTouchMode(boolean mode) {
4466 synchronized(mWindowMap) {
4467 mInTouchMode = mode;
4468 }
4469 }
4470
Romain Guy06882f82009-06-10 13:36:04 -07004471 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004472 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004474 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004475 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004476 }
4477
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004478 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 }
Romain Guy06882f82009-06-10 13:36:04 -07004480
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004481 public void setRotationUnchecked(int rotation,
4482 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004483 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004484 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486 long origId = Binder.clearCallingIdentity();
4487 boolean changed;
4488 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004489 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 }
Romain Guy06882f82009-06-10 13:36:04 -07004491
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004492 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004493 sendNewConfiguration();
4494 }
Romain Guy06882f82009-06-10 13:36:04 -07004495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 Binder.restoreCallingIdentity(origId);
4497 }
Romain Guy06882f82009-06-10 13:36:04 -07004498
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004499 /**
4500 * Apply a new rotation to the screen, respecting the requests of
4501 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4502 * re-evaluate the desired rotation.
4503 *
4504 * Returns null if the rotation has been changed. In this case YOU
4505 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4506 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004507 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508 boolean changed;
4509 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4510 rotation = mRequestedRotation;
4511 } else {
4512 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004513 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004515 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004516 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004518 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004519 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004522 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 "Rotation changed to " + rotation
4524 + " from " + mRotation
4525 + " (forceApp=" + mForcedAppOrientation
4526 + ", req=" + mRequestedRotation + ")");
4527 mRotation = rotation;
4528 mWindowsFreezingScreen = true;
4529 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4530 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4531 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004532 mWaitingForConfig = true;
4533 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004534 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004535 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004536 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004537 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004538 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004539 }
4540 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004541 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 if (w.mSurface != null) {
4543 w.mOrientationChanging = true;
4544 }
4545 }
4546 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4547 try {
4548 mRotationWatchers.get(i).onRotationChanged(rotation);
4549 } catch (RemoteException e) {
4550 }
4551 }
4552 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004554 return changed;
4555 }
Romain Guy06882f82009-06-10 13:36:04 -07004556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004557 public int getRotation() {
4558 return mRotation;
4559 }
4560
4561 public int watchRotation(IRotationWatcher watcher) {
4562 final IBinder watcherBinder = watcher.asBinder();
4563 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4564 public void binderDied() {
4565 synchronized (mWindowMap) {
4566 for (int i=0; i<mRotationWatchers.size(); i++) {
4567 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004568 IRotationWatcher removed = mRotationWatchers.remove(i);
4569 if (removed != null) {
4570 removed.asBinder().unlinkToDeath(this, 0);
4571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004572 i--;
4573 }
4574 }
4575 }
4576 }
4577 };
Romain Guy06882f82009-06-10 13:36:04 -07004578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579 synchronized (mWindowMap) {
4580 try {
4581 watcher.asBinder().linkToDeath(dr, 0);
4582 mRotationWatchers.add(watcher);
4583 } catch (RemoteException e) {
4584 // Client died, no cleanup needed.
4585 }
Romain Guy06882f82009-06-10 13:36:04 -07004586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004587 return mRotation;
4588 }
4589 }
4590
4591 /**
4592 * Starts the view server on the specified port.
4593 *
4594 * @param port The port to listener to.
4595 *
4596 * @return True if the server was successfully started, false otherwise.
4597 *
4598 * @see com.android.server.ViewServer
4599 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4600 */
4601 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004602 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004603 return false;
4604 }
4605
4606 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4607 return false;
4608 }
4609
4610 if (port < 1024) {
4611 return false;
4612 }
4613
4614 if (mViewServer != null) {
4615 if (!mViewServer.isRunning()) {
4616 try {
4617 return mViewServer.start();
4618 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004619 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004620 }
4621 }
4622 return false;
4623 }
4624
4625 try {
4626 mViewServer = new ViewServer(this, port);
4627 return mViewServer.start();
4628 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004629 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 }
4631 return false;
4632 }
4633
Romain Guy06882f82009-06-10 13:36:04 -07004634 private boolean isSystemSecure() {
4635 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4636 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4637 }
4638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 /**
4640 * Stops the view server if it exists.
4641 *
4642 * @return True if the server stopped, false if it wasn't started or
4643 * couldn't be stopped.
4644 *
4645 * @see com.android.server.ViewServer
4646 */
4647 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004648 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 return false;
4650 }
4651
4652 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4653 return false;
4654 }
4655
4656 if (mViewServer != null) {
4657 return mViewServer.stop();
4658 }
4659 return false;
4660 }
4661
4662 /**
4663 * Indicates whether the view server is running.
4664 *
4665 * @return True if the server is running, false otherwise.
4666 *
4667 * @see com.android.server.ViewServer
4668 */
4669 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07004670 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004671 return false;
4672 }
4673
4674 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
4675 return false;
4676 }
4677
4678 return mViewServer != null && mViewServer.isRunning();
4679 }
4680
4681 /**
4682 * Lists all availble windows in the system. The listing is written in the
4683 * specified Socket's output stream with the following syntax:
4684 * windowHashCodeInHexadecimal windowName
4685 * Each line of the ouput represents a different window.
4686 *
4687 * @param client The remote client to send the listing to.
4688 * @return False if an error occured, true otherwise.
4689 */
4690 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07004691 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004692 return false;
4693 }
4694
4695 boolean result = true;
4696
Jeff Browne33348b2010-07-15 23:54:05 -07004697 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004698 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07004700 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004701 }
4702
4703 BufferedWriter out = null;
4704
4705 // Any uncaught exception will crash the system process
4706 try {
4707 OutputStream clientStream = client.getOutputStream();
4708 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4709
4710 final int count = windows.length;
4711 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004712 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004713 out.write(Integer.toHexString(System.identityHashCode(w)));
4714 out.write(' ');
4715 out.append(w.mAttrs.getTitle());
4716 out.write('\n');
4717 }
4718
4719 out.write("DONE.\n");
4720 out.flush();
4721 } catch (Exception e) {
4722 result = false;
4723 } finally {
4724 if (out != null) {
4725 try {
4726 out.close();
4727 } catch (IOException e) {
4728 result = false;
4729 }
4730 }
4731 }
4732
4733 return result;
4734 }
4735
4736 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07004737 * Returns the focused window in the following format:
4738 * windowHashCodeInHexadecimal windowName
4739 *
4740 * @param client The remote client to send the listing to.
4741 * @return False if an error occurred, true otherwise.
4742 */
4743 boolean viewServerGetFocusedWindow(Socket client) {
4744 if (isSystemSecure()) {
4745 return false;
4746 }
4747
4748 boolean result = true;
4749
4750 WindowState focusedWindow = getFocusedWindow();
4751
4752 BufferedWriter out = null;
4753
4754 // Any uncaught exception will crash the system process
4755 try {
4756 OutputStream clientStream = client.getOutputStream();
4757 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
4758
4759 if(focusedWindow != null) {
4760 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
4761 out.write(' ');
4762 out.append(focusedWindow.mAttrs.getTitle());
4763 }
4764 out.write('\n');
4765 out.flush();
4766 } catch (Exception e) {
4767 result = false;
4768 } finally {
4769 if (out != null) {
4770 try {
4771 out.close();
4772 } catch (IOException e) {
4773 result = false;
4774 }
4775 }
4776 }
4777
4778 return result;
4779 }
4780
4781 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004782 * Sends a command to a target window. The result of the command, if any, will be
4783 * written in the output stream of the specified socket.
4784 *
4785 * The parameters must follow this syntax:
4786 * windowHashcode extra
4787 *
4788 * Where XX is the length in characeters of the windowTitle.
4789 *
4790 * The first parameter is the target window. The window with the specified hashcode
4791 * will be the target. If no target can be found, nothing happens. The extra parameters
4792 * will be delivered to the target window and as parameters to the command itself.
4793 *
4794 * @param client The remote client to sent the result, if any, to.
4795 * @param command The command to execute.
4796 * @param parameters The command parameters.
4797 *
4798 * @return True if the command was successfully delivered, false otherwise. This does
4799 * not indicate whether the command itself was successful.
4800 */
4801 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07004802 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004803 return false;
4804 }
4805
4806 boolean success = true;
4807 Parcel data = null;
4808 Parcel reply = null;
4809
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004810 BufferedWriter out = null;
4811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004812 // Any uncaught exception will crash the system process
4813 try {
4814 // Find the hashcode of the window
4815 int index = parameters.indexOf(' ');
4816 if (index == -1) {
4817 index = parameters.length();
4818 }
4819 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08004820 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821
4822 // Extract the command's parameter after the window description
4823 if (index < parameters.length()) {
4824 parameters = parameters.substring(index + 1);
4825 } else {
4826 parameters = "";
4827 }
4828
4829 final WindowManagerService.WindowState window = findWindow(hashCode);
4830 if (window == null) {
4831 return false;
4832 }
4833
4834 data = Parcel.obtain();
4835 data.writeInterfaceToken("android.view.IWindow");
4836 data.writeString(command);
4837 data.writeString(parameters);
4838 data.writeInt(1);
4839 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
4840
4841 reply = Parcel.obtain();
4842
4843 final IBinder binder = window.mClient.asBinder();
4844 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
4845 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
4846
4847 reply.readException();
4848
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004849 if (!client.isOutputShutdown()) {
4850 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
4851 out.write("DONE\n");
4852 out.flush();
4853 }
4854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004856 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 success = false;
4858 } finally {
4859 if (data != null) {
4860 data.recycle();
4861 }
4862 if (reply != null) {
4863 reply.recycle();
4864 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07004865 if (out != null) {
4866 try {
4867 out.close();
4868 } catch (IOException e) {
4869
4870 }
4871 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004872 }
4873
4874 return success;
4875 }
4876
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004877 public void addWindowChangeListener(WindowChangeListener listener) {
4878 synchronized(mWindowMap) {
4879 mWindowChangeListeners.add(listener);
4880 }
4881 }
4882
4883 public void removeWindowChangeListener(WindowChangeListener listener) {
4884 synchronized(mWindowMap) {
4885 mWindowChangeListeners.remove(listener);
4886 }
4887 }
4888
4889 private void notifyWindowsChanged() {
4890 WindowChangeListener[] windowChangeListeners;
4891 synchronized(mWindowMap) {
4892 if(mWindowChangeListeners.isEmpty()) {
4893 return;
4894 }
4895 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4896 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4897 }
4898 int N = windowChangeListeners.length;
4899 for(int i = 0; i < N; i++) {
4900 windowChangeListeners[i].windowsChanged();
4901 }
4902 }
4903
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07004904 private void notifyFocusChanged() {
4905 WindowChangeListener[] windowChangeListeners;
4906 synchronized(mWindowMap) {
4907 if(mWindowChangeListeners.isEmpty()) {
4908 return;
4909 }
4910 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
4911 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
4912 }
4913 int N = windowChangeListeners.length;
4914 for(int i = 0; i < N; i++) {
4915 windowChangeListeners[i].focusChanged();
4916 }
4917 }
4918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 private WindowState findWindow(int hashCode) {
4920 if (hashCode == -1) {
4921 return getFocusedWindow();
4922 }
4923
4924 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07004925 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 final int count = windows.size();
4927
4928 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004929 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 if (System.identityHashCode(w) == hashCode) {
4931 return w;
4932 }
4933 }
4934 }
4935
4936 return null;
4937 }
4938
4939 /*
4940 * Instruct the Activity Manager to fetch the current configuration and broadcast
4941 * that to config-changed listeners if appropriate.
4942 */
4943 void sendNewConfiguration() {
4944 try {
4945 mActivityManager.updateConfiguration(null);
4946 } catch (RemoteException e) {
4947 }
4948 }
Romain Guy06882f82009-06-10 13:36:04 -07004949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 public Configuration computeNewConfiguration() {
4951 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07004952 return computeNewConfigurationLocked();
4953 }
4954 }
Romain Guy06882f82009-06-10 13:36:04 -07004955
Dianne Hackbornc485a602009-03-24 22:39:49 -07004956 Configuration computeNewConfigurationLocked() {
4957 Configuration config = new Configuration();
4958 if (!computeNewConfigurationLocked(config)) {
4959 return null;
4960 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07004961 return config;
4962 }
Romain Guy06882f82009-06-10 13:36:04 -07004963
Dianne Hackbornc485a602009-03-24 22:39:49 -07004964 boolean computeNewConfigurationLocked(Configuration config) {
4965 if (mDisplay == null) {
4966 return false;
4967 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004968
4969 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07004970
4971 // Use the effective "visual" dimensions based on current rotation
4972 final boolean rotated = (mRotation == Surface.ROTATION_90
4973 || mRotation == Surface.ROTATION_270);
4974 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
4975 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
4976
Dianne Hackbornc485a602009-03-24 22:39:49 -07004977 int orientation = Configuration.ORIENTATION_SQUARE;
4978 if (dw < dh) {
4979 orientation = Configuration.ORIENTATION_PORTRAIT;
4980 } else if (dw > dh) {
4981 orientation = Configuration.ORIENTATION_LANDSCAPE;
4982 }
4983 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004984
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07004985 DisplayMetrics dm = new DisplayMetrics();
4986 mDisplay.getMetrics(dm);
4987 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
4988
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07004989 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07004990 // Note we only do this once because at this point we don't
4991 // expect the screen to change in this way at runtime, and want
4992 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07004993 int longSize = dw;
4994 int shortSize = dh;
4995 if (longSize < shortSize) {
4996 int tmp = longSize;
4997 longSize = shortSize;
4998 shortSize = tmp;
4999 }
5000 longSize = (int)(longSize/dm.density);
5001 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005002
Dianne Hackborn723738c2009-06-25 19:48:04 -07005003 // These semi-magic numbers define our compatibility modes for
5004 // applications with different screens. Don't change unless you
5005 // make sure to test lots and lots of apps!
5006 if (longSize < 470) {
5007 // This is shorter than an HVGA normal density screen (which
5008 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005009 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5010 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005011 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005012 // What size is this screen screen?
5013 if (longSize >= 800 && shortSize >= 600) {
5014 // SVGA or larger screens at medium density are the point
5015 // at which we consider it to be an extra large screen.
5016 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5017 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005018 // VGA or larger screens at medium density are the point
5019 // at which we consider it to be a large screen.
5020 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5021 } else {
5022 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005023
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005024 // If this screen is wider than normal HVGA, or taller
5025 // than FWVGA, then for old apps we want to run in size
5026 // compatibility mode.
5027 if (shortSize > 321 || longSize > 570) {
5028 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5029 }
5030 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005031
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005032 // Is this a long screen?
5033 if (((longSize*3)/5) >= (shortSize-1)) {
5034 // Anything wider than WVGA (5:3) is considering to be long.
5035 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5036 } else {
5037 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5038 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005039 }
5040 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005041 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005042
Dianne Hackbornc485a602009-03-24 22:39:49 -07005043 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5044 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5045 mPolicy.adjustConfigurationLw(config);
5046 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005047 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005049 // -------------------------------------------------------------
5050 // Input Events and Focus Management
5051 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005052
Jeff Brown349703e2010-06-22 01:27:15 -07005053 InputMonitor mInputMonitor = new InputMonitor();
5054
5055 /* Tracks the progress of input dispatch and ensures that input dispatch state
5056 * is kept in sync with changes in window focus, visibility, registration, and
5057 * other relevant Window Manager state transitions. */
5058 final class InputMonitor {
5059 // Current window with input focus for keys and other non-touch events. May be null.
5060 private WindowState mInputFocus;
5061
5062 // When true, prevents input dispatch from proceeding until set to false again.
5063 private boolean mInputDispatchFrozen;
5064
5065 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5066 private boolean mInputDispatchEnabled = true;
5067
5068 // Temporary list of windows information to provide to the input dispatcher.
5069 private InputWindowList mTempInputWindows = new InputWindowList();
5070
5071 // Temporary input application object to provide to the input dispatcher.
5072 private InputApplication mTempInputApplication = new InputApplication();
5073
5074 /* Notifies the window manager about a broken input channel.
5075 *
5076 * Called by the InputManager.
5077 */
5078 public void notifyInputChannelBroken(InputChannel inputChannel) {
5079 synchronized (mWindowMap) {
5080 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5081 if (windowState == null) {
5082 return; // irrelevant
5083 }
5084
5085 Slog.i(TAG, "WINDOW DIED " + windowState);
5086 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005087 }
5088 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005089
Jeff Brown349703e2010-06-22 01:27:15 -07005090 /* Notifies the window manager about an input channel that is not responding.
5091 * The method can either cause dispatching to be aborted by returning -2 or
5092 * return a new timeout in nanoseconds.
5093 *
5094 * Called by the InputManager.
5095 */
5096 public long notifyInputChannelANR(InputChannel inputChannel) {
5097 AppWindowToken token;
5098 synchronized (mWindowMap) {
5099 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5100 if (windowState == null) {
5101 return -2; // irrelevant, abort dispatching (-2)
5102 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005103
Jeff Brown349703e2010-06-22 01:27:15 -07005104 Slog.i(TAG, "Input event dispatching timed out sending to "
5105 + windowState.mAttrs.getTitle());
5106 token = windowState.mAppToken;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005107 }
5108
Jeff Brown349703e2010-06-22 01:27:15 -07005109 return notifyANRInternal(token);
5110 }
5111
5112 /* Notifies the window manager about an input channel spontaneously recovering from ANR
5113 * by successfully delivering the event that originally timed out.
5114 *
5115 * Called by the InputManager.
5116 */
5117 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
5118 // Nothing to do just now.
5119 // Just wait for the user to dismiss the ANR dialog.
5120 }
5121
5122 /* Notifies the window manager about an application that is not responding
5123 * in general rather than with respect to a particular input channel.
5124 * The method can either cause dispatching to be aborted by returning -2 or
5125 * return a new timeout in nanoseconds.
5126 *
5127 * Called by the InputManager.
5128 */
5129 public long notifyANR(Object token) {
5130 AppWindowToken appWindowToken = (AppWindowToken) token;
5131
5132 Slog.i(TAG, "Input event dispatching timed out sending to application "
5133 + appWindowToken.stringName);
5134 return notifyANRInternal(appWindowToken);
5135 }
5136
5137 private long notifyANRInternal(AppWindowToken token) {
5138 if (token != null && token.appToken != null) {
5139 try {
5140 // Notify the activity manager about the timeout and let it decide whether
5141 // to abort dispatching or keep waiting.
5142 boolean abort = token.appToken.keyDispatchingTimedOut();
5143 if (! abort) {
5144 // The activity manager declined to abort dispatching.
5145 // Wait a bit longer and timeout again later.
5146 return token.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005147 }
Jeff Brown349703e2010-06-22 01:27:15 -07005148 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005149 }
5150 }
Jeff Brown349703e2010-06-22 01:27:15 -07005151 return -2; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005152 }
5153
Jeff Brown349703e2010-06-22 01:27:15 -07005154 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5155 synchronized (mWindowMap) {
5156 return getWindowStateForInputChannelLocked(inputChannel);
5157 }
5158 }
5159
5160 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5161 int windowCount = mWindows.size();
5162 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005163 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005164 if (windowState.mInputChannel == inputChannel) {
5165 return windowState;
5166 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005167 }
5168
Jeff Brown349703e2010-06-22 01:27:15 -07005169 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005170 }
5171
Jeff Brown349703e2010-06-22 01:27:15 -07005172 /* Updates the cached window information provided to the input dispatcher. */
5173 public void updateInputWindowsLw() {
5174 // Populate the input window list with information about all of the windows that
5175 // could potentially receive input.
5176 // As an optimization, we could try to prune the list of windows but this turns
5177 // out to be difficult because only the native code knows for sure which window
5178 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005179 final ArrayList<WindowState> windows = mWindows;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005180 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005181 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005182 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005183 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005184 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005185 continue;
5186 }
5187
Jeff Brown349703e2010-06-22 01:27:15 -07005188 final int flags = child.mAttrs.flags;
5189 final int type = child.mAttrs.type;
5190
5191 final boolean hasFocus = (child == mInputFocus);
5192 final boolean isVisible = child.isVisibleLw();
5193 final boolean hasWallpaper = (child == mWallpaperTarget)
5194 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
5195
5196 // Add a window to our list of input windows.
5197 final InputWindow inputWindow = mTempInputWindows.add();
5198 inputWindow.inputChannel = child.mInputChannel;
5199 inputWindow.layoutParamsFlags = flags;
5200 inputWindow.layoutParamsType = type;
5201 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5202 inputWindow.visible = isVisible;
5203 inputWindow.hasFocus = hasFocus;
5204 inputWindow.hasWallpaper = hasWallpaper;
5205 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
5206 inputWindow.ownerPid = child.mSession.mPid;
5207 inputWindow.ownerUid = child.mSession.mUid;
5208
5209 final Rect frame = child.mFrame;
5210 inputWindow.frameLeft = frame.left;
5211 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005212 inputWindow.frameRight = frame.right;
5213 inputWindow.frameBottom = frame.bottom;
5214
5215 final Rect visibleFrame = child.mVisibleFrame;
5216 inputWindow.visibleFrameLeft = visibleFrame.left;
5217 inputWindow.visibleFrameTop = visibleFrame.top;
5218 inputWindow.visibleFrameRight = visibleFrame.right;
5219 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005220
5221 switch (child.mTouchableInsets) {
5222 default:
5223 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5224 inputWindow.touchableAreaLeft = frame.left;
5225 inputWindow.touchableAreaTop = frame.top;
5226 inputWindow.touchableAreaRight = frame.right;
5227 inputWindow.touchableAreaBottom = frame.bottom;
5228 break;
5229
5230 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5231 Rect inset = child.mGivenContentInsets;
5232 inputWindow.touchableAreaLeft = frame.left + inset.left;
5233 inputWindow.touchableAreaTop = frame.top + inset.top;
5234 inputWindow.touchableAreaRight = frame.right - inset.right;
5235 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5236 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005237 }
Jeff Brown349703e2010-06-22 01:27:15 -07005238
5239 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5240 Rect inset = child.mGivenVisibleInsets;
5241 inputWindow.touchableAreaLeft = frame.left + inset.left;
5242 inputWindow.touchableAreaTop = frame.top + inset.top;
5243 inputWindow.touchableAreaRight = frame.right - inset.right;
5244 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005245 break;
5246 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005247 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005248 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005249
Jeff Brown349703e2010-06-22 01:27:15 -07005250 // Send windows to native code.
5251 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005252
Jeff Brown349703e2010-06-22 01:27:15 -07005253 // Clear the list in preparation for the next round.
5254 // Also avoids keeping InputChannel objects referenced unnecessarily.
5255 mTempInputWindows.clear();
5256 }
5257
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005258 /* Provides feedback for a virtual key down. */
5259 public void virtualKeyDownFeedback() {
5260 synchronized (mWindowMap) {
5261 mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5262 }
5263 }
5264
Jeff Brown349703e2010-06-22 01:27:15 -07005265 /* Notifies that an app switch key (BACK / HOME) has just been pressed.
5266 * This essentially starts a .5 second timeout for the application to process
5267 * subsequent input events while waiting for the app switch to occur. If it takes longer
5268 * than this, the pending events will be dropped.
5269 */
5270 public void notifyAppSwitchComing() {
5271 // TODO Not implemented yet. Should go in the native side.
5272 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005273
5274 /* Notifies that the lid switch changed state. */
5275 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5276 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5277 }
5278
Jeff Brown349703e2010-06-22 01:27:15 -07005279 /* Provides an opportunity for the window manager policy to intercept early key
5280 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005281 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5282 int policyFlags, boolean isScreenOn) {
5283 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5284 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005285 }
5286
5287 /* Provides an opportunity for the window manager policy to process a key before
5288 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005289 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5290 int action, int flags, int keyCode, int metaState, int repeatCount,
5291 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005292 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005293 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5294 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005295 }
5296
5297 /* Called when the current input focus changes.
5298 * Layer assignment is assumed to be complete by the time this is called.
5299 */
5300 public void setInputFocusLw(WindowState newWindow) {
5301 if (DEBUG_INPUT) {
5302 Slog.d(TAG, "Input focus has changed to " + newWindow);
5303 }
5304
5305 if (newWindow != mInputFocus) {
5306 if (newWindow != null && newWindow.canReceiveKeys()) {
5307 // If the new input focus is an error window or appears above the current
5308 // input focus, preempt any pending synchronous dispatch so that we can
5309 // start delivering events to the new input focus as soon as possible.
5310 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
5311 if (DEBUG_INPUT) {
5312 Slog.v(TAG, "New SYSTEM_ERROR window; resetting state");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005313 }
Jeff Brown349703e2010-06-22 01:27:15 -07005314 preemptInputDispatchLw();
5315 } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) {
5316 if (DEBUG_INPUT) {
5317 Slog.v(TAG, "Transferring focus to new window at higher layer: "
5318 + "old win layer=" + mInputFocus.mLayer
5319 + ", new win layer=" + newWindow.mLayer);
5320 }
5321 preemptInputDispatchLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005322 }
Jeff Brown349703e2010-06-22 01:27:15 -07005323
5324 // Displaying a window implicitly causes dispatching to be unpaused.
5325 // This is to protect against bugs if someone pauses dispatching but
5326 // forgets to resume.
5327 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005328 }
Jeff Brown349703e2010-06-22 01:27:15 -07005329
5330 mInputFocus = newWindow;
5331 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005332 }
5333 }
5334
Jeff Brown349703e2010-06-22 01:27:15 -07005335 /* Tells the dispatcher to stop waiting for its current synchronous event targets.
5336 * Essentially, just makes those dispatches asynchronous so a new dispatch cycle
5337 * can begin.
5338 */
5339 private void preemptInputDispatchLw() {
5340 mInputManager.preemptInputDispatch();
5341 }
5342
5343 public void setFocusedAppLw(AppWindowToken newApp) {
5344 // Focused app has changed.
5345 if (newApp == null) {
5346 mInputManager.setFocusedApplication(null);
5347 } else {
5348 mTempInputApplication.name = newApp.toString();
5349 mTempInputApplication.dispatchingTimeoutNanos =
5350 newApp.inputDispatchingTimeoutNanos;
5351 mTempInputApplication.token = newApp;
5352
5353 mInputManager.setFocusedApplication(mTempInputApplication);
5354 }
5355 }
5356
Jeff Brown349703e2010-06-22 01:27:15 -07005357 public void pauseDispatchingLw(WindowToken window) {
5358 if (! window.paused) {
5359 if (DEBUG_INPUT) {
5360 Slog.v(TAG, "Pausing WindowToken " + window);
5361 }
5362
5363 window.paused = true;
5364 updateInputWindowsLw();
5365 }
5366 }
5367
5368 public void resumeDispatchingLw(WindowToken window) {
5369 if (window.paused) {
5370 if (DEBUG_INPUT) {
5371 Slog.v(TAG, "Resuming WindowToken " + window);
5372 }
5373
5374 window.paused = false;
5375 updateInputWindowsLw();
5376 }
5377 }
5378
5379 public void freezeInputDispatchingLw() {
5380 if (! mInputDispatchFrozen) {
5381 if (DEBUG_INPUT) {
5382 Slog.v(TAG, "Freezing input dispatching");
5383 }
5384
5385 mInputDispatchFrozen = true;
5386 updateInputDispatchModeLw();
5387 }
5388 }
5389
5390 public void thawInputDispatchingLw() {
5391 if (mInputDispatchFrozen) {
5392 if (DEBUG_INPUT) {
5393 Slog.v(TAG, "Thawing input dispatching");
5394 }
5395
5396 mInputDispatchFrozen = false;
5397 updateInputDispatchModeLw();
5398 }
5399 }
5400
5401 public void setEventDispatchingLw(boolean enabled) {
5402 if (mInputDispatchEnabled != enabled) {
5403 if (DEBUG_INPUT) {
5404 Slog.v(TAG, "Setting event dispatching to " + enabled);
5405 }
5406
5407 mInputDispatchEnabled = enabled;
5408 updateInputDispatchModeLw();
5409 }
5410 }
5411
5412 private void updateInputDispatchModeLw() {
5413 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5414 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005417 public void pauseKeyDispatching(IBinder _token) {
5418 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5419 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005420 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005421 }
5422
5423 synchronized (mWindowMap) {
5424 WindowToken token = mTokenMap.get(_token);
5425 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005426 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005427 }
5428 }
5429 }
5430
5431 public void resumeKeyDispatching(IBinder _token) {
5432 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5433 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005434 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005435 }
5436
5437 synchronized (mWindowMap) {
5438 WindowToken token = mTokenMap.get(_token);
5439 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005440 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005441 }
5442 }
5443 }
5444
5445 public void setEventDispatching(boolean enabled) {
5446 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5447 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005448 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005449 }
5450
5451 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005452 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005453 }
5454 }
Romain Guy06882f82009-06-10 13:36:04 -07005455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005456 /**
5457 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005458 * Even when sync is false, this method may block while waiting for current
5459 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005460 *
5461 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005462 * {@link SystemClock#uptimeMillis()} as the timebase.)
5463 * @param sync If true, wait for the event to be completed before returning to the caller.
5464 * @return Returns true if event was dispatched, false if it was dropped for any reason
5465 */
5466 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5467 long downTime = ev.getDownTime();
5468 long eventTime = ev.getEventTime();
5469
5470 int action = ev.getAction();
5471 int code = ev.getKeyCode();
5472 int repeatCount = ev.getRepeatCount();
5473 int metaState = ev.getMetaState();
5474 int deviceId = ev.getDeviceId();
5475 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005476 int source = ev.getSource();
5477
5478 if (source == InputDevice.SOURCE_UNKNOWN) {
5479 source = InputDevice.SOURCE_KEYBOARD;
5480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005481
5482 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5483 if (downTime == 0) downTime = eventTime;
5484
5485 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005486 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005487
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005488 final int pid = Binder.getCallingPid();
5489 final int uid = Binder.getCallingUid();
5490 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005491
Jeff Brownbbda99d2010-07-28 15:48:59 -07005492 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5493 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5494 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5495 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005496
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005497 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005498 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005499 }
5500
5501 /**
5502 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005503 * Even when sync is false, this method may block while waiting for current
5504 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005505 *
5506 * @param ev A motion event describing the pointer (touch) action. (As noted in
5507 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005508 * {@link SystemClock#uptimeMillis()} as the timebase.)
5509 * @param sync If true, wait for the event to be completed before returning to the caller.
5510 * @return Returns true if event was dispatched, false if it was dropped for any reason
5511 */
5512 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005513 final int pid = Binder.getCallingPid();
5514 final int uid = Binder.getCallingUid();
5515 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005516
Jeff Brownc5ed5912010-07-14 18:48:53 -07005517 MotionEvent newEvent = MotionEvent.obtain(ev);
5518 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5519 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5520 }
5521
Jeff Brownbbda99d2010-07-28 15:48:59 -07005522 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5523 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5524 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5525 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005526
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005527 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005528 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005529 }
Romain Guy06882f82009-06-10 13:36:04 -07005530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005531 /**
5532 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005533 * Even when sync is false, this method may block while waiting for current
5534 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005535 *
5536 * @param ev A motion event describing the trackball action. (As noted in
5537 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005538 * {@link SystemClock#uptimeMillis()} as the timebase.)
5539 * @param sync If true, wait for the event to be completed before returning to the caller.
5540 * @return Returns true if event was dispatched, false if it was dropped for any reason
5541 */
5542 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005543 final int pid = Binder.getCallingPid();
5544 final int uid = Binder.getCallingUid();
5545 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005546
Jeff Brownc5ed5912010-07-14 18:48:53 -07005547 MotionEvent newEvent = MotionEvent.obtain(ev);
5548 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5549 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5550 }
5551
Jeff Brownbbda99d2010-07-28 15:48:59 -07005552 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5553 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5554 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5555 INJECTION_TIMEOUT_MILLIS);
5556
5557 Binder.restoreCallingIdentity(ident);
5558 return reportInjectionResult(result);
5559 }
5560
5561 /**
5562 * Inject an input event into the UI without waiting for dispatch to commence.
5563 * This variant is useful for fire-and-forget input event injection. It does not
5564 * block any longer than it takes to enqueue the input event.
5565 *
5566 * @param ev An input event. (Be sure to set the input source correctly.)
5567 * @return Returns true if event was dispatched, false if it was dropped for any reason
5568 */
5569 public boolean injectInputEventNoWait(InputEvent ev) {
5570 final int pid = Binder.getCallingPid();
5571 final int uid = Binder.getCallingUid();
5572 final long ident = Binder.clearCallingIdentity();
5573
5574 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5575 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5576 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005577
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005578 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005579 return reportInjectionResult(result);
5580 }
5581
5582 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005583 switch (result) {
5584 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5585 Slog.w(TAG, "Input event injection permission denied.");
5586 throw new SecurityException(
5587 "Injecting to another application requires INJECT_EVENTS permission");
5588 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005589 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005590 return true;
5591 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5592 Slog.w(TAG, "Input event injection timed out.");
5593 return false;
5594 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5595 default:
5596 Slog.w(TAG, "Input event injection failed.");
5597 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005599 }
Romain Guy06882f82009-06-10 13:36:04 -07005600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005601 private WindowState getFocusedWindow() {
5602 synchronized (mWindowMap) {
5603 return getFocusedWindowLocked();
5604 }
5605 }
5606
5607 private WindowState getFocusedWindowLocked() {
5608 return mCurrentFocus;
5609 }
Romain Guy06882f82009-06-10 13:36:04 -07005610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005611 public boolean detectSafeMode() {
5612 mSafeMode = mPolicy.detectSafeMode();
5613 return mSafeMode;
5614 }
Romain Guy06882f82009-06-10 13:36:04 -07005615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005616 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005617 synchronized(mWindowMap) {
5618 if (mDisplay != null) {
5619 throw new IllegalStateException("Display already initialized");
5620 }
5621 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5622 mDisplay = wm.getDefaultDisplay();
5623 mInitialDisplayWidth = mDisplay.getWidth();
5624 mInitialDisplayHeight = mDisplay.getHeight();
5625 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
5626 }
5627
5628 try {
5629 mActivityManager.updateConfiguration(null);
5630 } catch (RemoteException e) {
5631 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07005632
5633 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07005634 }
5635
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005636 // -------------------------------------------------------------
5637 // Client Session State
5638 // -------------------------------------------------------------
5639
5640 private final class Session extends IWindowSession.Stub
5641 implements IBinder.DeathRecipient {
5642 final IInputMethodClient mClient;
5643 final IInputContext mInputContext;
5644 final int mUid;
5645 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005646 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005647 SurfaceSession mSurfaceSession;
5648 int mNumWindow = 0;
5649 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07005650
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005651 public Session(IInputMethodClient client, IInputContext inputContext) {
5652 mClient = client;
5653 mInputContext = inputContext;
5654 mUid = Binder.getCallingUid();
5655 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005656 StringBuilder sb = new StringBuilder();
5657 sb.append("Session{");
5658 sb.append(Integer.toHexString(System.identityHashCode(this)));
5659 sb.append(" uid ");
5660 sb.append(mUid);
5661 sb.append("}");
5662 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07005663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005664 synchronized (mWindowMap) {
5665 if (mInputMethodManager == null && mHaveInputMethods) {
5666 IBinder b = ServiceManager.getService(
5667 Context.INPUT_METHOD_SERVICE);
5668 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
5669 }
5670 }
5671 long ident = Binder.clearCallingIdentity();
5672 try {
5673 // Note: it is safe to call in to the input method manager
5674 // here because we are not holding our lock.
5675 if (mInputMethodManager != null) {
5676 mInputMethodManager.addClient(client, inputContext,
5677 mUid, mPid);
5678 } else {
5679 client.setUsingInputMethod(false);
5680 }
5681 client.asBinder().linkToDeath(this, 0);
5682 } catch (RemoteException e) {
5683 // The caller has died, so we can just forget about this.
5684 try {
5685 if (mInputMethodManager != null) {
5686 mInputMethodManager.removeClient(client);
5687 }
5688 } catch (RemoteException ee) {
5689 }
5690 } finally {
5691 Binder.restoreCallingIdentity(ident);
5692 }
5693 }
Romain Guy06882f82009-06-10 13:36:04 -07005694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005695 @Override
5696 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
5697 throws RemoteException {
5698 try {
5699 return super.onTransact(code, data, reply, flags);
5700 } catch (RuntimeException e) {
5701 // Log all 'real' exceptions thrown to the caller
5702 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005703 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005704 }
5705 throw e;
5706 }
5707 }
5708
5709 public void binderDied() {
5710 // Note: it is safe to call in to the input method manager
5711 // here because we are not holding our lock.
5712 try {
5713 if (mInputMethodManager != null) {
5714 mInputMethodManager.removeClient(mClient);
5715 }
5716 } catch (RemoteException e) {
5717 }
5718 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07005719 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005720 mClientDead = true;
5721 killSessionLocked();
5722 }
5723 }
5724
5725 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005726 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
5727 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
5728 outInputChannel);
5729 }
5730
5731 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005732 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005733 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005734 }
Romain Guy06882f82009-06-10 13:36:04 -07005735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005736 public void remove(IWindow window) {
5737 removeWindow(this, window);
5738 }
Romain Guy06882f82009-06-10 13:36:04 -07005739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005740 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
5741 int requestedWidth, int requestedHeight, int viewFlags,
5742 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005743 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005744 return relayoutWindow(this, window, attrs,
5745 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07005746 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005747 }
Romain Guy06882f82009-06-10 13:36:04 -07005748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005749 public void setTransparentRegion(IWindow window, Region region) {
5750 setTransparentRegionWindow(this, window, region);
5751 }
Romain Guy06882f82009-06-10 13:36:04 -07005752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005753 public void setInsets(IWindow window, int touchableInsets,
5754 Rect contentInsets, Rect visibleInsets) {
5755 setInsetsWindow(this, window, touchableInsets, contentInsets,
5756 visibleInsets);
5757 }
Romain Guy06882f82009-06-10 13:36:04 -07005758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005759 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
5760 getWindowDisplayFrame(this, window, outDisplayFrame);
5761 }
Romain Guy06882f82009-06-10 13:36:04 -07005762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005763 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005764 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005765 TAG, "IWindow finishDrawing called for " + window);
5766 finishDrawingWindow(this, window);
5767 }
5768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005769 public void setInTouchMode(boolean mode) {
5770 synchronized(mWindowMap) {
5771 mInTouchMode = mode;
5772 }
5773 }
5774
5775 public boolean getInTouchMode() {
5776 synchronized(mWindowMap) {
5777 return mInTouchMode;
5778 }
5779 }
5780
5781 public boolean performHapticFeedback(IWindow window, int effectId,
5782 boolean always) {
5783 synchronized(mWindowMap) {
5784 long ident = Binder.clearCallingIdentity();
5785 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07005786 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005787 windowForClientLocked(this, window, true),
5788 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005789 } finally {
5790 Binder.restoreCallingIdentity(ident);
5791 }
5792 }
5793 }
Romain Guy06882f82009-06-10 13:36:04 -07005794
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005795 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005796 synchronized(mWindowMap) {
5797 long ident = Binder.clearCallingIdentity();
5798 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005799 setWindowWallpaperPositionLocked(
5800 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08005801 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07005802 } finally {
5803 Binder.restoreCallingIdentity(ident);
5804 }
5805 }
5806 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005807
Dianne Hackborn19382ac2009-09-11 21:13:37 -07005808 public void wallpaperOffsetsComplete(IBinder window) {
5809 WindowManagerService.this.wallpaperOffsetsComplete(window);
5810 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005811
Dianne Hackborn75804932009-10-20 20:15:20 -07005812 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
5813 int z, Bundle extras, boolean sync) {
5814 synchronized(mWindowMap) {
5815 long ident = Binder.clearCallingIdentity();
5816 try {
5817 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005818 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07005819 action, x, y, z, extras, sync);
5820 } finally {
5821 Binder.restoreCallingIdentity(ident);
5822 }
5823 }
5824 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005825
Dianne Hackborn75804932009-10-20 20:15:20 -07005826 public void wallpaperCommandComplete(IBinder window, Bundle result) {
5827 WindowManagerService.this.wallpaperCommandComplete(window, result);
5828 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005830 void windowAddedLocked() {
5831 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005832 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005833 TAG, "First window added to " + this + ", creating SurfaceSession");
5834 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08005835 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005836 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005837 mSessions.add(this);
5838 }
5839 mNumWindow++;
5840 }
5841
5842 void windowRemovedLocked() {
5843 mNumWindow--;
5844 killSessionLocked();
5845 }
Romain Guy06882f82009-06-10 13:36:04 -07005846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005847 void killSessionLocked() {
5848 if (mNumWindow <= 0 && mClientDead) {
5849 mSessions.remove(this);
5850 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005851 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005852 TAG, "Last window removed from " + this
5853 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08005854 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07005855 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005856 try {
5857 mSurfaceSession.kill();
5858 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005859 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005860 + mSurfaceSession + " in session " + this
5861 + ": " + e.toString());
5862 }
5863 mSurfaceSession = null;
5864 }
5865 }
5866 }
Romain Guy06882f82009-06-10 13:36:04 -07005867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005868 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005869 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
5870 pw.print(" mClientDead="); pw.print(mClientDead);
5871 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005872 }
5873
5874 @Override
5875 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005876 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005877 }
5878 }
5879
5880 // -------------------------------------------------------------
5881 // Client Window State
5882 // -------------------------------------------------------------
5883
5884 private final class WindowState implements WindowManagerPolicy.WindowState {
5885 final Session mSession;
5886 final IWindow mClient;
5887 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07005888 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005889 AppWindowToken mAppToken;
5890 AppWindowToken mTargetAppToken;
5891 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
5892 final DeathRecipient mDeathRecipient;
5893 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07005894 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005895 final int mBaseLayer;
5896 final int mSubLayer;
5897 final boolean mLayoutAttached;
5898 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07005899 final boolean mIsWallpaper;
5900 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005901 int mViewVisibility;
5902 boolean mPolicyVisibility = true;
5903 boolean mPolicyVisibilityAfterAnim = true;
5904 boolean mAppFreezing;
5905 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07005906 boolean mReportDestroySurface;
5907 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005908 boolean mAttachedHidden; // is our parent window hidden?
5909 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07005910 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005911 int mRequestedWidth;
5912 int mRequestedHeight;
5913 int mLastRequestedWidth;
5914 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005915 int mLayer;
5916 int mAnimLayer;
5917 int mLastLayer;
5918 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07005919 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07005920 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005921
Dianne Hackborne36d6e22010-02-17 19:46:25 -08005922 int mLayoutSeq = -1;
5923
5924 Configuration mConfiguration = null;
5925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005926 // Actual frame shown on-screen (may be modified by animation)
5927 final Rect mShownFrame = new Rect();
5928 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005930 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08005931 * Set when we have changed the size of the surface, to know that
5932 * we must tell them application to resize (and thus redraw itself).
5933 */
5934 boolean mSurfaceResized;
5935
5936 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005937 * Insets that determine the actually visible area
5938 */
5939 final Rect mVisibleInsets = new Rect();
5940 final Rect mLastVisibleInsets = new Rect();
5941 boolean mVisibleInsetsChanged;
5942
5943 /**
5944 * Insets that are covered by system windows
5945 */
5946 final Rect mContentInsets = new Rect();
5947 final Rect mLastContentInsets = new Rect();
5948 boolean mContentInsetsChanged;
5949
5950 /**
5951 * Set to true if we are waiting for this window to receive its
5952 * given internal insets before laying out other windows based on it.
5953 */
5954 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07005955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005956 /**
5957 * These are the content insets that were given during layout for
5958 * this window, to be applied to windows behind it.
5959 */
5960 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005962 /**
5963 * These are the visible insets that were given during layout for
5964 * this window, to be applied to windows behind it.
5965 */
5966 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07005967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005968 /**
5969 * Flag indicating whether the touchable region should be adjusted by
5970 * the visible insets; if false the area outside the visible insets is
5971 * NOT touchable, so we must use those to adjust the frame during hit
5972 * tests.
5973 */
5974 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07005975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005976 // Current transformation being applied.
5977 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
5978 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
5979 float mHScale=1, mVScale=1;
5980 float mLastHScale=1, mLastVScale=1;
5981 final Matrix mTmpMatrix = new Matrix();
5982
5983 // "Real" frame that the application sees.
5984 final Rect mFrame = new Rect();
5985 final Rect mLastFrame = new Rect();
5986
5987 final Rect mContainingFrame = new Rect();
5988 final Rect mDisplayFrame = new Rect();
5989 final Rect mContentFrame = new Rect();
5990 final Rect mVisibleFrame = new Rect();
5991
5992 float mShownAlpha = 1;
5993 float mAlpha = 1;
5994 float mLastAlpha = 1;
5995
5996 // Set to true if, when the window gets displayed, it should perform
5997 // an enter animation.
5998 boolean mEnterAnimationPending;
5999
6000 // Currently running animation.
6001 boolean mAnimating;
6002 boolean mLocalAnimating;
6003 Animation mAnimation;
6004 boolean mAnimationIsEntrance;
6005 boolean mHasTransformation;
6006 boolean mHasLocalTransformation;
6007 final Transformation mTransformation = new Transformation();
6008
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006009 // If a window showing a wallpaper: the requested offset for the
6010 // wallpaper; if a wallpaper window: the currently applied offset.
6011 float mWallpaperX = -1;
6012 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006013
6014 // If a window showing a wallpaper: what fraction of the offset
6015 // range corresponds to a full virtual screen.
6016 float mWallpaperXStep = -1;
6017 float mWallpaperYStep = -1;
6018
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006019 // Wallpaper windows: pixels offset based on above variables.
6020 int mXOffset;
6021 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023 // This is set after IWindowSession.relayout() has been called at
6024 // least once for the window. It allows us to detect the situation
6025 // where we don't yet have a surface, but should have one soon, so
6026 // we can give the window focus before waiting for the relayout.
6027 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006029 // This is set after the Surface has been created but before the
6030 // window has been drawn. During this time the surface is hidden.
6031 boolean mDrawPending;
6032
6033 // This is set after the window has finished drawing for the first
6034 // time but before its surface is shown. The surface will be
6035 // displayed when the next layout is run.
6036 boolean mCommitDrawPending;
6037
6038 // This is set during the time after the window's drawing has been
6039 // committed, and before its surface is actually shown. It is used
6040 // to delay showing the surface until all windows in a token are ready
6041 // to be shown.
6042 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006044 // Set when the window has been shown in the screen the first time.
6045 boolean mHasDrawn;
6046
6047 // Currently running an exit animation?
6048 boolean mExiting;
6049
6050 // Currently on the mDestroySurface list?
6051 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006053 // Completely remove from window manager after exit animation?
6054 boolean mRemoveOnExit;
6055
6056 // Set when the orientation is changing and this window has not yet
6057 // been updated for the new orientation.
6058 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006060 // Is this window now (or just being) removed?
6061 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006062
Dianne Hackborn16064f92010-03-25 00:47:24 -07006063 // For debugging, this is the last information given to the surface flinger.
6064 boolean mSurfaceShown;
6065 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6066 int mSurfaceLayer;
6067 float mSurfaceAlpha;
6068
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006069 // Input channel
6070 InputChannel mInputChannel;
6071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072 WindowState(Session s, IWindow c, WindowToken token,
6073 WindowState attachedWindow, WindowManager.LayoutParams a,
6074 int viewVisibility) {
6075 mSession = s;
6076 mClient = c;
6077 mToken = token;
6078 mAttrs.copyFrom(a);
6079 mViewVisibility = viewVisibility;
6080 DeathRecipient deathRecipient = new DeathRecipient();
6081 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006082 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006083 TAG, "Window " + this + " client=" + c.asBinder()
6084 + " token=" + token + " (" + mAttrs.token + ")");
6085 try {
6086 c.asBinder().linkToDeath(deathRecipient, 0);
6087 } catch (RemoteException e) {
6088 mDeathRecipient = null;
6089 mAttachedWindow = null;
6090 mLayoutAttached = false;
6091 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006092 mIsWallpaper = false;
6093 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006094 mBaseLayer = 0;
6095 mSubLayer = 0;
6096 return;
6097 }
6098 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006100 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6101 mAttrs.type <= LAST_SUB_WINDOW)) {
6102 // The multiplier here is to reserve space for multiple
6103 // windows in the same type layer.
6104 mBaseLayer = mPolicy.windowTypeToLayerLw(
6105 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6106 + TYPE_LAYER_OFFSET;
6107 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6108 mAttachedWindow = attachedWindow;
6109 mAttachedWindow.mChildWindows.add(this);
6110 mLayoutAttached = mAttrs.type !=
6111 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6112 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6113 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006114 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6115 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 } else {
6117 // The multiplier here is to reserve space for multiple
6118 // windows in the same type layer.
6119 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6120 * TYPE_LAYER_MULTIPLIER
6121 + TYPE_LAYER_OFFSET;
6122 mSubLayer = 0;
6123 mAttachedWindow = null;
6124 mLayoutAttached = false;
6125 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6126 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006127 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6128 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006129 }
6130
6131 WindowState appWin = this;
6132 while (appWin.mAttachedWindow != null) {
6133 appWin = mAttachedWindow;
6134 }
6135 WindowToken appToken = appWin.mToken;
6136 while (appToken.appWindowToken == null) {
6137 WindowToken parent = mTokenMap.get(appToken.token);
6138 if (parent == null || appToken == parent) {
6139 break;
6140 }
6141 appToken = parent;
6142 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006143 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 mAppToken = appToken.appWindowToken;
6145
6146 mSurface = null;
6147 mRequestedWidth = 0;
6148 mRequestedHeight = 0;
6149 mLastRequestedWidth = 0;
6150 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006151 mXOffset = 0;
6152 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006153 mLayer = 0;
6154 mAnimLayer = 0;
6155 mLastLayer = 0;
6156 }
6157
6158 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006159 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006160 TAG, "Attaching " + this + " token=" + mToken
6161 + ", list=" + mToken.windows);
6162 mSession.windowAddedLocked();
6163 }
6164
6165 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6166 mHaveFrame = true;
6167
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006168 final Rect container = mContainingFrame;
6169 container.set(pf);
6170
6171 final Rect display = mDisplayFrame;
6172 display.set(df);
6173
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006174 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006175 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006176 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6177 display.intersect(mCompatibleScreenFrame);
6178 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006179 }
6180
6181 final int pw = container.right - container.left;
6182 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006183
6184 int w,h;
6185 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6186 w = mAttrs.width < 0 ? pw : mAttrs.width;
6187 h = mAttrs.height< 0 ? ph : mAttrs.height;
6188 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006189 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6190 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006191 }
Romain Guy06882f82009-06-10 13:36:04 -07006192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006193 final Rect content = mContentFrame;
6194 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006196 final Rect visible = mVisibleFrame;
6197 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006199 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006200 final int fw = frame.width();
6201 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006203 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6204 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6205
6206 Gravity.apply(mAttrs.gravity, w, h, container,
6207 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6208 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6209
6210 //System.out.println("Out: " + mFrame);
6211
6212 // Now make sure the window fits in the overall display.
6213 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006215 // Make sure the content and visible frames are inside of the
6216 // final window frame.
6217 if (content.left < frame.left) content.left = frame.left;
6218 if (content.top < frame.top) content.top = frame.top;
6219 if (content.right > frame.right) content.right = frame.right;
6220 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6221 if (visible.left < frame.left) visible.left = frame.left;
6222 if (visible.top < frame.top) visible.top = frame.top;
6223 if (visible.right > frame.right) visible.right = frame.right;
6224 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006226 final Rect contentInsets = mContentInsets;
6227 contentInsets.left = content.left-frame.left;
6228 contentInsets.top = content.top-frame.top;
6229 contentInsets.right = frame.right-content.right;
6230 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006232 final Rect visibleInsets = mVisibleInsets;
6233 visibleInsets.left = visible.left-frame.left;
6234 visibleInsets.top = visible.top-frame.top;
6235 visibleInsets.right = frame.right-visible.right;
6236 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006237
Dianne Hackborn284ac932009-08-28 10:34:25 -07006238 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6239 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006240 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006241 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006243 if (localLOGV) {
6244 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6245 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006246 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006247 + mRequestedWidth + ", mRequestedheight="
6248 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6249 + "): frame=" + mFrame.toShortString()
6250 + " ci=" + contentInsets.toShortString()
6251 + " vi=" + visibleInsets.toShortString());
6252 //}
6253 }
6254 }
Romain Guy06882f82009-06-10 13:36:04 -07006255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006256 public Rect getFrameLw() {
6257 return mFrame;
6258 }
6259
6260 public Rect getShownFrameLw() {
6261 return mShownFrame;
6262 }
6263
6264 public Rect getDisplayFrameLw() {
6265 return mDisplayFrame;
6266 }
6267
6268 public Rect getContentFrameLw() {
6269 return mContentFrame;
6270 }
6271
6272 public Rect getVisibleFrameLw() {
6273 return mVisibleFrame;
6274 }
6275
6276 public boolean getGivenInsetsPendingLw() {
6277 return mGivenInsetsPending;
6278 }
6279
6280 public Rect getGivenContentInsetsLw() {
6281 return mGivenContentInsets;
6282 }
Romain Guy06882f82009-06-10 13:36:04 -07006283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006284 public Rect getGivenVisibleInsetsLw() {
6285 return mGivenVisibleInsets;
6286 }
Romain Guy06882f82009-06-10 13:36:04 -07006287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006288 public WindowManager.LayoutParams getAttrs() {
6289 return mAttrs;
6290 }
6291
6292 public int getSurfaceLayer() {
6293 return mLayer;
6294 }
Romain Guy06882f82009-06-10 13:36:04 -07006295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006296 public IApplicationToken getAppToken() {
6297 return mAppToken != null ? mAppToken.appToken : null;
6298 }
Jeff Brown349703e2010-06-22 01:27:15 -07006299
6300 public long getInputDispatchingTimeoutNanos() {
6301 return mAppToken != null
6302 ? mAppToken.inputDispatchingTimeoutNanos
6303 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6304 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006305
6306 public boolean hasAppShownWindows() {
6307 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6308 }
6309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006310 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006311 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006312 TAG, "Setting animation in " + this + ": " + anim);
6313 mAnimating = false;
6314 mLocalAnimating = false;
6315 mAnimation = anim;
6316 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6317 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6318 }
6319
6320 public void clearAnimation() {
6321 if (mAnimation != null) {
6322 mAnimating = true;
6323 mLocalAnimating = false;
6324 mAnimation = null;
6325 }
6326 }
Romain Guy06882f82009-06-10 13:36:04 -07006327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006328 Surface createSurfaceLocked() {
6329 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006330 mReportDestroySurface = false;
6331 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006332 mDrawPending = true;
6333 mCommitDrawPending = false;
6334 mReadyToShow = false;
6335 if (mAppToken != null) {
6336 mAppToken.allDrawn = false;
6337 }
6338
6339 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006340 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006341 flags |= Surface.PUSH_BUFFERS;
6342 }
6343
6344 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6345 flags |= Surface.SECURE;
6346 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006347 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 TAG, "Creating surface in session "
6349 + mSession.mSurfaceSession + " window " + this
6350 + " w=" + mFrame.width()
6351 + " h=" + mFrame.height() + " format="
6352 + mAttrs.format + " flags=" + flags);
6353
6354 int w = mFrame.width();
6355 int h = mFrame.height();
6356 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6357 // for a scaled surface, we always want the requested
6358 // size.
6359 w = mRequestedWidth;
6360 h = mRequestedHeight;
6361 }
6362
Romain Guy9825ec62009-10-01 00:58:09 -07006363 // Something is wrong and SurfaceFlinger will not like this,
6364 // try to revert to sane values
6365 if (w <= 0) w = 1;
6366 if (h <= 0) h = 1;
6367
Dianne Hackborn16064f92010-03-25 00:47:24 -07006368 mSurfaceShown = false;
6369 mSurfaceLayer = 0;
6370 mSurfaceAlpha = 1;
6371 mSurfaceX = 0;
6372 mSurfaceY = 0;
6373 mSurfaceW = w;
6374 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006375 try {
6376 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006377 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006378 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006379 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006380 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006381 + mSurface + " IN SESSION "
6382 + mSession.mSurfaceSession
6383 + ": pid=" + mSession.mPid + " format="
6384 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006385 + Integer.toHexString(flags)
6386 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006387 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006388 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 reclaimSomeSurfaceMemoryLocked(this, "create");
6390 return null;
6391 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006392 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006393 return null;
6394 }
Romain Guy06882f82009-06-10 13:36:04 -07006395
Joe Onorato8a9b2202010-02-26 18:56:32 -08006396 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006397 TAG, "Got surface: " + mSurface
6398 + ", set left=" + mFrame.left + " top=" + mFrame.top
6399 + ", animLayer=" + mAnimLayer);
6400 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006401 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006402 if (SHOW_TRANSACTIONS) logSurface(this,
6403 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6404 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6405 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406 }
6407 Surface.openTransaction();
6408 try {
6409 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006410 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006411 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006412 mSurface.setPosition(mSurfaceX, mSurfaceY);
6413 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006414 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006415 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006416 mSurface.hide();
6417 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006418 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006419 mSurface.setFlags(Surface.SURFACE_DITHER,
6420 Surface.SURFACE_DITHER);
6421 }
6422 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006423 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006424 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6425 }
6426 mLastHidden = true;
6427 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006428 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006429 Surface.closeTransaction();
6430 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006431 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006432 TAG, "Created surface " + this);
6433 }
6434 return mSurface;
6435 }
Romain Guy06882f82009-06-10 13:36:04 -07006436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006437 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006438 if (mAppToken != null && this == mAppToken.startingWindow) {
6439 mAppToken.startingDisplayed = false;
6440 }
Romain Guy06882f82009-06-10 13:36:04 -07006441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006442 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006443 mDrawPending = false;
6444 mCommitDrawPending = false;
6445 mReadyToShow = false;
6446
6447 int i = mChildWindows.size();
6448 while (i > 0) {
6449 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006450 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006451 c.mAttachedHidden = true;
6452 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006453
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006454 if (mReportDestroySurface) {
6455 mReportDestroySurface = false;
6456 mSurfacePendingDestroy = true;
6457 try {
6458 mClient.dispatchGetNewSurface();
6459 // We'll really destroy on the next time around.
6460 return;
6461 } catch (RemoteException e) {
6462 }
6463 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006465 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006466 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006467 RuntimeException e = null;
6468 if (!HIDE_STACK_CRAWLS) {
6469 e = new RuntimeException();
6470 e.fillInStackTrace();
6471 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006472 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006473 + mSurface + ", session " + mSession, e);
6474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006475 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006476 RuntimeException e = null;
6477 if (!HIDE_STACK_CRAWLS) {
6478 e = new RuntimeException();
6479 e.fillInStackTrace();
6480 }
6481 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006483 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006484 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006485 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006486 + " surface " + mSurface + " session " + mSession
6487 + ": " + e.toString());
6488 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006489
Dianne Hackborn16064f92010-03-25 00:47:24 -07006490 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006491 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006492 }
6493 }
6494
6495 boolean finishDrawingLocked() {
6496 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006497 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006498 TAG, "finishDrawingLocked: " + mSurface);
6499 mCommitDrawPending = true;
6500 mDrawPending = false;
6501 return true;
6502 }
6503 return false;
6504 }
6505
6506 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006507 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006508 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006509 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006510 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006511 }
6512 mCommitDrawPending = false;
6513 mReadyToShow = true;
6514 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6515 final AppWindowToken atoken = mAppToken;
6516 if (atoken == null || atoken.allDrawn || starting) {
6517 performShowLocked();
6518 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006519 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006520 }
6521
6522 // This must be called while inside a transaction.
6523 boolean performShowLocked() {
6524 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006525 RuntimeException e = null;
6526 if (!HIDE_STACK_CRAWLS) {
6527 e = new RuntimeException();
6528 e.fillInStackTrace();
6529 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006530 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6532 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6533 }
6534 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006535 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6536 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006537 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006538 + " during animation: policyVis=" + mPolicyVisibility
6539 + " attHidden=" + mAttachedHidden
6540 + " tok.hiddenRequested="
6541 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07006542 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006543 + (mAppToken != null ? mAppToken.hidden : false)
6544 + " animating=" + mAnimating
6545 + " tok animating="
6546 + (mAppToken != null ? mAppToken.animating : false));
6547 if (!showSurfaceRobustlyLocked(this)) {
6548 return false;
6549 }
6550 mLastAlpha = -1;
6551 mHasDrawn = true;
6552 mLastHidden = false;
6553 mReadyToShow = false;
6554 enableScreenIfNeededLocked();
6555
6556 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07006557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006558 int i = mChildWindows.size();
6559 while (i > 0) {
6560 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006561 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006562 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006563 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07006564 if (c.mSurface != null) {
6565 c.performShowLocked();
6566 // It hadn't been shown, which means layout not
6567 // performed on it, so now we want to make sure to
6568 // do a layout. If called from within the transaction
6569 // loop, this will cause it to restart with a new
6570 // layout.
6571 mLayoutNeeded = true;
6572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006573 }
6574 }
Romain Guy06882f82009-06-10 13:36:04 -07006575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006576 if (mAttrs.type != TYPE_APPLICATION_STARTING
6577 && mAppToken != null) {
6578 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006579
Dianne Hackborn248b1882009-09-16 16:46:44 -07006580 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006581 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006582 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006583 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07006584 // If this initial window is animating, stop it -- we
6585 // will do an animation to reveal it from behind the
6586 // starting window, so there is no need for it to also
6587 // be doing its own stuff.
6588 if (mAnimation != null) {
6589 mAnimation = null;
6590 // Make sure we clean up the animation.
6591 mAnimating = true;
6592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006593 mFinishedStarting.add(mAppToken);
6594 mH.sendEmptyMessage(H.FINISHED_STARTING);
6595 }
6596 mAppToken.updateReportedVisibilityLocked();
6597 }
6598 }
6599 return true;
6600 }
Romain Guy06882f82009-06-10 13:36:04 -07006601
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006602 // This must be called while inside a transaction. Returns true if
6603 // there is more animation to run.
6604 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08006605 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006606 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07006607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006608 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
6609 mHasTransformation = true;
6610 mHasLocalTransformation = true;
6611 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006612 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006613 TAG, "Starting animation in " + this +
6614 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
6615 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
6616 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
6617 mAnimation.setStartTime(currentTime);
6618 mLocalAnimating = true;
6619 mAnimating = true;
6620 }
6621 mTransformation.clear();
6622 final boolean more = mAnimation.getTransformation(
6623 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006624 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006625 TAG, "Stepped animation in " + this +
6626 ": more=" + more + ", xform=" + mTransformation);
6627 if (more) {
6628 // we're not done!
6629 return true;
6630 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006631 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006632 TAG, "Finished animation in " + this +
6633 " @ " + currentTime);
6634 mAnimation = null;
6635 //WindowManagerService.this.dump();
6636 }
6637 mHasLocalTransformation = false;
6638 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006639 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006640 // When our app token is animating, we kind-of pretend like
6641 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
6642 // part of this check means that we will only do this if
6643 // our window is not currently exiting, or it is not
6644 // locally animating itself. The idea being that one that
6645 // is exiting and doing a local animation should be removed
6646 // once that animation is done.
6647 mAnimating = true;
6648 mHasTransformation = true;
6649 mTransformation.clear();
6650 return false;
6651 } else if (mHasTransformation) {
6652 // Little trick to get through the path below to act like
6653 // we have finished an animation.
6654 mAnimating = true;
6655 } else if (isAnimating()) {
6656 mAnimating = true;
6657 }
6658 } else if (mAnimation != null) {
6659 // If the display is frozen, and there is a pending animation,
6660 // clear it and make sure we run the cleanup code.
6661 mAnimating = true;
6662 mLocalAnimating = true;
6663 mAnimation = null;
6664 }
Romain Guy06882f82009-06-10 13:36:04 -07006665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006666 if (!mAnimating && !mLocalAnimating) {
6667 return false;
6668 }
6669
Joe Onorato8a9b2202010-02-26 18:56:32 -08006670 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006671 TAG, "Animation done in " + this + ": exiting=" + mExiting
6672 + ", reportedVisible="
6673 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07006674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006675 mAnimating = false;
6676 mLocalAnimating = false;
6677 mAnimation = null;
6678 mAnimLayer = mLayer;
6679 if (mIsImWindow) {
6680 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006681 } else if (mIsWallpaper) {
6682 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006683 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006684 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685 + " anim layer: " + mAnimLayer);
6686 mHasTransformation = false;
6687 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08006688 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
6689 if (DEBUG_VISIBILITY) {
6690 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
6691 + mPolicyVisibilityAfterAnim);
6692 }
6693 mPolicyVisibility = mPolicyVisibilityAfterAnim;
6694 if (!mPolicyVisibility) {
6695 if (mCurrentFocus == this) {
6696 mFocusMayChange = true;
6697 }
6698 // Window is no longer visible -- make sure if we were waiting
6699 // for it to be displayed before enabling the display, that
6700 // we allow the display to be enabled now.
6701 enableScreenIfNeededLocked();
6702 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08006703 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006704 mTransformation.clear();
6705 if (mHasDrawn
6706 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
6707 && mAppToken != null
6708 && mAppToken.firstWindowDrawn
6709 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006710 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006711 + mToken + ": first real window done animating");
6712 mFinishedStarting.add(mAppToken);
6713 mH.sendEmptyMessage(H.FINISHED_STARTING);
6714 }
Romain Guy06882f82009-06-10 13:36:04 -07006715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006716 finishExit();
6717
6718 if (mAppToken != null) {
6719 mAppToken.updateReportedVisibilityLocked();
6720 }
6721
6722 return false;
6723 }
6724
6725 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006726 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006727 TAG, "finishExit in " + this
6728 + ": exiting=" + mExiting
6729 + " remove=" + mRemoveOnExit
6730 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07006731
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006732 final int N = mChildWindows.size();
6733 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07006734 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006735 }
Romain Guy06882f82009-06-10 13:36:04 -07006736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006737 if (!mExiting) {
6738 return;
6739 }
Romain Guy06882f82009-06-10 13:36:04 -07006740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006741 if (isWindowAnimating()) {
6742 return;
6743 }
6744
Joe Onorato8a9b2202010-02-26 18:56:32 -08006745 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006746 TAG, "Exit animation finished in " + this
6747 + ": remove=" + mRemoveOnExit);
6748 if (mSurface != null) {
6749 mDestroySurface.add(this);
6750 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006751 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006752 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006753 try {
6754 mSurface.hide();
6755 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006756 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006757 }
6758 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006759 }
6760 mExiting = false;
6761 if (mRemoveOnExit) {
6762 mPendingRemove.add(this);
6763 mRemoveOnExit = false;
6764 }
6765 }
Romain Guy06882f82009-06-10 13:36:04 -07006766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006767 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
6768 if (dsdx < .99999f || dsdx > 1.00001f) return false;
6769 if (dtdy < .99999f || dtdy > 1.00001f) return false;
6770 if (dtdx < -.000001f || dtdx > .000001f) return false;
6771 if (dsdy < -.000001f || dsdy > .000001f) return false;
6772 return true;
6773 }
Romain Guy06882f82009-06-10 13:36:04 -07006774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006775 void computeShownFrameLocked() {
6776 final boolean selfTransformation = mHasLocalTransformation;
6777 Transformation attachedTransformation =
6778 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
6779 ? mAttachedWindow.mTransformation : null;
6780 Transformation appTransformation =
6781 (mAppToken != null && mAppToken.hasTransformation)
6782 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006783
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006784 // Wallpapers are animated based on the "real" window they
6785 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006786 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07006787 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07006788 if (mWallpaperTarget.mHasLocalTransformation &&
6789 mWallpaperTarget.mAnimation != null &&
6790 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006791 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006792 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006793 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006794 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006795 }
6796 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07006797 mWallpaperTarget.mAppToken.hasTransformation &&
6798 mWallpaperTarget.mAppToken.animation != null &&
6799 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006800 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07006801 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006802 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07006803 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006804 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 if (selfTransformation || attachedTransformation != null
6808 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07006809 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006810 final Rect frame = mFrame;
6811 final float tmpFloats[] = mTmpFloats;
6812 final Matrix tmpMatrix = mTmpMatrix;
6813
6814 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07006815 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006816 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006817 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006818 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07006819 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006820 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006821 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006822 }
6823 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07006824 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006825 }
6826
6827 // "convert" it into SurfaceFlinger's format
6828 // (a 2x2 matrix + an offset)
6829 // Here we must not transform the position of the surface
6830 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08006831 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07006832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006833 tmpMatrix.getValues(tmpFloats);
6834 mDsDx = tmpFloats[Matrix.MSCALE_X];
6835 mDtDx = tmpFloats[Matrix.MSKEW_X];
6836 mDsDy = tmpFloats[Matrix.MSKEW_Y];
6837 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006838 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
6839 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006840 int w = frame.width();
6841 int h = frame.height();
6842 mShownFrame.set(x, y, x+w, y+h);
6843
6844 // Now set the alpha... but because our current hardware
6845 // can't do alpha transformation on a non-opaque surface,
6846 // turn it off if we are running an animation that is also
6847 // transforming since it is more important to have that
6848 // animation be smooth.
6849 mShownAlpha = mAlpha;
6850 if (!mLimitedAlphaCompositing
6851 || (!PixelFormat.formatHasAlpha(mAttrs.format)
6852 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
6853 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006854 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006855 if (selfTransformation) {
6856 mShownAlpha *= mTransformation.getAlpha();
6857 }
6858 if (attachedTransformation != null) {
6859 mShownAlpha *= attachedTransformation.getAlpha();
6860 }
6861 if (appTransformation != null) {
6862 mShownAlpha *= appTransformation.getAlpha();
6863 }
6864 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006865 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006866 }
Romain Guy06882f82009-06-10 13:36:04 -07006867
Joe Onorato8a9b2202010-02-26 18:56:32 -08006868 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006869 TAG, "Continuing animation in " + this +
6870 ": " + mShownFrame +
6871 ", alpha=" + mTransformation.getAlpha());
6872 return;
6873 }
Romain Guy06882f82009-06-10 13:36:04 -07006874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006876 if (mXOffset != 0 || mYOffset != 0) {
6877 mShownFrame.offset(mXOffset, mYOffset);
6878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006879 mShownAlpha = mAlpha;
6880 mDsDx = 1;
6881 mDtDx = 0;
6882 mDsDy = 0;
6883 mDtDy = 1;
6884 }
Romain Guy06882f82009-06-10 13:36:04 -07006885
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006886 /**
6887 * Is this window visible? It is not visible if there is no
6888 * surface, or we are in the process of running an exit animation
6889 * that will remove the surface, or its app token has been hidden.
6890 */
6891 public boolean isVisibleLw() {
6892 final AppWindowToken atoken = mAppToken;
6893 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6894 && (atoken == null || !atoken.hiddenRequested)
6895 && !mExiting && !mDestroying;
6896 }
6897
6898 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006899 * Like {@link #isVisibleLw}, but also counts a window that is currently
6900 * "hidden" behind the keyguard as visible. This allows us to apply
6901 * things like window flags that impact the keyguard.
6902 * XXX I am starting to think we need to have ANOTHER visibility flag
6903 * for this "hidden behind keyguard" state rather than overloading
6904 * mPolicyVisibility. Ungh.
6905 */
6906 public boolean isVisibleOrBehindKeyguardLw() {
6907 final AppWindowToken atoken = mAppToken;
6908 return mSurface != null && !mAttachedHidden
6909 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006910 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07006911 && !mExiting && !mDestroying;
6912 }
6913
6914 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006915 * Is this window visible, ignoring its app token? It is not visible
6916 * if there is no surface, or we are in the process of running an exit animation
6917 * that will remove the surface.
6918 */
6919 public boolean isWinVisibleLw() {
6920 final AppWindowToken atoken = mAppToken;
6921 return mSurface != null && mPolicyVisibility && !mAttachedHidden
6922 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
6923 && !mExiting && !mDestroying;
6924 }
6925
6926 /**
6927 * The same as isVisible(), but follows the current hidden state of
6928 * the associated app token, not the pending requested hidden state.
6929 */
6930 boolean isVisibleNow() {
6931 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07006932 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006933 }
6934
6935 /**
6936 * Same as isVisible(), but we also count it as visible between the
6937 * call to IWindowSession.add() and the first relayout().
6938 */
6939 boolean isVisibleOrAdding() {
6940 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006941 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006942 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
6943 && mPolicyVisibility && !mAttachedHidden
6944 && (atoken == null || !atoken.hiddenRequested)
6945 && !mExiting && !mDestroying;
6946 }
6947
6948 /**
6949 * Is this window currently on-screen? It is on-screen either if it
6950 * is visible or it is currently running an animation before no longer
6951 * being visible.
6952 */
6953 boolean isOnScreen() {
6954 final AppWindowToken atoken = mAppToken;
6955 if (atoken != null) {
6956 return mSurface != null && mPolicyVisibility && !mDestroying
6957 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006958 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006959 } else {
6960 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006961 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006962 }
6963 }
Romain Guy06882f82009-06-10 13:36:04 -07006964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006965 /**
6966 * Like isOnScreen(), but we don't return true if the window is part
6967 * of a transition that has not yet been started.
6968 */
6969 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006970 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07006971 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07006972 return false;
6973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006974 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006975 final boolean animating = atoken != null
6976 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006977 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006978 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
6979 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07006980 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006981 }
6982
6983 /** Is the window or its container currently animating? */
6984 boolean isAnimating() {
6985 final WindowState attached = mAttachedWindow;
6986 final AppWindowToken atoken = mAppToken;
6987 return mAnimation != null
6988 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07006989 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006990 (atoken.animation != null
6991 || atoken.inPendingTransaction));
6992 }
6993
6994 /** Is this window currently animating? */
6995 boolean isWindowAnimating() {
6996 return mAnimation != null;
6997 }
6998
6999 /**
7000 * Like isOnScreen, but returns false if the surface hasn't yet
7001 * been drawn.
7002 */
7003 public boolean isDisplayedLw() {
7004 final AppWindowToken atoken = mAppToken;
7005 return mSurface != null && mPolicyVisibility && !mDestroying
7006 && !mDrawPending && !mCommitDrawPending
7007 && ((!mAttachedHidden &&
7008 (atoken == null || !atoken.hiddenRequested))
7009 || mAnimating);
7010 }
7011
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007012 /**
7013 * Returns true if the window has a surface that it has drawn a
7014 * complete UI in to.
7015 */
7016 public boolean isDrawnLw() {
7017 final AppWindowToken atoken = mAppToken;
7018 return mSurface != null && !mDestroying
7019 && !mDrawPending && !mCommitDrawPending;
7020 }
7021
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 public boolean fillsScreenLw(int screenWidth, int screenHeight,
7023 boolean shownFrame, boolean onlyOpaque) {
7024 if (mSurface == null) {
7025 return false;
7026 }
7027 if (mAppToken != null && !mAppToken.appFullscreen) {
7028 return false;
7029 }
7030 if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) {
7031 return false;
7032 }
7033 final Rect frame = shownFrame ? mShownFrame : mFrame;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007034
7035 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
7036 return frame.left <= mCompatibleScreenFrame.left &&
7037 frame.top <= mCompatibleScreenFrame.top &&
7038 frame.right >= mCompatibleScreenFrame.right &&
7039 frame.bottom >= mCompatibleScreenFrame.bottom;
7040 } else {
7041 return frame.left <= 0 && frame.top <= 0
7042 && frame.right >= screenWidth
7043 && frame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007045 }
Romain Guy06882f82009-06-10 13:36:04 -07007046
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007047 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007048 * Return true if the window is opaque and fully drawn. This indicates
7049 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007050 */
7051 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007052 return (mAttrs.format == PixelFormat.OPAQUE
7053 || mAttrs.type == TYPE_WALLPAPER)
7054 && mSurface != null && mAnimation == null
7055 && (mAppToken == null || mAppToken.animation == null)
7056 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007057 }
7058
7059 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7060 return
7061 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007062 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7063 // only if it's visible
7064 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007065 // and only if the application fills the compatible screen
7066 mFrame.left <= mCompatibleScreenFrame.left &&
7067 mFrame.top <= mCompatibleScreenFrame.top &&
7068 mFrame.right >= mCompatibleScreenFrame.right &&
7069 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007070 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007071 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007072 }
7073
7074 boolean isFullscreen(int screenWidth, int screenHeight) {
7075 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007076 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007077 }
7078
7079 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007080 disposeInputChannel();
7081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007082 if (mAttachedWindow != null) {
7083 mAttachedWindow.mChildWindows.remove(this);
7084 }
7085 destroySurfaceLocked();
7086 mSession.windowRemovedLocked();
7087 try {
7088 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7089 } catch (RuntimeException e) {
7090 // Ignore if it has already been removed (usually because
7091 // we are doing this as part of processing a death note.)
7092 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007093 }
7094
7095 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007096 if (mInputChannel != null) {
7097 mInputManager.unregisterInputChannel(mInputChannel);
7098
7099 mInputChannel.dispose();
7100 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007101 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007102 }
7103
7104 private class DeathRecipient implements IBinder.DeathRecipient {
7105 public void binderDied() {
7106 try {
7107 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007108 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007109 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007110 if (win != null) {
7111 removeWindowLocked(mSession, win);
7112 }
7113 }
7114 } catch (IllegalArgumentException ex) {
7115 // This will happen if the window has already been
7116 // removed.
7117 }
7118 }
7119 }
7120
7121 /** Returns true if this window desires key events. */
7122 public final boolean canReceiveKeys() {
7123 return isVisibleOrAdding()
7124 && (mViewVisibility == View.VISIBLE)
7125 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7126 }
7127
7128 public boolean hasDrawnLw() {
7129 return mHasDrawn;
7130 }
7131
7132 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007133 return showLw(doAnimation, true);
7134 }
7135
7136 boolean showLw(boolean doAnimation, boolean requestAnim) {
7137 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7138 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007139 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007140 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007141 if (doAnimation) {
7142 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7143 + mPolicyVisibility + " mAnimation=" + mAnimation);
7144 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7145 doAnimation = false;
7146 } else if (mPolicyVisibility && mAnimation == null) {
7147 // Check for the case where we are currently visible and
7148 // not animating; we do not want to do animation at such a
7149 // point to become visible when we already are.
7150 doAnimation = false;
7151 }
7152 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007153 mPolicyVisibility = true;
7154 mPolicyVisibilityAfterAnim = true;
7155 if (doAnimation) {
7156 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7157 }
7158 if (requestAnim) {
7159 requestAnimationLocked(0);
7160 }
7161 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007162 }
7163
7164 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007165 return hideLw(doAnimation, true);
7166 }
7167
7168 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007169 if (doAnimation) {
7170 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7171 doAnimation = false;
7172 }
7173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007174 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7175 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007176 if (!current) {
7177 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007178 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007179 if (doAnimation) {
7180 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7181 if (mAnimation == null) {
7182 doAnimation = false;
7183 }
7184 }
7185 if (doAnimation) {
7186 mPolicyVisibilityAfterAnim = false;
7187 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007188 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007189 mPolicyVisibilityAfterAnim = false;
7190 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007191 // Window is no longer visible -- make sure if we were waiting
7192 // for it to be displayed before enabling the display, that
7193 // we allow the display to be enabled now.
7194 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007195 if (mCurrentFocus == this) {
7196 mFocusMayChange = true;
7197 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007198 }
7199 if (requestAnim) {
7200 requestAnimationLocked(0);
7201 }
7202 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007203 }
7204
7205 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007206 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7207 pw.print(" mClient="); pw.println(mClient.asBinder());
7208 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7209 if (mAttachedWindow != null || mLayoutAttached) {
7210 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7211 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7212 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007213 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7214 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7215 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007216 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7217 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007218 }
7219 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7220 pw.print(" mSubLayer="); pw.print(mSubLayer);
7221 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7222 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7223 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7224 pw.print("="); pw.print(mAnimLayer);
7225 pw.print(" mLastLayer="); pw.println(mLastLayer);
7226 if (mSurface != null) {
7227 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007228 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7229 pw.print(" layer="); pw.print(mSurfaceLayer);
7230 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7231 pw.print(" rect=("); pw.print(mSurfaceX);
7232 pw.print(","); pw.print(mSurfaceY);
7233 pw.print(") "); pw.print(mSurfaceW);
7234 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007235 }
7236 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7237 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7238 if (mAppToken != null) {
7239 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7240 }
7241 if (mTargetAppToken != null) {
7242 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7243 }
7244 pw.print(prefix); pw.print("mViewVisibility=0x");
7245 pw.print(Integer.toHexString(mViewVisibility));
7246 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007247 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7248 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007249 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7250 pw.print(prefix); pw.print("mPolicyVisibility=");
7251 pw.print(mPolicyVisibility);
7252 pw.print(" mPolicyVisibilityAfterAnim=");
7253 pw.print(mPolicyVisibilityAfterAnim);
7254 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7255 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007256 if (!mRelayoutCalled) {
7257 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7258 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007259 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007260 pw.print(" h="); pw.print(mRequestedHeight);
7261 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007262 if (mXOffset != 0 || mYOffset != 0) {
7263 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7264 pw.print(" y="); pw.println(mYOffset);
7265 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007266 pw.print(prefix); pw.print("mGivenContentInsets=");
7267 mGivenContentInsets.printShortString(pw);
7268 pw.print(" mGivenVisibleInsets=");
7269 mGivenVisibleInsets.printShortString(pw);
7270 pw.println();
7271 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7272 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7273 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7274 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007275 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007276 pw.print(prefix); pw.print("mShownFrame=");
7277 mShownFrame.printShortString(pw);
7278 pw.print(" last="); mLastShownFrame.printShortString(pw);
7279 pw.println();
7280 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7281 pw.print(" last="); mLastFrame.printShortString(pw);
7282 pw.println();
7283 pw.print(prefix); pw.print("mContainingFrame=");
7284 mContainingFrame.printShortString(pw);
7285 pw.print(" mDisplayFrame=");
7286 mDisplayFrame.printShortString(pw);
7287 pw.println();
7288 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7289 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7290 pw.println();
7291 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7292 pw.print(" last="); mLastContentInsets.printShortString(pw);
7293 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7294 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7295 pw.println();
7296 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7297 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7298 pw.print(" mAlpha="); pw.print(mAlpha);
7299 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7300 }
7301 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7302 || mAnimation != null) {
7303 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7304 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7305 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7306 pw.print(" mAnimation="); pw.println(mAnimation);
7307 }
7308 if (mHasTransformation || mHasLocalTransformation) {
7309 pw.print(prefix); pw.print("XForm: has=");
7310 pw.print(mHasTransformation);
7311 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7312 pw.print(" "); mTransformation.printShortString(pw);
7313 pw.println();
7314 }
7315 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7316 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7317 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7318 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7319 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7320 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7321 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7322 pw.print(" mDestroying="); pw.print(mDestroying);
7323 pw.print(" mRemoved="); pw.println(mRemoved);
7324 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007325 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007326 pw.print(prefix); pw.print("mOrientationChanging=");
7327 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007328 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7329 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007330 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007331 if (mHScale != 1 || mVScale != 1) {
7332 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7333 pw.print(" mVScale="); pw.println(mVScale);
7334 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007335 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007336 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7337 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7338 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007339 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7340 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7341 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7342 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007343 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007344
7345 String makeInputChannelName() {
7346 return Integer.toHexString(System.identityHashCode(this))
7347 + " " + mAttrs.getTitle();
7348 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007349
7350 @Override
7351 public String toString() {
7352 return "Window{"
7353 + Integer.toHexString(System.identityHashCode(this))
7354 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7355 }
7356 }
Romain Guy06882f82009-06-10 13:36:04 -07007357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007358 // -------------------------------------------------------------
7359 // Window Token State
7360 // -------------------------------------------------------------
7361
7362 class WindowToken {
7363 // The actual token.
7364 final IBinder token;
7365
7366 // The type of window this token is for, as per WindowManager.LayoutParams.
7367 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007369 // Set if this token was explicitly added by a client, so should
7370 // not be removed when all windows are removed.
7371 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007372
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007373 // For printing.
7374 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007376 // If this is an AppWindowToken, this is non-null.
7377 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007379 // All of the windows associated with this token.
7380 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7381
7382 // Is key dispatching paused for this token?
7383 boolean paused = false;
7384
7385 // Should this token's windows be hidden?
7386 boolean hidden;
7387
7388 // Temporary for finding which tokens no longer have visible windows.
7389 boolean hasVisible;
7390
Dianne Hackborna8f60182009-09-01 19:01:50 -07007391 // Set to true when this token is in a pending transaction where it
7392 // will be shown.
7393 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007394
Dianne Hackborna8f60182009-09-01 19:01:50 -07007395 // Set to true when this token is in a pending transaction where it
7396 // will be hidden.
7397 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007398
Dianne Hackborna8f60182009-09-01 19:01:50 -07007399 // Set to true when this token is in a pending transaction where its
7400 // windows will be put to the bottom of the list.
7401 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007402
Dianne Hackborna8f60182009-09-01 19:01:50 -07007403 // Set to true when this token is in a pending transaction where its
7404 // windows will be put to the top of the list.
7405 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007407 WindowToken(IBinder _token, int type, boolean _explicit) {
7408 token = _token;
7409 windowType = type;
7410 explicit = _explicit;
7411 }
7412
7413 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007414 pw.print(prefix); pw.print("token="); pw.println(token);
7415 pw.print(prefix); pw.print("windows="); pw.println(windows);
7416 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7417 pw.print(" hidden="); pw.print(hidden);
7418 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007419 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7420 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7421 pw.print(" waitingToHide="); pw.print(waitingToHide);
7422 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7423 pw.print(" sendingToTop="); pw.println(sendingToTop);
7424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007425 }
7426
7427 @Override
7428 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007429 if (stringName == null) {
7430 StringBuilder sb = new StringBuilder();
7431 sb.append("WindowToken{");
7432 sb.append(Integer.toHexString(System.identityHashCode(this)));
7433 sb.append(" token="); sb.append(token); sb.append('}');
7434 stringName = sb.toString();
7435 }
7436 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007437 }
7438 };
7439
7440 class AppWindowToken extends WindowToken {
7441 // Non-null only for application tokens.
7442 final IApplicationToken appToken;
7443
7444 // All of the windows and child windows that are included in this
7445 // application token. Note this list is NOT sorted!
7446 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7447
7448 int groupId = -1;
7449 boolean appFullscreen;
7450 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007451
7452 // The input dispatching timeout for this application token in nanoseconds.
7453 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007455 // These are used for determining when all windows associated with
7456 // an activity have been drawn, so they can be made visible together
7457 // at the same time.
7458 int lastTransactionSequence = mTransactionSequence-1;
7459 int numInterestingWindows;
7460 int numDrawnWindows;
7461 boolean inPendingTransaction;
7462 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007464 // Is this token going to be hidden in a little while? If so, it
7465 // won't be taken into account for setting the screen orientation.
7466 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007468 // Is this window's surface needed? This is almost like hidden, except
7469 // it will sometimes be true a little earlier: when the token has
7470 // been shown, but is still waiting for its app transition to execute
7471 // before making its windows shown.
7472 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007474 // Have we told the window clients to hide themselves?
7475 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007477 // Last visibility state we reported to the app token.
7478 boolean reportedVisible;
7479
7480 // Set to true when the token has been removed from the window mgr.
7481 boolean removed;
7482
7483 // Have we been asked to have this token keep the screen frozen?
7484 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007486 boolean animating;
7487 Animation animation;
7488 boolean hasTransformation;
7489 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007491 // Offset to the window of all layers in the token, for use by
7492 // AppWindowToken animations.
7493 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007495 // Information about an application starting window if displayed.
7496 StartingData startingData;
7497 WindowState startingWindow;
7498 View startingView;
7499 boolean startingDisplayed;
7500 boolean startingMoved;
7501 boolean firstWindowDrawn;
7502
7503 AppWindowToken(IApplicationToken _token) {
7504 super(_token.asBinder(),
7505 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7506 appWindowToken = this;
7507 appToken = _token;
7508 }
Romain Guy06882f82009-06-10 13:36:04 -07007509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007510 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007511 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007512 TAG, "Setting animation in " + this + ": " + anim);
7513 animation = anim;
7514 animating = false;
7515 anim.restrictDuration(MAX_ANIMATION_DURATION);
7516 anim.scaleCurrentDuration(mTransitionAnimationScale);
7517 int zorder = anim.getZAdjustment();
7518 int adj = 0;
7519 if (zorder == Animation.ZORDER_TOP) {
7520 adj = TYPE_LAYER_OFFSET;
7521 } else if (zorder == Animation.ZORDER_BOTTOM) {
7522 adj = -TYPE_LAYER_OFFSET;
7523 }
Romain Guy06882f82009-06-10 13:36:04 -07007524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 if (animLayerAdjustment != adj) {
7526 animLayerAdjustment = adj;
7527 updateLayers();
7528 }
7529 }
Romain Guy06882f82009-06-10 13:36:04 -07007530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007531 public void setDummyAnimation() {
7532 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007533 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007534 TAG, "Setting dummy animation in " + this);
7535 animation = sDummyAnimation;
7536 }
7537 }
7538
7539 public void clearAnimation() {
7540 if (animation != null) {
7541 animation = null;
7542 animating = true;
7543 }
7544 }
Romain Guy06882f82009-06-10 13:36:04 -07007545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007546 void updateLayers() {
7547 final int N = allAppWindows.size();
7548 final int adj = animLayerAdjustment;
7549 for (int i=0; i<N; i++) {
7550 WindowState w = allAppWindows.get(i);
7551 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007552 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 + w.mAnimLayer);
7554 if (w == mInputMethodTarget) {
7555 setInputMethodAnimLayerAdjustment(adj);
7556 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007557 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007558 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007560 }
7561 }
Romain Guy06882f82009-06-10 13:36:04 -07007562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007563 void sendAppVisibilityToClients() {
7564 final int N = allAppWindows.size();
7565 for (int i=0; i<N; i++) {
7566 WindowState win = allAppWindows.get(i);
7567 if (win == startingWindow && clientHidden) {
7568 // Don't hide the starting window.
7569 continue;
7570 }
7571 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007572 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007573 "Setting visibility of " + win + ": " + (!clientHidden));
7574 win.mClient.dispatchAppVisibility(!clientHidden);
7575 } catch (RemoteException e) {
7576 }
7577 }
7578 }
Romain Guy06882f82009-06-10 13:36:04 -07007579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007580 void showAllWindowsLocked() {
7581 final int NW = allAppWindows.size();
7582 for (int i=0; i<NW; i++) {
7583 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007584 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007585 "performing show on: " + w);
7586 w.performShowLocked();
7587 }
7588 }
Romain Guy06882f82009-06-10 13:36:04 -07007589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007590 // This must be called while inside a transaction.
7591 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007592 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007593 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007595 if (animation == sDummyAnimation) {
7596 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007597 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007598 // when it is really time to animate, this will be set to
7599 // a real animation and the next call will execute normally.
7600 return false;
7601 }
Romain Guy06882f82009-06-10 13:36:04 -07007602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007603 if ((allDrawn || animating || startingDisplayed) && animation != null) {
7604 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007605 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007606 TAG, "Starting animation in " + this +
7607 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
7608 + " scale=" + mTransitionAnimationScale
7609 + " allDrawn=" + allDrawn + " animating=" + animating);
7610 animation.initialize(dw, dh, dw, dh);
7611 animation.setStartTime(currentTime);
7612 animating = true;
7613 }
7614 transformation.clear();
7615 final boolean more = animation.getTransformation(
7616 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007617 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007618 TAG, "Stepped animation in " + this +
7619 ": more=" + more + ", xform=" + transformation);
7620 if (more) {
7621 // we're done!
7622 hasTransformation = true;
7623 return true;
7624 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007625 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007626 TAG, "Finished animation in " + this +
7627 " @ " + currentTime);
7628 animation = null;
7629 }
7630 } else if (animation != null) {
7631 // If the display is frozen, and there is a pending animation,
7632 // clear it and make sure we run the cleanup code.
7633 animating = true;
7634 animation = null;
7635 }
7636
7637 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07007638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007639 if (!animating) {
7640 return false;
7641 }
7642
7643 clearAnimation();
7644 animating = false;
7645 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
7646 moveInputMethodWindowsIfNeededLocked(true);
7647 }
Romain Guy06882f82009-06-10 13:36:04 -07007648
Joe Onorato8a9b2202010-02-26 18:56:32 -08007649 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007650 TAG, "Animation done in " + this
7651 + ": reportedVisible=" + reportedVisible);
7652
7653 transformation.clear();
7654 if (animLayerAdjustment != 0) {
7655 animLayerAdjustment = 0;
7656 updateLayers();
7657 }
Romain Guy06882f82009-06-10 13:36:04 -07007658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007659 final int N = windows.size();
7660 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007661 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007662 }
7663 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07007664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007665 return false;
7666 }
7667
7668 void updateReportedVisibilityLocked() {
7669 if (appToken == null) {
7670 return;
7671 }
Romain Guy06882f82009-06-10 13:36:04 -07007672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007673 int numInteresting = 0;
7674 int numVisible = 0;
7675 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07007676
Joe Onorato8a9b2202010-02-26 18:56:32 -08007677 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007678 final int N = allAppWindows.size();
7679 for (int i=0; i<N; i++) {
7680 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08007681 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07007682 || win.mViewVisibility != View.VISIBLE
7683 || win.mAttrs.type == TYPE_APPLICATION_STARTING) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007684 continue;
7685 }
7686 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007687 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007688 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007689 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007690 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007691 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007692 + " pv=" + win.mPolicyVisibility
7693 + " dp=" + win.mDrawPending
7694 + " cdp=" + win.mCommitDrawPending
7695 + " ah=" + win.mAttachedHidden
7696 + " th="
7697 + (win.mAppToken != null
7698 ? win.mAppToken.hiddenRequested : false)
7699 + " a=" + win.mAnimating);
7700 }
7701 }
7702 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007703 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007704 if (!win.isAnimating()) {
7705 numVisible++;
7706 }
7707 nowGone = false;
7708 } else if (win.isAnimating()) {
7709 nowGone = false;
7710 }
7711 }
Romain Guy06882f82009-06-10 13:36:04 -07007712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007713 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007714 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007715 + numInteresting + " visible=" + numVisible);
7716 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007717 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007718 TAG, "Visibility changed in " + this
7719 + ": vis=" + nowVisible);
7720 reportedVisible = nowVisible;
7721 Message m = mH.obtainMessage(
7722 H.REPORT_APPLICATION_TOKEN_WINDOWS,
7723 nowVisible ? 1 : 0,
7724 nowGone ? 1 : 0,
7725 this);
7726 mH.sendMessage(m);
7727 }
7728 }
Romain Guy06882f82009-06-10 13:36:04 -07007729
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07007730 WindowState findMainWindow() {
7731 int j = windows.size();
7732 while (j > 0) {
7733 j--;
7734 WindowState win = windows.get(j);
7735 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
7736 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
7737 return win;
7738 }
7739 }
7740 return null;
7741 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007743 void dump(PrintWriter pw, String prefix) {
7744 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007745 if (appToken != null) {
7746 pw.print(prefix); pw.println("app=true");
7747 }
7748 if (allAppWindows.size() > 0) {
7749 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
7750 }
7751 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007752 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007753 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
7754 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
7755 pw.print(" clientHidden="); pw.print(clientHidden);
7756 pw.print(" willBeHidden="); pw.print(willBeHidden);
7757 pw.print(" reportedVisible="); pw.println(reportedVisible);
7758 if (paused || freezingScreen) {
7759 pw.print(prefix); pw.print("paused="); pw.print(paused);
7760 pw.print(" freezingScreen="); pw.println(freezingScreen);
7761 }
7762 if (numInterestingWindows != 0 || numDrawnWindows != 0
7763 || inPendingTransaction || allDrawn) {
7764 pw.print(prefix); pw.print("numInterestingWindows=");
7765 pw.print(numInterestingWindows);
7766 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
7767 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
7768 pw.print(" allDrawn="); pw.println(allDrawn);
7769 }
7770 if (animating || animation != null) {
7771 pw.print(prefix); pw.print("animating="); pw.print(animating);
7772 pw.print(" animation="); pw.println(animation);
7773 }
7774 if (animLayerAdjustment != 0) {
7775 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
7776 }
7777 if (hasTransformation) {
7778 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
7779 pw.print(" transformation="); transformation.printShortString(pw);
7780 pw.println();
7781 }
7782 if (startingData != null || removed || firstWindowDrawn) {
7783 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
7784 pw.print(" removed="); pw.print(removed);
7785 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
7786 }
7787 if (startingWindow != null || startingView != null
7788 || startingDisplayed || startingMoved) {
7789 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
7790 pw.print(" startingView="); pw.print(startingView);
7791 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
7792 pw.print(" startingMoved"); pw.println(startingMoved);
7793 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007794 }
7795
7796 @Override
7797 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007798 if (stringName == null) {
7799 StringBuilder sb = new StringBuilder();
7800 sb.append("AppWindowToken{");
7801 sb.append(Integer.toHexString(System.identityHashCode(this)));
7802 sb.append(" token="); sb.append(token); sb.append('}');
7803 stringName = sb.toString();
7804 }
7805 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007806 }
7807 }
Romain Guy06882f82009-06-10 13:36:04 -07007808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007809 // -------------------------------------------------------------
7810 // DummyAnimation
7811 // -------------------------------------------------------------
7812
7813 // This is an animation that does nothing: it just immediately finishes
7814 // itself every time it is called. It is used as a stub animation in cases
7815 // where we want to synchronize multiple things that may be animating.
7816 static final class DummyAnimation extends Animation {
7817 public boolean getTransformation(long currentTime, Transformation outTransformation) {
7818 return false;
7819 }
7820 }
7821 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07007822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007823 // -------------------------------------------------------------
7824 // Async Handler
7825 // -------------------------------------------------------------
7826
7827 static final class StartingData {
7828 final String pkg;
7829 final int theme;
7830 final CharSequence nonLocalizedLabel;
7831 final int labelRes;
7832 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07007833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007834 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
7835 int _labelRes, int _icon) {
7836 pkg = _pkg;
7837 theme = _theme;
7838 nonLocalizedLabel = _nonLocalizedLabel;
7839 labelRes = _labelRes;
7840 icon = _icon;
7841 }
7842 }
7843
7844 private final class H extends Handler {
7845 public static final int REPORT_FOCUS_CHANGE = 2;
7846 public static final int REPORT_LOSING_FOCUS = 3;
7847 public static final int ANIMATE = 4;
7848 public static final int ADD_STARTING = 5;
7849 public static final int REMOVE_STARTING = 6;
7850 public static final int FINISHED_STARTING = 7;
7851 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007852 public static final int WINDOW_FREEZE_TIMEOUT = 11;
7853 public static final int HOLD_SCREEN_CHANGED = 12;
7854 public static final int APP_TRANSITION_TIMEOUT = 13;
7855 public static final int PERSIST_ANIMATION_SCALE = 14;
7856 public static final int FORCE_GC = 15;
7857 public static final int ENABLE_SCREEN = 16;
7858 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007859 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07007860 public static final int REPORT_WINDOWS_CHANGE = 19;
Romain Guy06882f82009-06-10 13:36:04 -07007861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007862 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07007863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007864 public H() {
7865 }
Romain Guy06882f82009-06-10 13:36:04 -07007866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007867 @Override
7868 public void handleMessage(Message msg) {
7869 switch (msg.what) {
7870 case REPORT_FOCUS_CHANGE: {
7871 WindowState lastFocus;
7872 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07007873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007874 synchronized(mWindowMap) {
7875 lastFocus = mLastFocus;
7876 newFocus = mCurrentFocus;
7877 if (lastFocus == newFocus) {
7878 // Focus is not changing, so nothing to do.
7879 return;
7880 }
7881 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007882 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007883 // + " to " + newFocus);
7884 if (newFocus != null && lastFocus != null
7885 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007886 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007887 mLosingFocus.add(lastFocus);
7888 lastFocus = null;
7889 }
7890 }
7891
7892 if (lastFocus != newFocus) {
7893 //System.out.println("Changing focus from " + lastFocus
7894 // + " to " + newFocus);
7895 if (newFocus != null) {
7896 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007897 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
7899 } catch (RemoteException e) {
7900 // Ignore if process has died.
7901 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07007902 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007903 }
7904
7905 if (lastFocus != null) {
7906 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007907 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007908 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
7909 } catch (RemoteException e) {
7910 // Ignore if process has died.
7911 }
7912 }
7913 }
7914 } break;
7915
7916 case REPORT_LOSING_FOCUS: {
7917 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07007918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007919 synchronized(mWindowMap) {
7920 losers = mLosingFocus;
7921 mLosingFocus = new ArrayList<WindowState>();
7922 }
7923
7924 final int N = losers.size();
7925 for (int i=0; i<N; i++) {
7926 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007927 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007928 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
7929 } catch (RemoteException e) {
7930 // Ignore if process has died.
7931 }
7932 }
7933 } break;
7934
7935 case ANIMATE: {
7936 synchronized(mWindowMap) {
7937 mAnimationPending = false;
7938 performLayoutAndPlaceSurfacesLocked();
7939 }
7940 } break;
7941
7942 case ADD_STARTING: {
7943 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
7944 final StartingData sd = wtoken.startingData;
7945
7946 if (sd == null) {
7947 // Animation has been canceled... do nothing.
7948 return;
7949 }
Romain Guy06882f82009-06-10 13:36:04 -07007950
Joe Onorato8a9b2202010-02-26 18:56:32 -08007951 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007952 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07007953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007954 View view = null;
7955 try {
7956 view = mPolicy.addStartingWindow(
7957 wtoken.token, sd.pkg,
7958 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
7959 sd.icon);
7960 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007961 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007962 }
7963
7964 if (view != null) {
7965 boolean abort = false;
7966
7967 synchronized(mWindowMap) {
7968 if (wtoken.removed || wtoken.startingData == null) {
7969 // If the window was successfully added, then
7970 // we need to remove it.
7971 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007972 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007973 "Aborted starting " + wtoken
7974 + ": removed=" + wtoken.removed
7975 + " startingData=" + wtoken.startingData);
7976 wtoken.startingWindow = null;
7977 wtoken.startingData = null;
7978 abort = true;
7979 }
7980 } else {
7981 wtoken.startingView = view;
7982 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007983 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007984 "Added starting " + wtoken
7985 + ": startingWindow="
7986 + wtoken.startingWindow + " startingView="
7987 + wtoken.startingView);
7988 }
7989
7990 if (abort) {
7991 try {
7992 mPolicy.removeStartingWindow(wtoken.token, view);
7993 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007994 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007995 }
7996 }
7997 }
7998 } break;
7999
8000 case REMOVE_STARTING: {
8001 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8002 IBinder token = null;
8003 View view = null;
8004 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008005 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 + wtoken + ": startingWindow="
8007 + wtoken.startingWindow + " startingView="
8008 + wtoken.startingView);
8009 if (wtoken.startingWindow != null) {
8010 view = wtoken.startingView;
8011 token = wtoken.token;
8012 wtoken.startingData = null;
8013 wtoken.startingView = null;
8014 wtoken.startingWindow = null;
8015 }
8016 }
8017 if (view != null) {
8018 try {
8019 mPolicy.removeStartingWindow(token, view);
8020 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008021 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008022 }
8023 }
8024 } break;
8025
8026 case FINISHED_STARTING: {
8027 IBinder token = null;
8028 View view = null;
8029 while (true) {
8030 synchronized (mWindowMap) {
8031 final int N = mFinishedStarting.size();
8032 if (N <= 0) {
8033 break;
8034 }
8035 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8036
Joe Onorato8a9b2202010-02-26 18:56:32 -08008037 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 "Finished starting " + wtoken
8039 + ": startingWindow=" + wtoken.startingWindow
8040 + " startingView=" + wtoken.startingView);
8041
8042 if (wtoken.startingWindow == null) {
8043 continue;
8044 }
8045
8046 view = wtoken.startingView;
8047 token = wtoken.token;
8048 wtoken.startingData = null;
8049 wtoken.startingView = null;
8050 wtoken.startingWindow = null;
8051 }
8052
8053 try {
8054 mPolicy.removeStartingWindow(token, view);
8055 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008056 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008057 }
8058 }
8059 } break;
8060
8061 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8062 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8063
8064 boolean nowVisible = msg.arg1 != 0;
8065 boolean nowGone = msg.arg2 != 0;
8066
8067 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008068 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 TAG, "Reporting visible in " + wtoken
8070 + " visible=" + nowVisible
8071 + " gone=" + nowGone);
8072 if (nowVisible) {
8073 wtoken.appToken.windowsVisible();
8074 } else {
8075 wtoken.appToken.windowsGone();
8076 }
8077 } catch (RemoteException ex) {
8078 }
8079 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008081 case WINDOW_FREEZE_TIMEOUT: {
8082 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008083 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008084 int i = mWindows.size();
8085 while (i > 0) {
8086 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008087 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008088 if (w.mOrientationChanging) {
8089 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008090 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008091 }
8092 }
8093 performLayoutAndPlaceSurfacesLocked();
8094 }
8095 break;
8096 }
Romain Guy06882f82009-06-10 13:36:04 -07008097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008098 case HOLD_SCREEN_CHANGED: {
8099 Session oldHold;
8100 Session newHold;
8101 synchronized (mWindowMap) {
8102 oldHold = mLastReportedHold;
8103 newHold = (Session)msg.obj;
8104 mLastReportedHold = newHold;
8105 }
Romain Guy06882f82009-06-10 13:36:04 -07008106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008107 if (oldHold != newHold) {
8108 try {
8109 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008110 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008111 "window",
8112 BatteryStats.WAKE_TYPE_WINDOW);
8113 }
8114 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008115 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008116 "window",
8117 BatteryStats.WAKE_TYPE_WINDOW);
8118 }
8119 } catch (RemoteException e) {
8120 }
8121 }
8122 break;
8123 }
Romain Guy06882f82009-06-10 13:36:04 -07008124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008125 case APP_TRANSITION_TIMEOUT: {
8126 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008127 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008128 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008129 "*** APP TRANSITION TIMEOUT");
8130 mAppTransitionReady = true;
8131 mAppTransitionTimeout = true;
8132 performLayoutAndPlaceSurfacesLocked();
8133 }
8134 }
8135 break;
8136 }
Romain Guy06882f82009-06-10 13:36:04 -07008137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008138 case PERSIST_ANIMATION_SCALE: {
8139 Settings.System.putFloat(mContext.getContentResolver(),
8140 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8141 Settings.System.putFloat(mContext.getContentResolver(),
8142 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8143 break;
8144 }
Romain Guy06882f82009-06-10 13:36:04 -07008145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008146 case FORCE_GC: {
8147 synchronized(mWindowMap) {
8148 if (mAnimationPending) {
8149 // If we are animating, don't do the gc now but
8150 // delay a bit so we don't interrupt the animation.
8151 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8152 2000);
8153 return;
8154 }
8155 // If we are currently rotating the display, it will
8156 // schedule a new message when done.
8157 if (mDisplayFrozen) {
8158 return;
8159 }
8160 mFreezeGcPending = 0;
8161 }
8162 Runtime.getRuntime().gc();
8163 break;
8164 }
Romain Guy06882f82009-06-10 13:36:04 -07008165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008166 case ENABLE_SCREEN: {
8167 performEnableScreen();
8168 break;
8169 }
Romain Guy06882f82009-06-10 13:36:04 -07008170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008171 case APP_FREEZE_TIMEOUT: {
8172 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008173 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008174 int i = mAppTokens.size();
8175 while (i > 0) {
8176 i--;
8177 AppWindowToken tok = mAppTokens.get(i);
8178 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008179 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008180 unsetAppFreezingScreenLocked(tok, true, true);
8181 }
8182 }
8183 }
8184 break;
8185 }
Romain Guy06882f82009-06-10 13:36:04 -07008186
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008187 case SEND_NEW_CONFIGURATION: {
8188 removeMessages(SEND_NEW_CONFIGURATION);
8189 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008190 break;
8191 }
Romain Guy06882f82009-06-10 13:36:04 -07008192
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008193 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008194 if (mWindowsChanged) {
8195 synchronized (mWindowMap) {
8196 mWindowsChanged = false;
8197 }
8198 notifyWindowsChanged();
8199 }
8200 break;
8201 }
8202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008203 }
8204 }
8205 }
8206
8207 // -------------------------------------------------------------
8208 // IWindowManager API
8209 // -------------------------------------------------------------
8210
8211 public IWindowSession openSession(IInputMethodClient client,
8212 IInputContext inputContext) {
8213 if (client == null) throw new IllegalArgumentException("null client");
8214 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008215 Session session = new Session(client, inputContext);
8216 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008217 }
8218
8219 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8220 synchronized (mWindowMap) {
8221 // The focus for the client is the window immediately below
8222 // where we would place the input method window.
8223 int idx = findDesiredInputMethodWindowIndexLocked(false);
8224 WindowState imFocus;
8225 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008226 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008227 if (imFocus != null) {
8228 if (imFocus.mSession.mClient != null &&
8229 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8230 return true;
8231 }
8232 }
8233 }
8234 }
8235 return false;
8236 }
Romain Guy06882f82009-06-10 13:36:04 -07008237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 // -------------------------------------------------------------
8239 // Internals
8240 // -------------------------------------------------------------
8241
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008242 final WindowState windowForClientLocked(Session session, IWindow client,
8243 boolean throwOnError) {
8244 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008245 }
Romain Guy06882f82009-06-10 13:36:04 -07008246
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008247 final WindowState windowForClientLocked(Session session, IBinder client,
8248 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008249 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008250 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008251 TAG, "Looking up client " + client + ": " + win);
8252 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008253 RuntimeException ex = new IllegalArgumentException(
8254 "Requested window " + client + " does not exist");
8255 if (throwOnError) {
8256 throw ex;
8257 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008258 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008259 return null;
8260 }
8261 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008262 RuntimeException ex = new IllegalArgumentException(
8263 "Requested window " + client + " is in session " +
8264 win.mSession + ", not " + session);
8265 if (throwOnError) {
8266 throw ex;
8267 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008268 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008269 return null;
8270 }
8271
8272 return win;
8273 }
8274
Dianne Hackborna8f60182009-09-01 19:01:50 -07008275 final void rebuildAppWindowListLocked() {
8276 int NW = mWindows.size();
8277 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008278 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008279 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008280
Dianne Hackborna8f60182009-09-01 19:01:50 -07008281 // First remove all existing app windows.
8282 i=0;
8283 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008284 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008285 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008286 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008287 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008288 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008289 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008290 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008291 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008292 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008293 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8294 && lastWallpaper == i-1) {
8295 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008296 }
8297 i++;
8298 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008299
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008300 // The wallpaper window(s) typically live at the bottom of the stack,
8301 // so skip them before adding app tokens.
8302 lastWallpaper++;
8303 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008304
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008305 // First add all of the exiting app tokens... these are no longer
8306 // in the main app list, but still have windows shown. We put them
8307 // in the back because now that the animation is over we no longer
8308 // will care about them.
8309 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008310 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008311 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8312 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008313
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008314 // And add in the still active app tokens in Z order.
8315 NT = mAppTokens.size();
8316 for (int j=0; j<NT; j++) {
8317 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008318 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008319
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008320 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008321 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008322 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008323 + " windows but added " + i);
8324 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008325 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008327 private final void assignLayersLocked() {
8328 int N = mWindows.size();
8329 int curBaseLayer = 0;
8330 int curLayer = 0;
8331 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008332
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008333 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008334 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008335 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8336 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008337 curLayer += WINDOW_LAYER_MULTIPLIER;
8338 w.mLayer = curLayer;
8339 } else {
8340 curBaseLayer = curLayer = w.mBaseLayer;
8341 w.mLayer = curLayer;
8342 }
8343 if (w.mTargetAppToken != null) {
8344 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8345 } else if (w.mAppToken != null) {
8346 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8347 } else {
8348 w.mAnimLayer = w.mLayer;
8349 }
8350 if (w.mIsImWindow) {
8351 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008352 } else if (w.mIsWallpaper) {
8353 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008354 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008355 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008356 + w.mAnimLayer);
8357 //System.out.println(
8358 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8359 }
8360 }
8361
8362 private boolean mInLayout = false;
8363 private final void performLayoutAndPlaceSurfacesLocked() {
8364 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008365 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008366 throw new RuntimeException("Recursive call!");
8367 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008368 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008369 return;
8370 }
8371
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008372 if (mWaitingForConfig) {
8373 // Our configuration has changed (most likely rotation), but we
8374 // don't yet have the complete configuration to report to
8375 // applications. Don't do any window layout until we have it.
8376 return;
8377 }
8378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008379 boolean recoveringMemory = false;
8380 if (mForceRemoves != null) {
8381 recoveringMemory = true;
8382 // Wait a little it for things to settle down, and off we go.
8383 for (int i=0; i<mForceRemoves.size(); i++) {
8384 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008385 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008386 removeWindowInnerLocked(ws.mSession, ws);
8387 }
8388 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008389 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008390 Object tmp = new Object();
8391 synchronized (tmp) {
8392 try {
8393 tmp.wait(250);
8394 } catch (InterruptedException e) {
8395 }
8396 }
8397 }
Romain Guy06882f82009-06-10 13:36:04 -07008398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 mInLayout = true;
8400 try {
8401 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008403 int i = mPendingRemove.size()-1;
8404 if (i >= 0) {
8405 while (i >= 0) {
8406 WindowState w = mPendingRemove.get(i);
8407 removeWindowInnerLocked(w.mSession, w);
8408 i--;
8409 }
8410 mPendingRemove.clear();
8411
8412 mInLayout = false;
8413 assignLayersLocked();
8414 mLayoutNeeded = true;
8415 performLayoutAndPlaceSurfacesLocked();
8416
8417 } else {
8418 mInLayout = false;
8419 if (mLayoutNeeded) {
8420 requestAnimationLocked(0);
8421 }
8422 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008423 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008424 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8425 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008427 } catch (RuntimeException e) {
8428 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008429 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008430 }
8431 }
8432
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008433 private final int performLayoutLockedInner() {
8434 if (!mLayoutNeeded) {
8435 return 0;
8436 }
8437
8438 mLayoutNeeded = false;
8439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 final int dw = mDisplay.getWidth();
8441 final int dh = mDisplay.getHeight();
8442
8443 final int N = mWindows.size();
8444 int i;
8445
Joe Onorato8a9b2202010-02-26 18:56:32 -08008446 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008447 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8448
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008449 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008450
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008451 int seq = mLayoutSeq+1;
8452 if (seq < 0) seq = 0;
8453 mLayoutSeq = seq;
8454
8455 // First perform layout of any root windows (not attached
8456 // to another window).
8457 int topAttached = -1;
8458 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008459 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008460
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008461 // Don't do layout of a window if it is not visible, or
8462 // soon won't be visible, to avoid wasting time and funky
8463 // changes while a window is animating away.
8464 final AppWindowToken atoken = win.mAppToken;
8465 final boolean gone = win.mViewVisibility == View.GONE
8466 || !win.mRelayoutCalled
8467 || win.mRootToken.hidden
8468 || (atoken != null && atoken.hiddenRequested)
8469 || win.mAttachedHidden
8470 || win.mExiting || win.mDestroying;
8471
8472 if (!win.mLayoutAttached) {
8473 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8474 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8475 + " mLayoutAttached=" + win.mLayoutAttached);
8476 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8477 + win.mViewVisibility + " mRelayoutCalled="
8478 + win.mRelayoutCalled + " hidden="
8479 + win.mRootToken.hidden + " hiddenRequested="
8480 + (atoken != null && atoken.hiddenRequested)
8481 + " mAttachedHidden=" + win.mAttachedHidden);
8482 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008483
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008484 // 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 (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008490 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008491 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8492 win.mLayoutSeq = seq;
8493 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8494 + win.mFrame + " mContainingFrame="
8495 + win.mContainingFrame + " mDisplayFrame="
8496 + win.mDisplayFrame);
8497 } else {
8498 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008499 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008501 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008502
8503 // Now perform layout of attached windows, which usually
8504 // depend on the position of the window they are attached to.
8505 // XXX does not deal with windows that are attached to windows
8506 // that are themselves attached.
8507 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008508 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008509
8510 // If this view is GONE, then skip it -- keep the current
8511 // frame, and let the caller know so they can ignore it
8512 // if they want. (We do the normal layout for INVISIBLE
8513 // windows, since that means "perform layout as normal,
8514 // just don't display").
8515 if (win.mLayoutAttached) {
8516 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8517 + " mHaveFrame=" + win.mHaveFrame
8518 + " mViewVisibility=" + win.mViewVisibility
8519 + " mRelayoutCalled=" + win.mRelayoutCalled);
8520 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8521 || !win.mHaveFrame) {
8522 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8523 win.mLayoutSeq = seq;
8524 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8525 + win.mFrame + " mContainingFrame="
8526 + win.mContainingFrame + " mDisplayFrame="
8527 + win.mDisplayFrame);
8528 }
8529 }
8530 }
Jeff Brown349703e2010-06-22 01:27:15 -07008531
8532 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008533 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008534
8535 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 }
Romain Guy06882f82009-06-10 13:36:04 -07008537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008538 private final void performLayoutAndPlaceSurfacesLockedInner(
8539 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04008540 if (mDisplay == null) {
8541 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
8542 return;
8543 }
8544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008545 final long currentTime = SystemClock.uptimeMillis();
8546 final int dw = mDisplay.getWidth();
8547 final int dh = mDisplay.getHeight();
8548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008549 int i;
8550
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008551 if (mFocusMayChange) {
8552 mFocusMayChange = false;
8553 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
8554 }
8555
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 // Initialize state of exiting tokens.
8557 for (i=mExitingTokens.size()-1; i>=0; i--) {
8558 mExitingTokens.get(i).hasVisible = false;
8559 }
8560
8561 // Initialize state of exiting applications.
8562 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
8563 mExitingAppTokens.get(i).hasVisible = false;
8564 }
8565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008566 boolean orientationChangeComplete = true;
8567 Session holdScreen = null;
8568 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05008569 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 boolean focusDisplayed = false;
8571 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008572 boolean createWatermark = false;
8573
8574 if (mFxSession == null) {
8575 mFxSession = new SurfaceSession();
8576 createWatermark = true;
8577 }
8578
8579 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008580
8581 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07008582
8583 if (createWatermark) {
8584 createWatermark();
8585 }
8586 if (mWatermark != null) {
8587 mWatermark.positionSurface(dw, dh);
8588 }
8589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008590 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008591 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008592 int repeats = 0;
8593 int changes = 0;
8594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008595 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008596 repeats++;
8597 if (repeats > 6) {
8598 Slog.w(TAG, "Animation repeat aborted after too many iterations");
8599 mLayoutNeeded = false;
8600 break;
8601 }
8602
8603 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
8604 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
8605 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
8606 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
8607 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
8608 assignLayersLocked();
8609 mLayoutNeeded = true;
8610 }
8611 }
8612 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
8613 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
8614 if (updateOrientationFromAppTokensLocked()) {
8615 mLayoutNeeded = true;
8616 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
8617 }
8618 }
8619 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
8620 mLayoutNeeded = true;
8621 }
8622 }
8623
8624 // FIRST LOOP: Perform a layout, if needed.
8625 if (repeats < 4) {
8626 changes = performLayoutLockedInner();
8627 if (changes != 0) {
8628 continue;
8629 }
8630 } else {
8631 Slog.w(TAG, "Layout repeat skipped after too many iterations");
8632 changes = 0;
8633 }
8634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008635 final int transactionSequence = ++mTransactionSequence;
8636
8637 // Update animations of all applications, including those
8638 // associated with exiting/removed apps
8639 boolean tokensAnimating = false;
8640 final int NAT = mAppTokens.size();
8641 for (i=0; i<NAT; i++) {
8642 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8643 tokensAnimating = true;
8644 }
8645 }
8646 final int NEAT = mExitingAppTokens.size();
8647 for (i=0; i<NEAT; i++) {
8648 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
8649 tokensAnimating = true;
8650 }
8651 }
8652
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008653 // SECOND LOOP: Execute animations and update visibility of windows.
8654
Joe Onorato8a9b2202010-02-26 18:56:32 -08008655 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008656 + transactionSequence + " tokensAnimating="
8657 + tokensAnimating);
8658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008659 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008660
8661 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008662 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008663 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008664
8665 mPolicy.beginAnimationLw(dw, dh);
8666
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008667 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008669 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008670 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008671
8672 final WindowManager.LayoutParams attrs = w.mAttrs;
8673
8674 if (w.mSurface != null) {
8675 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008676 if (w.commitFinishDrawingLocked(currentTime)) {
8677 if ((w.mAttrs.flags
8678 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008679 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07008680 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008681 wallpaperMayChange = true;
8682 }
8683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008684
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008685 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 if (w.stepAnimationLocked(currentTime, dw, dh)) {
8687 animating = true;
8688 //w.dump(" ");
8689 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07008690 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
8691 wallpaperMayChange = true;
8692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008693
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008694 if (mPolicy.doesForceHide(w, attrs)) {
8695 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008696 if (DEBUG_VISIBILITY) Slog.v(TAG,
8697 "Animation done that could impact force hide: "
8698 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008699 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08008700 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008701 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
8702 forceHiding = true;
8703 }
8704 } else if (mPolicy.canBeForceHidden(w, attrs)) {
8705 boolean changed;
8706 if (forceHiding) {
8707 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008708 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8709 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008710 } else {
8711 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008712 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
8713 "Now policy shown: " + w);
8714 if (changed) {
8715 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008716 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008717 // Assume we will need to animate. If
8718 // we don't (because the wallpaper will
8719 // stay with the lock screen), then we will
8720 // clean up later.
8721 Animation a = mPolicy.createForceHideEnterAnimation();
8722 if (a != null) {
8723 w.setAnimation(a);
8724 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008725 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08008726 if (mCurrentFocus == null ||
8727 mCurrentFocus.mLayer < w.mLayer) {
8728 // We are showing on to of the current
8729 // focus, so re-evaluate focus to make
8730 // sure it is correct.
8731 mFocusMayChange = true;
8732 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008733 }
8734 }
8735 if (changed && (attrs.flags
8736 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
8737 wallpaperMayChange = true;
8738 }
8739 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008741 mPolicy.animatingWindowLw(w, attrs);
8742 }
8743
8744 final AppWindowToken atoken = w.mAppToken;
8745 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
8746 if (atoken.lastTransactionSequence != transactionSequence) {
8747 atoken.lastTransactionSequence = transactionSequence;
8748 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
8749 atoken.startingDisplayed = false;
8750 }
8751 if ((w.isOnScreen() || w.mAttrs.type
8752 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
8753 && !w.mExiting && !w.mDestroying) {
8754 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008755 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008756 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008757 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008758 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008759 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008760 + " pv=" + w.mPolicyVisibility
8761 + " dp=" + w.mDrawPending
8762 + " cdp=" + w.mCommitDrawPending
8763 + " ah=" + w.mAttachedHidden
8764 + " th=" + atoken.hiddenRequested
8765 + " a=" + w.mAnimating);
8766 }
8767 }
8768 if (w != atoken.startingWindow) {
8769 if (!atoken.freezingScreen || !w.mAppFreezing) {
8770 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008771 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008772 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008773 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008774 "tokenMayBeDrawn: " + atoken
8775 + " freezingScreen=" + atoken.freezingScreen
8776 + " mAppFreezing=" + w.mAppFreezing);
8777 tokenMayBeDrawn = true;
8778 }
8779 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008780 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008781 atoken.startingDisplayed = true;
8782 }
8783 }
8784 } else if (w.mReadyToShow) {
8785 w.performShowLocked();
8786 }
8787 }
8788
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008789 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008790
8791 if (tokenMayBeDrawn) {
8792 // See if any windows have been drawn, so they (and others
8793 // associated with them) can now be shown.
8794 final int NT = mTokenList.size();
8795 for (i=0; i<NT; i++) {
8796 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
8797 if (wtoken == null) {
8798 continue;
8799 }
8800 if (wtoken.freezingScreen) {
8801 int numInteresting = wtoken.numInterestingWindows;
8802 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008803 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008804 "allDrawn: " + wtoken
8805 + " interesting=" + numInteresting
8806 + " drawn=" + wtoken.numDrawnWindows);
8807 wtoken.showAllWindowsLocked();
8808 unsetAppFreezingScreenLocked(wtoken, false, true);
8809 orientationChangeComplete = true;
8810 }
8811 } else if (!wtoken.allDrawn) {
8812 int numInteresting = wtoken.numInterestingWindows;
8813 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008814 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008815 "allDrawn: " + wtoken
8816 + " interesting=" + numInteresting
8817 + " drawn=" + wtoken.numDrawnWindows);
8818 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008819 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008820
8821 // We can now show all of the drawn windows!
8822 if (!mOpeningApps.contains(wtoken)) {
8823 wtoken.showAllWindowsLocked();
8824 }
8825 }
8826 }
8827 }
8828 }
8829
8830 // If we are ready to perform an app transition, check through
8831 // all of the app tokens to be shown and see if they are ready
8832 // to go.
8833 if (mAppTransitionReady) {
8834 int NN = mOpeningApps.size();
8835 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008836 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008837 "Checking " + NN + " opening apps (frozen="
8838 + mDisplayFrozen + " timeout="
8839 + mAppTransitionTimeout + ")...");
8840 if (!mDisplayFrozen && !mAppTransitionTimeout) {
8841 // If the display isn't frozen, wait to do anything until
8842 // all of the apps are ready. Otherwise just go because
8843 // we'll unfreeze the display when everyone is ready.
8844 for (i=0; i<NN && goodToGo; i++) {
8845 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008846 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008847 "Check opening app" + wtoken + ": allDrawn="
8848 + wtoken.allDrawn + " startingDisplayed="
8849 + wtoken.startingDisplayed);
8850 if (!wtoken.allDrawn && !wtoken.startingDisplayed
8851 && !wtoken.startingMoved) {
8852 goodToGo = false;
8853 }
8854 }
8855 }
8856 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008857 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008858 int transit = mNextAppTransition;
8859 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008860 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008861 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008862 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008863 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008864 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008865 mAppTransitionTimeout = false;
8866 mStartingIconInTransition = false;
8867 mSkipAppTransitionAnimation = false;
8868
8869 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
8870
Dianne Hackborna8f60182009-09-01 19:01:50 -07008871 // If there are applications waiting to come to the
8872 // top of the stack, now is the time to move their windows.
8873 // (Note that we don't do apps going to the bottom
8874 // here -- we want to keep their windows in the old
8875 // Z-order until the animation completes.)
8876 if (mToTopApps.size() > 0) {
8877 NN = mAppTokens.size();
8878 for (i=0; i<NN; i++) {
8879 AppWindowToken wtoken = mAppTokens.get(i);
8880 if (wtoken.sendingToTop) {
8881 wtoken.sendingToTop = false;
8882 moveAppWindowsLocked(wtoken, NN, false);
8883 }
8884 }
8885 mToTopApps.clear();
8886 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008887
Dianne Hackborn25994b42009-09-04 14:21:19 -07008888 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008889
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008890 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07008891 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008892
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008893 // The top-most window will supply the layout params,
8894 // and we will determine it below.
8895 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008896 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008897 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008898
Joe Onorato8a9b2202010-02-26 18:56:32 -08008899 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008900 "New wallpaper target=" + mWallpaperTarget
8901 + ", lower target=" + mLowerWallpaperTarget
8902 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07008903 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008904 // Do a first pass through the tokens for two
8905 // things:
8906 // (1) Determine if both the closing and opening
8907 // app token sets are wallpaper targets, in which
8908 // case special animations are needed
8909 // (since the wallpaper needs to stay static
8910 // behind them).
8911 // (2) Find the layout params of the top-most
8912 // application window in the tokens, which is
8913 // what will control the animation theme.
8914 final int NC = mClosingApps.size();
8915 NN = NC + mOpeningApps.size();
8916 for (i=0; i<NN; i++) {
8917 AppWindowToken wtoken;
8918 int mode;
8919 if (i < NC) {
8920 wtoken = mClosingApps.get(i);
8921 mode = 1;
8922 } else {
8923 wtoken = mOpeningApps.get(i-NC);
8924 mode = 2;
8925 }
8926 if (mLowerWallpaperTarget != null) {
8927 if (mLowerWallpaperTarget.mAppToken == wtoken
8928 || mUpperWallpaperTarget.mAppToken == wtoken) {
8929 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008930 }
8931 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008932 if (wtoken.appFullscreen) {
8933 WindowState ws = wtoken.findMainWindow();
8934 if (ws != null) {
8935 // If this is a compatibility mode
8936 // window, we will always use its anim.
8937 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
8938 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008939 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008940 bestAnimLayer = Integer.MAX_VALUE;
8941 } else if (ws.mLayer > bestAnimLayer) {
8942 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008943 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008944 bestAnimLayer = ws.mLayer;
8945 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07008946 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07008947 }
8948 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008949
Dianne Hackborn25994b42009-09-04 14:21:19 -07008950 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008951 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008952 "Wallpaper animation!");
8953 switch (transit) {
8954 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
8955 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
8956 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
8957 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
8958 break;
8959 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
8960 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
8961 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
8962 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
8963 break;
8964 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008965 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008966 "New transit: " + transit);
8967 } else if (oldWallpaper != null) {
8968 // We are transitioning from an activity with
8969 // a wallpaper to one without.
8970 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008971 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008972 "New transit away from wallpaper: " + transit);
8973 } else if (mWallpaperTarget != null) {
8974 // We are transitioning from an activity without
8975 // a wallpaper to now showing the wallpaper
8976 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008977 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07008978 "New transit into wallpaper: " + transit);
8979 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008980
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008981 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
8982 mLastEnterAnimToken = animToken;
8983 mLastEnterAnimParams = animLp;
8984 } else if (mLastEnterAnimParams != null) {
8985 animLp = mLastEnterAnimParams;
8986 mLastEnterAnimToken = null;
8987 mLastEnterAnimParams = null;
8988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008989
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008990 // If all closing windows are obscured, then there is
8991 // no need to do an animation. This is the case, for
8992 // example, when this transition is being done behind
8993 // the lock screen.
8994 if (!mPolicy.allowAppAnimationsLw()) {
8995 animLp = null;
8996 }
8997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008998 NN = mOpeningApps.size();
8999 for (i=0; i<NN; i++) {
9000 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009001 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 "Now opening app" + wtoken);
9003 wtoken.reportedVisible = false;
9004 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009005 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009006 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009007 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009008 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009009 wtoken.showAllWindowsLocked();
9010 }
9011 NN = mClosingApps.size();
9012 for (i=0; i<NN; i++) {
9013 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009014 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009015 "Now closing app" + wtoken);
9016 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009017 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009018 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009019 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009020 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009021 // Force the allDrawn flag, because we want to start
9022 // this guy's animations regardless of whether it's
9023 // gotten drawn.
9024 wtoken.allDrawn = true;
9025 }
9026
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009027 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009029 mOpeningApps.clear();
9030 mClosingApps.clear();
9031
9032 // This has changed the visibility of windows, so perform
9033 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009034 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009035 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009036 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9037 assignLayersLocked();
9038 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009039 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009040 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009041 }
9042 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009043
Dianne Hackborn16064f92010-03-25 00:47:24 -07009044 int adjResult = 0;
9045
Dianne Hackborna8f60182009-09-01 19:01:50 -07009046 if (!animating && mAppTransitionRunning) {
9047 // We have finished the animation of an app transition. To do
9048 // this, we have delayed a lot of operations like showing and
9049 // hiding apps, moving apps in Z-order, etc. The app token list
9050 // reflects the correct Z-order, but the window list may now
9051 // be out of sync with it. So here we will just rebuild the
9052 // entire app window list. Fun!
9053 mAppTransitionRunning = false;
9054 // Clear information about apps that were moving.
9055 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009056
Dianne Hackborna8f60182009-09-01 19:01:50 -07009057 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009058 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009059 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009060 moveInputMethodWindowsIfNeededLocked(false);
9061 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009062 // Since the window list has been rebuilt, focus might
9063 // have to be recomputed since the actual order of windows
9064 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009065 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009066 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009067
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009068 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009069 // At this point, there was a window with a wallpaper that
9070 // was force hiding other windows behind it, but now it
9071 // is going away. This may be simple -- just animate
9072 // away the wallpaper and its window -- or it may be
9073 // hard -- the wallpaper now needs to be shown behind
9074 // something that was hidden.
9075 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009076 if (mLowerWallpaperTarget != null
9077 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009078 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009079 "wallpaperForceHiding changed with lower="
9080 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009081 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009082 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9083 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9084 if (mLowerWallpaperTarget.mAppToken.hidden) {
9085 // The lower target has become hidden before we
9086 // actually started the animation... let's completely
9087 // re-evaluate everything.
9088 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009089 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009090 }
9091 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009092 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009093 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009094 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009095 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009096 + " NEW: " + mWallpaperTarget
9097 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009098 if (mLowerWallpaperTarget == null) {
9099 // Whoops, we don't need a special wallpaper animation.
9100 // Clear them out.
9101 forceHiding = false;
9102 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009103 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009104 if (w.mSurface != null) {
9105 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009106 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009107 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009108 forceHiding = true;
9109 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9110 if (!w.mAnimating) {
9111 // We set the animation above so it
9112 // is not yet running.
9113 w.clearAnimation();
9114 }
9115 }
9116 }
9117 }
9118 }
9119 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009120
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009121 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009122 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009123 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009124 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009125 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009126
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009127 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009128 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009129 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009130 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009131 assignLayersLocked();
9132 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009133 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009134 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009135 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009137
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009138 if (mFocusMayChange) {
9139 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009140 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009141 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009142 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009143 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009144 }
9145
9146 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009147 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009148 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009149
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009150 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9151 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009152
Jeff Browne33348b2010-07-15 23:54:05 -07009153 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009154 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009155
9156 // THIRD LOOP: Update the surfaces of all windows.
9157
9158 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9159
9160 boolean obscured = false;
9161 boolean blurring = false;
9162 boolean dimming = false;
9163 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009164 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009165 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009166
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009167 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009169 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009170 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009171
9172 boolean displayed = false;
9173 final WindowManager.LayoutParams attrs = w.mAttrs;
9174 final int attrFlags = attrs.flags;
9175
9176 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009177 // XXX NOTE: The logic here could be improved. We have
9178 // the decision about whether to resize a window separated
9179 // from whether to hide the surface. This can cause us to
9180 // resize a surface even if we are going to hide it. You
9181 // can see this by (1) holding device in landscape mode on
9182 // home screen; (2) tapping browser icon (device will rotate
9183 // to landscape; (3) tap home. The wallpaper will be resized
9184 // in step 2 but then immediately hidden, causing us to
9185 // have to resize and then redraw it again in step 3. It
9186 // would be nice to figure out how to avoid this, but it is
9187 // difficult because we do need to resize surfaces in some
9188 // cases while they are hidden such as when first showing a
9189 // window.
9190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009191 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009192 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009193 TAG, "Placing surface #" + i + " " + w.mSurface
9194 + ": new=" + w.mShownFrame + ", old="
9195 + w.mLastShownFrame);
9196
9197 boolean resize;
9198 int width, height;
9199 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9200 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9201 w.mLastRequestedHeight != w.mRequestedHeight;
9202 // for a scaled surface, we just want to use
9203 // the requested size.
9204 width = w.mRequestedWidth;
9205 height = w.mRequestedHeight;
9206 w.mLastRequestedWidth = width;
9207 w.mLastRequestedHeight = height;
9208 w.mLastShownFrame.set(w.mShownFrame);
9209 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009210 if (SHOW_TRANSACTIONS) logSurface(w,
9211 "POS " + w.mShownFrame.left
9212 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009213 w.mSurfaceX = w.mShownFrame.left;
9214 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009215 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9216 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009217 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009218 if (!recoveringMemory) {
9219 reclaimSomeSurfaceMemoryLocked(w, "position");
9220 }
9221 }
9222 } else {
9223 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9224 width = w.mShownFrame.width();
9225 height = w.mShownFrame.height();
9226 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009227 }
9228
9229 if (resize) {
9230 if (width < 1) width = 1;
9231 if (height < 1) height = 1;
9232 if (w.mSurface != null) {
9233 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009234 if (SHOW_TRANSACTIONS) logSurface(w,
9235 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009236 + w.mShownFrame.top + " SIZE "
9237 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009238 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009239 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009240 w.mSurfaceW = width;
9241 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009242 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009243 w.mSurfaceX = w.mShownFrame.left;
9244 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009245 w.mSurface.setPosition(w.mShownFrame.left,
9246 w.mShownFrame.top);
9247 } catch (RuntimeException e) {
9248 // If something goes wrong with the surface (such
9249 // as running out of memory), don't take down the
9250 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009251 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009252 + "size=(" + width + "x" + height
9253 + "), pos=(" + w.mShownFrame.left
9254 + "," + w.mShownFrame.top + ")", e);
9255 if (!recoveringMemory) {
9256 reclaimSomeSurfaceMemoryLocked(w, "size");
9257 }
9258 }
9259 }
9260 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009261 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009262 w.mContentInsetsChanged =
9263 !w.mLastContentInsets.equals(w.mContentInsets);
9264 w.mVisibleInsetsChanged =
9265 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009266 boolean configChanged =
9267 w.mConfiguration != mCurConfiguration
9268 && (w.mConfiguration == null
9269 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009270 if (DEBUG_CONFIGURATION && configChanged) {
9271 Slog.v(TAG, "Win " + w + " config changed: "
9272 + mCurConfiguration);
9273 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009274 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009275 + ": configChanged=" + configChanged
9276 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009277 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009278 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009279 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009280 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009281 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009282 w.mLastFrame.set(w.mFrame);
9283 w.mLastContentInsets.set(w.mContentInsets);
9284 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009285 // If the screen is currently frozen, then keep
9286 // it frozen until this window draws at its new
9287 // orientation.
9288 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009289 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009290 "Resizing while display frozen: " + w);
9291 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009292 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009293 mWindowsFreezingScreen = true;
9294 // XXX should probably keep timeout from
9295 // when we first froze the display.
9296 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9297 mH.sendMessageDelayed(mH.obtainMessage(
9298 H.WINDOW_FREEZE_TIMEOUT), 2000);
9299 }
9300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009301 // If the orientation is changing, then we need to
9302 // hold off on unfreezing the display until this
9303 // window has been redrawn; to do that, we need
9304 // to go through the process of getting informed
9305 // by the application when it has finished drawing.
9306 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009307 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009308 "Orientation start waiting for draw in "
9309 + w + ", surface " + w.mSurface);
9310 w.mDrawPending = true;
9311 w.mCommitDrawPending = false;
9312 w.mReadyToShow = false;
9313 if (w.mAppToken != null) {
9314 w.mAppToken.allDrawn = false;
9315 }
9316 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009317 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009318 "Resizing window " + w + " to " + w.mFrame);
9319 mResizingWindows.add(w);
9320 } else if (w.mOrientationChanging) {
9321 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009322 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009323 "Orientation not waiting for draw in "
9324 + w + ", surface " + w.mSurface);
9325 w.mOrientationChanging = false;
9326 }
9327 }
9328 }
9329
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009330 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009331 if (!w.mLastHidden) {
9332 //dump();
9333 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009334 if (SHOW_TRANSACTIONS) logSurface(w,
9335 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009336 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009337 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009338 try {
9339 w.mSurface.hide();
9340 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009341 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009342 }
9343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009344 }
9345 // If we are waiting for this window to handle an
9346 // orientation change, well, it is hidden, so
9347 // doesn't really matter. Note that this does
9348 // introduce a potential glitch if the window
9349 // becomes unhidden before it has drawn for the
9350 // new orientation.
9351 if (w.mOrientationChanging) {
9352 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009353 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009354 "Orientation change skips hidden " + w);
9355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009356 } else if (w.mLastLayer != w.mAnimLayer
9357 || w.mLastAlpha != w.mShownAlpha
9358 || w.mLastDsDx != w.mDsDx
9359 || w.mLastDtDx != w.mDtDx
9360 || w.mLastDsDy != w.mDsDy
9361 || w.mLastDtDy != w.mDtDy
9362 || w.mLastHScale != w.mHScale
9363 || w.mLastVScale != w.mVScale
9364 || w.mLastHidden) {
9365 displayed = true;
9366 w.mLastAlpha = w.mShownAlpha;
9367 w.mLastLayer = w.mAnimLayer;
9368 w.mLastDsDx = w.mDsDx;
9369 w.mLastDtDx = w.mDtDx;
9370 w.mLastDsDy = w.mDsDy;
9371 w.mLastDtDy = w.mDtDy;
9372 w.mLastHScale = w.mHScale;
9373 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009374 if (SHOW_TRANSACTIONS) logSurface(w,
9375 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009376 + " matrix=[" + (w.mDsDx*w.mHScale)
9377 + "," + (w.mDtDx*w.mVScale)
9378 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009379 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009380 if (w.mSurface != null) {
9381 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009382 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009383 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009384 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009385 w.mSurface.setLayer(w.mAnimLayer);
9386 w.mSurface.setMatrix(
9387 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9388 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9389 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009390 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009391 if (!recoveringMemory) {
9392 reclaimSomeSurfaceMemoryLocked(w, "update");
9393 }
9394 }
9395 }
9396
9397 if (w.mLastHidden && !w.mDrawPending
9398 && !w.mCommitDrawPending
9399 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009400 if (SHOW_TRANSACTIONS) logSurface(w,
9401 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009402 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009403 + " during relayout");
9404 if (showSurfaceRobustlyLocked(w)) {
9405 w.mHasDrawn = true;
9406 w.mLastHidden = false;
9407 } else {
9408 w.mOrientationChanging = false;
9409 }
9410 }
9411 if (w.mSurface != null) {
9412 w.mToken.hasVisible = true;
9413 }
9414 } else {
9415 displayed = true;
9416 }
9417
9418 if (displayed) {
9419 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009420 if (attrs.width == LayoutParams.MATCH_PARENT
9421 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009422 covered = true;
9423 }
9424 }
9425 if (w.mOrientationChanging) {
9426 if (w.mDrawPending || w.mCommitDrawPending) {
9427 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009428 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009429 "Orientation continue waiting for draw in " + w);
9430 } else {
9431 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009432 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009433 "Orientation change complete in " + w);
9434 }
9435 }
9436 w.mToken.hasVisible = true;
9437 }
9438 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009439 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009440 "Orientation change skips hidden " + w);
9441 w.mOrientationChanging = false;
9442 }
9443
9444 final boolean canBeSeen = w.isDisplayedLw();
9445
9446 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9447 focusDisplayed = true;
9448 }
9449
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009450 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009452 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009453 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009454 if (w.mSurface != null) {
9455 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9456 holdScreen = w.mSession;
9457 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009458 if (!syswin && w.mAttrs.screenBrightness >= 0
9459 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009460 screenBrightness = w.mAttrs.screenBrightness;
9461 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009462 if (!syswin && w.mAttrs.buttonBrightness >= 0
9463 && buttonBrightness < 0) {
9464 buttonBrightness = w.mAttrs.buttonBrightness;
9465 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009466 if (canBeSeen
9467 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9468 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9469 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009470 syswin = true;
9471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009472 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009473
Dianne Hackborn25994b42009-09-04 14:21:19 -07009474 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9475 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009476 // This window completely covers everything behind it,
9477 // so we want to leave all of them as unblurred (for
9478 // performance reasons).
9479 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009480 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009481 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009482 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009483 obscured = true;
9484 if (mBackgroundFillerSurface == null) {
9485 try {
9486 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009487 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009488 0, dw, dh,
9489 PixelFormat.OPAQUE,
9490 Surface.FX_SURFACE_NORMAL);
9491 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009492 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009493 }
9494 }
9495 try {
9496 mBackgroundFillerSurface.setPosition(0, 0);
9497 mBackgroundFillerSurface.setSize(dw, dh);
9498 // Using the same layer as Dim because they will never be shown at the
9499 // same time.
9500 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9501 mBackgroundFillerSurface.show();
9502 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009503 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009504 }
9505 backgroundFillerShown = true;
9506 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009507 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009508 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009509 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009510 + ": blurring=" + blurring
9511 + " obscured=" + obscured
9512 + " displayed=" + displayed);
9513 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9514 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009515 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009516 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009517 if (mDimAnimator == null) {
9518 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009519 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009520 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009521 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009522 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009523 }
9524 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9525 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009526 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009527 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009528 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009529 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009530 + mBlurSurface + ": CREATE");
9531 try {
Romain Guy06882f82009-06-10 13:36:04 -07009532 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009533 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009534 -1, 16, 16,
9535 PixelFormat.OPAQUE,
9536 Surface.FX_SURFACE_BLUR);
9537 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009538 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009539 }
9540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009541 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009542 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9543 + mBlurSurface + ": pos=(0,0) (" +
9544 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009545 mBlurSurface.setPosition(0, 0);
9546 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009547 mBlurSurface.setLayer(w.mAnimLayer-2);
9548 if (!mBlurShown) {
9549 try {
9550 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
9551 + mBlurSurface + ": SHOW");
9552 mBlurSurface.show();
9553 } catch (RuntimeException e) {
9554 Slog.w(TAG, "Failure showing blur surface", e);
9555 }
9556 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009557 }
9558 }
9559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009560 }
9561 }
9562 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009563
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009564 if (obscuredChanged && mWallpaperTarget == w) {
9565 // This is the wallpaper target and its obscured state
9566 // changed... make sure the current wallaper's visibility
9567 // has been updated accordingly.
9568 updateWallpaperVisibilityLocked();
9569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009570 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009571
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009572 if (backgroundFillerShown == false && mBackgroundFillerShown) {
9573 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009574 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009575 try {
9576 mBackgroundFillerSurface.hide();
9577 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009578 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009579 }
9580 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009581
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009582 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009583 animating |= mDimAnimator.updateSurface(dimming, currentTime,
9584 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009585 }
Romain Guy06882f82009-06-10 13:36:04 -07009586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009587 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009588 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009589 + ": HIDE");
9590 try {
9591 mBlurSurface.hide();
9592 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009593 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009594 }
9595 mBlurShown = false;
9596 }
9597
Joe Onorato8a9b2202010-02-26 18:56:32 -08009598 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009599 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009600 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009601 }
9602
Jeff Browne33348b2010-07-15 23:54:05 -07009603 mInputMonitor.updateInputWindowsLw();
9604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009605 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -07009606
Dianne Hackbornb9fb1702010-08-23 16:49:02 -07009607 if (mWatermark != null) {
9608 mWatermark.drawIfNeeded();
9609 }
9610
Joe Onorato8a9b2202010-02-26 18:56:32 -08009611 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009612 "With display frozen, orientationChangeComplete="
9613 + orientationChangeComplete);
9614 if (orientationChangeComplete) {
9615 if (mWindowsFreezingScreen) {
9616 mWindowsFreezingScreen = false;
9617 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9618 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009619 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009620 }
Romain Guy06882f82009-06-10 13:36:04 -07009621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009622 i = mResizingWindows.size();
9623 if (i > 0) {
9624 do {
9625 i--;
9626 WindowState win = mResizingWindows.get(i);
9627 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009628 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
9629 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009630 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009631 boolean configChanged =
9632 win.mConfiguration != mCurConfiguration
9633 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009634 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
9635 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
9636 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009637 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009638 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009639 + " / " + mCurConfiguration + " / 0x"
9640 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009641 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009642 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009643 win.mClient.resized(win.mFrame.width(),
9644 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009645 win.mLastVisibleInsets, win.mDrawPending,
9646 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009647 win.mContentInsetsChanged = false;
9648 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009649 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009650 } catch (RemoteException e) {
9651 win.mOrientationChanging = false;
9652 }
9653 } while (i > 0);
9654 mResizingWindows.clear();
9655 }
Romain Guy06882f82009-06-10 13:36:04 -07009656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009657 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009658 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009659 i = mDestroySurface.size();
9660 if (i > 0) {
9661 do {
9662 i--;
9663 WindowState win = mDestroySurface.get(i);
9664 win.mDestroying = false;
9665 if (mInputMethodWindow == win) {
9666 mInputMethodWindow = null;
9667 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009668 if (win == mWallpaperTarget) {
9669 wallpaperDestroyed = true;
9670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009671 win.destroySurfaceLocked();
9672 } while (i > 0);
9673 mDestroySurface.clear();
9674 }
9675
9676 // Time to remove any exiting tokens?
9677 for (i=mExitingTokens.size()-1; i>=0; i--) {
9678 WindowToken token = mExitingTokens.get(i);
9679 if (!token.hasVisible) {
9680 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07009681 if (token.windowType == TYPE_WALLPAPER) {
9682 mWallpaperTokens.remove(token);
9683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009684 }
9685 }
9686
9687 // Time to remove any exiting applications?
9688 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9689 AppWindowToken token = mExitingAppTokens.get(i);
9690 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07009691 // Make sure there is no animation running on this token,
9692 // so any windows associated with it will be removed as
9693 // soon as their animations are complete
9694 token.animation = null;
9695 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009696 mAppTokens.remove(token);
9697 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009698 if (mLastEnterAnimToken == token) {
9699 mLastEnterAnimToken = null;
9700 mLastEnterAnimParams = null;
9701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009702 }
9703 }
9704
Dianne Hackborna8f60182009-09-01 19:01:50 -07009705 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009706
Dianne Hackborna8f60182009-09-01 19:01:50 -07009707 if (!animating && mAppTransitionRunning) {
9708 // We have finished the animation of an app transition. To do
9709 // this, we have delayed a lot of operations like showing and
9710 // hiding apps, moving apps in Z-order, etc. The app token list
9711 // reflects the correct Z-order, but the window list may now
9712 // be out of sync with it. So here we will just rebuild the
9713 // entire app window list. Fun!
9714 mAppTransitionRunning = false;
9715 needRelayout = true;
9716 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009717 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009718 // Clear information about apps that were moving.
9719 mToBottomApps.clear();
9720 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009722 if (focusDisplayed) {
9723 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
9724 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009725 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009726 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009727 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07009728 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009729 requestAnimationLocked(0);
9730 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009731 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
9732 }
Jeff Browneb857f12010-07-16 10:06:33 -07009733
Jeff Browne33348b2010-07-15 23:54:05 -07009734 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -07009735
Jeff Brown8e03b752010-06-13 19:16:55 -07009736 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009737 if (screenBrightness < 0 || screenBrightness > 1.0f) {
9738 mPowerManager.setScreenBrightnessOverride(-1);
9739 } else {
9740 mPowerManager.setScreenBrightnessOverride((int)
9741 (screenBrightness * Power.BRIGHTNESS_ON));
9742 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009743 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
9744 mPowerManager.setButtonBrightnessOverride(-1);
9745 } else {
9746 mPowerManager.setButtonBrightnessOverride((int)
9747 (buttonBrightness * Power.BRIGHTNESS_ON));
9748 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009749 if (holdScreen != mHoldingScreenOn) {
9750 mHoldingScreenOn = holdScreen;
9751 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
9752 mH.sendMessage(m);
9753 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009754
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009755 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009756 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009757 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
9758 LocalPowerManager.BUTTON_EVENT, true);
9759 mTurnOnScreen = false;
9760 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08009761
9762 // Check to see if we are now in a state where the screen should
9763 // be enabled, because the window obscured flags have changed.
9764 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07009766
9767 /**
9768 * Must be called with the main window manager lock held.
9769 */
9770 void setHoldScreenLocked(boolean holding) {
9771 boolean state = mHoldingScreenWakeLock.isHeld();
9772 if (holding != state) {
9773 if (holding) {
9774 mHoldingScreenWakeLock.acquire();
9775 } else {
9776 mPolicy.screenOnStoppedLw();
9777 mHoldingScreenWakeLock.release();
9778 }
9779 }
9780 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009781
9782 void requestAnimationLocked(long delay) {
9783 if (!mAnimationPending) {
9784 mAnimationPending = true;
9785 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
9786 }
9787 }
Romain Guy06882f82009-06-10 13:36:04 -07009788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009789 /**
9790 * Have the surface flinger show a surface, robustly dealing with
9791 * error conditions. In particular, if there is not enough memory
9792 * to show the surface, then we will try to get rid of other surfaces
9793 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -07009794 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 * @return Returns true if the surface was successfully shown.
9796 */
9797 boolean showSurfaceRobustlyLocked(WindowState win) {
9798 try {
9799 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009800 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009801 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009802 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009803 if (DEBUG_VISIBILITY) Slog.v(TAG,
9804 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07009805 win.mTurnOnScreen = false;
9806 mTurnOnScreen = true;
9807 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 }
9809 return true;
9810 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009811 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009812 }
Romain Guy06882f82009-06-10 13:36:04 -07009813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009814 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -07009815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009816 return false;
9817 }
Romain Guy06882f82009-06-10 13:36:04 -07009818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009819 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
9820 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -07009821
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009822 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009823 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -07009824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009825 if (mForceRemoves == null) {
9826 mForceRemoves = new ArrayList<WindowState>();
9827 }
Romain Guy06882f82009-06-10 13:36:04 -07009828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009829 long callingIdentity = Binder.clearCallingIdentity();
9830 try {
9831 // There was some problem... first, do a sanity check of the
9832 // window list to make sure we haven't left any dangling surfaces
9833 // around.
9834 int N = mWindows.size();
9835 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009836 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009837 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009838 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009839 if (ws.mSurface != null) {
9840 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009841 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009842 + ws + " surface=" + ws.mSurface
9843 + " token=" + win.mToken
9844 + " pid=" + ws.mSession.mPid
9845 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009846 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009847 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009848 ws.mSurface = null;
9849 mForceRemoves.add(ws);
9850 i--;
9851 N--;
9852 leakedSurface = true;
9853 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009854 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855 + ws + " surface=" + ws.mSurface
9856 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009857 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009858 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009859 ws.mSurface = null;
9860 leakedSurface = true;
9861 }
9862 }
9863 }
Romain Guy06882f82009-06-10 13:36:04 -07009864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009865 boolean killedApps = false;
9866 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009867 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009868 SparseIntArray pidCandidates = new SparseIntArray();
9869 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07009870 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009871 if (ws.mSurface != null) {
9872 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
9873 }
9874 }
9875 if (pidCandidates.size() > 0) {
9876 int[] pids = new int[pidCandidates.size()];
9877 for (int i=0; i<pids.length; i++) {
9878 pids[i] = pidCandidates.keyAt(i);
9879 }
9880 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -07009881 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009882 killedApps = true;
9883 }
9884 } catch (RemoteException e) {
9885 }
9886 }
9887 }
Romain Guy06882f82009-06-10 13:36:04 -07009888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009889 if (leakedSurface || killedApps) {
9890 // We managed to reclaim some memory, so get rid of the trouble
9891 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009892 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009894 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -07009895 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009896 win.mSurface = null;
9897 }
Romain Guy06882f82009-06-10 13:36:04 -07009898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009899 try {
9900 win.mClient.dispatchGetNewSurface();
9901 } catch (RemoteException e) {
9902 }
9903 }
9904 } finally {
9905 Binder.restoreCallingIdentity(callingIdentity);
9906 }
9907 }
Romain Guy06882f82009-06-10 13:36:04 -07009908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009909 private boolean updateFocusedWindowLocked(int mode) {
9910 WindowState newFocus = computeFocusedWindowLocked();
9911 if (mCurrentFocus != newFocus) {
9912 // This check makes sure that we don't already have the focus
9913 // change message pending.
9914 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
9915 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009916 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009917 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
9918 final WindowState oldFocus = mCurrentFocus;
9919 mCurrentFocus = newFocus;
9920 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -07009921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009922 final WindowState imWindow = mInputMethodWindow;
9923 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009924 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009925 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009926 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
9927 mLayoutNeeded = true;
9928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009929 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
9930 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009931 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
9932 // Client will do the layout, but we need to assign layers
9933 // for handleNewWindowLocked() below.
9934 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009935 }
9936 }
Jeff Brown349703e2010-06-22 01:27:15 -07009937
9938 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
9939 // If we defer assigning layers, then the caller is responsible for
9940 // doing this part.
9941 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08009942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009943 return true;
9944 }
9945 return false;
9946 }
Jeff Brown349703e2010-06-22 01:27:15 -07009947
9948 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07009949 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07009950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009951
9952 private WindowState computeFocusedWindowLocked() {
9953 WindowState result = null;
9954 WindowState win;
9955
9956 int i = mWindows.size() - 1;
9957 int nextAppIndex = mAppTokens.size()-1;
9958 WindowToken nextApp = nextAppIndex >= 0
9959 ? mAppTokens.get(nextAppIndex) : null;
9960
9961 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07009962 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009963
Joe Onorato8a9b2202010-02-26 18:56:32 -08009964 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009965 TAG, "Looking for focus: " + i
9966 + " = " + win
9967 + ", flags=" + win.mAttrs.flags
9968 + ", canReceive=" + win.canReceiveKeys());
9969
9970 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -07009971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009972 // If this window's application has been removed, just skip it.
9973 if (thisApp != null && thisApp.removed) {
9974 i--;
9975 continue;
9976 }
Romain Guy06882f82009-06-10 13:36:04 -07009977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009978 // If there is a focused app, don't allow focus to go to any
9979 // windows below it. If this is an application window, step
9980 // through the app tokens until we find its app.
9981 if (thisApp != null && nextApp != null && thisApp != nextApp
9982 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
9983 int origAppIndex = nextAppIndex;
9984 while (nextAppIndex > 0) {
9985 if (nextApp == mFocusedApp) {
9986 // Whoops, we are below the focused app... no focus
9987 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -08009988 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009989 TAG, "Reached focused app: " + mFocusedApp);
9990 return null;
9991 }
9992 nextAppIndex--;
9993 nextApp = mAppTokens.get(nextAppIndex);
9994 if (nextApp == thisApp) {
9995 break;
9996 }
9997 }
9998 if (thisApp != nextApp) {
9999 // Uh oh, the app token doesn't exist! This shouldn't
10000 // happen, but if it does we can get totally hosed...
10001 // so restart at the original app.
10002 nextAppIndex = origAppIndex;
10003 nextApp = mAppTokens.get(nextAppIndex);
10004 }
10005 }
10006
10007 // Dispatch to this window if it is wants key events.
10008 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010009 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010010 TAG, "Found focus @ " + i + " = " + win);
10011 result = win;
10012 break;
10013 }
10014
10015 i--;
10016 }
10017
10018 return result;
10019 }
10020
10021 private void startFreezingDisplayLocked() {
10022 if (mDisplayFrozen) {
10023 return;
10024 }
Romain Guy06882f82009-06-10 13:36:04 -070010025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010026 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010028 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010029 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010030 if (mFreezeGcPending != 0) {
10031 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010032 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010033 mH.removeMessages(H.FORCE_GC);
10034 Runtime.getRuntime().gc();
10035 mFreezeGcPending = now;
10036 }
10037 } else {
10038 mFreezeGcPending = now;
10039 }
Romain Guy06882f82009-06-10 13:36:04 -070010040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010041 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010042
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010043 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010044
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010045 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10046 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010047 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010048 mAppTransitionReady = true;
10049 }
Romain Guy06882f82009-06-10 13:36:04 -070010050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010051 if (PROFILE_ORIENTATION) {
10052 File file = new File("/data/system/frozen");
10053 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10054 }
10055 Surface.freezeDisplay(0);
10056 }
Romain Guy06882f82009-06-10 13:36:04 -070010057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 private void stopFreezingDisplayLocked() {
10059 if (!mDisplayFrozen) {
10060 return;
10061 }
Romain Guy06882f82009-06-10 13:36:04 -070010062
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010063 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10064 return;
10065 }
10066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010067 mDisplayFrozen = false;
10068 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10069 if (PROFILE_ORIENTATION) {
10070 Debug.stopMethodTracing();
10071 }
10072 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010073
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010074 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010075
Christopher Tateb696aee2010-04-02 19:08:30 -070010076 // While the display is frozen we don't re-compute the orientation
10077 // to avoid inconsistent states. However, something interesting
10078 // could have actually changed during that time so re-evaluate it
10079 // now to catch that.
10080 if (updateOrientationFromAppTokensLocked()) {
10081 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10082 }
10083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010084 // A little kludge: a lot could have happened while the
10085 // display was frozen, so now that we are coming back we
10086 // do a gc so that any remote references the system
10087 // processes holds on others can be released if they are
10088 // no longer needed.
10089 mH.removeMessages(H.FORCE_GC);
10090 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10091 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010093 mScreenFrozenLock.release();
10094 }
Romain Guy06882f82009-06-10 13:36:04 -070010095
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010096 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10097 DisplayMetrics dm) {
10098 if (index < tokens.length) {
10099 String str = tokens[index];
10100 if (str != null && str.length() > 0) {
10101 try {
10102 int val = Integer.parseInt(str);
10103 return val;
10104 } catch (Exception e) {
10105 }
10106 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010107 }
10108 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10109 return defDps;
10110 }
10111 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10112 return val;
10113 }
10114
10115 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010116 final String[] mTokens;
10117 final String mText;
10118 final Paint mTextPaint;
10119 final int mTextWidth;
10120 final int mTextHeight;
10121 final int mTextAscent;
10122 final int mTextDescent;
10123 final int mDeltaX;
10124 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010125
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010126 Surface mSurface;
10127 int mLastDW;
10128 int mLastDH;
10129 boolean mDrawNeeded;
10130
10131 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010132 final DisplayMetrics dm = new DisplayMetrics();
10133 mDisplay.getMetrics(dm);
10134
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010135 if (false) {
10136 Log.i(TAG, "*********************** WATERMARK");
10137 for (int i=0; i<tokens.length; i++) {
10138 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10139 }
10140 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010141
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010142 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010143
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010144 StringBuilder builder = new StringBuilder(32);
10145 int len = mTokens[0].length();
10146 len = len & ~1;
10147 for (int i=0; i<len; i+=2) {
10148 int c1 = mTokens[0].charAt(i);
10149 int c2 = mTokens[0].charAt(i+1);
10150 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10151 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10152 else c1 -= '0';
10153 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10154 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10155 else c2 -= '0';
10156 builder.append((char)(255-((c1*16)+c2)));
10157 }
10158 mText = builder.toString();
10159 if (false) {
10160 Log.i(TAG, "Final text: " + mText);
10161 }
10162
10163 int fontSize = getPropertyInt(tokens, 1,
10164 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10165
10166 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10167 mTextPaint.setTextSize(fontSize);
10168 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10169
10170 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10171 mTextWidth = (int)mTextPaint.measureText(mText);
10172 mTextAscent = fm.ascent;
10173 mTextDescent = fm.descent;
10174 mTextHeight = fm.descent - fm.ascent;
10175
10176 mDeltaX = getPropertyInt(tokens, 2,
10177 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10178 mDeltaY = getPropertyInt(tokens, 3,
10179 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10180 int shadowColor = getPropertyInt(tokens, 4,
10181 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10182 int color = getPropertyInt(tokens, 5,
10183 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10184 int shadowRadius = getPropertyInt(tokens, 6,
10185 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10186 int shadowDx = getPropertyInt(tokens, 8,
10187 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10188 int shadowDy = getPropertyInt(tokens, 9,
10189 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10190
10191 mTextPaint.setColor(color);
10192 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010193
10194 try {
10195 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010196 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010197 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010198 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010199 mSurface.show();
10200 } catch (OutOfResourcesException e) {
10201 }
10202 }
10203
10204 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010205 if (mLastDW != dw || mLastDH != dh) {
10206 mLastDW = dw;
10207 mLastDH = dh;
10208 mSurface.setSize(dw, dh);
10209 mDrawNeeded = true;
10210 }
10211 }
10212
10213 void drawIfNeeded() {
10214 if (mDrawNeeded) {
10215 final int dw = mLastDW;
10216 final int dh = mLastDH;
10217
10218 mDrawNeeded = false;
10219 Rect dirty = new Rect(0, 0, dw, dh);
10220 Canvas c = null;
10221 try {
10222 c = mSurface.lockCanvas(dirty);
10223 } catch (IllegalArgumentException e) {
10224 } catch (OutOfResourcesException e) {
10225 }
10226 if (c != null) {
10227 int deltaX = mDeltaX;
10228 int deltaY = mDeltaY;
10229
10230 // deltaX shouldn't be close to a round fraction of our
10231 // x step, or else things will line up too much.
10232 int div = (dw+mTextWidth)/deltaX;
10233 int rem = (dw+mTextWidth) - (div*deltaX);
10234 int qdelta = deltaX/4;
10235 if (rem < qdelta || rem > (deltaX-qdelta)) {
10236 deltaX += deltaX/3;
10237 }
10238
10239 int y = -mTextHeight;
10240 int x = -mTextWidth;
10241 while (y < (dh+mTextHeight)) {
10242 c.drawText(mText, x, y, mTextPaint);
10243 x += deltaX;
10244 if (x >= dw) {
10245 x -= (dw+mTextWidth);
10246 y += deltaY;
10247 }
10248 }
10249 mSurface.unlockCanvasAndPost(c);
10250 }
10251 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010252 }
10253 }
10254
10255 void createWatermark() {
10256 if (mWatermark != null) {
10257 return;
10258 }
10259
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010260 File file = new File("/system/etc/setup.conf");
10261 FileInputStream in = null;
10262 try {
10263 in = new FileInputStream(file);
10264 DataInputStream ind = new DataInputStream(in);
10265 String line = ind.readLine();
10266 if (line != null) {
10267 String[] toks = line.split("%");
10268 if (toks != null && toks.length > 0) {
10269 mWatermark = new Watermark(mFxSession, toks);
10270 }
10271 }
10272 } catch (FileNotFoundException e) {
10273 } catch (IOException e) {
10274 } finally {
10275 if (in != null) {
10276 try {
10277 in.close();
10278 } catch (IOException e) {
10279 }
10280 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010281 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010282 }
10283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010284 @Override
10285 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10286 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10287 != PackageManager.PERMISSION_GRANTED) {
10288 pw.println("Permission Denial: can't dump WindowManager from from pid="
10289 + Binder.getCallingPid()
10290 + ", uid=" + Binder.getCallingUid());
10291 return;
10292 }
Romain Guy06882f82009-06-10 13:36:04 -070010293
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010294 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010295 pw.println(" ");
10296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010297 synchronized(mWindowMap) {
10298 pw.println("Current Window Manager state:");
10299 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010300 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010301 pw.print(" Window #"); pw.print(i); pw.print(' ');
10302 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010303 w.dump(pw, " ");
10304 }
10305 if (mInputMethodDialogs.size() > 0) {
10306 pw.println(" ");
10307 pw.println(" Input method dialogs:");
10308 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10309 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010310 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010311 }
10312 }
10313 if (mPendingRemove.size() > 0) {
10314 pw.println(" ");
10315 pw.println(" Remove pending for:");
10316 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10317 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010318 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10319 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010320 w.dump(pw, " ");
10321 }
10322 }
10323 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10324 pw.println(" ");
10325 pw.println(" Windows force removing:");
10326 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10327 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010328 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10329 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010330 w.dump(pw, " ");
10331 }
10332 }
10333 if (mDestroySurface.size() > 0) {
10334 pw.println(" ");
10335 pw.println(" Windows waiting to destroy their surface:");
10336 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10337 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010338 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10339 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010340 w.dump(pw, " ");
10341 }
10342 }
10343 if (mLosingFocus.size() > 0) {
10344 pw.println(" ");
10345 pw.println(" Windows losing focus:");
10346 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10347 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010348 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10349 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010350 w.dump(pw, " ");
10351 }
10352 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010353 if (mResizingWindows.size() > 0) {
10354 pw.println(" ");
10355 pw.println(" Windows waiting to resize:");
10356 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10357 WindowState w = mResizingWindows.get(i);
10358 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10359 pw.print(w); pw.println(":");
10360 w.dump(pw, " ");
10361 }
10362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 if (mSessions.size() > 0) {
10364 pw.println(" ");
10365 pw.println(" All active sessions:");
10366 Iterator<Session> it = mSessions.iterator();
10367 while (it.hasNext()) {
10368 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010369 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010370 s.dump(pw, " ");
10371 }
10372 }
10373 if (mTokenMap.size() > 0) {
10374 pw.println(" ");
10375 pw.println(" All tokens:");
10376 Iterator<WindowToken> it = mTokenMap.values().iterator();
10377 while (it.hasNext()) {
10378 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010379 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010380 token.dump(pw, " ");
10381 }
10382 }
10383 if (mTokenList.size() > 0) {
10384 pw.println(" ");
10385 pw.println(" Window token list:");
10386 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010387 pw.print(" #"); pw.print(i); pw.print(": ");
10388 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010389 }
10390 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010391 if (mWallpaperTokens.size() > 0) {
10392 pw.println(" ");
10393 pw.println(" Wallpaper tokens:");
10394 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10395 WindowToken token = mWallpaperTokens.get(i);
10396 pw.print(" Wallpaper #"); pw.print(i);
10397 pw.print(' '); pw.print(token); pw.println(':');
10398 token.dump(pw, " ");
10399 }
10400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010401 if (mAppTokens.size() > 0) {
10402 pw.println(" ");
10403 pw.println(" Application tokens in Z order:");
10404 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010405 pw.print(" App #"); pw.print(i); pw.print(": ");
10406 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 }
10408 }
10409 if (mFinishedStarting.size() > 0) {
10410 pw.println(" ");
10411 pw.println(" Finishing start of application tokens:");
10412 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10413 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010414 pw.print(" Finished Starting #"); pw.print(i);
10415 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010416 token.dump(pw, " ");
10417 }
10418 }
10419 if (mExitingTokens.size() > 0) {
10420 pw.println(" ");
10421 pw.println(" Exiting tokens:");
10422 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10423 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010424 pw.print(" Exiting #"); pw.print(i);
10425 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010426 token.dump(pw, " ");
10427 }
10428 }
10429 if (mExitingAppTokens.size() > 0) {
10430 pw.println(" ");
10431 pw.println(" Exiting application tokens:");
10432 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10433 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010434 pw.print(" Exiting App #"); pw.print(i);
10435 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010436 token.dump(pw, " ");
10437 }
10438 }
10439 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010440 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10441 pw.print(" mLastFocus="); pw.println(mLastFocus);
10442 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10443 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10444 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010445 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010446 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10447 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10448 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10449 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010450 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10451 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10452 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010453 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10454 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10455 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10456 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010457 if (mDimAnimator != null) {
10458 mDimAnimator.printTo(pw);
10459 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010460 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010461 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010462 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010463 pw.print(mInputMethodAnimLayerAdjustment);
10464 pw.print(" mWallpaperAnimLayerAdjustment=");
10465 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010466 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10467 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010468 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10469 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010470 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10471 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010472 pw.print(" mRotation="); pw.print(mRotation);
10473 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10474 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10475 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10476 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10477 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10478 pw.print(" mNextAppTransition=0x");
10479 pw.print(Integer.toHexString(mNextAppTransition));
10480 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010481 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010482 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010483 if (mNextAppTransitionPackage != null) {
10484 pw.print(" mNextAppTransitionPackage=");
10485 pw.print(mNextAppTransitionPackage);
10486 pw.print(", mNextAppTransitionEnter=0x");
10487 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10488 pw.print(", mNextAppTransitionExit=0x");
10489 pw.print(Integer.toHexString(mNextAppTransitionExit));
10490 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010491 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10492 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010493 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10494 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10495 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10496 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010497 if (mOpeningApps.size() > 0) {
10498 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10499 }
10500 if (mClosingApps.size() > 0) {
10501 pw.print(" mClosingApps="); pw.println(mClosingApps);
10502 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010503 if (mToTopApps.size() > 0) {
10504 pw.print(" mToTopApps="); pw.println(mToTopApps);
10505 }
10506 if (mToBottomApps.size() > 0) {
10507 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10508 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010509 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10510 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010511 }
10512 }
10513
Jeff Brown349703e2010-06-22 01:27:15 -070010514 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 public void monitor() {
10516 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010517 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010518 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010519
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010520 /**
10521 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010522 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010523 */
10524 private static class DimAnimator {
10525 Surface mDimSurface;
10526 boolean mDimShown = false;
10527 float mDimCurrentAlpha;
10528 float mDimTargetAlpha;
10529 float mDimDeltaPerMs;
10530 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010531
10532 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010533
10534 DimAnimator (SurfaceSession session) {
10535 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010536 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010537 + mDimSurface + ": CREATE");
10538 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080010539 mDimSurface = new Surface(session, 0,
10540 "DimSurface",
10541 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010542 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010010543 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010544 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010545 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010546 }
10547 }
10548 }
10549
10550 /**
10551 * Show the dim surface.
10552 */
10553 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010554 if (!mDimShown) {
10555 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
10556 dw + "x" + dh + ")");
10557 mDimShown = true;
10558 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010559 mLastDimWidth = dw;
10560 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070010561 mDimSurface.setPosition(0, 0);
10562 mDimSurface.setSize(dw, dh);
10563 mDimSurface.show();
10564 } catch (RuntimeException e) {
10565 Slog.w(TAG, "Failure showing dim surface", e);
10566 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010567 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
10568 mLastDimWidth = dw;
10569 mLastDimHeight = dh;
10570 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010571 }
10572 }
10573
10574 /**
10575 * Set's the dim surface's layer and update dim parameters that will be used in
10576 * {@link updateSurface} after all windows are examined.
10577 */
10578 void updateParameters(WindowState w, long currentTime) {
10579 mDimSurface.setLayer(w.mAnimLayer-1);
10580
10581 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010582 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010583 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010584 if (mDimTargetAlpha != target) {
10585 // If the desired dim level has changed, then
10586 // start an animation to it.
10587 mLastDimAnimTime = currentTime;
10588 long duration = (w.mAnimating && w.mAnimation != null)
10589 ? w.mAnimation.computeDurationHint()
10590 : DEFAULT_DIM_DURATION;
10591 if (target > mDimTargetAlpha) {
10592 // This is happening behind the activity UI,
10593 // so we can make it run a little longer to
10594 // give a stronger impression without disrupting
10595 // the user.
10596 duration *= DIM_DURATION_MULTIPLIER;
10597 }
10598 if (duration < 1) {
10599 // Don't divide by zero
10600 duration = 1;
10601 }
10602 mDimTargetAlpha = target;
10603 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
10604 }
10605 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010606
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010607 /**
10608 * Updating the surface's alpha. Returns true if the animation continues, or returns
10609 * false when the animation is finished and the dim surface is hidden.
10610 */
10611 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
10612 if (!dimming) {
10613 if (mDimTargetAlpha != 0) {
10614 mLastDimAnimTime = currentTime;
10615 mDimTargetAlpha = 0;
10616 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
10617 }
10618 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010619
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010620 boolean animating = false;
10621 if (mLastDimAnimTime != 0) {
10622 mDimCurrentAlpha += mDimDeltaPerMs
10623 * (currentTime-mLastDimAnimTime);
10624 boolean more = true;
10625 if (displayFrozen) {
10626 // If the display is frozen, there is no reason to animate.
10627 more = false;
10628 } else if (mDimDeltaPerMs > 0) {
10629 if (mDimCurrentAlpha > mDimTargetAlpha) {
10630 more = false;
10631 }
10632 } else if (mDimDeltaPerMs < 0) {
10633 if (mDimCurrentAlpha < mDimTargetAlpha) {
10634 more = false;
10635 }
10636 } else {
10637 more = false;
10638 }
10639
10640 // Do we need to continue animating?
10641 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010642 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010643 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
10644 mLastDimAnimTime = currentTime;
10645 mDimSurface.setAlpha(mDimCurrentAlpha);
10646 animating = true;
10647 } else {
10648 mDimCurrentAlpha = mDimTargetAlpha;
10649 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010650 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010651 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
10652 mDimSurface.setAlpha(mDimCurrentAlpha);
10653 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010654 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010655 + ": HIDE");
10656 try {
10657 mDimSurface.hide();
10658 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010659 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010660 }
10661 mDimShown = false;
10662 }
10663 }
10664 }
10665 return animating;
10666 }
10667
10668 public void printTo(PrintWriter pw) {
10669 pw.print(" mDimShown="); pw.print(mDimShown);
10670 pw.print(" current="); pw.print(mDimCurrentAlpha);
10671 pw.print(" target="); pw.print(mDimTargetAlpha);
10672 pw.print(" delta="); pw.print(mDimDeltaPerMs);
10673 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
10674 }
10675 }
10676
10677 /**
10678 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
10679 * This is used for opening/closing transition for apps in compatible mode.
10680 */
10681 private static class FadeInOutAnimation extends Animation {
10682 int mWidth;
10683 boolean mFadeIn;
10684
10685 public FadeInOutAnimation(boolean fadeIn) {
10686 setInterpolator(new AccelerateInterpolator());
10687 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
10688 mFadeIn = fadeIn;
10689 }
10690
10691 @Override
10692 protected void applyTransformation(float interpolatedTime, Transformation t) {
10693 float x = interpolatedTime;
10694 if (!mFadeIn) {
10695 x = 1.0f - x; // reverse the interpolation for fade out
10696 }
10697 if (x < 0.5) {
10698 // move the window out of the screen.
10699 t.getMatrix().setTranslate(mWidth, 0);
10700 } else {
10701 t.getMatrix().setTranslate(0, 0);// show
10702 t.setAlpha((x - 0.5f) * 2);
10703 }
10704 }
10705
10706 @Override
10707 public void initialize(int width, int height, int parentWidth, int parentHeight) {
10708 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
10709 mWidth = width;
10710 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010711
10712 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070010713 public int getZAdjustment() {
10714 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010715 }
10716 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010717}