blob: 8be980fe2cc643fe8494c40e60d4b97f14344b05 [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;
Joe Onorato93056472010-09-10 10:30:46 -040026import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
29import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
32import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS;
34import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
35import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
37import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070038import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import com.android.internal.app.IBatteryStats;
41import com.android.internal.policy.PolicyManager;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -080042import com.android.internal.policy.impl.PhoneWindowManager;
Christopher Tatea53146c2010-09-07 11:57:52 -070043import com.android.internal.view.BaseInputHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import com.android.internal.view.IInputContext;
45import com.android.internal.view.IInputMethodClient;
46import com.android.internal.view.IInputMethodManager;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080047import com.android.internal.view.WindowManagerPolicyThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import com.android.server.am.BatteryStatsService;
49
50import android.Manifest;
51import android.app.ActivityManagerNative;
52import android.app.IActivityManager;
Jim Millerd6b57052010-06-07 17:52:42 -070053import android.app.admin.DevicePolicyManager;
Jim Miller284b62e2010-06-08 14:27:42 -070054import android.content.BroadcastReceiver;
Christopher Tatea53146c2010-09-07 11:57:52 -070055import android.content.ClipData;
56import android.content.ClipDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.content.Context;
Jim Miller284b62e2010-06-08 14:27:42 -070058import android.content.Intent;
59import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.content.pm.ActivityInfo;
61import android.content.pm.PackageManager;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.res.Configuration;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070064import android.graphics.Canvas;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.graphics.Matrix;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070066import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.graphics.PixelFormat;
68import android.graphics.Rect;
69import android.graphics.Region;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070070import android.graphics.Typeface;
71import android.graphics.Paint.FontMetricsInt;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.os.BatteryStats;
73import android.os.Binder;
Dianne Hackborn75804932009-10-20 20:15:20 -070074import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.os.Debug;
76import android.os.Handler;
77import android.os.IBinder;
78import android.os.LocalPowerManager;
79import android.os.Looper;
80import android.os.Message;
81import android.os.Parcel;
82import android.os.ParcelFileDescriptor;
83import android.os.Power;
84import android.os.PowerManager;
85import android.os.Process;
86import android.os.RemoteException;
87import android.os.ServiceManager;
88import android.os.SystemClock;
89import android.os.SystemProperties;
90import android.os.TokenWatcher;
91import android.provider.Settings;
Dianne Hackborn723738c2009-06-25 19:48:04 -070092import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.EventLog;
Jim Millerd6b57052010-06-07 17:52:42 -070094import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080095import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096import android.util.SparseIntArray;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070097import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.Display;
Christopher Tatea53146c2010-09-07 11:57:52 -070099import android.view.DragEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100import android.view.Gravity;
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700101import android.view.HapticFeedbackConstants;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102import android.view.IApplicationToken;
103import android.view.IOnKeyguardExitResult;
104import android.view.IRotationWatcher;
105import android.view.IWindow;
106import android.view.IWindowManager;
107import android.view.IWindowSession;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700108import android.view.InputChannel;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700109import android.view.InputDevice;
Jeff Brownbbda99d2010-07-28 15:48:59 -0700110import android.view.InputEvent;
Christopher Tatea53146c2010-09-07 11:57:52 -0700111import android.view.InputHandler;
112import android.view.InputQueue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113import android.view.KeyEvent;
114import android.view.MotionEvent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115import android.view.Surface;
116import android.view.SurfaceSession;
117import android.view.View;
118import android.view.ViewTreeObserver;
119import android.view.WindowManager;
120import android.view.WindowManagerImpl;
121import android.view.WindowManagerPolicy;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700122import android.view.Surface.OutOfResourcesException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager.LayoutParams;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700124import android.view.animation.AccelerateInterpolator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125import android.view.animation.Animation;
126import android.view.animation.AnimationUtils;
127import android.view.animation.Transformation;
128
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700129import java.io.BufferedReader;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130import java.io.BufferedWriter;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700131import java.io.DataInputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132import java.io.File;
133import java.io.FileDescriptor;
Dianne Hackbornb9fb1702010-08-23 16:49:02 -0700134import java.io.FileInputStream;
135import java.io.FileNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136import java.io.IOException;
137import java.io.OutputStream;
138import java.io.OutputStreamWriter;
139import java.io.PrintWriter;
140import java.io.StringWriter;
141import java.net.Socket;
142import java.util.ArrayList;
143import java.util.HashMap;
144import java.util.HashSet;
145import java.util.Iterator;
146import java.util.List;
147
148/** {@hide} */
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700149public class WindowManagerService extends IWindowManager.Stub
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700150 implements Watchdog.Monitor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
153 static final boolean DEBUG_FOCUS = false;
154 static final boolean DEBUG_ANIM = false;
Dianne Hackborn9b52a212009-12-11 14:51:35 -0800155 static final boolean DEBUG_LAYOUT = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800156 static final boolean DEBUG_RESIZE = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 static final boolean DEBUG_LAYERS = false;
158 static final boolean DEBUG_INPUT = false;
159 static final boolean DEBUG_INPUT_METHOD = false;
160 static final boolean DEBUG_VISIBILITY = false;
Dianne Hackbornbdd52b22009-09-02 21:46:19 -0700161 static final boolean DEBUG_WINDOW_MOVEMENT = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 static final boolean DEBUG_ORIENTATION = false;
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700163 static final boolean DEBUG_CONFIGURATION = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 static final boolean DEBUG_APP_TRANSITIONS = false;
165 static final boolean DEBUG_STARTING_WINDOW = false;
166 static final boolean DEBUG_REORDER = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -0700167 static final boolean DEBUG_WALLPAPER = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700168 static final boolean DEBUG_DRAG = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final boolean SHOW_TRANSACTIONS = false;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -0700170 static final boolean HIDE_STACK_CRAWLS = true;
Michael Chan53071d62009-05-13 17:29:48 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 static final boolean PROFILE_ORIENTATION = false;
173 static final boolean BLUR = true;
Dave Bortcfe65242009-04-09 14:51:04 -0700174 static final boolean localLOGV = DEBUG;
Romain Guy06882f82009-06-10 13:36:04 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /** How much to multiply the policy's type layer, to reserve room
177 * for multiple windows of the same type and Z-ordering adjustment
178 * with TYPE_LAYER_OFFSET. */
179 static final int TYPE_LAYER_MULTIPLIER = 10000;
Romain Guy06882f82009-06-10 13:36:04 -0700180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
182 * or below others in the same layer. */
183 static final int TYPE_LAYER_OFFSET = 1000;
Romain Guy06882f82009-06-10 13:36:04 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /** How much to increment the layer for each window, to reserve room
186 * for effect surfaces between them.
187 */
188 static final int WINDOW_LAYER_MULTIPLIER = 5;
Romain Guy06882f82009-06-10 13:36:04 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /** The maximum length we will accept for a loaded animation duration:
191 * this is 10 seconds.
192 */
193 static final int MAX_ANIMATION_DURATION = 10*1000;
194
195 /** Amount of time (in milliseconds) to animate the dim surface from one
196 * value to another, when no window animation is driving it.
197 */
198 static final int DEFAULT_DIM_DURATION = 200;
199
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700200 /** Amount of time (in milliseconds) to animate the fade-in-out transition for
201 * compatible windows.
202 */
203 static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /** Adjustment to time to perform a dim, to make it more dramatic.
206 */
207 static final int DIM_DURATION_MULTIPLIER = 6;
Jeff Brown7fbdc842010-06-17 20:52:56 -0700208
209 // Maximum number of milliseconds to wait for input event injection.
210 // FIXME is this value reasonable?
211 private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
Jeff Brown349703e2010-06-22 01:27:15 -0700212
213 // Default input dispatching timeout in nanoseconds.
214 private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
Romain Guy06882f82009-06-10 13:36:04 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 static final int UPDATE_FOCUS_NORMAL = 0;
217 static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
218 static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
219 static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
Romain Guy06882f82009-06-10 13:36:04 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 private static final String SYSTEM_SECURE = "ro.secure";
Romain Guy06882f82009-06-10 13:36:04 -0700222 private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 /**
225 * Condition waited on by {@link #reenableKeyguard} to know the call to
226 * the window policy has finished.
Mike Lockwood983ee092009-11-22 01:42:24 -0500227 * This is set to true only if mKeyguardTokenWatcher.acquired() has
228 * actually disabled the keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 */
Mike Lockwood983ee092009-11-22 01:42:24 -0500230 private boolean mKeyguardDisabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
Jim Miller284b62e2010-06-08 14:27:42 -0700232 private static final int ALLOW_DISABLE_YES = 1;
233 private static final int ALLOW_DISABLE_NO = 0;
234 private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager
235 private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher
236
Mike Lockwood983ee092009-11-22 01:42:24 -0500237 final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher(
238 new Handler(), "WindowManagerService.mKeyguardTokenWatcher") {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 public void acquired() {
Jim Miller284b62e2010-06-08 14:27:42 -0700240 if (shouldAllowDisableKeyguard()) {
241 mPolicy.enableKeyguard(false);
242 mKeyguardDisabled = true;
243 } else {
244 Log.v(TAG, "Not disabling keyguard since device policy is enforced");
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 }
247 public void released() {
Dianne Hackborna33e3f72009-09-29 17:28:24 -0700248 mPolicy.enableKeyguard(true);
Mike Lockwood983ee092009-11-22 01:42:24 -0500249 synchronized (mKeyguardTokenWatcher) {
250 mKeyguardDisabled = false;
251 mKeyguardTokenWatcher.notifyAll();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253 }
254 };
255
Jim Miller284b62e2010-06-08 14:27:42 -0700256 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
257 @Override
258 public void onReceive(Context context, Intent intent) {
259 mPolicy.enableKeyguard(true);
260 synchronized(mKeyguardTokenWatcher) {
261 // lazily evaluate this next time we're asked to disable keyguard
262 mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
263 mKeyguardDisabled = false;
264 }
265 }
266 };
267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 final Context mContext;
269
270 final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 final boolean mLimitedAlphaCompositing;
Romain Guy06882f82009-06-10 13:36:04 -0700273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
275
276 final IActivityManager mActivityManager;
Romain Guy06882f82009-06-10 13:36:04 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final IBatteryStats mBatteryStats;
Romain Guy06882f82009-06-10 13:36:04 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * All currently active sessions with clients.
282 */
283 final HashSet<Session> mSessions = new HashSet<Session>();
Romain Guy06882f82009-06-10 13:36:04 -0700284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Mapping from an IWindow IBinder to the server's Window object.
287 * This is also used as the lock for all of our state.
288 */
289 final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
290
291 /**
292 * Mapping from a token IBinder to a WindowToken object.
293 */
294 final HashMap<IBinder, WindowToken> mTokenMap =
295 new HashMap<IBinder, WindowToken>();
296
297 /**
298 * The same tokens as mTokenMap, stored in a list for efficient iteration
299 * over them.
300 */
301 final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * Window tokens that are in the process of exiting, but still
305 * on screen for animations.
306 */
307 final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
308
309 /**
310 * Z-ordered (bottom-most first) list of all application tokens, for
311 * controlling the ordering of windows in different applications. This
312 * contains WindowToken objects.
313 */
314 final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>();
315
316 /**
317 * Application tokens that are in the process of exiting, but still
318 * on screen for animations.
319 */
320 final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>();
321
322 /**
323 * List of window tokens that have finished starting their application,
324 * and now need to have the policy remove their windows.
325 */
326 final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
327
328 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700329 * This was the app token that was used to retrieve the last enter
330 * animation. It will be used for the next exit animation.
331 */
332 AppWindowToken mLastEnterAnimToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800333
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700334 /**
335 * These were the layout params used to retrieve the last enter animation.
336 * They will be used for the next exit animation.
337 */
338 LayoutParams mLastEnterAnimParams;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800339
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700340 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * Z-ordered (bottom-most first) list of all Window objects.
342 */
Jeff Browne33348b2010-07-15 23:54:05 -0700343 final ArrayList<WindowState> mWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 /**
346 * Windows that are being resized. Used so we can tell the client about
347 * the resize after closing the transaction in which we resized the
348 * underlying surface.
349 */
350 final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
351
352 /**
353 * Windows whose animations have ended and now must be removed.
354 */
355 final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
356
357 /**
358 * Windows whose surface should be destroyed.
359 */
360 final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
361
362 /**
363 * Windows that have lost input focus and are waiting for the new
364 * focus window to be displayed before they are told about this.
365 */
366 ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
367
368 /**
369 * This is set when we have run out of memory, and will either be an empty
370 * list or contain windows that need to be force removed.
371 */
372 ArrayList<WindowState> mForceRemoves;
Romain Guy06882f82009-06-10 13:36:04 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 IInputMethodManager mInputMethodManager;
Romain Guy06882f82009-06-10 13:36:04 -0700375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 SurfaceSession mFxSession;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -0700377 private DimAnimator mDimAnimator = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 Surface mBlurSurface;
379 boolean mBlurShown;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -0700380 Watermark mWatermark;
Romain Guy06882f82009-06-10 13:36:04 -0700381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 int mTransactionSequence = 0;
Romain Guy06882f82009-06-10 13:36:04 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 final float[] mTmpFloats = new float[9];
385
386 boolean mSafeMode;
387 boolean mDisplayEnabled = false;
388 boolean mSystemBooted = false;
Christopher Tateb696aee2010-04-02 19:08:30 -0700389 int mInitialDisplayWidth = 0;
390 int mInitialDisplayHeight = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 int mRotation = 0;
392 int mRequestedRotation = 0;
393 int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Dianne Hackborn321ae682009-03-27 16:16:03 -0700394 int mLastRotationFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 ArrayList<IRotationWatcher> mRotationWatchers
396 = new ArrayList<IRotationWatcher>();
Romain Guy06882f82009-06-10 13:36:04 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 boolean mLayoutNeeded = true;
399 boolean mAnimationPending = false;
400 boolean mDisplayFrozen = false;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800401 boolean mWaitingForConfig = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 boolean mWindowsFreezingScreen = false;
403 long mFreezeGcPending = 0;
404 int mAppsFreezingScreen = 0;
405
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800406 int mLayoutSeq = 0;
407
Dianne Hackbornb601ce12010-03-01 23:36:02 -0800408 // State while inside of layoutAndPlaceSurfacesLocked().
409 boolean mFocusMayChange;
410
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800411 Configuration mCurConfiguration = new Configuration();
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 // This is held as long as we have the screen frozen, to give us time to
414 // perform a rotation animation when turning off shows the lock screen which
415 // changes the orientation.
416 PowerManager.WakeLock mScreenFrozenLock;
Romain Guy06882f82009-06-10 13:36:04 -0700417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 // State management of app transitions. When we are preparing for a
419 // transition, mNextAppTransition will be the kind of transition to
420 // perform or TRANSIT_NONE if we are not waiting. If we are waiting,
421 // mOpeningApps and mClosingApps are the lists of tokens that will be
422 // made visible or hidden at the next transition.
Dianne Hackbornbfe319e2009-09-21 00:34:05 -0700423 int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700424 String mNextAppTransitionPackage;
425 int mNextAppTransitionEnter;
426 int mNextAppTransitionExit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 boolean mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700428 boolean mAppTransitionRunning = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 boolean mAppTransitionTimeout = false;
430 boolean mStartingIconInTransition = false;
431 boolean mSkipAppTransitionAnimation = false;
432 final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
433 final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
Dianne Hackborna8f60182009-09-01 19:01:50 -0700434 final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>();
435 final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>();
Romain Guy06882f82009-06-10 13:36:04 -0700436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 Display mDisplay;
Romain Guy06882f82009-06-10 13:36:04 -0700438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 H mH = new H();
440
441 WindowState mCurrentFocus = null;
442 WindowState mLastFocus = null;
Romain Guy06882f82009-06-10 13:36:04 -0700443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 // This just indicates the window the input method is on top of, not
445 // necessarily the window its input is going to.
446 WindowState mInputMethodTarget = null;
447 WindowState mUpcomingInputMethodTarget = null;
448 boolean mInputMethodTargetWaitingAnim;
449 int mInputMethodAnimLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -0700450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 WindowState mInputMethodWindow = null;
452 final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
453
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700454 final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800455
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700456 // If non-null, this is the currently visible window that is associated
457 // with the wallpaper.
458 WindowState mWallpaperTarget = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700459 // If non-null, we are in the middle of animating from one wallpaper target
460 // to another, and this is the lower one in Z-order.
461 WindowState mLowerWallpaperTarget = null;
462 // If non-null, we are in the middle of animating from one wallpaper target
463 // to another, and this is the higher one in Z-order.
464 WindowState mUpperWallpaperTarget = null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -0700465 int mWallpaperAnimLayerAdjustment;
Dianne Hackborn73e92b42009-10-15 14:29:19 -0700466 float mLastWallpaperX = -1;
467 float mLastWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -0800468 float mLastWallpaperXStep = -1;
469 float mLastWallpaperYStep = -1;
Dianne Hackborn19382ac2009-09-11 21:13:37 -0700470 // This is set when we are waiting for a wallpaper to tell us it is done
471 // changing its scroll position.
472 WindowState mWaitingOnWallpaper;
473 // The last time we had a timeout when waiting for a wallpaper.
474 long mLastWallpaperTimeoutTime;
475 // We give a wallpaper up to 150ms to finish scrolling.
476 static final long WALLPAPER_TIMEOUT = 150;
477 // Time we wait after a timeout before trying to wait again.
478 static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 AppWindowToken mFocusedApp = null;
481
482 PowerManagerService mPowerManager;
Romain Guy06882f82009-06-10 13:36:04 -0700483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 float mWindowAnimationScale = 1.0f;
485 float mTransitionAnimationScale = 1.0f;
Romain Guy06882f82009-06-10 13:36:04 -0700486
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 final InputManager mInputManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488
489 // Who is holding the screen on.
490 Session mHoldingScreenOn;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700491 PowerManager.WakeLock mHoldingScreenWakeLock;
Romain Guy06882f82009-06-10 13:36:04 -0700492
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700493 boolean mTurnOnScreen;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 /**
Christopher Tatea53146c2010-09-07 11:57:52 -0700496 * Drag/drop state
497 */
498 class DragState {
499 IBinder mToken;
500 Surface mSurface;
501 boolean mLocalOnly;
502 ClipData mData;
503 ClipDescription mDataDescription;
504 float mThumbOffsetX, mThumbOffsetY;
505 InputChannel mServerChannel, mClientChannel;
506 WindowState mTargetWindow;
507 ArrayList<WindowState> mNotifiedWindows;
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700508 boolean mDragInProgress;
Christopher Tatea53146c2010-09-07 11:57:52 -0700509
510 private final Rect tmpRect = new Rect();
511
512 DragState(IBinder token, Surface surface, boolean localOnly) {
513 mToken = token;
514 mSurface = surface;
515 mLocalOnly = localOnly;
516 mNotifiedWindows = new ArrayList<WindowState>();
517 }
518
519 void reset() {
520 if (mSurface != null) {
521 mSurface.destroy();
522 }
523 mSurface = null;
524 mLocalOnly = false;
525 mToken = null;
526 mData = null;
527 mThumbOffsetX = mThumbOffsetY = 0;
528 mNotifiedWindows = null;
529 }
530
531 void register() {
532 if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel");
533 if (mClientChannel != null) {
534 Slog.e(TAG, "Duplicate register of drag input channel");
535 } else {
536 InputChannel[] channels = InputChannel.openInputChannelPair("drag");
537 mServerChannel = channels[0];
538 mClientChannel = channels[1];
539 mInputManager.registerInputChannel(mServerChannel);
540 InputQueue.registerInputChannel(mClientChannel, mDragInputHandler,
541 mH.getLooper().getQueue());
542 }
543 }
544
545 void unregister() {
546 if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel");
547 if (mClientChannel == null) {
548 Slog.e(TAG, "Unregister of nonexistent drag input channel");
549 } else {
550 mInputManager.unregisterInputChannel(mServerChannel);
551 InputQueue.unregisterInputChannel(mClientChannel);
552 mClientChannel.dispose();
553 mClientChannel = null;
554 mServerChannel = null;
555 }
556 }
557
558 /* call out to each visible window/session informing it about the drag
559 */
560 void broadcastDragStartedLw() {
561 // Cache a base-class instance of the clip metadata so that parceling
562 // works correctly in calling out to the apps.
563 mDataDescription = new ClipDescription(mData);
564 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700565 mDragInProgress = true;
Christopher Tatea53146c2010-09-07 11:57:52 -0700566
567 if (DEBUG_DRAG) {
568 Slog.d(TAG, "broadcasting DRAG_STARTED of " + mDataDescription);
569 }
570
571 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0,
572 mDataDescription, null);
Christopher Tate2c095f32010-10-04 14:13:40 -0700573 final int N = mWindows.size();
574 for (int i = 0; i < N; i++) {
575 // sendDragStartedLw() clones evt for local-process dispatch
576 sendDragStartedLw(mWindows.get(i), evt);
Christopher Tatea53146c2010-09-07 11:57:52 -0700577 }
578 evt.recycle();
579 }
580
581 /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
582 * designated window is potentially a drop recipient. There are race situations
583 * around DRAG_ENDED broadcast, so we make sure that once we've declared that
584 * the drag has ended, we never send out another DRAG_STARTED for this drag action.
Christopher Tate2c095f32010-10-04 14:13:40 -0700585 *
586 * This method clones the 'event' parameter if it's being delivered to the same
587 * process, so it's safe for the caller to call recycle() on the event afterwards.
Christopher Tatea53146c2010-09-07 11:57:52 -0700588 */
Christopher Tate2c095f32010-10-04 14:13:40 -0700589 private void sendDragStartedLw(WindowState newWin, DragEvent event) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700590 if (mDragInProgress && newWin.isPotentialDragTarget()) {
Christopher Tatea53146c2010-09-07 11:57:52 -0700591 try {
Christopher Tate2c095f32010-10-04 14:13:40 -0700592 // clone for local callees since dispatch will recycle the event
593 if (Process.myPid() == newWin.mSession.mPid) {
594 event = DragEvent.obtain(event);
595 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700596 newWin.mClient.dispatchDragEvent(event);
597 // track each window that we've notified that the drag is starting
598 mNotifiedWindows.add(newWin);
599 } catch (RemoteException e) {
600 Slog.w(TAG, "Unable to drag-start window " + newWin);
601 }
602 }
603 }
604
605 /* helper - construct and send a DRAG_STARTED event only if the window has not
606 * previously been notified, i.e. it became visible after the drag operation
607 * was begun. This is a rare case.
608 */
609 private void sendDragStartedIfNeededLw(WindowState newWin) {
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700610 if (mDragInProgress) {
611 // If we have sent the drag-started, we needn't do so again
612 for (WindowState ws : mNotifiedWindows) {
613 if (ws == newWin) {
614 return;
615 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700616 }
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700617 if (DEBUG_DRAG) {
618 Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin);
619 }
620 DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0,
621 mDataDescription, null);
622 // sendDragStartedLw() clones 'event' if the window is process-local
623 sendDragStartedLw(newWin, event);
624 event.recycle();
Christopher Tatea53146c2010-09-07 11:57:52 -0700625 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700626 }
627
628 void broadcastDragEnded() {
629 if (DEBUG_DRAG) {
630 Slog.d(TAG, "broadcasting DRAG_ENDED");
631 }
632 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null);
633 synchronized (mWindowMap) {
634 for (WindowState ws: mNotifiedWindows) {
635 try {
636 ws.mClient.dispatchDragEvent(evt);
637 } catch (RemoteException e) {
638 Slog.w(TAG, "Unable to drag-end window " + ws);
639 }
640 }
641 mNotifiedWindows.clear();
Christopher Tate5ada6cb2010-10-05 14:15:29 -0700642 mDragInProgress = false;
Christopher Tatea53146c2010-09-07 11:57:52 -0700643 }
644 evt.recycle();
645 }
646
647 void notifyMoveLw(float x, float y) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700648 final int myPid = Process.myPid();
649
650 // Move the surface to the given touch
651 mSurface.openTransaction();
652 mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY));
653 mSurface.closeTransaction();
654
655 // Tell the affected window
Christopher Tatea53146c2010-09-07 11:57:52 -0700656 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
657 try {
658 // have we dragged over a new window?
659 if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
660 if (DEBUG_DRAG) {
661 Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow);
662 }
663 // force DRAG_EXITED_EVENT if appropriate
664 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
665 0, 0, null, null);
666 mTargetWindow.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700667 if (myPid != mTargetWindow.mSession.mPid) {
668 evt.recycle();
669 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700670 }
671 if (touchedWin != null) {
672 if (DEBUG_DRAG) {
673 Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin);
674 }
675 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
676 x, y, null, null);
677 touchedWin.mClient.dispatchDragEvent(evt);
Christopher Tate2c095f32010-10-04 14:13:40 -0700678 if (myPid != touchedWin.mSession.mPid) {
679 evt.recycle();
680 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700681 }
682 } catch (RemoteException e) {
683 Slog.w(TAG, "can't send drag notification to windows");
684 }
685 mTargetWindow = touchedWin;
686 }
687
688 // Tell the drop target about the data, and then broadcast the drag-ended notification
689 void notifyDropLw(float x, float y) {
690 WindowState touchedWin = getTouchedWinAtPointLw(x, y);
691 if (touchedWin != null) {
692 if (DEBUG_DRAG) {
693 Slog.d(TAG, "sending DROP to " + touchedWin);
694 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700695 final int myPid = Process.myPid();
Christopher Tatea53146c2010-09-07 11:57:52 -0700696 DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, x, y, null, mData);
697 try {
698 touchedWin.mClient.dispatchDragEvent(evt);
699 } catch (RemoteException e) {
700 Slog.w(TAG, "can't send drop notification to win " + touchedWin);
701 }
Christopher Tate2c095f32010-10-04 14:13:40 -0700702 if (myPid != touchedWin.mSession.mPid) {
703 evt.recycle();
704 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700705 }
706 }
707
708 // Find the visible, touch-deliverable window under the given point
709 private WindowState getTouchedWinAtPointLw(float xf, float yf) {
710 WindowState touchedWin = null;
711 final int x = (int) xf;
712 final int y = (int) yf;
713 final ArrayList<WindowState> windows = mWindows;
714 final int N = windows.size();
715 for (int i = N - 1; i >= 0; i--) {
716 WindowState child = windows.get(i);
717 final int flags = child.mAttrs.flags;
718 if (!child.isVisibleLw()) {
719 // not visible == don't tell about drags
720 continue;
721 }
722 if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) {
723 // not touchable == don't tell about drags
724 continue;
725 }
726 // account for the window's decor etc
727 tmpRect.set(child.mFrame);
728 if (child.mTouchableInsets == ViewTreeObserver
729 .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) {
730 // The point is inside of the window if it is
731 // inside the frame, AND the content part of that
732 // frame that was given by the application.
733 tmpRect.left += child.mGivenContentInsets.left;
734 tmpRect.top += child.mGivenContentInsets.top;
735 tmpRect.right -= child.mGivenContentInsets.right;
736 tmpRect.bottom -= child.mGivenContentInsets.bottom;
737 } else if (child.mTouchableInsets == ViewTreeObserver
738 .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) {
739 // The point is inside of the window if it is
740 // inside the frame, AND the visible part of that
741 // frame that was given by the application.
742 tmpRect.left += child.mGivenVisibleInsets.left;
743 tmpRect.top += child.mGivenVisibleInsets.top;
744 tmpRect.right -= child.mGivenVisibleInsets.right;
745 tmpRect.bottom -= child.mGivenVisibleInsets.bottom;
746 }
747 final int touchFlags = flags &
748 (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
749 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
750 if (tmpRect.contains(x, y) || touchFlags == 0) {
751 // Found it
752 touchedWin = child;
753 break;
754 }
755 }
756
757 return touchedWin;
758 }
759 }
760
761 DragState mDragState = null;
762 private final InputHandler mDragInputHandler = new BaseInputHandler() {
763 @Override
764 public void handleMotion(MotionEvent event, Runnable finishedCallback) {
765 boolean endDrag = false;
766 final float newX = event.getRawX();
767 final float newY = event.getRawY();
768
769 try {
770 if (mDragState != null) {
771 switch (event.getAction()) {
772 case MotionEvent.ACTION_DOWN: {
773 if (DEBUG_DRAG) {
774 Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
775 }
776 } break;
777
778 case MotionEvent.ACTION_MOVE: {
779 synchronized (mWindowMap) {
Christopher Tate2c095f32010-10-04 14:13:40 -0700780 // move the surface and tell the involved window(s) where we are
Christopher Tatea53146c2010-09-07 11:57:52 -0700781 mDragState.notifyMoveLw(newX, newY);
782 }
783 } break;
784
785 case MotionEvent.ACTION_UP: {
786 if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
787 + newX + "," + newY);
788 synchronized (mWindowMap) {
789 mDragState.notifyDropLw(newX, newY);
790 }
791 endDrag = true;
792 } break;
793
794 case MotionEvent.ACTION_CANCEL: {
795 if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
796 endDrag = true;
797 } break;
798 }
799
800 if (endDrag) {
801 if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
802 // tell all the windows that the drag has ended
803 mDragState.broadcastDragEnded();
804
805 // stop intercepting input
806 mDragState.unregister();
Chris Tate59943592010-10-11 20:33:44 -0700807 synchronized (mWindowMap) {
808 mInputMonitor.updateInputWindowsLw();
809 }
Christopher Tatea53146c2010-09-07 11:57:52 -0700810
811 // free our resources and drop all the object references
812 mDragState.reset();
813 mDragState = null;
814 }
815 }
816 } catch (Exception e) {
817 Slog.e(TAG, "Exception caught by drag handleMotion", e);
818 } finally {
819 finishedCallback.run();
820 }
821 }
822 };
823
824 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 * Whether the UI is currently running in touch mode (not showing
826 * navigational focus because the user is directly pressing the screen).
827 */
828 boolean mInTouchMode = false;
829
830 private ViewServer mViewServer;
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700831 private ArrayList<WindowChangeListener> mWindowChangeListeners =
832 new ArrayList<WindowChangeListener>();
833 private boolean mWindowsChanged = false;
834
835 public interface WindowChangeListener {
836 public void windowsChanged();
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -0700837 public void focusChanged();
Konstantin Lopyrevdc301012010-07-08 17:55:51 -0700838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839
Dianne Hackbornc485a602009-03-24 22:39:49 -0700840 final Configuration mTempConfiguration = new Configuration();
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700841 int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -0700842
843 // The frame use to limit the size of the app running in compatibility mode.
844 Rect mCompatibleScreenFrame = new Rect();
845 // The surface used to fill the outer rim of the app running in compatibility mode.
846 Surface mBackgroundFillerSurface = null;
847 boolean mBackgroundFillerShown = false;
848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 public static WindowManagerService main(Context context,
850 PowerManagerService pm, boolean haveInputMethods) {
851 WMThread thr = new WMThread(context, pm, haveInputMethods);
852 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 synchronized (thr) {
855 while (thr.mService == null) {
856 try {
857 thr.wait();
858 } catch (InterruptedException e) {
859 }
860 }
861 }
Romain Guy06882f82009-06-10 13:36:04 -0700862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 return thr.mService;
864 }
Romain Guy06882f82009-06-10 13:36:04 -0700865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 static class WMThread extends Thread {
867 WindowManagerService mService;
Romain Guy06882f82009-06-10 13:36:04 -0700868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 private final Context mContext;
870 private final PowerManagerService mPM;
871 private final boolean mHaveInputMethods;
Romain Guy06882f82009-06-10 13:36:04 -0700872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 public WMThread(Context context, PowerManagerService pm,
874 boolean haveInputMethods) {
875 super("WindowManager");
876 mContext = context;
877 mPM = pm;
878 mHaveInputMethods = haveInputMethods;
879 }
Romain Guy06882f82009-06-10 13:36:04 -0700880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 public void run() {
882 Looper.prepare();
883 WindowManagerService s = new WindowManagerService(mContext, mPM,
884 mHaveInputMethods);
885 android.os.Process.setThreadPriority(
886 android.os.Process.THREAD_PRIORITY_DISPLAY);
Christopher Tate160edb32010-06-30 17:46:30 -0700887 android.os.Process.setCanSelfBackground(false);
Romain Guy06882f82009-06-10 13:36:04 -0700888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 synchronized (this) {
890 mService = s;
891 notifyAll();
892 }
Romain Guy06882f82009-06-10 13:36:04 -0700893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 Looper.loop();
895 }
896 }
897
898 static class PolicyThread extends Thread {
899 private final WindowManagerPolicy mPolicy;
900 private final WindowManagerService mService;
901 private final Context mContext;
902 private final PowerManagerService mPM;
903 boolean mRunning = false;
Romain Guy06882f82009-06-10 13:36:04 -0700904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 public PolicyThread(WindowManagerPolicy policy,
906 WindowManagerService service, Context context,
907 PowerManagerService pm) {
908 super("WindowManagerPolicy");
909 mPolicy = policy;
910 mService = service;
911 mContext = context;
912 mPM = pm;
913 }
Romain Guy06882f82009-06-10 13:36:04 -0700914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 public void run() {
916 Looper.prepare();
Dianne Hackbornac3587d2010-03-11 11:12:11 -0800917 WindowManagerPolicyThread.set(this, Looper.myLooper());
918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 //Looper.myLooper().setMessageLogging(new LogPrinter(
Joe Onorato8a9b2202010-02-26 18:56:32 -0800920 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 android.os.Process.setThreadPriority(
922 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Christopher Tate160edb32010-06-30 17:46:30 -0700923 android.os.Process.setCanSelfBackground(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 mPolicy.init(mContext, mService, mPM);
Romain Guy06882f82009-06-10 13:36:04 -0700925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 synchronized (this) {
927 mRunning = true;
928 notifyAll();
929 }
Romain Guy06882f82009-06-10 13:36:04 -0700930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 Looper.loop();
932 }
933 }
934
935 private WindowManagerService(Context context, PowerManagerService pm,
936 boolean haveInputMethods) {
937 mContext = context;
938 mHaveInputMethods = haveInputMethods;
939 mLimitedAlphaCompositing = context.getResources().getBoolean(
940 com.android.internal.R.bool.config_sf_limitedAlpha);
Romain Guy06882f82009-06-10 13:36:04 -0700941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 mPowerManager = pm;
943 mPowerManager.setPolicy(mPolicy);
944 PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
945 mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
946 "SCREEN_FROZEN");
947 mScreenFrozenLock.setReferenceCounted(false);
948
949 mActivityManager = ActivityManagerNative.getDefault();
950 mBatteryStats = BatteryStatsService.getService();
951
952 // Get persisted window scale setting
953 mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(),
954 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
955 mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(),
956 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
Romain Guy06882f82009-06-10 13:36:04 -0700957
Jim Miller284b62e2010-06-08 14:27:42 -0700958 // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
959 IntentFilter filter = new IntentFilter();
960 filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
961 mContext.registerReceiver(mBroadcastReceiver, filter);
962
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700963 mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
964 "KEEP_SCREEN_ON_FLAG");
965 mHoldingScreenWakeLock.setReferenceCounted(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966
Jeff Browne33348b2010-07-15 23:54:05 -0700967 mInputManager = new InputManager(context, this);
Romain Guy06882f82009-06-10 13:36:04 -0700968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
970 thr.start();
Romain Guy06882f82009-06-10 13:36:04 -0700971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 synchronized (thr) {
973 while (!thr.mRunning) {
974 try {
975 thr.wait();
976 } catch (InterruptedException e) {
977 }
978 }
979 }
Romain Guy06882f82009-06-10 13:36:04 -0700980
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700981 mInputManager.start();
Romain Guy06882f82009-06-10 13:36:04 -0700982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 // Add ourself to the Watchdog monitors.
984 Watchdog.getInstance().addMonitor(this);
985 }
986
987 @Override
988 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
989 throws RemoteException {
990 try {
991 return super.onTransact(code, data, reply, flags);
992 } catch (RuntimeException e) {
993 // The window manager only throws security exceptions, so let's
994 // log all others.
995 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800996 Slog.e(TAG, "Window Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 }
998 throw e;
999 }
1000 }
1001
Jeff Browne33348b2010-07-15 23:54:05 -07001002 private void placeWindowAfter(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001004 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 TAG, "Adding window " + window + " at "
1006 + (i+1) + " of " + mWindows.size() + " (after " + pos + ")");
1007 mWindows.add(i+1, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001008 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 }
1010
Jeff Browne33348b2010-07-15 23:54:05 -07001011 private void placeWindowBefore(WindowState pos, WindowState window) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 final int i = mWindows.indexOf(pos);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001013 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 TAG, "Adding window " + window + " at "
1015 + i + " of " + mWindows.size() + " (before " + pos + ")");
1016 mWindows.add(i, window);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001017 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 }
1019
1020 //This method finds out the index of a window that has the same app token as
1021 //win. used for z ordering the windows in mWindows
1022 private int findIdxBasedOnAppTokens(WindowState win) {
1023 //use a local variable to cache mWindows
Jeff Browne33348b2010-07-15 23:54:05 -07001024 ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 int jmax = localmWindows.size();
1026 if(jmax == 0) {
1027 return -1;
1028 }
1029 for(int j = (jmax-1); j >= 0; j--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001030 WindowState wentry = localmWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 if(wentry.mAppToken == win.mAppToken) {
1032 return j;
1033 }
1034 }
1035 return -1;
1036 }
Romain Guy06882f82009-06-10 13:36:04 -07001037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001038 private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
1039 final IWindow client = win.mClient;
1040 final WindowToken token = win.mToken;
Jeff Browne33348b2010-07-15 23:54:05 -07001041 final ArrayList<WindowState> localmWindows = mWindows;
Romain Guy06882f82009-06-10 13:36:04 -07001042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 final int N = localmWindows.size();
1044 final WindowState attached = win.mAttachedWindow;
1045 int i;
1046 if (attached == null) {
1047 int tokenWindowsPos = token.windows.size();
1048 if (token.appWindowToken != null) {
1049 int index = tokenWindowsPos-1;
1050 if (index >= 0) {
1051 // If this application has existing windows, we
1052 // simply place the new window on top of them... but
1053 // keep the starting window on top.
1054 if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
1055 // Base windows go behind everything else.
1056 placeWindowBefore(token.windows.get(0), win);
1057 tokenWindowsPos = 0;
1058 } else {
1059 AppWindowToken atoken = win.mAppToken;
1060 if (atoken != null &&
1061 token.windows.get(index) == atoken.startingWindow) {
1062 placeWindowBefore(token.windows.get(index), win);
1063 tokenWindowsPos--;
1064 } else {
1065 int newIdx = findIdxBasedOnAppTokens(win);
1066 if(newIdx != -1) {
Romain Guy06882f82009-06-10 13:36:04 -07001067 //there is a window above this one associated with the same
1068 //apptoken note that the window could be a floating window
1069 //that was created later or a window at the top of the list of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001070 //windows associated with this token.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001071 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001072 TAG, "Adding window " + win + " at "
1073 + (newIdx+1) + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 localmWindows.add(newIdx+1, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001075 mWindowsChanged = true;
Romain Guy06882f82009-06-10 13:36:04 -07001076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 }
1078 }
1079 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001080 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 TAG, "Figuring out where to add app window "
1082 + client.asBinder() + " (token=" + token + ")");
1083 // Figure out where the window should go, based on the
1084 // order of applications.
1085 final int NA = mAppTokens.size();
Jeff Browne33348b2010-07-15 23:54:05 -07001086 WindowState pos = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 for (i=NA-1; i>=0; i--) {
1088 AppWindowToken t = mAppTokens.get(i);
1089 if (t == token) {
1090 i--;
1091 break;
1092 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001093
Dianne Hackborna8f60182009-09-01 19:01:50 -07001094 // We haven't reached the token yet; if this token
1095 // is not going to the bottom and has windows, we can
1096 // use it as an anchor for when we do reach the token.
1097 if (!t.sendingToBottom && t.windows.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 pos = t.windows.get(0);
1099 }
1100 }
1101 // We now know the index into the apps. If we found
1102 // an app window above, that gives us the position; else
1103 // we need to look some more.
1104 if (pos != null) {
1105 // Move behind any windows attached to this one.
Jeff Browne33348b2010-07-15 23:54:05 -07001106 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 if (atoken != null) {
1108 final int NC = atoken.windows.size();
1109 if (NC > 0) {
1110 WindowState bottom = atoken.windows.get(0);
1111 if (bottom.mSubLayer < 0) {
1112 pos = bottom;
1113 }
1114 }
1115 }
1116 placeWindowBefore(pos, win);
1117 } else {
Dianne Hackborna8f60182009-09-01 19:01:50 -07001118 // Continue looking down until we find the first
1119 // token that has windows.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 while (i >= 0) {
1121 AppWindowToken t = mAppTokens.get(i);
1122 final int NW = t.windows.size();
1123 if (NW > 0) {
1124 pos = t.windows.get(NW-1);
1125 break;
1126 }
1127 i--;
1128 }
1129 if (pos != null) {
1130 // Move in front of any windows attached to this
1131 // one.
Jeff Browne33348b2010-07-15 23:54:05 -07001132 WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 if (atoken != null) {
1134 final int NC = atoken.windows.size();
1135 if (NC > 0) {
1136 WindowState top = atoken.windows.get(NC-1);
1137 if (top.mSubLayer >= 0) {
1138 pos = top;
1139 }
1140 }
1141 }
1142 placeWindowAfter(pos, win);
1143 } else {
1144 // Just search for the start of this layer.
1145 final int myLayer = win.mBaseLayer;
1146 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07001147 WindowState w = localmWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 if (w.mBaseLayer > myLayer) {
1149 break;
1150 }
1151 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001152 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001153 TAG, "Adding window " + win + " at "
1154 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001156 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 }
1158 }
1159 }
1160 } else {
1161 // Figure out where window should go, based on layer.
1162 final int myLayer = win.mBaseLayer;
1163 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07001164 if (localmWindows.get(i).mBaseLayer <= myLayer) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 i++;
1166 break;
1167 }
1168 }
1169 if (i < 0) i = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001170 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001171 TAG, "Adding window " + win + " at "
1172 + i + " of " + N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 localmWindows.add(i, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001174 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 }
1176 if (addToToken) {
1177 token.windows.add(tokenWindowsPos, win);
1178 }
1179
1180 } else {
1181 // Figure out this window's ordering relative to the window
1182 // it is attached to.
1183 final int NA = token.windows.size();
1184 final int sublayer = win.mSubLayer;
1185 int largestSublayer = Integer.MIN_VALUE;
1186 WindowState windowWithLargestSublayer = null;
1187 for (i=0; i<NA; i++) {
1188 WindowState w = token.windows.get(i);
1189 final int wSublayer = w.mSubLayer;
1190 if (wSublayer >= largestSublayer) {
1191 largestSublayer = wSublayer;
1192 windowWithLargestSublayer = w;
1193 }
1194 if (sublayer < 0) {
1195 // For negative sublayers, we go below all windows
1196 // in the same sublayer.
1197 if (wSublayer >= sublayer) {
1198 if (addToToken) {
1199 token.windows.add(i, win);
1200 }
1201 placeWindowBefore(
1202 wSublayer >= 0 ? attached : w, win);
1203 break;
1204 }
1205 } else {
1206 // For positive sublayers, we go above all windows
1207 // in the same sublayer.
1208 if (wSublayer > sublayer) {
1209 if (addToToken) {
1210 token.windows.add(i, win);
1211 }
1212 placeWindowBefore(w, win);
1213 break;
1214 }
1215 }
1216 }
1217 if (i >= NA) {
1218 if (addToToken) {
1219 token.windows.add(win);
1220 }
1221 if (sublayer < 0) {
1222 placeWindowBefore(attached, win);
1223 } else {
1224 placeWindowAfter(largestSublayer >= 0
1225 ? windowWithLargestSublayer
1226 : attached,
1227 win);
1228 }
1229 }
1230 }
Romain Guy06882f82009-06-10 13:36:04 -07001231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 if (win.mAppToken != null && addToToken) {
1233 win.mAppToken.allAppWindows.add(win);
1234 }
1235 }
Romain Guy06882f82009-06-10 13:36:04 -07001236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 static boolean canBeImeTarget(WindowState w) {
1238 final int fl = w.mAttrs.flags
1239 & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
1240 if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1241 return w.isVisibleOrAdding();
1242 }
1243 return false;
1244 }
Romain Guy06882f82009-06-10 13:36:04 -07001245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
Jeff Browne33348b2010-07-15 23:54:05 -07001247 final ArrayList<WindowState> localmWindows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 final int N = localmWindows.size();
1249 WindowState w = null;
1250 int i = N;
1251 while (i > 0) {
1252 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001253 w = localmWindows.get(i);
Romain Guy06882f82009-06-10 13:36:04 -07001254
Joe Onorato8a9b2202010-02-26 18:56:32 -08001255 //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 // + Integer.toHexString(w.mAttrs.flags));
1257 if (canBeImeTarget(w)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001258 //Slog.i(TAG, "Putting input method here!");
Romain Guy06882f82009-06-10 13:36:04 -07001259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001260 // Yet more tricksyness! If this window is a "starting"
1261 // window, we do actually want to be on top of it, but
1262 // it is not -really- where input will go. So if the caller
1263 // is not actually looking to move the IME, look down below
1264 // for a real window to target...
1265 if (!willMove
1266 && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1267 && i > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001268 WindowState wb = localmWindows.get(i-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
1270 i--;
1271 w = wb;
1272 }
1273 }
1274 break;
1275 }
1276 }
Romain Guy06882f82009-06-10 13:36:04 -07001277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 mUpcomingInputMethodTarget = w;
Romain Guy06882f82009-06-10 13:36:04 -07001279
Joe Onorato8a9b2202010-02-26 18:56:32 -08001280 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 + w + " willMove=" + willMove);
Romain Guy06882f82009-06-10 13:36:04 -07001282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 if (willMove && w != null) {
1284 final WindowState curTarget = mInputMethodTarget;
1285 if (curTarget != null && curTarget.mAppToken != null) {
Romain Guy06882f82009-06-10 13:36:04 -07001286
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 // Now some fun for dealing with window animations that
1288 // modify the Z order. We need to look at all windows below
1289 // the current target that are in this app, finding the highest
1290 // visible one in layering.
1291 AppWindowToken token = curTarget.mAppToken;
1292 WindowState highestTarget = null;
1293 int highestPos = 0;
1294 if (token.animating || token.animation != null) {
1295 int pos = 0;
1296 pos = localmWindows.indexOf(curTarget);
1297 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001298 WindowState win = localmWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 if (win.mAppToken != token) {
1300 break;
1301 }
1302 if (!win.mRemoved) {
1303 if (highestTarget == null || win.mAnimLayer >
1304 highestTarget.mAnimLayer) {
1305 highestTarget = win;
1306 highestPos = pos;
1307 }
1308 }
1309 pos--;
1310 }
1311 }
Romain Guy06882f82009-06-10 13:36:04 -07001312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 if (highestTarget != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001314 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 + mNextAppTransition + " " + highestTarget
1316 + " animating=" + highestTarget.isAnimating()
1317 + " layer=" + highestTarget.mAnimLayer
1318 + " new layer=" + w.mAnimLayer);
Romain Guy06882f82009-06-10 13:36:04 -07001319
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001320 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 // If we are currently setting up for an animation,
1322 // hold everything until we can find out what will happen.
1323 mInputMethodTargetWaitingAnim = true;
1324 mInputMethodTarget = highestTarget;
1325 return highestPos + 1;
1326 } else if (highestTarget.isAnimating() &&
1327 highestTarget.mAnimLayer > w.mAnimLayer) {
1328 // If the window we are currently targeting is involved
1329 // with an animation, and it is on top of the next target
1330 // we will be over, then hold off on moving until
1331 // that is done.
1332 mInputMethodTarget = highestTarget;
1333 return highestPos + 1;
1334 }
1335 }
1336 }
1337 }
Romain Guy06882f82009-06-10 13:36:04 -07001338
Joe Onorato8a9b2202010-02-26 18:56:32 -08001339 //Slog.i(TAG, "Placing input method @" + (i+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 if (w != null) {
1341 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001342 if (DEBUG_INPUT_METHOD) {
1343 RuntimeException e = null;
1344 if (!HIDE_STACK_CRAWLS) {
1345 e = new RuntimeException();
1346 e.fillInStackTrace();
1347 }
1348 Slog.w(TAG, "Moving IM target from "
1349 + mInputMethodTarget + " to " + w, e);
1350 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 mInputMethodTarget = w;
1352 if (w.mAppToken != null) {
1353 setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment);
1354 } else {
1355 setInputMethodAnimLayerAdjustment(0);
1356 }
1357 }
1358 return i+1;
1359 }
1360 if (willMove) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08001361 if (DEBUG_INPUT_METHOD) {
1362 RuntimeException e = null;
1363 if (!HIDE_STACK_CRAWLS) {
1364 e = new RuntimeException();
1365 e.fillInStackTrace();
1366 }
1367 Slog.w(TAG, "Moving IM target from "
1368 + mInputMethodTarget + " to null", e);
1369 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 mInputMethodTarget = null;
1371 setInputMethodAnimLayerAdjustment(0);
1372 }
1373 return -1;
1374 }
Romain Guy06882f82009-06-10 13:36:04 -07001375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 void addInputMethodWindowToListLocked(WindowState win) {
1377 int pos = findDesiredInputMethodWindowIndexLocked(true);
1378 if (pos >= 0) {
1379 win.mTargetAppToken = mInputMethodTarget.mAppToken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001380 if (DEBUG_WINDOW_MOVEMENT) Slog.v(
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001381 TAG, "Adding input method window " + win + " at " + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 mWindows.add(pos, win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001383 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 moveInputMethodDialogsLocked(pos+1);
1385 return;
1386 }
1387 win.mTargetAppToken = null;
1388 addWindowToListInOrderLocked(win, true);
1389 moveInputMethodDialogsLocked(pos);
1390 }
Romain Guy06882f82009-06-10 13:36:04 -07001391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 void setInputMethodAnimLayerAdjustment(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001393 if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 mInputMethodAnimLayerAdjustment = adj;
1395 WindowState imw = mInputMethodWindow;
1396 if (imw != null) {
1397 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001398 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 + " anim layer: " + imw.mAnimLayer);
1400 int wi = imw.mChildWindows.size();
1401 while (wi > 0) {
1402 wi--;
Jeff Browne33348b2010-07-15 23:54:05 -07001403 WindowState cw = imw.mChildWindows.get(wi);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001404 cw.mAnimLayer = cw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001405 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 + " anim layer: " + cw.mAnimLayer);
1407 }
1408 }
1409 int di = mInputMethodDialogs.size();
1410 while (di > 0) {
1411 di --;
1412 imw = mInputMethodDialogs.get(di);
1413 imw.mAnimLayer = imw.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001414 if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 + " anim layer: " + imw.mAnimLayer);
1416 }
1417 }
Romain Guy06882f82009-06-10 13:36:04 -07001418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
1420 int wpos = mWindows.indexOf(win);
1421 if (wpos >= 0) {
1422 if (wpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001423 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001425 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 int NC = win.mChildWindows.size();
1427 while (NC > 0) {
1428 NC--;
Jeff Browne33348b2010-07-15 23:54:05 -07001429 WindowState cw = win.mChildWindows.get(NC);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 int cpos = mWindows.indexOf(cw);
1431 if (cpos >= 0) {
1432 if (cpos < interestingPos) interestingPos--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001433 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001434 + cpos + ": " + cw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 mWindows.remove(cpos);
1436 }
1437 }
1438 }
1439 return interestingPos;
1440 }
Romain Guy06882f82009-06-10 13:36:04 -07001441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 private void reAddWindowToListInOrderLocked(WindowState win) {
1443 addWindowToListInOrderLocked(win, false);
1444 // This is a hack to get all of the child windows added as well
1445 // at the right position. Child windows should be rare and
1446 // this case should be rare, so it shouldn't be that big a deal.
1447 int wpos = mWindows.indexOf(win);
1448 if (wpos >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001449 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001450 + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 mWindows.remove(wpos);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001452 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 reAddWindowLocked(wpos, win);
1454 }
1455 }
Romain Guy06882f82009-06-10 13:36:04 -07001456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 void logWindowList(String prefix) {
1458 int N = mWindows.size();
1459 while (N > 0) {
1460 N--;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001461 Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 }
1463 }
Romain Guy06882f82009-06-10 13:36:04 -07001464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 void moveInputMethodDialogsLocked(int pos) {
1466 ArrayList<WindowState> dialogs = mInputMethodDialogs;
Romain Guy06882f82009-06-10 13:36:04 -07001467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001468 final int N = dialogs.size();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001469 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 for (int i=0; i<N; i++) {
1471 pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
1472 }
1473 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001474 Slog.v(TAG, "Window list w/pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 logWindowList(" ");
1476 }
Romain Guy06882f82009-06-10 13:36:04 -07001477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 if (pos >= 0) {
1479 final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
1480 if (pos < mWindows.size()) {
Jeff Browne33348b2010-07-15 23:54:05 -07001481 WindowState wp = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 if (wp == mInputMethodWindow) {
1483 pos++;
1484 }
1485 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001486 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 for (int i=0; i<N; i++) {
1488 WindowState win = dialogs.get(i);
1489 win.mTargetAppToken = targetAppToken;
1490 pos = reAddWindowLocked(pos, win);
1491 }
1492 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001493 Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 logWindowList(" ");
1495 }
1496 return;
1497 }
1498 for (int i=0; i<N; i++) {
1499 WindowState win = dialogs.get(i);
1500 win.mTargetAppToken = null;
1501 reAddWindowToListInOrderLocked(win);
1502 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001503 Slog.v(TAG, "No IM target, final list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 logWindowList(" ");
1505 }
1506 }
1507 }
Romain Guy06882f82009-06-10 13:36:04 -07001508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
1510 final WindowState imWin = mInputMethodWindow;
1511 final int DN = mInputMethodDialogs.size();
1512 if (imWin == null && DN == 0) {
1513 return false;
1514 }
Romain Guy06882f82009-06-10 13:36:04 -07001515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 int imPos = findDesiredInputMethodWindowIndexLocked(true);
1517 if (imPos >= 0) {
1518 // In this case, the input method windows are to be placed
1519 // immediately above the window they are targeting.
Romain Guy06882f82009-06-10 13:36:04 -07001520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 // First check to see if the input method windows are already
1522 // located here, and contiguous.
1523 final int N = mWindows.size();
1524 WindowState firstImWin = imPos < N
Jeff Browne33348b2010-07-15 23:54:05 -07001525 ? mWindows.get(imPos) : null;
Romain Guy06882f82009-06-10 13:36:04 -07001526
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 // Figure out the actual input method window that should be
1528 // at the bottom of their stack.
1529 WindowState baseImWin = imWin != null
1530 ? imWin : mInputMethodDialogs.get(0);
1531 if (baseImWin.mChildWindows.size() > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001532 WindowState cw = baseImWin.mChildWindows.get(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 if (cw.mSubLayer < 0) baseImWin = cw;
1534 }
Romain Guy06882f82009-06-10 13:36:04 -07001535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 if (firstImWin == baseImWin) {
1537 // The windows haven't moved... but are they still contiguous?
1538 // First find the top IM window.
1539 int pos = imPos+1;
1540 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001541 if (!(mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 break;
1543 }
1544 pos++;
1545 }
1546 pos++;
1547 // Now there should be no more input method windows above.
1548 while (pos < N) {
Jeff Browne33348b2010-07-15 23:54:05 -07001549 if ((mWindows.get(pos)).mIsImWindow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 break;
1551 }
1552 pos++;
1553 }
1554 if (pos >= N) {
1555 // All is good!
1556 return false;
1557 }
1558 }
Romain Guy06882f82009-06-10 13:36:04 -07001559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 if (imWin != null) {
1561 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001562 Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 logWindowList(" ");
1564 }
1565 imPos = tmpRemoveWindowLocked(imPos, imWin);
1566 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001567 Slog.v(TAG, "List after moving with new pos " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 logWindowList(" ");
1569 }
1570 imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
1571 reAddWindowLocked(imPos, imWin);
1572 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001573 Slog.v(TAG, "List after moving IM to " + imPos + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 logWindowList(" ");
1575 }
1576 if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
1577 } else {
1578 moveInputMethodDialogsLocked(imPos);
1579 }
Romain Guy06882f82009-06-10 13:36:04 -07001580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 } else {
1582 // In this case, the input method windows go in a fixed layer,
1583 // because they aren't currently associated with a focus window.
Romain Guy06882f82009-06-10 13:36:04 -07001584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 if (imWin != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001586 if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 tmpRemoveWindowLocked(0, imWin);
1588 imWin.mTargetAppToken = null;
1589 reAddWindowToListInOrderLocked(imWin);
1590 if (DEBUG_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001591 Slog.v(TAG, "List with no IM target:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 logWindowList(" ");
1593 }
1594 if (DN > 0) moveInputMethodDialogsLocked(-1);;
1595 } else {
1596 moveInputMethodDialogsLocked(-1);;
1597 }
Romain Guy06882f82009-06-10 13:36:04 -07001598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 }
Romain Guy06882f82009-06-10 13:36:04 -07001600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 if (needAssignLayers) {
1602 assignLayersLocked();
1603 }
Romain Guy06882f82009-06-10 13:36:04 -07001604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 return true;
1606 }
Romain Guy06882f82009-06-10 13:36:04 -07001607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001608 void adjustInputMethodDialogsLocked() {
1609 moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
1610 }
Romain Guy06882f82009-06-10 13:36:04 -07001611
Dianne Hackborn25994b42009-09-04 14:21:19 -07001612 final boolean isWallpaperVisible(WindowState wallpaperTarget) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001613 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured="
Dianne Hackborn25994b42009-09-04 14:21:19 -07001614 + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
1615 + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
1616 ? wallpaperTarget.mAppToken.animation : null)
1617 + " upper=" + mUpperWallpaperTarget
1618 + " lower=" + mLowerWallpaperTarget);
1619 return (wallpaperTarget != null
1620 && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
1621 && wallpaperTarget.mAppToken.animation != null)))
1622 || mUpperWallpaperTarget != null
1623 || mLowerWallpaperTarget != null;
1624 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001625
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001626 static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
1627 static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001628
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001629 int adjustWallpaperWindowsLocked() {
1630 int changed = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001631
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001632 final int dw = mDisplay.getWidth();
1633 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001634
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001635 // First find top-most window that has asked to be on top of the
1636 // wallpaper; all wallpapers go behind it.
Jeff Browne33348b2010-07-15 23:54:05 -07001637 final ArrayList<WindowState> localmWindows = mWindows;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001638 int N = localmWindows.size();
1639 WindowState w = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001640 WindowState foundW = null;
1641 int foundI = 0;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001642 WindowState topCurW = null;
1643 int topCurI = 0;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001644 int i = N;
1645 while (i > 0) {
1646 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07001647 w = localmWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001648 if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
1649 if (topCurW == null) {
1650 topCurW = w;
1651 topCurI = i;
1652 }
1653 continue;
1654 }
1655 topCurW = null;
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001656 if (w.mAppToken != null) {
1657 // If this window's app token is hidden and not animating,
1658 // it is of no interest to us.
1659 if (w.mAppToken.hidden && w.mAppToken.animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001660 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001661 "Skipping hidden or animating token: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001662 topCurW = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001663 continue;
1664 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001665 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001666 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay="
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001667 + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
1668 + " commitdrawpending=" + w.mCommitDrawPending);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001669 if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07001670 && (mWallpaperTarget == w
1671 || (!w.mDrawPending && !w.mCommitDrawPending))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001672 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001673 "Found wallpaper activity: #" + i + "=" + w);
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001674 foundW = w;
1675 foundI = i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001676 if (w == mWallpaperTarget && ((w.mAppToken != null
1677 && w.mAppToken.animation != null)
1678 || w.mAnimation != null)) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001679 // The current wallpaper target is animating, so we'll
1680 // look behind it for another possible target and figure
1681 // out what is going on below.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001682 if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001683 + ": token animating, looking behind.");
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001684 continue;
1685 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001686 break;
1687 }
1688 }
1689
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07001690 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001691 // If we are currently waiting for an app transition, and either
1692 // the current target or the next target are involved with it,
1693 // then hold off on doing anything with the wallpaper.
1694 // Note that we are checking here for just whether the target
1695 // is part of an app token... which is potentially overly aggressive
1696 // (the app token may not be involved in the transition), but good
1697 // enough (we'll just wait until whatever transition is pending
1698 // executes).
1699 if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001700 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001701 "Wallpaper not changing: waiting for app anim in current target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001702 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001703 }
1704 if (foundW != null && foundW.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001705 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001706 "Wallpaper not changing: waiting for app anim in found target");
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001707 return 0;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001708 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001710
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001711 if (mWallpaperTarget != foundW) {
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001712 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001713 Slog.v(TAG, "New wallpaper target: " + foundW
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001714 + " oldTarget: " + mWallpaperTarget);
1715 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001716
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001717 mLowerWallpaperTarget = null;
1718 mUpperWallpaperTarget = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001719
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001720 WindowState oldW = mWallpaperTarget;
1721 mWallpaperTarget = foundW;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001723 // Now what is happening... if the current and new targets are
1724 // animating, then we are in our super special mode!
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001725 if (foundW != null && oldW != null) {
1726 boolean oldAnim = oldW.mAnimation != null
1727 || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
1728 boolean foundAnim = foundW.mAnimation != null
1729 || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001730 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001731 Slog.v(TAG, "New animation: " + foundAnim
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001732 + " old animation: " + oldAnim);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001733 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001734 if (foundAnim && oldAnim) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001735 int oldI = localmWindows.indexOf(oldW);
1736 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001737 Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001738 }
1739 if (oldI >= 0) {
1740 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001741 Slog.v(TAG, "Animating wallpapers: old#" + oldI
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001742 + "=" + oldW + "; new#" + foundI
1743 + "=" + foundW);
1744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001746 // Set the new target correctly.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001747 if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001748 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001749 Slog.v(TAG, "Old wallpaper still the target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001750 }
1751 mWallpaperTarget = oldW;
1752 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001753
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001754 // Now set the upper and lower wallpaper targets
1755 // correctly, and make sure that we are positioning
1756 // the wallpaper below the lower.
1757 if (foundI > oldI) {
1758 // The new target is on top of the old one.
1759 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001760 Slog.v(TAG, "Found target above old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001761 }
1762 mUpperWallpaperTarget = foundW;
1763 mLowerWallpaperTarget = oldW;
1764 foundW = oldW;
1765 foundI = oldI;
1766 } else {
1767 // The new target is below the old one.
1768 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001769 Slog.v(TAG, "Found target below old target.");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001770 }
1771 mUpperWallpaperTarget = oldW;
1772 mLowerWallpaperTarget = foundW;
1773 }
1774 }
1775 }
1776 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001777
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001778 } else if (mLowerWallpaperTarget != null) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001779 // Is it time to stop animating?
Dianne Hackborn6b1cb352009-09-28 18:27:26 -07001780 boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null
1781 || (mLowerWallpaperTarget.mAppToken != null
1782 && mLowerWallpaperTarget.mAppToken.animation != null);
1783 boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null
1784 || (mUpperWallpaperTarget.mAppToken != null
1785 && mUpperWallpaperTarget.mAppToken.animation != null);
1786 if (!lowerAnimating || !upperAnimating) {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001787 if (DEBUG_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001788 Slog.v(TAG, "No longer animating wallpaper targets!");
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001789 }
1790 mLowerWallpaperTarget = null;
1791 mUpperWallpaperTarget = null;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001792 }
1793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001794
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001795 boolean visible = foundW != null;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001796 if (visible) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001797 // The window is visible to the compositor... but is it visible
1798 // to the user? That is what the wallpaper cares about.
Dianne Hackborn25994b42009-09-04 14:21:19 -07001799 visible = isWallpaperVisible(foundW);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001800 if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001801
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001802 // If the wallpaper target is animating, we may need to copy
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001803 // its layer adjustment. Only do this if we are not transfering
1804 // between two wallpaper targets.
1805 mWallpaperAnimLayerAdjustment =
Dianne Hackborn3be63c02009-08-20 19:31:38 -07001806 (mLowerWallpaperTarget == null && foundW.mAppToken != null)
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001807 ? foundW.mAppToken.animLayerAdjustment : 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001808
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001809 final int maxLayer = mPolicy.getMaxWallpaperLayer()
1810 * TYPE_LAYER_MULTIPLIER
1811 + TYPE_LAYER_OFFSET;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001812
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001813 // Now w is the window we are supposed to be behind... but we
1814 // need to be sure to also be behind any of its attached windows,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001815 // AND any starting window associated with it, AND below the
1816 // maximum layer the policy allows for wallpapers.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001817 while (foundI > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07001818 WindowState wb = localmWindows.get(foundI-1);
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07001819 if (wb.mBaseLayer < maxLayer &&
1820 wb.mAttachedWindow != foundW &&
Pal Szasz73dc2592010-09-03 11:46:26 +02001821 wb.mAttachedWindow != foundW.mAttachedWindow &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001822 (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001823 wb.mToken != foundW.mToken)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001824 // This window is not related to the previous one in any
1825 // interesting way, so stop here.
1826 break;
1827 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001828 foundW = wb;
1829 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001830 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07001831 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001832 if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001834
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001835 if (foundW == null && topCurW != null) {
1836 // There is no wallpaper target, so it goes at the bottom.
1837 // We will assume it is the same place as last time, if known.
1838 foundW = topCurW;
1839 foundI = topCurI+1;
1840 } else {
1841 // Okay i is the position immediately above the wallpaper. Look at
1842 // what is below it for later.
Jeff Browne33348b2010-07-15 23:54:05 -07001843 foundW = foundI > 0 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07001844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001845
Dianne Hackborn284ac932009-08-28 10:34:25 -07001846 if (visible) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001847 if (mWallpaperTarget.mWallpaperX >= 0) {
1848 mLastWallpaperX = mWallpaperTarget.mWallpaperX;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001849 mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001850 }
1851 if (mWallpaperTarget.mWallpaperY >= 0) {
1852 mLastWallpaperY = mWallpaperTarget.mWallpaperY;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001853 mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001854 }
Dianne Hackborn284ac932009-08-28 10:34:25 -07001855 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001856
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001857 // Start stepping backwards from here, ensuring that our wallpaper windows
1858 // are correctly placed.
1859 int curTokenIndex = mWallpaperTokens.size();
1860 while (curTokenIndex > 0) {
1861 curTokenIndex--;
1862 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001863 if (token.hidden == visible) {
1864 changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
1865 token.hidden = !visible;
1866 // Need to do a layout to ensure the wallpaper now has the
1867 // correct size.
1868 mLayoutNeeded = true;
1869 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001870
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001871 int curWallpaperIndex = token.windows.size();
1872 while (curWallpaperIndex > 0) {
1873 curWallpaperIndex--;
1874 WindowState wallpaper = token.windows.get(curWallpaperIndex);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001875
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001876 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001877 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001878 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001879
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001880 // First, make sure the client has the current visibility
1881 // state.
1882 if (wallpaper.mWallpaperVisible != visible) {
1883 wallpaper.mWallpaperVisible = visible;
1884 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001885 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001886 "Setting visibility of wallpaper " + wallpaper
1887 + ": " + visible);
1888 wallpaper.mClient.dispatchAppVisibility(visible);
1889 } catch (RemoteException e) {
1890 }
1891 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001892
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001893 wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001894 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001895 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001896
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001897 // First, if this window is at the current index, then all
1898 // is well.
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001899 if (wallpaper == foundW) {
1900 foundI--;
1901 foundW = foundI > 0
Jeff Browne33348b2010-07-15 23:54:05 -07001902 ? localmWindows.get(foundI-1) : null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001903 continue;
1904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001905
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001906 // The window didn't match... the current wallpaper window,
1907 // wherever it is, is in the wrong place, so make sure it is
1908 // not in the list.
1909 int oldIndex = localmWindows.indexOf(wallpaper);
1910 if (oldIndex >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001911 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001912 + oldIndex + ": " + wallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001913 localmWindows.remove(oldIndex);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001914 mWindowsChanged = true;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001915 if (oldIndex < foundI) {
1916 foundI--;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001917 }
1918 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001919
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001920 // Now stick it in.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001921 if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07001922 "Moving wallpaper " + wallpaper
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001923 + " from " + oldIndex + " to " + foundI);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001924
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07001925 localmWindows.add(foundI, wallpaper);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07001926 mWindowsChanged = true;
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07001927 changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001928 }
1929 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001930
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001931 return changed;
1932 }
1933
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001934 void setWallpaperAnimLayerAdjustmentLocked(int adj) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001935 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001936 "Setting wallpaper layer adj to " + adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001937 mWallpaperAnimLayerAdjustment = adj;
1938 int curTokenIndex = mWallpaperTokens.size();
1939 while (curTokenIndex > 0) {
1940 curTokenIndex--;
1941 WindowToken token = mWallpaperTokens.get(curTokenIndex);
1942 int curWallpaperIndex = token.windows.size();
1943 while (curWallpaperIndex > 0) {
1944 curWallpaperIndex--;
1945 WindowState wallpaper = token.windows.get(curWallpaperIndex);
1946 wallpaper.mAnimLayer = wallpaper.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001947 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win "
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001948 + wallpaper + " anim layer: " + wallpaper.mAnimLayer);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07001949 }
1950 }
1951 }
1952
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001953 boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
1954 boolean sync) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001955 boolean changed = false;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001956 boolean rawChanged = false;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001957 float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001958 float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001959 int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
1960 int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
1961 changed = wallpaperWin.mXOffset != offset;
1962 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001963 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001964 + wallpaperWin + " x: " + offset);
1965 wallpaperWin.mXOffset = offset;
1966 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001967 if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001968 wallpaperWin.mWallpaperX = wpx;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001969 wallpaperWin.mWallpaperXStep = wpxs;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001970 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001971 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001972
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001973 float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001974 float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001975 int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
1976 offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
1977 if (wallpaperWin.mYOffset != offset) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001978 if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001979 + wallpaperWin + " y: " + offset);
1980 changed = true;
1981 wallpaperWin.mYOffset = offset;
1982 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001983 if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001984 wallpaperWin.mWallpaperY = wpy;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001985 wallpaperWin.mWallpaperYStep = wpys;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07001986 rawChanged = true;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07001987 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001988
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07001989 if (rawChanged) {
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001990 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001991 if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07001992 + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
1993 + " y=" + wallpaperWin.mWallpaperY);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001994 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07001995 mWaitingOnWallpaper = wallpaperWin;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07001996 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07001997 wallpaperWin.mClient.dispatchWallpaperOffsets(
Marco Nelissenbf6956b2009-11-09 15:21:13 -08001998 wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
1999 wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002000 if (sync) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002001 if (mWaitingOnWallpaper != null) {
2002 long start = SystemClock.uptimeMillis();
2003 if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
2004 < start) {
2005 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002006 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn75804932009-10-20 20:15:20 -07002007 "Waiting for offset complete...");
2008 mWindowMap.wait(WALLPAPER_TIMEOUT);
2009 } catch (InterruptedException e) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002010 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002011 if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
Dianne Hackborn75804932009-10-20 20:15:20 -07002012 if ((start+WALLPAPER_TIMEOUT)
2013 < SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002014 Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
Dianne Hackborn75804932009-10-20 20:15:20 -07002015 + wallpaperWin);
2016 mLastWallpaperTimeoutTime = start;
2017 }
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002018 }
Dianne Hackborn75804932009-10-20 20:15:20 -07002019 mWaitingOnWallpaper = null;
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002020 }
2021 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07002022 } catch (RemoteException e) {
2023 }
2024 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002025
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002026 return changed;
2027 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002028
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002029 void wallpaperOffsetsComplete(IBinder window) {
Dianne Hackborn75804932009-10-20 20:15:20 -07002030 synchronized (mWindowMap) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002031 if (mWaitingOnWallpaper != null &&
2032 mWaitingOnWallpaper.mClient.asBinder() == window) {
2033 mWaitingOnWallpaper = null;
Dianne Hackborn75804932009-10-20 20:15:20 -07002034 mWindowMap.notifyAll();
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002035 }
2036 }
2037 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002038
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002039 boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002040 final int dw = mDisplay.getWidth();
2041 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002042
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002043 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002044
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002045 WindowState target = mWallpaperTarget;
2046 if (target != null) {
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002047 if (target.mWallpaperX >= 0) {
2048 mLastWallpaperX = target.mWallpaperX;
2049 } else if (changingTarget.mWallpaperX >= 0) {
2050 mLastWallpaperX = changingTarget.mWallpaperX;
2051 }
2052 if (target.mWallpaperY >= 0) {
2053 mLastWallpaperY = target.mWallpaperY;
2054 } else if (changingTarget.mWallpaperY >= 0) {
2055 mLastWallpaperY = changingTarget.mWallpaperY;
2056 }
2057 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002058
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002059 int curTokenIndex = mWallpaperTokens.size();
2060 while (curTokenIndex > 0) {
2061 curTokenIndex--;
2062 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2063 int curWallpaperIndex = token.windows.size();
2064 while (curWallpaperIndex > 0) {
2065 curWallpaperIndex--;
2066 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2067 if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
2068 wallpaper.computeShownFrameLocked();
2069 changed = true;
2070 // We only want to be synchronous with one wallpaper.
2071 sync = false;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002072 }
2073 }
2074 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002075
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002076 return changed;
2077 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002078
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002079 void updateWallpaperVisibilityLocked() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07002080 final boolean visible = isWallpaperVisible(mWallpaperTarget);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002081 final int dw = mDisplay.getWidth();
2082 final int dh = mDisplay.getHeight();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002083
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002084 int curTokenIndex = mWallpaperTokens.size();
2085 while (curTokenIndex > 0) {
2086 curTokenIndex--;
2087 WindowToken token = mWallpaperTokens.get(curTokenIndex);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002088 if (token.hidden == visible) {
2089 token.hidden = !visible;
2090 // Need to do a layout to ensure the wallpaper now has the
2091 // correct size.
2092 mLayoutNeeded = true;
2093 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002094
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002095 int curWallpaperIndex = token.windows.size();
2096 while (curWallpaperIndex > 0) {
2097 curWallpaperIndex--;
2098 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2099 if (visible) {
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002100 updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002101 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002102
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002103 if (wallpaper.mWallpaperVisible != visible) {
2104 wallpaper.mWallpaperVisible = visible;
2105 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002106 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07002107 "Updating visibility of wallpaper " + wallpaper
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002108 + ": " + visible);
2109 wallpaper.mClient.dispatchAppVisibility(visible);
2110 } catch (RemoteException e) {
2111 }
2112 }
2113 }
2114 }
2115 }
Dianne Hackborn90d2db32010-02-11 22:19:06 -08002116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 public int addWindow(Session session, IWindow client,
2118 WindowManager.LayoutParams attrs, int viewVisibility,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002119 Rect outContentInsets, InputChannel outInputChannel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 int res = mPolicy.checkAddPermission(attrs);
2121 if (res != WindowManagerImpl.ADD_OKAY) {
2122 return res;
2123 }
Romain Guy06882f82009-06-10 13:36:04 -07002124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 boolean reportNewConfig = false;
2126 WindowState attachedWindow = null;
2127 WindowState win = null;
Dianne Hackborn5132b372010-07-29 12:51:35 -07002128 long origId;
Romain Guy06882f82009-06-10 13:36:04 -07002129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 synchronized(mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 if (mDisplay == null) {
Dianne Hackborn5132b372010-07-29 12:51:35 -07002132 throw new IllegalStateException("Display has not been initialialized");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 }
Romain Guy06882f82009-06-10 13:36:04 -07002134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 if (mWindowMap.containsKey(client.asBinder())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002136 Slog.w(TAG, "Window " + client + " is already added");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 return WindowManagerImpl.ADD_DUPLICATE_ADD;
2138 }
2139
2140 if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002141 attachedWindow = windowForClientLocked(null, attrs.token, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002142 if (attachedWindow == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002143 Slog.w(TAG, "Attempted to add window with token that is not a window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 + attrs.token + ". Aborting.");
2145 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2146 }
2147 if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
2148 && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002149 Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 + attrs.token + ". Aborting.");
2151 return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
2152 }
2153 }
2154
2155 boolean addToken = false;
2156 WindowToken token = mTokenMap.get(attrs.token);
2157 if (token == null) {
2158 if (attrs.type >= FIRST_APPLICATION_WINDOW
2159 && attrs.type <= LAST_APPLICATION_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002160 Slog.w(TAG, "Attempted to add application window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 + attrs.token + ". Aborting.");
2162 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2163 }
2164 if (attrs.type == TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002165 Slog.w(TAG, "Attempted to add input method window with unknown token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 + attrs.token + ". Aborting.");
2167 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2168 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002169 if (attrs.type == TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002170 Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002171 + attrs.token + ". Aborting.");
2172 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2173 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 token = new WindowToken(attrs.token, -1, false);
2175 addToken = true;
2176 } else if (attrs.type >= FIRST_APPLICATION_WINDOW
2177 && attrs.type <= LAST_APPLICATION_WINDOW) {
2178 AppWindowToken atoken = token.appWindowToken;
2179 if (atoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002180 Slog.w(TAG, "Attempted to add window with non-application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 + token + ". Aborting.");
2182 return WindowManagerImpl.ADD_NOT_APP_TOKEN;
2183 } else if (atoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002184 Slog.w(TAG, "Attempted to add window with exiting application token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 + token + ". Aborting.");
2186 return WindowManagerImpl.ADD_APP_EXITING;
2187 }
2188 if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
2189 // No need for this guy!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002190 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 TAG, "**** NO NEED TO START: " + attrs.getTitle());
2192 return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
2193 }
2194 } else if (attrs.type == TYPE_INPUT_METHOD) {
2195 if (token.windowType != TYPE_INPUT_METHOD) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002196 Slog.w(TAG, "Attempted to add input method window with bad token "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 + attrs.token + ". Aborting.");
2198 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2199 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002200 } else if (attrs.type == TYPE_WALLPAPER) {
2201 if (token.windowType != TYPE_WALLPAPER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002202 Slog.w(TAG, "Attempted to add wallpaper window with bad token "
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002203 + attrs.token + ". Aborting.");
2204 return WindowManagerImpl.ADD_BAD_APP_TOKEN;
2205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 }
2207
2208 win = new WindowState(session, client, token,
2209 attachedWindow, attrs, viewVisibility);
2210 if (win.mDeathRecipient == null) {
2211 // Client has apparently died, so there is no reason to
2212 // continue.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002213 Slog.w(TAG, "Adding window client " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 + " that is dead, aborting.");
2215 return WindowManagerImpl.ADD_APP_EXITING;
2216 }
2217
2218 mPolicy.adjustWindowParamsLw(win.mAttrs);
Romain Guy06882f82009-06-10 13:36:04 -07002219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 res = mPolicy.prepareAddWindowLw(win, attrs);
2221 if (res != WindowManagerImpl.ADD_OKAY) {
2222 return res;
2223 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002224
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002225 if (outInputChannel != null) {
2226 String name = win.makeInputChannelName();
2227 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2228 win.mInputChannel = inputChannels[0];
2229 inputChannels[1].transferToBinderOutParameter(outInputChannel);
2230
2231 mInputManager.registerInputChannel(win.mInputChannel);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07002232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233
2234 // From now on, no exceptions or errors allowed!
2235
2236 res = WindowManagerImpl.ADD_OKAY;
Romain Guy06882f82009-06-10 13:36:04 -07002237
Dianne Hackborn5132b372010-07-29 12:51:35 -07002238 origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002239
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240 if (addToken) {
2241 mTokenMap.put(attrs.token, token);
2242 mTokenList.add(token);
2243 }
2244 win.attach();
2245 mWindowMap.put(client.asBinder(), win);
2246
2247 if (attrs.type == TYPE_APPLICATION_STARTING &&
2248 token.appWindowToken != null) {
2249 token.appWindowToken.startingWindow = win;
2250 }
2251
2252 boolean imMayMove = true;
Romain Guy06882f82009-06-10 13:36:04 -07002253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002254 if (attrs.type == TYPE_INPUT_METHOD) {
2255 mInputMethodWindow = win;
2256 addInputMethodWindowToListLocked(win);
2257 imMayMove = false;
2258 } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
2259 mInputMethodDialogs.add(win);
2260 addWindowToListInOrderLocked(win, true);
2261 adjustInputMethodDialogsLocked();
2262 imMayMove = false;
2263 } else {
2264 addWindowToListInOrderLocked(win, true);
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002265 if (attrs.type == TYPE_WALLPAPER) {
2266 mLastWallpaperTimeoutTime = 0;
2267 adjustWallpaperWindowsLocked();
2268 } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002269 adjustWallpaperWindowsLocked();
2270 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 }
Romain Guy06882f82009-06-10 13:36:04 -07002272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 win.mEnterAnimationPending = true;
Romain Guy06882f82009-06-10 13:36:04 -07002274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 mPolicy.getContentInsetHintLw(attrs, outContentInsets);
Romain Guy06882f82009-06-10 13:36:04 -07002276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 if (mInTouchMode) {
2278 res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
2279 }
2280 if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
2281 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
2282 }
Romain Guy06882f82009-06-10 13:36:04 -07002283
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002284 boolean focusChanged = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 if (win.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07002286 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS);
2287 if (focusChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 imMayMove = false;
2289 }
2290 }
Romain Guy06882f82009-06-10 13:36:04 -07002291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 if (imMayMove) {
Romain Guy06882f82009-06-10 13:36:04 -07002293 moveInputMethodWindowsIfNeededLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 }
Romain Guy06882f82009-06-10 13:36:04 -07002295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 assignLayersLocked();
2297 // Don't do layout here, the window must call
2298 // relayout to be displayed, so we'll do it there.
Romain Guy06882f82009-06-10 13:36:04 -07002299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 //dump();
2301
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002302 if (focusChanged) {
Jeff Brown349703e2010-06-22 01:27:15 -07002303 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002304 }
Jeff Brown349703e2010-06-22 01:27:15 -07002305
Joe Onorato8a9b2202010-02-26 18:56:32 -08002306 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 TAG, "New client " + client.asBinder()
2308 + ": window=" + win);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002309
2310 if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
2311 reportNewConfig = true;
2312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002313 }
2314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 if (reportNewConfig) {
2316 sendNewConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 }
Dianne Hackborn5132b372010-07-29 12:51:35 -07002318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 return res;
2322 }
Romain Guy06882f82009-06-10 13:36:04 -07002323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 public void removeWindow(Session session, IWindow client) {
2325 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002326 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 if (win == null) {
2328 return;
2329 }
2330 removeWindowLocked(session, win);
2331 }
2332 }
Romain Guy06882f82009-06-10 13:36:04 -07002333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 public void removeWindowLocked(Session session, WindowState win) {
2335
Joe Onorato8a9b2202010-02-26 18:56:32 -08002336 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 TAG, "Remove " + win + " client="
2338 + Integer.toHexString(System.identityHashCode(
2339 win.mClient.asBinder()))
2340 + ", surface=" + win.mSurface);
2341
2342 final long origId = Binder.clearCallingIdentity();
Jeff Brownc5ed5912010-07-14 18:48:53 -07002343
2344 win.disposeInputChannel();
Romain Guy06882f82009-06-10 13:36:04 -07002345
Joe Onorato8a9b2202010-02-26 18:56:32 -08002346 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 TAG, "Remove " + win + ": mSurface=" + win.mSurface
2348 + " mExiting=" + win.mExiting
2349 + " isAnimating=" + win.isAnimating()
2350 + " app-animation="
2351 + (win.mAppToken != null ? win.mAppToken.animation : null)
2352 + " inPendingTransaction="
2353 + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
2354 + " mDisplayFrozen=" + mDisplayFrozen);
2355 // Visibility of the removed window. Will be used later to update orientation later on.
2356 boolean wasVisible = false;
2357 // First, see if we need to run an animation. If we do, we have
2358 // to hold off on removing the window until the animation is done.
2359 // If the display is frozen, just remove immediately, since the
2360 // animation wouldn't be seen.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002361 if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 // If we are not currently running the exit animation, we
2363 // need to see about starting one.
2364 if (wasVisible=win.isWinVisibleLw()) {
Romain Guy06882f82009-06-10 13:36:04 -07002365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2367 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2368 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2369 }
2370 // Try starting an animation.
2371 if (applyAnimationLocked(win, transit, false)) {
2372 win.mExiting = true;
2373 }
2374 }
2375 if (win.mExiting || win.isAnimating()) {
2376 // The exit animation is running... wait for it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08002377 //Slog.i(TAG, "*** Running exit animation...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 win.mExiting = true;
2379 win.mRemoveOnExit = true;
2380 mLayoutNeeded = true;
2381 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
2382 performLayoutAndPlaceSurfacesLocked();
2383 if (win.mAppToken != null) {
2384 win.mAppToken.updateReportedVisibilityLocked();
2385 }
2386 //dump();
2387 Binder.restoreCallingIdentity(origId);
2388 return;
2389 }
2390 }
2391
2392 removeWindowInnerLocked(session, win);
2393 // Removing a visible window will effect the computed orientation
2394 // So just update orientation if needed.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002395 if (wasVisible && computeForcedAppOrientationLocked()
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002396 != mForcedAppOrientation
2397 && updateOrientationFromAppTokensLocked()) {
2398 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 }
2400 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
2401 Binder.restoreCallingIdentity(origId);
2402 }
Romain Guy06882f82009-06-10 13:36:04 -07002403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 private void removeWindowInnerLocked(Session session, WindowState win) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 win.mRemoved = true;
Romain Guy06882f82009-06-10 13:36:04 -07002406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 if (mInputMethodTarget == win) {
2408 moveInputMethodWindowsIfNeededLocked(false);
2409 }
Romain Guy06882f82009-06-10 13:36:04 -07002410
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002411 if (false) {
2412 RuntimeException e = new RuntimeException("here");
2413 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002414 Slog.w(TAG, "Removing window " + win, e);
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07002415 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 mPolicy.removeWindowLw(win);
2418 win.removeLocked();
2419
2420 mWindowMap.remove(win.mClient.asBinder());
2421 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07002422 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002423 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424
2425 if (mInputMethodWindow == win) {
2426 mInputMethodWindow = null;
2427 } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
2428 mInputMethodDialogs.remove(win);
2429 }
Romain Guy06882f82009-06-10 13:36:04 -07002430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 final WindowToken token = win.mToken;
2432 final AppWindowToken atoken = win.mAppToken;
2433 token.windows.remove(win);
2434 if (atoken != null) {
2435 atoken.allAppWindows.remove(win);
2436 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002437 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 TAG, "**** Removing window " + win + ": count="
2439 + token.windows.size());
2440 if (token.windows.size() == 0) {
2441 if (!token.explicit) {
2442 mTokenMap.remove(token.token);
2443 mTokenList.remove(token);
2444 } else if (atoken != null) {
2445 atoken.firstWindowDrawn = false;
2446 }
2447 }
2448
2449 if (atoken != null) {
2450 if (atoken.startingWindow == win) {
2451 atoken.startingWindow = null;
2452 } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
2453 // If this is the last window and we had requested a starting
2454 // transition window, well there is no point now.
2455 atoken.startingData = null;
2456 } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
2457 // If this is the last window except for a starting transition
2458 // window, we need to get rid of the starting transition.
2459 if (DEBUG_STARTING_WINDOW) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002460 Slog.v(TAG, "Schedule remove starting " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 + ": no more real windows");
2462 }
2463 Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken);
2464 mH.sendMessage(m);
2465 }
2466 }
Romain Guy06882f82009-06-10 13:36:04 -07002467
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002468 if (win.mAttrs.type == TYPE_WALLPAPER) {
2469 mLastWallpaperTimeoutTime = 0;
2470 adjustWallpaperWindowsLocked();
2471 } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07002472 adjustWallpaperWindowsLocked();
2473 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 if (!mInLayout) {
2476 assignLayersLocked();
2477 mLayoutNeeded = true;
2478 performLayoutAndPlaceSurfacesLocked();
2479 if (win.mAppToken != null) {
2480 win.mAppToken.updateReportedVisibilityLocked();
2481 }
2482 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002483
2484 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 }
2486
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002487 private static void logSurface(WindowState w, String msg, RuntimeException where) {
2488 String str = " SURFACE " + Integer.toHexString(w.hashCode())
2489 + ": " + msg + " / " + w.mAttrs.getTitle();
2490 if (where != null) {
2491 Slog.i(TAG, str, where);
2492 } else {
2493 Slog.i(TAG, str);
2494 }
2495 }
2496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 private void setTransparentRegionWindow(Session session, IWindow client, Region region) {
2498 long origId = Binder.clearCallingIdentity();
2499 try {
2500 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002501 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 if ((w != null) && (w.mSurface != null)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002503 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 Surface.openTransaction();
2505 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002506 if (SHOW_TRANSACTIONS) logSurface(w,
2507 "transparentRegionHint=" + region, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 w.mSurface.setTransparentRegionHint(region);
2509 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002510 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 Surface.closeTransaction();
2512 }
2513 }
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(origId);
2517 }
2518 }
2519
2520 void setInsetsWindow(Session session, IWindow client,
Romain Guy06882f82009-06-10 13:36:04 -07002521 int touchableInsets, Rect contentInsets,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 Rect visibleInsets) {
2523 long origId = Binder.clearCallingIdentity();
2524 try {
2525 synchronized (mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002526 WindowState w = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 if (w != null) {
2528 w.mGivenInsetsPending = false;
2529 w.mGivenContentInsets.set(contentInsets);
2530 w.mGivenVisibleInsets.set(visibleInsets);
2531 w.mTouchableInsets = touchableInsets;
2532 mLayoutNeeded = true;
2533 performLayoutAndPlaceSurfacesLocked();
2534 }
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(origId);
2538 }
2539 }
Romain Guy06882f82009-06-10 13:36:04 -07002540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 public void getWindowDisplayFrame(Session session, IWindow client,
2542 Rect outDisplayFrame) {
2543 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002544 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 if (win == null) {
2546 outDisplayFrame.setEmpty();
2547 return;
2548 }
2549 outDisplayFrame.set(win.mDisplayFrame);
2550 }
2551 }
2552
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002553 public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
2554 float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002555 if (window.mWallpaperX != x || window.mWallpaperY != y) {
2556 window.mWallpaperX = x;
2557 window.mWallpaperY = y;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08002558 window.mWallpaperXStep = xStep;
2559 window.mWallpaperYStep = yStep;
Dianne Hackborn73e92b42009-10-15 14:29:19 -07002560 if (updateWallpaperOffsetLocked(window, true)) {
2561 performLayoutAndPlaceSurfacesLocked();
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07002562 }
2563 }
2564 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002565
Dianne Hackborn75804932009-10-20 20:15:20 -07002566 void wallpaperCommandComplete(IBinder window, Bundle result) {
2567 synchronized (mWindowMap) {
2568 if (mWaitingOnWallpaper != null &&
2569 mWaitingOnWallpaper.mClient.asBinder() == window) {
2570 mWaitingOnWallpaper = null;
2571 mWindowMap.notifyAll();
2572 }
2573 }
2574 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002575
Dianne Hackborn75804932009-10-20 20:15:20 -07002576 public Bundle sendWindowWallpaperCommandLocked(WindowState window,
2577 String action, int x, int y, int z, Bundle extras, boolean sync) {
2578 if (window == mWallpaperTarget || window == mLowerWallpaperTarget
2579 || window == mUpperWallpaperTarget) {
2580 boolean doWait = sync;
2581 int curTokenIndex = mWallpaperTokens.size();
2582 while (curTokenIndex > 0) {
2583 curTokenIndex--;
2584 WindowToken token = mWallpaperTokens.get(curTokenIndex);
2585 int curWallpaperIndex = token.windows.size();
2586 while (curWallpaperIndex > 0) {
2587 curWallpaperIndex--;
2588 WindowState wallpaper = token.windows.get(curWallpaperIndex);
2589 try {
2590 wallpaper.mClient.dispatchWallpaperCommand(action,
2591 x, y, z, extras, sync);
2592 // We only want to be synchronous with one wallpaper.
2593 sync = false;
2594 } catch (RemoteException e) {
2595 }
2596 }
2597 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002598
Dianne Hackborn75804932009-10-20 20:15:20 -07002599 if (doWait) {
2600 // XXX Need to wait for result.
2601 }
2602 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002603
Dianne Hackborn75804932009-10-20 20:15:20 -07002604 return null;
2605 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 public int relayoutWindow(Session session, IWindow client,
2608 WindowManager.LayoutParams attrs, int requestedWidth,
2609 int requestedHeight, int viewVisibility, boolean insetsPending,
2610 Rect outFrame, Rect outContentInsets, Rect outVisibleInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002611 Configuration outConfig, Surface outSurface) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 boolean displayed = false;
2613 boolean inTouchMode;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002614 boolean configChanged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07002616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002618 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 if (win == null) {
2620 return 0;
2621 }
2622 win.mRequestedWidth = requestedWidth;
2623 win.mRequestedHeight = requestedHeight;
2624
2625 if (attrs != null) {
2626 mPolicy.adjustWindowParamsLw(attrs);
2627 }
Romain Guy06882f82009-06-10 13:36:04 -07002628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 int attrChanges = 0;
2630 int flagChanges = 0;
2631 if (attrs != null) {
2632 flagChanges = win.mAttrs.flags ^= attrs.flags;
2633 attrChanges = win.mAttrs.copyFrom(attrs);
2634 }
2635
Joe Onorato8a9b2202010-02-26 18:56:32 -08002636 if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637
2638 if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
2639 win.mAlpha = attrs.alpha;
2640 }
2641
2642 final boolean scaledWindow =
2643 ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
2644
2645 if (scaledWindow) {
2646 // requested{Width|Height} Surface's physical size
2647 // attrs.{width|height} Size on screen
2648 win.mHScale = (attrs.width != requestedWidth) ?
2649 (attrs.width / (float)requestedWidth) : 1.0f;
2650 win.mVScale = (attrs.height != requestedHeight) ?
2651 (attrs.height / (float)requestedHeight) : 1.0f;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08002652 } else {
2653 win.mHScale = win.mVScale = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 }
2655
2656 boolean imMayMove = (flagChanges&(
2657 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
2658 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
Romain Guy06882f82009-06-10 13:36:04 -07002659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 boolean focusMayChange = win.mViewVisibility != viewVisibility
2661 || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0)
2662 || (!win.mRelayoutCalled);
Romain Guy06882f82009-06-10 13:36:04 -07002663
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002664 boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
2665 && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002666
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667 win.mRelayoutCalled = true;
2668 final int oldVisibility = win.mViewVisibility;
2669 win.mViewVisibility = viewVisibility;
2670 if (viewVisibility == View.VISIBLE &&
2671 (win.mAppToken == null || !win.mAppToken.clientHidden)) {
2672 displayed = !win.isVisibleLw();
2673 if (win.mExiting) {
2674 win.mExiting = false;
2675 win.mAnimation = null;
2676 }
2677 if (win.mDestroying) {
2678 win.mDestroying = false;
2679 mDestroySurface.remove(win);
2680 }
2681 if (oldVisibility == View.GONE) {
2682 win.mEnterAnimationPending = true;
2683 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -07002684 if (displayed) {
2685 if (win.mSurface != null && !win.mDrawPending
2686 && !win.mCommitDrawPending && !mDisplayFrozen
2687 && mPolicy.isScreenOn()) {
2688 applyEnterAnimationLocked(win);
2689 }
2690 if ((win.mAttrs.flags
2691 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
2692 if (DEBUG_VISIBILITY) Slog.v(TAG,
2693 "Relayout window turning screen on: " + win);
2694 win.mTurnOnScreen = true;
2695 }
2696 int diff = 0;
2697 if (win.mConfiguration != mCurConfiguration
2698 && (win.mConfiguration == null
2699 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) {
2700 win.mConfiguration = mCurConfiguration;
2701 if (DEBUG_CONFIGURATION) {
2702 Slog.i(TAG, "Window " + win + " visible with new config: "
2703 + win.mConfiguration + " / 0x"
2704 + Integer.toHexString(diff));
2705 }
2706 outConfig.setTo(mCurConfiguration);
2707 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002708 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
2710 // To change the format, we need to re-build the surface.
2711 win.destroySurfaceLocked();
2712 displayed = true;
2713 }
2714 try {
2715 Surface surface = win.createSurfaceLocked();
2716 if (surface != null) {
2717 outSurface.copyFrom(surface);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002718 win.mReportDestroySurface = false;
2719 win.mSurfacePendingDestroy = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08002720 if (SHOW_TRANSACTIONS) Slog.i(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002721 " OUT SURFACE " + outSurface + ": copied");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 } else {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002723 // For some reason there isn't a surface. Clear the
2724 // caller's object so they see the same state.
2725 outSurface.release();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 }
2727 } catch (Exception e) {
Jeff Browne33348b2010-07-15 23:54:05 -07002728 mInputMonitor.updateInputWindowsLw();
2729
Joe Onorato8a9b2202010-02-26 18:56:32 -08002730 Slog.w(TAG, "Exception thrown when creating surface for client "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002731 + client + " (" + win.mAttrs.getTitle() + ")",
2732 e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002733 Binder.restoreCallingIdentity(origId);
2734 return 0;
2735 }
2736 if (displayed) {
2737 focusMayChange = true;
2738 }
2739 if (win.mAttrs.type == TYPE_INPUT_METHOD
2740 && mInputMethodWindow == null) {
2741 mInputMethodWindow = win;
2742 imMayMove = true;
2743 }
Dianne Hackborn558947c2009-12-18 16:02:50 -08002744 if (win.mAttrs.type == TYPE_BASE_APPLICATION
2745 && win.mAppToken != null
2746 && win.mAppToken.startingWindow != null) {
2747 // Special handling of starting window over the base
2748 // window of the app: propagate lock screen flags to it,
2749 // to provide the correct semantics while starting.
2750 final int mask =
2751 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
Mike Lockwoodef731622010-01-27 17:51:34 -05002752 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
2753 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Dianne Hackborn558947c2009-12-18 16:02:50 -08002754 WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
2755 sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
2756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 } else {
2758 win.mEnterAnimationPending = false;
2759 if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002760 if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002761 + ": mExiting=" + win.mExiting
2762 + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 // If we are not currently running the exit animation, we
2764 // need to see about starting one.
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002765 if (!win.mExiting || win.mSurfacePendingDestroy) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 // Try starting an animation; if there isn't one, we
2767 // can destroy the surface right away.
2768 int transit = WindowManagerPolicy.TRANSIT_EXIT;
2769 if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
2770 transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
2771 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002772 if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 applyAnimationLocked(win, transit, false)) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002774 focusMayChange = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 win.mExiting = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 } else if (win.isAnimating()) {
2777 // Currently in a hide animation... turn this into
2778 // an exit.
2779 win.mExiting = true;
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07002780 } else if (win == mWallpaperTarget) {
2781 // If the wallpaper is currently behind this
2782 // window, we need to change both of them inside
2783 // of a transaction to avoid artifacts.
2784 win.mExiting = true;
2785 win.mAnimating = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 } else {
2787 if (mInputMethodWindow == win) {
2788 mInputMethodWindow = null;
2789 }
2790 win.destroySurfaceLocked();
2791 }
2792 }
2793 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002794
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002795 if (win.mSurface == null || (win.getAttrs().flags
2796 & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
2797 || win.mSurfacePendingDestroy) {
2798 // We are being called from a local process, which
2799 // means outSurface holds its current surface. Ensure the
2800 // surface object is cleared, but we don't want it actually
2801 // destroyed at this point.
2802 win.mSurfacePendingDestroy = false;
2803 outSurface.release();
Joe Onorato8a9b2202010-02-26 18:56:32 -08002804 if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002805 } else if (win.mSurface != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002806 if (DEBUG_VISIBILITY) Slog.i(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002807 "Keeping surface, will report destroy: " + win);
2808 win.mReportDestroySurface = true;
2809 outSurface.copyFrom(win.mSurface);
2810 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 }
2812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 if (focusMayChange) {
2814 //System.out.println("Focus may change: " + win.mAttrs.getTitle());
2815 if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 imMayMove = false;
2817 }
2818 //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
2819 }
Romain Guy06882f82009-06-10 13:36:04 -07002820
The Android Open Source Projectc474dec2009-03-04 09:49:09 -08002821 // updateFocusedWindowLocked() already assigned layers so we only need to
2822 // reassign them at this point if the IM window state gets shuffled
2823 boolean assignLayers = false;
Romain Guy06882f82009-06-10 13:36:04 -07002824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 if (imMayMove) {
Dianne Hackborn8abd5f02009-11-20 18:09:03 -08002826 if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
2827 // Little hack here -- we -should- be able to rely on the
2828 // function to return true if the IME has moved and needs
2829 // its layer recomputed. However, if the IME was hidden
2830 // and isn't actually moved in the list, its layer may be
2831 // out of data so we make sure to recompute it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 assignLayers = true;
2833 }
2834 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002835 if (wallpaperMayMove) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07002836 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07002837 assignLayers = true;
2838 }
2839 }
Romain Guy06882f82009-06-10 13:36:04 -07002840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 mLayoutNeeded = true;
2842 win.mGivenInsetsPending = insetsPending;
2843 if (assignLayers) {
2844 assignLayersLocked();
2845 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002846 configChanged = updateOrientationFromAppTokensLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 performLayoutAndPlaceSurfacesLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -07002848 if (displayed && win.mIsWallpaper) {
2849 updateWallpaperOffsetLocked(win, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07002850 mDisplay.getHeight(), false);
Dianne Hackborn284ac932009-08-28 10:34:25 -07002851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 if (win.mAppToken != null) {
2853 win.mAppToken.updateReportedVisibilityLocked();
2854 }
2855 outFrame.set(win.mFrame);
2856 outContentInsets.set(win.mContentInsets);
2857 outVisibleInsets.set(win.mVisibleInsets);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002858 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 TAG, "Relayout given client " + client.asBinder()
Romain Guy06882f82009-06-10 13:36:04 -07002860 + ", requestedWidth=" + requestedWidth
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 + ", requestedHeight=" + requestedHeight
2862 + ", viewVisibility=" + viewVisibility
2863 + "\nRelayout returning frame=" + outFrame
2864 + ", surface=" + outSurface);
2865
Joe Onorato8a9b2202010-02-26 18:56:32 -08002866 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
2868
2869 inTouchMode = mInTouchMode;
Jeff Browne33348b2010-07-15 23:54:05 -07002870
2871 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 }
2873
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002874 if (configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 sendNewConfiguration();
2876 }
Romain Guy06882f82009-06-10 13:36:04 -07002877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 Binder.restoreCallingIdentity(origId);
Romain Guy06882f82009-06-10 13:36:04 -07002879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0)
2881 | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
2882 }
2883
2884 public void finishDrawingWindow(Session session, IWindow client) {
2885 final long origId = Binder.clearCallingIdentity();
2886 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08002887 WindowState win = windowForClientLocked(session, client, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 if (win != null && win.finishDrawingLocked()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07002889 if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
2890 adjustWallpaperWindowsLocked();
2891 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 mLayoutNeeded = true;
2893 performLayoutAndPlaceSurfacesLocked();
2894 }
2895 }
2896 Binder.restoreCallingIdentity(origId);
2897 }
2898
2899 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002900 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 + (lp != null ? lp.packageName : null)
2902 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
2903 if (lp != null && lp.windowAnimations != 0) {
2904 // If this is a system resource, don't try to load it from the
2905 // application resources. It is nice to avoid loading application
2906 // resources if we can.
2907 String packageName = lp.packageName != null ? lp.packageName : "android";
2908 int resId = lp.windowAnimations;
2909 if ((resId&0xFF000000) == 0x01000000) {
2910 packageName = "android";
2911 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002912 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 + packageName);
2914 return AttributeCache.instance().get(packageName, resId,
2915 com.android.internal.R.styleable.WindowAnimation);
2916 }
2917 return null;
2918 }
Romain Guy06882f82009-06-10 13:36:04 -07002919
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002920 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002921 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002922 + packageName + " resId=0x" + Integer.toHexString(resId));
2923 if (packageName != null) {
2924 if ((resId&0xFF000000) == 0x01000000) {
2925 packageName = "android";
2926 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002927 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07002928 + packageName);
2929 return AttributeCache.instance().get(packageName, resId,
2930 com.android.internal.R.styleable.WindowAnimation);
2931 }
2932 return null;
2933 }
2934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 private void applyEnterAnimationLocked(WindowState win) {
2936 int transit = WindowManagerPolicy.TRANSIT_SHOW;
2937 if (win.mEnterAnimationPending) {
2938 win.mEnterAnimationPending = false;
2939 transit = WindowManagerPolicy.TRANSIT_ENTER;
2940 }
2941
2942 applyAnimationLocked(win, transit, true);
2943 }
2944
2945 private boolean applyAnimationLocked(WindowState win,
2946 int transit, boolean isEntrance) {
2947 if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) {
2948 // If we are trying to apply an animation, but already running
2949 // an animation of the same type, then just leave that one alone.
2950 return true;
2951 }
Romain Guy06882f82009-06-10 13:36:04 -07002952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 // Only apply an animation if the display isn't frozen. If it is
2954 // frozen, there is no reason to animate and it can cause strange
2955 // artifacts when we unfreeze the display if some different animation
2956 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08002957 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 int anim = mPolicy.selectAnimationLw(win, transit);
2959 int attr = -1;
2960 Animation a = null;
2961 if (anim != 0) {
2962 a = AnimationUtils.loadAnimation(mContext, anim);
2963 } else {
2964 switch (transit) {
2965 case WindowManagerPolicy.TRANSIT_ENTER:
2966 attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
2967 break;
2968 case WindowManagerPolicy.TRANSIT_EXIT:
2969 attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
2970 break;
2971 case WindowManagerPolicy.TRANSIT_SHOW:
2972 attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
2973 break;
2974 case WindowManagerPolicy.TRANSIT_HIDE:
2975 attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
2976 break;
2977 }
2978 if (attr >= 0) {
2979 a = loadAnimation(win.mAttrs, attr);
2980 }
2981 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002982 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
2984 + " mAnimation=" + win.mAnimation
2985 + " isEntrance=" + isEntrance);
2986 if (a != null) {
2987 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08002988 RuntimeException e = null;
2989 if (!HIDE_STACK_CRAWLS) {
2990 e = new RuntimeException();
2991 e.fillInStackTrace();
2992 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08002993 Slog.v(TAG, "Loaded animation " + a + " for " + win, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 }
2995 win.setAnimation(a);
2996 win.mAnimationIsEntrance = isEntrance;
2997 }
2998 } else {
2999 win.clearAnimation();
3000 }
3001
3002 return win.mAnimation != null;
3003 }
3004
3005 private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
3006 int anim = 0;
3007 Context context = mContext;
3008 if (animAttr >= 0) {
3009 AttributeCache.Entry ent = getCachedAnimations(lp);
3010 if (ent != null) {
3011 context = ent.context;
3012 anim = ent.array.getResourceId(animAttr, 0);
3013 }
3014 }
3015 if (anim != 0) {
3016 return AnimationUtils.loadAnimation(context, anim);
3017 }
3018 return null;
3019 }
Romain Guy06882f82009-06-10 13:36:04 -07003020
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003021 private Animation loadAnimation(String packageName, int resId) {
3022 int anim = 0;
3023 Context context = mContext;
3024 if (resId >= 0) {
3025 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
3026 if (ent != null) {
3027 context = ent.context;
3028 anim = resId;
3029 }
3030 }
3031 if (anim != 0) {
3032 return AnimationUtils.loadAnimation(context, anim);
3033 }
3034 return null;
3035 }
3036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003037 private boolean applyAnimationLocked(AppWindowToken wtoken,
3038 WindowManager.LayoutParams lp, int transit, boolean enter) {
3039 // Only apply an animation if the display isn't frozen. If it is
3040 // frozen, there is no reason to animate and it can cause strange
3041 // artifacts when we unfreeze the display if some different animation
3042 // is running.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003043 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003044 Animation a;
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07003045 if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003046 a = new FadeInOutAnimation(enter);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003047 if (DEBUG_ANIM) Slog.v(TAG,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003048 "applying FadeInOutAnimation for a window in compatibility mode");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003049 } else if (mNextAppTransitionPackage != null) {
3050 a = loadAnimation(mNextAppTransitionPackage, enter ?
3051 mNextAppTransitionEnter : mNextAppTransitionExit);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003052 } else {
3053 int animAttr = 0;
3054 switch (transit) {
3055 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
3056 animAttr = enter
3057 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
3058 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
3059 break;
3060 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
3061 animAttr = enter
3062 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
3063 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
3064 break;
3065 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
3066 animAttr = enter
3067 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
3068 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
3069 break;
3070 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
3071 animAttr = enter
3072 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
3073 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
3074 break;
3075 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
3076 animAttr = enter
3077 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
3078 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
3079 break;
3080 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
3081 animAttr = enter
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -07003082 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003083 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
3084 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003085 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003086 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003087 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
3088 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003089 break;
Dianne Hackborn25994b42009-09-04 14:21:19 -07003090 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE:
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003091 animAttr = enter
Dianne Hackborn25994b42009-09-04 14:21:19 -07003092 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
3093 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
3094 break;
3095 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN:
3096 animAttr = enter
3097 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
3098 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
3099 break;
3100 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE:
3101 animAttr = enter
3102 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
3103 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07003104 break;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003105 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003106 a = animAttr != 0 ? loadAnimation(lp, animAttr) : null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003107 if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07003108 + " anim=" + a
3109 + " animAttr=0x" + Integer.toHexString(animAttr)
3110 + " transit=" + transit);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 if (a != null) {
3113 if (DEBUG_ANIM) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003114 RuntimeException e = null;
3115 if (!HIDE_STACK_CRAWLS) {
3116 e = new RuntimeException();
3117 e.fillInStackTrace();
3118 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003119 Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 }
3121 wtoken.setAnimation(a);
3122 }
3123 } else {
3124 wtoken.clearAnimation();
3125 }
3126
3127 return wtoken.animation != null;
3128 }
3129
3130 // -------------------------------------------------------------
3131 // Application Window Tokens
3132 // -------------------------------------------------------------
3133
3134 public void validateAppTokens(List tokens) {
3135 int v = tokens.size()-1;
3136 int m = mAppTokens.size()-1;
3137 while (v >= 0 && m >= 0) {
3138 AppWindowToken wtoken = mAppTokens.get(m);
3139 if (wtoken.removed) {
3140 m--;
3141 continue;
3142 }
3143 if (tokens.get(v) != wtoken.token) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003144 Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 + " @ " + v + ", internal is " + wtoken.token + " @ " + m);
3146 }
3147 v--;
3148 m--;
3149 }
3150 while (v >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003151 Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 v--;
3153 }
3154 while (m >= 0) {
3155 AppWindowToken wtoken = mAppTokens.get(m);
3156 if (!wtoken.removed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003157 Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 }
3159 m--;
3160 }
3161 }
3162
3163 boolean checkCallingPermission(String permission, String func) {
3164 // Quick check: if the calling permission is me, it's all okay.
3165 if (Binder.getCallingPid() == Process.myPid()) {
3166 return true;
3167 }
Romain Guy06882f82009-06-10 13:36:04 -07003168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 if (mContext.checkCallingPermission(permission)
3170 == PackageManager.PERMISSION_GRANTED) {
3171 return true;
3172 }
3173 String msg = "Permission Denial: " + func + " from pid="
3174 + Binder.getCallingPid()
3175 + ", uid=" + Binder.getCallingUid()
3176 + " requires " + permission;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003177 Slog.w(TAG, msg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 return false;
3179 }
Romain Guy06882f82009-06-10 13:36:04 -07003180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 AppWindowToken findAppWindowToken(IBinder token) {
3182 WindowToken wtoken = mTokenMap.get(token);
3183 if (wtoken == null) {
3184 return null;
3185 }
3186 return wtoken.appWindowToken;
3187 }
Romain Guy06882f82009-06-10 13:36:04 -07003188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 public void addWindowToken(IBinder token, int type) {
3190 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3191 "addWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003192 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 }
Romain Guy06882f82009-06-10 13:36:04 -07003194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 synchronized(mWindowMap) {
3196 WindowToken wtoken = mTokenMap.get(token);
3197 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003198 Slog.w(TAG, "Attempted to add existing input method token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 return;
3200 }
3201 wtoken = new WindowToken(token, type, true);
3202 mTokenMap.put(token, wtoken);
3203 mTokenList.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003204 if (type == TYPE_WALLPAPER) {
3205 mWallpaperTokens.add(wtoken);
3206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 }
3208 }
Romain Guy06882f82009-06-10 13:36:04 -07003209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 public void removeWindowToken(IBinder token) {
3211 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3212 "removeWindowToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003213 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 }
3215
3216 final long origId = Binder.clearCallingIdentity();
3217 synchronized(mWindowMap) {
3218 WindowToken wtoken = mTokenMap.remove(token);
3219 mTokenList.remove(wtoken);
3220 if (wtoken != null) {
3221 boolean delayed = false;
3222 if (!wtoken.hidden) {
3223 wtoken.hidden = true;
Romain Guy06882f82009-06-10 13:36:04 -07003224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003225 final int N = wtoken.windows.size();
3226 boolean changed = false;
Romain Guy06882f82009-06-10 13:36:04 -07003227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228 for (int i=0; i<N; i++) {
3229 WindowState win = wtoken.windows.get(i);
3230
3231 if (win.isAnimating()) {
3232 delayed = true;
3233 }
Romain Guy06882f82009-06-10 13:36:04 -07003234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 if (win.isVisibleNow()) {
3236 applyAnimationLocked(win,
3237 WindowManagerPolicy.TRANSIT_EXIT, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238 changed = true;
3239 }
3240 }
3241
3242 if (changed) {
3243 mLayoutNeeded = true;
3244 performLayoutAndPlaceSurfacesLocked();
3245 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3246 }
Romain Guy06882f82009-06-10 13:36:04 -07003247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 if (delayed) {
3249 mExitingTokens.add(wtoken);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07003250 } else if (wtoken.windowType == TYPE_WALLPAPER) {
3251 mWallpaperTokens.remove(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 }
3253 }
Romain Guy06882f82009-06-10 13:36:04 -07003254
Jeff Brownc5ed5912010-07-14 18:48:53 -07003255 mInputMonitor.updateInputWindowsLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003257 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 }
3259 }
3260 Binder.restoreCallingIdentity(origId);
3261 }
3262
3263 public void addAppToken(int addPos, IApplicationToken token,
3264 int groupId, int requestedOrientation, boolean fullscreen) {
3265 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3266 "addAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003267 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 }
Jeff Brown349703e2010-06-22 01:27:15 -07003269
3270 // Get the dispatching timeout here while we are not holding any locks so that it
3271 // can be cached by the AppWindowToken. The timeout value is used later by the
3272 // input dispatcher in code that does hold locks. If we did not cache the value
3273 // here we would run the chance of introducing a deadlock between the window manager
3274 // (which holds locks while updating the input dispatcher state) and the activity manager
3275 // (which holds locks while querying the application token).
3276 long inputDispatchingTimeoutNanos;
3277 try {
3278 inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
3279 } catch (RemoteException ex) {
3280 Slog.w(TAG, "Could not get dispatching timeout.", ex);
3281 inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
3282 }
Romain Guy06882f82009-06-10 13:36:04 -07003283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 synchronized(mWindowMap) {
3285 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3286 if (wtoken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003287 Slog.w(TAG, "Attempted to add existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 return;
3289 }
3290 wtoken = new AppWindowToken(token);
Jeff Brown349703e2010-06-22 01:27:15 -07003291 wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 wtoken.groupId = groupId;
3293 wtoken.appFullscreen = fullscreen;
3294 wtoken.requestedOrientation = requestedOrientation;
3295 mAppTokens.add(addPos, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003296 if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 mTokenMap.put(token.asBinder(), wtoken);
3298 mTokenList.add(wtoken);
Romain Guy06882f82009-06-10 13:36:04 -07003299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 // Application tokens start out hidden.
3301 wtoken.hidden = true;
3302 wtoken.hiddenRequested = true;
Romain Guy06882f82009-06-10 13:36:04 -07003303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 //dump();
3305 }
3306 }
Romain Guy06882f82009-06-10 13:36:04 -07003307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 public void setAppGroupId(IBinder token, int groupId) {
3309 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3310 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003311 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 }
3313
3314 synchronized(mWindowMap) {
3315 AppWindowToken wtoken = findAppWindowToken(token);
3316 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003317 Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 return;
3319 }
3320 wtoken.groupId = groupId;
3321 }
3322 }
Romain Guy06882f82009-06-10 13:36:04 -07003323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 public int getOrientationFromWindowsLocked() {
3325 int pos = mWindows.size() - 1;
3326 while (pos >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07003327 WindowState wtoken = mWindows.get(pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 pos--;
3329 if (wtoken.mAppToken != null) {
3330 // We hit an application window. so the orientation will be determined by the
3331 // app window. No point in continuing further.
3332 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3333 }
Christopher Tateb696aee2010-04-02 19:08:30 -07003334 if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 continue;
3336 }
3337 int req = wtoken.mAttrs.screenOrientation;
3338 if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
3339 (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
3340 continue;
3341 } else {
3342 return req;
3343 }
3344 }
3345 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3346 }
Romain Guy06882f82009-06-10 13:36:04 -07003347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 public int getOrientationFromAppTokensLocked() {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003349 int pos = mAppTokens.size() - 1;
3350 int curGroup = 0;
3351 int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3352 boolean findingBehind = false;
3353 boolean haveGroup = false;
3354 boolean lastFullscreen = false;
3355 while (pos >= 0) {
3356 AppWindowToken wtoken = mAppTokens.get(pos);
3357 pos--;
3358 // if we're about to tear down this window and not seek for
3359 // the behind activity, don't use it for orientation
3360 if (!findingBehind
3361 && (!wtoken.hidden && wtoken.hiddenRequested)) {
3362 continue;
3363 }
3364
3365 if (!haveGroup) {
3366 // We ignore any hidden applications on the top.
3367 if (wtoken.hiddenRequested || wtoken.willBeHidden) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003368 continue;
3369 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003370 haveGroup = true;
3371 curGroup = wtoken.groupId;
3372 lastOrientation = wtoken.requestedOrientation;
3373 } else if (curGroup != wtoken.groupId) {
3374 // If we have hit a new application group, and the bottom
3375 // of the previous group didn't explicitly say to use
3376 // the orientation behind it, and the last app was
3377 // full screen, then we'll stick with the
3378 // user's orientation.
3379 if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
3380 && lastFullscreen) {
3381 return lastOrientation;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003382 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003384 int or = wtoken.requestedOrientation;
3385 // If this application is fullscreen, and didn't explicitly say
3386 // to use the orientation behind it, then just take whatever
3387 // orientation it has and ignores whatever is under it.
3388 lastFullscreen = wtoken.appFullscreen;
3389 if (lastFullscreen
3390 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
3391 return or;
3392 }
3393 // If this application has requested an explicit orientation,
3394 // then use it.
Dianne Hackborne5439f22010-10-02 16:53:50 -07003395 if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
3396 && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003397 return or;
3398 }
3399 findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
3400 }
3401 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 }
Romain Guy06882f82009-06-10 13:36:04 -07003403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003404 public Configuration updateOrientationFromAppTokens(
The Android Open Source Project10592532009-03-18 17:39:46 -07003405 Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003406 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3407 "updateOrientationFromAppTokens()")) {
3408 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3409 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003410
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003411 Configuration config = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 long ident = Binder.clearCallingIdentity();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003413
3414 synchronized(mWindowMap) {
3415 if (updateOrientationFromAppTokensLocked()) {
3416 if (freezeThisOneIfNeeded != null) {
3417 AppWindowToken wtoken = findAppWindowToken(
3418 freezeThisOneIfNeeded);
3419 if (wtoken != null) {
3420 startAppFreezingScreenLocked(wtoken,
3421 ActivityInfo.CONFIG_ORIENTATION);
3422 }
3423 }
3424 config = computeNewConfigurationLocked();
3425
3426 } else if (currentConfig != null) {
3427 // No obvious action we need to take, but if our current
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003428 // state mismatches the activity manager's, update it,
3429 // disregarding font scale, which should remain set to
3430 // the value of the previous configuration.
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003431 mTempConfiguration.setToDefaults();
Casey Burkhardt0920ba52010-08-03 12:04:19 -07003432 mTempConfiguration.fontScale = currentConfig.fontScale;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003433 if (computeNewConfigurationLocked(mTempConfiguration)) {
3434 if (currentConfig.diff(mTempConfiguration) != 0) {
3435 mWaitingForConfig = true;
3436 mLayoutNeeded = true;
3437 startFreezingDisplayLocked();
3438 config = new Configuration(mTempConfiguration);
3439 }
3440 }
3441 }
3442 }
3443
Dianne Hackborncfaef692009-06-15 14:24:44 -07003444 Binder.restoreCallingIdentity(ident);
3445 return config;
3446 }
3447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 /*
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003449 * Determine the new desired orientation of the display, returning
3450 * a non-null new Configuration if it has changed from the current
3451 * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
3452 * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
3453 * SCREEN. This will typically be done for you if you call
3454 * sendNewConfiguration().
3455 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456 * The orientation is computed from non-application windows first. If none of
3457 * the non-application windows specify orientation, the orientation is computed from
Romain Guy06882f82009-06-10 13:36:04 -07003458 * application tokens.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003459 * @see android.view.IWindowManager#updateOrientationFromAppTokens(
3460 * android.os.IBinder)
3461 */
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003462 boolean updateOrientationFromAppTokensLocked() {
Christopher Tateb696aee2010-04-02 19:08:30 -07003463 if (mDisplayFrozen) {
3464 // If the display is frozen, some activities may be in the middle
3465 // of restarting, and thus have removed their old window. If the
3466 // window has the flag to hide the lock screen, then the lock screen
3467 // can re-appear and inflict its own orientation on us. Keep the
3468 // orientation stable until this all settles down.
3469 return false;
3470 }
3471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 boolean changed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 long ident = Binder.clearCallingIdentity();
3474 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003475 int req = computeForcedAppOrientationLocked();
Romain Guy06882f82009-06-10 13:36:04 -07003476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003477 if (req != mForcedAppOrientation) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003478 mForcedAppOrientation = req;
3479 //send a message to Policy indicating orientation change to take
3480 //action like disabling/enabling sensors etc.,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003481 mPolicy.setCurrentOrientationLw(req);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003482 if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION,
3483 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) {
3484 changed = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 }
3486 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003487
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003488 return changed;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489 } finally {
3490 Binder.restoreCallingIdentity(ident);
3491 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 }
Romain Guy06882f82009-06-10 13:36:04 -07003493
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003494 int computeForcedAppOrientationLocked() {
3495 int req = getOrientationFromWindowsLocked();
3496 if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
3497 req = getOrientationFromAppTokensLocked();
3498 }
3499 return req;
3500 }
Romain Guy06882f82009-06-10 13:36:04 -07003501
Dianne Hackborne36d6e22010-02-17 19:46:25 -08003502 public void setNewConfiguration(Configuration config) {
3503 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3504 "setNewConfiguration()")) {
3505 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
3506 }
3507
3508 synchronized(mWindowMap) {
3509 mCurConfiguration = new Configuration(config);
3510 mWaitingForConfig = false;
3511 performLayoutAndPlaceSurfacesLocked();
3512 }
3513 }
3514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
3516 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3517 "setAppOrientation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003518 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 }
Romain Guy06882f82009-06-10 13:36:04 -07003520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 synchronized(mWindowMap) {
3522 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3523 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003524 Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003525 return;
3526 }
Romain Guy06882f82009-06-10 13:36:04 -07003527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 wtoken.requestedOrientation = requestedOrientation;
3529 }
3530 }
Romain Guy06882f82009-06-10 13:36:04 -07003531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 public int getAppOrientation(IApplicationToken token) {
3533 synchronized(mWindowMap) {
3534 AppWindowToken wtoken = findAppWindowToken(token.asBinder());
3535 if (wtoken == null) {
3536 return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
3537 }
Romain Guy06882f82009-06-10 13:36:04 -07003538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 return wtoken.requestedOrientation;
3540 }
3541 }
Romain Guy06882f82009-06-10 13:36:04 -07003542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 public void setFocusedApp(IBinder token, boolean moveFocusNow) {
3544 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3545 "setFocusedApp()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003546 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 }
3548
3549 synchronized(mWindowMap) {
3550 boolean changed = false;
3551 if (token == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003552 if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 changed = mFocusedApp != null;
3554 mFocusedApp = null;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003555 if (changed) {
3556 mInputMonitor.setFocusedAppLw(null);
Jeff Brown349703e2010-06-22 01:27:15 -07003557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 } else {
3559 AppWindowToken newFocus = findAppWindowToken(token);
3560 if (newFocus == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003561 Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 return;
3563 }
3564 changed = mFocusedApp != newFocus;
3565 mFocusedApp = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003566 if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003567 if (changed) {
3568 mInputMonitor.setFocusedAppLw(newFocus);
Jeff Brown349703e2010-06-22 01:27:15 -07003569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 }
3571
3572 if (moveFocusNow && changed) {
3573 final long origId = Binder.clearCallingIdentity();
3574 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
3575 Binder.restoreCallingIdentity(origId);
3576 }
3577 }
3578 }
3579
3580 public void prepareAppTransition(int transit) {
3581 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3582 "prepareAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003583 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 }
Romain Guy06882f82009-06-10 13:36:04 -07003585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003587 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 TAG, "Prepare app transition: transit=" + transit
3589 + " mNextAppTransition=" + mNextAppTransition);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003590 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003591 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
3592 || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 mNextAppTransition = transit;
Dianne Hackbornd7cd29d2009-07-01 11:22:45 -07003594 } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN
3595 && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) {
3596 // Opening a new task always supersedes a close for the anim.
3597 mNextAppTransition = transit;
3598 } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN
3599 && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) {
3600 // Opening a new activity always supersedes a close for the anim.
3601 mNextAppTransition = transit;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 }
3603 mAppTransitionReady = false;
3604 mAppTransitionTimeout = false;
3605 mStartingIconInTransition = false;
3606 mSkipAppTransitionAnimation = false;
3607 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
3608 mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT),
3609 5000);
3610 }
3611 }
3612 }
3613
3614 public int getPendingAppTransition() {
3615 return mNextAppTransition;
3616 }
Romain Guy06882f82009-06-10 13:36:04 -07003617
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003618 public void overridePendingAppTransition(String packageName,
3619 int enterAnim, int exitAnim) {
Dianne Hackborn8b571a82009-09-25 16:09:43 -07003620 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003621 mNextAppTransitionPackage = packageName;
3622 mNextAppTransitionEnter = enterAnim;
3623 mNextAppTransitionExit = exitAnim;
3624 }
3625 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 public void executeAppTransition() {
3628 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3629 "executeAppTransition()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003630 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 }
Romain Guy06882f82009-06-10 13:36:04 -07003632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 synchronized(mWindowMap) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003634 if (DEBUG_APP_TRANSITIONS) {
3635 RuntimeException e = new RuntimeException("here");
3636 e.fillInStackTrace();
Joe Onorato8a9b2202010-02-26 18:56:32 -08003637 Slog.w(TAG, "Execute app transition: mNextAppTransition="
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07003638 + mNextAppTransition, e);
3639 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003640 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 mAppTransitionReady = true;
3642 final long origId = Binder.clearCallingIdentity();
3643 performLayoutAndPlaceSurfacesLocked();
3644 Binder.restoreCallingIdentity(origId);
3645 }
3646 }
3647 }
3648
3649 public void setAppStartingWindow(IBinder token, String pkg,
3650 int theme, CharSequence nonLocalizedLabel, int labelRes, int icon,
3651 IBinder transferFrom, boolean createIfNeeded) {
3652 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3653 "setAppStartingIcon()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003654 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 }
3656
3657 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003658 if (DEBUG_STARTING_WINDOW) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659 TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg
3660 + " transferFrom=" + transferFrom);
Romain Guy06882f82009-06-10 13:36:04 -07003661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 AppWindowToken wtoken = findAppWindowToken(token);
3663 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003664 Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 return;
3666 }
3667
3668 // If the display is frozen, we won't do anything until the
3669 // actual window is displayed so there is no reason to put in
3670 // the starting window.
Dianne Hackbornde2606d2009-12-18 16:53:55 -08003671 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 return;
3673 }
Romain Guy06882f82009-06-10 13:36:04 -07003674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675 if (wtoken.startingData != null) {
3676 return;
3677 }
Romain Guy06882f82009-06-10 13:36:04 -07003678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 if (transferFrom != null) {
3680 AppWindowToken ttoken = findAppWindowToken(transferFrom);
3681 if (ttoken != null) {
3682 WindowState startingWindow = ttoken.startingWindow;
3683 if (startingWindow != null) {
3684 if (mStartingIconInTransition) {
3685 // In this case, the starting icon has already
3686 // been displayed, so start letting windows get
3687 // shown immediately without any more transitions.
3688 mSkipAppTransitionAnimation = true;
3689 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003690 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691 "Moving existing starting from " + ttoken
3692 + " to " + wtoken);
3693 final long origId = Binder.clearCallingIdentity();
Romain Guy06882f82009-06-10 13:36:04 -07003694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 // Transfer the starting window over to the new
3696 // token.
3697 wtoken.startingData = ttoken.startingData;
3698 wtoken.startingView = ttoken.startingView;
3699 wtoken.startingWindow = startingWindow;
3700 ttoken.startingData = null;
3701 ttoken.startingView = null;
3702 ttoken.startingWindow = null;
3703 ttoken.startingMoved = true;
3704 startingWindow.mToken = wtoken;
Dianne Hackbornef49c572009-03-24 19:27:32 -07003705 startingWindow.mRootToken = wtoken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 startingWindow.mAppToken = wtoken;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003707 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07003708 "Removing starting window: " + startingWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 mWindows.remove(startingWindow);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07003710 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 ttoken.windows.remove(startingWindow);
3712 ttoken.allAppWindows.remove(startingWindow);
3713 addWindowToListInOrderLocked(startingWindow, true);
Romain Guy06882f82009-06-10 13:36:04 -07003714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 // Propagate other interesting state between the
3716 // tokens. If the old token is displayed, we should
3717 // immediately force the new one to be displayed. If
3718 // it is animating, we need to move that animation to
3719 // the new one.
3720 if (ttoken.allDrawn) {
3721 wtoken.allDrawn = true;
3722 }
3723 if (ttoken.firstWindowDrawn) {
3724 wtoken.firstWindowDrawn = true;
3725 }
3726 if (!ttoken.hidden) {
3727 wtoken.hidden = false;
3728 wtoken.hiddenRequested = false;
3729 wtoken.willBeHidden = false;
3730 }
3731 if (wtoken.clientHidden != ttoken.clientHidden) {
3732 wtoken.clientHidden = ttoken.clientHidden;
3733 wtoken.sendAppVisibilityToClients();
3734 }
3735 if (ttoken.animation != null) {
3736 wtoken.animation = ttoken.animation;
3737 wtoken.animating = ttoken.animating;
3738 wtoken.animLayerAdjustment = ttoken.animLayerAdjustment;
3739 ttoken.animation = null;
3740 ttoken.animLayerAdjustment = 0;
3741 wtoken.updateLayers();
3742 ttoken.updateLayers();
3743 }
Romain Guy06882f82009-06-10 13:36:04 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 mLayoutNeeded = true;
3747 performLayoutAndPlaceSurfacesLocked();
3748 Binder.restoreCallingIdentity(origId);
3749 return;
3750 } else if (ttoken.startingData != null) {
3751 // The previous app was getting ready to show a
3752 // starting window, but hasn't yet done so. Steal it!
Joe Onorato8a9b2202010-02-26 18:56:32 -08003753 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 "Moving pending starting from " + ttoken
3755 + " to " + wtoken);
3756 wtoken.startingData = ttoken.startingData;
3757 ttoken.startingData = null;
3758 ttoken.startingMoved = true;
3759 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3760 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3761 // want to process the message ASAP, before any other queued
3762 // messages.
3763 mH.sendMessageAtFrontOfQueue(m);
3764 return;
3765 }
3766 }
3767 }
3768
3769 // There is no existing starting window, and the caller doesn't
3770 // want us to create one, so that's it!
3771 if (!createIfNeeded) {
3772 return;
3773 }
Romain Guy06882f82009-06-10 13:36:04 -07003774
Dianne Hackborn284ac932009-08-28 10:34:25 -07003775 // If this is a translucent or wallpaper window, then don't
3776 // show a starting window -- the current effect (a full-screen
3777 // opaque starting window that fades away to the real contents
3778 // when it is ready) does not work for this.
3779 if (theme != 0) {
3780 AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
3781 com.android.internal.R.styleable.Window);
3782 if (ent.array.getBoolean(
3783 com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
3784 return;
3785 }
3786 if (ent.array.getBoolean(
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07003787 com.android.internal.R.styleable.Window_windowIsFloating, false)) {
3788 return;
3789 }
3790 if (ent.array.getBoolean(
Dianne Hackborn284ac932009-08-28 10:34:25 -07003791 com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
3792 return;
3793 }
3794 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 mStartingIconInTransition = true;
3797 wtoken.startingData = new StartingData(
3798 pkg, theme, nonLocalizedLabel,
3799 labelRes, icon);
3800 Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
3801 // Note: we really want to do sendMessageAtFrontOfQueue() because we
3802 // want to process the message ASAP, before any other queued
3803 // messages.
3804 mH.sendMessageAtFrontOfQueue(m);
3805 }
3806 }
3807
3808 public void setAppWillBeHidden(IBinder token) {
3809 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3810 "setAppWillBeHidden()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003811 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 }
3813
3814 AppWindowToken wtoken;
3815
3816 synchronized(mWindowMap) {
3817 wtoken = findAppWindowToken(token);
3818 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003819 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 -08003820 return;
3821 }
3822 wtoken.willBeHidden = true;
3823 }
3824 }
Romain Guy06882f82009-06-10 13:36:04 -07003825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
3827 boolean visible, int transit, boolean performLayout) {
3828 boolean delayed = false;
3829
3830 if (wtoken.clientHidden == visible) {
3831 wtoken.clientHidden = !visible;
3832 wtoken.sendAppVisibilityToClients();
3833 }
Romain Guy06882f82009-06-10 13:36:04 -07003834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835 wtoken.willBeHidden = false;
3836 if (wtoken.hidden == visible) {
3837 final int N = wtoken.allAppWindows.size();
3838 boolean changed = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08003839 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
3841 + " performLayout=" + performLayout);
Romain Guy06882f82009-06-10 13:36:04 -07003842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843 boolean runningAppAnimation = false;
Romain Guy06882f82009-06-10 13:36:04 -07003844
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07003845 if (transit != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 if (wtoken.animation == sDummyAnimation) {
3847 wtoken.animation = null;
3848 }
3849 applyAnimationLocked(wtoken, lp, transit, visible);
3850 changed = true;
3851 if (wtoken.animation != null) {
3852 delayed = runningAppAnimation = true;
3853 }
3854 }
Romain Guy06882f82009-06-10 13:36:04 -07003855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 for (int i=0; i<N; i++) {
3857 WindowState win = wtoken.allAppWindows.get(i);
3858 if (win == wtoken.startingWindow) {
3859 continue;
3860 }
3861
3862 if (win.isAnimating()) {
3863 delayed = true;
3864 }
Romain Guy06882f82009-06-10 13:36:04 -07003865
Joe Onorato8a9b2202010-02-26 18:56:32 -08003866 //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 //win.dump(" ");
3868 if (visible) {
3869 if (!win.isVisibleNow()) {
3870 if (!runningAppAnimation) {
3871 applyAnimationLocked(win,
3872 WindowManagerPolicy.TRANSIT_ENTER, true);
3873 }
3874 changed = true;
3875 }
3876 } else if (win.isVisibleNow()) {
3877 if (!runningAppAnimation) {
3878 applyAnimationLocked(win,
3879 WindowManagerPolicy.TRANSIT_EXIT, false);
3880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003881 changed = true;
3882 }
3883 }
3884
3885 wtoken.hidden = wtoken.hiddenRequested = !visible;
3886 if (!visible) {
3887 unsetAppFreezingScreenLocked(wtoken, true, true);
3888 } else {
3889 // If we are being set visible, and the starting window is
3890 // not yet displayed, then make sure it doesn't get displayed.
3891 WindowState swin = wtoken.startingWindow;
3892 if (swin != null && (swin.mDrawPending
3893 || swin.mCommitDrawPending)) {
3894 swin.mPolicyVisibility = false;
3895 swin.mPolicyVisibilityAfterAnim = false;
3896 }
3897 }
Romain Guy06882f82009-06-10 13:36:04 -07003898
Joe Onorato8a9b2202010-02-26 18:56:32 -08003899 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003900 + ": hidden=" + wtoken.hidden + " hiddenRequested="
3901 + wtoken.hiddenRequested);
Romain Guy06882f82009-06-10 13:36:04 -07003902
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003903 if (changed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 mLayoutNeeded = true;
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003905 if (performLayout) {
3906 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
3907 performLayoutAndPlaceSurfacesLocked();
Jeff Browne33348b2010-07-15 23:54:05 -07003908 } else {
3909 mInputMonitor.updateInputWindowsLw();
Dianne Hackborn9b52a212009-12-11 14:51:35 -08003910 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911 }
3912 }
3913
3914 if (wtoken.animation != null) {
3915 delayed = true;
3916 }
Romain Guy06882f82009-06-10 13:36:04 -07003917
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003918 return delayed;
3919 }
3920
3921 public void setAppVisibility(IBinder token, boolean visible) {
3922 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
3923 "setAppVisibility()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07003924 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 }
3926
3927 AppWindowToken wtoken;
3928
3929 synchronized(mWindowMap) {
3930 wtoken = findAppWindowToken(token);
3931 if (wtoken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003932 Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003933 return;
3934 }
3935
3936 if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08003937 RuntimeException e = null;
3938 if (!HIDE_STACK_CRAWLS) {
3939 e = new RuntimeException();
3940 e.fillInStackTrace();
3941 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08003942 Slog.v(TAG, "setAppVisibility(" + token + ", " + visible
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 + "): mNextAppTransition=" + mNextAppTransition
3944 + " hidden=" + wtoken.hidden
3945 + " hiddenRequested=" + wtoken.hiddenRequested, e);
3946 }
Romain Guy06882f82009-06-10 13:36:04 -07003947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 // If we are preparing an app transition, then delay changing
3949 // the visibility of this token until we execute that transition.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08003950 if (!mDisplayFrozen && mPolicy.isScreenOn()
3951 && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 // Already in requested state, don't do anything more.
3953 if (wtoken.hiddenRequested != visible) {
3954 return;
3955 }
3956 wtoken.hiddenRequested = !visible;
Romain Guy06882f82009-06-10 13:36:04 -07003957
Joe Onorato8a9b2202010-02-26 18:56:32 -08003958 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959 TAG, "Setting dummy animation on: " + wtoken);
3960 wtoken.setDummyAnimation();
3961 mOpeningApps.remove(wtoken);
3962 mClosingApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07003963 wtoken.waitingToShow = wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003964 wtoken.inPendingTransaction = true;
3965 if (visible) {
3966 mOpeningApps.add(wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 wtoken.startingDisplayed = false;
3968 wtoken.startingMoved = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003969
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003970 // If the token is currently hidden (should be the
3971 // common case), then we need to set up to wait for
3972 // its windows to be ready.
3973 if (wtoken.hidden) {
3974 wtoken.allDrawn = false;
3975 wtoken.waitingToShow = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003976
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003977 if (wtoken.clientHidden) {
3978 // In the case where we are making an app visible
3979 // but holding off for a transition, we still need
3980 // to tell the client to make its windows visible so
3981 // they get drawn. Otherwise, we will wait on
3982 // performing the transition until all windows have
3983 // been drawn, they never will be, and we are sad.
3984 wtoken.clientHidden = false;
3985 wtoken.sendAppVisibilityToClients();
3986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 }
3988 } else {
3989 mClosingApps.add(wtoken);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003990
Dianne Hackborn195f6a02009-11-24 11:26:00 -08003991 // If the token is currently visible (should be the
3992 // common case), then set up to wait for it to be hidden.
3993 if (!wtoken.hidden) {
3994 wtoken.waitingToHide = true;
3995 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003996 }
3997 return;
3998 }
Romain Guy06882f82009-06-10 13:36:04 -07003999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 final long origId = Binder.clearCallingIdentity();
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004001 setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 wtoken.updateReportedVisibilityLocked();
4003 Binder.restoreCallingIdentity(origId);
4004 }
4005 }
4006
4007 void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
4008 boolean unfreezeSurfaceNow, boolean force) {
4009 if (wtoken.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004010 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004011 + " force=" + force);
4012 final int N = wtoken.allAppWindows.size();
4013 boolean unfrozeWindows = false;
4014 for (int i=0; i<N; i++) {
4015 WindowState w = wtoken.allAppWindows.get(i);
4016 if (w.mAppFreezing) {
4017 w.mAppFreezing = false;
4018 if (w.mSurface != null && !w.mOrientationChanging) {
4019 w.mOrientationChanging = true;
4020 }
4021 unfrozeWindows = true;
4022 }
4023 }
4024 if (force || unfrozeWindows) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004025 if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004026 wtoken.freezingScreen = false;
4027 mAppsFreezingScreen--;
4028 }
4029 if (unfreezeSurfaceNow) {
4030 if (unfrozeWindows) {
4031 mLayoutNeeded = true;
4032 performLayoutAndPlaceSurfacesLocked();
4033 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004034 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 }
4036 }
4037 }
Romain Guy06882f82009-06-10 13:36:04 -07004038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039 public void startAppFreezingScreenLocked(AppWindowToken wtoken,
4040 int configChanges) {
4041 if (DEBUG_ORIENTATION) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08004042 RuntimeException e = null;
4043 if (!HIDE_STACK_CRAWLS) {
4044 e = new RuntimeException();
4045 e.fillInStackTrace();
4046 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004047 Slog.i(TAG, "Set freezing of " + wtoken.appToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 + ": hidden=" + wtoken.hidden + " freezing="
4049 + wtoken.freezingScreen, e);
4050 }
4051 if (!wtoken.hiddenRequested) {
4052 if (!wtoken.freezingScreen) {
4053 wtoken.freezingScreen = true;
4054 mAppsFreezingScreen++;
4055 if (mAppsFreezingScreen == 1) {
4056 startFreezingDisplayLocked();
4057 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
4058 mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT),
4059 5000);
4060 }
4061 }
4062 final int N = wtoken.allAppWindows.size();
4063 for (int i=0; i<N; i++) {
4064 WindowState w = wtoken.allAppWindows.get(i);
4065 w.mAppFreezing = true;
4066 }
4067 }
4068 }
Romain Guy06882f82009-06-10 13:36:04 -07004069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004070 public void startAppFreezingScreen(IBinder token, int configChanges) {
4071 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4072 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004073 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004074 }
4075
4076 synchronized(mWindowMap) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08004077 if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004078 if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004079 return;
4080 }
Romain Guy06882f82009-06-10 13:36:04 -07004081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 AppWindowToken wtoken = findAppWindowToken(token);
4083 if (wtoken == null || wtoken.appToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004084 Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004085 return;
4086 }
4087 final long origId = Binder.clearCallingIdentity();
4088 startAppFreezingScreenLocked(wtoken, configChanges);
4089 Binder.restoreCallingIdentity(origId);
4090 }
4091 }
Romain Guy06882f82009-06-10 13:36:04 -07004092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 public void stopAppFreezingScreen(IBinder token, boolean force) {
4094 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4095 "setAppFreezingScreen()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004096 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 }
4098
4099 synchronized(mWindowMap) {
4100 AppWindowToken wtoken = findAppWindowToken(token);
4101 if (wtoken == null || wtoken.appToken == null) {
4102 return;
4103 }
4104 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004105 if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004106 + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen);
4107 unsetAppFreezingScreenLocked(wtoken, true, force);
4108 Binder.restoreCallingIdentity(origId);
4109 }
4110 }
Romain Guy06882f82009-06-10 13:36:04 -07004111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 public void removeAppToken(IBinder token) {
4113 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4114 "removeAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004115 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 }
4117
4118 AppWindowToken wtoken = null;
4119 AppWindowToken startingToken = null;
4120 boolean delayed = false;
4121
4122 final long origId = Binder.clearCallingIdentity();
4123 synchronized(mWindowMap) {
4124 WindowToken basewtoken = mTokenMap.remove(token);
4125 mTokenList.remove(basewtoken);
4126 if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004127 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004128 delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 wtoken.inPendingTransaction = false;
4130 mOpeningApps.remove(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004131 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004132 if (mClosingApps.contains(wtoken)) {
4133 delayed = true;
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004134 } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 mClosingApps.add(wtoken);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004136 wtoken.waitingToHide = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004137 delayed = true;
4138 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004139 if (DEBUG_APP_TRANSITIONS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 TAG, "Removing app " + wtoken + " delayed=" + delayed
4141 + " animation=" + wtoken.animation
4142 + " animating=" + wtoken.animating);
4143 if (delayed) {
4144 // set the token aside because it has an active animation to be finished
4145 mExitingAppTokens.add(wtoken);
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07004146 } else {
4147 // Make sure there is no animation running on this token,
4148 // so any windows associated with it will be removed as
4149 // soon as their animations are complete
4150 wtoken.animation = null;
4151 wtoken.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004152 }
4153 mAppTokens.remove(wtoken);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07004154 if (mLastEnterAnimToken == wtoken) {
4155 mLastEnterAnimToken = null;
4156 mLastEnterAnimParams = null;
4157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 wtoken.removed = true;
4159 if (wtoken.startingData != null) {
4160 startingToken = wtoken;
4161 }
4162 unsetAppFreezingScreenLocked(wtoken, true, true);
4163 if (mFocusedApp == wtoken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004164 if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004165 mFocusedApp = null;
4166 updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004167 mInputMonitor.setFocusedAppLw(null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 }
4169 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004170 Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004171 }
Romain Guy06882f82009-06-10 13:36:04 -07004172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 if (!delayed && wtoken != null) {
4174 wtoken.updateReportedVisibilityLocked();
4175 }
4176 }
4177 Binder.restoreCallingIdentity(origId);
4178
4179 if (startingToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004180 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 + startingToken + ": app token removed");
4182 Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken);
4183 mH.sendMessage(m);
4184 }
4185 }
4186
4187 private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
4188 final int NW = token.windows.size();
4189 for (int i=0; i<NW; i++) {
4190 WindowState win = token.windows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004191 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 mWindows.remove(win);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004193 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004194 int j = win.mChildWindows.size();
4195 while (j > 0) {
4196 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004197 WindowState cwin = win.mChildWindows.get(j);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004198 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004199 "Tmp removing child window " + cwin);
4200 mWindows.remove(cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 }
4202 }
4203 return NW > 0;
4204 }
4205
4206 void dumpAppTokensLocked() {
4207 for (int i=mAppTokens.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004208 Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004209 }
4210 }
Romain Guy06882f82009-06-10 13:36:04 -07004211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004212 void dumpWindowsLocked() {
4213 for (int i=mWindows.size()-1; i>=0; i--) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004214 Slog.v(TAG, " #" + i + ": " + mWindows.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004215 }
4216 }
Romain Guy06882f82009-06-10 13:36:04 -07004217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004218 private int findWindowOffsetLocked(int tokenPos) {
4219 final int NW = mWindows.size();
4220
4221 if (tokenPos >= mAppTokens.size()) {
4222 int i = NW;
4223 while (i > 0) {
4224 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07004225 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004226 if (win.getAppToken() != null) {
4227 return i+1;
4228 }
4229 }
4230 }
4231
4232 while (tokenPos > 0) {
4233 // Find the first app token below the new position that has
4234 // a window displayed.
4235 final AppWindowToken wtoken = mAppTokens.get(tokenPos-1);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004236 if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004237 + tokenPos + " -- " + wtoken.token);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004238 if (wtoken.sendingToBottom) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004239 if (DEBUG_REORDER) Slog.v(TAG,
Dianne Hackborna8f60182009-09-01 19:01:50 -07004240 "Skipping token -- currently sending to bottom");
4241 tokenPos--;
4242 continue;
4243 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004244 int i = wtoken.windows.size();
4245 while (i > 0) {
4246 i--;
4247 WindowState win = wtoken.windows.get(i);
4248 int j = win.mChildWindows.size();
4249 while (j > 0) {
4250 j--;
Jeff Browne33348b2010-07-15 23:54:05 -07004251 WindowState cwin = win.mChildWindows.get(j);
Dianne Hackborna8f60182009-09-01 19:01:50 -07004252 if (cwin.mSubLayer >= 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004253 for (int pos=NW-1; pos>=0; pos--) {
4254 if (mWindows.get(pos) == cwin) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004255 if (DEBUG_REORDER) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256 "Found child win @" + (pos+1));
4257 return pos+1;
4258 }
4259 }
4260 }
4261 }
4262 for (int pos=NW-1; pos>=0; pos--) {
4263 if (mWindows.get(pos) == win) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004264 if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004265 return pos+1;
4266 }
4267 }
4268 }
4269 tokenPos--;
4270 }
4271
4272 return 0;
4273 }
4274
4275 private final int reAddWindowLocked(int index, WindowState win) {
4276 final int NCW = win.mChildWindows.size();
4277 boolean added = false;
4278 for (int j=0; j<NCW; j++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004279 WindowState cwin = win.mChildWindows.get(j);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004280 if (!added && cwin.mSubLayer >= 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004281 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004282 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004283 mWindows.add(index, win);
4284 index++;
4285 added = true;
4286 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004287 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004288 + index + ": " + cwin);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004289 mWindows.add(index, cwin);
4290 index++;
4291 }
4292 if (!added) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004293 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07004294 + index + ": " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004295 mWindows.add(index, win);
4296 index++;
4297 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07004298 mWindowsChanged = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 return index;
4300 }
Romain Guy06882f82009-06-10 13:36:04 -07004301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004302 private final int reAddAppWindowsLocked(int index, WindowToken token) {
4303 final int NW = token.windows.size();
4304 for (int i=0; i<NW; i++) {
4305 index = reAddWindowLocked(index, token.windows.get(i));
4306 }
4307 return index;
4308 }
4309
4310 public void moveAppToken(int index, IBinder token) {
4311 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4312 "moveAppToken()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004313 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004314 }
4315
4316 synchronized(mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004317 if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004318 if (DEBUG_REORDER) dumpAppTokensLocked();
4319 final AppWindowToken wtoken = findAppWindowToken(token);
4320 if (wtoken == null || !mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004321 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004322 + token + " (" + wtoken + ")");
4323 return;
4324 }
4325 mAppTokens.add(index, wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004326 if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 if (DEBUG_REORDER) dumpAppTokensLocked();
Romain Guy06882f82009-06-10 13:36:04 -07004328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329 final long origId = Binder.clearCallingIdentity();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004330 if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 if (DEBUG_REORDER) dumpWindowsLocked();
4332 if (tmpRemoveAppWindowsLocked(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004333 if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 if (DEBUG_REORDER) dumpWindowsLocked();
4335 reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004336 if (DEBUG_REORDER) Slog.v(TAG, "Final window list:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 if (DEBUG_REORDER) dumpWindowsLocked();
4338 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 mLayoutNeeded = true;
4340 performLayoutAndPlaceSurfacesLocked();
4341 }
4342 Binder.restoreCallingIdentity(origId);
4343 }
4344 }
4345
4346 private void removeAppTokensLocked(List<IBinder> tokens) {
4347 // XXX This should be done more efficiently!
4348 // (take advantage of the fact that both lists should be
4349 // ordered in the same way.)
4350 int N = tokens.size();
4351 for (int i=0; i<N; i++) {
4352 IBinder token = tokens.get(i);
4353 final AppWindowToken wtoken = findAppWindowToken(token);
4354 if (!mAppTokens.remove(wtoken)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004355 Slog.w(TAG, "Attempting to reorder token that doesn't exist: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004356 + token + " (" + wtoken + ")");
4357 i--;
4358 N--;
4359 }
4360 }
4361 }
4362
Dianne Hackborna8f60182009-09-01 19:01:50 -07004363 private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos,
4364 boolean updateFocusAndLayout) {
4365 // First remove all of the windows from the list.
4366 tmpRemoveAppWindowsLocked(wtoken);
4367
4368 // Where to start adding?
4369 int pos = findWindowOffsetLocked(tokenPos);
4370
4371 // And now add them back at the correct place.
4372 pos = reAddAppWindowsLocked(pos, wtoken);
4373
4374 if (updateFocusAndLayout) {
4375 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4376 assignLayersLocked();
4377 }
4378 mLayoutNeeded = true;
4379 performLayoutAndPlaceSurfacesLocked();
4380 }
4381 }
4382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004383 private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) {
4384 // First remove all of the windows from the list.
4385 final int N = tokens.size();
4386 int i;
4387 for (i=0; i<N; i++) {
4388 WindowToken token = mTokenMap.get(tokens.get(i));
4389 if (token != null) {
4390 tmpRemoveAppWindowsLocked(token);
4391 }
4392 }
4393
4394 // Where to start adding?
4395 int pos = findWindowOffsetLocked(tokenPos);
4396
4397 // And now add them back at the correct place.
4398 for (i=0; i<N; i++) {
4399 WindowToken token = mTokenMap.get(tokens.get(i));
4400 if (token != null) {
4401 pos = reAddAppWindowsLocked(pos, token);
4402 }
4403 }
4404
Dianne Hackborna8f60182009-09-01 19:01:50 -07004405 if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
4406 assignLayersLocked();
4407 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 mLayoutNeeded = true;
4409 performLayoutAndPlaceSurfacesLocked();
4410
4411 //dump();
4412 }
4413
4414 public void moveAppTokensToTop(List<IBinder> tokens) {
4415 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4416 "moveAppTokensToTop()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004417 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004418 }
4419
4420 final long origId = Binder.clearCallingIdentity();
4421 synchronized(mWindowMap) {
4422 removeAppTokensLocked(tokens);
4423 final int N = tokens.size();
4424 for (int i=0; i<N; i++) {
4425 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4426 if (wt != null) {
4427 mAppTokens.add(wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004428 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004429 mToTopApps.remove(wt);
4430 mToBottomApps.remove(wt);
4431 mToTopApps.add(wt);
4432 wt.sendingToBottom = false;
4433 wt.sendingToTop = true;
4434 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 }
4436 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004437
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004438 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004439 moveAppWindowsLocked(tokens, mAppTokens.size());
4440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441 }
4442 Binder.restoreCallingIdentity(origId);
4443 }
4444
4445 public void moveAppTokensToBottom(List<IBinder> tokens) {
4446 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
4447 "moveAppTokensToBottom()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004448 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004449 }
4450
4451 final long origId = Binder.clearCallingIdentity();
4452 synchronized(mWindowMap) {
4453 removeAppTokensLocked(tokens);
4454 final int N = tokens.size();
4455 int pos = 0;
4456 for (int i=0; i<N; i++) {
4457 AppWindowToken wt = findAppWindowToken(tokens.get(i));
4458 if (wt != null) {
4459 mAppTokens.add(pos, wt);
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004460 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004461 mToTopApps.remove(wt);
4462 mToBottomApps.remove(wt);
4463 mToBottomApps.add(i, wt);
4464 wt.sendingToTop = false;
4465 wt.sendingToBottom = true;
4466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004467 pos++;
4468 }
4469 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004470
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07004471 if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07004472 moveAppWindowsLocked(tokens, 0);
4473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 }
4475 Binder.restoreCallingIdentity(origId);
4476 }
4477
4478 // -------------------------------------------------------------
4479 // Misc IWindowSession methods
4480 // -------------------------------------------------------------
Romain Guy06882f82009-06-10 13:36:04 -07004481
Jim Miller284b62e2010-06-08 14:27:42 -07004482 private boolean shouldAllowDisableKeyguard()
Jim Millerd6b57052010-06-07 17:52:42 -07004483 {
Jim Miller284b62e2010-06-08 14:27:42 -07004484 // We fail safe and prevent disabling keyguard in the unlikely event this gets
4485 // called before DevicePolicyManagerService has started.
4486 if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) {
4487 DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
4488 Context.DEVICE_POLICY_SERVICE);
4489 if (dpm != null) {
4490 mAllowDisableKeyguard = dpm.getPasswordQuality(null)
4491 == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ?
4492 ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
4493 }
Jim Millerd6b57052010-06-07 17:52:42 -07004494 }
Jim Miller284b62e2010-06-08 14:27:42 -07004495 return mAllowDisableKeyguard == ALLOW_DISABLE_YES;
Jim Millerd6b57052010-06-07 17:52:42 -07004496 }
4497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004498 public void disableKeyguard(IBinder token, String tag) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004499 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004500 != PackageManager.PERMISSION_GRANTED) {
4501 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4502 }
Jim Millerd6b57052010-06-07 17:52:42 -07004503
Jim Miller284b62e2010-06-08 14:27:42 -07004504 synchronized (mKeyguardTokenWatcher) {
4505 mKeyguardTokenWatcher.acquire(token, tag);
Mike Lockwooddd884682009-10-11 16:57:08 -04004506 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 }
4508
4509 public void reenableKeyguard(IBinder token) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004510 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 != PackageManager.PERMISSION_GRANTED) {
4512 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4513 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514
Jim Miller284b62e2010-06-08 14:27:42 -07004515 synchronized (mKeyguardTokenWatcher) {
4516 mKeyguardTokenWatcher.release(token);
Jim Millerd6b57052010-06-07 17:52:42 -07004517
Jim Miller284b62e2010-06-08 14:27:42 -07004518 if (!mKeyguardTokenWatcher.isAcquired()) {
4519 // If we are the last one to reenable the keyguard wait until
4520 // we have actually finished reenabling until returning.
4521 // It is possible that reenableKeyguard() can be called before
4522 // the previous disableKeyguard() is handled, in which case
4523 // neither mKeyguardTokenWatcher.acquired() or released() would
4524 // be called. In that case mKeyguardDisabled will be false here
4525 // and we have nothing to wait for.
4526 while (mKeyguardDisabled) {
4527 try {
4528 mKeyguardTokenWatcher.wait();
4529 } catch (InterruptedException e) {
4530 Thread.currentThread().interrupt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531 }
4532 }
4533 }
4534 }
4535 }
4536
4537 /**
4538 * @see android.app.KeyguardManager#exitKeyguardSecurely
4539 */
4540 public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
Mike Lockwood733fdf32009-09-28 19:08:53 -04004541 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 != PackageManager.PERMISSION_GRANTED) {
4543 throw new SecurityException("Requires DISABLE_KEYGUARD permission");
4544 }
4545 mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
4546 public void onKeyguardExitResult(boolean success) {
4547 try {
4548 callback.onKeyguardExitResult(success);
4549 } catch (RemoteException e) {
4550 // Client has died, we don't care.
4551 }
4552 }
4553 });
4554 }
4555
4556 public boolean inKeyguardRestrictedInputMode() {
4557 return mPolicy.inKeyguardRestrictedKeyInputMode();
4558 }
Romain Guy06882f82009-06-10 13:36:04 -07004559
Dianne Hackbornffa42482009-09-23 22:20:11 -07004560 public void closeSystemDialogs(String reason) {
4561 synchronized(mWindowMap) {
4562 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004563 WindowState w = mWindows.get(i);
Dianne Hackbornffa42482009-09-23 22:20:11 -07004564 if (w.mSurface != null) {
4565 try {
4566 w.mClient.closeSystemDialogs(reason);
4567 } catch (RemoteException e) {
4568 }
4569 }
4570 }
4571 }
4572 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004573
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004574 static float fixScale(float scale) {
4575 if (scale < 0) scale = 0;
4576 else if (scale > 20) scale = 20;
4577 return Math.abs(scale);
4578 }
Romain Guy06882f82009-06-10 13:36:04 -07004579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580 public void setAnimationScale(int which, float scale) {
4581 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4582 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004583 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004584 }
4585
4586 if (scale < 0) scale = 0;
4587 else if (scale > 20) scale = 20;
4588 scale = Math.abs(scale);
4589 switch (which) {
4590 case 0: mWindowAnimationScale = fixScale(scale); break;
4591 case 1: mTransitionAnimationScale = fixScale(scale); break;
4592 }
Romain Guy06882f82009-06-10 13:36:04 -07004593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004594 // Persist setting
4595 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4596 }
Romain Guy06882f82009-06-10 13:36:04 -07004597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004598 public void setAnimationScales(float[] scales) {
4599 if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
4600 "setAnimationScale()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004601 throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004602 }
4603
4604 if (scales != null) {
4605 if (scales.length >= 1) {
4606 mWindowAnimationScale = fixScale(scales[0]);
4607 }
4608 if (scales.length >= 2) {
4609 mTransitionAnimationScale = fixScale(scales[1]);
4610 }
4611 }
Romain Guy06882f82009-06-10 13:36:04 -07004612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 // Persist setting
4614 mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget();
4615 }
Romain Guy06882f82009-06-10 13:36:04 -07004616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004617 public float getAnimationScale(int which) {
4618 switch (which) {
4619 case 0: return mWindowAnimationScale;
4620 case 1: return mTransitionAnimationScale;
4621 }
4622 return 0;
4623 }
Romain Guy06882f82009-06-10 13:36:04 -07004624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004625 public float[] getAnimationScales() {
4626 return new float[] { mWindowAnimationScale, mTransitionAnimationScale };
4627 }
Romain Guy06882f82009-06-10 13:36:04 -07004628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004629 public int getSwitchState(int sw) {
4630 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4631 "getSwitchState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004632 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004634 return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004635 }
Romain Guy06882f82009-06-10 13:36:04 -07004636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004637 public int getSwitchStateForDevice(int devid, int sw) {
4638 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4639 "getSwitchStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004640 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004642 return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004643 }
Romain Guy06882f82009-06-10 13:36:04 -07004644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645 public int getScancodeState(int sw) {
4646 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4647 "getScancodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004648 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004649 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004650 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004651 }
Romain Guy06882f82009-06-10 13:36:04 -07004652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 public int getScancodeStateForDevice(int devid, int sw) {
4654 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4655 "getScancodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004656 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004657 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004658 return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 }
Romain Guy06882f82009-06-10 13:36:04 -07004660
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004661 public int getTrackballScancodeState(int sw) {
4662 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4663 "getTrackballScancodeState()")) {
4664 throw new SecurityException("Requires READ_INPUT_STATE permission");
4665 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004666 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004667 }
4668
4669 public int getDPadScancodeState(int sw) {
4670 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4671 "getDPadScancodeState()")) {
4672 throw new SecurityException("Requires READ_INPUT_STATE permission");
4673 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004674 return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004675 }
4676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004677 public int getKeycodeState(int sw) {
4678 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4679 "getKeycodeState()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004680 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004681 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004682 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683 }
Romain Guy06882f82009-06-10 13:36:04 -07004684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004685 public int getKeycodeStateForDevice(int devid, int sw) {
4686 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4687 "getKeycodeStateForDevice()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004688 throw new SecurityException("Requires READ_INPUT_STATE permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004689 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004690 return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004691 }
Romain Guy06882f82009-06-10 13:36:04 -07004692
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004693 public int getTrackballKeycodeState(int sw) {
4694 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4695 "getTrackballKeycodeState()")) {
4696 throw new SecurityException("Requires READ_INPUT_STATE permission");
4697 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004698 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004699 }
4700
4701 public int getDPadKeycodeState(int sw) {
4702 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4703 "getDPadKeycodeState()")) {
4704 throw new SecurityException("Requires READ_INPUT_STATE permission");
4705 }
Jeff Brown6d0fec22010-07-23 21:28:06 -07004706 return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw);
Dianne Hackborn1d62ea92009-11-17 12:49:50 -08004707 }
Jeff Browna41ca772010-08-11 14:46:32 -07004708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004709 public boolean hasKeys(int[] keycodes, boolean[] keyExists) {
Jeff Brown6d0fec22010-07-23 21:28:06 -07004710 return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004711 }
Romain Guy06882f82009-06-10 13:36:04 -07004712
Jeff Browna41ca772010-08-11 14:46:32 -07004713 public InputChannel monitorInput(String inputChannelName) {
4714 if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
4715 "monitorInput()")) {
4716 throw new SecurityException("Requires READ_INPUT_STATE permission");
4717 }
4718 return mInputManager.monitorInput(inputChannelName);
4719 }
4720
Jeff Brown8d608662010-08-30 03:02:23 -07004721 public InputDevice getInputDevice(int deviceId) {
4722 return mInputManager.getInputDevice(deviceId);
4723 }
4724
4725 public int[] getInputDeviceIds() {
4726 return mInputManager.getInputDeviceIds();
4727 }
4728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004729 public void enableScreenAfterBoot() {
4730 synchronized(mWindowMap) {
4731 if (mSystemBooted) {
4732 return;
4733 }
4734 mSystemBooted = true;
4735 }
Romain Guy06882f82009-06-10 13:36:04 -07004736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004737 performEnableScreen();
4738 }
Romain Guy06882f82009-06-10 13:36:04 -07004739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004740 public void enableScreenIfNeededLocked() {
4741 if (mDisplayEnabled) {
4742 return;
4743 }
4744 if (!mSystemBooted) {
4745 return;
4746 }
4747 mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
4748 }
Romain Guy06882f82009-06-10 13:36:04 -07004749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004750 public void performEnableScreen() {
4751 synchronized(mWindowMap) {
4752 if (mDisplayEnabled) {
4753 return;
4754 }
4755 if (!mSystemBooted) {
4756 return;
4757 }
Romain Guy06882f82009-06-10 13:36:04 -07004758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004759 // Don't enable the screen until all existing windows
4760 // have been drawn.
4761 final int N = mWindows.size();
4762 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07004763 WindowState w = mWindows.get(i);
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08004764 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004765 return;
4766 }
4767 }
Romain Guy06882f82009-06-10 13:36:04 -07004768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004769 mDisplayEnabled = true;
4770 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004771 Slog.i(TAG, "ENABLING SCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004772 StringWriter sw = new StringWriter();
4773 PrintWriter pw = new PrintWriter(sw);
4774 this.dump(null, pw, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004775 Slog.i(TAG, sw.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 }
4777 try {
4778 IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
4779 if (surfaceFlinger != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004780 //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004781 Parcel data = Parcel.obtain();
4782 data.writeInterfaceToken("android.ui.ISurfaceComposer");
4783 surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION,
4784 data, null, 0);
4785 data.recycle();
4786 }
4787 } catch (RemoteException ex) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004788 Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004789 }
4790 }
Romain Guy06882f82009-06-10 13:36:04 -07004791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 mPolicy.enableScreenAfterBoot();
Romain Guy06882f82009-06-10 13:36:04 -07004793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 // Make sure the last requested orientation has been applied.
Dianne Hackborn321ae682009-03-27 16:16:03 -07004795 setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false,
4796 mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004797 }
Romain Guy06882f82009-06-10 13:36:04 -07004798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004799 public void setInTouchMode(boolean mode) {
4800 synchronized(mWindowMap) {
4801 mInTouchMode = mode;
4802 }
4803 }
4804
Romain Guy06882f82009-06-10 13:36:04 -07004805 public void setRotation(int rotation,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004806 boolean alwaysSendConfiguration, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004808 "setRotation()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07004809 throw new SecurityException("Requires SET_ORIENTATION permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810 }
4811
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004812 setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004813 }
Romain Guy06882f82009-06-10 13:36:04 -07004814
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004815 public void setRotationUnchecked(int rotation,
4816 boolean alwaysSendConfiguration, int animFlags) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004817 if(DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818 "alwaysSendConfiguration set to "+alwaysSendConfiguration);
Romain Guy06882f82009-06-10 13:36:04 -07004819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004820 long origId = Binder.clearCallingIdentity();
4821 boolean changed;
4822 synchronized(mWindowMap) {
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004823 changed = setRotationUncheckedLocked(rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004824 }
Romain Guy06882f82009-06-10 13:36:04 -07004825
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004826 if (changed || alwaysSendConfiguration) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004827 sendNewConfiguration();
4828 }
Romain Guy06882f82009-06-10 13:36:04 -07004829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004830 Binder.restoreCallingIdentity(origId);
4831 }
Romain Guy06882f82009-06-10 13:36:04 -07004832
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004833 /**
4834 * Apply a new rotation to the screen, respecting the requests of
4835 * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply
4836 * re-evaluate the desired rotation.
4837 *
4838 * Returns null if the rotation has been changed. In this case YOU
4839 * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN.
4840 */
Dianne Hackborn1e880db2009-03-27 16:04:08 -07004841 public boolean setRotationUncheckedLocked(int rotation, int animFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 boolean changed;
4843 if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) {
4844 rotation = mRequestedRotation;
4845 } else {
4846 mRequestedRotation = rotation;
Dianne Hackborn321ae682009-03-27 16:16:03 -07004847 mLastRotationFlags = animFlags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08004849 if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004850 rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004851 mRotation, mDisplayEnabled);
Joe Onorato8a9b2202010-02-26 18:56:32 -08004852 if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004853 changed = mDisplayEnabled && mRotation != rotation;
Romain Guy06882f82009-06-10 13:36:04 -07004854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855 if (changed) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004856 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004857 "Rotation changed to " + rotation
4858 + " from " + mRotation
4859 + " (forceApp=" + mForcedAppOrientation
4860 + ", req=" + mRequestedRotation + ")");
4861 mRotation = rotation;
4862 mWindowsFreezingScreen = true;
4863 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
4864 mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT),
4865 2000);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08004866 mWaitingForConfig = true;
4867 mLayoutNeeded = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004868 startFreezingDisplayLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08004869 Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004870 mInputManager.setDisplayOrientation(0, rotation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871 if (mDisplayEnabled) {
Dianne Hackborn321ae682009-03-27 16:16:03 -07004872 Surface.setOrientation(0, rotation, animFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004873 }
4874 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07004875 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876 if (w.mSurface != null) {
4877 w.mOrientationChanging = true;
4878 }
4879 }
4880 for (int i=mRotationWatchers.size()-1; i>=0; i--) {
4881 try {
4882 mRotationWatchers.get(i).onRotationChanged(rotation);
4883 } catch (RemoteException e) {
4884 }
4885 }
4886 } //end if changed
Romain Guy06882f82009-06-10 13:36:04 -07004887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004888 return changed;
4889 }
Romain Guy06882f82009-06-10 13:36:04 -07004890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004891 public int getRotation() {
4892 return mRotation;
4893 }
4894
4895 public int watchRotation(IRotationWatcher watcher) {
4896 final IBinder watcherBinder = watcher.asBinder();
4897 IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
4898 public void binderDied() {
4899 synchronized (mWindowMap) {
4900 for (int i=0; i<mRotationWatchers.size(); i++) {
4901 if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07004902 IRotationWatcher removed = mRotationWatchers.remove(i);
4903 if (removed != null) {
4904 removed.asBinder().unlinkToDeath(this, 0);
4905 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004906 i--;
4907 }
4908 }
4909 }
4910 }
4911 };
Romain Guy06882f82009-06-10 13:36:04 -07004912
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004913 synchronized (mWindowMap) {
4914 try {
4915 watcher.asBinder().linkToDeath(dr, 0);
4916 mRotationWatchers.add(watcher);
4917 } catch (RemoteException e) {
4918 // Client died, no cleanup needed.
4919 }
Romain Guy06882f82009-06-10 13:36:04 -07004920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004921 return mRotation;
4922 }
4923 }
4924
4925 /**
4926 * Starts the view server on the specified port.
4927 *
4928 * @param port The port to listener to.
4929 *
4930 * @return True if the server was successfully started, false otherwise.
4931 *
4932 * @see com.android.server.ViewServer
4933 * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT
4934 */
4935 public boolean startViewServer(int port) {
Romain Guy06882f82009-06-10 13:36:04 -07004936 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004937 return false;
4938 }
4939
4940 if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
4941 return false;
4942 }
4943
4944 if (port < 1024) {
4945 return false;
4946 }
4947
4948 if (mViewServer != null) {
4949 if (!mViewServer.isRunning()) {
4950 try {
4951 return mViewServer.start();
4952 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004953 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004954 }
4955 }
4956 return false;
4957 }
4958
4959 try {
4960 mViewServer = new ViewServer(this, port);
4961 return mViewServer.start();
4962 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08004963 Slog.w(TAG, "View server did not start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004964 }
4965 return false;
4966 }
4967
Romain Guy06882f82009-06-10 13:36:04 -07004968 private boolean isSystemSecure() {
4969 return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
4970 "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
4971 }
4972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004973 /**
4974 * Stops the view server if it exists.
4975 *
4976 * @return True if the server stopped, false if it wasn't started or
4977 * couldn't be stopped.
4978 *
4979 * @see com.android.server.ViewServer
4980 */
4981 public boolean stopViewServer() {
Romain Guy06882f82009-06-10 13:36:04 -07004982 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004983 return false;
4984 }
4985
4986 if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
4987 return false;
4988 }
4989
4990 if (mViewServer != null) {
4991 return mViewServer.stop();
4992 }
4993 return false;
4994 }
4995
4996 /**
4997 * Indicates whether the view server is running.
4998 *
4999 * @return True if the server is running, false otherwise.
5000 *
5001 * @see com.android.server.ViewServer
5002 */
5003 public boolean isViewServerRunning() {
Romain Guy06882f82009-06-10 13:36:04 -07005004 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005005 return false;
5006 }
5007
5008 if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
5009 return false;
5010 }
5011
5012 return mViewServer != null && mViewServer.isRunning();
5013 }
5014
5015 /**
5016 * Lists all availble windows in the system. The listing is written in the
5017 * specified Socket's output stream with the following syntax:
5018 * windowHashCodeInHexadecimal windowName
5019 * Each line of the ouput represents a different window.
5020 *
5021 * @param client The remote client to send the listing to.
5022 * @return False if an error occured, true otherwise.
5023 */
5024 boolean viewServerListWindows(Socket client) {
Romain Guy06882f82009-06-10 13:36:04 -07005025 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005026 return false;
5027 }
5028
5029 boolean result = true;
5030
Jeff Browne33348b2010-07-15 23:54:05 -07005031 WindowState[] windows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 synchronized (mWindowMap) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005033 //noinspection unchecked
Jeff Browne33348b2010-07-15 23:54:05 -07005034 windows = mWindows.toArray(new WindowState[mWindows.size()]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 }
5036
5037 BufferedWriter out = null;
5038
5039 // Any uncaught exception will crash the system process
5040 try {
5041 OutputStream clientStream = client.getOutputStream();
5042 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5043
5044 final int count = windows.length;
5045 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005046 final WindowState w = windows[i];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005047 out.write(Integer.toHexString(System.identityHashCode(w)));
5048 out.write(' ');
5049 out.append(w.mAttrs.getTitle());
5050 out.write('\n');
5051 }
5052
5053 out.write("DONE.\n");
5054 out.flush();
5055 } catch (Exception e) {
5056 result = false;
5057 } finally {
5058 if (out != null) {
5059 try {
5060 out.close();
5061 } catch (IOException e) {
5062 result = false;
5063 }
5064 }
5065 }
5066
5067 return result;
5068 }
5069
5070 /**
Konstantin Lopyrevf9624762010-07-14 17:02:37 -07005071 * Returns the focused window in the following format:
5072 * windowHashCodeInHexadecimal windowName
5073 *
5074 * @param client The remote client to send the listing to.
5075 * @return False if an error occurred, true otherwise.
5076 */
5077 boolean viewServerGetFocusedWindow(Socket client) {
5078 if (isSystemSecure()) {
5079 return false;
5080 }
5081
5082 boolean result = true;
5083
5084 WindowState focusedWindow = getFocusedWindow();
5085
5086 BufferedWriter out = null;
5087
5088 // Any uncaught exception will crash the system process
5089 try {
5090 OutputStream clientStream = client.getOutputStream();
5091 out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
5092
5093 if(focusedWindow != null) {
5094 out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
5095 out.write(' ');
5096 out.append(focusedWindow.mAttrs.getTitle());
5097 }
5098 out.write('\n');
5099 out.flush();
5100 } catch (Exception e) {
5101 result = false;
5102 } finally {
5103 if (out != null) {
5104 try {
5105 out.close();
5106 } catch (IOException e) {
5107 result = false;
5108 }
5109 }
5110 }
5111
5112 return result;
5113 }
5114
5115 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005116 * Sends a command to a target window. The result of the command, if any, will be
5117 * written in the output stream of the specified socket.
5118 *
5119 * The parameters must follow this syntax:
5120 * windowHashcode extra
5121 *
5122 * Where XX is the length in characeters of the windowTitle.
5123 *
5124 * The first parameter is the target window. The window with the specified hashcode
5125 * will be the target. If no target can be found, nothing happens. The extra parameters
5126 * will be delivered to the target window and as parameters to the command itself.
5127 *
5128 * @param client The remote client to sent the result, if any, to.
5129 * @param command The command to execute.
5130 * @param parameters The command parameters.
5131 *
5132 * @return True if the command was successfully delivered, false otherwise. This does
5133 * not indicate whether the command itself was successful.
5134 */
5135 boolean viewServerWindowCommand(Socket client, String command, String parameters) {
Romain Guy06882f82009-06-10 13:36:04 -07005136 if (isSystemSecure()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005137 return false;
5138 }
5139
5140 boolean success = true;
5141 Parcel data = null;
5142 Parcel reply = null;
5143
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005144 BufferedWriter out = null;
5145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005146 // Any uncaught exception will crash the system process
5147 try {
5148 // Find the hashcode of the window
5149 int index = parameters.indexOf(' ');
5150 if (index == -1) {
5151 index = parameters.length();
5152 }
5153 final String code = parameters.substring(0, index);
Romain Guy236092a2009-12-14 15:31:48 -08005154 int hashCode = (int) Long.parseLong(code, 16);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005155
5156 // Extract the command's parameter after the window description
5157 if (index < parameters.length()) {
5158 parameters = parameters.substring(index + 1);
5159 } else {
5160 parameters = "";
5161 }
5162
5163 final WindowManagerService.WindowState window = findWindow(hashCode);
5164 if (window == null) {
5165 return false;
5166 }
5167
5168 data = Parcel.obtain();
5169 data.writeInterfaceToken("android.view.IWindow");
5170 data.writeString(command);
5171 data.writeString(parameters);
5172 data.writeInt(1);
5173 ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
5174
5175 reply = Parcel.obtain();
5176
5177 final IBinder binder = window.mClient.asBinder();
5178 // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
5179 binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
5180
5181 reply.readException();
5182
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005183 if (!client.isOutputShutdown()) {
5184 out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
5185 out.write("DONE\n");
5186 out.flush();
5187 }
5188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08005190 Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005191 success = false;
5192 } finally {
5193 if (data != null) {
5194 data.recycle();
5195 }
5196 if (reply != null) {
5197 reply.recycle();
5198 }
Konstantin Lopyrev43b9b482010-08-24 22:00:12 -07005199 if (out != null) {
5200 try {
5201 out.close();
5202 } catch (IOException e) {
5203
5204 }
5205 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005206 }
5207
5208 return success;
5209 }
5210
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07005211 public void addWindowChangeListener(WindowChangeListener listener) {
5212 synchronized(mWindowMap) {
5213 mWindowChangeListeners.add(listener);
5214 }
5215 }
5216
5217 public void removeWindowChangeListener(WindowChangeListener listener) {
5218 synchronized(mWindowMap) {
5219 mWindowChangeListeners.remove(listener);
5220 }
5221 }
5222
5223 private void notifyWindowsChanged() {
5224 WindowChangeListener[] windowChangeListeners;
5225 synchronized(mWindowMap) {
5226 if(mWindowChangeListeners.isEmpty()) {
5227 return;
5228 }
5229 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5230 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5231 }
5232 int N = windowChangeListeners.length;
5233 for(int i = 0; i < N; i++) {
5234 windowChangeListeners[i].windowsChanged();
5235 }
5236 }
5237
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07005238 private void notifyFocusChanged() {
5239 WindowChangeListener[] windowChangeListeners;
5240 synchronized(mWindowMap) {
5241 if(mWindowChangeListeners.isEmpty()) {
5242 return;
5243 }
5244 windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
5245 windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
5246 }
5247 int N = windowChangeListeners.length;
5248 for(int i = 0; i < N; i++) {
5249 windowChangeListeners[i].focusChanged();
5250 }
5251 }
5252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005253 private WindowState findWindow(int hashCode) {
5254 if (hashCode == -1) {
5255 return getFocusedWindow();
5256 }
5257
5258 synchronized (mWindowMap) {
Jeff Browne33348b2010-07-15 23:54:05 -07005259 final ArrayList<WindowState> windows = mWindows;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005260 final int count = windows.size();
5261
5262 for (int i = 0; i < count; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005263 WindowState w = windows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005264 if (System.identityHashCode(w) == hashCode) {
5265 return w;
5266 }
5267 }
5268 }
5269
5270 return null;
5271 }
5272
5273 /*
5274 * Instruct the Activity Manager to fetch the current configuration and broadcast
5275 * that to config-changed listeners if appropriate.
5276 */
5277 void sendNewConfiguration() {
5278 try {
5279 mActivityManager.updateConfiguration(null);
5280 } catch (RemoteException e) {
5281 }
5282 }
Romain Guy06882f82009-06-10 13:36:04 -07005283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005284 public Configuration computeNewConfiguration() {
5285 synchronized (mWindowMap) {
Dianne Hackbornc485a602009-03-24 22:39:49 -07005286 return computeNewConfigurationLocked();
5287 }
5288 }
Romain Guy06882f82009-06-10 13:36:04 -07005289
Dianne Hackbornc485a602009-03-24 22:39:49 -07005290 Configuration computeNewConfigurationLocked() {
5291 Configuration config = new Configuration();
5292 if (!computeNewConfigurationLocked(config)) {
5293 return null;
5294 }
Dianne Hackbornc485a602009-03-24 22:39:49 -07005295 return config;
5296 }
Romain Guy06882f82009-06-10 13:36:04 -07005297
Dianne Hackbornc485a602009-03-24 22:39:49 -07005298 boolean computeNewConfigurationLocked(Configuration config) {
5299 if (mDisplay == null) {
5300 return false;
5301 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005302
5303 mInputManager.getInputConfiguration(config);
Christopher Tateb696aee2010-04-02 19:08:30 -07005304
5305 // Use the effective "visual" dimensions based on current rotation
5306 final boolean rotated = (mRotation == Surface.ROTATION_90
5307 || mRotation == Surface.ROTATION_270);
5308 final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
5309 final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
5310
Dianne Hackbornc485a602009-03-24 22:39:49 -07005311 int orientation = Configuration.ORIENTATION_SQUARE;
5312 if (dw < dh) {
5313 orientation = Configuration.ORIENTATION_PORTRAIT;
5314 } else if (dw > dh) {
5315 orientation = Configuration.ORIENTATION_LANDSCAPE;
5316 }
5317 config.orientation = orientation;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005318
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005319 DisplayMetrics dm = new DisplayMetrics();
5320 mDisplay.getMetrics(dm);
5321 CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
5322
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005323 if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07005324 // Note we only do this once because at this point we don't
5325 // expect the screen to change in this way at runtime, and want
5326 // to avoid all of this computation for every config change.
Dianne Hackborn723738c2009-06-25 19:48:04 -07005327 int longSize = dw;
5328 int shortSize = dh;
5329 if (longSize < shortSize) {
5330 int tmp = longSize;
5331 longSize = shortSize;
5332 shortSize = tmp;
5333 }
5334 longSize = (int)(longSize/dm.density);
5335 shortSize = (int)(shortSize/dm.density);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07005336
Dianne Hackborn723738c2009-06-25 19:48:04 -07005337 // These semi-magic numbers define our compatibility modes for
5338 // applications with different screens. Don't change unless you
5339 // make sure to test lots and lots of apps!
5340 if (longSize < 470) {
5341 // This is shorter than an HVGA normal density screen (which
5342 // is 480 pixels on its long side).
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005343 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
5344 | Configuration.SCREENLAYOUT_LONG_NO;
Dianne Hackborn723738c2009-06-25 19:48:04 -07005345 } else {
Dianne Hackborn14cee9f2010-04-23 17:51:26 -07005346 // What size is this screen screen?
5347 if (longSize >= 800 && shortSize >= 600) {
5348 // SVGA or larger screens at medium density are the point
5349 // at which we consider it to be an extra large screen.
5350 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
5351 } else if (longSize >= 640 && shortSize >= 480) {
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005352 // VGA or larger screens at medium density are the point
5353 // at which we consider it to be a large screen.
5354 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
5355 } else {
5356 mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005357
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005358 // If this screen is wider than normal HVGA, or taller
5359 // than FWVGA, then for old apps we want to run in size
5360 // compatibility mode.
5361 if (shortSize > 321 || longSize > 570) {
5362 mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
5363 }
5364 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005365
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005366 // Is this a long screen?
5367 if (((longSize*3)/5) >= (shortSize-1)) {
5368 // Anything wider than WVGA (5:3) is considering to be long.
5369 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
5370 } else {
5371 mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
5372 }
Dianne Hackborn723738c2009-06-25 19:48:04 -07005373 }
5374 }
Dianne Hackbornc4db95c2009-07-21 17:46:02 -07005375 config.screenLayout = mScreenLayout;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08005376
Dianne Hackbornc485a602009-03-24 22:39:49 -07005377 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
5378 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
5379 mPolicy.adjustConfigurationLw(config);
5380 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005381 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005382
5383 // -------------------------------------------------------------
5384 // Drag and drop
5385 // -------------------------------------------------------------
5386
5387 IBinder prepareDragSurface(IWindow window, SurfaceSession session,
5388 boolean localOnly, int width, int height, Surface outSurface) {
5389 if (DEBUG_DRAG) {
5390 Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
5391 + " local=" + localOnly + " win=" + window
5392 + " asbinder=" + window.asBinder());
5393 }
5394
5395 final int callerPid = Binder.getCallingPid();
5396 final long origId = Binder.clearCallingIdentity();
5397 IBinder token = null;
5398
5399 try {
5400 synchronized (mWindowMap) {
5401 try {
5402 // !!! TODO: fail if the given window does not currently have touch focus?
5403
5404 if (mDragState == null) {
5405 Surface surface = new Surface(session, callerPid, "drag surface", 0,
5406 width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
5407 outSurface.copyFrom(surface);
5408 token = new Binder();
5409 mDragState = new DragState(token, surface, localOnly);
5410 mDragState.mSurface = surface;
5411 mDragState.mLocalOnly = localOnly;
5412 token = mDragState.mToken = new Binder();
5413
5414 // 5 second timeout for this window to actually begin the drag
5415 mH.removeMessages(H.DRAG_START_TIMEOUT, window);
5416 Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder());
5417 mH.sendMessageDelayed(msg, 5000);
5418 } else {
5419 Slog.w(TAG, "Drag already in progress");
5420 }
5421 } catch (Surface.OutOfResourcesException e) {
5422 Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
5423 if (mDragState != null) {
5424 mDragState.reset();
5425 mDragState = null;
5426 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005427 }
5428 }
5429 } finally {
5430 Binder.restoreCallingIdentity(origId);
5431 }
5432
5433 return token;
5434 }
5435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 // -------------------------------------------------------------
5437 // Input Events and Focus Management
5438 // -------------------------------------------------------------
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005439
Jeff Brown349703e2010-06-22 01:27:15 -07005440 InputMonitor mInputMonitor = new InputMonitor();
5441
5442 /* Tracks the progress of input dispatch and ensures that input dispatch state
5443 * is kept in sync with changes in window focus, visibility, registration, and
5444 * other relevant Window Manager state transitions. */
5445 final class InputMonitor {
5446 // Current window with input focus for keys and other non-touch events. May be null.
5447 private WindowState mInputFocus;
5448
5449 // When true, prevents input dispatch from proceeding until set to false again.
5450 private boolean mInputDispatchFrozen;
5451
5452 // When true, input dispatch proceeds normally. Otherwise all events are dropped.
5453 private boolean mInputDispatchEnabled = true;
5454
5455 // Temporary list of windows information to provide to the input dispatcher.
5456 private InputWindowList mTempInputWindows = new InputWindowList();
5457
5458 // Temporary input application object to provide to the input dispatcher.
5459 private InputApplication mTempInputApplication = new InputApplication();
5460
5461 /* Notifies the window manager about a broken input channel.
5462 *
5463 * Called by the InputManager.
5464 */
5465 public void notifyInputChannelBroken(InputChannel inputChannel) {
5466 synchronized (mWindowMap) {
5467 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5468 if (windowState == null) {
5469 return; // irrelevant
5470 }
5471
5472 Slog.i(TAG, "WINDOW DIED " + windowState);
5473 removeWindowLocked(windowState.mSession, windowState);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005474 }
5475 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005476
Jeff Brown519e0242010-09-15 15:18:56 -07005477 /* Notifies the window manager about an application that is not responding.
Jeff Brownb88102f2010-09-08 11:49:43 -07005478 * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
Jeff Brown349703e2010-06-22 01:27:15 -07005479 *
5480 * Called by the InputManager.
5481 */
Jeff Brown519e0242010-09-15 15:18:56 -07005482 public long notifyANR(Object token, InputChannel inputChannel) {
5483 AppWindowToken appWindowToken = null;
5484 if (inputChannel != null) {
5485 synchronized (mWindowMap) {
5486 WindowState windowState = getWindowStateForInputChannelLocked(inputChannel);
5487 if (windowState != null) {
5488 Slog.i(TAG, "Input event dispatching timed out sending to "
5489 + windowState.mAttrs.getTitle());
5490 appWindowToken = windowState.mAppToken;
5491 }
Jeff Brown349703e2010-06-22 01:27:15 -07005492 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005493 }
5494
Jeff Brown519e0242010-09-15 15:18:56 -07005495 if (appWindowToken == null && token != null) {
5496 appWindowToken = (AppWindowToken) token;
5497 Slog.i(TAG, "Input event dispatching timed out sending to application "
5498 + appWindowToken.stringName);
5499 }
Jeff Brown349703e2010-06-22 01:27:15 -07005500
Jeff Brown519e0242010-09-15 15:18:56 -07005501 if (appWindowToken != null && appWindowToken.appToken != null) {
Jeff Brown349703e2010-06-22 01:27:15 -07005502 try {
5503 // Notify the activity manager about the timeout and let it decide whether
5504 // to abort dispatching or keep waiting.
Jeff Brown519e0242010-09-15 15:18:56 -07005505 boolean abort = appWindowToken.appToken.keyDispatchingTimedOut();
Jeff Brown349703e2010-06-22 01:27:15 -07005506 if (! abort) {
5507 // The activity manager declined to abort dispatching.
5508 // Wait a bit longer and timeout again later.
Jeff Brown519e0242010-09-15 15:18:56 -07005509 return appWindowToken.inputDispatchingTimeoutNanos;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005510 }
Jeff Brown349703e2010-06-22 01:27:15 -07005511 } catch (RemoteException ex) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07005512 }
5513 }
Jeff Brownb88102f2010-09-08 11:49:43 -07005514 return 0; // abort dispatching
Jeff Brown7fbdc842010-06-17 20:52:56 -07005515 }
5516
Jeff Brown349703e2010-06-22 01:27:15 -07005517 private WindowState getWindowStateForInputChannel(InputChannel inputChannel) {
5518 synchronized (mWindowMap) {
5519 return getWindowStateForInputChannelLocked(inputChannel);
5520 }
5521 }
5522
5523 private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) {
5524 int windowCount = mWindows.size();
5525 for (int i = 0; i < windowCount; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07005526 WindowState windowState = mWindows.get(i);
Jeff Brown349703e2010-06-22 01:27:15 -07005527 if (windowState.mInputChannel == inputChannel) {
5528 return windowState;
5529 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005530 }
5531
Jeff Brown349703e2010-06-22 01:27:15 -07005532 return null;
Jeff Brown7fbdc842010-06-17 20:52:56 -07005533 }
Christopher Tatea53146c2010-09-07 11:57:52 -07005534
5535 private void addDragInputWindow(InputWindowList windowList) {
5536 final InputWindow inputWindow = windowList.add();
5537 inputWindow.inputChannel = mDragState.mServerChannel;
5538 inputWindow.name = "drag";
5539 inputWindow.layoutParamsFlags = 0;
5540 inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG;
5541 inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
5542 inputWindow.visible = true;
5543 inputWindow.canReceiveKeys = false;
5544 inputWindow.hasFocus = true;
5545 inputWindow.hasWallpaper = false;
5546 inputWindow.paused = false;
5547 inputWindow.layer = mPolicy.windowTypeToLayerLw(inputWindow.layoutParamsType)
5548 * TYPE_LAYER_MULTIPLIER
5549 + TYPE_LAYER_OFFSET;
5550 inputWindow.ownerPid = Process.myPid();
5551 inputWindow.ownerUid = Process.myUid();
5552
5553 // The drag window covers the entire display
5554 inputWindow.frameLeft = 0;
5555 inputWindow.frameTop = 0;
5556 inputWindow.frameRight = mDisplay.getWidth();
5557 inputWindow.frameBottom = mDisplay.getHeight();
Christopher Tate2c095f32010-10-04 14:13:40 -07005558
Christopher Tatea53146c2010-09-07 11:57:52 -07005559 inputWindow.visibleFrameLeft = inputWindow.frameLeft;
5560 inputWindow.visibleFrameTop = inputWindow.frameTop;
5561 inputWindow.visibleFrameRight = inputWindow.frameRight;
5562 inputWindow.visibleFrameBottom = inputWindow.frameBottom;
5563
5564 inputWindow.touchableAreaLeft = inputWindow.frameLeft;
5565 inputWindow.touchableAreaTop = inputWindow.frameTop;
5566 inputWindow.touchableAreaRight = inputWindow.frameRight;
5567 inputWindow.touchableAreaBottom = inputWindow.frameBottom;
5568 }
5569
Jeff Brown349703e2010-06-22 01:27:15 -07005570 /* Updates the cached window information provided to the input dispatcher. */
5571 public void updateInputWindowsLw() {
5572 // Populate the input window list with information about all of the windows that
5573 // could potentially receive input.
5574 // As an optimization, we could try to prune the list of windows but this turns
5575 // out to be difficult because only the native code knows for sure which window
5576 // currently has touch focus.
Jeff Browne33348b2010-07-15 23:54:05 -07005577 final ArrayList<WindowState> windows = mWindows;
Christopher Tatea53146c2010-09-07 11:57:52 -07005578
5579 // If there's a drag in flight, provide a pseudowindow to catch drag input
5580 final boolean inDrag = (mDragState != null);
5581 if (inDrag) {
5582 if (DEBUG_DRAG) {
5583 Log.d(TAG, "Inserting drag window");
5584 }
5585 addDragInputWindow(mTempInputWindows);
5586 }
5587
Jeff Brown7fbdc842010-06-17 20:52:56 -07005588 final int N = windows.size();
Jeff Brown349703e2010-06-22 01:27:15 -07005589 for (int i = N - 1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07005590 final WindowState child = windows.get(i);
Jeff Brownc5ed5912010-07-14 18:48:53 -07005591 if (child.mInputChannel == null || child.mRemoved) {
Jeff Brown349703e2010-06-22 01:27:15 -07005592 // Skip this window because it cannot possibly receive input.
Jeff Brown7fbdc842010-06-17 20:52:56 -07005593 continue;
5594 }
5595
Jeff Brown349703e2010-06-22 01:27:15 -07005596 final int flags = child.mAttrs.flags;
5597 final int type = child.mAttrs.type;
5598
5599 final boolean hasFocus = (child == mInputFocus);
5600 final boolean isVisible = child.isVisibleLw();
5601 final boolean hasWallpaper = (child == mWallpaperTarget)
5602 && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
Christopher Tatea53146c2010-09-07 11:57:52 -07005603
5604 // If there's a drag in progress and 'child' is a potential drop target,
5605 // make sure it's been told about the drag
5606 if (inDrag && isVisible) {
5607 mDragState.sendDragStartedIfNeededLw(child);
5608 }
5609
Jeff Brown349703e2010-06-22 01:27:15 -07005610 // Add a window to our list of input windows.
5611 final InputWindow inputWindow = mTempInputWindows.add();
5612 inputWindow.inputChannel = child.mInputChannel;
Jeff Brown519e0242010-09-15 15:18:56 -07005613 inputWindow.name = child.toString();
Jeff Brown349703e2010-06-22 01:27:15 -07005614 inputWindow.layoutParamsFlags = flags;
5615 inputWindow.layoutParamsType = type;
5616 inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
5617 inputWindow.visible = isVisible;
Jeff Brown519e0242010-09-15 15:18:56 -07005618 inputWindow.canReceiveKeys = child.canReceiveKeys();
Jeff Brown349703e2010-06-22 01:27:15 -07005619 inputWindow.hasFocus = hasFocus;
5620 inputWindow.hasWallpaper = hasWallpaper;
5621 inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false;
Jeff Brown519e0242010-09-15 15:18:56 -07005622 inputWindow.layer = child.mLayer;
Jeff Brown349703e2010-06-22 01:27:15 -07005623 inputWindow.ownerPid = child.mSession.mPid;
5624 inputWindow.ownerUid = child.mSession.mUid;
5625
5626 final Rect frame = child.mFrame;
5627 inputWindow.frameLeft = frame.left;
5628 inputWindow.frameTop = frame.top;
Jeff Brown85a31762010-09-01 17:01:00 -07005629 inputWindow.frameRight = frame.right;
5630 inputWindow.frameBottom = frame.bottom;
5631
5632 final Rect visibleFrame = child.mVisibleFrame;
5633 inputWindow.visibleFrameLeft = visibleFrame.left;
5634 inputWindow.visibleFrameTop = visibleFrame.top;
5635 inputWindow.visibleFrameRight = visibleFrame.right;
5636 inputWindow.visibleFrameBottom = visibleFrame.bottom;
Jeff Brown349703e2010-06-22 01:27:15 -07005637
5638 switch (child.mTouchableInsets) {
5639 default:
5640 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
5641 inputWindow.touchableAreaLeft = frame.left;
5642 inputWindow.touchableAreaTop = frame.top;
5643 inputWindow.touchableAreaRight = frame.right;
5644 inputWindow.touchableAreaBottom = frame.bottom;
5645 break;
5646
5647 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: {
5648 Rect inset = child.mGivenContentInsets;
5649 inputWindow.touchableAreaLeft = frame.left + inset.left;
5650 inputWindow.touchableAreaTop = frame.top + inset.top;
5651 inputWindow.touchableAreaRight = frame.right - inset.right;
5652 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
5653 break;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005654 }
Jeff Brown349703e2010-06-22 01:27:15 -07005655
5656 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: {
5657 Rect inset = child.mGivenVisibleInsets;
5658 inputWindow.touchableAreaLeft = frame.left + inset.left;
5659 inputWindow.touchableAreaTop = frame.top + inset.top;
5660 inputWindow.touchableAreaRight = frame.right - inset.right;
5661 inputWindow.touchableAreaBottom = frame.bottom - inset.bottom;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005662 break;
5663 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005664 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005665 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07005666
Jeff Brown349703e2010-06-22 01:27:15 -07005667 // Send windows to native code.
5668 mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray());
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005669
Jeff Brown349703e2010-06-22 01:27:15 -07005670 // Clear the list in preparation for the next round.
5671 // Also avoids keeping InputChannel objects referenced unnecessarily.
5672 mTempInputWindows.clear();
5673 }
5674
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005675 /* Notifies that the lid switch changed state. */
5676 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5677 mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
5678 }
5679
Jeff Brown349703e2010-06-22 01:27:15 -07005680 /* Provides an opportunity for the window manager policy to intercept early key
5681 * processing as soon as the key has been read from the device. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005682 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
5683 int policyFlags, boolean isScreenOn) {
5684 return mPolicy.interceptKeyBeforeQueueing(whenNanos,
5685 keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -07005686 }
5687
5688 /* Provides an opportunity for the window manager policy to process a key before
5689 * ordinary dispatch. */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005690 public boolean interceptKeyBeforeDispatching(InputChannel focus,
5691 int action, int flags, int keyCode, int metaState, int repeatCount,
5692 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -07005693 WindowState windowState = getWindowStateForInputChannel(focus);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005694 return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags,
5695 keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -07005696 }
5697
5698 /* Called when the current input focus changes.
5699 * Layer assignment is assumed to be complete by the time this is called.
5700 */
5701 public void setInputFocusLw(WindowState newWindow) {
5702 if (DEBUG_INPUT) {
5703 Slog.d(TAG, "Input focus has changed to " + newWindow);
5704 }
5705
5706 if (newWindow != mInputFocus) {
5707 if (newWindow != null && newWindow.canReceiveKeys()) {
Jeff Brown349703e2010-06-22 01:27:15 -07005708 // Displaying a window implicitly causes dispatching to be unpaused.
5709 // This is to protect against bugs if someone pauses dispatching but
5710 // forgets to resume.
5711 newWindow.mToken.paused = false;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005712 }
Jeff Brown349703e2010-06-22 01:27:15 -07005713
5714 mInputFocus = newWindow;
5715 updateInputWindowsLw();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005716 }
5717 }
5718
Jeff Brown349703e2010-06-22 01:27:15 -07005719 public void setFocusedAppLw(AppWindowToken newApp) {
5720 // Focused app has changed.
5721 if (newApp == null) {
5722 mInputManager.setFocusedApplication(null);
5723 } else {
5724 mTempInputApplication.name = newApp.toString();
5725 mTempInputApplication.dispatchingTimeoutNanos =
5726 newApp.inputDispatchingTimeoutNanos;
5727 mTempInputApplication.token = newApp;
5728
5729 mInputManager.setFocusedApplication(mTempInputApplication);
5730 }
5731 }
5732
Jeff Brown349703e2010-06-22 01:27:15 -07005733 public void pauseDispatchingLw(WindowToken window) {
5734 if (! window.paused) {
5735 if (DEBUG_INPUT) {
5736 Slog.v(TAG, "Pausing WindowToken " + window);
5737 }
5738
5739 window.paused = true;
5740 updateInputWindowsLw();
5741 }
5742 }
5743
5744 public void resumeDispatchingLw(WindowToken window) {
5745 if (window.paused) {
5746 if (DEBUG_INPUT) {
5747 Slog.v(TAG, "Resuming WindowToken " + window);
5748 }
5749
5750 window.paused = false;
5751 updateInputWindowsLw();
5752 }
5753 }
5754
5755 public void freezeInputDispatchingLw() {
5756 if (! mInputDispatchFrozen) {
5757 if (DEBUG_INPUT) {
5758 Slog.v(TAG, "Freezing input dispatching");
5759 }
5760
5761 mInputDispatchFrozen = true;
5762 updateInputDispatchModeLw();
5763 }
5764 }
5765
5766 public void thawInputDispatchingLw() {
5767 if (mInputDispatchFrozen) {
5768 if (DEBUG_INPUT) {
5769 Slog.v(TAG, "Thawing input dispatching");
5770 }
5771
5772 mInputDispatchFrozen = false;
5773 updateInputDispatchModeLw();
5774 }
5775 }
5776
5777 public void setEventDispatchingLw(boolean enabled) {
5778 if (mInputDispatchEnabled != enabled) {
5779 if (DEBUG_INPUT) {
5780 Slog.v(TAG, "Setting event dispatching to " + enabled);
5781 }
5782
5783 mInputDispatchEnabled = enabled;
5784 updateInputDispatchModeLw();
5785 }
5786 }
5787
5788 private void updateInputDispatchModeLw() {
5789 mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
5790 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005793 public void pauseKeyDispatching(IBinder _token) {
5794 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5795 "pauseKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005796 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005797 }
5798
5799 synchronized (mWindowMap) {
5800 WindowToken token = mTokenMap.get(_token);
5801 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005802 mInputMonitor.pauseDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005803 }
5804 }
5805 }
5806
5807 public void resumeKeyDispatching(IBinder _token) {
5808 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5809 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005810 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005811 }
5812
5813 synchronized (mWindowMap) {
5814 WindowToken token = mTokenMap.get(_token);
5815 if (token != null) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005816 mInputMonitor.resumeDispatchingLw(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005817 }
5818 }
5819 }
5820
5821 public void setEventDispatching(boolean enabled) {
5822 if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
5823 "resumeKeyDispatching()")) {
Dianne Hackborncfaef692009-06-15 14:24:44 -07005824 throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005825 }
5826
5827 synchronized (mWindowMap) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005828 mInputMonitor.setEventDispatchingLw(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005829 }
5830 }
Romain Guy06882f82009-06-10 13:36:04 -07005831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005832 /**
5833 * Injects a keystroke event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005834 * Even when sync is false, this method may block while waiting for current
5835 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005836 *
5837 * @param ev A motion event describing the keystroke action. (Be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005838 * {@link SystemClock#uptimeMillis()} as the timebase.)
5839 * @param sync If true, wait for the event to be completed before returning to the caller.
5840 * @return Returns true if event was dispatched, false if it was dropped for any reason
5841 */
5842 public boolean injectKeyEvent(KeyEvent ev, boolean sync) {
5843 long downTime = ev.getDownTime();
5844 long eventTime = ev.getEventTime();
5845
5846 int action = ev.getAction();
5847 int code = ev.getKeyCode();
5848 int repeatCount = ev.getRepeatCount();
5849 int metaState = ev.getMetaState();
5850 int deviceId = ev.getDeviceId();
5851 int scancode = ev.getScanCode();
Jeff Brownc5ed5912010-07-14 18:48:53 -07005852 int source = ev.getSource();
5853
5854 if (source == InputDevice.SOURCE_UNKNOWN) {
5855 source = InputDevice.SOURCE_KEYBOARD;
5856 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005857
5858 if (eventTime == 0) eventTime = SystemClock.uptimeMillis();
5859 if (downTime == 0) downTime = eventTime;
5860
5861 KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
Jeff Brownc5ed5912010-07-14 18:48:53 -07005862 deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005863
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005864 final int pid = Binder.getCallingPid();
5865 final int uid = Binder.getCallingUid();
5866 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005867
Jeff Brownbbda99d2010-07-28 15:48:59 -07005868 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5869 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5870 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5871 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005872
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005873 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005874 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005875 }
5876
5877 /**
5878 * Inject a pointer (touch) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005879 * Even when sync is false, this method may block while waiting for current
5880 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005881 *
5882 * @param ev A motion event describing the pointer (touch) action. (As noted in
5883 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005884 * {@link SystemClock#uptimeMillis()} as the timebase.)
5885 * @param sync If true, wait for the event to be completed before returning to the caller.
5886 * @return Returns true if event was dispatched, false if it was dropped for any reason
5887 */
5888 public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005889 final int pid = Binder.getCallingPid();
5890 final int uid = Binder.getCallingUid();
5891 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005892
Jeff Brownc5ed5912010-07-14 18:48:53 -07005893 MotionEvent newEvent = MotionEvent.obtain(ev);
5894 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
5895 newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN);
5896 }
5897
Jeff Brownbbda99d2010-07-28 15:48:59 -07005898 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5899 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5900 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5901 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005902
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005903 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005904 return reportInjectionResult(result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005905 }
Romain Guy06882f82009-06-10 13:36:04 -07005906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005907 /**
5908 * Inject a trackball (navigation device) event into the UI.
Jeff Brownbbda99d2010-07-28 15:48:59 -07005909 * Even when sync is false, this method may block while waiting for current
5910 * input events to be dispatched.
Romain Guy06882f82009-06-10 13:36:04 -07005911 *
5912 * @param ev A motion event describing the trackball action. (As noted in
5913 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005914 * {@link SystemClock#uptimeMillis()} as the timebase.)
5915 * @param sync If true, wait for the event to be completed before returning to the caller.
5916 * @return Returns true if event was dispatched, false if it was dropped for any reason
5917 */
5918 public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005919 final int pid = Binder.getCallingPid();
5920 final int uid = Binder.getCallingUid();
5921 final long ident = Binder.clearCallingIdentity();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005922
Jeff Brownc5ed5912010-07-14 18:48:53 -07005923 MotionEvent newEvent = MotionEvent.obtain(ev);
5924 if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
5925 newEvent.setSource(InputDevice.SOURCE_TRACKBALL);
5926 }
5927
Jeff Brownbbda99d2010-07-28 15:48:59 -07005928 final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
5929 sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
5930 : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
5931 INJECTION_TIMEOUT_MILLIS);
5932
5933 Binder.restoreCallingIdentity(ident);
5934 return reportInjectionResult(result);
5935 }
5936
5937 /**
5938 * Inject an input event into the UI without waiting for dispatch to commence.
5939 * This variant is useful for fire-and-forget input event injection. It does not
5940 * block any longer than it takes to enqueue the input event.
5941 *
5942 * @param ev An input event. (Be sure to set the input source correctly.)
5943 * @return Returns true if event was dispatched, false if it was dropped for any reason
5944 */
5945 public boolean injectInputEventNoWait(InputEvent ev) {
5946 final int pid = Binder.getCallingPid();
5947 final int uid = Binder.getCallingUid();
5948 final long ident = Binder.clearCallingIdentity();
5949
5950 final int result = mInputManager.injectInputEvent(ev, pid, uid,
5951 InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
5952 INJECTION_TIMEOUT_MILLIS);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07005953
Dianne Hackborn2bd33d72009-06-26 18:59:01 -07005954 Binder.restoreCallingIdentity(ident);
Jeff Brown7fbdc842010-06-17 20:52:56 -07005955 return reportInjectionResult(result);
5956 }
5957
5958 private boolean reportInjectionResult(int result) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005959 switch (result) {
5960 case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
5961 Slog.w(TAG, "Input event injection permission denied.");
5962 throw new SecurityException(
5963 "Injecting to another application requires INJECT_EVENTS permission");
5964 case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
Christopher Tate09e85dc2010-08-02 11:54:41 -07005965 //Slog.v(TAG, "Input event injection succeeded.");
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005966 return true;
5967 case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
5968 Slog.w(TAG, "Input event injection timed out.");
5969 return false;
5970 case InputManager.INPUT_EVENT_INJECTION_FAILED:
5971 default:
5972 Slog.w(TAG, "Input event injection failed.");
5973 return false;
Dianne Hackborncfaef692009-06-15 14:24:44 -07005974 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005975 }
Romain Guy06882f82009-06-10 13:36:04 -07005976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005977 private WindowState getFocusedWindow() {
5978 synchronized (mWindowMap) {
5979 return getFocusedWindowLocked();
5980 }
5981 }
5982
5983 private WindowState getFocusedWindowLocked() {
5984 return mCurrentFocus;
5985 }
Romain Guy06882f82009-06-10 13:36:04 -07005986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005987 public boolean detectSafeMode() {
5988 mSafeMode = mPolicy.detectSafeMode();
5989 return mSafeMode;
5990 }
Romain Guy06882f82009-06-10 13:36:04 -07005991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005992 public void systemReady() {
Dianne Hackborn5132b372010-07-29 12:51:35 -07005993 synchronized(mWindowMap) {
5994 if (mDisplay != null) {
5995 throw new IllegalStateException("Display already initialized");
5996 }
5997 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5998 mDisplay = wm.getDefaultDisplay();
5999 mInitialDisplayWidth = mDisplay.getWidth();
6000 mInitialDisplayHeight = mDisplay.getHeight();
6001 mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight);
6002 }
6003
6004 try {
6005 mActivityManager.updateConfiguration(null);
6006 } catch (RemoteException e) {
6007 }
Dianne Hackborn154db5f2010-07-29 19:15:19 -07006008
6009 mPolicy.systemReady();
Dianne Hackborn5132b372010-07-29 12:51:35 -07006010 }
6011
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006012 // -------------------------------------------------------------
6013 // Client Session State
6014 // -------------------------------------------------------------
6015
6016 private final class Session extends IWindowSession.Stub
6017 implements IBinder.DeathRecipient {
6018 final IInputMethodClient mClient;
6019 final IInputContext mInputContext;
6020 final int mUid;
6021 final int mPid;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006022 final String mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006023 SurfaceSession mSurfaceSession;
6024 int mNumWindow = 0;
6025 boolean mClientDead = false;
Romain Guy06882f82009-06-10 13:36:04 -07006026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006027 public Session(IInputMethodClient client, IInputContext inputContext) {
6028 mClient = client;
6029 mInputContext = inputContext;
6030 mUid = Binder.getCallingUid();
6031 mPid = Binder.getCallingPid();
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006032 StringBuilder sb = new StringBuilder();
6033 sb.append("Session{");
6034 sb.append(Integer.toHexString(System.identityHashCode(this)));
6035 sb.append(" uid ");
6036 sb.append(mUid);
6037 sb.append("}");
6038 mStringName = sb.toString();
Romain Guy06882f82009-06-10 13:36:04 -07006039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006040 synchronized (mWindowMap) {
6041 if (mInputMethodManager == null && mHaveInputMethods) {
6042 IBinder b = ServiceManager.getService(
6043 Context.INPUT_METHOD_SERVICE);
6044 mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
6045 }
6046 }
6047 long ident = Binder.clearCallingIdentity();
6048 try {
6049 // Note: it is safe to call in to the input method manager
6050 // here because we are not holding our lock.
6051 if (mInputMethodManager != null) {
6052 mInputMethodManager.addClient(client, inputContext,
6053 mUid, mPid);
6054 } else {
6055 client.setUsingInputMethod(false);
6056 }
6057 client.asBinder().linkToDeath(this, 0);
6058 } catch (RemoteException e) {
6059 // The caller has died, so we can just forget about this.
6060 try {
6061 if (mInputMethodManager != null) {
6062 mInputMethodManager.removeClient(client);
6063 }
6064 } catch (RemoteException ee) {
6065 }
6066 } finally {
6067 Binder.restoreCallingIdentity(ident);
6068 }
6069 }
Romain Guy06882f82009-06-10 13:36:04 -07006070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071 @Override
6072 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
6073 throws RemoteException {
6074 try {
6075 return super.onTransact(code, data, reply, flags);
6076 } catch (RuntimeException e) {
6077 // Log all 'real' exceptions thrown to the caller
6078 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006079 Slog.e(TAG, "Window Session Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006080 }
6081 throw e;
6082 }
6083 }
6084
6085 public void binderDied() {
6086 // Note: it is safe to call in to the input method manager
6087 // here because we are not holding our lock.
6088 try {
6089 if (mInputMethodManager != null) {
6090 mInputMethodManager.removeClient(mClient);
6091 }
6092 } catch (RemoteException e) {
6093 }
6094 synchronized(mWindowMap) {
Suchi Amalapurapufff2fda2009-06-30 21:36:16 -07006095 mClient.asBinder().unlinkToDeath(this, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006096 mClientDead = true;
6097 killSessionLocked();
6098 }
6099 }
6100
6101 public int add(IWindow window, WindowManager.LayoutParams attrs,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006102 int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
6103 return addWindow(this, window, attrs, viewVisibility, outContentInsets,
6104 outInputChannel);
6105 }
6106
6107 public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006108 int viewVisibility, Rect outContentInsets) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006109 return addWindow(this, window, attrs, viewVisibility, outContentInsets, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006110 }
Romain Guy06882f82009-06-10 13:36:04 -07006111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006112 public void remove(IWindow window) {
6113 removeWindow(this, window);
6114 }
Romain Guy06882f82009-06-10 13:36:04 -07006115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006116 public int relayout(IWindow window, WindowManager.LayoutParams attrs,
6117 int requestedWidth, int requestedHeight, int viewFlags,
6118 boolean insetsPending, Rect outFrame, Rect outContentInsets,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006119 Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
Dianne Hackbornf123e492010-09-24 11:16:23 -07006120 //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid());
6121 int res = relayoutWindow(this, window, attrs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006122 requestedWidth, requestedHeight, viewFlags, insetsPending,
Dianne Hackborn694f79b2010-03-17 19:44:59 -07006123 outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface);
Dianne Hackbornf123e492010-09-24 11:16:23 -07006124 //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid());
6125 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006126 }
Romain Guy06882f82009-06-10 13:36:04 -07006127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006128 public void setTransparentRegion(IWindow window, Region region) {
6129 setTransparentRegionWindow(this, window, region);
6130 }
Romain Guy06882f82009-06-10 13:36:04 -07006131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006132 public void setInsets(IWindow window, int touchableInsets,
6133 Rect contentInsets, Rect visibleInsets) {
6134 setInsetsWindow(this, window, touchableInsets, contentInsets,
6135 visibleInsets);
6136 }
Romain Guy06882f82009-06-10 13:36:04 -07006137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006138 public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
6139 getWindowDisplayFrame(this, window, outDisplayFrame);
6140 }
Romain Guy06882f82009-06-10 13:36:04 -07006141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006142 public void finishDrawing(IWindow window) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006143 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006144 TAG, "IWindow finishDrawing called for " + window);
6145 finishDrawingWindow(this, window);
6146 }
6147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006148 public void setInTouchMode(boolean mode) {
6149 synchronized(mWindowMap) {
6150 mInTouchMode = mode;
6151 }
6152 }
6153
6154 public boolean getInTouchMode() {
6155 synchronized(mWindowMap) {
6156 return mInTouchMode;
6157 }
6158 }
6159
6160 public boolean performHapticFeedback(IWindow window, int effectId,
6161 boolean always) {
6162 synchronized(mWindowMap) {
6163 long ident = Binder.clearCallingIdentity();
6164 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07006165 return mPolicy.performHapticFeedbackLw(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006166 windowForClientLocked(this, window, true),
6167 effectId, always);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006168 } finally {
6169 Binder.restoreCallingIdentity(ident);
6170 }
6171 }
6172 }
Romain Guy06882f82009-06-10 13:36:04 -07006173
Christopher Tatea53146c2010-09-07 11:57:52 -07006174 /* Drag/drop */
6175 public IBinder prepareDrag(IWindow window, boolean localOnly,
6176 int width, int height, Surface outSurface) {
6177 return prepareDragSurface(window, mSurfaceSession, localOnly,
6178 width, height, outSurface);
6179 }
6180
6181 public boolean performDrag(IWindow window, IBinder dragToken,
6182 float touchX, float touchY, float thumbCenterX, float thumbCenterY,
6183 ClipData data) {
6184 if (DEBUG_DRAG) {
6185 Slog.d(TAG, "perform drag: win=" + window + " data=" + data);
6186 }
6187
6188 synchronized (mWindowMap) {
6189 if (mDragState == null) {
6190 Slog.w(TAG, "No drag prepared");
6191 throw new IllegalStateException("performDrag() without prepareDrag()");
6192 }
6193
6194 if (dragToken != mDragState.mToken) {
6195 Slog.w(TAG, "Performing mismatched drag");
6196 throw new IllegalStateException("performDrag() does not match prepareDrag()");
6197 }
6198
6199 WindowState callingWin = windowForClientLocked(null, window, false);
6200 if (callingWin == null) {
6201 Slog.w(TAG, "Bad requesting window " + window);
6202 return false; // !!! TODO: throw here?
6203 }
6204
6205 // !!! TODO: if input is not still focused on the initiating window, fail
6206 // the drag initiation (e.g. an alarm window popped up just as the application
6207 // called performDrag()
6208
6209 mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
6210
Christopher Tate2c095f32010-10-04 14:13:40 -07006211 // !!! TODO: extract the current touch (x, y) in screen coordinates. That
6212 // will let us eliminate the (touchX,touchY) parameters from the API.
Christopher Tatea53146c2010-09-07 11:57:52 -07006213
6214 mDragState.register();
6215 mInputMonitor.updateInputWindowsLw();
6216 mInputManager.transferTouchFocus(callingWin.mInputChannel,
6217 mDragState.mServerChannel);
6218
6219 mDragState.mData = data;
6220 mDragState.broadcastDragStartedLw();
6221
6222 // remember the thumb offsets for later
6223 mDragState.mThumbOffsetX = thumbCenterX;
6224 mDragState.mThumbOffsetY = thumbCenterY;
6225
6226 // Make the surface visible at the proper location
6227 final Surface surface = mDragState.mSurface;
6228 surface.openTransaction();
6229 try {
6230 surface.setPosition((int)(touchX - thumbCenterX),
6231 (int)(touchY - thumbCenterY));
6232 surface.setAlpha(.5f);
6233 surface.show();
6234 } finally {
6235 surface.closeTransaction();
6236 }
6237 }
6238
6239 return true; // success!
6240 }
6241
6242 public void dragRecipientEntered(IWindow window) {
6243 if (DEBUG_DRAG) {
6244 Slog.d(TAG, "Drag into new candidate view @ " + window);
6245 }
6246 }
6247
6248 public void dragRecipientExited(IWindow window) {
6249 if (DEBUG_DRAG) {
6250 Slog.d(TAG, "Drag from old candidate view @ " + window);
6251 }
6252 }
6253
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006254 public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006255 synchronized(mWindowMap) {
6256 long ident = Binder.clearCallingIdentity();
6257 try {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006258 setWindowWallpaperPositionLocked(
6259 windowForClientLocked(this, window, true),
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006260 x, y, xStep, yStep);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006261 } finally {
6262 Binder.restoreCallingIdentity(ident);
6263 }
6264 }
6265 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006266
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006267 public void wallpaperOffsetsComplete(IBinder window) {
6268 WindowManagerService.this.wallpaperOffsetsComplete(window);
6269 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006270
Dianne Hackborn75804932009-10-20 20:15:20 -07006271 public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
6272 int z, Bundle extras, boolean sync) {
6273 synchronized(mWindowMap) {
6274 long ident = Binder.clearCallingIdentity();
6275 try {
6276 return sendWindowWallpaperCommandLocked(
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006277 windowForClientLocked(this, window, true),
Dianne Hackborn75804932009-10-20 20:15:20 -07006278 action, x, y, z, extras, sync);
6279 } finally {
6280 Binder.restoreCallingIdentity(ident);
6281 }
6282 }
6283 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006284
Dianne Hackborn75804932009-10-20 20:15:20 -07006285 public void wallpaperCommandComplete(IBinder window, Bundle result) {
6286 WindowManagerService.this.wallpaperCommandComplete(window, result);
6287 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006289 void windowAddedLocked() {
6290 if (mSurfaceSession == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006291 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006292 TAG, "First window added to " + this + ", creating SurfaceSession");
6293 mSurfaceSession = new SurfaceSession();
Joe Onorato8a9b2202010-02-26 18:56:32 -08006294 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006295 TAG, " NEW SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006296 mSessions.add(this);
6297 }
6298 mNumWindow++;
6299 }
6300
6301 void windowRemovedLocked() {
6302 mNumWindow--;
6303 killSessionLocked();
6304 }
Romain Guy06882f82009-06-10 13:36:04 -07006305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006306 void killSessionLocked() {
6307 if (mNumWindow <= 0 && mClientDead) {
6308 mSessions.remove(this);
6309 if (mSurfaceSession != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006310 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006311 TAG, "Last window removed from " + this
6312 + ", destroying " + mSurfaceSession);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006313 if (SHOW_TRANSACTIONS) Slog.i(
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006314 TAG, " KILL SURFACE SESSION " + mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006315 try {
6316 mSurfaceSession.kill();
6317 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006318 Slog.w(TAG, "Exception thrown when killing surface session "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006319 + mSurfaceSession + " in session " + this
6320 + ": " + e.toString());
6321 }
6322 mSurfaceSession = null;
6323 }
6324 }
6325 }
Romain Guy06882f82009-06-10 13:36:04 -07006326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006327 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006328 pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
6329 pw.print(" mClientDead="); pw.print(mClientDead);
6330 pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006331 }
6332
6333 @Override
6334 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07006335 return mStringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006336 }
6337 }
6338
6339 // -------------------------------------------------------------
6340 // Client Window State
6341 // -------------------------------------------------------------
6342
6343 private final class WindowState implements WindowManagerPolicy.WindowState {
6344 final Session mSession;
6345 final IWindow mClient;
6346 WindowToken mToken;
The Android Open Source Project10592532009-03-18 17:39:46 -07006347 WindowToken mRootToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006348 AppWindowToken mAppToken;
6349 AppWindowToken mTargetAppToken;
6350 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
6351 final DeathRecipient mDeathRecipient;
6352 final WindowState mAttachedWindow;
Jeff Browne33348b2010-07-15 23:54:05 -07006353 final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006354 final int mBaseLayer;
6355 final int mSubLayer;
6356 final boolean mLayoutAttached;
6357 final boolean mIsImWindow;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006358 final boolean mIsWallpaper;
6359 final boolean mIsFloatingLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006360 int mViewVisibility;
6361 boolean mPolicyVisibility = true;
6362 boolean mPolicyVisibilityAfterAnim = true;
6363 boolean mAppFreezing;
6364 Surface mSurface;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006365 boolean mReportDestroySurface;
6366 boolean mSurfacePendingDestroy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006367 boolean mAttachedHidden; // is our parent window hidden?
6368 boolean mLastHidden; // was this window last hidden?
Dianne Hackborn759a39e2009-08-09 17:20:27 -07006369 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006370 int mRequestedWidth;
6371 int mRequestedHeight;
6372 int mLastRequestedWidth;
6373 int mLastRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006374 int mLayer;
6375 int mAnimLayer;
6376 int mLastLayer;
6377 boolean mHaveFrame;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07006378 boolean mObscured;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07006379 boolean mTurnOnScreen;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006380
Dianne Hackborne36d6e22010-02-17 19:46:25 -08006381 int mLayoutSeq = -1;
6382
6383 Configuration mConfiguration = null;
6384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006385 // Actual frame shown on-screen (may be modified by animation)
6386 final Rect mShownFrame = new Rect();
6387 final Rect mLastShownFrame = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006389 /**
Dianne Hackbornac3587d2010-03-11 11:12:11 -08006390 * Set when we have changed the size of the surface, to know that
6391 * we must tell them application to resize (and thus redraw itself).
6392 */
6393 boolean mSurfaceResized;
6394
6395 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006396 * Insets that determine the actually visible area
6397 */
6398 final Rect mVisibleInsets = new Rect();
6399 final Rect mLastVisibleInsets = new Rect();
6400 boolean mVisibleInsetsChanged;
6401
6402 /**
6403 * Insets that are covered by system windows
6404 */
6405 final Rect mContentInsets = new Rect();
6406 final Rect mLastContentInsets = new Rect();
6407 boolean mContentInsetsChanged;
6408
6409 /**
6410 * Set to true if we are waiting for this window to receive its
6411 * given internal insets before laying out other windows based on it.
6412 */
6413 boolean mGivenInsetsPending;
Romain Guy06882f82009-06-10 13:36:04 -07006414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006415 /**
6416 * These are the content insets that were given during layout for
6417 * this window, to be applied to windows behind it.
6418 */
6419 final Rect mGivenContentInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006421 /**
6422 * These are the visible insets that were given during layout for
6423 * this window, to be applied to windows behind it.
6424 */
6425 final Rect mGivenVisibleInsets = new Rect();
Romain Guy06882f82009-06-10 13:36:04 -07006426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006427 /**
6428 * Flag indicating whether the touchable region should be adjusted by
6429 * the visible insets; if false the area outside the visible insets is
6430 * NOT touchable, so we must use those to adjust the frame during hit
6431 * tests.
6432 */
6433 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
Romain Guy06882f82009-06-10 13:36:04 -07006434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006435 // Current transformation being applied.
6436 float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
6437 float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
6438 float mHScale=1, mVScale=1;
6439 float mLastHScale=1, mLastVScale=1;
6440 final Matrix mTmpMatrix = new Matrix();
6441
6442 // "Real" frame that the application sees.
6443 final Rect mFrame = new Rect();
6444 final Rect mLastFrame = new Rect();
6445
6446 final Rect mContainingFrame = new Rect();
6447 final Rect mDisplayFrame = new Rect();
6448 final Rect mContentFrame = new Rect();
6449 final Rect mVisibleFrame = new Rect();
6450
6451 float mShownAlpha = 1;
6452 float mAlpha = 1;
6453 float mLastAlpha = 1;
6454
6455 // Set to true if, when the window gets displayed, it should perform
6456 // an enter animation.
6457 boolean mEnterAnimationPending;
6458
6459 // Currently running animation.
6460 boolean mAnimating;
6461 boolean mLocalAnimating;
6462 Animation mAnimation;
6463 boolean mAnimationIsEntrance;
6464 boolean mHasTransformation;
6465 boolean mHasLocalTransformation;
6466 final Transformation mTransformation = new Transformation();
6467
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006468 // If a window showing a wallpaper: the requested offset for the
6469 // wallpaper; if a wallpaper window: the currently applied offset.
6470 float mWallpaperX = -1;
6471 float mWallpaperY = -1;
Marco Nelissenbf6956b2009-11-09 15:21:13 -08006472
6473 // If a window showing a wallpaper: what fraction of the offset
6474 // range corresponds to a full virtual screen.
6475 float mWallpaperXStep = -1;
6476 float mWallpaperYStep = -1;
6477
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07006478 // Wallpaper windows: pixels offset based on above variables.
6479 int mXOffset;
6480 int mYOffset;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006482 // This is set after IWindowSession.relayout() has been called at
6483 // least once for the window. It allows us to detect the situation
6484 // where we don't yet have a surface, but should have one soon, so
6485 // we can give the window focus before waiting for the relayout.
6486 boolean mRelayoutCalled;
Romain Guy06882f82009-06-10 13:36:04 -07006487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006488 // This is set after the Surface has been created but before the
6489 // window has been drawn. During this time the surface is hidden.
6490 boolean mDrawPending;
6491
6492 // This is set after the window has finished drawing for the first
6493 // time but before its surface is shown. The surface will be
6494 // displayed when the next layout is run.
6495 boolean mCommitDrawPending;
6496
6497 // This is set during the time after the window's drawing has been
6498 // committed, and before its surface is actually shown. It is used
6499 // to delay showing the surface until all windows in a token are ready
6500 // to be shown.
6501 boolean mReadyToShow;
Romain Guy06882f82009-06-10 13:36:04 -07006502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006503 // Set when the window has been shown in the screen the first time.
6504 boolean mHasDrawn;
6505
6506 // Currently running an exit animation?
6507 boolean mExiting;
6508
6509 // Currently on the mDestroySurface list?
6510 boolean mDestroying;
Romain Guy06882f82009-06-10 13:36:04 -07006511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006512 // Completely remove from window manager after exit animation?
6513 boolean mRemoveOnExit;
6514
6515 // Set when the orientation is changing and this window has not yet
6516 // been updated for the new orientation.
6517 boolean mOrientationChanging;
Romain Guy06882f82009-06-10 13:36:04 -07006518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006519 // Is this window now (or just being) removed?
6520 boolean mRemoved;
Romain Guy06882f82009-06-10 13:36:04 -07006521
Dianne Hackborn16064f92010-03-25 00:47:24 -07006522 // For debugging, this is the last information given to the surface flinger.
6523 boolean mSurfaceShown;
6524 int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
6525 int mSurfaceLayer;
6526 float mSurfaceAlpha;
6527
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07006528 // Input channel
6529 InputChannel mInputChannel;
6530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006531 WindowState(Session s, IWindow c, WindowToken token,
6532 WindowState attachedWindow, WindowManager.LayoutParams a,
6533 int viewVisibility) {
6534 mSession = s;
6535 mClient = c;
6536 mToken = token;
6537 mAttrs.copyFrom(a);
6538 mViewVisibility = viewVisibility;
6539 DeathRecipient deathRecipient = new DeathRecipient();
6540 mAlpha = a.alpha;
Joe Onorato8a9b2202010-02-26 18:56:32 -08006541 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006542 TAG, "Window " + this + " client=" + c.asBinder()
6543 + " token=" + token + " (" + mAttrs.token + ")");
6544 try {
6545 c.asBinder().linkToDeath(deathRecipient, 0);
6546 } catch (RemoteException e) {
6547 mDeathRecipient = null;
6548 mAttachedWindow = null;
6549 mLayoutAttached = false;
6550 mIsImWindow = false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006551 mIsWallpaper = false;
6552 mIsFloatingLayer = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006553 mBaseLayer = 0;
6554 mSubLayer = 0;
6555 return;
6556 }
6557 mDeathRecipient = deathRecipient;
Romain Guy06882f82009-06-10 13:36:04 -07006558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006559 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
6560 mAttrs.type <= LAST_SUB_WINDOW)) {
6561 // The multiplier here is to reserve space for multiple
6562 // windows in the same type layer.
6563 mBaseLayer = mPolicy.windowTypeToLayerLw(
6564 attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER
6565 + TYPE_LAYER_OFFSET;
6566 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
6567 mAttachedWindow = attachedWindow;
6568 mAttachedWindow.mChildWindows.add(this);
6569 mLayoutAttached = mAttrs.type !=
6570 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
6571 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
6572 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006573 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
6574 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006575 } else {
6576 // The multiplier here is to reserve space for multiple
6577 // windows in the same type layer.
6578 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
6579 * TYPE_LAYER_MULTIPLIER
6580 + TYPE_LAYER_OFFSET;
6581 mSubLayer = 0;
6582 mAttachedWindow = null;
6583 mLayoutAttached = false;
6584 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
6585 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07006586 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
6587 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006588 }
6589
6590 WindowState appWin = this;
6591 while (appWin.mAttachedWindow != null) {
6592 appWin = mAttachedWindow;
6593 }
6594 WindowToken appToken = appWin.mToken;
6595 while (appToken.appWindowToken == null) {
6596 WindowToken parent = mTokenMap.get(appToken.token);
6597 if (parent == null || appToken == parent) {
6598 break;
6599 }
6600 appToken = parent;
6601 }
The Android Open Source Project10592532009-03-18 17:39:46 -07006602 mRootToken = appToken;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006603 mAppToken = appToken.appWindowToken;
6604
6605 mSurface = null;
6606 mRequestedWidth = 0;
6607 mRequestedHeight = 0;
6608 mLastRequestedWidth = 0;
6609 mLastRequestedHeight = 0;
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07006610 mXOffset = 0;
6611 mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006612 mLayer = 0;
6613 mAnimLayer = 0;
6614 mLastLayer = 0;
6615 }
6616
6617 void attach() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006618 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006619 TAG, "Attaching " + this + " token=" + mToken
6620 + ", list=" + mToken.windows);
6621 mSession.windowAddedLocked();
6622 }
6623
6624 public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
6625 mHaveFrame = true;
6626
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006627 final Rect container = mContainingFrame;
6628 container.set(pf);
6629
6630 final Rect display = mDisplayFrame;
6631 display.set(df);
6632
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07006633 if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) {
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006634 container.intersect(mCompatibleScreenFrame);
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07006635 if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) {
6636 display.intersect(mCompatibleScreenFrame);
6637 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07006638 }
6639
6640 final int pw = container.right - container.left;
6641 final int ph = container.bottom - container.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006642
6643 int w,h;
6644 if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) {
6645 w = mAttrs.width < 0 ? pw : mAttrs.width;
6646 h = mAttrs.height< 0 ? ph : mAttrs.height;
6647 } else {
Romain Guy980a9382010-01-08 15:06:28 -08006648 w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth;
6649 h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006650 }
Romain Guy06882f82009-06-10 13:36:04 -07006651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006652 final Rect content = mContentFrame;
6653 content.set(cf);
Romain Guy06882f82009-06-10 13:36:04 -07006654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006655 final Rect visible = mVisibleFrame;
6656 visible.set(vf);
Romain Guy06882f82009-06-10 13:36:04 -07006657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006658 final Rect frame = mFrame;
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006659 final int fw = frame.width();
6660 final int fh = frame.height();
Romain Guy06882f82009-06-10 13:36:04 -07006661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006662 //System.out.println("In: w=" + w + " h=" + h + " container=" +
6663 // container + " x=" + mAttrs.x + " y=" + mAttrs.y);
6664
6665 Gravity.apply(mAttrs.gravity, w, h, container,
6666 (int) (mAttrs.x + mAttrs.horizontalMargin * pw),
6667 (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame);
6668
6669 //System.out.println("Out: " + mFrame);
6670
6671 // Now make sure the window fits in the overall display.
6672 Gravity.applyDisplay(mAttrs.gravity, df, frame);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006674 // Make sure the content and visible frames are inside of the
6675 // final window frame.
6676 if (content.left < frame.left) content.left = frame.left;
6677 if (content.top < frame.top) content.top = frame.top;
6678 if (content.right > frame.right) content.right = frame.right;
6679 if (content.bottom > frame.bottom) content.bottom = frame.bottom;
6680 if (visible.left < frame.left) visible.left = frame.left;
6681 if (visible.top < frame.top) visible.top = frame.top;
6682 if (visible.right > frame.right) visible.right = frame.right;
6683 if (visible.bottom > frame.bottom) visible.bottom = frame.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006685 final Rect contentInsets = mContentInsets;
6686 contentInsets.left = content.left-frame.left;
6687 contentInsets.top = content.top-frame.top;
6688 contentInsets.right = frame.right-content.right;
6689 contentInsets.bottom = frame.bottom-content.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006691 final Rect visibleInsets = mVisibleInsets;
6692 visibleInsets.left = visible.left-frame.left;
6693 visibleInsets.top = visible.top-frame.top;
6694 visibleInsets.right = frame.right-visible.right;
6695 visibleInsets.bottom = frame.bottom-visible.bottom;
Romain Guy06882f82009-06-10 13:36:04 -07006696
Dianne Hackborn284ac932009-08-28 10:34:25 -07006697 if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
6698 updateWallpaperOffsetLocked(this, mDisplay.getWidth(),
Dianne Hackborn19382ac2009-09-11 21:13:37 -07006699 mDisplay.getHeight(), false);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07006700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006702 if (localLOGV) {
6703 //if ("com.google.android.youtube".equals(mAttrs.packageName)
6704 // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006705 Slog.v(TAG, "Resolving (mRequestedWidth="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006706 + mRequestedWidth + ", mRequestedheight="
6707 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
6708 + "): frame=" + mFrame.toShortString()
6709 + " ci=" + contentInsets.toShortString()
6710 + " vi=" + visibleInsets.toShortString());
6711 //}
6712 }
6713 }
Romain Guy06882f82009-06-10 13:36:04 -07006714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006715 public Rect getFrameLw() {
6716 return mFrame;
6717 }
6718
6719 public Rect getShownFrameLw() {
6720 return mShownFrame;
6721 }
6722
6723 public Rect getDisplayFrameLw() {
6724 return mDisplayFrame;
6725 }
6726
6727 public Rect getContentFrameLw() {
6728 return mContentFrame;
6729 }
6730
6731 public Rect getVisibleFrameLw() {
6732 return mVisibleFrame;
6733 }
6734
6735 public boolean getGivenInsetsPendingLw() {
6736 return mGivenInsetsPending;
6737 }
6738
6739 public Rect getGivenContentInsetsLw() {
6740 return mGivenContentInsets;
6741 }
Romain Guy06882f82009-06-10 13:36:04 -07006742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006743 public Rect getGivenVisibleInsetsLw() {
6744 return mGivenVisibleInsets;
6745 }
Romain Guy06882f82009-06-10 13:36:04 -07006746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006747 public WindowManager.LayoutParams getAttrs() {
6748 return mAttrs;
6749 }
6750
6751 public int getSurfaceLayer() {
6752 return mLayer;
6753 }
Romain Guy06882f82009-06-10 13:36:04 -07006754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006755 public IApplicationToken getAppToken() {
6756 return mAppToken != null ? mAppToken.appToken : null;
6757 }
Jeff Brown349703e2010-06-22 01:27:15 -07006758
6759 public long getInputDispatchingTimeoutNanos() {
6760 return mAppToken != null
6761 ? mAppToken.inputDispatchingTimeoutNanos
6762 : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
6763 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006764
6765 public boolean hasAppShownWindows() {
6766 return mAppToken != null ? mAppToken.firstWindowDrawn : false;
6767 }
6768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006769 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006770 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006771 TAG, "Setting animation in " + this + ": " + anim);
6772 mAnimating = false;
6773 mLocalAnimating = false;
6774 mAnimation = anim;
6775 mAnimation.restrictDuration(MAX_ANIMATION_DURATION);
6776 mAnimation.scaleCurrentDuration(mWindowAnimationScale);
6777 }
6778
6779 public void clearAnimation() {
6780 if (mAnimation != null) {
6781 mAnimating = true;
6782 mLocalAnimating = false;
6783 mAnimation = null;
6784 }
6785 }
Romain Guy06882f82009-06-10 13:36:04 -07006786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006787 Surface createSurfaceLocked() {
6788 if (mSurface == null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006789 mReportDestroySurface = false;
6790 mSurfacePendingDestroy = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006791 mDrawPending = true;
6792 mCommitDrawPending = false;
6793 mReadyToShow = false;
6794 if (mAppToken != null) {
6795 mAppToken.allDrawn = false;
6796 }
6797
6798 int flags = 0;
Mathias Agopian317a6282009-08-13 17:29:02 -07006799 if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006800 flags |= Surface.PUSH_BUFFERS;
6801 }
6802
6803 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
6804 flags |= Surface.SECURE;
6805 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006806 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006807 TAG, "Creating surface in session "
6808 + mSession.mSurfaceSession + " window " + this
6809 + " w=" + mFrame.width()
6810 + " h=" + mFrame.height() + " format="
6811 + mAttrs.format + " flags=" + flags);
6812
6813 int w = mFrame.width();
6814 int h = mFrame.height();
6815 if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
6816 // for a scaled surface, we always want the requested
6817 // size.
6818 w = mRequestedWidth;
6819 h = mRequestedHeight;
6820 }
6821
Romain Guy9825ec62009-10-01 00:58:09 -07006822 // Something is wrong and SurfaceFlinger will not like this,
6823 // try to revert to sane values
6824 if (w <= 0) w = 1;
6825 if (h <= 0) h = 1;
6826
Dianne Hackborn16064f92010-03-25 00:47:24 -07006827 mSurfaceShown = false;
6828 mSurfaceLayer = 0;
6829 mSurfaceAlpha = 1;
6830 mSurfaceX = 0;
6831 mSurfaceY = 0;
6832 mSurfaceW = w;
6833 mSurfaceH = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006834 try {
6835 mSurface = new Surface(
Romain Guy06882f82009-06-10 13:36:04 -07006836 mSession.mSurfaceSession, mSession.mPid,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08006837 mAttrs.getTitle().toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006838 0, w, h, mAttrs.format, flags);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006839 if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE "
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006840 + mSurface + " IN SESSION "
6841 + mSession.mSurfaceSession
6842 + ": pid=" + mSession.mPid + " format="
6843 + mAttrs.format + " flags=0x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006844 + Integer.toHexString(flags)
6845 + " / " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006846 } catch (Surface.OutOfResourcesException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006847 Slog.w(TAG, "OutOfResourcesException creating surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006848 reclaimSomeSurfaceMemoryLocked(this, "create");
6849 return null;
6850 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006851 Slog.e(TAG, "Exception creating surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006852 return null;
6853 }
Romain Guy06882f82009-06-10 13:36:04 -07006854
Joe Onorato8a9b2202010-02-26 18:56:32 -08006855 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006856 TAG, "Got surface: " + mSurface
6857 + ", set left=" + mFrame.left + " top=" + mFrame.top
6858 + ", animLayer=" + mAnimLayer);
6859 if (SHOW_TRANSACTIONS) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006860 Slog.i(TAG, ">>> OPEN TRANSACTION");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006861 if (SHOW_TRANSACTIONS) logSurface(this,
6862 "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" +
6863 mFrame.width() + "x" + mFrame.height() + "), layer=" +
6864 mAnimLayer + " HIDE", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006865 }
6866 Surface.openTransaction();
6867 try {
6868 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07006869 mSurfaceX = mFrame.left + mXOffset;
Dianne Hackborn529bef62010-03-25 11:48:43 -07006870 mSurfaceY = mFrame.top + mYOffset;
Dianne Hackborn16064f92010-03-25 00:47:24 -07006871 mSurface.setPosition(mSurfaceX, mSurfaceY);
6872 mSurfaceLayer = mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006873 mSurface.setLayer(mAnimLayer);
Dianne Hackborn16064f92010-03-25 00:47:24 -07006874 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006875 mSurface.hide();
6876 if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006877 if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006878 mSurface.setFlags(Surface.SURFACE_DITHER,
6879 Surface.SURFACE_DITHER);
6880 }
6881 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006882 Slog.w(TAG, "Error creating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006883 reclaimSomeSurfaceMemoryLocked(this, "create-init");
6884 }
6885 mLastHidden = true;
6886 } finally {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006887 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006888 Surface.closeTransaction();
6889 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006890 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006891 TAG, "Created surface " + this);
6892 }
6893 return mSurface;
6894 }
Romain Guy06882f82009-06-10 13:36:04 -07006895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006896 void destroySurfaceLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006897 if (mAppToken != null && this == mAppToken.startingWindow) {
6898 mAppToken.startingDisplayed = false;
6899 }
Romain Guy06882f82009-06-10 13:36:04 -07006900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006901 if (mSurface != null) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006902 mDrawPending = false;
6903 mCommitDrawPending = false;
6904 mReadyToShow = false;
6905
6906 int i = mChildWindows.size();
6907 while (i > 0) {
6908 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07006909 WindowState c = mChildWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006910 c.mAttachedHidden = true;
6911 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006912
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07006913 if (mReportDestroySurface) {
6914 mReportDestroySurface = false;
6915 mSurfacePendingDestroy = true;
6916 try {
6917 mClient.dispatchGetNewSurface();
6918 // We'll really destroy on the next time around.
6919 return;
6920 } catch (RemoteException e) {
6921 }
6922 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006924 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006925 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006926 RuntimeException e = null;
6927 if (!HIDE_STACK_CRAWLS) {
6928 e = new RuntimeException();
6929 e.fillInStackTrace();
6930 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006931 Slog.w(TAG, "Window " + this + " destroying surface "
Dianne Hackborn3be63c02009-08-20 19:31:38 -07006932 + mSurface + ", session " + mSession, e);
6933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006934 if (SHOW_TRANSACTIONS) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006935 RuntimeException e = null;
6936 if (!HIDE_STACK_CRAWLS) {
6937 e = new RuntimeException();
6938 e.fillInStackTrace();
6939 }
6940 if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006941 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07006942 mSurface.destroy();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006943 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006944 Slog.w(TAG, "Exception thrown when destroying Window " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006945 + " surface " + mSurface + " session " + mSession
6946 + ": " + e.toString());
6947 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006948
Dianne Hackborn16064f92010-03-25 00:47:24 -07006949 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006950 mSurface = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006951 }
6952 }
6953
6954 boolean finishDrawingLocked() {
6955 if (mDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006956 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006957 TAG, "finishDrawingLocked: " + mSurface);
6958 mCommitDrawPending = true;
6959 mDrawPending = false;
6960 return true;
6961 }
6962 return false;
6963 }
6964
6965 // This must be called while inside a transaction.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006966 boolean commitFinishDrawingLocked(long currentTime) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08006967 //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006968 if (!mCommitDrawPending) {
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006969 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006970 }
6971 mCommitDrawPending = false;
6972 mReadyToShow = true;
6973 final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING;
6974 final AppWindowToken atoken = mAppToken;
6975 if (atoken == null || atoken.allDrawn || starting) {
6976 performShowLocked();
6977 }
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07006978 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006979 }
6980
6981 // This must be called while inside a transaction.
6982 boolean performShowLocked() {
6983 if (DEBUG_VISIBILITY) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006984 RuntimeException e = null;
6985 if (!HIDE_STACK_CRAWLS) {
6986 e = new RuntimeException();
6987 e.fillInStackTrace();
6988 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08006989 Slog.v(TAG, "performShow on " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006990 + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay()
6991 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e);
6992 }
6993 if (mReadyToShow && isReadyForDisplay()) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08006994 if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this,
6995 "SHOW (performShowLocked)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08006996 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006997 + " during animation: policyVis=" + mPolicyVisibility
6998 + " attHidden=" + mAttachedHidden
6999 + " tok.hiddenRequested="
7000 + (mAppToken != null ? mAppToken.hiddenRequested : false)
Dianne Hackborn248b1882009-09-16 16:46:44 -07007001 + " tok.hidden="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007002 + (mAppToken != null ? mAppToken.hidden : false)
7003 + " animating=" + mAnimating
7004 + " tok animating="
7005 + (mAppToken != null ? mAppToken.animating : false));
7006 if (!showSurfaceRobustlyLocked(this)) {
7007 return false;
7008 }
7009 mLastAlpha = -1;
7010 mHasDrawn = true;
7011 mLastHidden = false;
7012 mReadyToShow = false;
7013 enableScreenIfNeededLocked();
7014
7015 applyEnterAnimationLocked(this);
Romain Guy06882f82009-06-10 13:36:04 -07007016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007017 int i = mChildWindows.size();
7018 while (i > 0) {
7019 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07007020 WindowState c = mChildWindows.get(i);
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007021 if (c.mAttachedHidden) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007022 c.mAttachedHidden = false;
Dianne Hackbornf09c1a22010-04-22 15:59:21 -07007023 if (c.mSurface != null) {
7024 c.performShowLocked();
7025 // It hadn't been shown, which means layout not
7026 // performed on it, so now we want to make sure to
7027 // do a layout. If called from within the transaction
7028 // loop, this will cause it to restart with a new
7029 // layout.
7030 mLayoutNeeded = true;
7031 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007032 }
7033 }
Romain Guy06882f82009-06-10 13:36:04 -07007034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007035 if (mAttrs.type != TYPE_APPLICATION_STARTING
7036 && mAppToken != null) {
7037 mAppToken.firstWindowDrawn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007038
Dianne Hackborn248b1882009-09-16 16:46:44 -07007039 if (mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007040 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG,
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007041 "Finish starting " + mToken
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007042 + ": first real window is shown, no animation");
Dianne Hackborn248b1882009-09-16 16:46:44 -07007043 // If this initial window is animating, stop it -- we
7044 // will do an animation to reveal it from behind the
7045 // starting window, so there is no need for it to also
7046 // be doing its own stuff.
7047 if (mAnimation != null) {
7048 mAnimation = null;
7049 // Make sure we clean up the animation.
7050 mAnimating = true;
7051 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007052 mFinishedStarting.add(mAppToken);
7053 mH.sendEmptyMessage(H.FINISHED_STARTING);
7054 }
7055 mAppToken.updateReportedVisibilityLocked();
7056 }
7057 }
7058 return true;
7059 }
Romain Guy06882f82009-06-10 13:36:04 -07007060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007061 // This must be called while inside a transaction. Returns true if
7062 // there is more animation to run.
7063 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08007064 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007065 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07007066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007067 if (!mDrawPending && !mCommitDrawPending && mAnimation != null) {
7068 mHasTransformation = true;
7069 mHasLocalTransformation = true;
7070 if (!mLocalAnimating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007071 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007072 TAG, "Starting animation in " + this +
7073 " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() +
7074 " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale);
7075 mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh);
7076 mAnimation.setStartTime(currentTime);
7077 mLocalAnimating = true;
7078 mAnimating = true;
7079 }
7080 mTransformation.clear();
7081 final boolean more = mAnimation.getTransformation(
7082 currentTime, mTransformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007083 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007084 TAG, "Stepped animation in " + this +
7085 ": more=" + more + ", xform=" + mTransformation);
7086 if (more) {
7087 // we're not done!
7088 return true;
7089 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007090 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007091 TAG, "Finished animation in " + this +
7092 " @ " + currentTime);
7093 mAnimation = null;
7094 //WindowManagerService.this.dump();
7095 }
7096 mHasLocalTransformation = false;
7097 if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007098 && mAppToken.animation != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007099 // When our app token is animating, we kind-of pretend like
7100 // we are as well. Note the mLocalAnimating mAnimationIsEntrance
7101 // part of this check means that we will only do this if
7102 // our window is not currently exiting, or it is not
7103 // locally animating itself. The idea being that one that
7104 // is exiting and doing a local animation should be removed
7105 // once that animation is done.
7106 mAnimating = true;
7107 mHasTransformation = true;
7108 mTransformation.clear();
7109 return false;
7110 } else if (mHasTransformation) {
7111 // Little trick to get through the path below to act like
7112 // we have finished an animation.
7113 mAnimating = true;
7114 } else if (isAnimating()) {
7115 mAnimating = true;
7116 }
7117 } else if (mAnimation != null) {
7118 // If the display is frozen, and there is a pending animation,
7119 // clear it and make sure we run the cleanup code.
7120 mAnimating = true;
7121 mLocalAnimating = true;
7122 mAnimation = null;
7123 }
Romain Guy06882f82009-06-10 13:36:04 -07007124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007125 if (!mAnimating && !mLocalAnimating) {
7126 return false;
7127 }
7128
Joe Onorato8a9b2202010-02-26 18:56:32 -08007129 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007130 TAG, "Animation done in " + this + ": exiting=" + mExiting
7131 + ", reportedVisible="
7132 + (mAppToken != null ? mAppToken.reportedVisible : false));
Romain Guy06882f82009-06-10 13:36:04 -07007133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007134 mAnimating = false;
7135 mLocalAnimating = false;
7136 mAnimation = null;
7137 mAnimLayer = mLayer;
7138 if (mIsImWindow) {
7139 mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007140 } else if (mIsWallpaper) {
7141 mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007142 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08007143 if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007144 + " anim layer: " + mAnimLayer);
7145 mHasTransformation = false;
7146 mHasLocalTransformation = false;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007147 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
7148 if (DEBUG_VISIBILITY) {
7149 Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
7150 + mPolicyVisibilityAfterAnim);
7151 }
7152 mPolicyVisibility = mPolicyVisibilityAfterAnim;
7153 if (!mPolicyVisibility) {
7154 if (mCurrentFocus == this) {
7155 mFocusMayChange = true;
7156 }
7157 // Window is no longer visible -- make sure if we were waiting
7158 // for it to be displayed before enabling the display, that
7159 // we allow the display to be enabled now.
7160 enableScreenIfNeededLocked();
7161 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007162 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007163 mTransformation.clear();
7164 if (mHasDrawn
7165 && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
7166 && mAppToken != null
7167 && mAppToken.firstWindowDrawn
7168 && mAppToken.startingData != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007169 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007170 + mToken + ": first real window done animating");
7171 mFinishedStarting.add(mAppToken);
7172 mH.sendEmptyMessage(H.FINISHED_STARTING);
7173 }
Romain Guy06882f82009-06-10 13:36:04 -07007174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007175 finishExit();
7176
7177 if (mAppToken != null) {
7178 mAppToken.updateReportedVisibilityLocked();
7179 }
7180
7181 return false;
7182 }
7183
7184 void finishExit() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007185 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007186 TAG, "finishExit in " + this
7187 + ": exiting=" + mExiting
7188 + " remove=" + mRemoveOnExit
7189 + " windowAnimating=" + isWindowAnimating());
Romain Guy06882f82009-06-10 13:36:04 -07007190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007191 final int N = mChildWindows.size();
7192 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07007193 mChildWindows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007194 }
Romain Guy06882f82009-06-10 13:36:04 -07007195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007196 if (!mExiting) {
7197 return;
7198 }
Romain Guy06882f82009-06-10 13:36:04 -07007199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007200 if (isWindowAnimating()) {
7201 return;
7202 }
7203
Joe Onorato8a9b2202010-02-26 18:56:32 -08007204 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007205 TAG, "Exit animation finished in " + this
7206 + ": remove=" + mRemoveOnExit);
7207 if (mSurface != null) {
7208 mDestroySurface.add(this);
7209 mDestroying = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007210 if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007211 mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007212 try {
7213 mSurface.hide();
7214 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007215 Slog.w(TAG, "Error hiding surface in " + this, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007216 }
7217 mLastHidden = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007218 }
7219 mExiting = false;
7220 if (mRemoveOnExit) {
7221 mPendingRemove.add(this);
7222 mRemoveOnExit = false;
7223 }
7224 }
Romain Guy06882f82009-06-10 13:36:04 -07007225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007226 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
7227 if (dsdx < .99999f || dsdx > 1.00001f) return false;
7228 if (dtdy < .99999f || dtdy > 1.00001f) return false;
7229 if (dtdx < -.000001f || dtdx > .000001f) return false;
7230 if (dsdy < -.000001f || dsdy > .000001f) return false;
7231 return true;
7232 }
Romain Guy06882f82009-06-10 13:36:04 -07007233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007234 void computeShownFrameLocked() {
7235 final boolean selfTransformation = mHasLocalTransformation;
7236 Transformation attachedTransformation =
7237 (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation)
7238 ? mAttachedWindow.mTransformation : null;
7239 Transformation appTransformation =
7240 (mAppToken != null && mAppToken.hasTransformation)
7241 ? mAppToken.transformation : null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007242
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007243 // Wallpapers are animated based on the "real" window they
7244 // are currently targeting.
Dianne Hackborn3be63c02009-08-20 19:31:38 -07007245 if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07007246 && mWallpaperTarget != null) {
Dianne Hackborn5baba162009-09-23 17:01:12 -07007247 if (mWallpaperTarget.mHasLocalTransformation &&
7248 mWallpaperTarget.mAnimation != null &&
7249 !mWallpaperTarget.mAnimation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007250 attachedTransformation = mWallpaperTarget.mTransformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007251 if (DEBUG_WALLPAPER && attachedTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007252 Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007253 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007254 }
7255 if (mWallpaperTarget.mAppToken != null &&
Dianne Hackborn5baba162009-09-23 17:01:12 -07007256 mWallpaperTarget.mAppToken.hasTransformation &&
7257 mWallpaperTarget.mAppToken.animation != null &&
7258 !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) {
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007259 appTransformation = mWallpaperTarget.mAppToken.transformation;
Dianne Hackborn5baba162009-09-23 17:01:12 -07007260 if (DEBUG_WALLPAPER && appTransformation != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007261 Slog.v(TAG, "WP target app xform: " + appTransformation);
Dianne Hackborn5baba162009-09-23 17:01:12 -07007262 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007263 }
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007264 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007266 if (selfTransformation || attachedTransformation != null
7267 || appTransformation != null) {
Romain Guy06882f82009-06-10 13:36:04 -07007268 // cache often used attributes locally
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007269 final Rect frame = mFrame;
7270 final float tmpFloats[] = mTmpFloats;
7271 final Matrix tmpMatrix = mTmpMatrix;
7272
7273 // Compute the desired transformation.
Dianne Hackborn65c23872009-09-18 17:47:02 -07007274 tmpMatrix.setTranslate(0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007275 if (selfTransformation) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007276 tmpMatrix.postConcat(mTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007277 }
Dianne Hackborn65c23872009-09-18 17:47:02 -07007278 tmpMatrix.postTranslate(frame.left, frame.top);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007279 if (attachedTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007280 tmpMatrix.postConcat(attachedTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007281 }
7282 if (appTransformation != null) {
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07007283 tmpMatrix.postConcat(appTransformation.getMatrix());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007284 }
7285
7286 // "convert" it into SurfaceFlinger's format
7287 // (a 2x2 matrix + an offset)
7288 // Here we must not transform the position of the surface
7289 // since it is already included in the transformation.
Joe Onorato8a9b2202010-02-26 18:56:32 -08007290 //Slog.i(TAG, "Transform: " + matrix);
Romain Guy06882f82009-06-10 13:36:04 -07007291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007292 tmpMatrix.getValues(tmpFloats);
7293 mDsDx = tmpFloats[Matrix.MSCALE_X];
7294 mDtDx = tmpFloats[Matrix.MSKEW_X];
7295 mDsDy = tmpFloats[Matrix.MSKEW_Y];
7296 mDtDy = tmpFloats[Matrix.MSCALE_Y];
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007297 int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset;
7298 int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007299 int w = frame.width();
7300 int h = frame.height();
7301 mShownFrame.set(x, y, x+w, y+h);
7302
7303 // Now set the alpha... but because our current hardware
7304 // can't do alpha transformation on a non-opaque surface,
7305 // turn it off if we are running an animation that is also
7306 // transforming since it is more important to have that
7307 // animation be smooth.
7308 mShownAlpha = mAlpha;
7309 if (!mLimitedAlphaCompositing
7310 || (!PixelFormat.formatHasAlpha(mAttrs.format)
7311 || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
7312 && x == frame.left && y == frame.top))) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007313 //Slog.i(TAG, "Applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007314 if (selfTransformation) {
7315 mShownAlpha *= mTransformation.getAlpha();
7316 }
7317 if (attachedTransformation != null) {
7318 mShownAlpha *= attachedTransformation.getAlpha();
7319 }
7320 if (appTransformation != null) {
7321 mShownAlpha *= appTransformation.getAlpha();
7322 }
7323 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007324 //Slog.i(TAG, "Not applying alpha transform");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007325 }
Romain Guy06882f82009-06-10 13:36:04 -07007326
Joe Onorato8a9b2202010-02-26 18:56:32 -08007327 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007328 TAG, "Continuing animation in " + this +
7329 ": " + mShownFrame +
7330 ", alpha=" + mTransformation.getAlpha());
7331 return;
7332 }
Romain Guy06882f82009-06-10 13:36:04 -07007333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007334 mShownFrame.set(mFrame);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007335 if (mXOffset != 0 || mYOffset != 0) {
7336 mShownFrame.offset(mXOffset, mYOffset);
7337 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007338 mShownAlpha = mAlpha;
7339 mDsDx = 1;
7340 mDtDx = 0;
7341 mDsDy = 0;
7342 mDtDy = 1;
7343 }
Romain Guy06882f82009-06-10 13:36:04 -07007344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007345 /**
7346 * Is this window visible? It is not visible if there is no
7347 * surface, or we are in the process of running an exit animation
7348 * that will remove the surface, or its app token has been hidden.
7349 */
7350 public boolean isVisibleLw() {
7351 final AppWindowToken atoken = mAppToken;
7352 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7353 && (atoken == null || !atoken.hiddenRequested)
7354 && !mExiting && !mDestroying;
7355 }
7356
7357 /**
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007358 * Like {@link #isVisibleLw}, but also counts a window that is currently
7359 * "hidden" behind the keyguard as visible. This allows us to apply
7360 * things like window flags that impact the keyguard.
7361 * XXX I am starting to think we need to have ANOTHER visibility flag
7362 * for this "hidden behind keyguard" state rather than overloading
7363 * mPolicyVisibility. Ungh.
7364 */
7365 public boolean isVisibleOrBehindKeyguardLw() {
7366 final AppWindowToken atoken = mAppToken;
7367 return mSurface != null && !mAttachedHidden
7368 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007369 && !mDrawPending && !mCommitDrawPending
Dianne Hackborn3d163f072009-10-07 21:26:57 -07007370 && !mExiting && !mDestroying;
7371 }
7372
7373 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007374 * Is this window visible, ignoring its app token? It is not visible
7375 * if there is no surface, or we are in the process of running an exit animation
7376 * that will remove the surface.
7377 */
7378 public boolean isWinVisibleLw() {
7379 final AppWindowToken atoken = mAppToken;
7380 return mSurface != null && mPolicyVisibility && !mAttachedHidden
7381 && (atoken == null || !atoken.hiddenRequested || atoken.animating)
7382 && !mExiting && !mDestroying;
7383 }
7384
7385 /**
7386 * The same as isVisible(), but follows the current hidden state of
7387 * the associated app token, not the pending requested hidden state.
7388 */
7389 boolean isVisibleNow() {
7390 return mSurface != null && mPolicyVisibility && !mAttachedHidden
The Android Open Source Project10592532009-03-18 17:39:46 -07007391 && !mRootToken.hidden && !mExiting && !mDestroying;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007392 }
7393
7394 /**
Christopher Tatea53146c2010-09-07 11:57:52 -07007395 * Can this window possibly be a drag/drop target? The test here is
7396 * a combination of the above "visible now" with the check that the
7397 * Input Manager uses when discarding windows from input consideration.
7398 */
7399 boolean isPotentialDragTarget() {
7400 return isVisibleNow() && (mInputChannel != null) && !mRemoved;
7401 }
7402
7403 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007404 * Same as isVisible(), but we also count it as visible between the
7405 * call to IWindowSession.add() and the first relayout().
7406 */
7407 boolean isVisibleOrAdding() {
7408 final AppWindowToken atoken = mAppToken;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007409 return ((mSurface != null && !mReportDestroySurface)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007410 || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
7411 && mPolicyVisibility && !mAttachedHidden
7412 && (atoken == null || !atoken.hiddenRequested)
7413 && !mExiting && !mDestroying;
7414 }
7415
7416 /**
7417 * Is this window currently on-screen? It is on-screen either if it
7418 * is visible or it is currently running an animation before no longer
7419 * being visible.
7420 */
7421 boolean isOnScreen() {
7422 final AppWindowToken atoken = mAppToken;
7423 if (atoken != null) {
7424 return mSurface != null && mPolicyVisibility && !mDestroying
7425 && ((!mAttachedHidden && !atoken.hiddenRequested)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007426 || mAnimation != null || atoken.animation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007427 } else {
7428 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007429 && (!mAttachedHidden || mAnimation != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007430 }
7431 }
Romain Guy06882f82009-06-10 13:36:04 -07007432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007433 /**
7434 * Like isOnScreen(), but we don't return true if the window is part
7435 * of a transition that has not yet been started.
7436 */
7437 boolean isReadyForDisplay() {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007438 if (mRootToken.waitingToShow &&
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07007439 mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Dianne Hackborna8f60182009-09-01 19:01:50 -07007440 return false;
7441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007442 final AppWindowToken atoken = mAppToken;
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007443 final boolean animating = atoken != null
7444 ? (atoken.animation != null) : false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007445 return mSurface != null && mPolicyVisibility && !mDestroying
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007446 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
7447 && !mRootToken.hidden)
Dianne Hackborn0cd48872009-08-13 18:51:59 -07007448 || mAnimation != null || animating);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007449 }
7450
7451 /** Is the window or its container currently animating? */
7452 boolean isAnimating() {
7453 final WindowState attached = mAttachedWindow;
7454 final AppWindowToken atoken = mAppToken;
7455 return mAnimation != null
7456 || (attached != null && attached.mAnimation != null)
Romain Guy06882f82009-06-10 13:36:04 -07007457 || (atoken != null &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007458 (atoken.animation != null
7459 || atoken.inPendingTransaction));
7460 }
7461
7462 /** Is this window currently animating? */
7463 boolean isWindowAnimating() {
7464 return mAnimation != null;
7465 }
7466
7467 /**
7468 * Like isOnScreen, but returns false if the surface hasn't yet
7469 * been drawn.
7470 */
7471 public boolean isDisplayedLw() {
7472 final AppWindowToken atoken = mAppToken;
7473 return mSurface != null && mPolicyVisibility && !mDestroying
7474 && !mDrawPending && !mCommitDrawPending
7475 && ((!mAttachedHidden &&
7476 (atoken == null || !atoken.hiddenRequested))
7477 || mAnimating);
7478 }
7479
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07007480 /**
7481 * Returns true if the window has a surface that it has drawn a
7482 * complete UI in to.
7483 */
7484 public boolean isDrawnLw() {
7485 final AppWindowToken atoken = mAppToken;
7486 return mSurface != null && !mDestroying
7487 && !mDrawPending && !mCommitDrawPending;
7488 }
7489
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007490 /**
Dianne Hackborn25994b42009-09-04 14:21:19 -07007491 * Return true if the window is opaque and fully drawn. This indicates
7492 * it may obscure windows behind it.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007493 */
7494 boolean isOpaqueDrawn() {
Dianne Hackborn25994b42009-09-04 14:21:19 -07007495 return (mAttrs.format == PixelFormat.OPAQUE
7496 || mAttrs.type == TYPE_WALLPAPER)
7497 && mSurface != null && mAnimation == null
7498 && (mAppToken == null || mAppToken.animation == null)
7499 && !mDrawPending && !mCommitDrawPending;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007500 }
7501
7502 boolean needsBackgroundFiller(int screenWidth, int screenHeight) {
7503 return
7504 // only if the application is requesting compatible window
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007505 (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 &&
7506 // only if it's visible
7507 mHasDrawn && mViewVisibility == View.VISIBLE &&
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007508 // and only if the application fills the compatible screen
7509 mFrame.left <= mCompatibleScreenFrame.left &&
7510 mFrame.top <= mCompatibleScreenFrame.top &&
7511 mFrame.right >= mCompatibleScreenFrame.right &&
7512 mFrame.bottom >= mCompatibleScreenFrame.bottom &&
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07007513 // and starting window do not need background filler
Mitsuru Oshimad2967e22009-07-20 14:01:43 -07007514 mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07007515 }
7516
7517 boolean isFullscreen(int screenWidth, int screenHeight) {
7518 return mFrame.left <= 0 && mFrame.top <= 0 &&
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007519 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007520 }
7521
7522 void removeLocked() {
Jeff Brownc5ed5912010-07-14 18:48:53 -07007523 disposeInputChannel();
7524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007525 if (mAttachedWindow != null) {
7526 mAttachedWindow.mChildWindows.remove(this);
7527 }
7528 destroySurfaceLocked();
7529 mSession.windowRemovedLocked();
7530 try {
7531 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
7532 } catch (RuntimeException e) {
7533 // Ignore if it has already been removed (usually because
7534 // we are doing this as part of processing a death note.)
7535 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07007536 }
7537
7538 void disposeInputChannel() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07007539 if (mInputChannel != null) {
7540 mInputManager.unregisterInputChannel(mInputChannel);
7541
7542 mInputChannel.dispose();
7543 mInputChannel = null;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007545 }
7546
7547 private class DeathRecipient implements IBinder.DeathRecipient {
7548 public void binderDied() {
7549 try {
7550 synchronized(mWindowMap) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007551 WindowState win = windowForClientLocked(mSession, mClient, false);
Joe Onorato8a9b2202010-02-26 18:56:32 -08007552 Slog.i(TAG, "WIN DEATH: " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007553 if (win != null) {
7554 removeWindowLocked(mSession, win);
7555 }
7556 }
7557 } catch (IllegalArgumentException ex) {
7558 // This will happen if the window has already been
7559 // removed.
7560 }
7561 }
7562 }
7563
7564 /** Returns true if this window desires key events. */
7565 public final boolean canReceiveKeys() {
7566 return isVisibleOrAdding()
7567 && (mViewVisibility == View.VISIBLE)
7568 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
7569 }
7570
7571 public boolean hasDrawnLw() {
7572 return mHasDrawn;
7573 }
7574
7575 public boolean showLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007576 return showLw(doAnimation, true);
7577 }
7578
7579 boolean showLw(boolean doAnimation, boolean requestAnim) {
7580 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
7581 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007582 }
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007583 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007584 if (doAnimation) {
7585 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
7586 + mPolicyVisibility + " mAnimation=" + mAnimation);
7587 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7588 doAnimation = false;
7589 } else if (mPolicyVisibility && mAnimation == null) {
7590 // Check for the case where we are currently visible and
7591 // not animating; we do not want to do animation at such a
7592 // point to become visible when we already are.
7593 doAnimation = false;
7594 }
7595 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007596 mPolicyVisibility = true;
7597 mPolicyVisibilityAfterAnim = true;
7598 if (doAnimation) {
7599 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true);
7600 }
7601 if (requestAnim) {
7602 requestAnimationLocked(0);
7603 }
7604 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007605 }
7606
7607 public boolean hideLw(boolean doAnimation) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007608 return hideLw(doAnimation, true);
7609 }
7610
7611 boolean hideLw(boolean doAnimation, boolean requestAnim) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007612 if (doAnimation) {
7613 if (mDisplayFrozen || !mPolicy.isScreenOn()) {
7614 doAnimation = false;
7615 }
7616 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007617 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
7618 : mPolicyVisibility;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007619 if (!current) {
7620 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007621 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007622 if (doAnimation) {
7623 applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false);
7624 if (mAnimation == null) {
7625 doAnimation = false;
7626 }
7627 }
7628 if (doAnimation) {
7629 mPolicyVisibilityAfterAnim = false;
7630 } else {
Dianne Hackbornb601ce12010-03-01 23:36:02 -08007631 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007632 mPolicyVisibilityAfterAnim = false;
7633 mPolicyVisibility = false;
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -08007634 // Window is no longer visible -- make sure if we were waiting
7635 // for it to be displayed before enabling the display, that
7636 // we allow the display to be enabled now.
7637 enableScreenIfNeededLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08007638 if (mCurrentFocus == this) {
7639 mFocusMayChange = true;
7640 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07007641 }
7642 if (requestAnim) {
7643 requestAnimationLocked(0);
7644 }
7645 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007646 }
7647
7648 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007649 pw.print(prefix); pw.print("mSession="); pw.print(mSession);
7650 pw.print(" mClient="); pw.println(mClient.asBinder());
7651 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
7652 if (mAttachedWindow != null || mLayoutAttached) {
7653 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
7654 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
7655 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07007656 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
7657 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
7658 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07007659 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
7660 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007661 }
7662 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
7663 pw.print(" mSubLayer="); pw.print(mSubLayer);
7664 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
7665 pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment
7666 : (mAppToken != null ? mAppToken.animLayerAdjustment : 0)));
7667 pw.print("="); pw.print(mAnimLayer);
7668 pw.print(" mLastLayer="); pw.println(mLastLayer);
7669 if (mSurface != null) {
7670 pw.print(prefix); pw.print("mSurface="); pw.println(mSurface);
Dianne Hackborn16064f92010-03-25 00:47:24 -07007671 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
7672 pw.print(" layer="); pw.print(mSurfaceLayer);
7673 pw.print(" alpha="); pw.print(mSurfaceAlpha);
7674 pw.print(" rect=("); pw.print(mSurfaceX);
7675 pw.print(","); pw.print(mSurfaceY);
7676 pw.print(") "); pw.print(mSurfaceW);
7677 pw.print(" x "); pw.println(mSurfaceH);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007678 }
7679 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
7680 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
7681 if (mAppToken != null) {
7682 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
7683 }
7684 if (mTargetAppToken != null) {
7685 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
7686 }
7687 pw.print(prefix); pw.print("mViewVisibility=0x");
7688 pw.print(Integer.toHexString(mViewVisibility));
7689 pw.print(" mLastHidden="); pw.print(mLastHidden);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07007690 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
7691 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007692 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) {
7693 pw.print(prefix); pw.print("mPolicyVisibility=");
7694 pw.print(mPolicyVisibility);
7695 pw.print(" mPolicyVisibilityAfterAnim=");
7696 pw.print(mPolicyVisibilityAfterAnim);
7697 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
7698 }
Dianne Hackborn9b52a212009-12-11 14:51:35 -08007699 if (!mRelayoutCalled) {
7700 pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled);
7701 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007702 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007703 pw.print(" h="); pw.print(mRequestedHeight);
7704 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007705 if (mXOffset != 0 || mYOffset != 0) {
7706 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
7707 pw.print(" y="); pw.println(mYOffset);
7708 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007709 pw.print(prefix); pw.print("mGivenContentInsets=");
7710 mGivenContentInsets.printShortString(pw);
7711 pw.print(" mGivenVisibleInsets=");
7712 mGivenVisibleInsets.printShortString(pw);
7713 pw.println();
7714 if (mTouchableInsets != 0 || mGivenInsetsPending) {
7715 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
7716 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
7717 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08007718 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007719 pw.print(prefix); pw.print("mShownFrame=");
7720 mShownFrame.printShortString(pw);
7721 pw.print(" last="); mLastShownFrame.printShortString(pw);
7722 pw.println();
7723 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
7724 pw.print(" last="); mLastFrame.printShortString(pw);
7725 pw.println();
7726 pw.print(prefix); pw.print("mContainingFrame=");
7727 mContainingFrame.printShortString(pw);
7728 pw.print(" mDisplayFrame=");
7729 mDisplayFrame.printShortString(pw);
7730 pw.println();
7731 pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw);
7732 pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw);
7733 pw.println();
7734 pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw);
7735 pw.print(" last="); mLastContentInsets.printShortString(pw);
7736 pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw);
7737 pw.print(" last="); mLastVisibleInsets.printShortString(pw);
7738 pw.println();
7739 if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
7740 pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
7741 pw.print(" mAlpha="); pw.print(mAlpha);
7742 pw.print(" mLastAlpha="); pw.println(mLastAlpha);
7743 }
7744 if (mAnimating || mLocalAnimating || mAnimationIsEntrance
7745 || mAnimation != null) {
7746 pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
7747 pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
7748 pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
7749 pw.print(" mAnimation="); pw.println(mAnimation);
7750 }
7751 if (mHasTransformation || mHasLocalTransformation) {
7752 pw.print(prefix); pw.print("XForm: has=");
7753 pw.print(mHasTransformation);
7754 pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
7755 pw.print(" "); mTransformation.printShortString(pw);
7756 pw.println();
7757 }
7758 pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending);
7759 pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending);
7760 pw.print(" mReadyToShow="); pw.print(mReadyToShow);
7761 pw.print(" mHasDrawn="); pw.println(mHasDrawn);
7762 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
7763 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
7764 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
7765 pw.print(" mDestroying="); pw.print(mDestroying);
7766 pw.print(" mRemoved="); pw.println(mRemoved);
7767 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007768 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007769 pw.print(prefix); pw.print("mOrientationChanging=");
7770 pw.print(mOrientationChanging);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07007771 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
7772 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007773 }
Mitsuru Oshima589cebe2009-07-22 20:38:58 -07007774 if (mHScale != 1 || mVScale != 1) {
7775 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
7776 pw.print(" mVScale="); pw.println(mVScale);
7777 }
Dianne Hackborn72c82ab2009-08-11 21:13:54 -07007778 if (mWallpaperX != -1 || mWallpaperY != -1) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07007779 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
7780 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
7781 }
Marco Nelissenbf6956b2009-11-09 15:21:13 -08007782 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
7783 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
7784 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
7785 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007786 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07007787
7788 String makeInputChannelName() {
7789 return Integer.toHexString(System.identityHashCode(this))
7790 + " " + mAttrs.getTitle();
7791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007792
7793 @Override
7794 public String toString() {
7795 return "Window{"
7796 + Integer.toHexString(System.identityHashCode(this))
7797 + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
7798 }
7799 }
Romain Guy06882f82009-06-10 13:36:04 -07007800
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007801 // -------------------------------------------------------------
7802 // Window Token State
7803 // -------------------------------------------------------------
7804
7805 class WindowToken {
7806 // The actual token.
7807 final IBinder token;
7808
7809 // The type of window this token is for, as per WindowManager.LayoutParams.
7810 final int windowType;
Romain Guy06882f82009-06-10 13:36:04 -07007811
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007812 // Set if this token was explicitly added by a client, so should
7813 // not be removed when all windows are removed.
7814 final boolean explicit;
Romain Guy06882f82009-06-10 13:36:04 -07007815
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007816 // For printing.
7817 String stringName;
Romain Guy06882f82009-06-10 13:36:04 -07007818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007819 // If this is an AppWindowToken, this is non-null.
7820 AppWindowToken appWindowToken;
Romain Guy06882f82009-06-10 13:36:04 -07007821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007822 // All of the windows associated with this token.
7823 final ArrayList<WindowState> windows = new ArrayList<WindowState>();
7824
7825 // Is key dispatching paused for this token?
7826 boolean paused = false;
7827
7828 // Should this token's windows be hidden?
7829 boolean hidden;
7830
7831 // Temporary for finding which tokens no longer have visible windows.
7832 boolean hasVisible;
7833
Dianne Hackborna8f60182009-09-01 19:01:50 -07007834 // Set to true when this token is in a pending transaction where it
7835 // will be shown.
7836 boolean waitingToShow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007837
Dianne Hackborna8f60182009-09-01 19:01:50 -07007838 // Set to true when this token is in a pending transaction where it
7839 // will be hidden.
7840 boolean waitingToHide;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007841
Dianne Hackborna8f60182009-09-01 19:01:50 -07007842 // Set to true when this token is in a pending transaction where its
7843 // windows will be put to the bottom of the list.
7844 boolean sendingToBottom;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007845
Dianne Hackborna8f60182009-09-01 19:01:50 -07007846 // Set to true when this token is in a pending transaction where its
7847 // windows will be put to the top of the list.
7848 boolean sendingToTop;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08007849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007850 WindowToken(IBinder _token, int type, boolean _explicit) {
7851 token = _token;
7852 windowType = type;
7853 explicit = _explicit;
7854 }
7855
7856 void dump(PrintWriter pw, String prefix) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007857 pw.print(prefix); pw.print("token="); pw.println(token);
7858 pw.print(prefix); pw.print("windows="); pw.println(windows);
7859 pw.print(prefix); pw.print("windowType="); pw.print(windowType);
7860 pw.print(" hidden="); pw.print(hidden);
7861 pw.print(" hasVisible="); pw.println(hasVisible);
Dianne Hackborna8f60182009-09-01 19:01:50 -07007862 if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) {
7863 pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow);
7864 pw.print(" waitingToHide="); pw.print(waitingToHide);
7865 pw.print(" sendingToBottom="); pw.print(sendingToBottom);
7866 pw.print(" sendingToTop="); pw.println(sendingToTop);
7867 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007868 }
7869
7870 @Override
7871 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07007872 if (stringName == null) {
7873 StringBuilder sb = new StringBuilder();
7874 sb.append("WindowToken{");
7875 sb.append(Integer.toHexString(System.identityHashCode(this)));
7876 sb.append(" token="); sb.append(token); sb.append('}');
7877 stringName = sb.toString();
7878 }
7879 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007880 }
7881 };
7882
7883 class AppWindowToken extends WindowToken {
7884 // Non-null only for application tokens.
7885 final IApplicationToken appToken;
7886
7887 // All of the windows and child windows that are included in this
7888 // application token. Note this list is NOT sorted!
7889 final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>();
7890
7891 int groupId = -1;
7892 boolean appFullscreen;
7893 int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Jeff Brown349703e2010-06-22 01:27:15 -07007894
7895 // The input dispatching timeout for this application token in nanoseconds.
7896 long inputDispatchingTimeoutNanos;
Romain Guy06882f82009-06-10 13:36:04 -07007897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007898 // These are used for determining when all windows associated with
7899 // an activity have been drawn, so they can be made visible together
7900 // at the same time.
7901 int lastTransactionSequence = mTransactionSequence-1;
7902 int numInterestingWindows;
7903 int numDrawnWindows;
7904 boolean inPendingTransaction;
7905 boolean allDrawn;
Romain Guy06882f82009-06-10 13:36:04 -07007906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007907 // Is this token going to be hidden in a little while? If so, it
7908 // won't be taken into account for setting the screen orientation.
7909 boolean willBeHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007911 // Is this window's surface needed? This is almost like hidden, except
7912 // it will sometimes be true a little earlier: when the token has
7913 // been shown, but is still waiting for its app transition to execute
7914 // before making its windows shown.
7915 boolean hiddenRequested;
Romain Guy06882f82009-06-10 13:36:04 -07007916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007917 // Have we told the window clients to hide themselves?
7918 boolean clientHidden;
Romain Guy06882f82009-06-10 13:36:04 -07007919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007920 // Last visibility state we reported to the app token.
7921 boolean reportedVisible;
7922
7923 // Set to true when the token has been removed from the window mgr.
7924 boolean removed;
7925
7926 // Have we been asked to have this token keep the screen frozen?
7927 boolean freezingScreen;
Romain Guy06882f82009-06-10 13:36:04 -07007928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007929 boolean animating;
7930 Animation animation;
7931 boolean hasTransformation;
7932 final Transformation transformation = new Transformation();
Romain Guy06882f82009-06-10 13:36:04 -07007933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007934 // Offset to the window of all layers in the token, for use by
7935 // AppWindowToken animations.
7936 int animLayerAdjustment;
Romain Guy06882f82009-06-10 13:36:04 -07007937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007938 // Information about an application starting window if displayed.
7939 StartingData startingData;
7940 WindowState startingWindow;
7941 View startingView;
7942 boolean startingDisplayed;
7943 boolean startingMoved;
7944 boolean firstWindowDrawn;
7945
7946 AppWindowToken(IApplicationToken _token) {
7947 super(_token.asBinder(),
7948 WindowManager.LayoutParams.TYPE_APPLICATION, true);
7949 appWindowToken = this;
7950 appToken = _token;
7951 }
Romain Guy06882f82009-06-10 13:36:04 -07007952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007953 public void setAnimation(Animation anim) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007954 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007955 TAG, "Setting animation in " + this + ": " + anim);
7956 animation = anim;
7957 animating = false;
7958 anim.restrictDuration(MAX_ANIMATION_DURATION);
7959 anim.scaleCurrentDuration(mTransitionAnimationScale);
7960 int zorder = anim.getZAdjustment();
7961 int adj = 0;
7962 if (zorder == Animation.ZORDER_TOP) {
7963 adj = TYPE_LAYER_OFFSET;
7964 } else if (zorder == Animation.ZORDER_BOTTOM) {
7965 adj = -TYPE_LAYER_OFFSET;
7966 }
Romain Guy06882f82009-06-10 13:36:04 -07007967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007968 if (animLayerAdjustment != adj) {
7969 animLayerAdjustment = adj;
7970 updateLayers();
7971 }
7972 }
Romain Guy06882f82009-06-10 13:36:04 -07007973
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007974 public void setDummyAnimation() {
7975 if (animation == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08007976 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007977 TAG, "Setting dummy animation in " + this);
7978 animation = sDummyAnimation;
7979 }
7980 }
7981
7982 public void clearAnimation() {
7983 if (animation != null) {
7984 animation = null;
7985 animating = true;
7986 }
7987 }
Romain Guy06882f82009-06-10 13:36:04 -07007988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007989 void updateLayers() {
7990 final int N = allAppWindows.size();
7991 final int adj = animLayerAdjustment;
7992 for (int i=0; i<N; i++) {
7993 WindowState w = allAppWindows.get(i);
7994 w.mAnimLayer = w.mLayer + adj;
Joe Onorato8a9b2202010-02-26 18:56:32 -08007995 if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007996 + w.mAnimLayer);
7997 if (w == mInputMethodTarget) {
7998 setInputMethodAnimLayerAdjustment(adj);
7999 }
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008000 if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
Dianne Hackbornc8a0a752009-08-10 23:05:49 -07008001 setWallpaperAnimLayerAdjustmentLocked(adj);
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008002 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008003 }
8004 }
Romain Guy06882f82009-06-10 13:36:04 -07008005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008006 void sendAppVisibilityToClients() {
8007 final int N = allAppWindows.size();
8008 for (int i=0; i<N; i++) {
8009 WindowState win = allAppWindows.get(i);
8010 if (win == startingWindow && clientHidden) {
8011 // Don't hide the starting window.
8012 continue;
8013 }
8014 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008015 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008016 "Setting visibility of " + win + ": " + (!clientHidden));
8017 win.mClient.dispatchAppVisibility(!clientHidden);
8018 } catch (RemoteException e) {
8019 }
8020 }
8021 }
Romain Guy06882f82009-06-10 13:36:04 -07008022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008023 void showAllWindowsLocked() {
8024 final int NW = allAppWindows.size();
8025 for (int i=0; i<NW; i++) {
8026 WindowState w = allAppWindows.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008027 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008028 "performing show on: " + w);
8029 w.performShowLocked();
8030 }
8031 }
Romain Guy06882f82009-06-10 13:36:04 -07008032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008033 // This must be called while inside a transaction.
8034 boolean stepAnimationLocked(long currentTime, int dw, int dh) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08008035 if (!mDisplayFrozen && mPolicy.isScreenOn()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008036 // We will run animations as long as the display isn't frozen.
Romain Guy06882f82009-06-10 13:36:04 -07008037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008038 if (animation == sDummyAnimation) {
8039 // This guy is going to animate, but not yet. For now count
Dianne Hackborn3be63c02009-08-20 19:31:38 -07008040 // it as not animating for purposes of scheduling transactions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008041 // when it is really time to animate, this will be set to
8042 // a real animation and the next call will execute normally.
8043 return false;
8044 }
Romain Guy06882f82009-06-10 13:36:04 -07008045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008046 if ((allDrawn || animating || startingDisplayed) && animation != null) {
8047 if (!animating) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008048 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008049 TAG, "Starting animation in " + this +
8050 " @ " + currentTime + ": dw=" + dw + " dh=" + dh
8051 + " scale=" + mTransitionAnimationScale
8052 + " allDrawn=" + allDrawn + " animating=" + animating);
8053 animation.initialize(dw, dh, dw, dh);
8054 animation.setStartTime(currentTime);
8055 animating = true;
8056 }
8057 transformation.clear();
8058 final boolean more = animation.getTransformation(
8059 currentTime, transformation);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008060 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008061 TAG, "Stepped animation in " + this +
8062 ": more=" + more + ", xform=" + transformation);
8063 if (more) {
8064 // we're done!
8065 hasTransformation = true;
8066 return true;
8067 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008068 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008069 TAG, "Finished animation in " + this +
8070 " @ " + currentTime);
8071 animation = null;
8072 }
8073 } else if (animation != null) {
8074 // If the display is frozen, and there is a pending animation,
8075 // clear it and make sure we run the cleanup code.
8076 animating = true;
8077 animation = null;
8078 }
8079
8080 hasTransformation = false;
Romain Guy06882f82009-06-10 13:36:04 -07008081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008082 if (!animating) {
8083 return false;
8084 }
8085
8086 clearAnimation();
8087 animating = false;
8088 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) {
8089 moveInputMethodWindowsIfNeededLocked(true);
8090 }
Romain Guy06882f82009-06-10 13:36:04 -07008091
Joe Onorato8a9b2202010-02-26 18:56:32 -08008092 if (DEBUG_ANIM) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008093 TAG, "Animation done in " + this
8094 + ": reportedVisible=" + reportedVisible);
8095
8096 transformation.clear();
8097 if (animLayerAdjustment != 0) {
8098 animLayerAdjustment = 0;
8099 updateLayers();
8100 }
Romain Guy06882f82009-06-10 13:36:04 -07008101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008102 final int N = windows.size();
8103 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008104 windows.get(i).finishExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008105 }
8106 updateReportedVisibilityLocked();
Romain Guy06882f82009-06-10 13:36:04 -07008107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008108 return false;
8109 }
8110
8111 void updateReportedVisibilityLocked() {
8112 if (appToken == null) {
8113 return;
8114 }
Romain Guy06882f82009-06-10 13:36:04 -07008115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008116 int numInteresting = 0;
8117 int numVisible = 0;
8118 boolean nowGone = true;
Romain Guy06882f82009-06-10 13:36:04 -07008119
Joe Onorato8a9b2202010-02-26 18:56:32 -08008120 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008121 final int N = allAppWindows.size();
8122 for (int i=0; i<N; i++) {
8123 WindowState win = allAppWindows.get(i);
Dianne Hackborn6cf67fa2009-12-21 16:46:34 -08008124 if (win == startingWindow || win.mAppFreezing
The Android Open Source Project727cec02010-04-08 11:35:37 -07008125 || win.mViewVisibility != View.VISIBLE
Ulf Rosdahl39357702010-09-29 12:34:38 +02008126 || win.mAttrs.type == TYPE_APPLICATION_STARTING
8127 || win.mDestroying) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008128 continue;
8129 }
8130 if (DEBUG_VISIBILITY) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008131 Slog.v(TAG, "Win " + win + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008132 + win.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008133 + ", isAnimating=" + win.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008134 if (!win.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008135 Slog.v(TAG, "Not displayed: s=" + win.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008136 + " pv=" + win.mPolicyVisibility
8137 + " dp=" + win.mDrawPending
8138 + " cdp=" + win.mCommitDrawPending
8139 + " ah=" + win.mAttachedHidden
8140 + " th="
8141 + (win.mAppToken != null
8142 ? win.mAppToken.hiddenRequested : false)
8143 + " a=" + win.mAnimating);
8144 }
8145 }
8146 numInteresting++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07008147 if (win.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008148 if (!win.isAnimating()) {
8149 numVisible++;
8150 }
8151 nowGone = false;
8152 } else if (win.isAnimating()) {
8153 nowGone = false;
8154 }
8155 }
Romain Guy06882f82009-06-10 13:36:04 -07008156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008157 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008158 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008159 + numInteresting + " visible=" + numVisible);
8160 if (nowVisible != reportedVisible) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008161 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008162 TAG, "Visibility changed in " + this
8163 + ": vis=" + nowVisible);
8164 reportedVisible = nowVisible;
8165 Message m = mH.obtainMessage(
8166 H.REPORT_APPLICATION_TOKEN_WINDOWS,
8167 nowVisible ? 1 : 0,
8168 nowGone ? 1 : 0,
8169 this);
8170 mH.sendMessage(m);
8171 }
8172 }
Romain Guy06882f82009-06-10 13:36:04 -07008173
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07008174 WindowState findMainWindow() {
8175 int j = windows.size();
8176 while (j > 0) {
8177 j--;
8178 WindowState win = windows.get(j);
8179 if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
8180 || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
8181 return win;
8182 }
8183 }
8184 return null;
8185 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008187 void dump(PrintWriter pw, String prefix) {
8188 super.dump(pw, prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008189 if (appToken != null) {
8190 pw.print(prefix); pw.println("app=true");
8191 }
8192 if (allAppWindows.size() > 0) {
8193 pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
8194 }
8195 pw.print(prefix); pw.print("groupId="); pw.print(groupId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008196 pw.print(" appFullscreen="); pw.print(appFullscreen);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008197 pw.print(" requestedOrientation="); pw.println(requestedOrientation);
8198 pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
8199 pw.print(" clientHidden="); pw.print(clientHidden);
8200 pw.print(" willBeHidden="); pw.print(willBeHidden);
8201 pw.print(" reportedVisible="); pw.println(reportedVisible);
8202 if (paused || freezingScreen) {
8203 pw.print(prefix); pw.print("paused="); pw.print(paused);
8204 pw.print(" freezingScreen="); pw.println(freezingScreen);
8205 }
8206 if (numInterestingWindows != 0 || numDrawnWindows != 0
8207 || inPendingTransaction || allDrawn) {
8208 pw.print(prefix); pw.print("numInterestingWindows=");
8209 pw.print(numInterestingWindows);
8210 pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
8211 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
8212 pw.print(" allDrawn="); pw.println(allDrawn);
8213 }
8214 if (animating || animation != null) {
8215 pw.print(prefix); pw.print("animating="); pw.print(animating);
8216 pw.print(" animation="); pw.println(animation);
8217 }
8218 if (animLayerAdjustment != 0) {
8219 pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment);
8220 }
8221 if (hasTransformation) {
8222 pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation);
8223 pw.print(" transformation="); transformation.printShortString(pw);
8224 pw.println();
8225 }
8226 if (startingData != null || removed || firstWindowDrawn) {
8227 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
8228 pw.print(" removed="); pw.print(removed);
8229 pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
8230 }
8231 if (startingWindow != null || startingView != null
8232 || startingDisplayed || startingMoved) {
8233 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
8234 pw.print(" startingView="); pw.print(startingView);
8235 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
8236 pw.print(" startingMoved"); pw.println(startingMoved);
8237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008238 }
8239
8240 @Override
8241 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07008242 if (stringName == null) {
8243 StringBuilder sb = new StringBuilder();
8244 sb.append("AppWindowToken{");
8245 sb.append(Integer.toHexString(System.identityHashCode(this)));
8246 sb.append(" token="); sb.append(token); sb.append('}');
8247 stringName = sb.toString();
8248 }
8249 return stringName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008250 }
8251 }
Romain Guy06882f82009-06-10 13:36:04 -07008252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008253 // -------------------------------------------------------------
8254 // DummyAnimation
8255 // -------------------------------------------------------------
8256
8257 // This is an animation that does nothing: it just immediately finishes
8258 // itself every time it is called. It is used as a stub animation in cases
8259 // where we want to synchronize multiple things that may be animating.
8260 static final class DummyAnimation extends Animation {
8261 public boolean getTransformation(long currentTime, Transformation outTransformation) {
8262 return false;
8263 }
8264 }
8265 static final Animation sDummyAnimation = new DummyAnimation();
Romain Guy06882f82009-06-10 13:36:04 -07008266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008267 // -------------------------------------------------------------
8268 // Async Handler
8269 // -------------------------------------------------------------
8270
8271 static final class StartingData {
8272 final String pkg;
8273 final int theme;
8274 final CharSequence nonLocalizedLabel;
8275 final int labelRes;
8276 final int icon;
Romain Guy06882f82009-06-10 13:36:04 -07008277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008278 StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel,
8279 int _labelRes, int _icon) {
8280 pkg = _pkg;
8281 theme = _theme;
8282 nonLocalizedLabel = _nonLocalizedLabel;
8283 labelRes = _labelRes;
8284 icon = _icon;
8285 }
8286 }
8287
8288 private final class H extends Handler {
8289 public static final int REPORT_FOCUS_CHANGE = 2;
8290 public static final int REPORT_LOSING_FOCUS = 3;
8291 public static final int ANIMATE = 4;
8292 public static final int ADD_STARTING = 5;
8293 public static final int REMOVE_STARTING = 6;
8294 public static final int FINISHED_STARTING = 7;
8295 public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008296 public static final int WINDOW_FREEZE_TIMEOUT = 11;
8297 public static final int HOLD_SCREEN_CHANGED = 12;
8298 public static final int APP_TRANSITION_TIMEOUT = 13;
8299 public static final int PERSIST_ANIMATION_SCALE = 14;
8300 public static final int FORCE_GC = 15;
8301 public static final int ENABLE_SCREEN = 16;
8302 public static final int APP_FREEZE_TIMEOUT = 17;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008303 public static final int SEND_NEW_CONFIGURATION = 18;
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008304 public static final int REPORT_WINDOWS_CHANGE = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -07008305 public static final int DRAG_START_TIMEOUT = 20;
Romain Guy06882f82009-06-10 13:36:04 -07008306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008307 private Session mLastReportedHold;
Romain Guy06882f82009-06-10 13:36:04 -07008308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008309 public H() {
8310 }
Romain Guy06882f82009-06-10 13:36:04 -07008311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008312 @Override
8313 public void handleMessage(Message msg) {
8314 switch (msg.what) {
8315 case REPORT_FOCUS_CHANGE: {
8316 WindowState lastFocus;
8317 WindowState newFocus;
Romain Guy06882f82009-06-10 13:36:04 -07008318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008319 synchronized(mWindowMap) {
8320 lastFocus = mLastFocus;
8321 newFocus = mCurrentFocus;
8322 if (lastFocus == newFocus) {
8323 // Focus is not changing, so nothing to do.
8324 return;
8325 }
8326 mLastFocus = newFocus;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008327 //Slog.i(TAG, "Focus moving from " + lastFocus
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008328 // + " to " + newFocus);
8329 if (newFocus != null && lastFocus != null
8330 && !newFocus.isDisplayedLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008331 //Slog.i(TAG, "Delaying loss of focus...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008332 mLosingFocus.add(lastFocus);
8333 lastFocus = null;
8334 }
8335 }
8336
8337 if (lastFocus != newFocus) {
8338 //System.out.println("Changing focus from " + lastFocus
8339 // + " to " + newFocus);
8340 if (newFocus != null) {
8341 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008342 //Slog.i(TAG, "Gaining focus: " + newFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008343 newFocus.mClient.windowFocusChanged(true, mInTouchMode);
8344 } catch (RemoteException e) {
8345 // Ignore if process has died.
8346 }
Konstantin Lopyrev5e7833a2010-08-09 17:01:11 -07008347 notifyFocusChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008348 }
8349
8350 if (lastFocus != null) {
8351 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008352 //Slog.i(TAG, "Losing focus: " + lastFocus);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008353 lastFocus.mClient.windowFocusChanged(false, mInTouchMode);
8354 } catch (RemoteException e) {
8355 // Ignore if process has died.
8356 }
8357 }
8358 }
8359 } break;
8360
8361 case REPORT_LOSING_FOCUS: {
8362 ArrayList<WindowState> losers;
Romain Guy06882f82009-06-10 13:36:04 -07008363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008364 synchronized(mWindowMap) {
8365 losers = mLosingFocus;
8366 mLosingFocus = new ArrayList<WindowState>();
8367 }
8368
8369 final int N = losers.size();
8370 for (int i=0; i<N; i++) {
8371 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008372 //Slog.i(TAG, "Losing delayed focus: " + losers.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008373 losers.get(i).mClient.windowFocusChanged(false, mInTouchMode);
8374 } catch (RemoteException e) {
8375 // Ignore if process has died.
8376 }
8377 }
8378 } break;
8379
8380 case ANIMATE: {
8381 synchronized(mWindowMap) {
8382 mAnimationPending = false;
8383 performLayoutAndPlaceSurfacesLocked();
8384 }
8385 } break;
8386
8387 case ADD_STARTING: {
8388 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8389 final StartingData sd = wtoken.startingData;
8390
8391 if (sd == null) {
8392 // Animation has been canceled... do nothing.
8393 return;
8394 }
Romain Guy06882f82009-06-10 13:36:04 -07008395
Joe Onorato8a9b2202010-02-26 18:56:32 -08008396 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008397 + wtoken + ": pkg=" + sd.pkg);
Romain Guy06882f82009-06-10 13:36:04 -07008398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008399 View view = null;
8400 try {
8401 view = mPolicy.addStartingWindow(
8402 wtoken.token, sd.pkg,
8403 sd.theme, sd.nonLocalizedLabel, sd.labelRes,
8404 sd.icon);
8405 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008406 Slog.w(TAG, "Exception when adding starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008407 }
8408
8409 if (view != null) {
8410 boolean abort = false;
8411
8412 synchronized(mWindowMap) {
8413 if (wtoken.removed || wtoken.startingData == null) {
8414 // If the window was successfully added, then
8415 // we need to remove it.
8416 if (wtoken.startingWindow != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008417 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008418 "Aborted starting " + wtoken
8419 + ": removed=" + wtoken.removed
8420 + " startingData=" + wtoken.startingData);
8421 wtoken.startingWindow = null;
8422 wtoken.startingData = null;
8423 abort = true;
8424 }
8425 } else {
8426 wtoken.startingView = view;
8427 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008428 if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008429 "Added starting " + wtoken
8430 + ": startingWindow="
8431 + wtoken.startingWindow + " startingView="
8432 + wtoken.startingView);
8433 }
8434
8435 if (abort) {
8436 try {
8437 mPolicy.removeStartingWindow(wtoken.token, view);
8438 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008439 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008440 }
8441 }
8442 }
8443 } break;
8444
8445 case REMOVE_STARTING: {
8446 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8447 IBinder token = null;
8448 View view = null;
8449 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008450 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008451 + wtoken + ": startingWindow="
8452 + wtoken.startingWindow + " startingView="
8453 + wtoken.startingView);
8454 if (wtoken.startingWindow != null) {
8455 view = wtoken.startingView;
8456 token = wtoken.token;
8457 wtoken.startingData = null;
8458 wtoken.startingView = null;
8459 wtoken.startingWindow = null;
8460 }
8461 }
8462 if (view != null) {
8463 try {
8464 mPolicy.removeStartingWindow(token, view);
8465 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008466 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008467 }
8468 }
8469 } break;
8470
8471 case FINISHED_STARTING: {
8472 IBinder token = null;
8473 View view = null;
8474 while (true) {
8475 synchronized (mWindowMap) {
8476 final int N = mFinishedStarting.size();
8477 if (N <= 0) {
8478 break;
8479 }
8480 AppWindowToken wtoken = mFinishedStarting.remove(N-1);
8481
Joe Onorato8a9b2202010-02-26 18:56:32 -08008482 if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008483 "Finished starting " + wtoken
8484 + ": startingWindow=" + wtoken.startingWindow
8485 + " startingView=" + wtoken.startingView);
8486
8487 if (wtoken.startingWindow == null) {
8488 continue;
8489 }
8490
8491 view = wtoken.startingView;
8492 token = wtoken.token;
8493 wtoken.startingData = null;
8494 wtoken.startingView = null;
8495 wtoken.startingWindow = null;
8496 }
8497
8498 try {
8499 mPolicy.removeStartingWindow(token, view);
8500 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008501 Slog.w(TAG, "Exception when removing starting window", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008502 }
8503 }
8504 } break;
8505
8506 case REPORT_APPLICATION_TOKEN_WINDOWS: {
8507 final AppWindowToken wtoken = (AppWindowToken)msg.obj;
8508
8509 boolean nowVisible = msg.arg1 != 0;
8510 boolean nowGone = msg.arg2 != 0;
8511
8512 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008513 if (DEBUG_VISIBILITY) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008514 TAG, "Reporting visible in " + wtoken
8515 + " visible=" + nowVisible
8516 + " gone=" + nowGone);
8517 if (nowVisible) {
8518 wtoken.appToken.windowsVisible();
8519 } else {
8520 wtoken.appToken.windowsGone();
8521 }
8522 } catch (RemoteException ex) {
8523 }
8524 } break;
Romain Guy06882f82009-06-10 13:36:04 -07008525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008526 case WINDOW_FREEZE_TIMEOUT: {
8527 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008528 Slog.w(TAG, "Window freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008529 int i = mWindows.size();
8530 while (i > 0) {
8531 i--;
Jeff Browne33348b2010-07-15 23:54:05 -07008532 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008533 if (w.mOrientationChanging) {
8534 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008535 Slog.w(TAG, "Force clearing orientation change: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008536 }
8537 }
8538 performLayoutAndPlaceSurfacesLocked();
8539 }
8540 break;
8541 }
Romain Guy06882f82009-06-10 13:36:04 -07008542
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008543 case HOLD_SCREEN_CHANGED: {
8544 Session oldHold;
8545 Session newHold;
8546 synchronized (mWindowMap) {
8547 oldHold = mLastReportedHold;
8548 newHold = (Session)msg.obj;
8549 mLastReportedHold = newHold;
8550 }
Romain Guy06882f82009-06-10 13:36:04 -07008551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008552 if (oldHold != newHold) {
8553 try {
8554 if (oldHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008555 mBatteryStats.noteStopWakelock(oldHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008556 "window",
8557 BatteryStats.WAKE_TYPE_WINDOW);
8558 }
8559 if (newHold != null) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07008560 mBatteryStats.noteStartWakelock(newHold.mUid, -1,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008561 "window",
8562 BatteryStats.WAKE_TYPE_WINDOW);
8563 }
8564 } catch (RemoteException e) {
8565 }
8566 }
8567 break;
8568 }
Romain Guy06882f82009-06-10 13:36:04 -07008569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008570 case APP_TRANSITION_TIMEOUT: {
8571 synchronized (mWindowMap) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07008572 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008573 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008574 "*** APP TRANSITION TIMEOUT");
8575 mAppTransitionReady = true;
8576 mAppTransitionTimeout = true;
8577 performLayoutAndPlaceSurfacesLocked();
8578 }
8579 }
8580 break;
8581 }
Romain Guy06882f82009-06-10 13:36:04 -07008582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008583 case PERSIST_ANIMATION_SCALE: {
8584 Settings.System.putFloat(mContext.getContentResolver(),
8585 Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
8586 Settings.System.putFloat(mContext.getContentResolver(),
8587 Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
8588 break;
8589 }
Romain Guy06882f82009-06-10 13:36:04 -07008590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008591 case FORCE_GC: {
8592 synchronized(mWindowMap) {
8593 if (mAnimationPending) {
8594 // If we are animating, don't do the gc now but
8595 // delay a bit so we don't interrupt the animation.
8596 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
8597 2000);
8598 return;
8599 }
8600 // If we are currently rotating the display, it will
8601 // schedule a new message when done.
8602 if (mDisplayFrozen) {
8603 return;
8604 }
8605 mFreezeGcPending = 0;
8606 }
8607 Runtime.getRuntime().gc();
8608 break;
8609 }
Romain Guy06882f82009-06-10 13:36:04 -07008610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008611 case ENABLE_SCREEN: {
8612 performEnableScreen();
8613 break;
8614 }
Romain Guy06882f82009-06-10 13:36:04 -07008615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008616 case APP_FREEZE_TIMEOUT: {
8617 synchronized (mWindowMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008618 Slog.w(TAG, "App freeze timeout expired.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008619 int i = mAppTokens.size();
8620 while (i > 0) {
8621 i--;
8622 AppWindowToken tok = mAppTokens.get(i);
8623 if (tok.freezingScreen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008624 Slog.w(TAG, "Force clearing freeze: " + tok);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008625 unsetAppFreezingScreenLocked(tok, true, true);
8626 }
8627 }
8628 }
8629 break;
8630 }
Romain Guy06882f82009-06-10 13:36:04 -07008631
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008632 case SEND_NEW_CONFIGURATION: {
8633 removeMessages(SEND_NEW_CONFIGURATION);
8634 sendNewConfiguration();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07008635 break;
8636 }
Romain Guy06882f82009-06-10 13:36:04 -07008637
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008638 case REPORT_WINDOWS_CHANGE: {
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008639 if (mWindowsChanged) {
8640 synchronized (mWindowMap) {
8641 mWindowsChanged = false;
8642 }
8643 notifyWindowsChanged();
8644 }
8645 break;
8646 }
8647
Christopher Tatea53146c2010-09-07 11:57:52 -07008648 case DRAG_START_TIMEOUT: {
8649 IBinder win = (IBinder)msg.obj;
8650 if (DEBUG_DRAG) {
8651 Slog.w(TAG, "Timeout starting drag by win " + win);
8652 }
8653 synchronized (mWindowMap) {
8654 // !!! TODO: ANR the app that has failed to start the drag in time
8655 if (mDragState != null) {
8656 mDragState.reset();
8657 mDragState = null;
8658 }
8659 }
8660 }
8661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008662 }
8663 }
8664 }
8665
8666 // -------------------------------------------------------------
8667 // IWindowManager API
8668 // -------------------------------------------------------------
8669
8670 public IWindowSession openSession(IInputMethodClient client,
8671 IInputContext inputContext) {
8672 if (client == null) throw new IllegalArgumentException("null client");
8673 if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07008674 Session session = new Session(client, inputContext);
8675 return session;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008676 }
8677
8678 public boolean inputMethodClientHasFocus(IInputMethodClient client) {
8679 synchronized (mWindowMap) {
8680 // The focus for the client is the window immediately below
8681 // where we would place the input method window.
8682 int idx = findDesiredInputMethodWindowIndexLocked(false);
8683 WindowState imFocus;
8684 if (idx > 0) {
Jeff Browne33348b2010-07-15 23:54:05 -07008685 imFocus = mWindows.get(idx-1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008686 if (imFocus != null) {
8687 if (imFocus.mSession.mClient != null &&
8688 imFocus.mSession.mClient.asBinder() == client.asBinder()) {
8689 return true;
8690 }
8691 }
8692 }
8693 }
8694 return false;
8695 }
Romain Guy06882f82009-06-10 13:36:04 -07008696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008697 // -------------------------------------------------------------
8698 // Internals
8699 // -------------------------------------------------------------
8700
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008701 final WindowState windowForClientLocked(Session session, IWindow client,
8702 boolean throwOnError) {
8703 return windowForClientLocked(session, client.asBinder(), throwOnError);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008704 }
Romain Guy06882f82009-06-10 13:36:04 -07008705
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008706 final WindowState windowForClientLocked(Session session, IBinder client,
8707 boolean throwOnError) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008708 WindowState win = mWindowMap.get(client);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008709 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008710 TAG, "Looking up client " + client + ": " + win);
8711 if (win == null) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008712 RuntimeException ex = new IllegalArgumentException(
8713 "Requested window " + client + " does not exist");
8714 if (throwOnError) {
8715 throw ex;
8716 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008717 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008718 return null;
8719 }
8720 if (session != null && win.mSession != session) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008721 RuntimeException ex = new IllegalArgumentException(
8722 "Requested window " + client + " is in session " +
8723 win.mSession + ", not " + session);
8724 if (throwOnError) {
8725 throw ex;
8726 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008727 Slog.w(TAG, "Failed looking up window", ex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008728 return null;
8729 }
8730
8731 return win;
8732 }
8733
Dianne Hackborna8f60182009-09-01 19:01:50 -07008734 final void rebuildAppWindowListLocked() {
8735 int NW = mWindows.size();
8736 int i;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008737 int lastWallpaper = -1;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008738 int numRemoved = 0;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008739
Dianne Hackborna8f60182009-09-01 19:01:50 -07008740 // First remove all existing app windows.
8741 i=0;
8742 while (i < NW) {
Jeff Browne33348b2010-07-15 23:54:05 -07008743 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008744 if (w.mAppToken != null) {
Jeff Browne33348b2010-07-15 23:54:05 -07008745 WindowState win = mWindows.remove(i);
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008746 mWindowsChanged = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008747 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008748 "Rebuild removing window: " + win);
Dianne Hackborna8f60182009-09-01 19:01:50 -07008749 NW--;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008750 numRemoved++;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008751 continue;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008752 } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER
8753 && lastWallpaper == i-1) {
8754 lastWallpaper = i;
Dianne Hackborna8f60182009-09-01 19:01:50 -07008755 }
8756 i++;
8757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008758
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008759 // The wallpaper window(s) typically live at the bottom of the stack,
8760 // so skip them before adding app tokens.
8761 lastWallpaper++;
8762 i = lastWallpaper;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008763
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008764 // First add all of the exiting app tokens... these are no longer
8765 // in the main app list, but still have windows shown. We put them
8766 // in the back because now that the animation is over we no longer
8767 // will care about them.
8768 int NT = mExitingAppTokens.size();
Dianne Hackborna8f60182009-09-01 19:01:50 -07008769 for (int j=0; j<NT; j++) {
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008770 i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j));
8771 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008772
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07008773 // And add in the still active app tokens in Z order.
8774 NT = mAppTokens.size();
8775 for (int j=0; j<NT; j++) {
8776 i = reAddAppWindowsLocked(i, mAppTokens.get(j));
Dianne Hackborna8f60182009-09-01 19:01:50 -07008777 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008778
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07008779 i -= lastWallpaper;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008780 if (i != numRemoved) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08008781 Slog.w(TAG, "Rebuild removed " + numRemoved
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008782 + " windows but added " + i);
8783 }
Dianne Hackborna8f60182009-09-01 19:01:50 -07008784 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008786 private final void assignLayersLocked() {
8787 int N = mWindows.size();
8788 int curBaseLayer = 0;
8789 int curLayer = 0;
8790 int i;
Romain Guy06882f82009-06-10 13:36:04 -07008791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008792 for (i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -07008793 WindowState w = mWindows.get(i);
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07008794 if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
8795 || (i > 0 && w.mIsWallpaper)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008796 curLayer += WINDOW_LAYER_MULTIPLIER;
8797 w.mLayer = curLayer;
8798 } else {
8799 curBaseLayer = curLayer = w.mBaseLayer;
8800 w.mLayer = curLayer;
8801 }
8802 if (w.mTargetAppToken != null) {
8803 w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment;
8804 } else if (w.mAppToken != null) {
8805 w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment;
8806 } else {
8807 w.mAnimLayer = w.mLayer;
8808 }
8809 if (w.mIsImWindow) {
8810 w.mAnimLayer += mInputMethodAnimLayerAdjustment;
Dianne Hackborn759a39e2009-08-09 17:20:27 -07008811 } else if (w.mIsWallpaper) {
8812 w.mAnimLayer += mWallpaperAnimLayerAdjustment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008813 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008814 if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008815 + w.mAnimLayer);
8816 //System.out.println(
8817 // "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
8818 }
8819 }
8820
8821 private boolean mInLayout = false;
8822 private final void performLayoutAndPlaceSurfacesLocked() {
8823 if (mInLayout) {
Dave Bortcfe65242009-04-09 14:51:04 -07008824 if (DEBUG) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008825 throw new RuntimeException("Recursive call!");
8826 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08008827 Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008828 return;
8829 }
8830
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008831 if (mWaitingForConfig) {
8832 // Our configuration has changed (most likely rotation), but we
8833 // don't yet have the complete configuration to report to
8834 // applications. Don't do any window layout until we have it.
8835 return;
8836 }
8837
Dianne Hackbornce2ef762010-09-20 11:39:14 -07008838 if (mDisplay == null) {
8839 // Not yet initialized, nothing to do.
8840 return;
8841 }
8842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008843 boolean recoveringMemory = false;
8844 if (mForceRemoves != null) {
8845 recoveringMemory = true;
8846 // Wait a little it for things to settle down, and off we go.
8847 for (int i=0; i<mForceRemoves.size(); i++) {
8848 WindowState ws = mForceRemoves.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08008849 Slog.i(TAG, "Force removing: " + ws);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008850 removeWindowInnerLocked(ws.mSession, ws);
8851 }
8852 mForceRemoves = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008853 Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008854 Object tmp = new Object();
8855 synchronized (tmp) {
8856 try {
8857 tmp.wait(250);
8858 } catch (InterruptedException e) {
8859 }
8860 }
8861 }
Romain Guy06882f82009-06-10 13:36:04 -07008862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008863 mInLayout = true;
8864 try {
8865 performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
Romain Guy06882f82009-06-10 13:36:04 -07008866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008867 int i = mPendingRemove.size()-1;
8868 if (i >= 0) {
8869 while (i >= 0) {
8870 WindowState w = mPendingRemove.get(i);
8871 removeWindowInnerLocked(w.mSession, w);
8872 i--;
8873 }
8874 mPendingRemove.clear();
8875
8876 mInLayout = false;
8877 assignLayersLocked();
8878 mLayoutNeeded = true;
8879 performLayoutAndPlaceSurfacesLocked();
8880
8881 } else {
8882 mInLayout = false;
8883 if (mLayoutNeeded) {
8884 requestAnimationLocked(0);
8885 }
8886 }
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008887 if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
Konstantin Lopyrev6e0f65f2010-07-14 14:55:33 -07008888 mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
8889 mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE));
Konstantin Lopyrevdc301012010-07-08 17:55:51 -07008890 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008891 } catch (RuntimeException e) {
8892 mInLayout = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08008893 Slog.e(TAG, "Unhandled exception while layout out windows", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008894 }
8895 }
8896
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008897 private final int performLayoutLockedInner() {
8898 if (!mLayoutNeeded) {
8899 return 0;
8900 }
8901
8902 mLayoutNeeded = false;
8903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008904 final int dw = mDisplay.getWidth();
8905 final int dh = mDisplay.getHeight();
8906
8907 final int N = mWindows.size();
8908 int i;
8909
Joe Onorato8a9b2202010-02-26 18:56:32 -08008910 if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed="
Dianne Hackborn9b52a212009-12-11 14:51:35 -08008911 + mLayoutNeeded + " dw=" + dw + " dh=" + dh);
8912
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008913 mPolicy.beginLayoutLw(dw, dh);
Romain Guy06882f82009-06-10 13:36:04 -07008914
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008915 int seq = mLayoutSeq+1;
8916 if (seq < 0) seq = 0;
8917 mLayoutSeq = seq;
8918
8919 // First perform layout of any root windows (not attached
8920 // to another window).
8921 int topAttached = -1;
8922 for (i = N-1; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008923 WindowState win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008924
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008925 // Don't do layout of a window if it is not visible, or
8926 // soon won't be visible, to avoid wasting time and funky
8927 // changes while a window is animating away.
8928 final AppWindowToken atoken = win.mAppToken;
8929 final boolean gone = win.mViewVisibility == View.GONE
8930 || !win.mRelayoutCalled
8931 || win.mRootToken.hidden
8932 || (atoken != null && atoken.hiddenRequested)
8933 || win.mAttachedHidden
8934 || win.mExiting || win.mDestroying;
8935
8936 if (!win.mLayoutAttached) {
8937 if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win
8938 + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
8939 + " mLayoutAttached=" + win.mLayoutAttached);
8940 if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility="
8941 + win.mViewVisibility + " mRelayoutCalled="
8942 + win.mRelayoutCalled + " hidden="
8943 + win.mRootToken.hidden + " hiddenRequested="
8944 + (atoken != null && atoken.hiddenRequested)
8945 + " mAttachedHidden=" + win.mAttachedHidden);
8946 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008947
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008948 // If this view is GONE, then skip it -- keep the current
8949 // frame, and let the caller know so they can ignore it
8950 // if they want. (We do the normal layout for INVISIBLE
8951 // windows, since that means "perform layout as normal,
8952 // just don't display").
8953 if (!gone || !win.mHaveFrame) {
Dianne Hackborne36d6e22010-02-17 19:46:25 -08008954 if (!win.mLayoutAttached) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008955 mPolicy.layoutWindowLw(win, win.mAttrs, null);
8956 win.mLayoutSeq = seq;
8957 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8958 + win.mFrame + " mContainingFrame="
8959 + win.mContainingFrame + " mDisplayFrame="
8960 + win.mDisplayFrame);
8961 } else {
8962 if (topAttached < 0) topAttached = i;
Dianne Hackborn9bfb7072009-09-22 11:37:40 -07008963 }
Dianne Hackborn958b9ad2009-03-31 18:00:36 -07008964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008965 }
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008966
8967 // Now perform layout of attached windows, which usually
8968 // depend on the position of the window they are attached to.
8969 // XXX does not deal with windows that are attached to windows
8970 // that are themselves attached.
8971 for (i = topAttached; i >= 0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07008972 WindowState win = mWindows.get(i);
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008973
8974 // If this view is GONE, then skip it -- keep the current
8975 // frame, and let the caller know so they can ignore it
8976 // if they want. (We do the normal layout for INVISIBLE
8977 // windows, since that means "perform layout as normal,
8978 // just don't display").
8979 if (win.mLayoutAttached) {
8980 if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win
8981 + " mHaveFrame=" + win.mHaveFrame
8982 + " mViewVisibility=" + win.mViewVisibility
8983 + " mRelayoutCalled=" + win.mRelayoutCalled);
8984 if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
8985 || !win.mHaveFrame) {
8986 mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
8987 win.mLayoutSeq = seq;
8988 if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame="
8989 + win.mFrame + " mContainingFrame="
8990 + win.mContainingFrame + " mDisplayFrame="
8991 + win.mDisplayFrame);
8992 }
8993 }
8994 }
Jeff Brown349703e2010-06-22 01:27:15 -07008995
8996 // Window frames may have changed. Tell the input dispatcher about it.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07008997 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08008998
8999 return mPolicy.finishLayoutLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009000 }
Romain Guy06882f82009-06-10 13:36:04 -07009001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009002 private final void performLayoutAndPlaceSurfacesLockedInner(
9003 boolean recoveringMemory) {
Joe Onorato34bcebc2010-07-07 18:05:01 -04009004 if (mDisplay == null) {
9005 Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay");
9006 return;
9007 }
9008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009009 final long currentTime = SystemClock.uptimeMillis();
9010 final int dw = mDisplay.getWidth();
9011 final int dh = mDisplay.getHeight();
9012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009013 int i;
9014
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009015 if (mFocusMayChange) {
9016 mFocusMayChange = false;
9017 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES);
9018 }
9019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009020 // Initialize state of exiting tokens.
9021 for (i=mExitingTokens.size()-1; i>=0; i--) {
9022 mExitingTokens.get(i).hasVisible = false;
9023 }
9024
9025 // Initialize state of exiting applications.
9026 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
9027 mExitingAppTokens.get(i).hasVisible = false;
9028 }
9029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009030 boolean orientationChangeComplete = true;
9031 Session holdScreen = null;
9032 float screenBrightness = -1;
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009033 float buttonBrightness = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009034 boolean focusDisplayed = false;
9035 boolean animating = false;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009036 boolean createWatermark = false;
9037
9038 if (mFxSession == null) {
9039 mFxSession = new SurfaceSession();
9040 createWatermark = true;
9041 }
9042
9043 if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009044
9045 Surface.openTransaction();
Dianne Hackbornfb86ce92010-08-11 18:11:23 -07009046
9047 if (createWatermark) {
9048 createWatermark();
9049 }
9050 if (mWatermark != null) {
9051 mWatermark.positionSurface(dw, dh);
9052 }
9053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009054 try {
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009055 boolean wallpaperForceHidingChanged = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009056 int repeats = 0;
9057 int changes = 0;
9058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009059 do {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009060 repeats++;
9061 if (repeats > 6) {
9062 Slog.w(TAG, "Animation repeat aborted after too many iterations");
9063 mLayoutNeeded = false;
9064 break;
9065 }
9066
9067 if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER
9068 | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG
9069 | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) {
9070 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
9071 if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
9072 assignLayersLocked();
9073 mLayoutNeeded = true;
9074 }
9075 }
9076 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
9077 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
9078 if (updateOrientationFromAppTokensLocked()) {
9079 mLayoutNeeded = true;
9080 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
9081 }
9082 }
9083 if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
9084 mLayoutNeeded = true;
9085 }
9086 }
9087
9088 // FIRST LOOP: Perform a layout, if needed.
9089 if (repeats < 4) {
9090 changes = performLayoutLockedInner();
9091 if (changes != 0) {
9092 continue;
9093 }
9094 } else {
9095 Slog.w(TAG, "Layout repeat skipped after too many iterations");
9096 changes = 0;
9097 }
9098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009099 final int transactionSequence = ++mTransactionSequence;
9100
9101 // Update animations of all applications, including those
9102 // associated with exiting/removed apps
9103 boolean tokensAnimating = false;
9104 final int NAT = mAppTokens.size();
9105 for (i=0; i<NAT; i++) {
9106 if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9107 tokensAnimating = true;
9108 }
9109 }
9110 final int NEAT = mExitingAppTokens.size();
9111 for (i=0; i<NEAT; i++) {
9112 if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) {
9113 tokensAnimating = true;
9114 }
9115 }
9116
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009117 // SECOND LOOP: Execute animations and update visibility of windows.
9118
Joe Onorato8a9b2202010-02-26 18:56:32 -08009119 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq="
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009120 + transactionSequence + " tokensAnimating="
9121 + tokensAnimating);
9122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009123 animating = tokensAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009124
9125 boolean tokenMayBeDrawn = false;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009126 boolean wallpaperMayChange = false;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009127 boolean forceHiding = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009128
9129 mPolicy.beginAnimationLw(dw, dh);
9130
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009131 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009133 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009134 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009135
9136 final WindowManager.LayoutParams attrs = w.mAttrs;
9137
9138 if (w.mSurface != null) {
9139 // Execute animation.
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009140 if (w.commitFinishDrawingLocked(currentTime)) {
9141 if ((w.mAttrs.flags
9142 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009143 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009144 "First draw done in potential wallpaper target " + w);
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009145 wallpaperMayChange = true;
9146 }
9147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009148
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009149 boolean wasAnimating = w.mAnimating;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009150 if (w.stepAnimationLocked(currentTime, dw, dh)) {
9151 animating = true;
9152 //w.dump(" ");
9153 }
Dianne Hackborn6136b7e2009-09-18 01:53:49 -07009154 if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) {
9155 wallpaperMayChange = true;
9156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009157
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009158 if (mPolicy.doesForceHide(w, attrs)) {
9159 if (!wasAnimating && animating) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009160 if (DEBUG_VISIBILITY) Slog.v(TAG,
9161 "Animation done that could impact force hide: "
9162 + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009163 wallpaperForceHidingChanged = true;
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009164 mFocusMayChange = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009165 } else if (w.isReadyForDisplay() && w.mAnimation == null) {
9166 forceHiding = true;
9167 }
9168 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9169 boolean changed;
9170 if (forceHiding) {
9171 changed = w.hideLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009172 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9173 "Now policy hidden: " + w);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009174 } else {
9175 changed = w.showLw(false, false);
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009176 if (DEBUG_VISIBILITY && changed) Slog.v(TAG,
9177 "Now policy shown: " + w);
9178 if (changed) {
9179 if (wallpaperForceHidingChanged
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009180 && w.isVisibleNow() /*w.isReadyForDisplay()*/) {
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009181 // Assume we will need to animate. If
9182 // we don't (because the wallpaper will
9183 // stay with the lock screen), then we will
9184 // clean up later.
9185 Animation a = mPolicy.createForceHideEnterAnimation();
9186 if (a != null) {
9187 w.setAnimation(a);
9188 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009189 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08009190 if (mCurrentFocus == null ||
9191 mCurrentFocus.mLayer < w.mLayer) {
9192 // We are showing on to of the current
9193 // focus, so re-evaluate focus to make
9194 // sure it is correct.
9195 mFocusMayChange = true;
9196 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009197 }
9198 }
9199 if (changed && (attrs.flags
9200 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
9201 wallpaperMayChange = true;
9202 }
9203 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009205 mPolicy.animatingWindowLw(w, attrs);
9206 }
9207
9208 final AppWindowToken atoken = w.mAppToken;
9209 if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) {
9210 if (atoken.lastTransactionSequence != transactionSequence) {
9211 atoken.lastTransactionSequence = transactionSequence;
9212 atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
9213 atoken.startingDisplayed = false;
9214 }
9215 if ((w.isOnScreen() || w.mAttrs.type
9216 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
9217 && !w.mExiting && !w.mDestroying) {
9218 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009219 Slog.v(TAG, "Eval win " + w + ": isDrawn="
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009220 + w.isDrawnLw()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009221 + ", isAnimating=" + w.isAnimating());
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009222 if (!w.isDrawnLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009223 Slog.v(TAG, "Not displayed: s=" + w.mSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009224 + " pv=" + w.mPolicyVisibility
9225 + " dp=" + w.mDrawPending
9226 + " cdp=" + w.mCommitDrawPending
9227 + " ah=" + w.mAttachedHidden
9228 + " th=" + atoken.hiddenRequested
9229 + " a=" + w.mAnimating);
9230 }
9231 }
9232 if (w != atoken.startingWindow) {
9233 if (!atoken.freezingScreen || !w.mAppFreezing) {
9234 atoken.numInterestingWindows++;
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009235 if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009236 atoken.numDrawnWindows++;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009237 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009238 "tokenMayBeDrawn: " + atoken
9239 + " freezingScreen=" + atoken.freezingScreen
9240 + " mAppFreezing=" + w.mAppFreezing);
9241 tokenMayBeDrawn = true;
9242 }
9243 }
Dianne Hackborn7433e8a2009-09-27 13:21:20 -07009244 } else if (w.isDrawnLw()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009245 atoken.startingDisplayed = true;
9246 }
9247 }
9248 } else if (w.mReadyToShow) {
9249 w.performShowLocked();
9250 }
9251 }
9252
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009253 changes |= mPolicy.finishAnimationLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009254
9255 if (tokenMayBeDrawn) {
9256 // See if any windows have been drawn, so they (and others
9257 // associated with them) can now be shown.
9258 final int NT = mTokenList.size();
9259 for (i=0; i<NT; i++) {
9260 AppWindowToken wtoken = mTokenList.get(i).appWindowToken;
9261 if (wtoken == null) {
9262 continue;
9263 }
9264 if (wtoken.freezingScreen) {
9265 int numInteresting = wtoken.numInterestingWindows;
9266 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009267 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009268 "allDrawn: " + wtoken
9269 + " interesting=" + numInteresting
9270 + " drawn=" + wtoken.numDrawnWindows);
9271 wtoken.showAllWindowsLocked();
9272 unsetAppFreezingScreenLocked(wtoken, false, true);
9273 orientationChangeComplete = true;
9274 }
9275 } else if (!wtoken.allDrawn) {
9276 int numInteresting = wtoken.numInterestingWindows;
9277 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009278 if (DEBUG_VISIBILITY) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009279 "allDrawn: " + wtoken
9280 + " interesting=" + numInteresting
9281 + " drawn=" + wtoken.numDrawnWindows);
9282 wtoken.allDrawn = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009283 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009284
9285 // We can now show all of the drawn windows!
9286 if (!mOpeningApps.contains(wtoken)) {
9287 wtoken.showAllWindowsLocked();
9288 }
9289 }
9290 }
9291 }
9292 }
9293
9294 // If we are ready to perform an app transition, check through
9295 // all of the app tokens to be shown and see if they are ready
9296 // to go.
9297 if (mAppTransitionReady) {
9298 int NN = mOpeningApps.size();
9299 boolean goodToGo = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009300 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009301 "Checking " + NN + " opening apps (frozen="
9302 + mDisplayFrozen + " timeout="
9303 + mAppTransitionTimeout + ")...");
9304 if (!mDisplayFrozen && !mAppTransitionTimeout) {
9305 // If the display isn't frozen, wait to do anything until
9306 // all of the apps are ready. Otherwise just go because
9307 // we'll unfreeze the display when everyone is ready.
9308 for (i=0; i<NN && goodToGo; i++) {
9309 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009310 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009311 "Check opening app" + wtoken + ": allDrawn="
9312 + wtoken.allDrawn + " startingDisplayed="
9313 + wtoken.startingDisplayed);
9314 if (!wtoken.allDrawn && !wtoken.startingDisplayed
9315 && !wtoken.startingMoved) {
9316 goodToGo = false;
9317 }
9318 }
9319 }
9320 if (goodToGo) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009321 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009322 int transit = mNextAppTransition;
9323 if (mSkipAppTransitionAnimation) {
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009324 transit = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009325 }
Dianne Hackbornbfe319e2009-09-21 00:34:05 -07009326 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009327 mAppTransitionReady = false;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009328 mAppTransitionRunning = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009329 mAppTransitionTimeout = false;
9330 mStartingIconInTransition = false;
9331 mSkipAppTransitionAnimation = false;
9332
9333 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
9334
Dianne Hackborna8f60182009-09-01 19:01:50 -07009335 // If there are applications waiting to come to the
9336 // top of the stack, now is the time to move their windows.
9337 // (Note that we don't do apps going to the bottom
9338 // here -- we want to keep their windows in the old
9339 // Z-order until the animation completes.)
9340 if (mToTopApps.size() > 0) {
9341 NN = mAppTokens.size();
9342 for (i=0; i<NN; i++) {
9343 AppWindowToken wtoken = mAppTokens.get(i);
9344 if (wtoken.sendingToTop) {
9345 wtoken.sendingToTop = false;
9346 moveAppWindowsLocked(wtoken, NN, false);
9347 }
9348 }
9349 mToTopApps.clear();
9350 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009351
Dianne Hackborn25994b42009-09-04 14:21:19 -07009352 WindowState oldWallpaper = mWallpaperTarget;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009353
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009354 adjustWallpaperWindowsLocked();
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009355 wallpaperMayChange = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009356
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009357 // The top-most window will supply the layout params,
9358 // and we will determine it below.
9359 LayoutParams animLp = null;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009360 AppWindowToken animToken = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009361 int bestAnimLayer = -1;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009362
Joe Onorato8a9b2202010-02-26 18:56:32 -08009363 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn3be63c02009-08-20 19:31:38 -07009364 "New wallpaper target=" + mWallpaperTarget
9365 + ", lower target=" + mLowerWallpaperTarget
9366 + ", upper target=" + mUpperWallpaperTarget);
Dianne Hackborn25994b42009-09-04 14:21:19 -07009367 int foundWallpapers = 0;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009368 // Do a first pass through the tokens for two
9369 // things:
9370 // (1) Determine if both the closing and opening
9371 // app token sets are wallpaper targets, in which
9372 // case special animations are needed
9373 // (since the wallpaper needs to stay static
9374 // behind them).
9375 // (2) Find the layout params of the top-most
9376 // application window in the tokens, which is
9377 // what will control the animation theme.
9378 final int NC = mClosingApps.size();
9379 NN = NC + mOpeningApps.size();
9380 for (i=0; i<NN; i++) {
9381 AppWindowToken wtoken;
9382 int mode;
9383 if (i < NC) {
9384 wtoken = mClosingApps.get(i);
9385 mode = 1;
9386 } else {
9387 wtoken = mOpeningApps.get(i-NC);
9388 mode = 2;
9389 }
9390 if (mLowerWallpaperTarget != null) {
9391 if (mLowerWallpaperTarget.mAppToken == wtoken
9392 || mUpperWallpaperTarget.mAppToken == wtoken) {
9393 foundWallpapers |= mode;
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009394 }
9395 }
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009396 if (wtoken.appFullscreen) {
9397 WindowState ws = wtoken.findMainWindow();
9398 if (ws != null) {
9399 // If this is a compatibility mode
9400 // window, we will always use its anim.
9401 if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) {
9402 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009403 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009404 bestAnimLayer = Integer.MAX_VALUE;
9405 } else if (ws.mLayer > bestAnimLayer) {
9406 animLp = ws.mAttrs;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009407 animToken = ws.mAppToken;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009408 bestAnimLayer = ws.mLayer;
9409 }
Dianne Hackborn25994b42009-09-04 14:21:19 -07009410 }
Dianne Hackbornf8fbdb62009-08-19 12:39:43 -07009411 }
9412 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009413
Dianne Hackborn25994b42009-09-04 14:21:19 -07009414 if (foundWallpapers == 3) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009415 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009416 "Wallpaper animation!");
9417 switch (transit) {
9418 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
9419 case WindowManagerPolicy.TRANSIT_TASK_OPEN:
9420 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
9421 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
9422 break;
9423 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
9424 case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
9425 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
9426 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE;
9427 break;
9428 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009429 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009430 "New transit: " + transit);
9431 } else if (oldWallpaper != null) {
9432 // We are transitioning from an activity with
9433 // a wallpaper to one without.
9434 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009435 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009436 "New transit away from wallpaper: " + transit);
9437 } else if (mWallpaperTarget != null) {
9438 // We are transitioning from an activity without
9439 // a wallpaper to now showing the wallpaper
9440 transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009441 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
Dianne Hackborn25994b42009-09-04 14:21:19 -07009442 "New transit into wallpaper: " + transit);
9443 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009444
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009445 if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) {
9446 mLastEnterAnimToken = animToken;
9447 mLastEnterAnimParams = animLp;
9448 } else if (mLastEnterAnimParams != null) {
9449 animLp = mLastEnterAnimParams;
9450 mLastEnterAnimToken = null;
9451 mLastEnterAnimParams = null;
9452 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009453
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009454 // If all closing windows are obscured, then there is
9455 // no need to do an animation. This is the case, for
9456 // example, when this transition is being done behind
9457 // the lock screen.
9458 if (!mPolicy.allowAppAnimationsLw()) {
9459 animLp = null;
9460 }
9461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009462 NN = mOpeningApps.size();
9463 for (i=0; i<NN; i++) {
9464 AppWindowToken wtoken = mOpeningApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009465 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009466 "Now opening app" + wtoken);
9467 wtoken.reportedVisible = false;
9468 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009469 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009470 setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009471 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009472 wtoken.waitingToShow = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009473 wtoken.showAllWindowsLocked();
9474 }
9475 NN = mClosingApps.size();
9476 for (i=0; i<NN; i++) {
9477 AppWindowToken wtoken = mClosingApps.get(i);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009478 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009479 "Now closing app" + wtoken);
9480 wtoken.inPendingTransaction = false;
Dianne Hackborn83360b32009-08-24 18:43:32 -07009481 wtoken.animation = null;
Dianne Hackbornbcbcaa72009-09-10 10:54:46 -07009482 setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009483 wtoken.updateReportedVisibilityLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -07009484 wtoken.waitingToHide = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009485 // Force the allDrawn flag, because we want to start
9486 // this guy's animations regardless of whether it's
9487 // gotten drawn.
9488 wtoken.allDrawn = true;
9489 }
9490
Dianne Hackborn8b571a82009-09-25 16:09:43 -07009491 mNextAppTransitionPackage = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009493 mOpeningApps.clear();
9494 mClosingApps.clear();
9495
9496 // This has changed the visibility of windows, so perform
9497 // a new layout to get them all up-to-date.
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009498 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009499 mLayoutNeeded = true;
Dianne Hackborn20583ff2009-07-27 21:51:05 -07009500 if (!moveInputMethodWindowsIfNeededLocked(true)) {
9501 assignLayersLocked();
9502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009503 updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES);
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009504 mFocusMayChange = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009505 }
9506 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009507
Dianne Hackborn16064f92010-03-25 00:47:24 -07009508 int adjResult = 0;
9509
Dianne Hackborna8f60182009-09-01 19:01:50 -07009510 if (!animating && mAppTransitionRunning) {
9511 // We have finished the animation of an app transition. To do
9512 // this, we have delayed a lot of operations like showing and
9513 // hiding apps, moving apps in Z-order, etc. The app token list
9514 // reflects the correct Z-order, but the window list may now
9515 // be out of sync with it. So here we will just rebuild the
9516 // entire app window list. Fun!
9517 mAppTransitionRunning = false;
9518 // Clear information about apps that were moving.
9519 mToBottomApps.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009520
Dianne Hackborna8f60182009-09-01 19:01:50 -07009521 rebuildAppWindowListLocked();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009522 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009523 adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009524 moveInputMethodWindowsIfNeededLocked(false);
9525 wallpaperMayChange = true;
Suchi Amalapurapuc9568e32009-11-05 18:51:16 -08009526 // Since the window list has been rebuilt, focus might
9527 // have to be recomputed since the actual order of windows
9528 // might have changed again.
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009529 mFocusMayChange = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -07009530 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009531
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009532 if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) {
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009533 // At this point, there was a window with a wallpaper that
9534 // was force hiding other windows behind it, but now it
9535 // is going away. This may be simple -- just animate
9536 // away the wallpaper and its window -- or it may be
9537 // hard -- the wallpaper now needs to be shown behind
9538 // something that was hidden.
9539 WindowState oldWallpaper = mWallpaperTarget;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009540 if (mLowerWallpaperTarget != null
9541 && mLowerWallpaperTarget.mAppToken != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009542 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009543 "wallpaperForceHiding changed with lower="
9544 + mLowerWallpaperTarget);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009545 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009546 "hidden=" + mLowerWallpaperTarget.mAppToken.hidden +
9547 " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested);
9548 if (mLowerWallpaperTarget.mAppToken.hidden) {
9549 // The lower target has become hidden before we
9550 // actually started the animation... let's completely
9551 // re-evaluate everything.
9552 mLowerWallpaperTarget = mUpperWallpaperTarget = null;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009553 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009554 }
9555 }
Dianne Hackborn16064f92010-03-25 00:47:24 -07009556 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009557 wallpaperMayChange = false;
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009558 wallpaperForceHidingChanged = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009559 if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009560 + " NEW: " + mWallpaperTarget
9561 + " LOWER: " + mLowerWallpaperTarget);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009562 if (mLowerWallpaperTarget == null) {
9563 // Whoops, we don't need a special wallpaper animation.
9564 // Clear them out.
9565 forceHiding = false;
9566 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009567 WindowState w = mWindows.get(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009568 if (w.mSurface != null) {
9569 final WindowManager.LayoutParams attrs = w.mAttrs;
Suchi Amalapurapuc03d28b2009-10-28 14:32:05 -07009570 if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009571 if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009572 forceHiding = true;
9573 } else if (mPolicy.canBeForceHidden(w, attrs)) {
9574 if (!w.mAnimating) {
9575 // We set the animation above so it
9576 // is not yet running.
9577 w.clearAnimation();
9578 }
9579 }
9580 }
9581 }
9582 }
9583 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009584
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009585 if (wallpaperMayChange) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009586 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009587 "Wallpaper may change! Adjusting");
Dianne Hackborn16064f92010-03-25 00:47:24 -07009588 adjResult |= adjustWallpaperWindowsLocked();
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009589 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009590
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009591 if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009592 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009593 "Wallpaper layer changed: assigning layers + relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009594 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009595 assignLayersLocked();
9596 } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009597 if (DEBUG_WALLPAPER) Slog.v(TAG,
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009598 "Wallpaper visibility changed: relayout");
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009599 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009600 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009601
Dianne Hackbornb601ce12010-03-01 23:36:02 -08009602 if (mFocusMayChange) {
9603 mFocusMayChange = false;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009604 if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009605 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009606 adjResult = 0;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009607 }
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009608 }
9609
9610 if (mLayoutNeeded) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009611 changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
Dianne Hackborn6c3f5712009-08-25 18:42:59 -07009612 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009613
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009614 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x"
9615 + Integer.toHexString(changes));
Dianne Hackbornde2606d2009-12-18 16:53:55 -08009616
Jeff Browne33348b2010-07-15 23:54:05 -07009617 mInputMonitor.updateInputWindowsLw();
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009618 } while (changes != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009619
9620 // THIRD LOOP: Update the surfaces of all windows.
9621
9622 final boolean someoneLosingFocus = mLosingFocus.size() != 0;
9623
9624 boolean obscured = false;
9625 boolean blurring = false;
9626 boolean dimming = false;
9627 boolean covered = false;
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009628 boolean syswin = false;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009629 boolean backgroundFillerShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009630
Dianne Hackbornbdd52b22009-09-02 21:46:19 -07009631 final int N = mWindows.size();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009633 for (i=N-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -07009634 WindowState w = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009635
9636 boolean displayed = false;
9637 final WindowManager.LayoutParams attrs = w.mAttrs;
9638 final int attrFlags = attrs.flags;
9639
9640 if (w.mSurface != null) {
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009641 // XXX NOTE: The logic here could be improved. We have
9642 // the decision about whether to resize a window separated
9643 // from whether to hide the surface. This can cause us to
9644 // resize a surface even if we are going to hide it. You
9645 // can see this by (1) holding device in landscape mode on
9646 // home screen; (2) tapping browser icon (device will rotate
9647 // to landscape; (3) tap home. The wallpaper will be resized
9648 // in step 2 but then immediately hidden, causing us to
9649 // have to resize and then redraw it again in step 3. It
9650 // would be nice to figure out how to avoid this, but it is
9651 // difficult because we do need to resize surfaces in some
9652 // cases while they are hidden such as when first showing a
9653 // window.
9654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009655 w.computeShownFrameLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08009656 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009657 TAG, "Placing surface #" + i + " " + w.mSurface
9658 + ": new=" + w.mShownFrame + ", old="
9659 + w.mLastShownFrame);
9660
9661 boolean resize;
9662 int width, height;
9663 if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) {
9664 resize = w.mLastRequestedWidth != w.mRequestedWidth ||
9665 w.mLastRequestedHeight != w.mRequestedHeight;
9666 // for a scaled surface, we just want to use
9667 // the requested size.
9668 width = w.mRequestedWidth;
9669 height = w.mRequestedHeight;
9670 w.mLastRequestedWidth = width;
9671 w.mLastRequestedHeight = height;
9672 w.mLastShownFrame.set(w.mShownFrame);
9673 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009674 if (SHOW_TRANSACTIONS) logSurface(w,
9675 "POS " + w.mShownFrame.left
9676 + ", " + w.mShownFrame.top, null);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009677 w.mSurfaceX = w.mShownFrame.left;
9678 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009679 w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top);
9680 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009681 Slog.w(TAG, "Error positioning surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009682 if (!recoveringMemory) {
9683 reclaimSomeSurfaceMemoryLocked(w, "position");
9684 }
9685 }
9686 } else {
9687 resize = !w.mLastShownFrame.equals(w.mShownFrame);
9688 width = w.mShownFrame.width();
9689 height = w.mShownFrame.height();
9690 w.mLastShownFrame.set(w.mShownFrame);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009691 }
9692
9693 if (resize) {
9694 if (width < 1) width = 1;
9695 if (height < 1) height = 1;
9696 if (w.mSurface != null) {
9697 try {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009698 if (SHOW_TRANSACTIONS) logSurface(w,
9699 "POS " + w.mShownFrame.left + ","
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009700 + w.mShownFrame.top + " SIZE "
9701 + w.mShownFrame.width() + "x"
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009702 + w.mShownFrame.height(), null);
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009703 w.mSurfaceResized = true;
Dianne Hackborn16064f92010-03-25 00:47:24 -07009704 w.mSurfaceW = width;
9705 w.mSurfaceH = height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009706 w.mSurface.setSize(width, height);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009707 w.mSurfaceX = w.mShownFrame.left;
9708 w.mSurfaceY = w.mShownFrame.top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009709 w.mSurface.setPosition(w.mShownFrame.left,
9710 w.mShownFrame.top);
9711 } catch (RuntimeException e) {
9712 // If something goes wrong with the surface (such
9713 // as running out of memory), don't take down the
9714 // entire system.
Joe Onorato8a9b2202010-02-26 18:56:32 -08009715 Slog.e(TAG, "Failure updating surface of " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009716 + "size=(" + width + "x" + height
9717 + "), pos=(" + w.mShownFrame.left
9718 + "," + w.mShownFrame.top + ")", e);
9719 if (!recoveringMemory) {
9720 reclaimSomeSurfaceMemoryLocked(w, "size");
9721 }
9722 }
9723 }
9724 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009725 if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009726 w.mContentInsetsChanged =
9727 !w.mLastContentInsets.equals(w.mContentInsets);
9728 w.mVisibleInsetsChanged =
9729 !w.mLastVisibleInsets.equals(w.mVisibleInsets);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009730 boolean configChanged =
9731 w.mConfiguration != mCurConfiguration
9732 && (w.mConfiguration == null
9733 || mCurConfiguration.diff(w.mConfiguration) != 0);
Dianne Hackborn694f79b2010-03-17 19:44:59 -07009734 if (DEBUG_CONFIGURATION && configChanged) {
9735 Slog.v(TAG, "Win " + w + " config changed: "
9736 + mCurConfiguration);
9737 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08009738 if (localLOGV) Slog.v(TAG, "Resizing " + w
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009739 + ": configChanged=" + configChanged
9740 + " last=" + w.mLastFrame + " frame=" + w.mFrame);
Romain Guy06882f82009-06-10 13:36:04 -07009741 if (!w.mLastFrame.equals(w.mFrame)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009742 || w.mContentInsetsChanged
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009743 || w.mVisibleInsetsChanged
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009744 || w.mSurfaceResized
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009745 || configChanged) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009746 w.mLastFrame.set(w.mFrame);
9747 w.mLastContentInsets.set(w.mContentInsets);
9748 w.mLastVisibleInsets.set(w.mVisibleInsets);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009749 // If the screen is currently frozen, then keep
9750 // it frozen until this window draws at its new
9751 // orientation.
9752 if (mDisplayFrozen) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009753 if (DEBUG_ORIENTATION) Slog.v(TAG,
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009754 "Resizing while display frozen: " + w);
9755 w.mOrientationChanging = true;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08009756 if (!mWindowsFreezingScreen) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009757 mWindowsFreezingScreen = true;
9758 // XXX should probably keep timeout from
9759 // when we first froze the display.
9760 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
9761 mH.sendMessageDelayed(mH.obtainMessage(
9762 H.WINDOW_FREEZE_TIMEOUT), 2000);
9763 }
9764 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009765 // If the orientation is changing, then we need to
9766 // hold off on unfreezing the display until this
9767 // window has been redrawn; to do that, we need
9768 // to go through the process of getting informed
9769 // by the application when it has finished drawing.
9770 if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009771 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009772 "Orientation start waiting for draw in "
9773 + w + ", surface " + w.mSurface);
9774 w.mDrawPending = true;
9775 w.mCommitDrawPending = false;
9776 w.mReadyToShow = false;
9777 if (w.mAppToken != null) {
9778 w.mAppToken.allDrawn = false;
9779 }
9780 }
Dianne Hackbornac3587d2010-03-11 11:12:11 -08009781 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009782 "Resizing window " + w + " to " + w.mFrame);
9783 mResizingWindows.add(w);
9784 } else if (w.mOrientationChanging) {
9785 if (!w.mDrawPending && !w.mCommitDrawPending) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009786 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009787 "Orientation not waiting for draw in "
9788 + w + ", surface " + w.mSurface);
9789 w.mOrientationChanging = false;
9790 }
9791 }
9792 }
9793
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009794 if (w.mAttachedHidden || !w.isReadyForDisplay()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009795 if (!w.mLastHidden) {
9796 //dump();
9797 w.mLastHidden = true;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009798 if (SHOW_TRANSACTIONS) logSurface(w,
9799 "HIDE (performLayout)", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009800 if (w.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009801 w.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009802 try {
9803 w.mSurface.hide();
9804 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009805 Slog.w(TAG, "Exception hiding surface in " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009806 }
9807 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009808 }
9809 // If we are waiting for this window to handle an
9810 // orientation change, well, it is hidden, so
9811 // doesn't really matter. Note that this does
9812 // introduce a potential glitch if the window
9813 // becomes unhidden before it has drawn for the
9814 // new orientation.
9815 if (w.mOrientationChanging) {
9816 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009817 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009818 "Orientation change skips hidden " + w);
9819 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009820 } else if (w.mLastLayer != w.mAnimLayer
9821 || w.mLastAlpha != w.mShownAlpha
9822 || w.mLastDsDx != w.mDsDx
9823 || w.mLastDtDx != w.mDtDx
9824 || w.mLastDsDy != w.mDsDy
9825 || w.mLastDtDy != w.mDtDy
9826 || w.mLastHScale != w.mHScale
9827 || w.mLastVScale != w.mVScale
9828 || w.mLastHidden) {
9829 displayed = true;
9830 w.mLastAlpha = w.mShownAlpha;
9831 w.mLastLayer = w.mAnimLayer;
9832 w.mLastDsDx = w.mDsDx;
9833 w.mLastDtDx = w.mDtDx;
9834 w.mLastDsDy = w.mDsDy;
9835 w.mLastDtDy = w.mDtDy;
9836 w.mLastHScale = w.mHScale;
9837 w.mLastVScale = w.mVScale;
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009838 if (SHOW_TRANSACTIONS) logSurface(w,
9839 "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer
Dianne Hackborn0586a1b2009-09-06 21:08:27 -07009840 + " matrix=[" + (w.mDsDx*w.mHScale)
9841 + "," + (w.mDtDx*w.mVScale)
9842 + "][" + (w.mDsDy*w.mHScale)
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009843 + "," + (w.mDtDy*w.mVScale) + "]", null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009844 if (w.mSurface != null) {
9845 try {
Dianne Hackborn16064f92010-03-25 00:47:24 -07009846 w.mSurfaceAlpha = w.mShownAlpha;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009847 w.mSurface.setAlpha(w.mShownAlpha);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009848 w.mSurfaceLayer = w.mAnimLayer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009849 w.mSurface.setLayer(w.mAnimLayer);
9850 w.mSurface.setMatrix(
9851 w.mDsDx*w.mHScale, w.mDtDx*w.mVScale,
9852 w.mDsDy*w.mHScale, w.mDtDy*w.mVScale);
9853 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009854 Slog.w(TAG, "Error updating surface in " + w, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009855 if (!recoveringMemory) {
9856 reclaimSomeSurfaceMemoryLocked(w, "update");
9857 }
9858 }
9859 }
9860
9861 if (w.mLastHidden && !w.mDrawPending
9862 && !w.mCommitDrawPending
9863 && !w.mReadyToShow) {
Dianne Hackbornb8b11a02010-03-10 15:53:11 -08009864 if (SHOW_TRANSACTIONS) logSurface(w,
9865 "SHOW (performLayout)", null);
Joe Onorato8a9b2202010-02-26 18:56:32 -08009866 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009867 + " during relayout");
9868 if (showSurfaceRobustlyLocked(w)) {
9869 w.mHasDrawn = true;
9870 w.mLastHidden = false;
9871 } else {
9872 w.mOrientationChanging = false;
9873 }
9874 }
9875 if (w.mSurface != null) {
9876 w.mToken.hasVisible = true;
9877 }
9878 } else {
9879 displayed = true;
9880 }
9881
9882 if (displayed) {
9883 if (!covered) {
Romain Guy980a9382010-01-08 15:06:28 -08009884 if (attrs.width == LayoutParams.MATCH_PARENT
9885 && attrs.height == LayoutParams.MATCH_PARENT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009886 covered = true;
9887 }
9888 }
9889 if (w.mOrientationChanging) {
9890 if (w.mDrawPending || w.mCommitDrawPending) {
9891 orientationChangeComplete = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009892 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009893 "Orientation continue waiting for draw in " + w);
9894 } else {
9895 w.mOrientationChanging = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -08009896 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009897 "Orientation change complete in " + w);
9898 }
9899 }
9900 w.mToken.hasVisible = true;
9901 }
9902 } else if (w.mOrientationChanging) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009903 if (DEBUG_ORIENTATION) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009904 "Orientation change skips hidden " + w);
9905 w.mOrientationChanging = false;
9906 }
9907
9908 final boolean canBeSeen = w.isDisplayedLw();
9909
9910 if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) {
9911 focusDisplayed = true;
9912 }
9913
Dianne Hackborne9e9bca2009-08-18 15:08:22 -07009914 final boolean obscuredChanged = w.mObscured != obscured;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009915
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009916 // Update effect.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -07009917 if (!(w.mObscured=obscured)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009918 if (w.mSurface != null) {
9919 if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
9920 holdScreen = w.mSession;
9921 }
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009922 if (!syswin && w.mAttrs.screenBrightness >= 0
9923 && screenBrightness < 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009924 screenBrightness = w.mAttrs.screenBrightness;
9925 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -05009926 if (!syswin && w.mAttrs.buttonBrightness >= 0
9927 && buttonBrightness < 0) {
9928 buttonBrightness = w.mAttrs.buttonBrightness;
9929 }
Mike Lockwood46af6a82010-03-09 08:28:22 -05009930 if (canBeSeen
9931 && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG
9932 || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD
9933 || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) {
Dianne Hackborn9ed4a4b2009-03-25 17:10:37 -07009934 syswin = true;
9935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009936 }
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009937
Dianne Hackborn25994b42009-09-04 14:21:19 -07009938 boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
9939 if (opaqueDrawn && w.isFullscreen(dw, dh)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009940 // This window completely covers everything behind it,
9941 // so we want to leave all of them as unblurred (for
9942 // performance reasons).
9943 obscured = true;
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009944 } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009945 if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009946 // This window is in compatibility mode, and needs background filler.
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009947 obscured = true;
9948 if (mBackgroundFillerSurface == null) {
9949 try {
9950 mBackgroundFillerSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009951 "BackGroundFiller",
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009952 0, dw, dh,
9953 PixelFormat.OPAQUE,
9954 Surface.FX_SURFACE_NORMAL);
9955 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009956 Slog.e(TAG, "Exception creating filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009957 }
9958 }
9959 try {
9960 mBackgroundFillerSurface.setPosition(0, 0);
9961 mBackgroundFillerSurface.setSize(dw, dh);
9962 // Using the same layer as Dim because they will never be shown at the
9963 // same time.
9964 mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1);
9965 mBackgroundFillerSurface.show();
9966 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009967 Slog.e(TAG, "Exception showing filler surface");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -07009968 }
9969 backgroundFillerShown = true;
9970 mBackgroundFillerShown = true;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -07009971 } else if (canBeSeen && !obscured &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009972 (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009973 if (localLOGV) Slog.v(TAG, "Win " + w
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009974 + ": blurring=" + blurring
9975 + " obscured=" + obscured
9976 + " displayed=" + displayed);
9977 if ((attrFlags&FLAG_DIM_BEHIND) != 0) {
9978 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009979 //Slog.i(TAG, "DIM BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009980 dimming = true;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009981 if (mDimAnimator == null) {
9982 mDimAnimator = new DimAnimator(mFxSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009983 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -07009984 mDimAnimator.show(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -07009985 mDimAnimator.updateParameters(w, currentTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009987 }
9988 if ((attrFlags&FLAG_BLUR_BEHIND) != 0) {
9989 if (!blurring) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009990 //Slog.i(TAG, "BLUR BEHIND: " + w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009991 blurring = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009992 if (mBlurSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08009993 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009994 + mBlurSurface + ": CREATE");
9995 try {
Romain Guy06882f82009-06-10 13:36:04 -07009996 mBlurSurface = new Surface(mFxSession, 0,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -08009997 "BlurSurface",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009998 -1, 16, 16,
9999 PixelFormat.OPAQUE,
10000 Surface.FX_SURFACE_BLUR);
10001 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010002 Slog.e(TAG, "Exception creating Blur surface", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010003 }
10004 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010005 if (mBlurSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010006 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10007 + mBlurSurface + ": pos=(0,0) (" +
10008 dw + "x" + dh + "), layer=" + (w.mAnimLayer-1));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010009 mBlurSurface.setPosition(0, 0);
10010 mBlurSurface.setSize(dw, dh);
Dianne Hackborn16064f92010-03-25 00:47:24 -070010011 mBlurSurface.setLayer(w.mAnimLayer-2);
10012 if (!mBlurShown) {
10013 try {
10014 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR "
10015 + mBlurSurface + ": SHOW");
10016 mBlurSurface.show();
10017 } catch (RuntimeException e) {
10018 Slog.w(TAG, "Failure showing blur surface", e);
10019 }
10020 mBlurShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010021 }
10022 }
10023 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010024 }
10025 }
10026 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010027
Dianne Hackborne9e9bca2009-08-18 15:08:22 -070010028 if (obscuredChanged && mWallpaperTarget == w) {
10029 // This is the wallpaper target and its obscured state
10030 // changed... make sure the current wallaper's visibility
10031 // has been updated accordingly.
10032 updateWallpaperVisibilityLocked();
10033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010034 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010035
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010036 if (backgroundFillerShown == false && mBackgroundFillerShown) {
10037 mBackgroundFillerShown = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010038 if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler");
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010039 try {
10040 mBackgroundFillerSurface.hide();
10041 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010042 Slog.e(TAG, "Exception hiding filler surface", e);
Mitsuru Oshima1ecf5d22009-07-06 17:20:38 -070010043 }
10044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010045
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010046 if (mDimAnimator != null && mDimAnimator.mDimShown) {
Dianne Hackbornde2606d2009-12-18 16:53:55 -080010047 animating |= mDimAnimator.updateSurface(dimming, currentTime,
10048 mDisplayFrozen || !mPolicy.isScreenOn());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010049 }
Romain Guy06882f82009-06-10 13:36:04 -070010050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010051 if (!blurring && mBlurShown) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010052 if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010053 + ": HIDE");
10054 try {
10055 mBlurSurface.hide();
10056 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010057 Slog.w(TAG, "Illegal argument exception hiding blur surface");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010058 }
10059 mBlurShown = false;
10060 }
10061
Joe Onorato8a9b2202010-02-26 18:56:32 -080010062 if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010063 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010064 Slog.e(TAG, "Unhandled exception in Window Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010065 }
10066
Jeff Browne33348b2010-07-15 23:54:05 -070010067 mInputMonitor.updateInputWindowsLw();
10068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010069 Surface.closeTransaction();
Romain Guy06882f82009-06-10 13:36:04 -070010070
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010071 if (mWatermark != null) {
10072 mWatermark.drawIfNeeded();
10073 }
10074
Joe Onorato8a9b2202010-02-26 18:56:32 -080010075 if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010076 "With display frozen, orientationChangeComplete="
10077 + orientationChangeComplete);
10078 if (orientationChangeComplete) {
10079 if (mWindowsFreezingScreen) {
10080 mWindowsFreezingScreen = false;
10081 mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
10082 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010083 stopFreezingDisplayLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010084 }
Romain Guy06882f82009-06-10 13:36:04 -070010085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010086 i = mResizingWindows.size();
10087 if (i > 0) {
10088 do {
10089 i--;
10090 WindowState win = mResizingWindows.get(i);
10091 try {
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010092 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
10093 "Reporting new frame to " + win + ": " + win.mFrame);
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010094 int diff = 0;
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010095 boolean configChanged =
10096 win.mConfiguration != mCurConfiguration
10097 && (win.mConfiguration == null
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010098 || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0);
10099 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
10100 && configChanged) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010101 Slog.i(TAG, "Sending new config to window " + win + ": "
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010102 + win.mFrame.width() + "x" + win.mFrame.height()
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010103 + " / " + mCurConfiguration + " / 0x"
10104 + Integer.toHexString(diff));
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010105 }
Dianne Hackborn694f79b2010-03-17 19:44:59 -070010106 win.mConfiguration = mCurConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010107 win.mClient.resized(win.mFrame.width(),
10108 win.mFrame.height(), win.mLastContentInsets,
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010109 win.mLastVisibleInsets, win.mDrawPending,
10110 configChanged ? win.mConfiguration : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010111 win.mContentInsetsChanged = false;
10112 win.mVisibleInsetsChanged = false;
Dianne Hackbornac3587d2010-03-11 11:12:11 -080010113 win.mSurfaceResized = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010114 } catch (RemoteException e) {
10115 win.mOrientationChanging = false;
10116 }
10117 } while (i > 0);
10118 mResizingWindows.clear();
10119 }
Romain Guy06882f82009-06-10 13:36:04 -070010120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010121 // Destroy the surface of any windows that are no longer visible.
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010122 boolean wallpaperDestroyed = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010123 i = mDestroySurface.size();
10124 if (i > 0) {
10125 do {
10126 i--;
10127 WindowState win = mDestroySurface.get(i);
10128 win.mDestroying = false;
10129 if (mInputMethodWindow == win) {
10130 mInputMethodWindow = null;
10131 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010132 if (win == mWallpaperTarget) {
10133 wallpaperDestroyed = true;
10134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010135 win.destroySurfaceLocked();
10136 } while (i > 0);
10137 mDestroySurface.clear();
10138 }
10139
10140 // Time to remove any exiting tokens?
10141 for (i=mExitingTokens.size()-1; i>=0; i--) {
10142 WindowToken token = mExitingTokens.get(i);
10143 if (!token.hasVisible) {
10144 mExitingTokens.remove(i);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010145 if (token.windowType == TYPE_WALLPAPER) {
10146 mWallpaperTokens.remove(token);
10147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010148 }
10149 }
10150
10151 // Time to remove any exiting applications?
10152 for (i=mExitingAppTokens.size()-1; i>=0; i--) {
10153 AppWindowToken token = mExitingAppTokens.get(i);
10154 if (!token.hasVisible && !mClosingApps.contains(token)) {
Dianne Hackborn9bfb7072009-09-22 11:37:40 -070010155 // Make sure there is no animation running on this token,
10156 // so any windows associated with it will be removed as
10157 // soon as their animations are complete
10158 token.animation = null;
10159 token.animating = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010160 mAppTokens.remove(token);
10161 mExitingAppTokens.remove(i);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010162 if (mLastEnterAnimToken == token) {
10163 mLastEnterAnimToken = null;
10164 mLastEnterAnimParams = null;
10165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010166 }
10167 }
10168
Dianne Hackborna8f60182009-09-01 19:01:50 -070010169 boolean needRelayout = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010170
Dianne Hackborna8f60182009-09-01 19:01:50 -070010171 if (!animating && mAppTransitionRunning) {
10172 // We have finished the animation of an app transition. To do
10173 // this, we have delayed a lot of operations like showing and
10174 // hiding apps, moving apps in Z-order, etc. The app token list
10175 // reflects the correct Z-order, but the window list may now
10176 // be out of sync with it. So here we will just rebuild the
10177 // entire app window list. Fun!
10178 mAppTransitionRunning = false;
10179 needRelayout = true;
10180 rebuildAppWindowListLocked();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010181 assignLayersLocked();
Dianne Hackborna8f60182009-09-01 19:01:50 -070010182 // Clear information about apps that were moving.
10183 mToBottomApps.clear();
10184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010186 if (focusDisplayed) {
10187 mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
10188 }
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010189 if (wallpaperDestroyed) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010190 needRelayout = adjustWallpaperWindowsLocked() != 0;
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010191 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010192 if (needRelayout) {
Dianne Hackborn7341d7a2009-08-14 11:37:52 -070010193 requestAnimationLocked(0);
10194 } else if (animating) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010195 requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis());
10196 }
Jeff Browneb857f12010-07-16 10:06:33 -070010197
Jeff Browne33348b2010-07-15 23:54:05 -070010198 mInputMonitor.updateInputWindowsLw();
Jeff Browneb857f12010-07-16 10:06:33 -070010199
Jeff Brown8e03b752010-06-13 19:16:55 -070010200 setHoldScreenLocked(holdScreen != null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010201 if (screenBrightness < 0 || screenBrightness > 1.0f) {
10202 mPowerManager.setScreenBrightnessOverride(-1);
10203 } else {
10204 mPowerManager.setScreenBrightnessOverride((int)
10205 (screenBrightness * Power.BRIGHTNESS_ON));
10206 }
Mike Lockwoodfb73f792009-11-20 11:31:18 -050010207 if (buttonBrightness < 0 || buttonBrightness > 1.0f) {
10208 mPowerManager.setButtonBrightnessOverride(-1);
10209 } else {
10210 mPowerManager.setButtonBrightnessOverride((int)
10211 (buttonBrightness * Power.BRIGHTNESS_ON));
10212 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010213 if (holdScreen != mHoldingScreenOn) {
10214 mHoldingScreenOn = holdScreen;
10215 Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen);
10216 mH.sendMessage(m);
10217 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010218
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010219 if (mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010220 if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010221 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
10222 LocalPowerManager.BUTTON_EVENT, true);
10223 mTurnOnScreen = false;
10224 }
Dianne Hackbornf3bea9c2009-12-09 18:26:21 -080010225
10226 // Check to see if we are now in a state where the screen should
10227 // be enabled, because the window obscured flags have changed.
10228 enableScreenIfNeededLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010229 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070010230
10231 /**
10232 * Must be called with the main window manager lock held.
10233 */
10234 void setHoldScreenLocked(boolean holding) {
10235 boolean state = mHoldingScreenWakeLock.isHeld();
10236 if (holding != state) {
10237 if (holding) {
10238 mHoldingScreenWakeLock.acquire();
10239 } else {
10240 mPolicy.screenOnStoppedLw();
10241 mHoldingScreenWakeLock.release();
10242 }
10243 }
10244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010245
10246 void requestAnimationLocked(long delay) {
10247 if (!mAnimationPending) {
10248 mAnimationPending = true;
10249 mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay);
10250 }
10251 }
Romain Guy06882f82009-06-10 13:36:04 -070010252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010253 /**
10254 * Have the surface flinger show a surface, robustly dealing with
10255 * error conditions. In particular, if there is not enough memory
10256 * to show the surface, then we will try to get rid of other surfaces
10257 * in order to succeed.
Romain Guy06882f82009-06-10 13:36:04 -070010258 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010259 * @return Returns true if the surface was successfully shown.
10260 */
10261 boolean showSurfaceRobustlyLocked(WindowState win) {
10262 try {
10263 if (win.mSurface != null) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070010264 win.mSurfaceShown = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010265 win.mSurface.show();
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010266 if (win.mTurnOnScreen) {
Dianne Hackbornb601ce12010-03-01 23:36:02 -080010267 if (DEBUG_VISIBILITY) Slog.v(TAG,
10268 "Show surface turning screen on: " + win);
Dianne Hackborn93e462b2009-09-15 22:50:40 -070010269 win.mTurnOnScreen = false;
10270 mTurnOnScreen = true;
10271 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010272 }
10273 return true;
10274 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010275 Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010276 }
Romain Guy06882f82009-06-10 13:36:04 -070010277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010278 reclaimSomeSurfaceMemoryLocked(win, "show");
Romain Guy06882f82009-06-10 13:36:04 -070010279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010280 return false;
10281 }
Romain Guy06882f82009-06-10 13:36:04 -070010282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010283 void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) {
10284 final Surface surface = win.mSurface;
Romain Guy06882f82009-06-10 13:36:04 -070010285
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010286 EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010287 win.mSession.mPid, operation);
Romain Guy06882f82009-06-10 13:36:04 -070010288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010289 if (mForceRemoves == null) {
10290 mForceRemoves = new ArrayList<WindowState>();
10291 }
Romain Guy06882f82009-06-10 13:36:04 -070010292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010293 long callingIdentity = Binder.clearCallingIdentity();
10294 try {
10295 // There was some problem... first, do a sanity check of the
10296 // window list to make sure we haven't left any dangling surfaces
10297 // around.
10298 int N = mWindows.size();
10299 boolean leakedSurface = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -080010300 Slog.i(TAG, "Out of memory for surface! Looking for leaks...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010301 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010302 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010303 if (ws.mSurface != null) {
10304 if (!mSessions.contains(ws.mSession)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010305 Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010306 + ws + " surface=" + ws.mSurface
10307 + " token=" + win.mToken
10308 + " pid=" + ws.mSession.mPid
10309 + " uid=" + ws.mSession.mUid);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010310 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010311 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010312 ws.mSurface = null;
10313 mForceRemoves.add(ws);
10314 i--;
10315 N--;
10316 leakedSurface = true;
10317 } else if (win.mAppToken != null && win.mAppToken.clientHidden) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010318 Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010319 + ws + " surface=" + ws.mSurface
10320 + " token=" + win.mAppToken);
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010321 ws.mSurface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010322 ws.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010323 ws.mSurface = null;
10324 leakedSurface = true;
10325 }
10326 }
10327 }
Romain Guy06882f82009-06-10 13:36:04 -070010328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010329 boolean killedApps = false;
10330 if (!leakedSurface) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010331 Slog.w(TAG, "No leaked surfaces; killing applicatons!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010332 SparseIntArray pidCandidates = new SparseIntArray();
10333 for (int i=0; i<N; i++) {
Jeff Browne33348b2010-07-15 23:54:05 -070010334 WindowState ws = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010335 if (ws.mSurface != null) {
10336 pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid);
10337 }
10338 }
10339 if (pidCandidates.size() > 0) {
10340 int[] pids = new int[pidCandidates.size()];
10341 for (int i=0; i<pids.length; i++) {
10342 pids[i] = pidCandidates.keyAt(i);
10343 }
10344 try {
Suchi Amalapurapue99bb5f2010-03-19 14:36:49 -070010345 if (mActivityManager.killPids(pids, "Free memory")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010346 killedApps = true;
10347 }
10348 } catch (RemoteException e) {
10349 }
10350 }
10351 }
Romain Guy06882f82009-06-10 13:36:04 -070010352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010353 if (leakedSurface || killedApps) {
10354 // We managed to reclaim some memory, so get rid of the trouble
10355 // surface and ask the app to request another one.
Joe Onorato8a9b2202010-02-26 18:56:32 -080010356 Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010357 if (surface != null) {
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010358 surface.destroy();
Dianne Hackborn16064f92010-03-25 00:47:24 -070010359 win.mSurfaceShown = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010360 win.mSurface = null;
10361 }
Romain Guy06882f82009-06-10 13:36:04 -070010362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010363 try {
10364 win.mClient.dispatchGetNewSurface();
10365 } catch (RemoteException e) {
10366 }
10367 }
10368 } finally {
10369 Binder.restoreCallingIdentity(callingIdentity);
10370 }
10371 }
Romain Guy06882f82009-06-10 13:36:04 -070010372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010373 private boolean updateFocusedWindowLocked(int mode) {
10374 WindowState newFocus = computeFocusedWindowLocked();
10375 if (mCurrentFocus != newFocus) {
10376 // This check makes sure that we don't already have the focus
10377 // change message pending.
10378 mH.removeMessages(H.REPORT_FOCUS_CHANGE);
10379 mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -080010380 if (localLOGV) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010381 TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus);
10382 final WindowState oldFocus = mCurrentFocus;
10383 mCurrentFocus = newFocus;
10384 mLosingFocus.remove(newFocus);
Romain Guy06882f82009-06-10 13:36:04 -070010385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010386 final WindowState imWindow = mInputMethodWindow;
10387 if (newFocus != imWindow && oldFocus != imWindow) {
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010388 if (moveInputMethodWindowsIfNeededLocked(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010389 mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS &&
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010390 mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
10391 mLayoutNeeded = true;
10392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010393 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
10394 performLayoutLockedInner();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010395 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
10396 // Client will do the layout, but we need to assign layers
10397 // for handleNewWindowLocked() below.
10398 assignLayersLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010399 }
10400 }
Jeff Brown349703e2010-06-22 01:27:15 -070010401
10402 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
10403 // If we defer assigning layers, then the caller is responsible for
10404 // doing this part.
10405 finishUpdateFocusedWindowAfterAssignLayersLocked();
The Android Open Source Projectc474dec2009-03-04 09:49:09 -080010406 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010407 return true;
10408 }
10409 return false;
10410 }
Jeff Brown349703e2010-06-22 01:27:15 -070010411
10412 private void finishUpdateFocusedWindowAfterAssignLayersLocked() {
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010413 mInputMonitor.setInputFocusLw(mCurrentFocus);
Jeff Brown349703e2010-06-22 01:27:15 -070010414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010415
10416 private WindowState computeFocusedWindowLocked() {
10417 WindowState result = null;
10418 WindowState win;
10419
10420 int i = mWindows.size() - 1;
10421 int nextAppIndex = mAppTokens.size()-1;
10422 WindowToken nextApp = nextAppIndex >= 0
10423 ? mAppTokens.get(nextAppIndex) : null;
10424
10425 while (i >= 0) {
Jeff Browne33348b2010-07-15 23:54:05 -070010426 win = mWindows.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010427
Joe Onorato8a9b2202010-02-26 18:56:32 -080010428 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010429 TAG, "Looking for focus: " + i
10430 + " = " + win
10431 + ", flags=" + win.mAttrs.flags
10432 + ", canReceive=" + win.canReceiveKeys());
10433
10434 AppWindowToken thisApp = win.mAppToken;
Romain Guy06882f82009-06-10 13:36:04 -070010435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010436 // If this window's application has been removed, just skip it.
10437 if (thisApp != null && thisApp.removed) {
10438 i--;
10439 continue;
10440 }
Romain Guy06882f82009-06-10 13:36:04 -070010441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010442 // If there is a focused app, don't allow focus to go to any
10443 // windows below it. If this is an application window, step
10444 // through the app tokens until we find its app.
10445 if (thisApp != null && nextApp != null && thisApp != nextApp
10446 && win.mAttrs.type != TYPE_APPLICATION_STARTING) {
10447 int origAppIndex = nextAppIndex;
10448 while (nextAppIndex > 0) {
10449 if (nextApp == mFocusedApp) {
10450 // Whoops, we are below the focused app... no focus
10451 // for you!
Joe Onorato8a9b2202010-02-26 18:56:32 -080010452 if (localLOGV || DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010453 TAG, "Reached focused app: " + mFocusedApp);
10454 return null;
10455 }
10456 nextAppIndex--;
10457 nextApp = mAppTokens.get(nextAppIndex);
10458 if (nextApp == thisApp) {
10459 break;
10460 }
10461 }
10462 if (thisApp != nextApp) {
10463 // Uh oh, the app token doesn't exist! This shouldn't
10464 // happen, but if it does we can get totally hosed...
10465 // so restart at the original app.
10466 nextAppIndex = origAppIndex;
10467 nextApp = mAppTokens.get(nextAppIndex);
10468 }
10469 }
10470
10471 // Dispatch to this window if it is wants key events.
10472 if (win.canReceiveKeys()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010473 if (DEBUG_FOCUS) Slog.v(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010474 TAG, "Found focus @ " + i + " = " + win);
10475 result = win;
10476 break;
10477 }
10478
10479 i--;
10480 }
10481
10482 return result;
10483 }
10484
10485 private void startFreezingDisplayLocked() {
10486 if (mDisplayFrozen) {
10487 return;
10488 }
Romain Guy06882f82009-06-10 13:36:04 -070010489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010490 mScreenFrozenLock.acquire();
Romain Guy06882f82009-06-10 13:36:04 -070010491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010492 long now = SystemClock.uptimeMillis();
Joe Onorato8a9b2202010-02-26 18:56:32 -080010493 //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010494 if (mFreezeGcPending != 0) {
10495 if (now > (mFreezeGcPending+1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080010496 //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010497 mH.removeMessages(H.FORCE_GC);
10498 Runtime.getRuntime().gc();
10499 mFreezeGcPending = now;
10500 }
10501 } else {
10502 mFreezeGcPending = now;
10503 }
Romain Guy06882f82009-06-10 13:36:04 -070010504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010505 mDisplayFrozen = true;
Jeff Brown349703e2010-06-22 01:27:15 -070010506
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010507 mInputMonitor.freezeInputDispatchingLw();
Jeff Brown349703e2010-06-22 01:27:15 -070010508
Dianne Hackbornbfe319e2009-09-21 00:34:05 -070010509 if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
10510 mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010511 mNextAppTransitionPackage = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010512 mAppTransitionReady = true;
10513 }
Romain Guy06882f82009-06-10 13:36:04 -070010514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010515 if (PROFILE_ORIENTATION) {
10516 File file = new File("/data/system/frozen");
10517 Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
10518 }
10519 Surface.freezeDisplay(0);
10520 }
Romain Guy06882f82009-06-10 13:36:04 -070010521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010522 private void stopFreezingDisplayLocked() {
10523 if (!mDisplayFrozen) {
10524 return;
10525 }
Romain Guy06882f82009-06-10 13:36:04 -070010526
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010527 if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) {
10528 return;
10529 }
10530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010531 mDisplayFrozen = false;
10532 mH.removeMessages(H.APP_FREEZE_TIMEOUT);
10533 if (PROFILE_ORIENTATION) {
10534 Debug.stopMethodTracing();
10535 }
10536 Surface.unfreezeDisplay(0);
Romain Guy06882f82009-06-10 13:36:04 -070010537
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010538 mInputMonitor.thawInputDispatchingLw();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010539
Christopher Tateb696aee2010-04-02 19:08:30 -070010540 // While the display is frozen we don't re-compute the orientation
10541 // to avoid inconsistent states. However, something interesting
10542 // could have actually changed during that time so re-evaluate it
10543 // now to catch that.
10544 if (updateOrientationFromAppTokensLocked()) {
10545 mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
10546 }
10547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010548 // A little kludge: a lot could have happened while the
10549 // display was frozen, so now that we are coming back we
10550 // do a gc so that any remote references the system
10551 // processes holds on others can be released if they are
10552 // no longer needed.
10553 mH.removeMessages(H.FORCE_GC);
10554 mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC),
10555 2000);
Romain Guy06882f82009-06-10 13:36:04 -070010556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010557 mScreenFrozenLock.release();
10558 }
Romain Guy06882f82009-06-10 13:36:04 -070010559
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010560 static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
10561 DisplayMetrics dm) {
10562 if (index < tokens.length) {
10563 String str = tokens[index];
10564 if (str != null && str.length() > 0) {
10565 try {
10566 int val = Integer.parseInt(str);
10567 return val;
10568 } catch (Exception e) {
10569 }
10570 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010571 }
10572 if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
10573 return defDps;
10574 }
10575 int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
10576 return val;
10577 }
10578
10579 class Watermark {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010580 final String[] mTokens;
10581 final String mText;
10582 final Paint mTextPaint;
10583 final int mTextWidth;
10584 final int mTextHeight;
10585 final int mTextAscent;
10586 final int mTextDescent;
10587 final int mDeltaX;
10588 final int mDeltaY;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010589
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010590 Surface mSurface;
10591 int mLastDW;
10592 int mLastDH;
10593 boolean mDrawNeeded;
10594
10595 Watermark(SurfaceSession session, String[] tokens) {
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010596 final DisplayMetrics dm = new DisplayMetrics();
10597 mDisplay.getMetrics(dm);
10598
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010599 if (false) {
10600 Log.i(TAG, "*********************** WATERMARK");
10601 for (int i=0; i<tokens.length; i++) {
10602 Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]);
10603 }
10604 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010605
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010606 mTokens = tokens;
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010607
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010608 StringBuilder builder = new StringBuilder(32);
10609 int len = mTokens[0].length();
10610 len = len & ~1;
10611 for (int i=0; i<len; i+=2) {
10612 int c1 = mTokens[0].charAt(i);
10613 int c2 = mTokens[0].charAt(i+1);
10614 if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
10615 else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
10616 else c1 -= '0';
10617 if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
10618 else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
10619 else c2 -= '0';
10620 builder.append((char)(255-((c1*16)+c2)));
10621 }
10622 mText = builder.toString();
10623 if (false) {
10624 Log.i(TAG, "Final text: " + mText);
10625 }
10626
10627 int fontSize = getPropertyInt(tokens, 1,
10628 TypedValue.COMPLEX_UNIT_DIP, 20, dm);
10629
10630 mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
10631 mTextPaint.setTextSize(fontSize);
10632 mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
10633
10634 FontMetricsInt fm = mTextPaint.getFontMetricsInt();
10635 mTextWidth = (int)mTextPaint.measureText(mText);
10636 mTextAscent = fm.ascent;
10637 mTextDescent = fm.descent;
10638 mTextHeight = fm.descent - fm.ascent;
10639
10640 mDeltaX = getPropertyInt(tokens, 2,
10641 TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
10642 mDeltaY = getPropertyInt(tokens, 3,
10643 TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
10644 int shadowColor = getPropertyInt(tokens, 4,
10645 TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
10646 int color = getPropertyInt(tokens, 5,
10647 TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
10648 int shadowRadius = getPropertyInt(tokens, 6,
10649 TypedValue.COMPLEX_UNIT_PX, 7, dm);
10650 int shadowDx = getPropertyInt(tokens, 8,
10651 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10652 int shadowDy = getPropertyInt(tokens, 9,
10653 TypedValue.COMPLEX_UNIT_PX, 0, dm);
10654
10655 mTextPaint.setColor(color);
10656 mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010657
10658 try {
10659 mSurface = new Surface(session, 0,
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010660 "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010661 mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100);
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010662 mSurface.setPosition(0, 0);
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010663 mSurface.show();
10664 } catch (OutOfResourcesException e) {
10665 }
10666 }
10667
10668 void positionSurface(int dw, int dh) {
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010669 if (mLastDW != dw || mLastDH != dh) {
10670 mLastDW = dw;
10671 mLastDH = dh;
10672 mSurface.setSize(dw, dh);
10673 mDrawNeeded = true;
10674 }
10675 }
10676
10677 void drawIfNeeded() {
10678 if (mDrawNeeded) {
10679 final int dw = mLastDW;
10680 final int dh = mLastDH;
10681
10682 mDrawNeeded = false;
10683 Rect dirty = new Rect(0, 0, dw, dh);
10684 Canvas c = null;
10685 try {
10686 c = mSurface.lockCanvas(dirty);
10687 } catch (IllegalArgumentException e) {
10688 } catch (OutOfResourcesException e) {
10689 }
10690 if (c != null) {
10691 int deltaX = mDeltaX;
10692 int deltaY = mDeltaY;
10693
10694 // deltaX shouldn't be close to a round fraction of our
10695 // x step, or else things will line up too much.
10696 int div = (dw+mTextWidth)/deltaX;
10697 int rem = (dw+mTextWidth) - (div*deltaX);
10698 int qdelta = deltaX/4;
10699 if (rem < qdelta || rem > (deltaX-qdelta)) {
10700 deltaX += deltaX/3;
10701 }
10702
10703 int y = -mTextHeight;
10704 int x = -mTextWidth;
10705 while (y < (dh+mTextHeight)) {
10706 c.drawText(mText, x, y, mTextPaint);
10707 x += deltaX;
10708 if (x >= dw) {
10709 x -= (dw+mTextWidth);
10710 y += deltaY;
10711 }
10712 }
10713 mSurface.unlockCanvasAndPost(c);
10714 }
10715 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010716 }
10717 }
10718
10719 void createWatermark() {
10720 if (mWatermark != null) {
10721 return;
10722 }
10723
Dianne Hackbornb9fb1702010-08-23 16:49:02 -070010724 File file = new File("/system/etc/setup.conf");
10725 FileInputStream in = null;
10726 try {
10727 in = new FileInputStream(file);
10728 DataInputStream ind = new DataInputStream(in);
10729 String line = ind.readLine();
10730 if (line != null) {
10731 String[] toks = line.split("%");
10732 if (toks != null && toks.length > 0) {
10733 mWatermark = new Watermark(mFxSession, toks);
10734 }
10735 }
10736 } catch (FileNotFoundException e) {
10737 } catch (IOException e) {
10738 } finally {
10739 if (in != null) {
10740 try {
10741 in.close();
10742 } catch (IOException e) {
10743 }
10744 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010745 }
Dianne Hackbornfb86ce92010-08-11 18:11:23 -070010746 }
10747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010748 @Override
10749 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
10750 if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
10751 != PackageManager.PERMISSION_GRANTED) {
10752 pw.println("Permission Denial: can't dump WindowManager from from pid="
10753 + Binder.getCallingPid()
10754 + ", uid=" + Binder.getCallingUid());
10755 return;
10756 }
Romain Guy06882f82009-06-10 13:36:04 -070010757
Jeff Brown00fa7bd2010-07-02 15:37:36 -070010758 mInputManager.dump(pw);
Dianne Hackborna2e92262010-03-02 17:19:29 -080010759 pw.println(" ");
10760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010761 synchronized(mWindowMap) {
10762 pw.println("Current Window Manager state:");
10763 for (int i=mWindows.size()-1; i>=0; i--) {
Jeff Browne33348b2010-07-15 23:54:05 -070010764 WindowState w = mWindows.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010765 pw.print(" Window #"); pw.print(i); pw.print(' ');
10766 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010767 w.dump(pw, " ");
10768 }
10769 if (mInputMethodDialogs.size() > 0) {
10770 pw.println(" ");
10771 pw.println(" Input method dialogs:");
10772 for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
10773 WindowState w = mInputMethodDialogs.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010774 pw.print(" IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010775 }
10776 }
10777 if (mPendingRemove.size() > 0) {
10778 pw.println(" ");
10779 pw.println(" Remove pending for:");
10780 for (int i=mPendingRemove.size()-1; i>=0; i--) {
10781 WindowState w = mPendingRemove.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010782 pw.print(" Remove #"); pw.print(i); pw.print(' ');
10783 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010784 w.dump(pw, " ");
10785 }
10786 }
10787 if (mForceRemoves != null && mForceRemoves.size() > 0) {
10788 pw.println(" ");
10789 pw.println(" Windows force removing:");
10790 for (int i=mForceRemoves.size()-1; i>=0; i--) {
10791 WindowState w = mForceRemoves.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010792 pw.print(" Removing #"); pw.print(i); pw.print(' ');
10793 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010794 w.dump(pw, " ");
10795 }
10796 }
10797 if (mDestroySurface.size() > 0) {
10798 pw.println(" ");
10799 pw.println(" Windows waiting to destroy their surface:");
10800 for (int i=mDestroySurface.size()-1; i>=0; i--) {
10801 WindowState w = mDestroySurface.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010802 pw.print(" Destroy #"); pw.print(i); pw.print(' ');
10803 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010804 w.dump(pw, " ");
10805 }
10806 }
10807 if (mLosingFocus.size() > 0) {
10808 pw.println(" ");
10809 pw.println(" Windows losing focus:");
10810 for (int i=mLosingFocus.size()-1; i>=0; i--) {
10811 WindowState w = mLosingFocus.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010812 pw.print(" Losing #"); pw.print(i); pw.print(' ');
10813 pw.print(w); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010814 w.dump(pw, " ");
10815 }
10816 }
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070010817 if (mResizingWindows.size() > 0) {
10818 pw.println(" ");
10819 pw.println(" Windows waiting to resize:");
10820 for (int i=mResizingWindows.size()-1; i>=0; i--) {
10821 WindowState w = mResizingWindows.get(i);
10822 pw.print(" Resizing #"); pw.print(i); pw.print(' ');
10823 pw.print(w); pw.println(":");
10824 w.dump(pw, " ");
10825 }
10826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010827 if (mSessions.size() > 0) {
10828 pw.println(" ");
10829 pw.println(" All active sessions:");
10830 Iterator<Session> it = mSessions.iterator();
10831 while (it.hasNext()) {
10832 Session s = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010833 pw.print(" Session "); pw.print(s); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010834 s.dump(pw, " ");
10835 }
10836 }
10837 if (mTokenMap.size() > 0) {
10838 pw.println(" ");
10839 pw.println(" All tokens:");
10840 Iterator<WindowToken> it = mTokenMap.values().iterator();
10841 while (it.hasNext()) {
10842 WindowToken token = it.next();
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010843 pw.print(" Token "); pw.print(token.token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010844 token.dump(pw, " ");
10845 }
10846 }
10847 if (mTokenList.size() > 0) {
10848 pw.println(" ");
10849 pw.println(" Window token list:");
10850 for (int i=0; i<mTokenList.size(); i++) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010851 pw.print(" #"); pw.print(i); pw.print(": ");
10852 pw.println(mTokenList.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010853 }
10854 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070010855 if (mWallpaperTokens.size() > 0) {
10856 pw.println(" ");
10857 pw.println(" Wallpaper tokens:");
10858 for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
10859 WindowToken token = mWallpaperTokens.get(i);
10860 pw.print(" Wallpaper #"); pw.print(i);
10861 pw.print(' '); pw.print(token); pw.println(':');
10862 token.dump(pw, " ");
10863 }
10864 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010865 if (mAppTokens.size() > 0) {
10866 pw.println(" ");
10867 pw.println(" Application tokens in Z order:");
10868 for (int i=mAppTokens.size()-1; i>=0; i--) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010869 pw.print(" App #"); pw.print(i); pw.print(": ");
10870 pw.println(mAppTokens.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010871 }
10872 }
10873 if (mFinishedStarting.size() > 0) {
10874 pw.println(" ");
10875 pw.println(" Finishing start of application tokens:");
10876 for (int i=mFinishedStarting.size()-1; i>=0; i--) {
10877 WindowToken token = mFinishedStarting.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010878 pw.print(" Finished Starting #"); pw.print(i);
10879 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010880 token.dump(pw, " ");
10881 }
10882 }
10883 if (mExitingTokens.size() > 0) {
10884 pw.println(" ");
10885 pw.println(" Exiting tokens:");
10886 for (int i=mExitingTokens.size()-1; i>=0; i--) {
10887 WindowToken token = mExitingTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010888 pw.print(" Exiting #"); pw.print(i);
10889 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010890 token.dump(pw, " ");
10891 }
10892 }
10893 if (mExitingAppTokens.size() > 0) {
10894 pw.println(" ");
10895 pw.println(" Exiting application tokens:");
10896 for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
10897 WindowToken token = mExitingAppTokens.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010898 pw.print(" Exiting App #"); pw.print(i);
10899 pw.print(' '); pw.print(token); pw.println(':');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010900 token.dump(pw, " ");
10901 }
10902 }
10903 pw.println(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010904 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
10905 pw.print(" mLastFocus="); pw.println(mLastFocus);
10906 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
10907 pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget);
10908 pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow);
Dianne Hackbornf21adf62009-08-13 10:20:21 -070010909 pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010910 if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) {
10911 pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
10912 pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
10913 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010914 pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration);
10915 pw.print(" mInTouchMode="); pw.print(mInTouchMode);
10916 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010917 pw.print(" mSystemBooted="); pw.print(mSystemBooted);
10918 pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
10919 pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded);
10920 pw.print(" mBlurShown="); pw.println(mBlurShown);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010921 if (mDimAnimator != null) {
10922 mDimAnimator.printTo(pw);
10923 } else {
Dianne Hackborna2e92262010-03-02 17:19:29 -080010924 pw.println( " no DimAnimator ");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010925 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010926 pw.print(" mInputMethodAnimLayerAdjustment=");
Dianne Hackborn759a39e2009-08-09 17:20:27 -070010927 pw.print(mInputMethodAnimLayerAdjustment);
10928 pw.print(" mWallpaperAnimLayerAdjustment=");
10929 pw.println(mWallpaperAnimLayerAdjustment);
Dianne Hackborn284ac932009-08-28 10:34:25 -070010930 pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX);
10931 pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010932 pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen);
10933 pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen);
Dianne Hackborne36d6e22010-02-17 19:46:25 -080010934 pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen);
10935 pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010936 pw.print(" mRotation="); pw.print(mRotation);
10937 pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation);
10938 pw.print(", mRequestedRotation="); pw.println(mRequestedRotation);
10939 pw.print(" mAnimationPending="); pw.print(mAnimationPending);
10940 pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale);
10941 pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale);
10942 pw.print(" mNextAppTransition=0x");
10943 pw.print(Integer.toHexString(mNextAppTransition));
10944 pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady);
Dianne Hackborna8f60182009-09-01 19:01:50 -070010945 pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning);
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010946 pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010947 if (mNextAppTransitionPackage != null) {
10948 pw.print(" mNextAppTransitionPackage=");
10949 pw.print(mNextAppTransitionPackage);
10950 pw.print(", mNextAppTransitionEnter=0x");
10951 pw.print(Integer.toHexString(mNextAppTransitionEnter));
10952 pw.print(", mNextAppTransitionExit=0x");
10953 pw.print(Integer.toHexString(mNextAppTransitionExit));
10954 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010955 pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition);
10956 pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
Dianne Hackborn3b3e1452009-09-24 19:22:12 -070010957 if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) {
10958 pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken);
10959 pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams);
10960 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010961 if (mOpeningApps.size() > 0) {
10962 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
10963 }
10964 if (mClosingApps.size() > 0) {
10965 pw.print(" mClosingApps="); pw.println(mClosingApps);
10966 }
Dianne Hackborna8f60182009-09-01 19:01:50 -070010967 if (mToTopApps.size() > 0) {
10968 pw.print(" mToTopApps="); pw.println(mToTopApps);
10969 }
10970 if (mToBottomApps.size() > 0) {
10971 pw.print(" mToBottomApps="); pw.println(mToBottomApps);
10972 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -070010973 pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth());
10974 pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010975 }
10976 }
10977
Jeff Brown349703e2010-06-22 01:27:15 -070010978 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010979 public void monitor() {
10980 synchronized (mWindowMap) { }
Mike Lockwood983ee092009-11-22 01:42:24 -050010981 synchronized (mKeyguardTokenWatcher) { }
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070010982 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010983
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010984 /**
10985 * DimAnimator class that controls the dim animation. This holds the surface and
Doug Zongkerab5c49c2009-12-04 10:31:43 -080010986 * all state used for dim animation.
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010987 */
10988 private static class DimAnimator {
10989 Surface mDimSurface;
10990 boolean mDimShown = false;
10991 float mDimCurrentAlpha;
10992 float mDimTargetAlpha;
10993 float mDimDeltaPerMs;
10994 long mLastDimAnimTime;
Dianne Hackbornf83c5552010-03-31 22:19:32 -070010995
10996 int mLastDimWidth, mLastDimHeight;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070010997
10998 DimAnimator (SurfaceSession session) {
10999 if (mDimSurface == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011000 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011001 + mDimSurface + ": CREATE");
11002 try {
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080011003 mDimSurface = new Surface(session, 0,
11004 "DimSurface",
11005 -1, 16, 16, PixelFormat.OPAQUE,
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011006 Surface.FX_SURFACE_DIM);
Maciej Białka9ee5c222010-03-24 10:25:40 +010011007 mDimSurface.setAlpha(0.0f);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011008 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011009 Slog.e(TAG, "Exception creating Dim surface", e);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011010 }
11011 }
11012 }
11013
11014 /**
11015 * Show the dim surface.
11016 */
11017 void show(int dw, int dh) {
Dianne Hackborn16064f92010-03-25 00:47:24 -070011018 if (!mDimShown) {
11019 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
11020 dw + "x" + dh + ")");
11021 mDimShown = true;
11022 try {
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011023 mLastDimWidth = dw;
11024 mLastDimHeight = dh;
Dianne Hackborn16064f92010-03-25 00:47:24 -070011025 mDimSurface.setPosition(0, 0);
11026 mDimSurface.setSize(dw, dh);
11027 mDimSurface.show();
11028 } catch (RuntimeException e) {
11029 Slog.w(TAG, "Failure showing dim surface", e);
11030 }
Dianne Hackbornf83c5552010-03-31 22:19:32 -070011031 } else if (mLastDimWidth != dw || mLastDimHeight != dh) {
11032 mLastDimWidth = dw;
11033 mLastDimHeight = dh;
11034 mDimSurface.setSize(dw, dh);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011035 }
11036 }
11037
11038 /**
11039 * Set's the dim surface's layer and update dim parameters that will be used in
11040 * {@link updateSurface} after all windows are examined.
11041 */
11042 void updateParameters(WindowState w, long currentTime) {
11043 mDimSurface.setLayer(w.mAnimLayer-1);
11044
11045 final float target = w.mExiting ? 0 : w.mAttrs.dimAmount;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011046 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Dianne Hackborn0586a1b2009-09-06 21:08:27 -070011047 + ": layer=" + (w.mAnimLayer-1) + " target=" + target);
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011048 if (mDimTargetAlpha != target) {
11049 // If the desired dim level has changed, then
11050 // start an animation to it.
11051 mLastDimAnimTime = currentTime;
11052 long duration = (w.mAnimating && w.mAnimation != null)
11053 ? w.mAnimation.computeDurationHint()
11054 : DEFAULT_DIM_DURATION;
11055 if (target > mDimTargetAlpha) {
11056 // This is happening behind the activity UI,
11057 // so we can make it run a little longer to
11058 // give a stronger impression without disrupting
11059 // the user.
11060 duration *= DIM_DURATION_MULTIPLIER;
11061 }
11062 if (duration < 1) {
11063 // Don't divide by zero
11064 duration = 1;
11065 }
11066 mDimTargetAlpha = target;
11067 mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration;
11068 }
11069 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011070
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011071 /**
11072 * Updating the surface's alpha. Returns true if the animation continues, or returns
11073 * false when the animation is finished and the dim surface is hidden.
11074 */
11075 boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
11076 if (!dimming) {
11077 if (mDimTargetAlpha != 0) {
11078 mLastDimAnimTime = currentTime;
11079 mDimTargetAlpha = 0;
11080 mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION;
11081 }
11082 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -080011083
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011084 boolean animating = false;
11085 if (mLastDimAnimTime != 0) {
11086 mDimCurrentAlpha += mDimDeltaPerMs
11087 * (currentTime-mLastDimAnimTime);
11088 boolean more = true;
11089 if (displayFrozen) {
11090 // If the display is frozen, there is no reason to animate.
11091 more = false;
11092 } else if (mDimDeltaPerMs > 0) {
11093 if (mDimCurrentAlpha > mDimTargetAlpha) {
11094 more = false;
11095 }
11096 } else if (mDimDeltaPerMs < 0) {
11097 if (mDimCurrentAlpha < mDimTargetAlpha) {
11098 more = false;
11099 }
11100 } else {
11101 more = false;
11102 }
11103
11104 // Do we need to continue animating?
11105 if (more) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011106 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011107 + mDimSurface + ": alpha=" + mDimCurrentAlpha);
11108 mLastDimAnimTime = currentTime;
11109 mDimSurface.setAlpha(mDimCurrentAlpha);
11110 animating = true;
11111 } else {
11112 mDimCurrentAlpha = mDimTargetAlpha;
11113 mLastDimAnimTime = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -080011114 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM "
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011115 + mDimSurface + ": final alpha=" + mDimCurrentAlpha);
11116 mDimSurface.setAlpha(mDimCurrentAlpha);
11117 if (!dimming) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011118 if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011119 + ": HIDE");
11120 try {
11121 mDimSurface.hide();
11122 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -080011123 Slog.w(TAG, "Illegal argument exception hiding dim surface");
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011124 }
11125 mDimShown = false;
11126 }
11127 }
11128 }
11129 return animating;
11130 }
11131
11132 public void printTo(PrintWriter pw) {
11133 pw.print(" mDimShown="); pw.print(mDimShown);
11134 pw.print(" current="); pw.print(mDimCurrentAlpha);
11135 pw.print(" target="); pw.print(mDimTargetAlpha);
11136 pw.print(" delta="); pw.print(mDimDeltaPerMs);
11137 pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime);
11138 }
11139 }
11140
11141 /**
11142 * Animation that fade in after 0.5 interpolate time, or fade out in reverse order.
11143 * This is used for opening/closing transition for apps in compatible mode.
11144 */
11145 private static class FadeInOutAnimation extends Animation {
11146 int mWidth;
11147 boolean mFadeIn;
11148
11149 public FadeInOutAnimation(boolean fadeIn) {
11150 setInterpolator(new AccelerateInterpolator());
11151 setDuration(DEFAULT_FADE_IN_OUT_DURATION);
11152 mFadeIn = fadeIn;
11153 }
11154
11155 @Override
11156 protected void applyTransformation(float interpolatedTime, Transformation t) {
11157 float x = interpolatedTime;
11158 if (!mFadeIn) {
11159 x = 1.0f - x; // reverse the interpolation for fade out
11160 }
11161 if (x < 0.5) {
11162 // move the window out of the screen.
11163 t.getMatrix().setTranslate(mWidth, 0);
11164 } else {
11165 t.getMatrix().setTranslate(0, 0);// show
11166 t.setAlpha((x - 0.5f) * 2);
11167 }
11168 }
11169
11170 @Override
11171 public void initialize(int width, int height, int parentWidth, int parentHeight) {
11172 // width is the screen width {@see AppWindowToken#stepAnimatinoLocked}
11173 mWidth = width;
11174 }
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011175
11176 @Override
Mitsuru Oshima5a2b91d2009-07-16 16:30:02 -070011177 public int getZAdjustment() {
11178 return Animation.ZORDER_TOP;
Mitsuru Oshima0a5d2c42009-07-14 14:10:30 -070011179 }
11180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080011181}